Debian Codegraph @

tests/integration/sq_pki.rs

raw
1 use std::collections::HashMap;
2 use std::fmt::{Display, Formatter};
3 use std::fmt::Result as FMTResult;
4 use std::path;
5 use std::time;
6
7 use regex::bytes::Regex;
8
9 use sequoia_openpgp as openpgp;
10
11 use openpgp::Fingerprint;
12 use openpgp::Result;
13 use openpgp::packet::UserID;
14
15 use super::common::Sq;
16 use super::common::UserIDArg;
17
18 const HR_OK: &'static str = "[ ✓ ]";
19 const HR_NOT_OK: &'static str = "[ 0/120 ]";
20 const HR_NOT_OK_EMPTY: &'static str = "[ ]";
21 const HR_PATH: &'static str = "◯ ";
22
23 fn no_output() -> &'static HashMap::<OutputFormat, Vec<(usize, Regex)>> {
24 use std::sync::OnceLock;
25 static NO_OUTPUT: OnceLock<HashMap::<OutputFormat, Vec<(usize, Regex)>>>
26 = OnceLock::new();
27 NO_OUTPUT.get_or_init(|| Default::default())
28 }
29
30 /// Supported output types
31 ///
32 /// These need to be synced with the ones in src/cli.rs
33 #[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
34 enum OutputFormat {
35 /// output in human readable format
36 HumanReadable,
37 }
38
39 impl OutputFormat {
40 pub fn iterator() -> impl Iterator<Item = &'static OutputFormat> {
41 static FORMATS: [OutputFormat; 1] =
42 [OutputFormat::HumanReadable];
43 FORMATS.iter()
44 }
45 }
46
47 impl Display for OutputFormat {
48 fn fmt(&self, f: &mut Formatter) -> FMTResult {
49 write!(
50 f,
51 "{}",
52 match self {
53 OutputFormat::HumanReadable => "human-readable",
54 }
55 )
56 }
57 }
58
59 fn dir() -> path::PathBuf {
60 path::Path::new("tests").join("data").join("keyrings")
61 }
62
63 fn regexify(needle: &str) -> Regex {
64 Regex::new(
65 &regex::escape(needle).replace(char::is_whitespace, "[\\s\\n─┬│└]*"))
66 .unwrap()
67 }
68
69 /// Create a HashMap, containing per OutputFormat lists of occurrences
70 /// of strings
71 fn output_map<S>(
72 human: &[(usize, S)],
73 ) -> HashMap<OutputFormat, Vec<(usize, Regex)>>
74 where S: AsRef<str>,
75 {
76 let mut output = HashMap::<OutputFormat, Vec<(usize, Regex)>>::new();
77 output.insert(OutputFormat::HumanReadable,
78 human.iter().map(|(c, n)| (*c, regexify(n.as_ref()))).collect());
79 output
80 }
81
82 fn test<'a, R, U>(
83 keyring: &str,
84 trust_root: R,
85 sqwot_args: &[&str],
86 command: &str,
87 args: &[&str],
88 amount: usize,
89 userid: U,
90 target: Option<&Fingerprint>,
91 success: bool,
92 output: &HashMap<OutputFormat, Vec<(usize, Regex)>>,
93 ) -> Result<()>
94 where
95 R: Into<Option<&'a Fingerprint>>,
96 U: Into<Option<&'a UserIDArg<'a>>>,
97 {
98 let sq = Sq::new();
99 let trust_root = trust_root.into();
100 let userid = userid.into();
101
102 for outputformat in OutputFormat::iterator() {
103 let mut cmd = sq.command();
104 cmd.current_dir(&dir())
105 .args(&["--keyring", keyring]);
106 if let Some(trust_root) = trust_root {
107 cmd.args(&["--trust-root", &trust_root.to_string()]);
108 }
109 cmd
110 .arg(if command == "list" { "cert" } else { "pki" })
111 .arg(command)
112 .args(sqwot_args);
113 // We test the verbose output. Enable it (when appropriate).
114 if ["authenticate", "lookup", "identify", "list"].contains(&command) {
115 cmd.arg("--show-paths");
116 }
117 if let Some(target) = target {
118 if ["authenticate", "identify"].contains(&command) {
119 cmd.arg("--cert");
120 }
121 cmd.arg(&target.to_string());
122 }
123 if let Some(userid) = userid {
124 if command == "list" {
125 userid.as_cert_designator(&mut cmd);
126 } else {
127 userid.as_arg(&mut cmd);
128 }
129 }
130 for arg in args {
131 cmd.arg(arg);
132 }
133 cmd.args(&["--amount", &format!("{}", amount)]);
134
135 eprintln!("Running: {}",
136 std::iter::once(cmd.get_program())
137 .chain(cmd.get_args())
138 .map(|arg| {
139 let arg = arg.to_string_lossy();
140 if arg.contains(" ") {
141 format!("{:?}", arg)
142 } else {
143 arg.into_owned()
144 }
145 })
146 .collect::<Vec<_>>()
147 .join(" "));
148
149 if success {
150 let assertion = cmd.assert();
151 let assertion = assertion.success();
152
153 if let Some(output) = output.get(outputformat) {
154 for (expected_occurrences, s) in output {
155 let haystack = &assertion.get_output().stdout;
156 let occurrences =
157 s.find_iter(haystack.as_ref()).count();
158
159 assert_eq!(
160 occurrences, *expected_occurrences,
161 "Failed to find: '{}' {} times \
162 in output:\n\n\
163 {}",
164 s, expected_occurrences,
165 String::from_utf8_lossy(haystack),
166 );
167 }
168 }
169 } else {
170 let assertion = cmd.assert();
171 let assertion = assertion.failure();
172
173 if let Some(output) = output.get(outputformat) {
174 for (expected_occurrences, s) in output {
175 let haystack = &assertion.get_output().stdout;
176 let occurrences =
177 s.find_iter(haystack.as_ref()).count();
178
179 assert_eq!(
180 occurrences, *expected_occurrences,
181 "Failed to find: '{}' {} times \
182 in output:\n\n\
183 {}",
184 s, expected_occurrences,
185 String::from_utf8_lossy(haystack),
186 );
187 }
188 }
189 // TODO: check stderr?
190 }
191 }
192
193 Ok(())
194 }
195
196 // Test authenticating a binding (User ID and certificate).
197 #[test]
198 #[allow(unused)]
199 fn authenticate() -> Result<()> {
200 let alice_fpr: Fingerprint =
201 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
202 .parse().expect("valid fingerprint");
203 let alice_uid
204 = UserIDArg::UserID("<[email protected]>");
205
206 let dave_fpr: Fingerprint =
207 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
208 .parse().expect("valid fingerprint");
209 let dave_uid
210 = UserIDArg::UserID("<[email protected]>");
211
212 let ellen_fpr: Fingerprint =
213 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
214 .parse().expect("valid fingerprint");
215 let ellen_uid
216 = UserIDArg::UserID("<[email protected]>");
217 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
218
219 // defaults
220 let keyring = "simple.pgp";
221 let trust_root = &alice_fpr;
222 let sqwot_args = &[];
223 let command = "authenticate";
224 let args = &[];
225
226 let human_output =
227 [(1, format!("- {} {}", HR_OK, &dave_uid))];
228 test(
229 keyring,
230 trust_root,
231 sqwot_args,
232 command,
233 args,
234 100,
235 Some(&dave_uid),
236 Some(&dave_fpr),
237 true,
238 &output_map(&human_output),
239 );
240 test(
241 keyring,
242 trust_root,
243 sqwot_args,
244 command,
245 args,
246 120,
247 Some(&dave_uid),
248 Some(&dave_fpr),
249 false,
250 no_output(),
251 );
252
253 // Not enough depth.
254 test(
255 keyring,
256 trust_root,
257 sqwot_args,
258 command,
259 args,
260 100,
261 Some(&ellen_uid),
262 Some(&ellen_fpr),
263 false,
264 no_output(),
265 );
266 test(
267 keyring,
268 trust_root,
269 sqwot_args,
270 command,
271 args,
272 120,
273 Some(&ellen_uid),
274 Some(&ellen_fpr),
275 false,
276 no_output(),
277 );
278
279 // No such User ID on dave's key.
280 test(
281 keyring,
282 trust_root,
283 sqwot_args,
284 command,
285 args,
286 100,
287 Some(&ellen_uid),
288 Some(&dave_fpr),
289 false,
290 no_output(),
291 );
292 test(
293 keyring,
294 trust_root,
295 sqwot_args,
296 command,
297 args,
298 120,
299 Some(&ellen_uid),
300 Some(&dave_fpr),
301 false,
302 no_output(),
303 );
304
305 Ok(())
306 }
307
308 // Test authenticating bindings where we match on just the email
309 // address, not the whole User ID.
310 #[test]
311 #[allow(unused)]
312 fn authenticate_email() -> Result<()> {
313 let alice_fpr: Fingerprint =
314 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
315 .parse().expect("valid fingerprint");
316 // Yes, UserIDArg::Email, not UserIDArg::UserID. We're testing
317 // what --email matches!
318 let alice_uid
319 = UserIDArg::Email("<[email protected]>");
320
321 let dave_fpr: Fingerprint =
322 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
323 .parse().expect("valid fingerprint");
324 // Yes, UserIDArg::Email, not UserIDArg::UserID.
325 let dave_uid
326 = UserIDArg::Email("<[email protected]>");
327 let dave_email = UserIDArg::Email("[email protected]");
328 let dave_email_uc1 = UserIDArg::Email("[email protected]");
329 let dave_email_uc2 = UserIDArg::Email("[email protected]");
330
331 let ellen_fpr: Fingerprint =
332 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
333 .parse().expect("valid fingerprint");
334 // Yes, UserIDArg::Email, not UserIDArg::UserID.
335 let ellen_uid
336 = UserIDArg::Email("<[email protected]>");
337 let ellen_email = UserIDArg::Email("[email protected]");
338 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
339
340 // defaults
341 let keyring = "simple.pgp";
342 let trust_root = &alice_fpr;
343 let sqwot_args = &[];
344 let command = "authenticate";
345 let args = &[];
346
347 test(
348 keyring,
349 trust_root,
350 sqwot_args,
351 command,
352 args,
353 100,
354 Some(&dave_uid),
355 Some(&dave_fpr),
356 false,
357 no_output(),
358 );
359
360 let human_output =
361 [(1, format!("- {} {}", HR_OK, &dave_uid))];
362 test(
363 keyring,
364 trust_root,
365 sqwot_args,
366 command,
367 args,
368 100,
369 Some(&dave_email),
370 Some(&dave_fpr),
371 true,
372 &output_map(&human_output),
373 );
374 test(
375 keyring,
376 trust_root,
377 sqwot_args,
378 command,
379 args,
380 120,
381 Some(&dave_uid),
382 Some(&dave_fpr),
383 false,
384 no_output(),
385 );
386 test(
387 keyring,
388 trust_root,
389 sqwot_args,
390 command,
391 args,
392 120,
393 Some(&dave_email),
394 Some(&dave_fpr),
395 false,
396 no_output(),
397 );
398
399 // Not enough depth.
400 test(
401 keyring,
402 trust_root,
403 sqwot_args,
404 command,
405 args,
406 100,
407 Some(&ellen_uid),
408 Some(&ellen_fpr),
409 false,
410 no_output(),
411 );
412 test(
413 keyring,
414 trust_root,
415 sqwot_args,
416 command,
417 args,
418 100,
419 Some(&ellen_email),
420 Some(&ellen_fpr),
421 false,
422 no_output(),
423 );
424 test(
425 keyring,
426 trust_root,
427 sqwot_args,
428 command,
429 args,
430 120,
431 Some(&ellen_uid),
432 Some(&ellen_fpr),
433 false,
434 no_output(),
435 );
436 test(
437 keyring,
438 trust_root,
439 sqwot_args,
440 command,
441 args,
442 120,
443 Some(&ellen_email),
444 Some(&ellen_fpr),
445 false,
446 no_output(),
447 );
448
449 // No such User ID on dave's key.
450 test(
451 keyring,
452 trust_root,
453 sqwot_args,
454 command,
455 args,
456 100,
457 Some(&ellen_uid),
458 Some(&dave_fpr),
459 false,
460 no_output(),
461 );
462 test(
463 keyring,
464 trust_root,
465 sqwot_args,
466 command,
467 args,
468 100,
469 Some(&ellen_email),
470 Some(&dave_fpr),
471 false,
472 no_output(),
473 );
474 test(
475 keyring,
476 trust_root,
477 sqwot_args,
478 command,
479 args,
480 120,
481 Some(&ellen_uid),
482 Some(&dave_fpr),
483 false,
484 no_output(),
485 );
486 test(
487 keyring,
488 trust_root,
489 sqwot_args,
490 command,
491 args,
492 120,
493 Some(&ellen_email),
494 Some(&dave_fpr),
495 false,
496 no_output(),
497 );
498
499 // Normalized.
500 test(
501 keyring,
502 trust_root,
503 sqwot_args,
504 command,
505 args,
506 100,
507 Some(&dave_email_uc1),
508 Some(&dave_fpr),
509 true,
510 &output_map(&human_output),
511 );
512 test(
513 keyring,
514 trust_root,
515 sqwot_args,
516 command,
517 args,
518 100,
519 Some(&dave_email_uc2),
520 Some(&dave_fpr),
521 true,
522 &output_map(&human_output),
523 );
524
525 // Puny code and case normalization.
526 let alice_fpr: Fingerprint =
527 "B8DA8B318149B1C8C0CBD1ECB1CEC6D3CD00E69D"
528 .parse().expect("valid fingerprint");
529 let alice_uid
530 = UserIDArg::UserID("<[email protected]>");
531 let alice_email
532 = UserIDArg::Email("[email protected]");
533
534 let hans_fpr: Fingerprint =
535 "74767C4F2B15F57F3394FCA99DE867E6CA6A2756"
536 .parse().expect("valid fingerprint");
537 let hans_uid
538 = UserIDArg::UserID("<hÄNS@bücher.tld>");
539 // Certified by: B8DA8B318149B1C8C0CBD1ECB1CEC6D3CD00E69D
540
541 let hans_email
542 = UserIDArg::Email("hÄNS@bücher.tld");
543 let hans_email_lowercase
544 = UserIDArg::Email("häns@bücher.tld");
545 let hans_email_punycode
546 = UserIDArg::Email("hÄ[email protected]");
547 let hans_email_punycode_lowercase
548 = UserIDArg::Email("hä[email protected]");
549
550 let carol_fpr: Fingerprint =
551 "7432C123761B94EC50D50CF6562B9ADEE7F789F6"
552 .parse().expect("valid fingerprint");
553 let carol_uid
554 = UserIDArg::UserID("<[email protected]>");
555 // Certified by: 74767C4F2B15F57F3394FCA99DE867E6CA6A2756
556
557 let carol_email
558 = UserIDArg::Email("[email protected]");
559
560 // defaults
561 let keyring = "puny-code.pgp";
562 let trust_root = &alice_fpr;
563 let sqwot_args = &[];
564 let command = "authenticate";
565 let args = &[];
566
567 let human_output =
568 [(1, format!("- {} {}", HR_OK, &alice_uid))];
569 test(
570 keyring,
571 trust_root,
572 sqwot_args,
573 command,
574 args,
575 120,
576 Some(&alice_email),
577 Some(&alice_fpr),
578 true,
579 &output_map(&human_output),
580 );
581
582 let human_output =
583 [(1, format!("- {} {}", HR_OK, &hans_uid))];
584 test(
585 keyring,
586 trust_root,
587 sqwot_args,
588 command,
589 args,
590 100,
591 Some(&hans_email),
592 Some(&hans_fpr),
593 true,
594 &output_map(&human_output),
595 );
596
597 test(
598 keyring,
599 trust_root,
600 sqwot_args,
601 command,
602 args,
603 100,
604 Some(&hans_email_lowercase),
605 Some(&hans_fpr),
606 true,
607 &output_map(&human_output),
608 );
609
610 test(
611 keyring,
612 trust_root,
613 sqwot_args,
614 command,
615 args,
616 100,
617 Some(&hans_email_punycode),
618 Some(&hans_fpr),
619 true,
620 &output_map(&human_output),
621 );
622 test(
623 keyring,
624 trust_root,
625 sqwot_args,
626 command,
627 args,
628 100,
629 Some(&hans_email_punycode_lowercase),
630 Some(&hans_fpr),
631 true,
632 &output_map(&human_output),
633 );
634
635 let human_output =
636 [(1, format!("- {} {}", HR_OK, &carol_uid))];
637 test(
638 keyring,
639 trust_root,
640 sqwot_args,
641 command,
642 args,
643 100,
644 Some(&carol_email),
645 Some(&carol_fpr),
646 true,
647 &output_map(&human_output),
648 );
649
650 Ok(())
651 }
652
653 // Test looking up a certificate by User ID.
654 #[test]
655 #[allow(unused)]
656 fn lookup() -> Result<()> {
657 let alice_fpr: Fingerprint =
658 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
659 .parse().expect("valid fingerprint");
660 let alice_uid = UserIDArg::UserID("<[email protected]>");
661 let alice_uid_uppercase = UserIDArg::UserID("<[email protected]>");
662 let alice_uid_uppercase2 = UserIDArg::UserID("<[email protected]>");
663
664 let dave_fpr: Fingerprint =
665 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
666 .parse().expect("valid fingerprint");
667 let dave_uid = UserIDArg::UserID("<[email protected]>");
668 let dave_uid_uppercase = UserIDArg::UserID("<[email protected]>");
669 let dave_uid_uppercase2 = UserIDArg::UserID("<[email protected]>");
670
671 let ellen_fpr: Fingerprint =
672 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
673 .parse().expect("valid fingerprint");
674 let ellen_uid
675 = UserIDArg::UserID("<[email protected]>");
676 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
677
678 // defaults
679 let keyring = "simple.pgp";
680 let trust_root = &alice_fpr;
681 let sqwot_args = &[];
682 let command = "lookup";
683 let args = &[];
684
685 let human_output =
686 [(1, format!("- {} {}", HR_OK, &alice_uid))];
687 test(
688 keyring,
689 trust_root,
690 sqwot_args,
691 command,
692 args,
693 100,
694 Some(&alice_uid),
695 None,
696 true,
697 &output_map(&human_output),
698 );
699 test(
700 keyring,
701 trust_root,
702 sqwot_args,
703 command,
704 args,
705 120,
706 Some(&alice_uid),
707 None,
708 true,
709 &output_map(&human_output),
710 );
711
712 let human_output = [
713 (1, format!("- {} {}", HR_OK, &dave_uid)),
714 (1, format!("{}{} ({})", HR_PATH, &alice_fpr, &alice_uid)),
715 ];
716 test(
717 keyring,
718 trust_root,
719 sqwot_args,
720 command,
721 args,
722 100,
723 Some(&dave_uid),
724 None,
725 true,
726 &output_map(&human_output),
727 );
728 test(
729 keyring,
730 trust_root,
731 sqwot_args,
732 command,
733 args,
734 120,
735 Some(&dave_uid),
736 None,
737 false,
738 no_output(),
739 );
740
741 // Not enough depth.
742 test(
743 keyring,
744 trust_root,
745 sqwot_args,
746 command,
747 args,
748 100,
749 Some(&ellen_uid),
750 None,
751 false,
752 no_output(),
753 );
754 test(
755 keyring,
756 trust_root,
757 sqwot_args,
758 command,
759 args,
760 120,
761 Some(&ellen_uid),
762 None,
763 false,
764 no_output(),
765 );
766
767 // No such User ID.
768 test(
769 keyring,
770 trust_root,
771 sqwot_args,
772 command,
773 args,
774 100,
775 &UserIDArg::UserID("Gary <[email protected]>"),
776 None,
777 false,
778 no_output(),
779 );
780
781 // We need an exact match.
782 test(
783 keyring,
784 trust_root,
785 sqwot_args,
786 command,
787 args,
788 100,
789 Some(&alice_uid_uppercase),
790 None,
791 false,
792 no_output(),
793 );
794 test(
795 keyring,
796 trust_root,
797 sqwot_args,
798 command,
799 args,
800 100,
801 Some(&alice_uid_uppercase2),
802 None,
803 false,
804 no_output(),
805 );
806 test(
807 keyring,
808 trust_root,
809 sqwot_args,
810 command,
811 args,
812 100,
813 Some(&dave_uid_uppercase),
814 None,
815 false,
816 no_output(),
817 );
818 test(
819 keyring,
820 trust_root,
821 sqwot_args,
822 command,
823 args,
824 100,
825 Some(&dave_uid_uppercase2),
826 None,
827 false,
828 no_output(),
829 );
830
831 Ok(())
832 }
833
834 // Test looking up a certificate by email address.
835 #[test]
836 #[allow(unused)]
837 fn lookup_email() -> Result<()> {
838 let alice_fpr: Fingerprint =
839 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
840 .parse().expect("valid fingerprint");
841 let alice_uid = UserIDArg::UserID("<[email protected]>");
842 let alice_email = UserIDArg::Email("[email protected]");
843
844 let dave_fpr: Fingerprint =
845 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
846 .parse().expect("valid fingerprint");
847 let dave_uid = UserIDArg::UserID("<[email protected]>");
848 let dave_email = UserIDArg::Email("[email protected]");
849
850 let ellen_fpr: Fingerprint =
851 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
852 .parse().expect("valid fingerprint");
853 let ellen_uid
854 = UserIDArg::UserID("<[email protected]>");
855 let ellen_email = UserIDArg::Email("[email protected]");
856 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
857
858 // defaults for test() call
859 let keyring = "simple.pgp";
860 let trust_root = &alice_fpr;
861 let sqwot_args = [];
862 let command = "lookup";
863 let args = [];
864 let target = None;
865
866 let human_output =
867 [(1, format!("- {} {}", HR_OK, &alice_uid))];
868 test(
869 keyring,
870 trust_root,
871 &sqwot_args,
872 command,
873 &args,
874 100,
875 Some(&alice_email),
876 target,
877 true,
878 &output_map(&human_output),
879 );
880 test(
881 keyring,
882 trust_root,
883 &sqwot_args,
884 command,
885 &args,
886 120,
887 &alice_email,
888 target,
889 true,
890 &output_map(&human_output),
891 );
892
893 let human_output =
894 [(1, format!("- {} {}", HR_OK, dave_uid))];
895 test(
896 keyring,
897 trust_root,
898 &sqwot_args,
899 command,
900 &args,
901 100,
902 &dave_email,
903 target,
904 true,
905 &output_map(&human_output),
906 );
907 test(
908 keyring,
909 trust_root,
910 &sqwot_args,
911 command,
912 &args,
913 120,
914 &dave_email,
915 target,
916 false,
917 no_output(),
918 );
919
920 // Not enough depth.
921 test(
922 keyring,
923 trust_root,
924 &sqwot_args,
925 command,
926 &args,
927 100,
928 &ellen_email,
929 target,
930 false,
931 no_output(),
932 );
933 test(
934 keyring,
935 trust_root,
936 &sqwot_args,
937 command,
938 &args,
939 120,
940 &ellen_email,
941 target,
942 false,
943 no_output(),
944 );
945
946 // No such User ID.
947 test(
948 keyring,
949 trust_root,
950 &sqwot_args,
951 command,
952 &args,
953 100,
954 &UserIDArg::Email("[email protected]"),
955 target,
956 false,
957 no_output(),
958 );
959
960 Ok(())
961 }
962
963 // Test identifying a certificate.
964 #[test]
965 #[allow(unused)]
966 fn identify() -> Result<()> {
967 let alice_fpr: Fingerprint =
968 "2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA"
969 .parse().expect("valid fingerprint");
970 let alice_uid
971 = UserID::from("<[email protected]>");
972
973 let bob_fpr: Fingerprint =
974 "03182611B91B1E7E20B848E83DFC151ABFAD85D5"
975 .parse().expect("valid fingerprint");
976 let bob_uid
977 = UserID::from("<[email protected]>");
978 // Certified by: 2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA
979 let bob_some_org_uid
980 = UserID::from("<[email protected]>");
981 // Certified by: 2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA
982
983 let carol_fpr: Fingerprint =
984 "9CA36907B46FE7B6B9EE9601E78064C12B6D7902"
985 .parse().expect("valid fingerprint");
986 let carol_uid
987 = UserID::from("<[email protected]>");
988 // Certified by: 03182611B91B1E7E20B848E83DFC151ABFAD85D5
989
990 let dave_fpr: Fingerprint =
991 "C1BC6794A6C6281B968A6A41ACE2055D610CEA03"
992 .parse().expect("valid fingerprint");
993 let dave_uid
994 = UserID::from("<[email protected]>");
995 // Certified by: 9CA36907B46FE7B6B9EE9601E78064C12B6D7902
996
997 // defaults for test() call
998 let keyring = "multiple-userids-1.pgp";
999 let trust_root = &alice_fpr;
1000 let sqwot_args = &[];
1001 let command = "identify";
1002 let args = &[];
1003 let userid = None;
1004
1005 let userids = &[&alice_uid];
1006 let human_output = userids
1007 .iter()
1008 .map(|userid| {
1009 (
1010 1,
1011 format!("- {} {}", HR_OK, userid)
1012 .to_string(),
1013 )
1014 })
1015 .chain(vec![(userids.len(), HR_OK.to_string())].into_iter())
1016 .collect::<Vec<_>>();
1017 test(
1018 keyring,
1019 trust_root,
1020 sqwot_args,
1021 command,
1022 args,
1023 100,
1024 userid,
1025 Some(&alice_fpr),
1026 true,
1027 &output_map(&human_output),
1028 );
1029 test(
1030 keyring,
1031 trust_root,
1032 sqwot_args,
1033 command,
1034 args,
1035 120,
1036 userid,
1037 Some(&alice_fpr),
1038 true,
1039 &output_map(&human_output),
1040 );
1041
1042 let userids = &[&dave_uid];
1043 let human_output = userids
1044 .iter()
1045 .map(|userid| {
1046 (
1047 1,
1048 format!("- {} {}", HR_OK, userid).to_string(),
1049 )
1050 })
1051 .chain(vec![(userids.len(), HR_OK.to_string())].into_iter())
1052 .collect::<Vec<_>>();
1053 test(
1054 keyring,
1055 trust_root,
1056 sqwot_args,
1057 command,
1058 args,
1059 50,
1060 userid,
1061 Some(&dave_fpr),
1062 true,
1063 &output_map(&human_output),
1064 );
1065
1066 test(
1067 keyring,
1068 trust_root,
1069 sqwot_args,
1070 command,
1071 args,
1072 120,
1073 userid,
1074 Some(&dave_fpr),
1075 false,
1076 no_output(),
1077 );
1078
1079 let userids = &[&bob_uid, &bob_some_org_uid];
1080 let human_output = userids
1081 .iter()
1082 .map(|userid| {
1083 (
1084 1,
1085 format!("- {} {}", HR_OK, userid).to_string(),
1086 )
1087 })
1088 .chain(vec![(userids.len(), HR_OK.to_string())].into_iter())
1089 .collect::<Vec<_>>();
1090 test(
1091 keyring,
1092 trust_root,
1093 sqwot_args,
1094 command,
1095 args,
1096 50,
1097 userid,
1098 Some(&bob_fpr),
1099 true,
1100 &output_map(&human_output),
1101 );
1102 test(
1103 keyring,
1104 trust_root,
1105 sqwot_args,
1106 command,
1107 args,
1108 120,
1109 userid,
1110 Some(&bob_fpr),
1111 false,
1112 no_output(),
1113 );
1114
1115 Ok(())
1116 }
1117
1118 // List all authenticated bindings.
1119 #[test]
1120 #[allow(unused)]
1121 fn list() -> Result<()> {
1122 let alice_fpr: Fingerprint =
1123 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
1124 .parse().expect("valid fingerprint");
1125 let alice_uid
1126 = UserID::from("<[email protected]>");
1127
1128 let bob_fpr: Fingerprint =
1129 "39A479816C934B9E0464F1F4BC1DCFDEADA4EE90"
1130 .parse().expect("valid fingerprint");
1131 let bob_uid
1132 = UserID::from("<[email protected]>");
1133 // Certified by: 85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D
1134
1135 let carol_fpr: Fingerprint =
1136 "43530F91B450EDB269AA58821A1CF4DC7F500F04"
1137 .parse().expect("valid fingerprint");
1138 let carol_uid
1139 = UserID::from("<[email protected]>");
1140 // Certified by: 39A479816C934B9E0464F1F4BC1DCFDEADA4EE90
1141
1142 let dave_fpr: Fingerprint =
1143 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
1144 .parse().expect("valid fingerprint");
1145 let dave_uid
1146 = UserID::from("<[email protected]>");
1147 // Certified by: 43530F91B450EDB269AA58821A1CF4DC7F500F04
1148
1149 let ellen_fpr: Fingerprint =
1150 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
1151 .parse().expect("valid fingerprint");
1152 let ellen_uid
1153 = UserID::from("<[email protected]>");
1154 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
1155
1156 let frank_fpr: Fingerprint =
1157 "2693237D2CED0BB68F118D78DC86A97CD2C819D9"
1158 .parse().expect("valid fingerprint");
1159 let frank_uid
1160 = UserID::from("<[email protected]>");
1161
1162 // defaults for test() call
1163 let keyring = "simple.pgp";
1164 let trust_root = &alice_fpr;
1165 let sqwot_args = &[];
1166 let command = "list";
1167 let args = &[];
1168 let userid = None;
1169 let target = None;
1170
1171 let bindings = &[(&alice_uid, &alice_fpr)];
1172 let human_output = bindings
1173 .iter()
1174 .map(|(userid, target)| {
1175 (1, format!("- {} {}", HR_OK, userid).to_string())
1176 })
1177 .chain(vec![(bindings.len(), HR_OK.to_string())].into_iter())
1178 .collect::<Vec<_>>();
1179 test(
1180 keyring,
1181 trust_root,
1182 sqwot_args,
1183 command,
1184 args,
1185 120,
1186 userid,
1187 target,
1188 true,
1189 &output_map(&human_output),
1190 );
1191
1192 let bindings = &[
1193 (&alice_uid, &alice_fpr),
1194 (&bob_uid, &bob_fpr),
1195 (&carol_uid, &carol_fpr),
1196 (&dave_uid, &dave_fpr),
1197 ];
1198 let human_output = bindings
1199 .iter()
1200 .map(|(userid, target)| {
1201 (1, format!("- {} {}", HR_OK, userid).to_string())
1202 })
1203 .chain(vec![(bindings.len(), HR_OK.to_string())].into_iter())
1204 .collect::<Vec<_>>();
1205 test(
1206 keyring,
1207 trust_root,
1208 sqwot_args,
1209 command,
1210 args,
1211 50,
1212 userid,
1213 target,
1214 true,
1215 &output_map(&human_output),
1216 );
1217
1218 Ok(())
1219 }
1220
1221 // List all authenticated bindings matching a pattern.
1222 #[test]
1223 #[allow(unused)]
1224 fn list_pattern() -> Result<()> {
1225 let alice_fpr: Fingerprint =
1226 "2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA"
1227 .parse().expect("valid fingerprint");
1228 let alice_uid
1229 = UserID::from("<[email protected]>");
1230
1231 let bob_fpr: Fingerprint =
1232 "03182611B91B1E7E20B848E83DFC151ABFAD85D5"
1233 .parse().expect("valid fingerprint");
1234 let bob_uid
1235 = UserID::from("<[email protected]>");
1236 // Certified by: 2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA
1237 let bob_some_org_uid
1238 = UserID::from("<[email protected]>");
1239 // Certified by: 2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA
1240
1241 let carol_fpr: Fingerprint =
1242 "9CA36907B46FE7B6B9EE9601E78064C12B6D7902"
1243 .parse().expect("valid fingerprint");
1244 let carol_uid
1245 = UserID::from("<[email protected]>");
1246 // Certified by: 03182611B91B1E7E20B848E83DFC151ABFAD85D5
1247
1248 let dave_fpr: Fingerprint =
1249 "C1BC6794A6C6281B968A6A41ACE2055D610CEA03"
1250 .parse().expect("valid fingerprint");
1251 let dave_uid
1252 = UserID::from("<[email protected]>");
1253 // Certified by: 9CA36907B46FE7B6B9EE9601E78064C12B6D7902
1254
1255 // defaults
1256 let keyring = "multiple-userids-1.pgp";
1257 let trust_root = &alice_fpr;
1258 let sqwot_args = &[];
1259 let command = "list";
1260
1261 let bindings = &[(&bob_uid, &bob_fpr), (&bob_some_org_uid, &bob_fpr)];
1262 let human_output = bindings
1263 .iter()
1264 .map(|(userid, target)| {
1265 (1, format!("- {} {}", HR_OK, userid).to_string())
1266 })
1267 .chain(vec![(bindings.len(), HR_OK.to_string())].into_iter())
1268 .collect::<Vec<_>>();
1269
1270 test(
1271 keyring,
1272 trust_root,
1273 sqwot_args,
1274 command,
1275 &["bob"],
1276 50,
1277 None,
1278 None,
1279 true,
1280 &output_map(&human_output),
1281 );
1282
1283 test(
1284 keyring,
1285 trust_root,
1286 sqwot_args,
1287 command,
1288 &["BOB"],
1289 50,
1290 None,
1291 None,
1292 true,
1293 &output_map(&human_output),
1294 );
1295
1296 let bindings = &[(&alice_uid, &alice_fpr), (&carol_uid, &carol_fpr)];
1297 let human_output = bindings
1298 .iter()
1299 .map(|(userid, target)| {
1300 (1, format!("- {} {}", HR_OK, userid).to_string())
1301 })
1302 .chain(vec![(bindings.len(), HR_OK.to_string())].into_iter())
1303 .collect::<Vec<_>>();
1304
1305 test(
1306 keyring,
1307 trust_root,
1308 sqwot_args,
1309 command,
1310 &["@example.org"],
1311 50,
1312 None,
1313 None,
1314 true,
1315 &output_map(&human_output),
1316 );
1317
1318 test(
1319 keyring,
1320 trust_root,
1321 sqwot_args,
1322 command,
1323 &["@EXAMPLE.ORG"],
1324 50,
1325 None,
1326 None,
1327 true,
1328 &output_map(&human_output),
1329 );
1330
1331 let bindings = &[(&bob_uid, &bob_fpr), (&dave_uid, &dave_fpr)];
1332 let human_output = bindings
1333 .iter()
1334 .map(|(userid, target)| {
1335 (1, format!("- {} {}", HR_OK, userid).to_string())
1336 })
1337 .chain(vec![(bindings.len(), HR_OK.to_string())].into_iter())
1338 .collect::<Vec<_>>();
1339
1340 test(
1341 keyring,
1342 trust_root,
1343 sqwot_args,
1344 command,
1345 &["@OTHER.ORG"],
1346 50,
1347 None,
1348 None,
1349 true,
1350 &output_map(&human_output),
1351 );
1352
1353 let bindings = &[
1354 (&alice_uid, &alice_fpr),
1355 (&bob_uid, &bob_fpr),
1356 (&bob_some_org_uid, &bob_fpr),
1357 (&carol_uid, &carol_fpr),
1358 (&dave_uid, &dave_fpr),
1359 ];
1360 let human_output = bindings
1361 .iter()
1362 .map(|(userid, target)| {
1363 (1, format!("- {} {}", HR_OK, userid).to_string())
1364 })
1365 .chain(vec![(bindings.len(), HR_OK.to_string())].into_iter())
1366 .collect::<Vec<_>>();
1367
1368 test(
1369 keyring,
1370 trust_root,
1371 sqwot_args,
1372 command,
1373 &["ORG"],
1374 50,
1375 None,
1376 None,
1377 true,
1378 &output_map(&human_output),
1379 );
1380
1381 // Puny code.
1382 let alice_fpr: Fingerprint = "B8DA8B318149B1C8C0CBD1ECB1CEC6D3CD00E69D"
1383 .parse()
1384 .expect("valid fingerprint");
1385 let alice_uid = UserID::from("<[email protected]>");
1386 let alice_email = UserID::from("[email protected]");
1387
1388 let hans_fpr: Fingerprint = "74767C4F2B15F57F3394FCA99DE867E6CA6A2756"
1389 .parse()
1390 .expect("valid fingerprint");
1391 let hans_uid = UserID::from("<hÄNS@bücher.tld>");
1392 // Certified by: B8DA8B318149B1C8C0CBD1ECB1CEC6D3CD00E69D
1393
1394 let hans_email = "hÄNS@bücher.tld";
1395 let hans_email_punycode = "hÄ[email protected]";
1396 let hans_email_punycode_lowercase = "hä[email protected]";
1397
1398 let carol_fpr: Fingerprint = "7432C123761B94EC50D50CF6562B9ADEE7F789F6"
1399 .parse()
1400 .expect("valid fingerprint");
1401 let carol_uid = UserID::from("<[email protected]>");
1402 // Certified by: 74767C4F2B15F57F3394FCA99DE867E6CA6A2756
1403
1404 let carol_email
1405 = UserID::from("[email protected]");
1406
1407 // defaults
1408 let keyring = "puny-code.pgp";
1409 let trust_root = &alice_fpr;
1410 let sqwot_args = &[];
1411 let command = "list";
1412
1413 let bindings = &[(&hans_uid, &hans_fpr)];
1414 let human_output = bindings
1415 .iter()
1416 .map(|(userid, target)| {
1417 (1, format!("- {} {}", HR_OK, userid).to_string())
1418 })
1419 .chain(vec![(bindings.len(), HR_OK.to_string())].into_iter())
1420 .collect::<Vec<_>>();
1421
1422 // If we don't provide --email, then we only case
1423 // insensitively match on the raw User ID; we don't perform
1424 // puny code normalization.
1425 test(
1426 keyring,
1427 trust_root,
1428 sqwot_args,
1429 command,
1430 &["bücher.tld"],
1431 100,
1432 None,
1433 None,
1434 true,
1435 &output_map(&human_output),
1436 );
1437
1438 test(
1439 keyring,
1440 trust_root,
1441 sqwot_args,
1442 command,
1443 &["BÜCHER.TLD"],
1444 100,
1445 None,
1446 None,
1447 true,
1448 &output_map(&human_output),
1449 );
1450
1451 test(
1452 keyring,
1453 trust_root,
1454 sqwot_args,
1455 command,
1456 &[hans_email],
1457 100,
1458 None,
1459 None,
1460 true,
1461 &output_map(&human_output),
1462 );
1463
1464 test(
1465 keyring,
1466 trust_root,
1467 sqwot_args,
1468 command,
1469 &[&format!("<{}>", hans_email)],
1470 100,
1471 None,
1472 None,
1473 true,
1474 &output_map(&human_output),
1475 );
1476
1477 test(
1478 keyring,
1479 trust_root,
1480 sqwot_args,
1481 command,
1482 &[hans_email_punycode],
1483 100,
1484 None,
1485 None,
1486 false,
1487 no_output(),
1488 );
1489
1490 test(
1491 keyring,
1492 trust_root,
1493 sqwot_args,
1494 command,
1495 &[hans_email_punycode_lowercase],
1496 100,
1497 None,
1498 None,
1499 false,
1500 no_output(),
1501 );
1502
1503 Ok(())
1504 }
1505
1506 // List all authenticated bindings where the email address matches
1507 // a pattern.
1508 #[test]
1509 #[allow(unused)]
1510 fn list_email_pattern() -> Result<()> {
1511 // Puny code and case normalization.
1512 let alice_fpr: Fingerprint =
1513 "B8DA8B318149B1C8C0CBD1ECB1CEC6D3CD00E69D"
1514 .parse().expect("valid fingerprint");
1515 let alice_uid
1516 = UserID::from("<[email protected]>");
1517 let alice_email
1518 = UserID::from("[email protected]");
1519
1520 let hans_fpr: Fingerprint =
1521 "74767C4F2B15F57F3394FCA99DE867E6CA6A2756"
1522 .parse().expect("valid fingerprint");
1523 let hans_uid
1524 = UserID::from("<hÄNS@bücher.tld>");
1525 // Certified by: B8DA8B318149B1C8C0CBD1ECB1CEC6D3CD00E69D
1526
1527 let hans_email = UserIDArg::Email("hÄNS@bücher.tld");
1528 let hans_email_bad = UserIDArg::Email("<hÄNS@bücher.tld>");
1529 let hans_email_punycode
1530 = UserIDArg::Email("hÄ[email protected]");
1531 let hans_email_punycode_lowercase
1532 = UserIDArg::Email("hä[email protected]");
1533
1534 let carol_fpr: Fingerprint =
1535 "7432C123761B94EC50D50CF6562B9ADEE7F789F6"
1536 .parse().expect("valid fingerprint");
1537 let carol_uid
1538 = UserID::from("<[email protected]>");
1539 // Certified by: 74767C4F2B15F57F3394FCA99DE867E6CA6A2756
1540
1541 let carol_email
1542 = UserID::from("[email protected]");
1543
1544 // defaults
1545 let keyring = "puny-code.pgp";
1546 let trust_root = &alice_fpr;
1547 let sqwot_args = &[];
1548 let command = "list";
1549
1550 let bindings = &[(&hans_uid, &hans_fpr)];
1551 let human_output = bindings
1552 .iter()
1553 .map(|(userid, target)| {
1554 (1, format!("- {} {}", HR_OK, userid).to_string())
1555 })
1556 .chain(vec![(bindings.len(), HR_OK.to_string())].into_iter())
1557 .collect::<Vec<_>>();
1558
1559 // --email has to match the whole email, not a substring.
1560 test(
1561 keyring,
1562 trust_root,
1563 sqwot_args,
1564 command,
1565 &[],
1566 100,
1567 &UserIDArg::Email("bücher.tld"),
1568 None,
1569 false,
1570 no_output(),
1571 );
1572
1573 // --email has to match the whole email, not a substring.
1574 test(
1575 keyring,
1576 trust_root,
1577 sqwot_args,
1578 command,
1579 &[],
1580 100,
1581 &UserIDArg::Email("BÜCHER.TLD"),
1582 None,
1583 false,
1584 no_output(),
1585 );
1586
1587 test(
1588 keyring,
1589 trust_root,
1590 sqwot_args,
1591 command,
1592 &[],
1593 100,
1594 &hans_email,
1595 None,
1596 true,
1597 &output_map(&human_output),
1598 );
1599
1600 test(
1601 keyring,
1602 trust_root,
1603 sqwot_args,
1604 command,
1605 &[],
1606 100,
1607 &hans_email_bad,
1608 None,
1609 false,
1610 no_output(),
1611 );
1612
1613 test(
1614 keyring,
1615 trust_root,
1616 sqwot_args,
1617 command,
1618 &[],
1619 100,
1620 &hans_email_punycode,
1621 None,
1622 true,
1623 &output_map(&human_output),
1624 );
1625
1626 test(
1627 keyring,
1628 trust_root,
1629 sqwot_args,
1630 command,
1631 &[],
1632 100,
1633 &hans_email_punycode_lowercase,
1634 None,
1635 true,
1636 &output_map(&human_output),
1637 );
1638
1639 Ok(())
1640 }
1641
1642 #[test]
1643 #[allow(unused)]
1644 fn path_simple() -> Result<()> {
1645 let alice_fpr: Fingerprint =
1646 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
1647 .parse().expect("valid fingerprint");
1648 let alice_uid
1649 = UserIDArg::UserID("<[email protected]>");
1650
1651 let bob_fpr: Fingerprint =
1652 "39A479816C934B9E0464F1F4BC1DCFDEADA4EE90"
1653 .parse().expect("valid fingerprint");
1654 let bob_uid
1655 = UserIDArg::UserID("<[email protected]>");
1656 // Certified by: 85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D
1657
1658 let carol_fpr: Fingerprint =
1659 "43530F91B450EDB269AA58821A1CF4DC7F500F04"
1660 .parse().expect("valid fingerprint");
1661 let carol_uid
1662 = UserIDArg::UserID("<[email protected]>");
1663 // Certified by: 39A479816C934B9E0464F1F4BC1DCFDEADA4EE90
1664
1665 let dave_fpr: Fingerprint =
1666 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
1667 .parse().expect("valid fingerprint");
1668 let dave_uid
1669 = UserIDArg::UserID("<[email protected]>");
1670 // Certified by: 43530F91B450EDB269AA58821A1CF4DC7F500F04
1671
1672 let ellen_fpr: Fingerprint =
1673 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
1674 .parse().expect("valid fingerprint");
1675 let ellen_uid
1676 = UserIDArg::UserID("<[email protected]>");
1677 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
1678
1679 let frank_fpr: Fingerprint =
1680 "2693237D2CED0BB68F118D78DC86A97CD2C819D9"
1681 .parse().expect("valid fingerprint");
1682 let frank_uid
1683 = UserIDArg::UserID("<[email protected]>");
1684
1685 // defaults
1686 let keyring = "simple.pgp";
1687 let trust_root = None; // No trust root for path.
1688 let sqwot_args = &[];
1689 let command = "path";
1690
1691 // Alice certifies Bob at trust amount = 100. (120 required).
1692 let human_output =
1693 [(1, format!("{} {} {}", HR_NOT_OK_EMPTY, &bob_fpr, &bob_uid))];
1694 test(
1695 keyring,
1696 trust_root,
1697 sqwot_args,
1698 command,
1699 &[
1700 &alice_fpr.to_string(),
1701 &bob_fpr.to_string(),
1702 ],
1703 120,
1704 Some(&bob_uid),
1705 None,
1706 false,
1707 &output_map(&human_output),
1708 );
1709
1710 let human_output = [(1, format!("{} {} {}", HR_OK, bob_fpr, bob_uid))];
1711 // As above, but we only require 100.
1712 test(
1713 keyring,
1714 trust_root,
1715 sqwot_args,
1716 command,
1717 &[
1718 &alice_fpr.to_string(),
1719 &bob_fpr.to_string(),
1720 ],
1721 100,
1722 Some(&bob_uid),
1723 None,
1724 true,
1725 &output_map(&human_output),
1726 );
1727
1728 // Alice makes Bob a level 2 trusted introducer.
1729 // Bob certificates Carol, but for Bob.
1730 let human_output =
1731 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &carol_fpr, &bob_uid))];
1732 test(
1733 keyring,
1734 trust_root,
1735 sqwot_args,
1736 command,
1737 &[
1738 &alice_fpr.to_string(),
1739 &bob_fpr.to_string(),
1740 &carol_fpr.to_string(),
1741 ],
1742 100,
1743 Some(&bob_uid),
1744 None,
1745 false,
1746 &output_map(&human_output),
1747 );
1748
1749 let human_output =
1750 [(1, format!("{} {} {}", HR_OK, carol_fpr, carol_uid))];
1751 // Alice makes Bob a level 2 trusted introducer.
1752 // Bob certificates Carol.
1753 test(
1754 keyring,
1755 trust_root,
1756 sqwot_args,
1757 command,
1758 &[
1759 &alice_fpr.to_string(),
1760 &bob_fpr.to_string(),
1761 &carol_fpr.to_string(),
1762 ],
1763 100,
1764 Some(&carol_uid),
1765 None,
1766 true,
1767 &output_map(&human_output),
1768 );
1769
1770 let human_output =
1771 [(1, format!("{} {} {}", HR_OK, dave_fpr, dave_uid))];
1772 // Alice makes Bob a level 2 trusted introducer.
1773 // Bob makes Carol a level 1 trust introducer.
1774 // Carol certifies Dave.
1775 test(
1776 keyring,
1777 trust_root,
1778 sqwot_args,
1779 command,
1780 &[
1781 &alice_fpr.to_string(),
1782 &bob_fpr.to_string(),
1783 &carol_fpr.to_string(),
1784 &dave_fpr.to_string(),
1785 ],
1786 100,
1787 Some(&dave_uid),
1788 None,
1789 true,
1790 &output_map(&human_output),
1791 );
1792
1793 // Alice makes Bob a level 2 trusted introducer (require level 3).
1794 // Bob makes Carol a level 1 trusted introducer (require level 2).
1795 // Carol makes Dave a level 1 trusted introducer.
1796 // Dave certifies Ellen.
1797 let human_output =
1798 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &ellen_fpr, &ellen_uid))];
1799 test(
1800 keyring,
1801 trust_root,
1802 sqwot_args,
1803 command,
1804 &[
1805 &alice_fpr.to_string(),
1806 &bob_fpr.to_string(),
1807 &carol_fpr.to_string(),
1808 &dave_fpr.to_string(),
1809 &ellen_fpr.to_string(),
1810 ],
1811 100,
1812 Some(&ellen_uid),
1813 None,
1814 false,
1815 &output_map(&human_output),
1816 );
1817
1818 // Alice makes Bob a level 2 trusted introducer.
1819 // Bob does *not* certify Dave.
1820 // Dave certifies Ellen.
1821 let human_output =
1822 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &ellen_fpr, &ellen_uid))];
1823 test(
1824 keyring,
1825 trust_root,
1826 sqwot_args,
1827 command,
1828 &[
1829 &alice_fpr.to_string(),
1830 &bob_fpr.to_string(),
1831 &dave_fpr.to_string(),
1832 &ellen_fpr.to_string(),
1833 ],
1834 100,
1835 Some(&ellen_uid),
1836 None,
1837 false,
1838 &output_map(&human_output),
1839 );
1840
1841 Ok(())
1842 }
1843
1844 #[test]
1845 #[allow(unused)]
1846 fn path_missing_certs() -> Result<()> {
1847 let alice_fpr: Fingerprint =
1848 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
1849 .parse().expect("valid fingerprint");
1850 let alice_uid
1851 = UserIDArg::UserID("<[email protected]>");
1852
1853 let bob_fpr: Fingerprint =
1854 "39A479816C934B9E0464F1F4BC1DCFDEADA4EE90"
1855 .parse().expect("valid fingerprint");
1856 let bob_uid
1857 = UserIDArg::UserID("<[email protected]>");
1858 // Certified by: 85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D
1859
1860 let carol_fpr: Fingerprint =
1861 "43530F91B450EDB269AA58821A1CF4DC7F500F04"
1862 .parse().expect("valid fingerprint");
1863 let carol_uid
1864 = UserIDArg::UserID("<[email protected]>");
1865 // Certified by: 39A479816C934B9E0464F1F4BC1DCFDEADA4EE90
1866
1867 let dave_fpr: Fingerprint =
1868 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
1869 .parse().expect("valid fingerprint");
1870 let dave_uid
1871 = UserIDArg::UserID("<[email protected]>");
1872 // Certified by: 43530F91B450EDB269AA58821A1CF4DC7F500F04
1873
1874 let ellen_fpr: Fingerprint =
1875 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
1876 .parse().expect("valid fingerprint");
1877 let ellen_uid
1878 = UserIDArg::UserID("<[email protected]>");
1879 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
1880
1881 let frank_fpr: Fingerprint =
1882 "2693237D2CED0BB68F118D78DC86A97CD2C819D9"
1883 .parse().expect("valid fingerprint");
1884 let frank_uid
1885 = UserIDArg::UserID("<[email protected]>");
1886
1887 let missing_fpr: Fingerprint =
1888 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
1889 .parse().expect("valid fingerprint");
1890
1891 // defaults
1892 let keyring = "simple.pgp";
1893 let trust_root = None; // No trust root for path.
1894 let sqwot_args = &[];
1895 let command = "path";
1896
1897 let human_output =
1898 [(1, format!("{} {} {}", HR_OK, carol_fpr, carol_uid))];
1899 // Alice tsigns Bob at depth = 2, trust amount = 100.
1900 // Bob certifies Carol, trust amount = 100.
1901 test(
1902 keyring,
1903 trust_root,
1904 sqwot_args,
1905 command,
1906 &[
1907 &alice_fpr.to_string(),
1908 &bob_fpr.to_string(),
1909 &carol_fpr.to_string(),
1910 ],
1911 100,
1912 Some(&carol_uid),
1913 None,
1914 true,
1915 &output_map(&human_output),
1916 );
1917
1918 let human_output =
1919 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &carol_fpr, &carol_uid))];
1920 test(
1921 keyring,
1922 trust_root,
1923 sqwot_args,
1924 command,
1925 &[
1926 &missing_fpr.to_string(),
1927 &bob_fpr.to_string(),
1928 &carol_fpr.to_string(),
1929 ],
1930 100,
1931 Some(&carol_uid),
1932 None,
1933 false,
1934 &output_map(&human_output),
1935 );
1936
1937 let human_output =
1938 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &carol_fpr, &carol_uid))];
1939 test(
1940 keyring,
1941 trust_root,
1942 sqwot_args,
1943 command,
1944 &[
1945 &alice_fpr.to_string(),
1946 &missing_fpr.to_string(),
1947 &carol_fpr.to_string(),
1948 ],
1949 100,
1950 Some(&carol_uid),
1951 None,
1952 false,
1953 &output_map(&human_output),
1954 );
1955
1956 let human_output =
1957 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &missing_fpr, &carol_uid))];
1958 test(
1959 keyring,
1960 trust_root,
1961 sqwot_args,
1962 command,
1963 &[
1964 &alice_fpr.to_string(),
1965 &bob_fpr.to_string(),
1966 &missing_fpr.to_string(),
1967 ],
1968 100,
1969 Some(&carol_uid),
1970 None,
1971 false,
1972 &output_map(&human_output),
1973 );
1974
1975 Ok(())
1976 }
1977
1978 #[test]
1979 #[allow(unused)]
1980 fn path_singleton() -> Result<()> {
1981 let alice_fpr: Fingerprint =
1982 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
1983 .parse().expect("valid fingerprint");
1984 let alice_uid
1985 = UserIDArg::UserID("<[email protected]>");
1986
1987 let bob_fpr: Fingerprint =
1988 "39A479816C934B9E0464F1F4BC1DCFDEADA4EE90"
1989 .parse().expect("valid fingerprint");
1990 let bob_uid
1991 = UserIDArg::UserID("<[email protected]>");
1992 // Certified by: 85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D
1993
1994 let carol_fpr: Fingerprint =
1995 "43530F91B450EDB269AA58821A1CF4DC7F500F04"
1996 .parse().expect("valid fingerprint");
1997 let carol_uid
1998 = UserIDArg::UserID("<[email protected]>");
1999 // Certified by: 39A479816C934B9E0464F1F4BC1DCFDEADA4EE90
2000
2001 let dave_fpr: Fingerprint =
2002 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
2003 .parse().expect("valid fingerprint");
2004 let dave_uid
2005 = UserIDArg::UserID("<[email protected]>");
2006 // Certified by: 43530F91B450EDB269AA58821A1CF4DC7F500F04
2007
2008 let ellen_fpr: Fingerprint =
2009 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
2010 .parse().expect("valid fingerprint");
2011 let ellen_uid
2012 = UserIDArg::UserID("<[email protected]>");
2013 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
2014
2015 let frank_fpr: Fingerprint =
2016 "2693237D2CED0BB68F118D78DC86A97CD2C819D9"
2017 .parse().expect("valid fingerprint");
2018 let frank_uid
2019 = UserIDArg::UserID("<[email protected]>");
2020
2021 let missing_fpr: Fingerprint =
2022 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
2023 .parse().expect("valid fingerprint");
2024
2025 // defaults
2026 let keyring = "simple.pgp";
2027 let trust_root = None; // No trust root for path.
2028 let sqwot_args = &[];
2029 let command = "path";
2030
2031 let human_output =
2032 [(1, format!("{} {} {}: ", HR_OK, &alice_fpr, &alice_uid))];
2033 // A self signed User ID.
2034 test(
2035 keyring,
2036 trust_root,
2037 sqwot_args,
2038 command,
2039 &[
2040 &alice_fpr.to_string(),
2041 ],
2042 120,
2043 Some(&alice_uid),
2044 None,
2045 true,
2046 &output_map(&human_output),
2047 );
2048
2049 // A User ID that is not self signed.
2050 let human_output =
2051 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &alice_fpr, &bob_uid))];
2052 test(
2053 keyring,
2054 trust_root,
2055 sqwot_args,
2056 command,
2057 &[
2058 &alice_fpr.to_string(),
2059 ],
2060 120,
2061 Some(&bob_uid),
2062 None,
2063 false,
2064 &output_map(&human_output),
2065 );
2066
2067 Ok(())
2068 }
2069
2070 #[test]
2071 #[allow(unused)]
2072 fn path_multiple_userids_1() -> Result<()> {
2073 let alice_fpr: Fingerprint =
2074 "2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA"
2075 .parse().expect("valid fingerprint");
2076 let alice_uid
2077 = UserIDArg::UserID("<[email protected]>");
2078
2079 let bob_fpr: Fingerprint =
2080 "03182611B91B1E7E20B848E83DFC151ABFAD85D5"
2081 .parse().expect("valid fingerprint");
2082 let bob_uid
2083 = UserIDArg::UserID("<[email protected]>");
2084 // Certified by: 2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA
2085 let bob_some_org_uid
2086 = UserIDArg::UserID("<[email protected]>");
2087 // Certified by: 2A2A4A23A7EEC119BC0B46642B3825DC02A05FEA
2088
2089 let carol_fpr: Fingerprint =
2090 "9CA36907B46FE7B6B9EE9601E78064C12B6D7902"
2091 .parse().expect("valid fingerprint");
2092 let carol_uid
2093 = UserIDArg::UserID("<[email protected]>");
2094 // Certified by: 03182611B91B1E7E20B848E83DFC151ABFAD85D5
2095
2096 let dave_fpr: Fingerprint =
2097 "C1BC6794A6C6281B968A6A41ACE2055D610CEA03"
2098 .parse().expect("valid fingerprint");
2099 let dave_uid
2100 = UserIDArg::UserID("<[email protected]>");
2101 // Certified by: 9CA36907B46FE7B6B9EE9601E78064C12B6D7902
2102
2103 // defaults
2104 let keyring = "multiple-userids-1.pgp";
2105 let trust_root = None; // No trust root for path.
2106 let sqwot_args = &[];
2107 let command = "path";
2108
2109 // Alice certifies Bob as:
2110 // a level 2 trusted introducer, amount = 50
2111 // a level 1 trusted introducer, amount = 70
2112 // Bob certifies Carol as a level 2 trusted introducer
2113 // Carol certifies Dave
2114 let human_output =
2115 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &dave_fpr, &dave_uid))];
2116 test(
2117 keyring,
2118 trust_root,
2119 sqwot_args,
2120 command,
2121 &[
2122 &alice_fpr.to_string(),
2123 &bob_fpr.to_string(),
2124 &carol_fpr.to_string(),
2125 &dave_fpr.to_string(),
2126 ],
2127 70,
2128 Some(&dave_uid),
2129 None,
2130 false,
2131 &output_map(&human_output),
2132 );
2133
2134 let human_output =
2135 [(1, format!("{} {} {}", HR_OK, dave_fpr, dave_uid))];
2136 // As above, but
2137 test(
2138 keyring,
2139 trust_root,
2140 sqwot_args,
2141 command,
2142 &[
2143 &alice_fpr.to_string(),
2144 &bob_fpr.to_string(),
2145 &carol_fpr.to_string(),
2146 &dave_fpr.to_string(),
2147 ],
2148 50,
2149 Some(&dave_uid),
2150 None,
2151 true,
2152 &output_map(&human_output),
2153 );
2154
2155 Ok(())
2156 }
2157
2158 #[test]
2159 #[allow(unused)]
2160 fn path_multiple_users_2() -> Result<()> {
2161 // Note: this also tests regular expressions.
2162
2163 let alice_fpr: Fingerprint =
2164 "F1C99C4019837703DD17C45440F8A0141DF278EA"
2165 .parse().expect("valid fingerprint");
2166 let alice_uid
2167 = UserIDArg::UserID("<[email protected]>");
2168
2169 let bob_fpr: Fingerprint =
2170 "5528B9E5DAFC519ED2E37F0377B332E4111456CB"
2171 .parse().expect("valid fingerprint");
2172 let bob_uid
2173 = UserIDArg::UserID("<[email protected]>");
2174 // Certified by: F1C99C4019837703DD17C45440F8A0141DF278EA
2175 let bob_some_org_uid
2176 = UserIDArg::UserID("<[email protected]>");
2177 // Certified by: F1C99C4019837703DD17C45440F8A0141DF278EA
2178
2179 let carol_fpr: Fingerprint =
2180 "6F8291428420AB53576BAB4BEFF6477D3E348D71"
2181 .parse().expect("valid fingerprint");
2182 let carol_uid
2183 = UserIDArg::UserID("<[email protected]>");
2184 // Certified by: 5528B9E5DAFC519ED2E37F0377B332E4111456CB
2185
2186 let dave_fpr: Fingerprint =
2187 "62C57D90DAD253DEA01D5A86C7382FD6285C18F0"
2188 .parse().expect("valid fingerprint");
2189 let dave_uid
2190 = UserIDArg::UserID("<[email protected]>");
2191 // Certified by: 6F8291428420AB53576BAB4BEFF6477D3E348D71
2192
2193 let ed_fpr: Fingerprint =
2194 "0E974D0ACBA0C4D8F51D7CF68F048FF83B173504"
2195 .parse().expect("valid fingerprint");
2196 let ed_uid
2197 = UserIDArg::UserID("<[email protected]>");
2198 // Certified by: 6F8291428420AB53576BAB4BEFF6477D3E348D71
2199
2200 let frank_fpr: Fingerprint =
2201 "5BEE3D41F85B2FCBC300DE4E18CB2BDA65465F03"
2202 .parse().expect("valid fingerprint");
2203 let frank_uid
2204 = UserIDArg::UserID("<[email protected]>");
2205 // Certified by: 5528B9E5DAFC519ED2E37F0377B332E4111456CB
2206
2207 // defaults
2208 let keyring = "multiple-userids-2.pgp";
2209 let trust_root = None; // No trust root for path.
2210 let sqwot_args = &[];
2211 let command = "path";
2212
2213 let human_output = [(1, format!("{} {}", HR_OK, frank_fpr))];
2214 // Alice certifies Bob as:
2215 // a level 255 trusted introducer, amount = 70 for other.org
2216 // a level 1 trusted introducer, amount = 50
2217 // Bob certifies [email protected]
2218 test(
2219 keyring,
2220 trust_root,
2221 sqwot_args,
2222 command,
2223 &[
2224 &alice_fpr.to_string(),
2225 &bob_fpr.to_string(),
2226 &frank_fpr.to_string(),
2227 ],
2228 70,
2229 Some(&frank_uid),
2230 None,
2231 true,
2232 &output_map(&human_output),
2233 );
2234
2235 // Alice certifies Bob as:
2236 // a level 255 trusted introducer, amount = 70 for other.org
2237 // a level 1 trusted introducer, amount = 50
2238 // Bob certifies [email protected]
2239 let human_output =
2240 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &carol_fpr, &carol_uid))];
2241 test(
2242 keyring,
2243 trust_root,
2244 sqwot_args,
2245 command,
2246 &[
2247 &alice_fpr.to_string(),
2248 &bob_fpr.to_string(),
2249 &carol_fpr.to_string(),
2250 ],
2251 70,
2252 Some(&carol_uid),
2253 None,
2254 false,
2255 &output_map(&human_output),
2256 );
2257
2258 let human_output =
2259 [(1, format!("{} {} {}", HR_OK, carol_fpr, carol_uid))];
2260 // As above, but reduce the required trust amount to 50.
2261 test(
2262 keyring,
2263 trust_root,
2264 sqwot_args,
2265 command,
2266 &[
2267 &alice_fpr.to_string(),
2268 &bob_fpr.to_string(),
2269 &carol_fpr.to_string(),
2270 ],
2271 50,
2272 Some(&carol_uid),
2273 None,
2274 true,
2275 &output_map(&human_output),
2276 );
2277
2278 let human_output =
2279 [(1, format!("{} {} {}", HR_OK, dave_fpr, dave_uid))];
2280 // Alice certifies Bob as:
2281 // a level 255 trusted introducer, amount = 70 for other.org
2282 // a level 1 trusted introducer, amount = 50
2283 // Bob certifies carol as a level 2 trusted introducer
2284 // Carol certifies [email protected]
2285 test(
2286 keyring,
2287 trust_root,
2288 sqwot_args,
2289 command,
2290 &[
2291 &alice_fpr.to_string(),
2292 &bob_fpr.to_string(),
2293 &carol_fpr.to_string(),
2294 &dave_fpr.to_string(),
2295 ],
2296 70,
2297 Some(&dave_uid),
2298 None,
2299 true,
2300 &output_map(&human_output),
2301 );
2302
2303 // Alice certifies Bob as:
2304 // a level 255 trusted introducer, amount = 70 for other.org
2305 // a level 1 trusted introducer, amount = 50
2306 // Bob certifies carol as a level 2 trusted introducer
2307 // Carol certifies [email protected]
2308 let human_output =
2309 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &ed_fpr, &ed_uid))];
2310 test(
2311 keyring,
2312 trust_root,
2313 sqwot_args,
2314 command,
2315 &[
2316 &alice_fpr.to_string(),
2317 &bob_fpr.to_string(),
2318 &carol_fpr.to_string(),
2319 &ed_fpr.to_string(),
2320 ],
2321 70,
2322 Some(&ed_uid),
2323 None,
2324 false,
2325 &output_map(&human_output),
2326 );
2327
2328 Ok(())
2329 }
2330
2331 #[test]
2332 #[allow(unused)]
2333 fn path_sha1() -> Result<()> {
2334 let alice_fpr: Fingerprint =
2335 "B5FA089BA76FE3E17DC11660960E53286738F94C"
2336 .parse().expect("valid fingerprint");
2337 let alice_uid
2338 = UserIDArg::UserID("<[email protected]>");
2339
2340 let bob_fpr: Fingerprint =
2341 "231BC4AB9D8CAB86D1622CE02C0CE554998EECDB"
2342 .parse().expect("valid fingerprint");
2343 let bob_uid
2344 = UserIDArg::UserID("<[email protected]>");
2345 // Certified by: B5FA089BA76FE3E17DC11660960E53286738F94C
2346 // Certified by: B5FA089BA76FE3E17DC11660960E53286738F94C
2347
2348 let carol_fpr: Fingerprint =
2349 "FABA8485B2D4D5BF1582AA963A8115E774FA9852"
2350 .parse().expect("valid fingerprint");
2351 let carol_uid
2352 = UserIDArg::UserID("<[email protected]>");
2353 // Certified by: 231BC4AB9D8CAB86D1622CE02C0CE554998EECDB
2354 // Certified by: 231BC4AB9D8CAB86D1622CE02C0CE554998EECDB
2355
2356 // defaults
2357 let keyring = "sha1.pgp";
2358 let trust_root = None; // No trust root for path.
2359 let sqwot_args = &[ "--time", "2023-01-10T15:07:01" ];
2360 let command = "path";
2361
2362 // Alice certifies Bob as
2363 // a level 1 trusted introducer, amount = 120 using sha1
2364 // a level 1 trusted introducer, amount = 60 using sha512 (future)
2365 // Bob certifies carol as a
2366 // a level 1 trusted introducer, amount = 120 using sha1
2367 // a level 1 trusted introducer, amount = 60 using sha512 (future)
2368 //
2369 // The valid signatures won't be used because they are from
2370 // the future (after the reference time).
2371 let human_output =
2372 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &carol_fpr, &carol_uid))];
2373 test(
2374 keyring,
2375 trust_root,
2376 sqwot_args,
2377 command,
2378 &[
2379 &alice_fpr.to_string(),
2380 &bob_fpr.to_string(),
2381 &carol_fpr.to_string(),
2382 ],
2383 120,
2384 Some(&carol_uid),
2385 None,
2386 false,
2387 &output_map(&human_output),
2388 );
2389
2390 // Again, but this time only require a trust amount of 60.
2391 let human_output =
2392 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &carol_fpr, &carol_uid))];
2393 test(
2394 keyring,
2395 trust_root,
2396 sqwot_args,
2397 command,
2398 &[
2399 &alice_fpr.to_string(),
2400 &bob_fpr.to_string(),
2401 &carol_fpr.to_string(),
2402 ],
2403 60,
2404 Some(&carol_uid),
2405 None,
2406 false,
2407 &output_map(&human_output),
2408 );
2409
2410 // set sq-wot args again
2411 let sqwot_args = &[];
2412
2413 // Again, after the SHA256 certificates are valid. But with a
2414 // trust amount of 120.
2415 let human_output =
2416 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &carol_fpr, &carol_uid))];
2417 test(
2418 keyring,
2419 trust_root,
2420 sqwot_args,
2421 command,
2422 &[
2423 &alice_fpr.to_string(),
2424 &bob_fpr.to_string(),
2425 &carol_fpr.to_string(),
2426 ],
2427 120,
2428 Some(&carol_uid),
2429 None,
2430 false,
2431 &output_map(&human_output),
2432 );
2433
2434 let human_output =
2435 [(1, format!("{} {} {}", HR_OK, carol_fpr, carol_uid))];
2436 test(
2437 keyring,
2438 trust_root,
2439 sqwot_args,
2440 command,
2441 &[
2442 &alice_fpr.to_string(),
2443 &bob_fpr.to_string(),
2444 &carol_fpr.to_string(),
2445 ],
2446 60,
2447 Some(&carol_uid),
2448 None,
2449 true,
2450 &output_map(&human_output),
2451 );
2452
2453 Ok(())
2454 }
2455
2456 #[test]
2457 #[allow(unused)]
2458 fn authenticate_certification_network_simple() -> Result<()> {
2459 let alice_fpr: Fingerprint =
2460 "85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D"
2461 .parse().expect("valid fingerprint");
2462 let alice_uid
2463 = UserIDArg::UserID("<[email protected]>");
2464
2465 let bob_fpr: Fingerprint =
2466 "39A479816C934B9E0464F1F4BC1DCFDEADA4EE90"
2467 .parse().expect("valid fingerprint");
2468 let bob_uid
2469 = UserIDArg::UserID("<[email protected]>");
2470 // Certified by: 85DAB65713B2D0ABFC5A4F28BC10C9CE4A699D8D
2471
2472 let carol_fpr: Fingerprint =
2473 "43530F91B450EDB269AA58821A1CF4DC7F500F04"
2474 .parse().expect("valid fingerprint");
2475 let carol_uid
2476 = UserIDArg::UserID("<[email protected]>");
2477 // Certified by: 39A479816C934B9E0464F1F4BC1DCFDEADA4EE90
2478
2479 let dave_fpr: Fingerprint =
2480 "329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281"
2481 .parse().expect("valid fingerprint");
2482 let dave_uid
2483 = UserIDArg::UserID("<[email protected]>");
2484 // Certified by: 43530F91B450EDB269AA58821A1CF4DC7F500F04
2485
2486 let ellen_fpr: Fingerprint =
2487 "A7319A9B166AB530A5FBAC8AB43CA77F7C176AF4"
2488 .parse().expect("valid fingerprint");
2489 let ellen_uid
2490 = UserIDArg::UserID("<[email protected]>");
2491 // Certified by: 329D5AAF73DC70B4E3DD2D11677CB70FFBFE1281
2492
2493 let frank_fpr: Fingerprint =
2494 "2693237D2CED0BB68F118D78DC86A97CD2C819D9"
2495 .parse().expect("valid fingerprint");
2496 let frank_uid
2497 = UserIDArg::UserID("<[email protected]>");
2498
2499 // defaults
2500 let keyring = "simple.pgp";
2501 let trust_root = &alice_fpr;
2502 let sqwot_args = &[];
2503 let command = "authenticate";
2504 let args = &[];
2505
2506 test(
2507 keyring,
2508 trust_root,
2509 sqwot_args,
2510 command,
2511 args,
2512 100,
2513 Some(&ellen_uid),
2514 Some(&ellen_fpr),
2515 false,
2516 no_output(),
2517 );
2518
2519 let sqwot_args = &["--certification-network"];
2520 let human_output =
2521 [(1, format!("- {} {}", HR_OK, &ellen_uid))];
2522 test(
2523 keyring,
2524 trust_root,
2525 sqwot_args,
2526 command,
2527 args,
2528 100,
2529 Some(&ellen_uid),
2530 Some(&ellen_fpr),
2531 true,
2532 &output_map(&human_output),
2533 );
2534
2535 Ok(())
2536 }
2537
2538 #[test]
2539 #[allow(unused)]
2540 fn authenticate_certification_network() -> Result<()> {
2541 let alice_fpr: Fingerprint =
2542 "B2B371214EF71AFD16E42C62D81360B4C0489225"
2543 .parse().expect("valid fingerprint");
2544 let alice_uid
2545 = UserIDArg::UserID("<[email protected]>");
2546 // Certified by: 9A1AE937B5CB8BC46048AB63023CC01973ED9DF3
2547
2548 let bob_fpr: Fingerprint =
2549 "A68DF00EB82F9C49C27CC7723C5F5BBE6B790C05"
2550 .parse().expect("valid fingerprint");
2551 let bob_uid
2552 = UserIDArg::UserID("<[email protected]>");
2553 // Certified by: B2B371214EF71AFD16E42C62D81360B4C0489225
2554
2555 let carol_fpr: Fingerprint =
2556 "AB9EF1C89631519842ED559697557DD147D99C97"
2557 .parse().expect("valid fingerprint");
2558 let carol_uid
2559 = UserIDArg::UserID("<[email protected]>");
2560 // Certified by: A68DF00EB82F9C49C27CC7723C5F5BBE6B790C05
2561
2562 let dave_fpr: Fingerprint =
2563 "9A1AE937B5CB8BC46048AB63023CC01973ED9DF3"
2564 .parse().expect("valid fingerprint");
2565 let dave_uid
2566 = UserIDArg::UserID("<[email protected]>");
2567 // Certified by: AB9EF1C89631519842ED559697557DD147D99C97
2568
2569 // defaults
2570 let keyring = "certification-network.pgp";
2571 let trust_root = &alice_fpr;
2572 let sqwot_args = &[];
2573 let command = "authenticate";
2574 let args = &[];
2575
2576 let human_output =
2577 [(1, format!("- {} {}", HR_OK, &bob_uid))];
2578 // Alice does not make Bob a trusted introducer. So without
2579 // --certificate-network, she can only authenticate Bob, but
2580 // not Carol or Dave.
2581 test(
2582 keyring,
2583 trust_root,
2584 sqwot_args,
2585 command,
2586 args,
2587 120,
2588 Some(&bob_uid),
2589 Some(&bob_fpr),
2590 true,
2591 &output_map(&human_output),
2592 );
2593
2594 test(
2595 keyring,
2596 trust_root,
2597 sqwot_args,
2598 command,
2599 args,
2600 120,
2601 Some(&carol_uid),
2602 Some(&carol_fpr),
2603 false,
2604 no_output(),
2605 );
2606
2607 test(
2608 keyring,
2609 trust_root,
2610 sqwot_args,
2611 command,
2612 args,
2613 120,
2614 Some(&dave_uid),
2615 Some(&dave_fpr),
2616 false,
2617 no_output(),
2618 );
2619
2620 // With --certification-network, she can authenticate them all.
2621 let sqwot_args = &["--certification-network"];
2622 let human_output =
2623 [(1, format!("- {} {}", HR_OK, &bob_uid))];
2624 test(
2625 keyring,
2626 trust_root,
2627 sqwot_args,
2628 command,
2629 args,
2630 120,
2631 Some(&bob_uid),
2632 Some(&bob_fpr),
2633 true,
2634 &output_map(&human_output),
2635 );
2636
2637 let human_output =
2638 [(1, format!("- {} {}", HR_OK, &carol_uid))];
2639 test(
2640 keyring,
2641 trust_root,
2642 sqwot_args,
2643 command,
2644 args,
2645 120,
2646 Some(&carol_uid),
2647 Some(&carol_fpr),
2648 true,
2649 &output_map(&human_output),
2650 );
2651
2652 let human_output =
2653 [(1, format!("- {} {}", HR_OK, &dave_uid))];
2654 test(
2655 keyring,
2656 trust_root,
2657 sqwot_args,
2658 command,
2659 args,
2660 120,
2661 Some(&dave_uid),
2662 Some(&dave_fpr),
2663 true,
2664 &output_map(&human_output),
2665 );
2666
2667 let sqwot_args = &[];
2668 let trust_root = &dave_fpr;
2669 // dave authenticates alice for 60 of 120.
2670 test(
2671 keyring,
2672 trust_root,
2673 sqwot_args,
2674 command,
2675 args,
2676 120,
2677 Some(&alice_uid),
2678 Some(&alice_fpr),
2679 false,
2680 no_output(),
2681 );
2682
2683 let human_output =
2684 [(1, format!("- {} {}", HR_OK, &alice_uid))];
2685 test(
2686 keyring,
2687 trust_root,
2688 sqwot_args,
2689 command,
2690 args,
2691 60,
2692 Some(&alice_uid),
2693 Some(&alice_fpr),
2694 true,
2695 &output_map(&human_output),
2696 );
2697
2698 // use --certification-network
2699 let sqwot_args = &["--certification-network"];
2700 test(
2701 keyring,
2702 trust_root,
2703 sqwot_args,
2704 command,
2705 args,
2706 120,
2707 Some(&alice_uid),
2708 Some(&alice_fpr),
2709 false,
2710 no_output(),
2711 );
2712
2713 let human_output =
2714 [(1, format!("- {} {}", HR_OK, &alice_uid))];
2715 test(
2716 keyring,
2717 trust_root,
2718 sqwot_args,
2719 command,
2720 args,
2721 60,
2722 Some(&alice_uid),
2723 Some(&alice_fpr),
2724 true,
2725 &output_map(&human_output),
2726 );
2727
2728 let sqwot_args = &[];
2729 // use carol as trust root
2730 let trust_root = &carol_fpr;
2731 test(
2732 keyring,
2733 trust_root,
2734 sqwot_args,
2735 command,
2736 args,
2737 60,
2738 Some(&alice_uid),
2739 Some(&alice_fpr),
2740 false,
2741 no_output(),
2742 );
2743
2744 // use --certification-network
2745 let sqwot_args = &["--certification-network"];
2746 let human_output =
2747 [(1, format!("- {} {}", HR_OK, &alice_uid))];
2748 test(
2749 keyring,
2750 trust_root,
2751 sqwot_args,
2752 command,
2753 args,
2754 60,
2755 Some(&alice_uid),
2756 Some(&alice_fpr),
2757 true,
2758 &output_map(&human_output),
2759 );
2760
2761 let human_output =
2762 [(1, format!("- {} {}", HR_OK, &bob_uid))];
2763 test(
2764 keyring,
2765 trust_root,
2766 sqwot_args,
2767 command,
2768 args,
2769 60,
2770 Some(&bob_uid),
2771 Some(&bob_fpr),
2772 true,
2773 &output_map(&human_output),
2774 );
2775
2776 Ok(())
2777 }
2778
2779 #[test]
2780 #[allow(unused)]
2781 fn path_certification_network() -> Result<()> {
2782 let alice_fpr: Fingerprint =
2783 "B2B371214EF71AFD16E42C62D81360B4C0489225"
2784 .parse().expect("valid fingerprint");
2785 let alice_uid
2786 = UserIDArg::UserID("<[email protected]>");
2787 // Certified by: 9A1AE937B5CB8BC46048AB63023CC01973ED9DF3
2788
2789 let bob_fpr: Fingerprint =
2790 "A68DF00EB82F9C49C27CC7723C5F5BBE6B790C05"
2791 .parse().expect("valid fingerprint");
2792 let bob_uid
2793 = UserIDArg::UserID("<[email protected]>");
2794 // Certified by: B2B371214EF71AFD16E42C62D81360B4C0489225
2795
2796 let carol_fpr: Fingerprint =
2797 "AB9EF1C89631519842ED559697557DD147D99C97"
2798 .parse().expect("valid fingerprint");
2799 let carol_uid
2800 = UserIDArg::UserID("<[email protected]>");
2801 // Certified by: A68DF00EB82F9C49C27CC7723C5F5BBE6B790C05
2802
2803 let dave_fpr: Fingerprint =
2804 "9A1AE937B5CB8BC46048AB63023CC01973ED9DF3"
2805 .parse().expect("valid fingerprint");
2806 let dave_uid
2807 = UserIDArg::UserID("<[email protected]>");
2808 // Certified by: AB9EF1C89631519842ED559697557DD147D99C97
2809
2810 // defaults
2811 let keyring = "certification-network.pgp";
2812 let trust_root = &alice_fpr;
2813 let sqwot_args = &[];
2814 let command = "path";
2815
2816 let human_output =
2817 [(1, format!("{} {} {}: ", HR_OK, &bob_fpr, &bob_uid))];
2818 // Alice does not make Bob a trusted introducer. So without
2819 // --certificate-network, she can only authenticate Bob, but
2820 // not Carol or Dave.
2821 test(
2822 keyring,
2823 trust_root,
2824 sqwot_args,
2825 command,
2826 &[
2827 &alice_fpr.to_string(),
2828 &bob_fpr.to_string(),
2829 ],
2830 120,
2831 Some(&bob_uid),
2832 None,
2833 true,
2834 &output_map(&human_output),
2835 );
2836
2837 let human_output =
2838 [(1, format!("{} {} {}:", HR_NOT_OK_EMPTY, &carol_fpr, &carol_uid))];
2839 test(
2840 keyring,
2841 trust_root,
2842 sqwot_args,
2843 command,
2844 &[
2845 &alice_fpr.to_string(),
2846 &bob_fpr.to_string(),
2847 &carol_fpr.to_string(),
2848 ],
2849 120,
2850 Some(&carol_uid),
2851 None,
2852 false,
2853 &output_map(&human_output),
2854 );
2855
2856 let human_output =
2857 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &dave_fpr, &dave_uid))];
2858 test(
2859 keyring,
2860 trust_root,
2861 sqwot_args,
2862 command,
2863 &[
2864 &alice_fpr.to_string(),
2865 &bob_fpr.to_string(),
2866 &carol_fpr.to_string(),
2867 &dave_fpr.to_string(),
2868 ],
2869 120,
2870 Some(&dave_uid),
2871 None,
2872 false,
2873 &output_map(&human_output),
2874 );
2875
2876 // change sq-wot args
2877 let sqwot_args = &["--certification-network"];
2878
2879 let human_output =
2880 [(1, format!("{} {} {}: ", HR_OK, &bob_fpr, &bob_uid))];
2881 // With --certification-network, she can authenticate them all.
2882 test(
2883 keyring,
2884 trust_root,
2885 sqwot_args,
2886 command,
2887 &[
2888 &alice_fpr.to_string(),
2889 &bob_fpr.to_string(),
2890 ],
2891 120,
2892 Some(&bob_uid),
2893 None,
2894 true,
2895 &output_map(&human_output),
2896 );
2897
2898 let human_output =
2899 [(1, format!("{} {} {}: ", HR_OK, &carol_fpr, &carol_uid))];
2900 test(
2901 keyring,
2902 trust_root,
2903 sqwot_args,
2904 command,
2905 &[
2906 &alice_fpr.to_string(),
2907 &bob_fpr.to_string(),
2908 &carol_fpr.to_string(),
2909 ],
2910 120,
2911 Some(&carol_uid),
2912 None,
2913 true,
2914 &output_map(&human_output),
2915 );
2916
2917 let human_output =
2918 [(1, format!("{} {} {}: ", HR_OK, &dave_fpr, &dave_uid))];
2919 test(
2920 keyring,
2921 trust_root,
2922 sqwot_args,
2923 command,
2924 &[
2925 &alice_fpr.to_string(),
2926 &bob_fpr.to_string(),
2927 &carol_fpr.to_string(),
2928 &dave_fpr.to_string(),
2929 ],
2930 120,
2931 Some(&dave_uid),
2932 None,
2933 true,
2934 &output_map(&human_output),
2935 );
2936
2937 let human_output =
2938 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &carol_fpr, &carol_uid))];
2939 // But invalid paths should stay invalid.
2940 test(
2941 keyring,
2942 trust_root,
2943 sqwot_args,
2944 command,
2945 &[
2946 &alice_fpr.to_string(),
2947 &carol_fpr.to_string(),
2948 ],
2949 120,
2950 Some(&carol_uid),
2951 None,
2952 false,
2953 &output_map(&human_output),
2954 );
2955
2956 // set dave as trust root
2957 let trust_root = &dave_fpr;
2958 // reset sq-wot args again
2959 let sqwot_args = &[];
2960 let human_output =
2961 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &alice_fpr, &alice_uid))];
2962 // dave authenticates alice for 60 of 120.
2963 test(
2964 keyring,
2965 trust_root,
2966 sqwot_args,
2967 command,
2968 &[
2969 &dave_fpr.to_string(),
2970 &alice_fpr.to_string(),
2971 ],
2972 120,
2973 Some(&alice_uid),
2974 None,
2975 false,
2976 &output_map(&human_output),
2977 );
2978
2979 let human_output =
2980 [(1, format!("{} {} {}: ", HR_OK, &alice_fpr, &alice_uid))];
2981 test(
2982 keyring,
2983 trust_root,
2984 sqwot_args,
2985 command,
2986 &[
2987 &dave_fpr.to_string(),
2988 &alice_fpr.to_string(),
2989 ],
2990 60,
2991 Some(&alice_uid),
2992 None,
2993 true,
2994 &output_map(&human_output),
2995 );
2996
2997 // set sq-wot args to use certification network
2998 let sqwot_args = &["--certification-network"];
2999 let human_output =
3000 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &alice_fpr, &alice_uid))];
3001 test(
3002 keyring,
3003 trust_root,
3004 sqwot_args,
3005 command,
3006 &[
3007 &dave_fpr.to_string(),
3008 &alice_fpr.to_string(),
3009 ],
3010 120,
3011 Some(&alice_uid),
3012 None,
3013 false,
3014 &output_map(&human_output),
3015 );
3016
3017 let human_output =
3018 [(1, format!("{} {} {}: ", HR_OK, &alice_fpr, &alice_uid))];
3019 test(
3020 keyring,
3021 trust_root,
3022 sqwot_args,
3023 command,
3024 &[
3025 &dave_fpr.to_string(),
3026 &alice_fpr.to_string(),
3027 ],
3028 60,
3029 Some(&alice_uid),
3030 None,
3031 true,
3032 &output_map(&human_output),
3033 );
3034
3035 // set carol as trust root
3036 let trust_root = &carol_fpr;
3037 // reset sq-wot args again
3038 let sqwot_args = &[];
3039 let human_output =
3040 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &alice_fpr, &alice_uid))];
3041 test(
3042 keyring,
3043 trust_root,
3044 sqwot_args,
3045 command,
3046 &[
3047 &carol_fpr.to_string(),
3048 &dave_fpr.to_string(),
3049 &alice_fpr.to_string(),
3050 ],
3051 60,
3052 Some(&alice_uid),
3053 None,
3054 false,
3055 &output_map(&human_output),
3056 );
3057
3058 // set sq-wot args to use certification network
3059 let sqwot_args = &["--certification-network"];
3060
3061 let human_output =
3062 [(1, format!("{} {} {}: ", HR_OK, &alice_fpr, &alice_uid))];
3063 test(
3064 keyring,
3065 trust_root,
3066 sqwot_args,
3067 command,
3068 &[
3069 &carol_fpr.to_string(),
3070 &dave_fpr.to_string(),
3071 &alice_fpr.to_string(),
3072 ],
3073 60,
3074 Some(&alice_uid),
3075 None,
3076 true,
3077 &output_map(&human_output),
3078 );
3079
3080 let human_output =
3081 [(1, format!("{} {} {}: ", HR_OK, &bob_fpr, &bob_uid))];
3082 test(
3083 keyring,
3084 trust_root,
3085 sqwot_args,
3086 command,
3087 &[
3088 &carol_fpr.to_string(),
3089 &dave_fpr.to_string(),
3090 &alice_fpr.to_string(),
3091 &bob_fpr.to_string(),
3092 ],
3093 60,
3094 Some(&bob_uid),
3095 None,
3096 true,
3097 &output_map(&human_output),
3098 );
3099
3100 Ok(())
3101 }
3102
3103 #[test]
3104 #[allow(unused)]
3105 fn gossip_certification_network() -> Result<()> {
3106 let alice_fpr: Fingerprint =
3107 "B2B371214EF71AFD16E42C62D81360B4C0489225"
3108 .parse().expect("valid fingerprint");
3109 let alice_uid
3110 = UserIDArg::UserID("<[email protected]>");
3111 // Certified by: 9A1AE937B5CB8BC46048AB63023CC01973ED9DF3
3112
3113 let bob_fpr: Fingerprint =
3114 "A68DF00EB82F9C49C27CC7723C5F5BBE6B790C05"
3115 .parse().expect("valid fingerprint");
3116 let bob_uid
3117 = UserIDArg::UserID("<[email protected]>");
3118 // Certified by: B2B371214EF71AFD16E42C62D81360B4C0489225
3119
3120 let carol_fpr: Fingerprint =
3121 "AB9EF1C89631519842ED559697557DD147D99C97"
3122 .parse().expect("valid fingerprint");
3123 let carol_uid
3124 = UserIDArg::UserID("<[email protected]>");
3125 // Certified by: A68DF00EB82F9C49C27CC7723C5F5BBE6B790C05
3126
3127 let dave_fpr: Fingerprint =
3128 "9A1AE937B5CB8BC46048AB63023CC01973ED9DF3"
3129 .parse().expect("valid fingerprint");
3130 let dave_uid
3131 = UserIDArg::UserID("<[email protected]>");
3132 // Certified by: AB9EF1C89631519842ED559697557DD147D99C97
3133
3134 // defaults
3135 let keyring = "certification-network.pgp";
3136 let trust_root = None;
3137 let sqwot_args = &["--gossip"];
3138 let command = "authenticate";
3139 let args = &[];
3140
3141 let human_output =
3142 [(1, format!("- {} {}", HR_NOT_OK, &bob_uid))];
3143 // Alice certified Bob. Although the path is unauthenticated (the
3144 // path is not from a trust root), we should print it: the user
3145 // asked for gossip.
3146 test(
3147 keyring,
3148 trust_root,
3149 sqwot_args,
3150 command,
3151 args,
3152 120,
3153 Some(&bob_uid),
3154 Some(&bob_fpr),
3155 true,
3156 &output_map(&human_output),
3157 );
3158
3159 let trust_root = &alice_fpr;
3160 // Even when we specify --gossip, paths are authenticated as much
3161 // as possible.
3162 let human_output =
3163 [(1, format!("- {} {}", HR_OK, &bob_uid))];
3164 test(
3165 keyring,
3166 trust_root,
3167 sqwot_args,
3168 command,
3169 args,
3170 120,
3171 Some(&bob_uid),
3172 Some(&bob_fpr),
3173 true,
3174 &output_map(&human_output),
3175 );
3176
3177 Ok(())
3178 }
3179
3180 #[test]
3181 #[allow(unused)]
3182 fn target_cert_expired() -> Result<()> {
3183 let alice_fpr: Fingerprint =
3184 "1FA62523FB7C06E71EEFB82BB5159F3FC3EB3AC9"
3185 .parse().expect("valid fingerprint");
3186 let alice_uid
3187 = UserIDArg::UserID("<[email protected]>");
3188
3189 let bob_fpr: Fingerprint =
3190 "B166B31AE5F95600B3F7184FE74C6CE62821686F"
3191 .parse().expect("valid fingerprint");
3192 let bob_uid
3193 = UserIDArg::UserID("<[email protected]>");
3194 // Certified by: 1FA62523FB7C06E71EEFB82BB5159F3FC3EB3AC9
3195
3196 let carol_fpr: Fingerprint =
3197 "81CD118AC5BD9156DC113772626222D76ACDFFCF"
3198 .parse().expect("valid fingerprint");
3199 let carol_uid
3200 = UserIDArg::UserID("<[email protected]>");
3201 // Certified by: B166B31AE5F95600B3F7184FE74C6CE62821686F
3202
3203 // $ date '+%s' -d 20200202
3204 // 1580598000
3205 let t1 = std::time::UNIX_EPOCH + time::Duration::new(1580598000, 0);
3206 // $ date '+%s' -d 20200302
3207 // 1583103600
3208 let t2 = std::time::UNIX_EPOCH + time::Duration::new(1583103600, 0);
3209 // $ date '+%s' -d 20200402
3210 // 1585778400
3211 let t3 = std::time::UNIX_EPOCH + time::Duration::new(1585778400, 0);
3212
3213 // At t1, Alice certifies Bob (amount = 60).
3214 // At t2, Bob's certificate expires.
3215
3216 // defaults
3217 let keyring = "cert-expired.pgp";
3218 let trust_root: Option<&Fingerprint> = Some(&alice_fpr);
3219 let sqwot_args = &[];
3220 let command = "authenticate";
3221
3222 let human_output =
3223 [(1, format!("- {} {}", HR_OK, &bob_uid))];
3224 // Bob's certificate is not yet expired.
3225 test(
3226 keyring,
3227 trust_root,
3228 sqwot_args,
3229 command,
3230 &["--time", "20200214"],
3231 60,
3232 Some(&bob_uid),
3233 Some(&bob_fpr),
3234 true,
3235 &output_map(&human_output),
3236 );
3237
3238 let trust_root = None; // no trust root for path
3239 let command = "path";
3240 let human_output =
3241 [(1, format!("{} {} {}: ", HR_OK, &bob_fpr, &bob_uid))];
3242 test(
3243 keyring,
3244 trust_root,
3245 sqwot_args,
3246 command,
3247 &[
3248 "--time",
3249 "20200214",
3250 &alice_fpr.to_string(),
3251 &bob_fpr.to_string(),
3252 ],
3253 60,
3254 Some(&bob_uid),
3255 None,
3256 true,
3257 &output_map(&human_output),
3258 );
3259
3260 let trust_root = Some(&alice_fpr);
3261 let command = "authenticate";
3262 // Bob's certificate is expired.
3263 test(
3264 keyring,
3265 trust_root,
3266 sqwot_args,
3267 command,
3268 &["--time", "20200216"],
3269 60,
3270 Some(&bob_uid),
3271 Some(&bob_fpr),
3272 false,
3273 no_output(),
3274 );
3275
3276 let trust_root = None;
3277 let command = "path";
3278 let human_output =
3279 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &bob_fpr, &bob_uid))];
3280 test(
3281 keyring,
3282 trust_root,
3283 sqwot_args,
3284 command,
3285 &[
3286 "--time",
3287 "20200216",
3288 &alice_fpr.to_string(),
3289 &bob_fpr.to_string(),
3290 ],
3291 60,
3292 Some(&bob_uid),
3293 None,
3294 false,
3295 &output_map(&human_output),
3296 );
3297
3298 Ok(())
3299 }
3300
3301 #[test]
3302 #[allow(unused)]
3303 fn target_cert_hard_revoked() -> Result<()> {
3304 let alice_fpr: Fingerprint =
3305 "219AAB661C8AAF4526DBC31AA751A7A0532863BA"
3306 .parse().expect("valid fingerprint");
3307 let alice_uid
3308 = UserIDArg::UserID("<[email protected]>");
3309
3310 let bob_fpr: Fingerprint =
3311 "90E02BFB03FAA04714D1D3D87543157EF3B12BE9"
3312 .parse().expect("valid fingerprint");
3313 let bob_uid
3314 = UserIDArg::UserID("<[email protected]>");
3315 // Certified by: 219AAB661C8AAF4526DBC31AA751A7A0532863BA
3316 // Certified by: 219AAB661C8AAF4526DBC31AA751A7A0532863BA
3317
3318 let carol_fpr: Fingerprint =
3319 "BF680710128E6BCCB2268154569F5F6BFB95C544"
3320 .parse().expect("valid fingerprint");
3321 let carol_uid
3322 = UserIDArg::UserID("<[email protected]>");
3323 // Certified by: 219AAB661C8AAF4526DBC31AA751A7A0532863BA
3324
3325 let dave_fpr: Fingerprint =
3326 "46945292F8F643F0573AF71183F9C1A4759A16D6"
3327 .parse().expect("valid fingerprint");
3328 let dave_uid
3329 = UserIDArg::UserID("<[email protected]>");
3330 // Certified by: 90E02BFB03FAA04714D1D3D87543157EF3B12BE9
3331 // Certified by: BF680710128E6BCCB2268154569F5F6BFB95C544
3332 // Certified by: 90E02BFB03FAA04714D1D3D87543157EF3B12BE9
3333
3334 // defaults
3335 let keyring = "cert-revoked-hard.pgp";
3336 let trust_root: Option<&Fingerprint> = Some(&alice_fpr);
3337 let sqwot_args = &[];
3338 let command = "authenticate";
3339
3340 // Bob's certificate is hard revoked.
3341 test(
3342 keyring,
3343 trust_root,
3344 sqwot_args,
3345 command,
3346 &[],
3347 60,
3348 Some(&bob_uid),
3349 Some(&bob_fpr),
3350 false,
3351 no_output(),
3352 );
3353
3354 let trust_root: Option<&Fingerprint> = None;
3355 let command = "path";
3356 let human_output =
3357 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &bob_fpr, &bob_uid))];
3358 test(
3359 keyring,
3360 trust_root,
3361 sqwot_args,
3362 command,
3363 &[
3364 &alice_fpr.to_string(),
3365 &bob_fpr.to_string(),
3366 ],
3367 60,
3368 Some(&bob_uid),
3369 None,
3370 false,
3371 &output_map(&human_output),
3372 );
3373
3374 Ok(())
3375 }
3376
3377 #[test]
3378 #[allow(unused)]
3379 fn target_cert_soft_revoked() -> Result<()> {
3380 let alice_fpr: Fingerprint =
3381 "66037F98B444BBAFDFE98E871738DFAB86878262"
3382 .parse().expect("valid fingerprint");
3383 let alice_uid
3384 = UserIDArg::UserID("<[email protected]>");
3385
3386 let bob_fpr: Fingerprint =
3387 "4CD8737F76C2B897C4F058DBF28C47540FA2C3B3"
3388 .parse().expect("valid fingerprint");
3389 let bob_uid
3390 = UserIDArg::UserID("<[email protected]>");
3391 // Certified by: 66037F98B444BBAFDFE98E871738DFAB86878262
3392
3393 let carol_fpr: Fingerprint =
3394 "AB4E3F8EE8BBD3459754D75ACE570F9B8C7DC75D"
3395 .parse().expect("valid fingerprint");
3396 let carol_uid
3397 = UserIDArg::UserID("<[email protected]>");
3398 // Certified by: 66037F98B444BBAFDFE98E871738DFAB86878262
3399
3400 let dave_fpr: Fingerprint =
3401 "DF6A440ED9DE723B0EBC7F50E24FBB1B9FADC999"
3402 .parse().expect("valid fingerprint");
3403 let dave_uid
3404 = UserIDArg::UserID("<[email protected]>");
3405 // Certified by: 4CD8737F76C2B897C4F058DBF28C47540FA2C3B3
3406 // Certified by: AB4E3F8EE8BBD3459754D75ACE570F9B8C7DC75D
3407 // Certified by: 4CD8737F76C2B897C4F058DBF28C47540FA2C3B3
3408
3409 // defaults
3410 let keyring = "cert-revoked-soft.pgp";
3411 let trust_root: Option<&Fingerprint> = Some(&alice_fpr);
3412 let sqwot_args = &["--time", "20200228"];
3413 let command = "authenticate";
3414 let args = &[];
3415
3416 let human_output =
3417 [(1, format!("- {} {}", HR_OK, &bob_uid))];
3418 // Bob's certificate is soft revoked on 20200301. If the
3419 // reference time is before that, we should be able to
3420 // authenticate Bob. After that and we should fail to do so.
3421 test(
3422 keyring,
3423 trust_root,
3424 sqwot_args,
3425 command,
3426 args,
3427 60,
3428 Some(&bob_uid),
3429 Some(&bob_fpr),
3430 true,
3431 &output_map(&human_output),
3432 );
3433
3434 let trust_root: Option<&Fingerprint> = None; // no trust root for binding
3435 let command = "path";
3436 let human_output =
3437 [(1, format!("{} {} {}: ", HR_OK, &bob_fpr, &bob_uid))];
3438 test(
3439 keyring,
3440 trust_root,
3441 sqwot_args,
3442 command,
3443 &[
3444 &alice_fpr.to_string(),
3445 &bob_fpr.to_string(),
3446 ],
3447 60,
3448 Some(&bob_uid),
3449 None,
3450 true,
3451 &output_map(&human_output),
3452 );
3453
3454 let trust_root: Option<&Fingerprint> = Some(&alice_fpr);
3455 let command = "authenticate";
3456 let sqwot_args = &["--time", "20200302"]; // setting time again
3457
3458 test(
3459 keyring,
3460 trust_root,
3461 sqwot_args,
3462 command,
3463 &[],
3464 60,
3465 Some(&bob_uid),
3466 Some(&bob_fpr),
3467 false,
3468 no_output(),
3469 );
3470
3471 let command = "path";
3472 let human_output =
3473 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &bob_fpr, &bob_uid))];
3474 test(
3475 keyring,
3476 trust_root,
3477 sqwot_args,
3478 command,
3479 &[
3480 &alice_fpr.to_string(),
3481 &bob_fpr.to_string(),
3482 ],
3483 60,
3484 Some(&bob_uid),
3485 None,
3486 false,
3487 &output_map(&human_output),
3488 );
3489
3490 Ok(())
3491 }
3492
3493 #[test]
3494 #[allow(unused)]
3495 fn target_userid_revoked() -> Result<()> {
3496 let alice_fpr: Fingerprint =
3497 "01672BB67E4B4047E5A4EC0A731CEA092C465FC8"
3498 .parse().expect("valid fingerprint");
3499 let alice_uid
3500 = UserIDArg::UserID("<[email protected]>");
3501
3502 let bob_fpr: Fingerprint =
3503 "EA479A77CD074458EAFE56B4861BF42FF490C581"
3504 .parse().expect("valid fingerprint");
3505 let bob_uid
3506 = UserIDArg::UserID("<[email protected]>");
3507 // Certified by: 01672BB67E4B4047E5A4EC0A731CEA092C465FC8
3508 // Certified by: 01672BB67E4B4047E5A4EC0A731CEA092C465FC8
3509
3510 let carol_fpr: Fingerprint =
3511 "212873BB9C4CC49F8E5A6FEA78BC5397470BA7F0"
3512 .parse().expect("valid fingerprint");
3513 let carol_uid
3514 = UserIDArg::UserID("<[email protected]>");
3515 // Certified by: EA479A77CD074458EAFE56B4861BF42FF490C581
3516 // Certified by: EA479A77CD074458EAFE56B4861BF42FF490C581
3517
3518 // defaults
3519 let keyring = "userid-revoked.pgp";
3520 let trust_root = Some(&alice_fpr);
3521 let sqwot_args = &["--time", "20200228"];
3522 let command = "authenticate";
3523
3524 let human_output =
3525 [(1, format!("- {} {}", HR_OK, &bob_uid))];
3526 // Bob's User ID is soft revoked on 20200301. If the
3527 // reference time is before that, we should be able to
3528 // authenticate Bob. After that and we should fail to do so.
3529 test(
3530 keyring,
3531 trust_root,
3532 sqwot_args,
3533 command,
3534 &[],
3535 60,
3536 Some(&bob_uid),
3537 Some(&bob_fpr),
3538 true,
3539 &output_map(&human_output),
3540 );
3541
3542 let trust_root = None;
3543 let command = "path";
3544 let human_output =
3545 [(1, format!("{} {} {}: ", HR_OK, &bob_fpr, &bob_uid))];
3546 test(
3547 keyring,
3548 trust_root,
3549 sqwot_args,
3550 command,
3551 &[
3552 &alice_fpr.to_string(),
3553 &bob_fpr.to_string(),
3554 ],
3555 60,
3556 Some(&bob_uid),
3557 None,
3558 true,
3559 &output_map(&human_output),
3560 );
3561
3562 let trust_root = Some(&alice_fpr);
3563 let sqwot_args = &["--time", "20200302"];
3564 let command = "authenticate";
3565 test(
3566 keyring,
3567 trust_root,
3568 sqwot_args,
3569 command,
3570 &[],
3571 60,
3572 Some(&bob_uid),
3573 Some(&bob_fpr),
3574 false,
3575 no_output(),
3576 );
3577
3578 let trust_root = None;
3579 let command = "path";
3580 let human_output =
3581 [(1, format!("{} {} {}: ", HR_NOT_OK_EMPTY, &bob_fpr, &bob_uid))];
3582 test(
3583 keyring,
3584 trust_root,
3585 sqwot_args,
3586 command,
3587 &[
3588 &alice_fpr.to_string(),
3589 &bob_fpr.to_string(),
3590 ],
3591 60,
3592 Some(&bob_uid),
3593 None,
3594 false,
3595 &output_map(&human_output),
3596 );
3597
3598 Ok(())
3599 }