Skip to content

Commit ae079f3

Browse files
authored
Merge pull request #168 from alan-turing-institute/94-cr-cli-demo
Revise update key handling during challenge-response
2 parents 3180b0d + 408cbe9 commit ae079f3

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

trustchain-cli/src/bin/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clap::{arg, ArgAction, Command};
33
use core::panic;
44
use did_ion::sidetree::PublicKeyJwk;
55
use serde_json::to_string_pretty;
6-
use ssi::{jsonld::ContextLoader, jwk::JWK, ldp::LinkedDataDocument, vc::Credential};
6+
use ssi::{jsonld::ContextLoader, ldp::LinkedDataDocument, vc::Credential};
77
use std::{
88
fs::File,
99
io::{self, stdin, BufReader},
@@ -52,7 +52,7 @@ fn cli() -> Command {
5252
.arg(arg!(-v - -verbose).action(ArgAction::SetTrue))
5353
.arg(arg!(-m - -mnemonic).action(ArgAction::SetTrue))
5454
.arg(arg!(-f --file_path <FILE_PATH>).required(false))
55-
.arg(arg!(-f --update_p_key_file_path <FILE_PATH_TO_UPDATE_P_KEY>).required(false)),
55+
.arg(arg!(-u --update_p_key_file_path <FILE_PATH_TO_UPDATE_P_KEY>).required(false)),
5656
)
5757
.subcommand(
5858
Command::new("attest")

trustchain-http/src/attestor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl TrustchainAttestorHTTPHandler {
185185
let content_initiation = ContentCRInitiation {
186186
requester_did: Some(ddid),
187187
};
188-
content_initiation.elementwise_serialize(&path);
188+
content_initiation.elementwise_serialize(&path).unwrap();
189189
// extract map of keys from candidate document and generate a nonce per key
190190
let requester_keys = extract_key_ids_and_jwk(&candidate_doc).unwrap();
191191
let attestor = Entity {};
@@ -343,7 +343,7 @@ pub fn present_identity_challenge(
343343
identity_response_signature: None,
344344
};
345345

346-
// make payload
346+
// make payload (only nonce and update_p_key are included)
347347
let payload = JwtPayload::try_from(&identity_challenge).unwrap();
348348

349349
// get signing key from ION attestor

trustchain-http/src/requester.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,14 @@ pub async fn identity_response(
133133
.as_str()
134134
.unwrap();
135135
let nonce = Nonce::from(String::from(nonce_str));
136-
// update struct
137-
identity_challenge.update_p_key = Some(attestor_p_key.clone());
136+
let update_p_key_str = decrypted_verified_payload
137+
.claim("update_p_key")
138+
.unwrap()
139+
.as_str()
140+
.unwrap();
141+
let update_p_key: Jwk = serde_json::from_str(update_p_key_str).unwrap();
142+
// update struct: add nonce and update_p_key
143+
identity_challenge.update_p_key = Some(update_p_key);
138144
identity_challenge.identity_nonce = Some(nonce);
139145
identity_challenge.identity_response_signature = Some(signed_encrypted_response);
140146

trustchain-http/tests/attestation.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ use trustchain_ion::{trustchain_resolver, verifier::TrustchainVerifier};
1717
const ROOT_EVENT_TIME_1: u64 = 1666265405;
1818

1919
use mockall::automock;
20-
use std::fs;
21-
use std::path::PathBuf;
22-
use trustchain_core::utils::{extract_keys, init};
20+
use trustchain_core::utils::extract_keys;
2321

2422
#[automock]
2523
pub trait AttestationUtils {
@@ -133,6 +131,20 @@ async fn attestation_challenge_response() {
133131
let result = identity_response(&requester_path, &services, &attestor_public_key).await;
134132
assert!(result.is_ok());
135133
let identity_challenge_requester = result.unwrap();
134+
assert_eq!(
135+
identity_challenge_requester.update_p_key,
136+
identity_challenge_attestor.update_p_key
137+
);
138+
assert_eq!(
139+
identity_challenge_attestor
140+
.update_s_key
141+
.unwrap()
142+
.to_public_key()
143+
.ok(),
144+
identity_challenge_attestor.update_p_key
145+
);
146+
assert_eq!(identity_challenge_requester.update_s_key, None);
147+
136148
identity_challenge_requester
137149
.elementwise_serialize(&requester_path)
138150
.unwrap();

0 commit comments

Comments
 (0)