Skip to content

Commit 2cc67e1

Browse files
committed
fix(rust/signed-doc): use rbac-registration type for public key and algorithm verification
1 parent 0897cd6 commit 2cc67e1

File tree

3 files changed

+44
-25
lines changed

3 files changed

+44
-25
lines changed

rust/signed_doc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ license.workspace = true
1111
workspace = true
1212

1313
[dependencies]
14+
rbac-registration = { version = "0.0.2", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250128-01" }
1415
catalyst-types = { version = "0.0.1", git = "https://github.com/input-output-hk/catalyst-libs.git", tag = "r20250128-01" }
1516
anyhow = "1.0.95"
1617
serde = { version = "1.0.217", features = ["derive"] }

rust/signed_doc/examples/mk_signed_doc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{
88
path::PathBuf,
99
};
1010

11-
use catalyst_signed_doc::{Builder, CatalystSignedDocument, IdUri, Metadata};
11+
use catalyst_signed_doc::{Builder, CatalystSignedDocument, IdUri, Metadata, SimplePublicKeyType};
1212
use clap::Parser;
1313
use ed25519_dalek::pkcs8::{DecodePrivateKey, DecodePublicKey};
1414

@@ -107,9 +107,9 @@ impl Cli {
107107
signed_doc
108108
.verify(|k| {
109109
if k.to_string() == kid.to_string() {
110-
pk
110+
SimplePublicKeyType::Ed25519(pk)
111111
} else {
112-
k.role0_pk()
112+
SimplePublicKeyType::Undefined
113113
}
114114
})
115115
.map_err(|e| anyhow::anyhow!("Catalyst Document Verification failed: {e}"))?;

rust/signed_doc/src/lib.rs

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ pub use builder::Builder;
1717
use catalyst_types::problem_report::ProblemReport;
1818
pub use content::Content;
1919
use coset::{CborSerializable, Header};
20-
use ed25519_dalek::VerifyingKey;
2120
use error::CatalystSignedDocError;
2221
pub use metadata::{DocumentRef, ExtraFields, Metadata, UuidV4, UuidV7};
2322
pub use minicbor::{decode, encode, Decode, Decoder, Encode};
23+
pub use rbac_registration::cardano::cip509::SimplePublicKeyType;
2424
pub use signature::{IdUri, Signatures};
2525
use utils::context::DecodeSignDocCtx;
2626

@@ -131,34 +131,50 @@ impl CatalystSignedDocument {
131131
/// Returns a report of verification failures and the source error.
132132
#[allow(clippy::indexing_slicing)]
133133
pub fn verify<P>(&self, pk_getter: P) -> Result<(), CatalystSignedDocError>
134-
where P: Fn(&IdUri) -> VerifyingKey {
134+
where P: Fn(&IdUri) -> SimplePublicKeyType {
135135
let error_report = ProblemReport::new("Catalyst Signed Document Verification");
136136

137137
match self.as_cose_sign() {
138138
Ok(cose_sign) => {
139139
let signatures = self.signatures().cose_signatures();
140140
for (idx, kid) in self.signatures().kids().iter().enumerate() {
141-
let pk = pk_getter(kid);
142-
let signature = &signatures[idx];
143-
let tbs_data = cose_sign.tbs_data(&[], signature);
144-
match signature.signature.as_slice().try_into() {
145-
Ok(signature_bytes) => {
146-
let signature = ed25519_dalek::Signature::from_bytes(signature_bytes);
147-
if let Err(e) = pk.verify_strict(&tbs_data, &signature) {
148-
error_report.functional_validation(
149-
&format!(
150-
"Verification failed for signature with Key ID {kid}: {e}"
151-
),
152-
"During signature validation with verifying key",
153-
);
141+
match pk_getter(kid) {
142+
SimplePublicKeyType::Ed25519(pk) => {
143+
let signature = &signatures[idx];
144+
let tbs_data = cose_sign.tbs_data(&[], signature);
145+
match signature.signature.as_slice().try_into() {
146+
Ok(signature_bytes) => {
147+
let signature =
148+
ed25519_dalek::Signature::from_bytes(signature_bytes);
149+
if let Err(e) = pk.verify_strict(&tbs_data, &signature) {
150+
error_report.functional_validation(
151+
&format!(
152+
"Verification failed for signature with Key ID {kid}: {e}"
153+
),
154+
"During signature validation with verifying key",
155+
);
156+
}
157+
},
158+
Err(_) => {
159+
error_report.invalid_value(
160+
"cose signature",
161+
&format!("{}", signature.signature.len()),
162+
&format!("must be {}", ed25519_dalek::Signature::BYTE_SIZE),
163+
"During encoding cose signature to bytes",
164+
);
165+
},
154166
}
155167
},
156-
Err(_) => {
157-
error_report.invalid_value(
158-
"cose signature",
159-
&format!("{}", signature.signature.len()),
160-
&format!("must be {}", ed25519_dalek::Signature::BYTE_SIZE),
161-
"During encoding cose signature to bytes",
168+
SimplePublicKeyType::Deleted => {
169+
error_report.other(
170+
&format!("Public key for {kid} has been deleted."),
171+
"During public key extraction",
172+
);
173+
},
174+
SimplePublicKeyType::Undefined => {
175+
error_report.other(
176+
&format!("Public key for {kid} is undefined."),
177+
"During public key extraction",
162178
);
163179
},
164180
}
@@ -417,6 +433,8 @@ mod tests {
417433
.build()
418434
.unwrap();
419435

420-
assert!(signed_doc.verify(|_| { pk }).is_ok());
436+
assert!(signed_doc
437+
.verify(|_| { SimplePublicKeyType::Ed25519(pk) })
438+
.is_ok());
421439
}
422440
}

0 commit comments

Comments
 (0)