chiark / gitweb /
doc: Document summary values of TOFU_STATS
[gnupg2.git] / tests / openpgp / ssh-import.scm
1 #!/usr/bin/env gpgscm
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 (setup-environment)
22
23 (define GNUPGHOME (getenv "GNUPGHOME"))
24 (if (string=? "" GNUPGHOME)
25     (fail "GNUPGHOME not set"))
26
27 (setenv "SSH_AUTH_SOCK"
28         (call-check `(,(tool 'gpgconf) --null --list-dirs agent-ssh-socket))
29         #t)
30
31 (define SSH-ADD #f)
32 (catch (skip "ssh-add not found")
33        (set! SSH-ADD
34              (path-expand "ssh-add" (string-split (getenv "PATH") *pathsep*))))
35
36 (define keys
37   '(("dsa" "9a:e1:f1:5f:46:ea:a5:06:e1:e2:f8:38:8e:06:54:58")
38     ("rsa" "c9:85:b5:55:00:84:a9:82:5a:df:d6:62:1b:5a:28:22")
39     ("ecdsa" "93:37:30:a6:4e:e7:6a:22:79:77:8e:bf:ed:14:e9:8e")
40     ("ed25519" "08:df:be:af:d2:f5:32:20:3a:1c:56:06:be:31:0f:bf")))
41
42 (for-each-p'
43  "Importing ssh keys..."
44  (lambda (key)
45    (let ((file (path-join (in-srcdir "samplekeys")
46                           (string-append "ssh-" (car key) ".key")))
47          (hash (cadr key)))
48      ;; We pipe the key to ssh-add so that it won't complain about
49      ;; file's permissions.
50      (pipe:do
51       (pipe:open file (logior O_RDONLY O_BINARY))
52       (pipe:spawn `(,SSH-ADD -)))
53      (unless (string-contains? (call-popen `(,SSH-ADD -l "-E" md5) "") hash)
54              (fail "key not added"))))
55  car keys)
56
57 (info "Checking for issue2316...")
58 (unlink (string-append GNUPGHOME "/sshcontrol"))
59 (pipe:do
60  (pipe:open (path-join (in-srcdir "samplekeys")
61                        (string-append "ssh-rsa.key"))
62             (logior O_RDONLY O_BINARY))
63  (pipe:spawn `(,SSH-ADD -)))
64 (unless
65  (string-contains? (call-popen `(,SSH-ADD -l "-E" md5) "")
66                    "c9:85:b5:55:00:84:a9:82:5a:df:d6:62:1b:5a:28:22")
67  (fail "known private key not (re-)added to sshcontrol"))