3 ;; Copyright (C) 2016 g10 Code GmbH
5 ;; This file is part of GnuPG.
7 ;; GnuPG is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GnuPG is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, see <http://www.gnu.org/licenses/>.
20 (load (with-path "defs.scm"))
23 ;; XXX because of --always-trust, the trustdb is not created.
24 ;; Therefore, we redefine GPG without --always-trust.
25 (define GPG `(,(tool 'gpg) --no-permission-warning))
28 (string-append "=" id))
30 (define (count-uids-of-secret-key id)
31 (length (filter (lambda (x) (and (string=? "uid" (car x))
32 (not (string=? "r" (cadr x)))))
35 --list-secret-keys ,(exact id))))))
37 (define alpha "Alpha <alpha@invalid.example.net>")
38 (define bravo "Bravo <bravo@invalid.example.net>")
40 (define (key-data key)
41 (filter (lambda (x) (or (string=? (car x) "pub")
42 (string=? (car x) "sub")))
43 (gpg-with-colons `(-k ,key))))
45 (setenv "PINENTRY_USER_DATA" "test" #t)
47 (info "Checking quick key generation...")
48 (call-check `(,@GPG --quick-generate-key ,alpha))
50 (define keyinfo (gpg-with-colons `(-k ,(exact alpha))))
51 (define fpr (:fpr (assoc "fpr" keyinfo)))
53 (assert (= 1 (count-uids-of-secret-key alpha)))
54 (assert (not (equal? "" (:expire (assoc "pub" keyinfo)))))
56 (info "Checking that we can add a user ID...")
58 ;; Make sure the key capabilities don't change when we add a user id.
60 (let ((pre (key-data (exact alpha)))
61 (result (call-check `(,@GPG --quick-add-uid ,(exact alpha) ,bravo)))
62 (post (key-data (exact alpha))))
63 (if (not (equal? pre post))
65 (display "Key capabilities changed when adding a user id:")
75 (assert (= 2 (count-uids-of-secret-key alpha)))
76 (assert (= 2 (count-uids-of-secret-key bravo)))
78 (info "Checking that we can revoke a user ID...")
79 (call-check `(,@GPG --quick-revoke-uid ,(exact bravo) ,alpha))
81 (assert (= 1 (count-uids-of-secret-key bravo)))
83 (info "Checking that we can change the expiration time.")
85 (define (expiration-time id)
86 (:expire (assoc "pub" (gpg-with-colons `(-k ,id)))))
88 ;; Remove the expiration date.
89 (call-check `(,@gpg --quick-set-expire ,fpr "0"))
90 (assert (equal? "" (expiration-time fpr)))
92 ;; Make the key expire in one year.
93 (call-check `(,@gpg --quick-set-expire ,fpr "1y"))
94 ;; XXX It'd be nice to check that the value is right.
95 (assert (not (equal? "" (expiration-time fpr))))
99 ;; Check --quick-addkey
103 (define (get-subkeys)
104 (filter (lambda (x) (equal? "sub" (car x)))
105 (gpg-with-colons `(-k ,fpr))))
107 ;; This keeps track of the number of subkeys.
108 (define count (length (get-subkeys)))
111 "Checking that we can add subkeys..."
113 (set! count (+ 1 count))
114 (call-check `(,@gpg --quick-add-key ,fpr ,@args))
115 (let ((subkeys (get-subkeys)))
116 (assert (= count (length subkeys)))
117 (if check (check (last subkeys)))))
118 ;; A bunch of arguments...
121 (default default never)
125 (rsa4096 sign,auth "2y")
127 ;; ... with functions to check that the created key matches the
128 ;; expectations (or #f for no tests).
133 (assert (equal? "" (:expire subkey))))
135 (assert (= 1 (:alg subkey)))
136 (assert (string-contains? (:cap subkey) "s"))
137 (assert (not (equal? "" (:expire subkey)))))
139 (assert (= 1 (:alg subkey)))
140 (assert (= 1024 (:length subkey)))
141 (assert (string-contains? (:cap subkey) "s"))
142 (assert (not (equal? "" (:expire subkey)))))
144 (assert (= 1 (:alg subkey)))
145 (assert (= 2048 (:length subkey)))
146 (assert (string-contains? (:cap subkey) "e"))
147 (assert (not (equal? "" (:expire subkey)))))
149 (assert (= 1 (:alg subkey)))
150 (assert (= 4096 (:length subkey)))
151 (assert (string-contains? (:cap subkey) "s"))
152 (assert (string-contains? (:cap subkey) "a"))
153 (assert (not (equal? "" (:expire subkey)))))