chiark / gitweb /
doc: Document summary values of TOFU_STATS
[gnupg2.git] / tests / openpgp / ssh-export.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 key
24   `(,(in-srcdir "samplekeys" "authenticate-only.sec.asc")
25     "927EF377FD1A1B6F795E40C02A87917D8FFBA49F"
26     "72360FDB6380212D5DAF2FA9E51185A9253C496D"
27     "ssh-rsa"))
28
29 (define :file car)
30 (define :fpr cadr)
31 (define :subkey-fpr caddr)
32 (define :kind cadddr)
33
34 ;; Return true if a-str and b-str share a suffix of length n.
35 (define (string-common-suffix? n a-str b-str)
36   (let ((a-len (string-length a-str))
37         (b-len (string-length b-str)))
38   (if (> n (min a-len b-len))
39       #f
40       (string=? (substring a-str (- a-len n) a-len)
41                 (substring b-str (- b-len n) b-len)))))
42
43 (info "Checking ssh export...")
44 (call-check `(,@GPG --yes --import ,(:file key)))
45
46 (let* ((result (call-check `(,@GPG --export-ssh-key ,(:fpr key))))
47        ;; XXX: We should split at any whitespace here.
48        (parts (string-split (string-trim char-whitespace? result) #\space)))
49   (assert (string=? (car parts) (:kind key)))
50   ;; XXX: We should not use a short keyid as the comment when
51   ;; exporting an ssh key.
52   (assert (string-common-suffix? 8 (caddr parts) (:subkey-fpr key))))