1 ;; Common definitions for the GPGSM test scripts.
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"))
22 ;; This is the list of certificates that we install in the test
26 (define (new fpr issuer-fpr uid)
28 (define (new-uid CN OU O L C)
30 (define test-1 (new "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E"
31 "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E"
32 (new-uid "test cert 1"
37 (define all-certs (list certs::test-1))
39 (define gpgsm `(,(tool 'gpgsm) --yes)) ;; more/less options
41 (define (tr:gpgsm input args)
42 (tr:spawn input `(,@gpgsm --output **out** ,@args **in**)))
44 (define (pipe:gpgsm args)
45 (pipe:spawn `(,@gpgsm --output - ,@args -)))
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))))
52 (define (sm-have-public-key? key)
54 (pair? (filter (lambda (l) (and (equal? 'fpr (:type l))
55 (equal? key::fpr (:fpr l))))
56 (gpgsm-with-colons `(--list-keys ,key::fpr))))))
58 (define (sm-have-secret-key? key)
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))))))
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))
70 (define (create-gpgsmhome)
71 (create-file "gpgsm.conf"
73 "faked-system-time 1008241200")
74 (create-file "gpg-agent.conf"
75 (string-append "pinentry-program " (tool 'pinentry)))
78 "32100C27173EF6E9C4E9A25D3D69F86D37A4F939"
79 "# CN=test cert 1,OU=Aegypten Project,O=g10 Code GmbH,L=Düsseldorf,C=DE"
80 "3CF405464F66ED4A7DF45BBDD1E4282E33BDB76E S")
82 (log "Storing private keys")
83 (mkdir "private-keys-v1.d" "-rwx")
86 (file-copy (in-srcdir name)
87 (path-join "private-keys-v1.d"
88 (string-append name ".key"))))
89 '("32100C27173EF6E9C4E9A25D3D69F86D37A4F939"))
91 (log "Importing public demo and test keys")
92 (call-check `(,@gpgsm --import ,(in-srcdir "cert_g10code_test1.der")))
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))