chiark / gitweb /
gpg: Fix searching for mail addresses in keyrings.
[gnupg2.git] / tests / gpgsm / gpgsm-defs.scm
1 ;; Common definitions for the GPGSM test scripts.
2 ;;
3 ;; Copyright (C) 2016 g10 Code GmbH
4 ;;
5 ;; This file is part of GnuPG.
6 ;;
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.
11 ;;
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.
16 ;;
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/>.
19
20 (load (with-path "defs.scm"))
21
22 ;; This is the list of certificates that we install in the test
23 ;; environment.
24 (define certs
25   (package
26    (define (new fpr issuer-fpr uid)
27      (package))
28    (define (new-uid CN OU O L C)
29      (package))
30    (define test-1 (new "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E"
31                        "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E"
32                        (new-uid "test cert 1"
33                                 "Aegypten Project"
34                                 "g10 Code GmbH"
35                                 "Düsseldorf"
36                                 "DE")))))
37 (define all-certs (list certs::test-1))
38
39 (define gpgsm `(,(tool 'gpgsm) --yes)) ;; more/less options
40
41 (define (tr:gpgsm input args)
42   (tr:spawn input `(,@gpgsm --output **out** ,@args **in**)))
43
44 (define (pipe:gpgsm args)
45   (pipe:spawn `(,@gpgsm --output - ,@args -)))
46
47 (define (gpgsm-with-colons args)
48   (let ((s (call-popen `(,@gpgsm --with-colons ,@args) "")))
49     (map (lambda (line) (string-split line #\:))
50          (string-split-newlines s))))
51
52 (define (sm-have-public-key? key)
53   (catch #f
54          (pair? (filter (lambda (l) (and (equal? 'fpr (:type l))
55                                          (equal? key::fpr (:fpr l))))
56                         (gpgsm-with-colons `(--list-keys ,key::fpr))))))
57
58 (define (sm-have-secret-key? key)
59   (catch #f
60          (pair? (filter (lambda (l) (and (equal? 'fpr (:type l))
61                                          (equal? key::fpr (:fpr l))))
62                         (gpgsm-with-colons `(--list-secret-keys ,key::fpr))))))
63
64 (define (create-file name . lines)
65   (letfd ((fd (open name (logior O_WRONLY O_CREAT O_BINARY) #o600)))
66     (let ((port (fdopen fd "wb")))
67       (for-each (lambda (line) (display line port) (newline port))
68                 lines))))
69
70 (define (create-gpgsmhome)
71   (create-file "gpgsm.conf"
72                "disable-crl-checks"
73                "faked-system-time 1008241200")
74   (create-file "gpg-agent.conf"
75                (string-append "pinentry-program " (tool 'pinentry)))
76   (create-file
77    "trustlist.txt"
78    "32100C27173EF6E9C4E9A25D3D69F86D37A4F939"
79    "# CN=test cert 1,OU=Aegypten Project,O=g10 Code GmbH,L=Düsseldorf,C=DE"
80    "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E S")
81
82   (log "Storing private keys")
83   (mkdir "private-keys-v1.d" "-rwx")
84   (for-each
85    (lambda (name)
86      (file-copy (in-srcdir name)
87                 (path-join "private-keys-v1.d"
88                            (string-append name ".key"))))
89    '("32100C27173EF6E9C4E9A25D3D69F86D37A4F939"))
90
91   (log "Importing public demo and test keys")
92   (call-check `(,@gpgsm --import ,(in-srcdir "cert_g10code_test1.der")))
93
94   (create-sample-files)
95   (stop-agent))
96
97 ;; Initialize the test environment, install appropriate configuration
98 ;; and start the agent, with the keys from the legacy test suite.
99 (define (setup-gpgsm-environment)
100   (if (member "--unpack-tarball" *args*)
101       (call-check `(,(tool 'gpgtar) --extract --directory=. ,(cadr *args*)))
102       (create-gpgsm-gpghome))
103   (start-agent))