| 1 |
use crate::integration::common::CertArg; |
| 2 |
use crate::integration::common::Sq; |
| 3 |
use crate::integration::common::check_fingerprints; |
| 4 |
|
| 5 |
#[test] |
| 6 |
fn list() { |
| 7 |
let mut sq = Sq::new(); |
| 8 |
|
| 9 |
let alice_email = "[email protected]"; |
| 10 |
let alice_userid = &format!("Alice <{}>", alice_email); |
| 11 |
let (alice, alice_pgp, _alice_rev) |
| 12 |
= sq.key_generate(&[], &[ alice_userid ]); |
| 13 |
sq.key_import(&alice_pgp); |
| 14 |
|
| 15 |
let bob_email = "[email protected]"; |
| 16 |
let bob_userid = &format!("Bob <{}>", bob_email); |
| 17 |
let (bob, bob_pgp, _bob_rev) |
| 18 |
= sq.key_generate(&[], &[ bob_userid ]); |
| 19 |
sq.key_import(&bob_pgp); |
| 20 |
|
| 21 |
let carol_email = "[email protected]"; |
| 22 |
let carol_userid = &format!("Carol <{}>", carol_email); |
| 23 |
let (carol, carol_pgp, _carol_rev) |
| 24 |
= sq.key_generate(&[], &[ carol_userid ]); |
| 25 |
sq.key_import(&carol_pgp); |
| 26 |
|
| 27 |
// Alice hasn't certified anything. `sq pki vouch list` with no |
| 28 |
// filter should show nothing, but still return success. |
| 29 |
let output = sq.pki_vouch_list(&[], CertArg::from(&alice), None); |
| 30 |
check_fingerprints(&output, []); |
| 31 |
|
| 32 |
// Alice hasn't certified Bob, so this should return nothing. |
| 33 |
let output = sq.pki_vouch_list( |
| 34 |
&[], |
| 35 |
CertArg::from(&alice), |
| 36 |
CertArg::from(&bob)); |
| 37 |
check_fingerprints(&output, []); |
| 38 |
|
| 39 |
// No one has certified Bob, so this should return nothing. |
| 40 |
let output = sq.pki_vouch_list( |
| 41 |
&[], |
| 42 |
None, |
| 43 |
CertArg::from(&bob)); |
| 44 |
check_fingerprints(&output, []); |
| 45 |
|
| 46 |
sq.tick(10); |
| 47 |
|
| 48 |
// Alice certifies Bob (the certification expires in a day). |
| 49 |
|
| 50 |
sq.pki_vouch_add( |
| 51 |
&["--expiration", "1d"], |
| 52 |
&alice.key_handle(), &bob.key_handle(), &[bob_userid], |
| 53 |
None); |
| 54 |
|
| 55 |
// Now listing the certifications for Bob's certificate should |
| 56 |
// work. |
| 57 |
let output = sq.pki_vouch_list( |
| 58 |
&[], CertArg::from(&alice), |
| 59 |
CertArg::from(&bob)); |
| 60 |
check_fingerprints( |
| 61 |
&output, |
| 62 |
[ |
| 63 |
(alice.fingerprint(), 1), |
| 64 |
(bob.fingerprint(), 1), |
| 65 |
]); |
| 66 |
|
| 67 |
let output = sq.pki_vouch_list( |
| 68 |
&[], None, |
| 69 |
CertArg::from(&bob)); |
| 70 |
check_fingerprints( |
| 71 |
&output, |
| 72 |
[ |
| 73 |
(alice.fingerprint(), 1), |
| 74 |
(bob.fingerprint(), 1), |
| 75 |
]); |
| 76 |
|
| 77 |
// But not when we specify Carol. |
| 78 |
let output = sq.pki_vouch_list( |
| 79 |
&[], CertArg::from(&alice), |
| 80 |
CertArg::from(&carol)); |
| 81 |
check_fingerprints(&output, []); |
| 82 |
|
| 83 |
let output = sq.pki_vouch_list( |
| 84 |
&[], None, |
| 85 |
CertArg::from(&carol)); |
| 86 |
check_fingerprints(&output, []); |
| 87 |
|
| 88 |
// It will still list the certification after it has expired. |
| 89 |
let output = sq.pki_vouch_list( |
| 90 |
&["--time", "+2d"], |
| 91 |
CertArg::from(&alice), |
| 92 |
CertArg::from(&bob)); |
| 93 |
check_fingerprints( |
| 94 |
&output, |
| 95 |
[ |
| 96 |
(alice.fingerprint(), 1), |
| 97 |
(bob.fingerprint(), 1), |
| 98 |
]); |
| 99 |
|
| 100 |
// And it will list the certification even if the certification |
| 101 |
// was made in the future. |
| 102 |
sq.pki_vouch_list( |
| 103 |
&["--time", "-5s"], |
| 104 |
CertArg::from(&alice), |
| 105 |
CertArg::from(&bob)); |
| 106 |
check_fingerprints( |
| 107 |
&output, |
| 108 |
[ |
| 109 |
(alice.fingerprint(), 1), |
| 110 |
(bob.fingerprint(), 1), |
| 111 |
]); |
| 112 |
} |
| 113 |
|
| 114 |
#[test] |
| 115 |
fn list_multiple_certifications() { |
| 116 |
// Check that all certifications are shown. |
| 117 |
|
| 118 |
let mut sq = Sq::new(); |
| 119 |
|
| 120 |
let alice_email = "[email protected]"; |
| 121 |
let alice_userid = &format!("Alice <{}>", alice_email); |
| 122 |
let (alice, alice_pgp, _alice_rev) |
| 123 |
= sq.key_generate(&[], &[ alice_userid ]); |
| 124 |
sq.key_import(&alice_pgp); |
| 125 |
|
| 126 |
let bob_email = "[email protected]"; |
| 127 |
let bob_userid = &format!("Bob <{}>", bob_email); |
| 128 |
let (bob, bob_pgp, _bob_rev) |
| 129 |
= sq.key_generate(&[], &[ bob_userid ]); |
| 130 |
sq.key_import(&bob_pgp); |
| 131 |
|
| 132 |
let carol_email = "[email protected]"; |
| 133 |
let carol_userid = &format!("Carol <{}>", carol_email); |
| 134 |
let (carol, carol_pgp, _carol_rev) |
| 135 |
= sq.key_generate(&[], &[ carol_userid ]); |
| 136 |
sq.key_import(&carol_pgp); |
| 137 |
|
| 138 |
// No one has certified anything. `sq pki vouch list` should show |
| 139 |
// nothing, but still return success. |
| 140 |
let output = sq.pki_vouch_list(&[], CertArg::from(&alice), None); |
| 141 |
check_fingerprints(&output, []); |
| 142 |
|
| 143 |
let output = sq.pki_vouch_list(&[], CertArg::from(&bob), None); |
| 144 |
check_fingerprints(&output, []); |
| 145 |
|
| 146 |
let output = sq.pki_vouch_list(&[], CertArg::from(&carol), None); |
| 147 |
check_fingerprints(&output, []); |
| 148 |
|
| 149 |
let output = sq.pki_vouch_list(&[], None, CertArg::from(&alice)); |
| 150 |
check_fingerprints(&output, []); |
| 151 |
|
| 152 |
let output = sq.pki_vouch_list(&[], None, CertArg::from(&bob)); |
| 153 |
check_fingerprints(&output, []); |
| 154 |
|
| 155 |
let output = sq.pki_vouch_list(&[], None, CertArg::from(&carol)); |
| 156 |
check_fingerprints(&output, []); |
| 157 |
|
| 158 |
let output = sq.pki_vouch_list( |
| 159 |
&[], CertArg::from(&bob), CertArg::from(&alice)); |
| 160 |
check_fingerprints(&output, []); |
| 161 |
|
| 162 |
let output = sq.pki_vouch_list( |
| 163 |
&[], CertArg::from(&alice), CertArg::from(&bob)); |
| 164 |
check_fingerprints(&output, []); |
| 165 |
|
| 166 |
let output = sq.pki_vouch_list( |
| 167 |
&[], CertArg::from(&alice), CertArg::from(&carol)); |
| 168 |
check_fingerprints(&output, []); |
| 169 |
|
| 170 |
|
| 171 |
// Alice certifies Carol once. |
| 172 |
sq.tick(10); |
| 173 |
sq.pki_vouch_add( |
| 174 |
&[], |
| 175 |
&alice.key_handle(), &carol.key_handle(), &[carol_userid], |
| 176 |
None); |
| 177 |
|
| 178 |
// Bob certifies Carol twice. |
| 179 |
for _ in 0..2 { |
| 180 |
sq.tick(10); |
| 181 |
sq.pki_vouch_add( |
| 182 |
&[], |
| 183 |
&bob.key_handle(), &carol.key_handle(), &[carol_userid], |
| 184 |
None); |
| 185 |
} |
| 186 |
|
| 187 |
// Carol certifies Bob three times. |
| 188 |
for _ in 0..3 { |
| 189 |
sq.tick(10); |
| 190 |
sq.pki_vouch_add( |
| 191 |
&[], |
| 192 |
&carol.key_handle(), &bob.key_handle(), &[bob_userid], |
| 193 |
None); |
| 194 |
} |
| 195 |
|
| 196 |
// Now list the certifications. |
| 197 |
|
| 198 |
let output = sq.pki_vouch_list(&[], CertArg::from(&alice), None); |
| 199 |
check_fingerprints( |
| 200 |
&output, |
| 201 |
[ |
| 202 |
(alice.fingerprint(), 1), |
| 203 |
(bob.fingerprint(), 0), |
| 204 |
(carol.fingerprint(), 1), |
| 205 |
]); |
| 206 |
|
| 207 |
let output = sq.pki_vouch_list(&[], CertArg::from(&bob), None); |
| 208 |
check_fingerprints( |
| 209 |
&output, |
| 210 |
[ |
| 211 |
(alice.fingerprint(), 0), |
| 212 |
(bob.fingerprint(), 1), |
| 213 |
(carol.fingerprint(), 2), |
| 214 |
]); |
| 215 |
|
| 216 |
let output = sq.pki_vouch_list(&[], CertArg::from(&carol), None); |
| 217 |
check_fingerprints( |
| 218 |
&output, |
| 219 |
[ |
| 220 |
(alice.fingerprint(), 0), |
| 221 |
(bob.fingerprint(), 3), |
| 222 |
(carol.fingerprint(), 1), |
| 223 |
]); |
| 224 |
|
| 225 |
|
| 226 |
let output = sq.pki_vouch_list(&[], None, CertArg::from(&alice)); |
| 227 |
check_fingerprints( |
| 228 |
&output, |
| 229 |
[ |
| 230 |
(alice.fingerprint(), 0), |
| 231 |
(bob.fingerprint(), 0), |
| 232 |
(carol.fingerprint(), 0), |
| 233 |
]); |
| 234 |
|
| 235 |
|
| 236 |
let output = sq.pki_vouch_list(&[], None, CertArg::from(&bob)); |
| 237 |
check_fingerprints( |
| 238 |
&output, |
| 239 |
[ |
| 240 |
(alice.fingerprint(), 0), |
| 241 |
(bob.fingerprint(), 3), |
| 242 |
(carol.fingerprint(), 1), |
| 243 |
]); |
| 244 |
|
| 245 |
|
| 246 |
let output = sq.pki_vouch_list(&[], None, CertArg::from(&carol)); |
| 247 |
check_fingerprints( |
| 248 |
&output, |
| 249 |
[ |
| 250 |
(alice.fingerprint(), 1), |
| 251 |
(bob.fingerprint(), 1), |
| 252 |
(carol.fingerprint(), 3), |
| 253 |
]); |
| 254 |
|
| 255 |
|
| 256 |
let output = sq.pki_vouch_list( |
| 257 |
&[], CertArg::from(&bob), CertArg::from(&alice)); |
| 258 |
check_fingerprints( |
| 259 |
&output, |
| 260 |
[ |
| 261 |
(alice.fingerprint(), 0), |
| 262 |
(bob.fingerprint(), 0), |
| 263 |
(carol.fingerprint(), 0), |
| 264 |
]); |
| 265 |
|
| 266 |
|
| 267 |
let output = sq.pki_vouch_list( |
| 268 |
&[], CertArg::from(&alice), CertArg::from(&bob)); |
| 269 |
check_fingerprints( |
| 270 |
&output, |
| 271 |
[ |
| 272 |
(alice.fingerprint(), 0), |
| 273 |
(bob.fingerprint(), 0), |
| 274 |
(carol.fingerprint(), 0), |
| 275 |
]); |
| 276 |
|
| 277 |
|
| 278 |
let output = sq.pki_vouch_list( |
| 279 |
&[], CertArg::from(&alice), CertArg::from(&carol)); |
| 280 |
check_fingerprints( |
| 281 |
&output, |
| 282 |
[ |
| 283 |
(alice.fingerprint(), 1), |
| 284 |
(bob.fingerprint(), 0), |
| 285 |
(carol.fingerprint(), 1), |
| 286 |
]); |
| 287 |
|
| 288 |
|
| 289 |
let output = sq.pki_vouch_list( |
| 290 |
&[], CertArg::from(&bob), CertArg::from(&carol)); |
| 291 |
check_fingerprints( |
| 292 |
&output, |
| 293 |
[ |
| 294 |
(alice.fingerprint(), 0), |
| 295 |
(bob.fingerprint(), 1), |
| 296 |
(carol.fingerprint(), 2), |
| 297 |
]); |
| 298 |
|
| 299 |
|
| 300 |
let output = sq.pki_vouch_list( |
| 301 |
&[], CertArg::from(&carol), CertArg::from(&bob)); |
| 302 |
check_fingerprints( |
| 303 |
&output, |
| 304 |
[ |
| 305 |
(alice.fingerprint(), 0), |
| 306 |
(bob.fingerprint(), 3), |
| 307 |
(carol.fingerprint(), 1), |
| 308 |
]); |
| 309 |
} |
| 310 |
|
| 311 |
#[test] |
| 312 |
fn list_with_unauthenticated_handle() { |
| 313 |
// Make sure it isn't possible to use --cert-email, etc. with an |
| 314 |
// unauthenticated handle. |
| 315 |
let sq = Sq::new(); |
| 316 |
|
| 317 |
let alice_name = "Alice Lovelace"; |
| 318 |
let alice_domain = "example.org"; |
| 319 |
let alice_email = &format!("alice@{}", alice_domain); |
| 320 |
let alice_userid = &format!("{} <{}>", alice_name, alice_email); |
| 321 |
|
| 322 |
let (alice_cert, alice_cert_path, _rev_path) |
| 323 |
= sq.key_generate(&[], &[ alice_userid, ]); |
| 324 |
|
| 325 |
sq.key_import(&alice_cert_path); |
| 326 |
|
| 327 |
let bob_name = "Bob Lovelace"; |
| 328 |
let bob_domain = "example.org"; |
| 329 |
let bob_email = &format!("bob@{}", bob_domain); |
| 330 |
let bob_userid = &format!("{} <{}>", bob_name, bob_email); |
| 331 |
|
| 332 |
let (bob_cert, bob_cert_path, _rev_path) |
| 333 |
= sq.key_generate(&[], &[ bob_userid, ]); |
| 334 |
|
| 335 |
sq.key_import(&bob_cert_path); |
| 336 |
|
| 337 |
sq.pki_vouch_add( |
| 338 |
&["--expiration", "1d"], |
| 339 |
&alice_cert.key_handle(), bob_cert.key_handle(), &[bob_userid], |
| 340 |
None); |
| 341 |
|
| 342 |
// We need to link a user ID otherwise sq pki vouch list will |
| 343 |
// refuse to list the certificate. |
| 344 |
sq.pki_link_add( |
| 345 |
&["--amount", "40"], alice_cert.key_handle(), &[ alice_userid ]); |
| 346 |
|
| 347 |
for linked in [false, true] { |
| 348 |
if linked { |
| 349 |
// The second time through we link the certificates and |
| 350 |
// make sure the certificate designator actually work. |
| 351 |
sq.pki_link_add( |
| 352 |
&[], alice_cert.key_handle(), &[ alice_userid ]); |
| 353 |
sq.pki_link_add( |
| 354 |
&[], bob_cert.key_handle(), &[ bob_userid ]); |
| 355 |
} |
| 356 |
|
| 357 |
|
| 358 |
sq.pki_vouch_list(&[], CertArg::from(&alice_cert), None); |
| 359 |
assert_eq!(sq.try_pki_vouch_list(&[], |
| 360 |
CertArg::UserID(alice_userid), |
| 361 |
None).is_ok(), |
| 362 |
linked); |
| 363 |
assert_eq!(sq.try_pki_vouch_list(&[], |
| 364 |
CertArg::Email(alice_email), |
| 365 |
None).is_ok(), |
| 366 |
linked); |
| 367 |
|
| 368 |
sq.pki_vouch_list(&[], |
| 369 |
CertArg::from(&alice_cert), |
| 370 |
CertArg::from(&bob_cert)); |
| 371 |
assert_eq!(sq.try_pki_vouch_list(&[], |
| 372 |
CertArg::from(&alice_cert), |
| 373 |
CertArg::UserID(bob_userid)).is_ok(), |
| 374 |
linked); |
| 375 |
assert_eq!(sq.try_pki_vouch_list(&[], |
| 376 |
CertArg::from(&alice_cert), |
| 377 |
CertArg::Email(bob_email)).is_ok(), |
| 378 |
linked); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
#[test] |
| 383 |
fn list_missing_certifier() { |
| 384 |
// Alice certifies Bob's certificate. The certificate store only |
| 385 |
// contains Bob's certificate. We should still list Alice's |
| 386 |
// certification, even though we can't verify it. |
| 387 |
|
| 388 |
let sq = Sq::new(); |
| 389 |
|
| 390 |
let alice_email = "[email protected]"; |
| 391 |
let alice_userid = &format!("Alice <{}>", alice_email); |
| 392 |
let (alice, alice_pgp, _alice_rev) |
| 393 |
= sq.key_generate(&[], &[ alice_userid ]); |
| 394 |
// We explicitly DO not import Alice's certificate. |
| 395 |
// sq.key_import(&alice_pgp); |
| 396 |
|
| 397 |
let bob_email = "[email protected]"; |
| 398 |
let bob_userid = &format!("Bob <{}>", bob_email); |
| 399 |
let (bob, bob_pgp, _bob_rev) |
| 400 |
= sq.key_generate(&[], &[ bob_userid ]); |
| 401 |
sq.key_import(&bob_pgp); |
| 402 |
|
| 403 |
sq.pki_vouch_add( |
| 404 |
&[], |
| 405 |
&alice_pgp, &bob.key_handle(), &[bob_userid], |
| 406 |
None); |
| 407 |
|
| 408 |
let output = sq.pki_vouch_list( |
| 409 |
&[], None, |
| 410 |
CertArg::from(&bob)); |
| 411 |
check_fingerprints( |
| 412 |
&output, |
| 413 |
[ |
| 414 |
(alice.fingerprint(), 1), |
| 415 |
(bob.fingerprint(), 1), |
| 416 |
]); |
| 417 |
assert!(output.contains("unknown: missing certificate")); |
| 418 |
} |