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