tests: Move some functions into a common module.
[gnupg.git] / tests / openpgp / multisig.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 ;; Check that gpg verifies only signatures where there is no ambiguity
21 ;; in the order of packets.  Needs the Demo Keys Lima and Mike.
22 ;;
23 ;; Note: We do not support multiple signatures anymore thus this test is
24 ;; not really needed because verify could do the same.  We keep it anyway.
25
26 (load (in-srcdir "tests" "openpgp" "defs.scm"))
27 (setup-legacy-environment)
28
29 (define sig-1ls1ls-valid "
30 -----BEGIN PGP ARMORED FILE-----
31
32 kA0DAAIRN8q1H7eRA/gBrCdiBXRleHQxOogq9EkgYW0gc29ycnksIEkgY2FuJ3Qg
33 ZG8gdGhhdAqIPwMFADqIKvQ3yrUft5ED+BEC2joAoJaSaXOZEtSZqQ780HIXG77e
34 8PB7AJ4wCprmaFTO0fBaTcXDuEOBdAWnOZANAwACETfKtR+3kQP4AawnYgV0ZXh0
35 MTqIKvRJIGFtIHNvcnJ5LCBJIGNhbid0IGRvIHRoYXQKiD8DBQA6iCr0N8q1H7eR
36 A/gRAto6AKCWkmlzmRLUmakO/NByFxu+3vDwewCeMAqa5mhUztHwWk3Fw7hDgXQF
37 pzk=
38 =8jSC
39 -----END PGP ARMORED FILE-----
40 ")
41 (define sig-ls-valid "
42 -----BEGIN PGP ARMORED FILE-----
43
44 rCdiBXRleHQxOogrS0kgYW0gc29ycnksIEkgY2FuJ3QgZG8gdGhhdAqIPwMFADqI
45 K0s3yrUft5ED+BECLQMAn2jZUNOpB4OuurSQkc2TRfg6ek02AJ9+oJS0frQ+yUsT
46 QDUFTH2PvZRxjw==
47 =J+lb
48 -----END PGP ARMORED FILE-----
49 ")
50 (define sig-sl-valid "
51 -----BEGIN PGP ARMORED FILE-----
52
53 iD8DBQA6iCtLN8q1H7eRA/gRAi0DAJ9o2VDTqQeDrrq0kJHNk0X4OnpNNgCffqCU
54 tH60PslLE0A1BUx9j72UcY+sJ2IFdGV4dDE6iCtLSSBhbSBzb3JyeSwgSSBjYW4n
55 dCBkbyB0aGF0Cg==
56 =N9MP
57 -----END PGP ARMORED FILE-----
58 ")
59 (define sig-11lss-valid-but-is-not "
60 -----BEGIN PGP ARMORED FILE-----
61
62 kA0DAAIRN8q1H7eRA/gAkA0DAAIRN8q1H7eRA/gBrCdiBXRleHQxOogyXUkgYW0g
63 c29ycnksIEkgY2FuJ3QgZG8gdGhhdAqIPwMFADqIMl03yrUft5ED+BECwQAAnRXT
64 mXjVd385oD38W80XuheWKTGcAJ9pZ6/flaKDfw+SLido7xaUHuhp5Yg/AwUAOogy
65 XTfKtR+3kQP4EQLBAACgnN0IP+NztE0aAc/DZ17yHWR9diwAniN0P01WmbgZJoZB
66 Q341WRXKS/at
67 =Ekrs
68 -----END PGP ARMORED FILE-----
69 ")
70 (define sig-11lss11lss-valid-but-is-not "
71 -----BEGIN PGP ARMORED FILE-----
72
73 kA0DAAIRN8q1H7eRA/gAkA0DAAIRN8q1H7eRA/gBrCdiBXRleHQxOogyXUkgYW0g
74 c29ycnksIEkgY2FuJ3QgZG8gdGhhdAqIPwMFADqIMl03yrUft5ED+BECwQAAnRXT
75 mXjVd385oD38W80XuheWKTGcAJ9pZ6/flaKDfw+SLido7xaUHuhp5Yg/AwUAOogy
76 XTfKtR+3kQP4EQLBAACgnN0IP+NztE0aAc/DZ17yHWR9diwAniN0P01WmbgZJoZB
77 Q341WRXKS/atkA0DAAIRN8q1H7eRA/gAkA0DAAIRN8q1H7eRA/gBrCdiBXRleHQx
78 OogyXUkgYW0gc29ycnksIEkgY2FuJ3QgZG8gdGhhdAqIPwMFADqIMl03yrUft5ED
79 +BECwQAAnRXTmXjVd385oD38W80XuheWKTGcAJ9pZ6/flaKDfw+SLido7xaUHuhp
80 5Yg/AwUAOogyXTfKtR+3kQP4EQLBAACgnN0IP+NztE0aAc/DZ17yHWR9diwAniN0
81 P01WmbgZJoZBQ341WRXKS/at
82 =P1Mu
83 -----END PGP ARMORED FILE-----
84 ")
85 (define sig-ssl-valid-but-is-not "
86 -----BEGIN PGP ARMORED FILE-----
87
88 iD8DBQA6iCtLN8q1H7eRA/gRAi0DAJ9o2VDTqQeDrrq0kJHNk0X4OnpNNgCffqCU
89 tH60PslLE0A1BUx9j72UcY+IPwMFADqIK0s3yrUft5ED+BECLQMAn2jZUNOpB4Ou
90 urSQkc2TRfg6ek02AJ9+oJS0frQ+yUsTQDUFTH2PvZRxj6wnYgV0ZXh0MTqIK0tJ
91 IGFtIHNvcnJ5LCBJIGNhbid0IGRvIHRoYXQK
92 =Zven
93 -----END PGP ARMORED FILE-----
94 ")
95 (define sig-1lsls-invalid "
96 -----BEGIN PGP ARMORED FILE-----
97
98 kA0DAAIRN8q1H7eRA/gBrCdiBXRleHQxOogq9EkgYW0gc29ycnksIEkgY2FuJ3Qg
99 ZG8gdGhhdAqIPwMFADqIKvQ3yrUft5ED+BEC2joAoJaSaXOZEtSZqQ780HIXG77e
100 8PB7AJ4wCprmaFTO0fBaTcXDuEOBdAWnOawnYgV0ZXh0MTqIK0tJIGFtIHNvcnJ5
101 LCBJIGNhbid0IGRvIHRoYXQKiD8DBQA6iCtLN8q1H7eRA/gRAi0DAJ9o2VDTqQeD
102 rrq0kJHNk0X4OnpNNgCffqCUtH60PslLE0A1BUx9j72UcY8=
103 =nkeu
104 -----END PGP ARMORED FILE-----
105 ")
106 (define sig-lsls-invalid "
107 -----BEGIN PGP ARMORED FILE-----
108
109 rCdiBXRleHQxOogrS0kgYW0gc29ycnksIEkgY2FuJ3QgZG8gdGhhdAqIPwMFADqI
110 K0s3yrUft5ED+BECLQMAn2jZUNOpB4OuurSQkc2TRfg6ek02AJ9+oJS0frQ+yUsT
111 QDUFTH2PvZRxj6wnYgV0ZXh0MTqIK0tJIGFtIHNvcnJ5LCBJIGNhbid0IGRvIHRo
112 YXQKiD8DBQA6iCtLN8q1H7eRA/gRAi0DAJ9o2VDTqQeDrrq0kJHNk0X4OnpNNgCf
113 fqCUtH60PslLE0A1BUx9j72UcY8=
114 =BlZH
115 -----END PGP ARMORED FILE-----
116 ")
117 (define sig-lss-invalid "
118 -----BEGIN PGP ARMORED FILE-----
119
120 rCdiBXRleHQxOogrS0kgYW0gc29ycnksIEkgY2FuJ3QgZG8gdGhhdAqIPwMFADqI
121 K0s3yrUft5ED+BECLQMAn2jZUNOpB4OuurSQkc2TRfg6ek02AJ9+oJS0frQ+yUsT
122 QDUFTH2PvZRxj4g/AwUAOogrSzfKtR+3kQP4EQItAwCfaNlQ06kHg666tJCRzZNF
123 +Dp6TTYAn36glLR+tD7JSxNANQVMfY+9lHGP
124 =jmt6
125 -----END PGP ARMORED FILE-----
126 ")
127 (define sig-slsl-invalid "
128 -----BEGIN PGP ARMORED FILE-----
129
130 iD8DBQA6iCtLN8q1H7eRA/gRAi0DAJ9o2VDTqQeDrrq0kJHNk0X4OnpNNgCffqCU
131 tH60PslLE0A1BUx9j72UcY+sJ2IFdGV4dDE6iCtLSSBhbSBzb3JyeSwgSSBjYW4n
132 dCBkbyB0aGF0Cog/AwUAOogrSzfKtR+3kQP4EQItAwCfaNlQ06kHg666tJCRzZNF
133 +Dp6TTYAn36glLR+tD7JSxNANQVMfY+9lHGPrCdiBXRleHQxOogrS0kgYW0gc29y
134 cnksIEkgY2FuJ3QgZG8gdGhhdAo=
135 =phBF
136 -----END PGP ARMORED FILE-----
137 ")
138
139 (for-each-p
140  "Checking that a valid signature is verified as such"
141  (lambda (armored-file)
142    (tr:do
143     (tr:pipe-do
144      (pipe:echo (eval armored-file (current-environment)))
145      (pipe:spawn `(,@GPG --dearmor)))
146     (tr:spawn "" `(,@GPG --verify **in**))))
147  '(sig-sl-valid))
148
149 ;; ???
150 ;;
151 ;; #for i in "$sig-11lss-valid-but-is-not" "$sig-11lss11lss-valid-but-is-not" \
152 ;; #         "$sig-ssl-valid-but-is-not"; do
153 ;; #    echo "$i" | $GPG --dearmor >x
154 ;; #    $GPG --verify <x 2>/dev/null || error "valid is invalid"
155 ;; #done
156
157 (for-each-p
158  "Checking that an invalid signature is verified as such"
159  (lambda (armored-file)
160    (lettmp (file)
161      (pipe:do
162       (pipe:echo (eval armored-file (current-environment)))
163       (pipe:spawn `(,@GPG --dearmor))
164       (pipe:write-to file (logior O_WRONLY O_CREAT O_BINARY) #o600))
165
166      (if (= 0 (call `(,@GPG --verify ,file)))
167          (fail "Bad signature verified ok"))))
168  '(sig-1ls1ls-valid sig-ls-valid sig-1lsls-invalid
169                     sig-lsls-invalid sig-lss-invalid sig-slsl-invalid))