Skip to content

Commit 7e6978d

Browse files
authored
Expose the parsed label, rather than just the parameters, to the public (#40)
Systems need to be able to log aspects of the message that was received. Previously, we only exposed `ParameterDetails`, which were sufficient for logging a select few properties found in the message. However, there's more value in exposing the contents of the chosen Signature and Signature-Input label, allowing people to view the raw signature, as well as the signed components in the message, so as to enforce their own requirements. This change drops exposing `ParameterDetails` directly and instead exposes `ParsedLabel`, which both allows access to `ParameterDetails` and additionally exposes the signature components and the signature itself.
1 parent fb63807 commit 7e6978d

File tree

7 files changed

+42
-22
lines changed

7 files changed

+42
-22
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
resolver = "2"
77

88
[workspace.package]
9-
version = "0.3.0"
9+
version = "0.4.0"
1010
authors = [
1111
"Akshat Mahajan <akshat@cloudflare.com>",
1212
"Gauri Baraskar <gbaraskar@cloudflare.com>",
@@ -32,4 +32,4 @@ serde_json = "1.0.140"
3232
data-url = "0.3.1"
3333

3434
# workspace dependencies
35-
web-bot-auth = { version = "0.3.0", path = "./crates/web-bot-auth" }
35+
web-bot-auth = { version = "0.4.0", path = "./crates/web-bot-auth" }

crates/http-signature-directory/src/main.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ fn main() -> Result<(), String> {
175175
)
176176
})?;
177177

178-
let advisory = verifier.get_details().possibly_insecure(|_| false);
178+
let advisory = verifier
179+
.parsed
180+
.base
181+
.parameters
182+
.details
183+
.possibly_insecure(|_| false);
179184
// Since the expiry date is in the past.
180185
if advisory.is_expired.unwrap_or(true) {
181186
return Err(String::from(

crates/web-bot-auth/src/lib.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub mod keyring;
2626
pub mod message_signatures;
2727

2828
use components::CoveredComponent;
29-
use message_signatures::{MessageVerifier, ParameterDetails, SignatureTiming, SignedMessage};
29+
use message_signatures::{MessageVerifier, ParsedLabel, SignatureTiming, SignedMessage};
3030

3131
use data_url::DataUrl;
3232
use keyring::{Algorithm, JSONWebKeySet, KeyRing};
@@ -212,10 +212,10 @@ impl WebBotAuthVerifier {
212212
self.message_verifier.verify(keyring, key_id)
213213
}
214214

215-
/// Retrieve the parsed `ParameterDetails` from the message. Useful for logging
216-
/// information about the message.
217-
pub fn get_details(&self) -> &ParameterDetails {
218-
self.message_verifier.get_details()
215+
/// Retrieve the contents of the chosen signature and signature input label for
216+
/// verification.
217+
pub fn get_parsed_label(&self) -> &ParsedLabel {
218+
&self.message_verifier.parsed
219219
}
220220
}
221221

@@ -267,7 +267,12 @@ mod tests {
267267
public_key.to_vec(),
268268
);
269269
let verifier = WebBotAuthVerifier::parse(&test).unwrap();
270-
let advisory = verifier.get_details().possibly_insecure(|_| false);
270+
let advisory = verifier
271+
.get_parsed_label()
272+
.base
273+
.parameters
274+
.details
275+
.possibly_insecure(|_| false);
271276
// Since the expiry date is in the past.
272277
assert!(advisory.is_expired.unwrap_or(true));
273278
assert!(!advisory.nonce_is_invalid.unwrap_or(true));
@@ -364,7 +369,12 @@ mod tests {
364369
.unwrap();
365370

366371
let verifier = WebBotAuthVerifier::parse(&mytest).unwrap();
367-
let advisory = verifier.get_details().possibly_insecure(|_| false);
372+
let advisory = verifier
373+
.get_parsed_label()
374+
.base
375+
.parameters
376+
.details
377+
.possibly_insecure(|_| false);
368378
assert!(!advisory.is_expired.unwrap_or(true));
369379
assert!(!advisory.nonce_is_invalid.unwrap_or(true));
370380

crates/web-bot-auth/src/message_signatures.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use super::ImplementationError;
1010
/// The component parameters associated with the signature in `Signature-Input`
1111
#[derive(Clone, Debug)]
1212
pub struct SignatureParams {
13-
raw: sfv::Parameters,
13+
/// The raw signature parameters associated with this request.
14+
pub raw: sfv::Parameters,
1415
/// Standard values obtained from the component parameters, such as created, etc.
1516
pub details: ParameterDetails,
1617
}
@@ -486,12 +487,6 @@ impl MessageVerifier {
486487
})
487488
}
488489

489-
/// Retrieve the parsed `ParameterDetails` from the message. Useful for logging
490-
/// information about the message.
491-
pub fn get_details(&self) -> &ParameterDetails {
492-
&self.parsed.base.parameters.details
493-
}
494-
495490
/// Verify the messsage, consuming the verifier in the process.
496491
/// If `key_id` is not supplied, a key ID to fetch the public key
497492
/// from `keyring` will be sourced from the `keyid` parameter

examples/rust/verify.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ fn main() {
6565
);
6666
let test = MySignedMsg {};
6767
let verifier = WebBotAuthVerifier::parse(&test).unwrap();
68-
let advisory = verifier.get_details().possibly_insecure(|_| false);
68+
let advisory = verifier
69+
.get_parsed_label()
70+
.base
71+
.parameters
72+
.details
73+
.possibly_insecure(|_| false);
6974
for url in verifier.get_signature_agents().iter() {
7075
assert_eq!(
7176
url,

examples/rust/verify_arbitrary.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ fn main() {
5252
);
5353
let test = MySignedMsg {};
5454
let verifier = MessageVerifier::parse(&test, |_| true).unwrap();
55-
let advisory = verifier.get_details().possibly_insecure(|_| false);
55+
let advisory = verifier
56+
.parsed
57+
.base
58+
.parameters
59+
.details
60+
.possibly_insecure(|_| false);
5661
// Since the expiry date is in the past.
5762
assert!(advisory.is_expired.unwrap_or(true));
5863
assert!(!advisory.nonce_is_invalid.unwrap_or(true));

0 commit comments

Comments
 (0)