| 1 |
use sequoia_openpgp as openpgp; |
| 2 |
use openpgp::Cert; |
| 3 |
use openpgp::cert::amalgamation::ValidateAmalgamation; |
| 4 |
use openpgp::parse::Parse; |
| 5 |
use openpgp::types::RevocationStatus; |
| 6 |
|
| 7 |
use super::common::artifact; |
| 8 |
use super::common::Sq; |
| 9 |
use super::common::STANDARD_POLICY; |
| 10 |
use super::common::UserIDArg; |
| 11 |
|
| 12 |
#[test] |
| 13 |
fn list() { |
| 14 |
let sq = Sq::new(); |
| 15 |
|
| 16 |
let alice_name = "Alice Lovelace"; |
| 17 |
|
| 18 |
// Self-signed and linked. |
| 19 |
let alice_authenticated_domain = "example.org"; |
| 20 |
let alice_authenticated_email |
| 21 |
= &format!("alice@{}", alice_authenticated_domain); |
| 22 |
let alice_authenticated_userid |
| 23 |
= &format!("{} <{}>", alice_name, alice_authenticated_email); |
| 24 |
let alice_name = "Alice Lovelace"; |
| 25 |
|
| 26 |
// Self-signed, but not linked. |
| 27 |
let alice_unauthenticated_domain = "some.org"; |
| 28 |
let alice_unauthenticated_email |
| 29 |
= &format!("alice@{}", alice_unauthenticated_domain); |
| 30 |
let alice_unauthenticated_userid |
| 31 |
= &format!("{} <{}>", alice_name, alice_unauthenticated_email); |
| 32 |
|
| 33 |
// Self-signed, and partially (but insufficiently) authenticated. |
| 34 |
let alice_insufficient_domain = "insufficient.org"; |
| 35 |
let alice_insufficient_email |
| 36 |
= &format!("alice@{}", alice_insufficient_domain); |
| 37 |
let alice_insufficient_userid |
| 38 |
= &format!("{} <{}>", alice_name, alice_insufficient_email); |
| 39 |
|
| 40 |
let (alice_cert, alice_cert_path, _rev_path) |
| 41 |
= sq.key_generate( |
| 42 |
&[], |
| 43 |
&[ |
| 44 |
alice_authenticated_userid, |
| 45 |
alice_unauthenticated_userid, |
| 46 |
alice_insufficient_userid, |
| 47 |
]); |
| 48 |
|
| 49 |
sq.key_import(&alice_cert_path); |
| 50 |
sq.pki_link_add(&[], alice_cert.key_handle(), &[ alice_authenticated_userid ]); |
| 51 |
sq.pki_link_add(&["--amount=1"], alice_cert.key_handle(), |
| 52 |
&[ alice_insufficient_userid ]); |
| 53 |
|
| 54 |
// Not self-signed, but linked. |
| 55 |
let alice_petname_domain = "other.org"; |
| 56 |
let alice_petname_email |
| 57 |
= &format!("alice@{}", alice_petname_domain); |
| 58 |
let alice_petname_userid |
| 59 |
= &format!("{} <{}>", alice_name, alice_petname_email); |
| 60 |
|
| 61 |
sq.pki_link_add(&[], alice_cert.key_handle(), |
| 62 |
&[ UserIDArg::AddUserID(alice_petname_userid) ]); |
| 63 |
|
| 64 |
let unknown_domain = "unknown.org"; |
| 65 |
let unknown_email = &format!("alice@{}", unknown_domain); |
| 66 |
let unknown_userid = &format!("{} <{}>", alice_name, unknown_email); |
| 67 |
|
| 68 |
let list = |args: &[&str], success: bool, gossip_success: bool| { |
| 69 |
assert_eq!(sq.cert_list_maybe(args).is_ok(), success); |
| 70 |
|
| 71 |
let mut gossip_args: Vec<&str> = args.to_vec(); |
| 72 |
gossip_args.push("--gossip"); |
| 73 |
assert_eq!(sq.cert_list_maybe(&gossip_args[..]).is_ok(), gossip_success); |
| 74 |
}; |
| 75 |
|
| 76 |
// By fingerprint. |
| 77 |
list(&[&alice_cert.fingerprint().to_string()], true, true); |
| 78 |
list(&["--cert", &alice_cert.fingerprint().to_string()], true, true); |
| 79 |
// By key ID. |
| 80 |
list(&[&alice_cert.keyid().to_string()], true, true); |
| 81 |
list(&["--cert", &alice_cert.keyid().to_string()], true, true); |
| 82 |
|
| 83 |
// By user ID. |
| 84 |
list(&[alice_authenticated_userid], true, true); |
| 85 |
list(&["--cert-userid", alice_authenticated_userid], true, true); |
| 86 |
|
| 87 |
list(&[alice_unauthenticated_userid], false, true); |
| 88 |
list(&["--cert-userid", alice_unauthenticated_userid], false, true); |
| 89 |
|
| 90 |
list(&[alice_insufficient_userid], false, true); |
| 91 |
list(&["--cert-userid", alice_insufficient_userid], false, true); |
| 92 |
|
| 93 |
list(&[alice_petname_userid], true, true); |
| 94 |
list(&["--cert-userid", alice_petname_userid], true, true); |
| 95 |
|
| 96 |
list(&[unknown_userid], false, false); |
| 97 |
list(&["--cert-userid", unknown_userid], false, false); |
| 98 |
|
| 99 |
// By email. |
| 100 |
list(&[alice_authenticated_email], true, true); |
| 101 |
list(&["--cert-email", alice_authenticated_email], true, true); |
| 102 |
|
| 103 |
list(&[alice_unauthenticated_email], false, true); |
| 104 |
list(&["--cert-email", alice_unauthenticated_email], false, true); |
| 105 |
|
| 106 |
list(&[alice_insufficient_email], false, true); |
| 107 |
list(&["--cert-email", alice_insufficient_email], false, true); |
| 108 |
|
| 109 |
list(&[alice_petname_email], true, true); |
| 110 |
list(&["--cert-email", alice_petname_email], true, true); |
| 111 |
|
| 112 |
list(&[unknown_email], false, false); |
| 113 |
list(&["--cert-email", unknown_email], false, false); |
| 114 |
|
| 115 |
// By domain. |
| 116 |
list(&[alice_authenticated_domain], true, true); |
| 117 |
list(&["--cert-domain", alice_authenticated_domain], true, true); |
| 118 |
|
| 119 |
list(&[alice_unauthenticated_domain], false, true); |
| 120 |
list(&["--cert-domain", alice_unauthenticated_domain], false, true); |
| 121 |
|
| 122 |
list(&[alice_insufficient_domain], false, true); |
| 123 |
list(&["--cert-domain", alice_insufficient_domain], false, true); |
| 124 |
|
| 125 |
list(&[alice_petname_domain], true, true); |
| 126 |
list(&["--cert-domain", alice_petname_domain], true, true); |
| 127 |
|
| 128 |
list(&[unknown_domain], false, false); |
| 129 |
list(&["--cert-domain", unknown_domain], false, false); |
| 130 |
|
| 131 |
// Grep. |
| 132 |
list(&[alice_name], true, true); |
| 133 |
list(&["--cert-grep", alice_name], true, true); |
| 134 |
|
| 135 |
list(&[&alice_authenticated_userid[1..]], true, true); |
| 136 |
list(&["--cert-grep", &alice_authenticated_userid[1..]], true, true); |
| 137 |
|
| 138 |
list(&[&alice_unauthenticated_userid[1..]], false, true); |
| 139 |
list(&["--cert-grep", &alice_unauthenticated_userid[1..]], false, true); |
| 140 |
|
| 141 |
list(&[&alice_insufficient_userid[1..]], false, true); |
| 142 |
list(&["--cert-grep", &alice_insufficient_userid[1..]], false, true); |
| 143 |
|
| 144 |
list(&[&alice_petname_userid[1..]], true, true); |
| 145 |
list(&["--cert-grep", &alice_petname_userid[1..]], true, true); |
| 146 |
|
| 147 |
list(&[&unknown_userid[1..]], false, false); |
| 148 |
list(&["--cert-grep", &unknown_userid[1..]], false, false); |
| 149 |
|
| 150 |
// By substring. |
| 151 |
list(&["lice"], true, true); |
| 152 |
list(&["LICE"], true, true); |
| 153 |
list(&["example.or"], true, true); |
| 154 |
list(&["ExAmPlE.Or"], true, true); |
| 155 |
|
| 156 |
// When we use --userid, then we don't do substring matching. |
| 157 |
list(&["--cert-userid", &alice_authenticated_userid[1..]], false, false); |
| 158 |
|
| 159 |
// When we use --email, then we don't do substring matching. |
| 160 |
list(&["--cert-email", &alice_authenticated_email[1..]], false, false); |
| 161 |
} |
| 162 |
|
| 163 |
#[test] |
| 164 |
fn list_with_unauthenticated_handle() { |
| 165 |
// This is similar to the previous test, but uses a certificate |
| 166 |
// that only has unauthenticated user IDs. |
| 167 |
|
| 168 |
let sq = Sq::new(); |
| 169 |
|
| 170 |
let alice_name = "Alice Lovelace"; |
| 171 |
let alice_domain = "example.org"; |
| 172 |
let alice_email = &format!("alice@{}", alice_domain); |
| 173 |
let alice_userid = &format!("{} <{}>", alice_name, alice_email); |
| 174 |
|
| 175 |
let (alice_cert, alice_cert_path, _rev_path) |
| 176 |
= sq.key_generate(&[], &[ alice_userid, ]); |
| 177 |
|
| 178 |
sq.key_import(&alice_cert_path); |
| 179 |
|
| 180 |
let list = |args: &[&str], success: bool, gossip_success: bool| { |
| 181 |
assert_eq!(sq.cert_list_maybe(args).is_ok(), success); |
| 182 |
|
| 183 |
let mut gossip_args: Vec<&str> = args.to_vec(); |
| 184 |
gossip_args.push("--gossip"); |
| 185 |
assert_eq!(sq.cert_list_maybe(&gossip_args[..]).is_ok(), gossip_success); |
| 186 |
}; |
| 187 |
|
| 188 |
list(&["--cert", &alice_cert.fingerprint().to_string()], true, true); |
| 189 |
list(&["--cert-userid", alice_userid], false, true); |
| 190 |
list(&["--cert-email", alice_email], false, true); |
| 191 |
list(&["--cert-domain", alice_domain], false, true); |
| 192 |
list(&["--cert-grep", &alice_name[1..]], false, true); |
| 193 |
} |
| 194 |
|
| 195 |
/// Check that multiple simultaneous queries work. |
| 196 |
#[test] |
| 197 |
fn list_multiple_queries() { |
| 198 |
let sq = Sq::new(); |
| 199 |
|
| 200 |
let alice_email = "[email protected]"; |
| 201 |
let alice_name = "Alice Lovelace"; |
| 202 |
let alice_userid = &format!("{} <{}>", alice_name, alice_email); |
| 203 |
let (alice_cert, alice_cert_path, _rev_path) |
| 204 |
= sq.key_generate(&[], &[ alice_userid ]); |
| 205 |
|
| 206 |
sq.key_import(&alice_cert_path); |
| 207 |
|
| 208 |
let alice_petname_email = "[email protected]"; |
| 209 |
let alice_petname_userid |
| 210 |
= &format!("{} <{}>", alice_name, alice_petname_email); |
| 211 |
|
| 212 |
let bob_email = "[email protected]"; |
| 213 |
let bob_name = "Bob"; |
| 214 |
let bob_userid = &format!("{} <{}>", bob_name, bob_email); |
| 215 |
let (bob_cert, bob_cert_path, _rev_path) |
| 216 |
= sq.key_generate(&[], &[ bob_userid ]); |
| 217 |
|
| 218 |
sq.key_import(&bob_cert_path); |
| 219 |
|
| 220 |
let bob_petname_email = "[email protected]"; |
| 221 |
let bob_petname_userid |
| 222 |
= &format!("{} <{}>", bob_name, bob_petname_email); |
| 223 |
|
| 224 |
let unknown_domain = "unknown.org"; |
| 225 |
let unknown_email = "[email protected]"; |
| 226 |
//let unknown_userid = &format!("Unknown <{}>", unknown_email); |
| 227 |
|
| 228 |
// We don't link the self-signed user IDs, just the petnames. |
| 229 |
sq.pki_link_add(&[], alice_cert.key_handle(), |
| 230 |
&[UserIDArg::AddUserID(alice_petname_userid)]); |
| 231 |
sq.pki_link_add(&[], bob_cert.key_handle(), |
| 232 |
&[UserIDArg::AddUserID(bob_petname_userid)]); |
| 233 |
|
| 234 |
let list = |args: &[&str], success: bool, gossip_success: bool| { |
| 235 |
assert_eq!(sq.cert_list_maybe(args).is_ok(), success); |
| 236 |
|
| 237 |
let mut gossip_args: Vec<&str> = args.to_vec(); |
| 238 |
gossip_args.push("--gossip"); |
| 239 |
assert_eq!(sq.cert_list_maybe(&gossip_args[..]).is_ok(), gossip_success); |
| 240 |
}; |
| 241 |
|
| 242 |
// Smoke test: make sure we the individual queries work. |
| 243 |
list(&[alice_email], false, true); |
| 244 |
list(&["--cert-email", alice_email], false, true); |
| 245 |
|
| 246 |
list(&[bob_email], false, true); |
| 247 |
list(&["--cert-email", bob_email], false, true); |
| 248 |
|
| 249 |
list(&[alice_petname_email], true, true); |
| 250 |
list(&["--cert-email", alice_petname_email], true, true); |
| 251 |
|
| 252 |
list(&[bob_petname_email], true, true); |
| 253 |
list(&["--cert-email", bob_petname_email], true, true); |
| 254 |
|
| 255 |
list(&[unknown_email], false, false); |
| 256 |
list(&["--cert-email", unknown_email], false, false); |
| 257 |
|
| 258 |
list(&["--cert-domain", "example.org"], false, true); |
| 259 |
list(&["--cert-domain", "alice.org"], true, true); |
| 260 |
list(&["--cert-domain", "bob.org"], true, true); |
| 261 |
list(&["--cert-domain", unknown_domain], false, false); |
| 262 |
|
| 263 |
// Multiple queries where all queries have an authenticated match. |
| 264 |
list(&["--cert-email", alice_petname_email, |
| 265 |
"--cert-email", bob_petname_email], |
| 266 |
true, true); |
| 267 |
list(&["--cert-domain", "alice.org", |
| 268 |
"--cert-domain", "bob.org"], |
| 269 |
true, true); |
| 270 |
list(&["--cert", &alice_cert.key_handle().to_string(), |
| 271 |
"--cert-domain", "bob.org"], |
| 272 |
true, true); |
| 273 |
list(&["--cert-domain", "alice.org", |
| 274 |
"--cert-domain", "bob.org", |
| 275 |
"--cert", &alice_cert.key_handle().to_string()], |
| 276 |
true, true); |
| 277 |
|
| 278 |
// Multiple queries where one query has a match, but that match |
| 279 |
// doesn't authenticate. |
| 280 |
list(&["--cert-email", alice_email, |
| 281 |
"--cert-email", bob_petname_email], |
| 282 |
false, true); |
| 283 |
list(&["--cert-email", alice_petname_email, |
| 284 |
"--cert-email", bob_email], |
| 285 |
false, true); |
| 286 |
list(&["--cert-email", alice_petname_email, |
| 287 |
"--cert-email", unknown_email], |
| 288 |
false, false); |
| 289 |
|
| 290 |
list(&["--cert-domain", "example.org", |
| 291 |
"--cert-domain", "bob.org"], |
| 292 |
false, true); |
| 293 |
list(&["--cert-domain", "example.org", |
| 294 |
"--cert-domain", unknown_domain], |
| 295 |
false, false); |
| 296 |
} |
| 297 |
|
| 298 |
#[test] |
| 299 |
fn list_empty() { |
| 300 |
let sq = Sq::new(); |
| 301 |
|
| 302 |
// Listing an empty certificate store should not be an error. |
| 303 |
sq.cert_list(&[]); |
| 304 |
|
| 305 |
// Listing an empty certificate store with a pattern (that doesn't |
| 306 |
// match anything) should be. |
| 307 |
assert!(sq.cert_list_maybe(&["not found"]).is_err()); |
| 308 |
|
| 309 |
let (cert, cert_path, _rev_path) |
| 310 |
= sq.key_generate(&[], &[ "alice" ]); |
| 311 |
sq.key_import(cert_path); |
| 312 |
|
| 313 |
// Not linked => error. |
| 314 |
assert!(sq.cert_list_maybe(&["alice"]).is_err()); |
| 315 |
// Not found => error. |
| 316 |
assert!(sq.cert_list_maybe(&["not found"]).is_err()); |
| 317 |
|
| 318 |
// Linked and found => ok. |
| 319 |
sq.pki_link_add(&[], cert.key_handle(), &["alice"]); |
| 320 |
sq.cert_list(&["alice"]); |
| 321 |
} |
| 322 |
|
| 323 |
/// Tests that listing a cert without user IDs works. |
| 324 |
#[test] |
| 325 |
fn list_no_userids() { |
| 326 |
let sq = Sq::new(); |
| 327 |
let (cert, cert_path, _rev_path) |
| 328 |
= sq.key_generate::<&str>(&[], &[]); |
| 329 |
sq.key_import(&cert_path); |
| 330 |
let fp = cert.fingerprint().to_string(); |
| 331 |
|
| 332 |
// When listing by fingerprint, the certificate is considered |
| 333 |
// authenticated. |
| 334 |
let output = sq.cert_list(&[&fp]); |
| 335 |
assert!(std::str::from_utf8(&output).unwrap().contains(&fp)); |
| 336 |
|
| 337 |
let output = sq.cert_list(&["--gossip", &fp]); |
| 338 |
assert!(std::str::from_utf8(&output).unwrap().contains(&fp)); |
| 339 |
} |
| 340 |
|
| 341 |
#[test] |
| 342 |
fn list_all_no_userids() { |
| 343 |
// Check that `sq cert list` does not show certificates without |
| 344 |
// user IDs, but `sq cert list --gossip` does. |
| 345 |
let sq = Sq::new(); |
| 346 |
let (cert, cert_path, _rev_path) |
| 347 |
= sq.key_generate::<&str>(&[], &[]); |
| 348 |
sq.key_import(&cert_path); |
| 349 |
let fp = cert.fingerprint().to_string(); |
| 350 |
|
| 351 |
let output = sq.cert_list(&[]); |
| 352 |
assert!(! std::str::from_utf8(&output).unwrap().contains(&fp)); |
| 353 |
|
| 354 |
let output = sq.cert_list(&["--gossip"]); |
| 355 |
assert!(std::str::from_utf8(&output).unwrap().contains(&fp)); |
| 356 |
} |
| 357 |
|
| 358 |
/// Check that --cert FPR shows certificates that are otherwise |
| 359 |
/// unauthenticate. |
| 360 |
#[test] |
| 361 |
fn list_unauthenticated_cert() { |
| 362 |
let sq = Sq::new(); |
| 363 |
|
| 364 |
let email = "[email protected]"; |
| 365 |
let name = "Alice Lovelace"; |
| 366 |
let userid = &format!("{} <{}>", name, email); |
| 367 |
let (cert, cert_path, _rev_path) |
| 368 |
= sq.key_generate(&[], &[ userid ]); |
| 369 |
|
| 370 |
sq.key_import(&cert_path); |
| 371 |
|
| 372 |
// The certificate is unauthenticated so the following won't work: |
| 373 |
assert!(sq.cert_list_maybe(&[email]).is_err()); |
| 374 |
|
| 375 |
// If we use --cert FINGERPRINT or provide the fingerprint, it |
| 376 |
// will. |
| 377 |
sq.cert_list(&[&cert.fingerprint().to_string()]); |
| 378 |
sq.cert_list(&["--cert", &cert.fingerprint().to_string()]); |
| 379 |
|
| 380 |
// When we link it, the above will work. |
| 381 |
sq.pki_link_add(&[], cert.key_handle(), &[userid]); |
| 382 |
sq.cert_list(&[email]); |
| 383 |
sq.cert_list(&[&cert.fingerprint().to_string()]); |
| 384 |
sq.cert_list(&["--cert", &cert.fingerprint().to_string()]); |
| 385 |
} |
| 386 |
|
| 387 |
#[test] |
| 388 |
fn list_invalid_certs() { |
| 389 |
// Check that we can't list invalid certificates. |
| 390 |
// |
| 391 |
// Check: |
| 392 |
// |
| 393 |
// - a certificate that only uses SHA-1 |
| 394 |
// - a certificate that is revoked |
| 395 |
// - a certificate that is expired |
| 396 |
for path in [ |
| 397 |
"keys/only-sha1-priv.pgp", |
| 398 |
"keys/soft-revoked-cert.pgp", |
| 399 |
"keys/expired-cert.pgp", |
| 400 |
] { |
| 401 |
eprintln!("Checking {}", path); |
| 402 |
|
| 403 |
let sq = Sq::new(); |
| 404 |
|
| 405 |
let cert_file = artifact(path); |
| 406 |
let cert = Cert::from_file(&cert_file).expect("valid cert"); |
| 407 |
let fpr = &cert.fingerprint().to_string()[..]; |
| 408 |
let userids = cert.userids() |
| 409 |
.map(|ua| String::from_utf8_lossy(ua.userid().value())) |
| 410 |
.collect::<Vec<_>>(); |
| 411 |
|
| 412 |
sq.cert_import(&cert_file); |
| 413 |
|
| 414 |
assert!(sq.cert_list_maybe(&[fpr]).is_err()); |
| 415 |
assert!(sq.cert_list_maybe(&["--gossip", fpr]).is_err()); |
| 416 |
|
| 417 |
for userid in userids.iter() { |
| 418 |
assert!(sq.cert_list_maybe(&["--cert-userid", &userid[..]]).is_err()); |
| 419 |
assert!(sq.cert_list_maybe(&["--gossip", "--cert-userid", &userid[..]]) |
| 420 |
.is_err()); |
| 421 |
sq.cert_list(&["--gossip", "--unusable", |
| 422 |
"--cert-userid", &userid[..]]); |
| 423 |
} |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
#[test] |
| 428 |
fn list_sha1_userid() { |
| 429 |
// Check that we can list a user ID with --gossip even if it is |
| 430 |
// only bound by a self-signature that relies on SHA-1. |
| 431 |
let sq = Sq::new(); |
| 432 |
|
| 433 |
let cert_file = artifact("keys/sha1-userid-priv.pgp"); |
| 434 |
let cert = Cert::from_file(&cert_file).expect("valid cert"); |
| 435 |
let fpr = &cert.fingerprint().to_string()[..]; |
| 436 |
|
| 437 |
sq.cert_import(&cert_file); |
| 438 |
|
| 439 |
// Listing the certificate is okay. |
| 440 |
sq.cert_list(&[fpr]); |
| 441 |
sq.cert_list(&["--gossip", fpr]); |
| 442 |
|
| 443 |
let mut saw_invalid = false; |
| 444 |
|
| 445 |
for ua in cert.userids() { |
| 446 |
let userid = String::from_utf8_lossy(ua.userid().value()); |
| 447 |
|
| 448 |
if ua.with_policy(STANDARD_POLICY, None).is_err() { |
| 449 |
saw_invalid = true; |
| 450 |
} |
| 451 |
|
| 452 |
// Not linked, so should fail. |
| 453 |
assert!( |
| 454 |
sq.cert_list_maybe(&["--cert-userid", &userid[..]]).is_err()); |
| 455 |
// Using --gossip should succeed. |
| 456 |
sq.cert_list(&["--gossip", "--cert-userid", &userid[..]]); |
| 457 |
sq.cert_list(&["--gossip", "--unusable", "--cert-userid", &userid[..]]); |
| 458 |
} |
| 459 |
|
| 460 |
assert!(saw_invalid); |
| 461 |
|
| 462 |
// We now link all of the user IDs. Even though the |
| 463 |
// self-signature relies on SHA-1, the links don't so we'll be |
| 464 |
// able to authenticate the user IDs. |
| 465 |
for ua in cert.userids() { |
| 466 |
let userid = String::from_utf8_lossy(ua.userid().value()).to_string(); |
| 467 |
sq.pki_link_add(&[], cert.key_handle(), &[UserIDArg::AddUserID(&userid)]); |
| 468 |
|
| 469 |
assert!( |
| 470 |
sq.cert_list_maybe(&["--cert-userid", &userid[..]]).is_ok()); |
| 471 |
assert!( |
| 472 |
sq.cert_list_maybe(&["--gossip", "--cert-userid", &userid[..]]).is_ok()); |
| 473 |
sq.cert_list(&["--gossip", "--unusable", "--cert-userid", &userid[..]]); |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
#[test] |
| 478 |
fn list_revoked_userid() { |
| 479 |
// Check that we can't list a user ID that is revoked. |
| 480 |
let sq = Sq::new(); |
| 481 |
|
| 482 |
let cert_file = artifact("keys/retired-userid.pgp"); |
| 483 |
let cert = Cert::from_file(&cert_file).expect("valid cert"); |
| 484 |
let fpr = &cert.fingerprint().to_string()[..]; |
| 485 |
|
| 486 |
sq.cert_import(&cert_file); |
| 487 |
|
| 488 |
// Listing the certificate is okay. |
| 489 |
sq.cert_list(&[fpr]); |
| 490 |
sq.cert_list(&["--gossip", fpr]); |
| 491 |
|
| 492 |
let mut saw_revoked = false; |
| 493 |
|
| 494 |
for ua in cert.userids() { |
| 495 |
let userid = String::from_utf8_lossy(ua.userid().value()); |
| 496 |
|
| 497 |
let good = if let RevocationStatus::Revoked(_) |
| 498 |
= ua.revocation_status(STANDARD_POLICY, None) |
| 499 |
{ |
| 500 |
saw_revoked = true; |
| 501 |
false |
| 502 |
} else { |
| 503 |
true |
| 504 |
}; |
| 505 |
|
| 506 |
// Not linked, so should fail. |
| 507 |
assert!( |
| 508 |
sq.cert_list_maybe(&["--cert-userid", &userid[..]]).is_err()); |
| 509 |
// Using --gossip, so should succeed if the user ID is valid. |
| 510 |
assert_eq!( |
| 511 |
sq.cert_list_maybe(&["--gossip", "--cert-userid", &userid[..]]).is_ok(), |
| 512 |
good); |
| 513 |
// Using --gossip --unusable, so should always succeed. |
| 514 |
sq.cert_list(&["--gossip", "--unusable", "--cert-userid", &userid[..]]); |
| 515 |
} |
| 516 |
|
| 517 |
assert!(saw_revoked); |
| 518 |
} |