Skip to content

Commit

Permalink
Merge pull request openwsn-berkeley#307 from geonnave/fix-examples-ne…
Browse files Browse the repository at this point in the history
…w-cred-api

Examples: fix after new credential api
  • Loading branch information
geonnave authored Aug 30, 2024
2 parents a09314c + 83da142 commit 7dceb21
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/lakers-c-native/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int main(void)
memcpy(message_2.content, coap_response_payload, coap_response_payload_len);
EADItemC ead_2 = {0};
uint8_t c_r;
CredentialC id_cred_r = {0};
IdCred id_cred_r = {0};
#ifdef LAKERS_EAD_AUTHZ
// res = initiator_parse_message_2(&initiator, &message_2, &cred_r, &c_r, &id_cred_r, &ead_2);
res = initiator_parse_message_2(&initiator, &message_2, &c_r, &id_cred_r, &ead_2);
Expand Down
15 changes: 9 additions & 6 deletions examples/lakers-nrf52840/src/bin/initiator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ async fn main(spawner: Spawner) {
mbedtls_memory_buffer_alloc_init(buffer.as_mut_ptr(), buffer.len());
}

let cred_i = CredentialRPK::new(common::CRED_I.try_into().unwrap()).unwrap();
let cred_r = CredentialRPK::new(common::CRED_R.try_into().unwrap()).unwrap();
let cred_i = Credential::parse_ccs(common::CRED_I.try_into().unwrap()).unwrap();
let cred_r = Credential::parse_ccs(common::CRED_R.try_into().unwrap()).unwrap();

let mut initiator = EdhocInitiator::new(lakers_crypto::default_crypto());
let mut initiator = EdhocInitiator::new(
lakers_crypto::default_crypto(),
EDHOCMethod::StatStat,
EDHOCSuite::CipherSuite2,
);
initiator.set_identity(common::I.try_into().unwrap(), cred_i);

// Send Message 1 over raw BLE and convert the response to byte
let c_i = generate_connection_identifier_cbor(&mut lakers_crypto::default_crypto());
Expand All @@ -85,9 +90,7 @@ async fn main(spawner: Spawner) {
pckt_2.pdu[1..pckt_2.len].try_into().expect("wrong length");
let (initiator, c_r, id_cred_r, ead_2) = initiator.parse_message_2(&message_2).unwrap();
let valid_cred_r = credential_check_or_fetch(Some(cred_r), id_cred_r).unwrap();
let initiator = initiator
.verify_message_2(common::I, cred_i, valid_cred_r)
.unwrap();
let initiator = initiator.verify_message_2(valid_cred_r).unwrap();

let (mut initiator, message_3, i_prk_out) = initiator
.prepare_message_3(CredentialTransfer::ByReference, &None)
Expand Down
11 changes: 8 additions & 3 deletions examples/lakers-nrf52840/src/bin/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ async fn main(spawner: Spawner) {

info!("Received message_1");

let cred_r = CredentialRPK::new(common::CRED_R.try_into().unwrap()).unwrap();
let responder = EdhocResponder::new(lakers_crypto::default_crypto(), &common::R, cred_r);
let cred_r = Credential::parse_ccs(common::CRED_R.try_into().unwrap()).unwrap();
let responder = EdhocResponder::new(
lakers_crypto::default_crypto(),
EDHOCMethod::StatStat,
common::R.try_into().unwrap(),
cred_r,
);

let message_1: EdhocMessageBuffer = pckt.pdu[1..pckt.len].try_into().expect("wrong length"); // get rid of the TRUE byte

Expand Down Expand Up @@ -114,7 +119,7 @@ async fn main(spawner: Spawner) {
};

let cred_i =
CredentialRPK::new(common::CRED_I.try_into().unwrap()).unwrap();
Credential::parse_ccs(common::CRED_I.try_into().unwrap()).unwrap();
let valid_cred_i =
credential_check_or_fetch(Some(cred_i), id_cred_i).unwrap();

Expand Down

0 comments on commit 7dceb21

Please sign in to comment.