Skip to content

Commit e186044

Browse files
author
Amanjeev Sethi
committed
Hashes revocation review: RevocationInfo not to be optional
Reviewed-by: Pietro Albini <[email protected]> Ticket: https://ferroussystems.clickup.com/t/86947z6fp
1 parent 7733b97 commit e186044

File tree

4 files changed

+53
-49
lines changed

4 files changed

+53
-49
lines changed

crates/criticaltrust/src/keys/pair_aws_kms.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mod tests {
109109
// "localstack", a local replica of AWS services meant for testing.
110110

111111
#[test]
112+
#[ignore = "This test will be enabled in a later release."]
112113
fn test_roundtrip() {
113114
let localstack = Localstack::init();
114115
let key = localstack.create_key(KeySpec::EccNistP256);
@@ -125,7 +126,7 @@ mod tests {
125126
let signature = keypair.sign(&payload).expect("failed to sign");
126127
keypair
127128
.public()
128-
.verify(KeyRole::Root, &payload, &signature, None)
129+
.verify_without_checking_revocations(KeyRole::Root, &payload, &signature)
129130
.expect("failed to verify");
130131
}
131132

crates/criticaltrust/src/keys/public.rs

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,27 @@ impl PublicKey {
3636
role: KeyRole,
3737
payload: &PayloadBytes<'_>,
3838
signature: &SignatureBytes<'_>,
39-
signed_revocation_info: Option<SignedPayload<RevocationInfo>>,
39+
signed_revocation_info: SignedPayload<RevocationInfo>,
4040
) -> Result<(), Error> {
4141
// We need to check if there is revoked content. If the following checks pass, then bail out
4242
// early with an error.
4343
// 1. Check if the expiration date has passed.
4444
// 2. Check whether the `signature` is inside the vector
4545
// `RevocationInfo.revoked_content_sha256`.
46-
if let Some(revoked_hashes) = signed_revocation_info {
47-
let verified_revoked_content = revoked_hashes.get_verified(self)?;
48-
49-
let expiration_in_days =
50-
(verified_revoked_content.expires_at - OffsetDateTime::now_utc()).whole_days();
51-
if expiration_in_days < MAX_REVOCATION_INFO_EXPIRATION_DURATION {
52-
return Err(Error::VerificationFailed);
53-
}
46+
let verified_revoked_content = signed_revocation_info.get_verified(self)?;
47+
let expiration_in_days =
48+
(verified_revoked_content.expires_at - OffsetDateTime::now_utc()).whole_days();
49+
if expiration_in_days < MAX_REVOCATION_INFO_EXPIRATION_DURATION {
50+
return Err(Error::VerificationFailed);
51+
}
5452

55-
let based_signature =
56-
base64::engine::general_purpose::STANDARD.encode(signature.as_bytes());
57-
if verified_revoked_content
58-
.revoked_content_sha256
59-
.contains(&based_signature)
60-
{
61-
return Err(Error::VerificationFailed);
62-
}
53+
let based_signature =
54+
base64::engine::general_purpose::STANDARD.encode(signature.as_bytes());
55+
if verified_revoked_content
56+
.revoked_content_sha256
57+
.contains(&based_signature)
58+
{
59+
return Err(Error::VerificationFailed);
6360
}
6461

6562
self.verify_without_checking_revocations(role, payload, signature)?;
@@ -166,7 +163,7 @@ mod tests {
166163

167164
assert!(key
168165
.public()
169-
.verify(KeyRole::Root, &SAMPLE_PAYLOAD, &signature, None)
166+
.verify_without_checking_revocations(KeyRole::Root, &SAMPLE_PAYLOAD, &signature)
170167
.is_ok())
171168
}
172169

@@ -177,7 +174,7 @@ mod tests {
177174

178175
assert!(key
179176
.public()
180-
.verify(KeyRole::Root, &SAMPLE_PAYLOAD, &signature, None)
177+
.verify_without_checking_revocations(KeyRole::Root, &SAMPLE_PAYLOAD, &signature)
181178
.is_ok());
182179
}
183180

@@ -187,8 +184,11 @@ mod tests {
187184
let signature = key.sign(&SAMPLE_PAYLOAD).unwrap();
188185

189186
assert!(matches!(
190-
key.public()
191-
.verify(KeyRole::Packages, &SAMPLE_PAYLOAD, &signature, None),
187+
key.public().verify_without_checking_revocations(
188+
KeyRole::Packages,
189+
&SAMPLE_PAYLOAD,
190+
&signature
191+
),
192192
Err(Error::VerificationFailed)
193193
));
194194
}
@@ -199,8 +199,11 @@ mod tests {
199199
let signature = key.sign(&SAMPLE_PAYLOAD).unwrap();
200200

201201
assert!(matches!(
202-
key.public()
203-
.verify(KeyRole::Unknown, &SAMPLE_PAYLOAD, &signature, None),
202+
key.public().verify_without_checking_revocations(
203+
KeyRole::Unknown,
204+
&SAMPLE_PAYLOAD,
205+
&signature
206+
),
204207
Err(Error::VerificationFailed)
205208
));
206209
}
@@ -211,8 +214,11 @@ mod tests {
211214
let signature = key.sign(&SAMPLE_PAYLOAD).unwrap();
212215

213216
assert!(matches!(
214-
key.public()
215-
.verify(KeyRole::Root, &SAMPLE_PAYLOAD, &signature, None),
217+
key.public().verify_without_checking_revocations(
218+
KeyRole::Root,
219+
&SAMPLE_PAYLOAD,
220+
&signature
221+
),
216222
Err(Error::VerificationFailed)
217223
));
218224
}
@@ -226,11 +232,10 @@ mod tests {
226232
*bad_signature.last_mut().unwrap() = bad_signature.last().unwrap().wrapping_add(1);
227233

228234
assert!(matches!(
229-
key.public().verify(
235+
key.public().verify_without_checking_revocations(
230236
KeyRole::Root,
231237
&SAMPLE_PAYLOAD,
232238
&SignatureBytes::owned(bad_signature),
233-
None
234239
),
235240
Err(Error::VerificationFailed)
236241
));
@@ -242,11 +247,10 @@ mod tests {
242247
let signature = key.sign(&SAMPLE_PAYLOAD).unwrap();
243248

244249
assert!(matches!(
245-
key.public().verify(
250+
key.public().verify_without_checking_revocations(
246251
KeyRole::Root,
247252
&PayloadBytes::borrowed("Hello world!".as_bytes()),
248253
&signature,
249-
None
250254
),
251255
Err(Error::VerificationFailed)
252256
));
@@ -257,11 +261,10 @@ mod tests {
257261
let key = generate(KeyRole::Root, None);
258262

259263
assert!(matches!(
260-
key.public().verify(
264+
key.public().verify_without_checking_revocations(
261265
KeyRole::Root,
262266
&SAMPLE_PAYLOAD,
263267
&SignatureBytes::borrowed(&[]),
264-
None
265268
),
266269
Err(Error::VerificationFailed)
267270
));
@@ -275,8 +278,11 @@ mod tests {
275278
let signature = key1.sign(&SAMPLE_PAYLOAD).unwrap();
276279

277280
assert!(matches!(
278-
key2.public()
279-
.verify(KeyRole::Root, &SAMPLE_PAYLOAD, &signature, None),
281+
key2.public().verify_without_checking_revocations(
282+
KeyRole::Root,
283+
&SAMPLE_PAYLOAD,
284+
&signature
285+
),
280286
Err(Error::VerificationFailed)
281287
));
282288
}
@@ -290,7 +296,7 @@ mod tests {
290296
public.algorithm = KeyAlgorithm::Unknown;
291297

292298
assert!(matches!(
293-
public.verify(KeyRole::Root, &SAMPLE_PAYLOAD, &signature, None),
299+
public.verify_without_checking_revocations(KeyRole::Root, &SAMPLE_PAYLOAD, &signature),
294300
Err(Error::UnsupportedKey)
295301
));
296302
}
@@ -342,11 +348,10 @@ mod tests {
342348
.unwrap();
343349

344350
// Ensure the key can verify messages signed with the corresponding private key.
345-
key.verify(
351+
key.verify_without_checking_revocations(
346352
KeyRole::Root,
347353
&SAMPLE_PAYLOAD,
348354
&SignatureBytes::owned(base64_decode(SAMPLE_SIGNATURE).unwrap()),
349-
None,
350355
)
351356
.unwrap();
352357
}
@@ -465,7 +470,7 @@ mod tests {
465470
KeyRole::Root,
466471
&SAMPLE_PAYLOAD,
467472
&signature,
468-
Some(signed_revocation_info)
473+
signed_revocation_info
469474
),
470475
Err(Error::VerificationFailed)
471476
));
@@ -496,7 +501,7 @@ mod tests {
496501
KeyRole::Root,
497502
&SAMPLE_PAYLOAD,
498503
&signature,
499-
Some(signed_revocation_info.clone())
504+
signed_revocation_info.clone()
500505
),
501506
Err(Error::VerificationFailed)
502507
));
@@ -506,7 +511,7 @@ mod tests {
506511
KeyRole::Revocation,
507512
&SAMPLE_PAYLOAD,
508513
&signature,
509-
Some(signed_revocation_info)
514+
signed_revocation_info
510515
),
511516
Err(Error::VerificationFailed)
512517
));

crates/criticaltrust/src/manifests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Signable for RevocationInfo {
171171
pub struct KeysManifest {
172172
pub version: ManifestVersion<1>,
173173
pub keys: Vec<SignedPayload<PublicKey>>,
174-
pub revoked_signatures: Option<SignedPayload<RevocationInfo>>,
174+
pub revoked_signatures: SignedPayload<RevocationInfo>,
175175
}
176176

177177
#[cfg(test)]

crates/mock-download-server/src/lib.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub struct AuthenticationToken {
2121
pub struct Data {
2222
pub tokens: HashMap<String, AuthenticationToken>,
2323
pub keys: Vec<SignedPayload<PublicKey>>,
24-
pub revoked_signatures: Option<SignedPayload<RevocationInfo>>,
24+
pub revoked_signatures: SignedPayload<RevocationInfo>,
2525
pub release_manifests: HashMap<(String, String), ReleaseManifest>,
2626
}
2727

@@ -30,13 +30,11 @@ pub fn new() -> Builder {
3030
data: Data {
3131
tokens: HashMap::new(),
3232
keys: Vec::new(),
33-
revoked_signatures: Some(
34-
SignedPayload::new(&RevocationInfo {
35-
revoked_content_sha256: Vec::new(),
36-
expires_at: OffsetDateTime::now_utc(),
37-
})
38-
.unwrap(),
39-
),
33+
revoked_signatures: SignedPayload::new(&RevocationInfo {
34+
revoked_content_sha256: Vec::new(),
35+
expires_at: OffsetDateTime::now_utc(),
36+
})
37+
.unwrap(),
4038
release_manifests: HashMap::new(),
4139
},
4240
}

0 commit comments

Comments
 (0)