chiark / gitweb /
gpg: Fix searching for mail addresses in keyrings.
[gnupg2.git] / tests / gpgsm / verify.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 "gpgsm-defs.scm"))
21 (setup-gpgsm-environment)
22
23 ;;
24 ;; Two simple tests to check that verify fails for bad input data
25 ;;
26 (for-each-p
27  "Checking bogus signature."
28  (lambda (char)
29    (lettmp (x)
30      (call-with-binary-output-file
31       x
32       (lambda (port)
33         (display (make-string 64 (integer->char (string->number char)))
34                  port)))
35      (assert (not (zero? (call `(,@gpgsm --verify ,x data-500)))))))
36  '("#x2d" "#xca"))
37
38 (define test-text1 "Hallo Leute!\n")
39 (define test-text1f "Hallo Leute?\n")
40 (define test-sig1 "
41 -----BEGIN CMS OBJECT-----
42 MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAA
43 MYIBOTCCATUCAQEwcDBrMQswCQYDVQQGEwJERTETMBEGA1UEBxQKRPxzc2VsZG9y
44 ZjEWMBQGA1UEChMNZzEwIENvZGUgR21iSDEZMBcGA1UECxMQQWVneXB0ZW4gUHJv
45 amVjdDEUMBIGA1UEAxMLdGVzdCBjZXJ0IDECAQAwBwYFKw4DAhqgJTAjBgkqhkiG
46 9w0BCQQxFgQU7FC/ibH3lC9GE24RJJxa8zqP7wEwCwYJKoZIhvcNAQEBBIGAA3oC
47 DUmKERmD1eoJYFw38y/qnncS/6ZPjWINDIphZeK8mzAANpvpIaRPf3sNBznb89QF
48 mRgCXIWcjlHT0DTRLBf192Ve22IyKH00L52CqFsSN3a2sajqRUlXH8RY2D+Al71e
49 MYdRclgjObCcoilA8fZ13VR4DiMJVFCxJL4qVWI=
50 -----END CMS OBJECT-----")
51
52 ;;
53 ;; Now run the tests.
54 ;;
55 (info "Checking that a valid signature is verified as such.")
56 (lettmp (sig body)
57   (with-output-to-file sig (lambda () (display test-sig1)))
58   (with-output-to-file body (lambda () (display test-text1)))
59   (call-check `(,@gpgsm --verify ,sig ,body)))
60
61 (info "Checking that an invalid signature is verified as such.")
62 (lettmp (sig body)
63   (with-output-to-file sig (lambda () (display test-sig1)))
64   (with-output-to-file body (lambda () (display test-text1f)))
65   (assert (not (zero? (call `(,@gpgsm --verify ,sig ,body))))))