diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-02-09 16:00:23 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-02-09 16:00:23 +0900 |
commit | 5ce840383da7cf82ffa7dfaeda187f3fe3d591a7 (patch) | |
tree | f93fb33cde2a62aa414b61dca085f3fd0613aaca /tests | |
parent | d9f0d99e31569835e295b990029c6dd19554299c (diff) | |
download | gpg2-5ce840383da7cf82ffa7dfaeda187f3fe3d591a7.tar.gz gpg2-5ce840383da7cf82ffa7dfaeda187f3fe3d591a7.tar.bz2 gpg2-5ce840383da7cf82ffa7dfaeda187f3fe3d591a7.zip |
Imported Upstream version 2.1.22upstream/2.1.22
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fake-pinentries/README.txt | 2 | ||||
-rw-r--r-- | tests/gpgme/gpgme-defs.scm | 4 | ||||
-rw-r--r-- | tests/gpgscm/ffi.c | 2 | ||||
-rw-r--r-- | tests/gpgscm/ffi.scm | 3 | ||||
-rw-r--r-- | tests/gpgscm/init.scm | 6 | ||||
-rw-r--r-- | tests/gpgscm/main.c | 19 | ||||
-rw-r--r-- | tests/gpgscm/repl.scm | 12 | ||||
-rw-r--r-- | tests/gpgscm/scheme.c | 53 | ||||
-rw-r--r-- | tests/gpgscm/tests.scm | 128 | ||||
-rw-r--r-- | tests/gpgsm/gpgsm-defs.scm | 4 | ||||
-rw-r--r-- | tests/openpgp/Makefile.am | 3 | ||||
-rw-r--r-- | tests/openpgp/all-tests.scm | 22 | ||||
-rw-r--r-- | tests/openpgp/defs.scm | 10 | ||||
-rwxr-xr-x | tests/openpgp/gpgv.scm | 75 | ||||
-rw-r--r-- | tests/openpgp/shell.scm | 28 | ||||
-rw-r--r-- | tests/openpgp/signed-messages.scm | 281 | ||||
-rwxr-xr-x | tests/openpgp/ssh-export.scm | 4 | ||||
-rwxr-xr-x | tests/openpgp/verify.scm | 268 |
18 files changed, 588 insertions, 336 deletions
diff --git a/tests/fake-pinentries/README.txt b/tests/fake-pinentries/README.txt index 9272ae5..0654f56 100644 --- a/tests/fake-pinentries/README.txt +++ b/tests/fake-pinentries/README.txt @@ -35,4 +35,4 @@ Troubleshooting If you have any trouble with this technique, please drop a line to the GnuPG development mailing list <gnupg-devel@gnupg.org> or open a -report on the GnuPG bug tracker at https://bugs.gnupg.org/gnupg +report on the GnuPG bug tracker at https://dev.gnupg.org/gnupg diff --git a/tests/gpgme/gpgme-defs.scm b/tests/gpgme/gpgme-defs.scm index e24db25..0de589f 100644 --- a/tests/gpgme/gpgme-defs.scm +++ b/tests/gpgme/gpgme-defs.scm @@ -66,7 +66,9 @@ (string-append "agent-program " (tool 'gpg-agent) "|--debug-quick-random\n")) (create-file "gpg-agent.conf" - (string-append "pinentry-program " (tool 'pinentry))) + (string-append "pinentry-program " (tool 'pinentry)) + (string-append "scdaemon-program " (tool 'scdaemon)) + ) (start-agent) diff --git a/tests/gpgscm/ffi.c b/tests/gpgscm/ffi.c index 3af3328..4c03ba6 100644 --- a/tests/gpgscm/ffi.c +++ b/tests/gpgscm/ffi.c @@ -915,6 +915,8 @@ do_wait_processes (scheme *sc, pointer args) retcodes); if (err == GPG_ERR_GENERAL) err = 0; /* Let the return codes speak. */ + if (err == GPG_ERR_TIMEOUT) + err = 0; /* We may have got some results. */ for (i = 0; i < count; i++) retcodes_list = diff --git a/tests/gpgscm/ffi.scm b/tests/gpgscm/ffi.scm index 3f2e553..051c2c2 100644 --- a/tests/gpgscm/ffi.scm +++ b/tests/gpgscm/ffi.scm @@ -36,8 +36,7 @@ (define (ffi-fail name args message) (let ((args' (open-output-string))) (write (cons (string->symbol name) args) args') - (throw (string-append - (get-output-string args') ": " message)))) + (throw (get-output-string args') message))) ;; Pseudo-definitions for foreign functions. Evaluates to no code, ;; but serves as documentation. diff --git a/tests/gpgscm/init.scm b/tests/gpgscm/init.scm index 3769ed0..66bec0f 100644 --- a/tests/gpgscm/init.scm +++ b/tests/gpgscm/init.scm @@ -605,17 +605,17 @@ ;; This is used by the vm to throw exceptions. (define (throw' message args history) (cond - ((more-handlers?) - ((pop-handler) message args history)) ((and args (list? args) (= 2 (length args)) (equal? *interpreter-exit* (car args))) (*run-atexit-handlers*) (quit (cadr args))) + ((more-handlers?) + ((pop-handler) message args history)) (else (display message) (when (and args (not (null? args))) (display ": ") - (if (string? (car args)) + (if (and (pair? args) (string? (car args))) (begin (display (car args)) (unless (null? (cdr args)) (newline) diff --git a/tests/gpgscm/main.c b/tests/gpgscm/main.c index e4b535e..5540ac3 100644 --- a/tests/gpgscm/main.c +++ b/tests/gpgscm/main.c @@ -124,6 +124,19 @@ my_strusage( int level ) } + +static int +path_absolute_p (const char *p) +{ +#if _WIN32 + return ((strlen (p) > 2 && p[1] == ':' && (p[2] == '\\' || p[2] == '/')) + || p[0] == '\\' || p[0] == '/'); +#else + return p[0] == '/'; +#endif +} + + /* Load the Scheme program from FILE_NAME. If FILE_NAME is not an absolute path, and LOOKUP_IN_PATH is given, then it is qualified with the values in scmpath until the file is found. */ @@ -139,9 +152,9 @@ load (scheme *sc, char *file_name, FILE *h = NULL; use_path = - lookup_in_path && ! (file_name[0] == '/' || scmpath_len == 0); + lookup_in_path && ! (path_absolute_p (file_name) || scmpath_len == 0); - if (file_name[0] == '/' || lookup_in_cwd || scmpath_len == 0) + if (path_absolute_p (file_name) || lookup_in_cwd || scmpath_len == 0) { h = fopen (file_name, "r"); if (! h) @@ -182,7 +195,7 @@ load (scheme *sc, char *file_name, "of the Scheme library.\n"); goto leave; } - if (verbose > 1) + if (verbose > 2) fprintf (stderr, "Loading %s...\n", qualified_name); #if HAVE_MMAP diff --git a/tests/gpgscm/repl.scm b/tests/gpgscm/repl.scm index 84454dc..833ec0d 100644 --- a/tests/gpgscm/repl.scm +++ b/tests/gpgscm/repl.scm @@ -55,3 +55,15 @@ (define (interactive-repl . environment) (repl (lambda (p) (prompt-append-prefix "gpgscm " p)) (if (null? environment) (interaction-environment) (car environment)))) + +;; Ask a yes/no question. +(define (prompt-yes-no? question default) + (let ((answer (prompt (string-append question "? [" + (if default "Y/n" "y/N") "] ")))) + (cond + ((= 0 (string-length answer)) + default) + ((or (equal? "y" answer) (equal? "Y" answer)) + #t) + (else + #f)))) diff --git a/tests/gpgscm/scheme.c b/tests/gpgscm/scheme.c index 26bb5a5..f5e52fc 100644 --- a/tests/gpgscm/scheme.c +++ b/tests/gpgscm/scheme.c @@ -3451,9 +3451,10 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { double dd; #endif int (*comp_func)(num, num) = NULL; - const struct op_code_info *pcd = &dispatch_table[op]; + const struct op_code_info *pcd; dispatch: + pcd = &dispatch_table[op]; if (pcd->name[0] != 0) { /* if built-in function, check arguments */ char msg[STRBUFFSIZE]; if (! check_arguments (sc, pcd, msg, sizeof msg)) { @@ -3564,7 +3565,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { if (x != sc->NIL) { s_return(sc,slot_value_in_env(x)); } else { - Error_1(sc,"eval: unbound variable:", sc->code); + Error_1(sc, "eval: unbound variable", sc->code); } } else if (is_pair(sc->code)) { if (is_syntax(x = car(sc->code))) { /* SYNTAX */ @@ -3676,7 +3677,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { for (x = car(closure_code(sc->code)), y = sc->args; is_pair(x); x = cdr(x), y = cdr(y)) { if (y == sc->NIL) { - Error_1(sc, "not enough arguments, missing:", x); + Error_1(sc, "not enough arguments, missing", x); } else if (is_symbol(car(x))) { new_slot_in_env(sc, car(x), car(y)); } else { @@ -3691,7 +3692,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { } else if (is_symbol(x)) new_slot_in_env(sc, x, y); else { - Error_1(sc,"syntax error in closure: not a symbol:", x); + Error_1(sc, "syntax error in closure: not a symbol", x); } sc->code = cdr(closure_code(sc->code)); sc->args = sc->NIL; @@ -3804,7 +3805,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { set_slot_in_env(sc, y, sc->value); s_return(sc,sc->value); } else { - Error_1(sc,"set!: unbound variable:", sc->code); + Error_1(sc, "set!: unbound variable", sc->code); } @@ -3854,7 +3855,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { if (is_pair(sc->code)) { /* continue */ if (!is_pair(car(sc->code)) || !is_pair(cdar(sc->code))) { gc_enable(sc); - Error_1(sc, "Bad syntax of binding spec in let :", + Error_1(sc, "Bad syntax of binding spec in let", car(sc->code)); } s_save(sc,OP_LET1, sc->args, cdr(sc->code)); @@ -3880,9 +3881,9 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { if (is_symbol(car(sc->code))) { /* named let */ for (x = cadr(sc->code), sc->args = sc->NIL; x != sc->NIL; x = cdr(x)) { if (!is_pair(x)) - Error_1(sc, "Bad syntax of binding in let :", x); + Error_1(sc, "Bad syntax of binding in let", x); if (!is_list(sc, car(x))) - Error_1(sc, "Bad syntax of binding in let :", car(x)); + Error_1(sc, "Bad syntax of binding in let", car(x)); gc_disable(sc, 1); sc->args = cons(sc, caar(x), sc->args); gc_enable(sc); @@ -3906,7 +3907,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { s_thread_to(sc,OP_BEGIN); } if(!is_pair(car(sc->code)) || !is_pair(caar(sc->code)) || !is_pair(cdaar(sc->code))) { - Error_1(sc,"Bad syntax of binding spec in let* :",car(sc->code)); + Error_1(sc, "Bad syntax of binding spec in let*", car(sc->code)); } s_save(sc,OP_LET1AST, cdr(sc->code), car(sc->code)); sc->code = cadaar(sc->code); @@ -3945,7 +3946,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { gc_enable(sc); if (is_pair(sc->code)) { /* continue */ if (!is_pair(car(sc->code)) || !is_pair(cdar(sc->code))) { - Error_1(sc, "Bad syntax of binding spec in letrec :", + Error_1(sc, "Bad syntax of binding spec in letrec", car(sc->code)); } s_save(sc,OP_LET1REC, sc->args, cdr(sc->code)); @@ -4164,7 +4165,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { } else if(modf(rvalue_unchecked(x),&dd)==0.0) { s_return(sc,mk_integer(sc,ivalue(x))); } else { - Error_1(sc,"inexact->exact: not integral:",x); + Error_1(sc, "inexact->exact: not integral", x); } CASE(OP_EXP): @@ -4424,7 +4425,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { } } if (pf < 0) { - Error_1(sc, "string->atom: bad base:", cadr(sc->args)); + Error_1(sc, "string->atom: bad base", cadr(sc->args)); } else if(*s=='#') /* no use of base! */ { s_return(sc, mk_sharp_const(sc, s+1)); } else { @@ -4465,7 +4466,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { } } if (pf < 0) { - Error_1(sc, "atom->string: bad base:", cadr(sc->args)); + Error_1(sc, "atom->string: bad base", cadr(sc->args)); } else if(is_number(x) || is_character(x) || is_string(x) || is_symbol(x)) { char *p; int len; @@ -4473,7 +4474,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { gc_disable(sc, 1); s_return_enable_gc(sc, mk_counted_string(sc, p, len)); } else { - Error_1(sc, "atom->string: not an atom:", x); + Error_1(sc, "atom->string: not an atom", x); } } @@ -4503,7 +4504,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { index=ivalue(cadr(sc->args)); if(index>=strlength(car(sc->args))) { - Error_1(sc,"string-ref: out of bounds:",cadr(sc->args)); + Error_1(sc, "string-ref: out of bounds", cadr(sc->args)); } gc_disable(sc, 1); @@ -4517,13 +4518,14 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { int c; if(is_immutable(car(sc->args))) { - Error_1(sc,"string-set!: unable to alter immutable string:",car(sc->args)); + Error_1(sc, "string-set!: unable to alter immutable string", + car(sc->args)); } str=strvalue(car(sc->args)); index=ivalue(cadr(sc->args)); if(index>=strlength(car(sc->args))) { - Error_1(sc,"string-set!: out of bounds:",cadr(sc->args)); + Error_1(sc, "string-set!: out of bounds", cadr(sc->args)); } c=charvalue(caddr(sc->args)); @@ -4562,13 +4564,13 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { index0=ivalue(cadr(sc->args)); if(index0>strlength(car(sc->args))) { - Error_1(sc,"substring: start out of bounds:",cadr(sc->args)); + Error_1(sc, "substring: start out of bounds", cadr(sc->args)); } if(cddr(sc->args)!=sc->NIL) { index1=ivalue(caddr(sc->args)); if(index1>strlength(car(sc->args)) || index1<index0) { - Error_1(sc,"substring: end out of bounds:",caddr(sc->args)); + Error_1(sc, "substring: end out of bounds", caddr(sc->args)); } } else { index1=strlength(car(sc->args)); @@ -4583,7 +4585,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { pointer vec; int len=list_length(sc,sc->args); if(len<0) { - Error_1(sc,"vector: not a proper list:",sc->args); + Error_1(sc, "vector: not a proper list", sc->args); } vec=mk_vector(sc,len); if(sc->no_memory) { s_return(sc, sc->sink); } @@ -4621,7 +4623,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { index=ivalue(cadr(sc->args)); if(index >= vector_length(car(sc->args))) { - Error_1(sc,"vector-ref: out of bounds:",cadr(sc->args)); + Error_1(sc, "vector-ref: out of bounds", cadr(sc->args)); } s_return(sc,vector_elem(car(sc->args),index)); @@ -4631,12 +4633,13 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { int index; if(is_immutable(car(sc->args))) { - Error_1(sc,"vector-set!: unable to alter immutable vector:",car(sc->args)); + Error_1(sc, "vector-set!: unable to alter immutable vector", + car(sc->args)); } index=ivalue(cadr(sc->args)); if(index >= vector_length(car(sc->args))) { - Error_1(sc,"vector-set!: out of bounds:",cadr(sc->args)); + Error_1(sc, "vector-set!: out of bounds", cadr(sc->args)); } set_vector_elem(car(sc->args),index,caddr(sc->args)); @@ -4979,7 +4982,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { s_thread_to(sc,OP_READ_INTERNAL); } if(!is_inport(car(sc->args))) { - Error_1(sc,"read: not an input port:",car(sc->args)); + Error_1(sc, "read: not an input port", car(sc->args)); } if(car(sc->args)==sc->inport) { s_thread_to(sc,OP_READ_INTERNAL); @@ -5257,7 +5260,7 @@ Eval_Cycle(scheme *sc, enum scheme_opcodes op) { CASE(OP_LIST_LENGTH): { /* length */ /* a.k */ long l = list_length(sc, car(sc->args)); if(l<0) { - Error_1(sc,"length: not a list:",car(sc->args)); + Error_1(sc, "length: not a list", car(sc->args)); } gc_disable(sc, 1); s_return_enable_gc(sc, mk_integer(sc, l)); diff --git a/tests/gpgscm/tests.scm b/tests/gpgscm/tests.scm index eee8ce5..40ba7e3 100644 --- a/tests/gpgscm/tests.scm +++ b/tests/gpgscm/tests.scm @@ -192,6 +192,16 @@ (define (in-srcdir . names) (canonical-path (apply path-join (cons (getenv "abs_top_srcdir") names)))) +;; Split a list of paths. +(define (pathsep-split s) + (string-split s *pathsep*)) + +;; Join a list of paths. +(define (pathsep-join paths) + (foldr (lambda (a b) (string-append a (string *pathsep*) b)) + (car paths) + (cdr paths))) + ;; Try to find NAME in PATHS. Returns the full path name on success, ;; or raises an error. (define (path-expand name paths) @@ -209,7 +219,7 @@ ;; (load (with-path "library.scm")) (define (with-path name) (catch name - (path-expand name (string-split (getenv "GPGSCM_PATH") *pathsep*)))) + (path-expand name (pathsep-split (getenv "GPGSCM_PATH"))))) (define (basename path) (let ((i (string-index path #\/))) @@ -498,29 +508,98 @@ ;; The main test framework. ;; +(define semaphore + (package + (define (new n) + (package + (define (acquire!?) + (if (> n 0) + (begin + (set! n (- n 1)) + #t) + #f)) + (define (release!) + (set! n (+ n 1))))))) + ;; A pool of tests. (define test-pool (package - (define (new procs) + (define (new n) (package + ;; A semaphore to restrict the number of spawned processes. + (define sem (semaphore::new n)) + + ;; A list of enqueued, but not yet run tests. + (define enqueued '()) + + ;; A list of running or finished processes. + (define procs '()) + (define (add test) - (set! procs (cons test procs)) + (if (test::started?) + (set! procs (cons test procs)) + (if (sem::acquire!?) + (add (test::run-async)) + (set! enqueued (cons test enqueued)))) (current-environment)) + + ;; Pop the last of the enqueued tests off the fifo queue. + (define (pop-test!) + (let ((i (length enqueued))) + (assert (> i 0)) + (cond + ((= i 1) + (let ((test (car enqueued))) + (set! enqueued '()) + test)) + (else + (let* ((tail (list-tail enqueued (- i 2))) + (test (cadr tail))) + (set-cdr! tail '()) + (assert (= (length enqueued) (- i 1))) + test))))) + (define (pid->test pid) (let ((t (filter (lambda (x) (= pid x::pid)) procs))) (if (null? t) #f (car t)))) (define (wait) + (if (null? enqueued) + ;; If no tests are enqueued, we can just block until all + ;; of them finished. + (wait' #t) + ;; Otherwise, we must not block, but give some tests the + ;; chance to finish so that we can start new ones. + (begin + (wait' #f) + (usleep (/ 1000000 10)) + (wait)))) + (define (wait' hang) (let ((unfinished (filter (lambda (t) (not t::retcode)) procs))) (if (null? unfinished) (current-environment) (let ((names (map (lambda (t) t::name) unfinished)) - (pids (map (lambda (t) t::pid) unfinished))) + (pids (map (lambda (t) t::pid) unfinished)) + (any #f)) (for-each (lambda (test retcode) - (test::set-end-time!) - (test:::set! 'retcode retcode)) + (unless (< retcode 0) + (test::set-end-time!) + (test:::set! 'retcode retcode) + (test::report) + (sem::release!) + (set! any #t))) (map pid->test pids) - (wait-processes (map stringify names) pids #t))))) + (wait-processes (map stringify names) pids hang)) + + ;; If some processes finished, try to start new ones. + (let loop () + (cond + ((not any) #f) + ((pair? enqueued) + (if (sem::acquire!?) + (let ((test (pop-test!))) + (add (test::run-async)) + (loop))))))))) (current-environment)) (define (filter-tests status) (filter (lambda (p) (eq? status (p::status))) procs)) @@ -629,6 +708,10 @@ (define (set-end-time!) (set! end-time (get-time))) + ;; Has the test been started yet? + (define (started?) + (number? pid)) + (define (open-log-file) (unless log-file-name (set! log-file-name (string-append (basename name) ".log"))) @@ -713,23 +796,22 @@ ;; Run the setup target to create an environment, then run all given ;; tests in parallel. -(define (run-tests-parallel tests) - (let loop ((pool (test-pool::new '())) (tests' tests)) +(define (run-tests-parallel tests n) + (let loop ((pool (test-pool::new n)) (tests' tests)) (if (null? tests') (let ((results (pool::wait))) - (for-each (lambda (t) (t::report)) (reverse results::procs)) ((results::xml) (open-output-file "report.xml")) (exit (results::report))) (let ((wd (mkdtemp-autoremove)) (test (car tests'))) (test:::set! 'directory wd) - (loop (pool::add (test::run-async)) + (loop (pool::add test) (cdr tests')))))) ;; Run the setup target to create an environment, then run all given ;; tests in sequence. (define (run-tests-sequential tests) - (let loop ((pool (test-pool::new '())) (tests' tests)) + (let loop ((pool (test-pool::new 1)) (tests' tests)) (if (null? tests') (let ((results (pool::wait))) ((results::xml) (open-output-file "report.xml")) @@ -743,10 +825,14 @@ ;; Run tests either in sequence or in parallel, depending on the ;; number of tests and the command line flags. (define (run-tests tests) - (if (and (flag "--parallel" *args*) - (> (length tests) 1)) - (run-tests-parallel tests) - (run-tests-sequential tests))) + (let ((parallel (flag "--parallel" *args*)) + (default-parallel-jobs 32)) + (if (and parallel (> (length tests) 1)) + (run-tests-parallel tests (if (and (pair? parallel) + (string->number (car parallel))) + (string->number (car parallel)) + default-parallel-jobs)) + (run-tests-sequential tests)))) ;; Load all tests from the given path. (define (load-tests . path) @@ -762,11 +848,14 @@ (let ((tarball (make-temporary-file "environment-cache"))) (atexit (lambda () (remove-temporary-file tarball))) (setup::run-sync '--create-tarball tarball) + (if (not (equal? 'PASS (setup::status))) + (fail "Setup failed.")) `(--unpack-tarball ,tarball))))) ;; Command line flag handling. Returns the elements following KEY in ;; ARGUMENTS up to the next argument, or #f if KEY is not in -;; ARGUMENTS. +;; ARGUMENTS. If 'KEY=XYZ' is encountered, then the singleton list +;; containing 'XYZ' is returned. (define (flag key arguments) (cond ((null? arguments) @@ -777,6 +866,10 @@ (if (or (null? args) (string-prefix? (car args) "--")) (reverse acc) (loop (cons (car args) acc) (cdr args))))) + ((string-prefix? (car arguments) (string-append key "=")) + (list (substring (car arguments) + (+ (string-length key) 1) + (string-length (car arguments))))) ((string=? "--" (car arguments)) #f) (else @@ -784,6 +877,7 @@ (assert (equal? (flag "--xxx" '("--yyy")) #f)) (assert (equal? (flag "--xxx" '("--xxx")) '())) (assert (equal? (flag "--xxx" '("--xxx" "yyy")) '("yyy"))) +(assert (equal? (flag "--xxx" '("--xxx=foo" "yyy")) '("foo"))) (assert (equal? (flag "--xxx" '("--xxx" "yyy" "zzz")) '("yyy" "zzz"))) (assert (equal? (flag "--xxx" '("--xxx" "yyy" "zzz" "--")) '("yyy" "zzz"))) (assert (equal? (flag "--xxx" '("--xxx" "yyy" "--" "zzz")) '("yyy"))) diff --git a/tests/gpgsm/gpgsm-defs.scm b/tests/gpgsm/gpgsm-defs.scm index 711922a..d99d7da 100644 --- a/tests/gpgsm/gpgsm-defs.scm +++ b/tests/gpgsm/gpgsm-defs.scm @@ -66,7 +66,9 @@ "disable-crl-checks" "faked-system-time 1008241200") (create-file "gpg-agent.conf" - (string-append "pinentry-program " (tool 'pinentry))) + (string-append "pinentry-program " (tool 'pinentry)) + (string-append "scdaemon-program " (tool 'scdaemon)) + ) (start-agent) (create-file "trustlist.txt" diff --git a/tests/openpgp/Makefile.am b/tests/openpgp/Makefile.am index bf9673f..506bce5 100644 --- a/tests/openpgp/Makefile.am +++ b/tests/openpgp/Makefile.am @@ -74,6 +74,7 @@ XTESTS = \ multisig.scm \ verify.scm \ verify-multifile.scm \ + gpgv.scm \ gpgv-forged-keyring.scm \ armor.scm \ import.scm \ @@ -250,7 +251,7 @@ sample_msgs = samplemsgs/clearsig-1-key-1.asc \ EXTRA_DIST = defs.scm $(XTESTS) $(TEST_FILES) \ mkdemodirs signdemokey $(priv_keys) $(sample_keys) \ $(sample_msgs) ChangeLog-2011 run-tests.scm \ - setup.scm shell.scm all-tests.scm + setup.scm shell.scm all-tests.scm signed-messages.scm CLEANFILES = prepared.stamp x y yy z out err $(data_files) \ plain-1 plain-2 plain-3 trustdb.gpg *.lock .\#lk* \ diff --git a/tests/openpgp/all-tests.scm b/tests/openpgp/all-tests.scm index 6584df2..4dd6d6f 100644 --- a/tests/openpgp/all-tests.scm +++ b/tests/openpgp/all-tests.scm @@ -33,13 +33,19 @@ (path-join "tests" "openpgp" "setup.scm") (in-srcdir "tests" "openpgp" "setup.scm")))) - (define setup-use-keyring + (define (qualify path variant) + (string-append "<" variant ">" path)) + + (define (setup* variant) (make-environment-cache (test::scm #f - (string-append "<use-keyring>" (path-join "tests" "openpgp" "setup.scm")) + (qualify (path-join "tests" "openpgp" "setup.scm") variant) (in-srcdir "tests" "openpgp" "setup.scm") - "--use-keyring"))) + (string-append "--" variant)))) + + (define setup-use-keyring (setup* "use-keyring")) + (define setup-extended-key-format (setup* "extended-key-format")) (define all-tests (parse-makefile-expand (in-srcdir "tests" "openpgp" "Makefile.am") @@ -52,7 +58,11 @@ (in-srcdir "tests" "openpgp" name))) all-tests) (map (lambda (name) (test::scm setup-use-keyring - (string-append "<use-keyring>" - (path-join "tests" "openpgp" name)) + (qualify (path-join "tests" "openpgp" name) "use-keyring") + (in-srcdir "tests" "openpgp" name) + "--use-keyring")) all-tests) + (map (lambda (name) + (test::scm setup-extended-key-format + (qualify (path-join "tests" "openpgp" name) "extended-key-format") (in-srcdir "tests" "openpgp" name) - "--use-keyring")) all-tests))) + "--extended-key-format")) all-tests))) diff --git a/tests/openpgp/defs.scm b/tests/openpgp/defs.scm index 1531dc1..b5e3078 100644 --- a/tests/openpgp/defs.scm +++ b/tests/openpgp/defs.scm @@ -316,6 +316,7 @@ (display (make-random-string size) port)))) (define (create-file name . lines) + (catch #f (unlink name)) (letfd ((fd (open name (logior O_WRONLY O_CREAT O_BINARY) #o600))) (let ((port (fdopen fd "wb"))) (for-each (lambda (line) (display line port) (newline port)) @@ -348,7 +349,10 @@ "allow-preset-passphrase" "no-grab" "enable-ssh-support" + (if (flag "--extended-key-format" *args*) + "enable-extended-key-format" "#enable-extended-key-format") (string-append "pinentry-program " (tool 'pinentry)) + (string-append "scdaemon-program " (tool 'scdaemon)) )) ;; Initialize the test environment, install appropriate configuration @@ -447,7 +451,7 @@ (with-home-directory gnupghome (stop-agent))))) (catch (log "Warning: Creating socket directory failed:" (car *error*)) - (call-popen `(,(tool 'gpgconf) --create-socketdir) "")) + (gpg-conf '--create-socketdir)) (call-check `(,(tool 'gpg-connect-agent) --verbose ,(string-append "--agent-program=" (tool 'gpg-agent) "|--debug-quick-random") @@ -456,9 +460,9 @@ ;; Stop the agent and other daemons and remove the socket dir. (define (stop-agent) (log "Stopping gpg-agent...") - (call-check `(,(tool 'gpgconf) --kill all)) + (gpg-conf '--kill 'all) (catch (log "Warning: Removing socket directory failed.") - (call-popen `(,(tool 'gpgconf) --remove-socketdir) ""))) + (gpg-conf '--remove-socketdir))) ;; end diff --git a/tests/openpgp/gpgv.scm b/tests/openpgp/gpgv.scm new file mode 100755 index 0000000..819d15f --- /dev/null +++ b/tests/openpgp/gpgv.scm @@ -0,0 +1,75 @@ +#!/usr/bin/env gpgscm + +;; Copyright (C) 2016-2017 g10 Code GmbH +;; +;; This file is part of GnuPG. +;; +;; GnuPG is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3 of the License, or +;; (at your option) any later version. +;; +;; GnuPG is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program; if not, see <http://www.gnu.org/licenses/>. + +(load (in-srcdir "tests" "openpgp" "defs.scm")) +(load (in-srcdir "tests" "openpgp" "signed-messages.scm")) +(setup-legacy-environment) + +(define keyring (if (file-exists? "pubring.kbx") "pubring.kbx" "pubring.gpg")) + +;; +;; Two simple tests to check that verify fails for bad input data +;; +(for-each-p + "Checking bogus signature" + (lambda (char) + (lettmp (x) + (call-with-binary-output-file + x + (lambda (port) + (display (make-string 64 (integer->char (string->number char))) + port))) + (if (= 0 (call `(,@gpgv --keyring ,keyring ,x data-500))) + (fail "no error code from verify")))) + '("#x2d" "#xca")) + +;; Fixme: We need more tests with manipulated cleartext signatures. + +;; +;; Now run the tests. +;; +(for-each-p + "Checking that a valid signature is verified as such" + (lambda (armored-file) + (pipe:do + (pipe:echo (eval armored-file (current-environment))) + (pipe:spawn `(,@gpgv --keyring ,keyring)))) + '(msg_ols_asc msg_cols_asc msg_sl_asc msg_oolss_asc msg_cls_asc msg_clss_asc)) + +(for-each-p + "Checking that an invalid signature is verified as such" + (lambda (armored-file) + (catch '() + (pipe:do + (pipe:echo (eval armored-file (current-environment))) + (pipe:spawn `(,@gpgv --keyring ,keyring))) + (fail "verification succeeded but should not"))) + '(bad_ls_asc bad_fols_asc bad_olsf_asc bad_ools_asc)) + + +;; Need to import the ed25519 sample key used for the next two tests. +(call-check `(,@gpg --quiet --yes + --import ,(in-srcdir "tests" "openpgp" key-file2))) +(for-each-p + "Checking that a valid Ed25519 signature is verified as such" + (lambda (armored-file) + (pipe:do + (pipe:echo (eval armored-file (current-environment))) + (pipe:spawn `(,@gpgv --keyring ,keyring)))) + '(msg_ed25519_rshort msg_ed25519_sshort)) diff --git a/tests/openpgp/shell.scm b/tests/openpgp/shell.scm index bd6059a..347b3a0 100644 --- a/tests/openpgp/shell.scm +++ b/tests/openpgp/shell.scm @@ -18,7 +18,6 @@ ;; along with this program; if not, see <http://www.gnu.org/licenses/>. (load (in-srcdir "tests" "openpgp" "defs.scm")) -(setup-environment) ;; This is not a test, but can be used to inspect the test ;; environment. Simply execute @@ -27,7 +26,28 @@ ;; ;; to run it. -(echo "Note that gpg.conf includes 'batch'. If you want to use gpg") -(echo "interactively you should drop that.") -(echo) +(if (prompt-yes-no? "Load legacy test environment" #t) + (setup-legacy-environment) + (setup-environment)) + +(if (prompt-yes-no? "Drop 'batch' from gpg.conf" #t) + (apply create-file + (cons "gpg.conf" + (filter (lambda (line) (not (equal? "batch" line))) + (string-split-newlines + (call-with-input-file "gpg.conf" read-all))))) + (begin + (echo "Note that gpg.conf includes 'batch'. If you want to use gpg") + (echo "interactively you should drop that."))) + +;; Add paths to tools to PATH. +(setenv "PATH" (pathsep-join + (append (map (lambda (t) (dirname (tool t))) + '(gpg gpg-agent scdaemon gpgsm dirmngr gpgconf)) + (pathsep-split (getenv "PATH")))) + #t) + +(echo "\nEnjoy your test environment. " + "Type 'exit' to exit it, it will be cleaned up after you.\n") + (interactive-shell) diff --git a/tests/openpgp/signed-messages.scm b/tests/openpgp/signed-messages.scm new file mode 100644 index 0000000..d012f2f --- /dev/null +++ b/tests/openpgp/signed-messages.scm @@ -0,0 +1,281 @@ +;; Copyright (C) 2016 g10 Code GmbH +;; +;; This file is part of GnuPG. +;; +;; GnuPG is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3 of the License, or +;; (at your option) any later version. +;; +;; GnuPG is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with this program; if not, see <http://www.gnu.org/licenses/>. + +;; A plain signed message created using +;; echo abc | gpg --homedir . --passphrase-fd 0 -u Alpha -z0 -sa msg +(define msg_ols_asc " +-----BEGIN PGP MESSAGE----- + +kA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGluayB0aGF0IGFsbCByaWdo +dC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5IGFyZSBzaWNrIGFuZAp0 +aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkgZGVjZW50IHBlb3BsZSBh +cmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJlaW5nIHNpY2sgYW5kIHRp +cmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdtCnNpY2sgYW5kIHRpcmVk +IG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5IFB5dGhvbgqIPwMFAEQM +UlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk01pbAKCIjkzLOAmkZNm0 +D8luT78c/1x45Q== +=a29i +-----END PGP MESSAGE----- +") + +;; A plain signed message created using +;; echo abc | gpg --homedir . --passphrase-fd 0 -u Alpha -sa msg +(define msg_cols_asc " +-----BEGIN PGP MESSAGE----- + +owGbwMvMwCSoW1RzPCOz3IRxLSN7EnNucboLT6Cgp0JJRmZeNpBMLFFIzMlRKMpM +zyjRBQtm5qUrFKTmF+SkKmTmgdQVKyTnl+aVFFUqJBalKhRnJmcrJOalcJVkFqWm +KOSnKSSlgrSU5OekQMzLL0rJzEsEKk9JTU7NK4EZBtKcBtRRWgAzlwtmbnlmSQbU +GJjxCmDj9RQUPNVzFZJTi0oSM/NyKhXy8kuAYk6lJSBxLlTF2NziqZCYq8elq+Cb +n1dSqRBQWZKRn8fVYc/MygAKBljYCDIFiTDMT+9seu836Q+bevyHTJ0dzPNuvCjn +ZpgrwX38z58rJsfYDhwOSS4SkN/d6vUAAA== +=s6sY +-----END PGP MESSAGE----- +") + +;; A PGP 2 style message. +(define msg_sl_asc " +-----BEGIN PGP MESSAGE----- + +iD8DBQBEDFJaLXJ8x2hpdzQRAkeCAKCZRBk2Pmx4w9h2LgosS0AppNNaWwCgiI5M +yzgJpGTZtA/Jbk+/HP9ceOWtAQdiA21zZ0QMUlpJIHRoaW5rIHRoYXQgYWxsIHJp +Z2h0LXRoaW5raW5nIHBlb3BsZSBpbiB0aGlzIGNvdW50cnkgYXJlIHNpY2sgYW5k +CnRpcmVkIG9mIGJlaW5nIHRvbGQgdGhhdCBvcmRpbmFyeSBkZWNlbnQgcGVvcGxl +IGFyZSBmZWQgdXAgaW4gdGhpcwpjb3VudHJ5IHdpdGggYmVpbmcgc2ljayBhbmQg +dGlyZWQuICBJJ20gY2VydGFpbmx5IG5vdC4gIEJ1dCBJJ20Kc2ljayBhbmQgdGly +ZWQgb2YgYmVpbmcgdG9sZCB0aGF0IEkgYW0uCi0gTW9udHkgUHl0aG9uCg== +=0ukK +-----END PGP MESSAGE----- +") + +;; An OpenPGP message lacking the onepass packet. We used to accept +;; such messages but now consider them invalid. +(define bad_ls_asc " +-----BEGIN PGP MESSAGE----- + +rQEHYgNtc2dEDFJaSSB0aGluayB0aGF0IGFsbCByaWdodC10aGlua2luZyBwZW9w +bGUgaW4gdGhpcyBjb3VudHJ5IGFyZSBzaWNrIGFuZAp0aXJlZCBvZiBiZWluZyB0 +b2xkIHRoYXQgb3JkaW5hcnkgZGVjZW50IHBlb3BsZSBhcmUgZmVkIHVwIGluIHRo +aXMKY291bnRyeSB3aXRoIGJlaW5nIHNpY2sgYW5kIHRpcmVkLiAgSSdtIGNlcnRh +aW5seSBub3QuICBCdXQgSSdtCnNpY2sgYW5kIHRpcmVkIG9mIGJlaW5nIHRvbGQg +dGhhdCBJIGFtLgotIE1vbnR5IFB5dGhvbgqIPwMFAEQMUlotcnzHaGl3NBECR4IA +oJlEGTY+bHjD2HYuCixLQCmk01pbAKCIjkzLOAmkZNm0D8luT78c/1x45Q== +=Mpiu +-----END PGP MESSAGE----- +") + + +;; A signed message prefixed with an unsigned literal packet. +;; (fols = faked-literal-data, one-pass, literal-data, signature) +;; This should throw an error because running gpg to extract the +;; signed data will return both literal data packets +(define bad_fols_asc " +-----BEGIN PGP MESSAGE----- + +rF1iDG1zZy51bnNpZ25lZEQMY0x0aW1lc2hhcmluZywgbjoKCUFuIGFjY2VzcyBt +ZXRob2Qgd2hlcmVieSBvbmUgY29tcHV0ZXIgYWJ1c2VzIG1hbnkgcGVvcGxlLgqQ +DQMAAhEtcnzHaGl3NAGtAQdiA21zZ0QMUlpJIHRoaW5rIHRoYXQgYWxsIHJpZ2h0 +LXRoaW5raW5nIHBlb3BsZSBpbiB0aGlzIGNvdW50cnkgYXJlIHNpY2sgYW5kCnRp +cmVkIG9mIGJlaW5nIHRvbGQgdGhhdCBvcmRpbmFyeSBkZWNlbnQgcGVvcGxlIGFy +ZSBmZWQgdXAgaW4gdGhpcwpjb3VudHJ5IHdpdGggYmVpbmcgc2ljayBhbmQgdGly +ZWQuICBJJ20gY2VydGFpbmx5IG5vdC4gIEJ1dCBJJ20Kc2ljayBhbmQgdGlyZWQg +b2YgYmVpbmcgdG9sZCB0aGF0IEkgYW0uCi0gTW9udHkgUHl0aG9uCog/AwUARAxS +Wi1yfMdoaXc0EQJHggCgmUQZNj5seMPYdi4KLEtAKaTTWlsAoIiOTMs4CaRk2bQP +yW5Pvxz/XHjl +=UNM4 +-----END PGP MESSAGE----- +") + +;; A signed message suffixed with an unsigned literal packet. +;; (fols = faked-literal-data, one-pass, literal-data, signature) +;; This should throw an error because running gpg to extract the +;; signed data will return both literal data packets +(define bad_olsf_asc " +-----BEGIN PGP MESSAGE----- + +kA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGluayB0aGF0IGFsbCByaWdo +dC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5IGFyZSBzaWNrIGFuZAp0 +aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkgZGVjZW50IHBlb3BsZSBh +cmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJlaW5nIHNpY2sgYW5kIHRp +cmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdtCnNpY2sgYW5kIHRpcmVk +IG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5IFB5dGhvbgqIPwMFAEQM +UlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk01pbAKCIjkzLOAmkZNm0 +D8luT78c/1x45axdYgxtc2cudW5zaWduZWREDGNMdGltZXNoYXJpbmcsIG46CglB +biBhY2Nlc3MgbWV0aG9kIHdoZXJlYnkgb25lIGNvbXB1dGVyIGFidXNlcyBtYW55 +IHBlb3BsZS4K +=3gnG +-----END PGP MESSAGE----- +") + + +;; Two standard signed messages in a row +(define msg_olsols_asc_multiple " +-----BEGIN PGP MESSAGE----- + +kA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGluayB0aGF0IGFsbCByaWdo +dC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5IGFyZSBzaWNrIGFuZAp0 +aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkgZGVjZW50IHBlb3BsZSBh +cmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJlaW5nIHNpY2sgYW5kIHRp +cmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdtCnNpY2sgYW5kIHRpcmVk +IG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5IFB5dGhvbgqIPwMFAEQM +UlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk01pbAKCIjkzLOAmkZNm0 +D8luT78c/1x45ZANAwACES1yfMdoaXc0Aa0BB2IDbXNnRAxSWkkgdGhpbmsgdGhh +dCBhbGwgcmlnaHQtdGhpbmtpbmcgcGVvcGxlIGluIHRoaXMgY291bnRyeSBhcmUg +c2ljayBhbmQKdGlyZWQgb2YgYmVpbmcgdG9sZCB0aGF0IG9yZGluYXJ5IGRlY2Vu +dCBwZW9wbGUgYXJlIGZlZCB1cCBpbiB0aGlzCmNvdW50cnkgd2l0aCBiZWluZyBz +aWNrIGFuZCB0aXJlZC4gIEknbSBjZXJ0YWlubHkgbm90LiAgQnV0IEknbQpzaWNr +IGFuZCB0aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgSSBhbS4KLSBNb250eSBQeXRo +b24KiD8DBQBEDFJaLXJ8x2hpdzQRAkeCAKCZRBk2Pmx4w9h2LgosS0AppNNaWwCg +iI5MyzgJpGTZtA/Jbk+/HP9ceOU= +=8nLN +-----END PGP MESSAGE----- +") + +;; A standard message with two signatures (actually the same signature +;; duplicated). +(define msg_oolss_asc " +-----BEGIN PGP MESSAGE----- + +kA0DAAIRLXJ8x2hpdzQBkA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGlu +ayB0aGF0IGFsbCByaWdodC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5 +IGFyZSBzaWNrIGFuZAp0aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkg +ZGVjZW50IHBlb3BsZSBhcmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJl +aW5nIHNpY2sgYW5kIHRpcmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdt +CnNpY2sgYW5kIHRpcmVkIG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5 +IFB5dGhvbgqIPwMFAEQMUlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk +01pbAKCIjkzLOAmkZNm0D8luT78c/1x45Yg/AwUARAxSWi1yfMdoaXc0EQJHggCg +mUQZNj5seMPYdi4KLEtAKaTTWlsAoIiOTMs4CaRk2bQPyW5Pvxz/XHjl +=KVw5 +-----END PGP MESSAGE----- +") + +;; A standard message with two one-pass packet but only one signature +;; packet +(define bad_ools_asc " +-----BEGIN PGP MESSAGE----- + +kA0DAAIRLXJ8x2hpdzQBkA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGlu +ayB0aGF0IGFsbCByaWdodC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5 +IGFyZSBzaWNrIGFuZAp0aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkg +ZGVjZW50IHBlb3BsZSBhcmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJl +aW5nIHNpY2sgYW5kIHRpcmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdt +CnNpY2sgYW5kIHRpcmVkIG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5 +IFB5dGhvbgqIPwMFAEQMUlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk +01pbAKCIjkzLOAmkZNm0D8luT78c/1x45Q== +=1/ix +-----END PGP MESSAGE----- +") + +;; Standard cleartext signature +(define msg_cls_asc " +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +I think that all right-thinking people in this country are sick and +tired of being told that ordinary decent people are fed up in this +country with being sick and tired. I'm certainly not. But I'm +sick and tired of being told that I am. +- - Monty Python +-----BEGIN PGP SIGNATURE----- + +iD8DBQFEDVp1LXJ8x2hpdzQRAplUAKCMfpG3GPw/TLN52tosgXP5lNECkwCfQhAa +emmev7IuQjWYrGF9Lxj+zj8= +=qJsY +-----END PGP SIGNATURE----- +") + +;; Cleartext signature with two signatures +(define msg_clss_asc " +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA1 + +What is the difference between a Turing machine and the modern computer? +It's the same as that between Hillary's ascent of Everest and the +establishment of a Hilton on its peak. +-----BEGIN PGP SIGNATURE----- + +iD8DBQFEDVz6LXJ8x2hpdzQRAtkGAKCeMhNbHnh339fpjNj9owsYcC4zBwCfYO5l +2u+KEfXX0FKyk8SMzLjZ536IPwMFAUQNXPr+GAsdqeOwshEC2QYAoPOWAiQm0EF/ +FWIAQUplk7JWbyRKAJ92ZJyJpWfzb0yc1s7MY65r2qEHrg== +=1Xvv +-----END PGP SIGNATURE----- +") + +;; Two clear text signatures in a row +(define msg_clsclss_asc_multiple (string-append msg_cls_asc msg_clss_asc)) + + +;; An Ed25519 cleartext message with an R parameter of only 247 bits +;; so that the code to re-insert the stripped zero byte kicks in. The +;; S parameter has 253 bits but that does not strip a full byte. +;; +;; Note that the message has a typo ("the the"), but this should not +;; be fixed because it breaks this test. +(define msg_ed25519_rshort " +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +Dear Emily: + I'm still confused as to what groups articles should be posted +to. How about an example? + -- Still Confused + +Dear Still: + Ok. Let's say you want to report that Gretzky has been traded from +the Oilers to the Kings. Now right away you might think rec.sport.hockey +would be enough. WRONG. Many more people might be interested. This is a +big trade! Since it's a NEWS article, it belongs in the news.* hierarchy +as well. If you are a news admin, or there is one on your machine, try +news.admin. If not, use news.misc. + The Oilers are probably interested in geology, so try sci.physics. +He is a big star, so post to sci.astro, and sci.space because they are also +interested in stars. Next, his name is Polish sounding. So post to +soc.culture.polish. But that group doesn't exist, so cross-post to +news.groups suggesting it should be created. With this many groups of +interest, your article will be quite bizarre, so post to talk.bizarre as +well. (And post to comp.std.mumps, since they hardly get any articles +there, and a \"comp\" group will propagate your article further.) + You may also find it is more fun to post the article once in each +group. If you list all the newsgroups in the same article, some newsreaders +will only show the the article to the reader once! Don't tolerate this. + -- Emily Postnews Answers Your Questions on Netiquette +-----BEGIN PGP SIGNATURE----- + +iJEEARYIADoWIQSyHeq0+HX7PaQvHR0TlWNoKgINCgUCV772DhwccGF0cmljZS5s +dW11bWJhQGV4YW1wbGUubmV0AAoJEBOVY2gqAg0KMAIA90EtUwAja0iJGpO91wyz +GLh9pS5v495V0r94yU6uUyUA/RT/StyPWe1wbnEZuacZnLbUV6Yy/aTXCVAlxf0r +TusO +=vQ3f +-----END PGP SIGNATURE----- +") + +;; An Ed25519 cleartext message with an S parameter of only 248 bits +;; so that the code to re-insert the stripped zero byte kicks in. +(define msg_ed25519_sshort " +-----BEGIN PGP SIGNED MESSAGE----- +Hash: SHA256 + +All articles that coruscate with resplendence are not truly auriferous. +-----BEGIN PGP SIGNATURE----- + +iJEEARYIADoWIQSyHeq0+HX7PaQvHR0TlWNoKgINCgUCV771QhwccGF0cmljZS5s +dW11bWJhQGV4YW1wbGUubmV0AAoJEBOVY2gqAg0KHVEBAI66OPDYXKWO3r6SaFT+ +uxmh8x4ZerW41vMA9gkJ4AEKAPjoe/Z7fDqo1lCptIFutFAGbfNxcm/53prfx2fT +GisM +=L7sk +-----END PGP SIGNATURE----- +") diff --git a/tests/openpgp/ssh-export.scm b/tests/openpgp/ssh-export.scm index 7f51447..136c6e0 100755 --- a/tests/openpgp/ssh-export.scm +++ b/tests/openpgp/ssh-export.scm @@ -44,8 +44,8 @@ (call-check `(,@GPG --yes --import ,(:file key))) (let* ((result (call-check `(,@GPG --export-ssh-key ,(:fpr key)))) - ;; XXX: We should split at any whitespace here. - (parts (string-split (string-trim char-whitespace? result) #\space))) + (parts (string-splitp (string-trim char-whitespace? result) + char-whitespace? -1))) (assert (string=? (car parts) (:kind key))) ;; XXX: We should not use a short keyid as the comment when ;; exporting an ssh key. diff --git a/tests/openpgp/verify.scm b/tests/openpgp/verify.scm index cb6eb59..b4dd49b 100755 --- a/tests/openpgp/verify.scm +++ b/tests/openpgp/verify.scm @@ -18,6 +18,7 @@ ;; along with this program; if not, see <http://www.gnu.org/licenses/>. (load (in-srcdir "tests" "openpgp" "defs.scm")) +(load (in-srcdir "tests" "openpgp" "signed-messages.scm")) (setup-legacy-environment) ;; @@ -36,273 +37,6 @@ (fail "no error code from verify")))) '("#x2d" "#xca")) -;; A plain signed message created using -;; echo abc | gpg --homedir . --passphrase-fd 0 -u Alpha -z0 -sa msg -(define msg_ols_asc " ------BEGIN PGP MESSAGE----- - -kA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGluayB0aGF0IGFsbCByaWdo -dC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5IGFyZSBzaWNrIGFuZAp0 -aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkgZGVjZW50IHBlb3BsZSBh -cmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJlaW5nIHNpY2sgYW5kIHRp -cmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdtCnNpY2sgYW5kIHRpcmVk -IG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5IFB5dGhvbgqIPwMFAEQM -UlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk01pbAKCIjkzLOAmkZNm0 -D8luT78c/1x45Q== -=a29i ------END PGP MESSAGE----- -") - -;; A plain signed message created using -;; echo abc | gpg --homedir . --passphrase-fd 0 -u Alpha -sa msg -(define msg_cols_asc " ------BEGIN PGP MESSAGE----- - -owGbwMvMwCSoW1RzPCOz3IRxLSN7EnNucboLT6Cgp0JJRmZeNpBMLFFIzMlRKMpM -zyjRBQtm5qUrFKTmF+SkKmTmgdQVKyTnl+aVFFUqJBalKhRnJmcrJOalcJVkFqWm -KOSnKSSlgrSU5OekQMzLL0rJzEsEKk9JTU7NK4EZBtKcBtRRWgAzlwtmbnlmSQbU -GJjxCmDj9RQUPNVzFZJTi0oSM/NyKhXy8kuAYk6lJSBxLlTF2NziqZCYq8elq+Cb -n1dSqRBQWZKRn8fVYc/MygAKBljYCDIFiTDMT+9seu836Q+bevyHTJ0dzPNuvCjn -ZpgrwX38z58rJsfYDhwOSS4SkN/d6vUAAA== -=s6sY ------END PGP MESSAGE----- -") - -;; A PGP 2 style message. -(define msg_sl_asc " ------BEGIN PGP MESSAGE----- - -iD8DBQBEDFJaLXJ8x2hpdzQRAkeCAKCZRBk2Pmx4w9h2LgosS0AppNNaWwCgiI5M -yzgJpGTZtA/Jbk+/HP9ceOWtAQdiA21zZ0QMUlpJIHRoaW5rIHRoYXQgYWxsIHJp -Z2h0LXRoaW5raW5nIHBlb3BsZSBpbiB0aGlzIGNvdW50cnkgYXJlIHNpY2sgYW5k -CnRpcmVkIG9mIGJlaW5nIHRvbGQgdGhhdCBvcmRpbmFyeSBkZWNlbnQgcGVvcGxl -IGFyZSBmZWQgdXAgaW4gdGhpcwpjb3VudHJ5IHdpdGggYmVpbmcgc2ljayBhbmQg -dGlyZWQuICBJJ20gY2VydGFpbmx5IG5vdC4gIEJ1dCBJJ20Kc2ljayBhbmQgdGly -ZWQgb2YgYmVpbmcgdG9sZCB0aGF0IEkgYW0uCi0gTW9udHkgUHl0aG9uCg== -=0ukK ------END PGP MESSAGE----- -") - -;; An OpenPGP message lacking the onepass packet. We used to accept -;; such messages but now consider them invalid. -(define bad_ls_asc " ------BEGIN PGP MESSAGE----- - -rQEHYgNtc2dEDFJaSSB0aGluayB0aGF0IGFsbCByaWdodC10aGlua2luZyBwZW9w -bGUgaW4gdGhpcyBjb3VudHJ5IGFyZSBzaWNrIGFuZAp0aXJlZCBvZiBiZWluZyB0 -b2xkIHRoYXQgb3JkaW5hcnkgZGVjZW50IHBlb3BsZSBhcmUgZmVkIHVwIGluIHRo -aXMKY291bnRyeSB3aXRoIGJlaW5nIHNpY2sgYW5kIHRpcmVkLiAgSSdtIGNlcnRh -aW5seSBub3QuICBCdXQgSSdtCnNpY2sgYW5kIHRpcmVkIG9mIGJlaW5nIHRvbGQg -dGhhdCBJIGFtLgotIE1vbnR5IFB5dGhvbgqIPwMFAEQMUlotcnzHaGl3NBECR4IA -oJlEGTY+bHjD2HYuCixLQCmk01pbAKCIjkzLOAmkZNm0D8luT78c/1x45Q== -=Mpiu ------END PGP MESSAGE----- -") - - -;; A signed message prefixed with an unsigned literal packet. -;; (fols = faked-literal-data, one-pass, literal-data, signature) -;; This should throw an error because running gpg to extract the -;; signed data will return both literal data packets -(define bad_fols_asc " ------BEGIN PGP MESSAGE----- - -rF1iDG1zZy51bnNpZ25lZEQMY0x0aW1lc2hhcmluZywgbjoKCUFuIGFjY2VzcyBt -ZXRob2Qgd2hlcmVieSBvbmUgY29tcHV0ZXIgYWJ1c2VzIG1hbnkgcGVvcGxlLgqQ -DQMAAhEtcnzHaGl3NAGtAQdiA21zZ0QMUlpJIHRoaW5rIHRoYXQgYWxsIHJpZ2h0 -LXRoaW5raW5nIHBlb3BsZSBpbiB0aGlzIGNvdW50cnkgYXJlIHNpY2sgYW5kCnRp -cmVkIG9mIGJlaW5nIHRvbGQgdGhhdCBvcmRpbmFyeSBkZWNlbnQgcGVvcGxlIGFy -ZSBmZWQgdXAgaW4gdGhpcwpjb3VudHJ5IHdpdGggYmVpbmcgc2ljayBhbmQgdGly -ZWQuICBJJ20gY2VydGFpbmx5IG5vdC4gIEJ1dCBJJ20Kc2ljayBhbmQgdGlyZWQg -b2YgYmVpbmcgdG9sZCB0aGF0IEkgYW0uCi0gTW9udHkgUHl0aG9uCog/AwUARAxS -Wi1yfMdoaXc0EQJHggCgmUQZNj5seMPYdi4KLEtAKaTTWlsAoIiOTMs4CaRk2bQP -yW5Pvxz/XHjl -=UNM4 ------END PGP MESSAGE----- -") - -;; A signed message suffixed with an unsigned literal packet. -;; (fols = faked-literal-data, one-pass, literal-data, signature) -;; This should throw an error because running gpg to extract the -;; signed data will return both literal data packets -(define bad_olsf_asc " ------BEGIN PGP MESSAGE----- - -kA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGluayB0aGF0IGFsbCByaWdo -dC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5IGFyZSBzaWNrIGFuZAp0 -aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkgZGVjZW50IHBlb3BsZSBh -cmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJlaW5nIHNpY2sgYW5kIHRp -cmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdtCnNpY2sgYW5kIHRpcmVk -IG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5IFB5dGhvbgqIPwMFAEQM -UlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk01pbAKCIjkzLOAmkZNm0 -D8luT78c/1x45axdYgxtc2cudW5zaWduZWREDGNMdGltZXNoYXJpbmcsIG46CglB -biBhY2Nlc3MgbWV0aG9kIHdoZXJlYnkgb25lIGNvbXB1dGVyIGFidXNlcyBtYW55 -IHBlb3BsZS4K -=3gnG ------END PGP MESSAGE----- -") - - -;; Two standard signed messages in a row -(define msg_olsols_asc_multiple " ------BEGIN PGP MESSAGE----- - -kA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGluayB0aGF0IGFsbCByaWdo -dC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5IGFyZSBzaWNrIGFuZAp0 -aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkgZGVjZW50IHBlb3BsZSBh -cmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJlaW5nIHNpY2sgYW5kIHRp -cmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdtCnNpY2sgYW5kIHRpcmVk -IG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5IFB5dGhvbgqIPwMFAEQM -UlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk01pbAKCIjkzLOAmkZNm0 -D8luT78c/1x45ZANAwACES1yfMdoaXc0Aa0BB2IDbXNnRAxSWkkgdGhpbmsgdGhh -dCBhbGwgcmlnaHQtdGhpbmtpbmcgcGVvcGxlIGluIHRoaXMgY291bnRyeSBhcmUg -c2ljayBhbmQKdGlyZWQgb2YgYmVpbmcgdG9sZCB0aGF0IG9yZGluYXJ5IGRlY2Vu -dCBwZW9wbGUgYXJlIGZlZCB1cCBpbiB0aGlzCmNvdW50cnkgd2l0aCBiZWluZyBz -aWNrIGFuZCB0aXJlZC4gIEknbSBjZXJ0YWlubHkgbm90LiAgQnV0IEknbQpzaWNr -IGFuZCB0aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgSSBhbS4KLSBNb250eSBQeXRo -b24KiD8DBQBEDFJaLXJ8x2hpdzQRAkeCAKCZRBk2Pmx4w9h2LgosS0AppNNaWwCg -iI5MyzgJpGTZtA/Jbk+/HP9ceOU= -=8nLN ------END PGP MESSAGE----- -") - -;; A standard message with two signatures (actually the same signature -;; duplicated). -(define msg_oolss_asc " ------BEGIN PGP MESSAGE----- - -kA0DAAIRLXJ8x2hpdzQBkA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGlu -ayB0aGF0IGFsbCByaWdodC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5 -IGFyZSBzaWNrIGFuZAp0aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkg -ZGVjZW50IHBlb3BsZSBhcmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJl -aW5nIHNpY2sgYW5kIHRpcmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdt -CnNpY2sgYW5kIHRpcmVkIG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5 -IFB5dGhvbgqIPwMFAEQMUlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk -01pbAKCIjkzLOAmkZNm0D8luT78c/1x45Yg/AwUARAxSWi1yfMdoaXc0EQJHggCg -mUQZNj5seMPYdi4KLEtAKaTTWlsAoIiOTMs4CaRk2bQPyW5Pvxz/XHjl -=KVw5 ------END PGP MESSAGE----- -") - -;; A standard message with two one-pass packet but only one signature -;; packet -(define bad_ools_asc " ------BEGIN PGP MESSAGE----- - -kA0DAAIRLXJ8x2hpdzQBkA0DAAIRLXJ8x2hpdzQBrQEHYgNtc2dEDFJaSSB0aGlu -ayB0aGF0IGFsbCByaWdodC10aGlua2luZyBwZW9wbGUgaW4gdGhpcyBjb3VudHJ5 -IGFyZSBzaWNrIGFuZAp0aXJlZCBvZiBiZWluZyB0b2xkIHRoYXQgb3JkaW5hcnkg -ZGVjZW50IHBlb3BsZSBhcmUgZmVkIHVwIGluIHRoaXMKY291bnRyeSB3aXRoIGJl -aW5nIHNpY2sgYW5kIHRpcmVkLiAgSSdtIGNlcnRhaW5seSBub3QuICBCdXQgSSdt -CnNpY2sgYW5kIHRpcmVkIG9mIGJlaW5nIHRvbGQgdGhhdCBJIGFtLgotIE1vbnR5 -IFB5dGhvbgqIPwMFAEQMUlotcnzHaGl3NBECR4IAoJlEGTY+bHjD2HYuCixLQCmk -01pbAKCIjkzLOAmkZNm0D8luT78c/1x45Q== -=1/ix ------END PGP MESSAGE----- -") - -;; Standard cleartext signature -(define msg_cls_asc " ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -I think that all right-thinking people in this country are sick and -tired of being told that ordinary decent people are fed up in this -country with being sick and tired. I'm certainly not. But I'm -sick and tired of being told that I am. -- - Monty Python ------BEGIN PGP SIGNATURE----- - -iD8DBQFEDVp1LXJ8x2hpdzQRAplUAKCMfpG3GPw/TLN52tosgXP5lNECkwCfQhAa -emmev7IuQjWYrGF9Lxj+zj8= -=qJsY ------END PGP SIGNATURE----- -") - -;; Cleartext signature with two signatures -(define msg_clss_asc " ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -What is the difference between a Turing machine and the modern computer? -It's the same as that between Hillary's ascent of Everest and the -establishment of a Hilton on its peak. ------BEGIN PGP SIGNATURE----- - -iD8DBQFEDVz6LXJ8x2hpdzQRAtkGAKCeMhNbHnh339fpjNj9owsYcC4zBwCfYO5l -2u+KEfXX0FKyk8SMzLjZ536IPwMFAUQNXPr+GAsdqeOwshEC2QYAoPOWAiQm0EF/ -FWIAQUplk7JWbyRKAJ92ZJyJpWfzb0yc1s7MY65r2qEHrg== -=1Xvv ------END PGP SIGNATURE----- -") - -;; Two clear text signatures in a row -(define msg_clsclss_asc_multiple (string-append msg_cls_asc msg_clss_asc)) - - -;; An Ed25519 cleartext message with an R parameter of only 247 bits -;; so that the code to re-insert the stripped zero byte kicks in. The -;; S parameter has 253 bits but that does not strip a full byte. -;; -;; Note that the message has a typo ("the the"), but this should not -;; be fixed because it breaks this test. -(define msg_ed25519_rshort " ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA256 - -Dear Emily: - I'm still confused as to what groups articles should be posted -to. How about an example? - -- Still Confused - -Dear Still: - Ok. Let's say you want to report that Gretzky has been traded from -the Oilers to the Kings. Now right away you might think rec.sport.hockey -would be enough. WRONG. Many more people might be interested. This is a -big trade! Since it's a NEWS article, it belongs in the news.* hierarchy -as well. If you are a news admin, or there is one on your machine, try -news.admin. If not, use news.misc. - The Oilers are probably interested in geology, so try sci.physics. -He is a big star, so post to sci.astro, and sci.space because they are also -interested in stars. Next, his name is Polish sounding. So post to -soc.culture.polish. But that group doesn't exist, so cross-post to -news.groups suggesting it should be created. With this many groups of -interest, your article will be quite bizarre, so post to talk.bizarre as -well. (And post to comp.std.mumps, since they hardly get any articles -there, and a \"comp\" group will propagate your article further.) - You may also find it is more fun to post the article once in each -group. If you list all the newsgroups in the same article, some newsreaders -will only show the the article to the reader once! Don't tolerate this. - -- Emily Postnews Answers Your Questions on Netiquette ------BEGIN PGP SIGNATURE----- - -iJEEARYIADoWIQSyHeq0+HX7PaQvHR0TlWNoKgINCgUCV772DhwccGF0cmljZS5s -dW11bWJhQGV4YW1wbGUubmV0AAoJEBOVY2gqAg0KMAIA90EtUwAja0iJGpO91wyz -GLh9pS5v495V0r94yU6uUyUA/RT/StyPWe1wbnEZuacZnLbUV6Yy/aTXCVAlxf0r -TusO -=vQ3f ------END PGP SIGNATURE----- -") - -;; An Ed25519 cleartext message with an S parameter of only 248 bits -;; so that the code to re-insert the stripped zero byte kicks in. -(define msg_ed25519_sshort " ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA256 - -All articles that coruscate with resplendence are not truly auriferous. ------BEGIN PGP SIGNATURE----- - -iJEEARYIADoWIQSyHeq0+HX7PaQvHR0TlWNoKgINCgUCV771QhwccGF0cmljZS5s -dW11bWJhQGV4YW1wbGUubmV0AAoJEBOVY2gqAg0KHVEBAI66OPDYXKWO3r6SaFT+ -uxmh8x4ZerW41vMA9gkJ4AEKAPjoe/Z7fDqo1lCptIFutFAGbfNxcm/53prfx2fT -GisM -=L7sk ------END PGP SIGNATURE----- -") - - - ;; Fixme: We need more tests with manipulated cleartext signatures. ;; |