6
6
import org .bouncycastle .bcpg .BCPGOutputStream ;
7
7
import org .bouncycastle .bcpg .HashAlgorithmTags ;
8
8
import org .bouncycastle .bcpg .PacketFormat ;
9
- import org .bouncycastle .bcpg .PublicKeyAlgorithmTags ;
10
- import org .bouncycastle .bcpg .SignaturePacket ;
11
9
import org .bouncycastle .bcpg .SignatureSubpacket ;
12
10
import org .bouncycastle .bcpg .SignatureSubpacketTags ;
13
11
import org .bouncycastle .bcpg .sig .IssuerFingerprint ;
27
25
import org .bouncycastle .openpgp .PGPSignature ;
28
26
import org .bouncycastle .openpgp .PGPSignatureGenerator ;
29
27
import org .bouncycastle .openpgp .PGPSignatureList ;
30
- import org .bouncycastle .openpgp .PGPSignatureSubpacketGenerator ;
31
28
import org .bouncycastle .openpgp .bc .BcPGPObjectFactory ;
32
29
import org .bouncycastle .openpgp .operator .bc .BcPGPContentSignerBuilder ;
33
30
import org .bouncycastle .openpgp .operator .bc .BcPGPContentVerifierBuilderProvider ;
41
38
import java .io .InputStream ;
42
39
import java .io .OutputStream ;
43
40
import java .nio .charset .StandardCharsets ;
44
- import java .util .Date ;
45
41
import java .util .Iterator ;
46
42
47
43
public class PGPv6SignatureTest
48
44
extends AbstractPacketTest
49
45
{
50
-
46
+ // https://www.rfc-editor.org/rfc/rfc9580.html#name-sample-version-6-certificat
51
47
private static final String ARMORED_CERT = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n " +
52
48
"\n " +
53
49
"xioGY4d/4xsAAAAg+U2nu0jWCmHlZ3BqZYfQMxmZu52JGggkLq2EVD34laPCsQYf\n " +
@@ -60,6 +56,7 @@ public class PGPv6SignatureTest
60
56
"j+VjFM21J0hqWlEg+bdiojWnKfA5AQpWUWtnNwDEM0g12vYxoWM8Y81W+bHBw805\n " +
61
57
"I8kWVkXU6vFOi+HWvv/ira7ofJu16NnoUkhclkUrk0mXubZvyl4GBg==\n " +
62
58
"-----END PGP PUBLIC KEY BLOCK-----" ;
59
+ // https://www.rfc-editor.org/rfc/rfc9580.html#name-sample-version-6-secret-key
63
60
private static final String ARMORED_KEY = "-----BEGIN PGP PRIVATE KEY BLOCK-----\n " +
64
61
"\n " +
65
62
"xUsGY4d/4xsAAAAg+U2nu0jWCmHlZ3BqZYfQMxmZu52JGggkLq2EVD34laMAGXKB\n " +
@@ -85,13 +82,13 @@ public String getName()
85
82
public void performTest ()
86
83
throws Exception
87
84
{
88
- verifyV6DirectKeySignatureTestVector ();
85
+ verifySignatureOnTestKey ();
89
86
90
- verifyV6BinarySignature ();
87
+ verifyV6DetachedSignature ();
91
88
verifyV6InlineSignature ();
92
89
verifyV6CleartextSignature ();
93
90
94
- generateAndVerifyV6BinarySignature ();
91
+ generateAndVerifyV6DetachedSignature ();
95
92
generateAndVerifyV6InlineSignature ();
96
93
generateAndVerifyV6CleartextSignature ();
97
94
@@ -102,10 +99,13 @@ public void performTest()
102
99
verifySignaturesOnEd448X448Key ();
103
100
generateAndVerifyInlineSignatureUsingRSAKey ();
104
101
105
- testVerificationOfV3SigWithV6KeyFails ();
102
+ testVerificationOfV4SigWithV6KeyFails ();
106
103
}
107
104
108
- private void verifyV6DirectKeySignatureTestVector ()
105
+ /**
106
+ * Verify that the known-good key signatures on the minimal test key verify properly.
107
+ */
108
+ private void verifySignatureOnTestKey ()
109
109
throws IOException , PGPException
110
110
{
111
111
ByteArrayInputStream bIn = new ByteArrayInputStream (ARMORED_CERT .getBytes (StandardCharsets .UTF_8 ));
@@ -129,7 +129,10 @@ private void verifyV6DirectKeySignatureTestVector()
129
129
subkeyBinding .verifyCertification (primaryKey , subkey ));
130
130
}
131
131
132
- private void verifyV6BinarySignature ()
132
+ /**
133
+ * Verify that a good v6 detached signature is verified properly.
134
+ */
135
+ private void verifyV6DetachedSignature ()
133
136
throws IOException , PGPException
134
137
{
135
138
String msg = "Hello, World!\n " ;
@@ -161,6 +164,9 @@ private void verifyV6BinarySignature()
161
164
binarySig .verify ());
162
165
}
163
166
167
+ /**
168
+ * Verify that a good v6 inline signature is verified properly.
169
+ */
164
170
private void verifyV6InlineSignature ()
165
171
throws IOException , PGPException
166
172
{
@@ -203,6 +209,9 @@ private void verifyV6InlineSignature()
203
209
isTrue ("Verifying OPS signature MUST succeed" , ops .verify (sig ));
204
210
}
205
211
212
+ /**
213
+ * Verify that a good v6 cleartext signature is verified properly.
214
+ */
206
215
private void verifyV6CleartextSignature ()
207
216
throws IOException , PGPException
208
217
{
@@ -247,6 +256,10 @@ private void verifyV6CleartextSignature()
247
256
isTrue ("Cleartext Signature MUST verify successfully" , sig .verify ());
248
257
}
249
258
259
+ /**
260
+ * A v6 signature with too few salt bytes.
261
+ * This test verifies that the signature is properly rejected.
262
+ */
250
263
private void verifyingSignatureWithMismatchedSaltSizeFails ()
251
264
throws IOException
252
265
{
@@ -285,6 +298,10 @@ private void verifyingSignatureWithMismatchedSaltSizeFails()
285
298
}
286
299
}
287
300
301
+ /**
302
+ * Verify that a OPS signature where the length of the salt array does not match the expectations
303
+ * is rejected properly.
304
+ */
288
305
private void verifyingOPSWithMismatchedSaltSizeFails ()
289
306
throws IOException
290
307
{
@@ -325,6 +342,10 @@ private void verifyingOPSWithMismatchedSaltSizeFails()
325
342
}
326
343
}
327
344
345
+ /**
346
+ * Test verifying that an inline signature where the salt of the OPS packet mismatches that of the signature
347
+ * is rejected properly.
348
+ */
328
349
private void verifyingInlineSignatureWithSignatureSaltValueMismatchFails ()
329
350
throws IOException , PGPException
330
351
{
@@ -378,6 +399,9 @@ private void verifyingInlineSignatureWithSignatureSaltValueMismatchFails()
378
399
}
379
400
}
380
401
402
+ /**
403
+ * Verify self signatures on a v6 Ed448/X448 key.
404
+ */
381
405
private void verifySignaturesOnEd448X448Key ()
382
406
throws PGPException , IOException
383
407
{
@@ -518,7 +542,10 @@ private PGPPublicKey getSigningKeyFor(PGPKeyRing keys, PGPSignature sig)
518
542
return null ;
519
543
}
520
544
521
- private void generateAndVerifyV6BinarySignature ()
545
+ /**
546
+ * Generate and verify a detached v6 signature using the v6 test key.
547
+ */
548
+ private void generateAndVerifyV6DetachedSignature ()
522
549
throws IOException , PGPException
523
550
{
524
551
String msg = "Hello, World!\n " ;
@@ -547,6 +574,9 @@ private void generateAndVerifyV6BinarySignature()
547
574
binarySig .verify ());
548
575
}
549
576
577
+ /**
578
+ * Generate and verify a v6 inline signature using the v6 test key.
579
+ */
550
580
private void generateAndVerifyV6InlineSignature ()
551
581
throws IOException , PGPException
552
582
{
@@ -610,6 +640,9 @@ private void generateAndVerifyV6InlineSignature()
610
640
isTrue ("Generated Inline OPS signature MUST verify successful" , ops .verify (sig ));
611
641
}
612
642
643
+ /**
644
+ * Generate and verify a v6 signature using the cleartext signature framework and the v6 test key.
645
+ */
613
646
private void generateAndVerifyV6CleartextSignature ()
614
647
throws IOException , PGPException
615
648
{
@@ -677,6 +710,9 @@ private void generateAndVerifyV6CleartextSignature()
677
710
isTrue ("Generated Cleartext Signature MUST verify successfully" , v );
678
711
}
679
712
713
+ /**
714
+ * Generate and verify an inline text signature using a v6 RSA key.
715
+ */
680
716
private void generateAndVerifyInlineSignatureUsingRSAKey ()
681
717
throws PGPException , IOException
682
718
{
@@ -787,7 +823,11 @@ private void generateAndVerifyInlineSignatureUsingRSAKey()
787
823
isTrue ("V6 inline sig made using RSA key MUST verify" , ops .verify (sig ));
788
824
}
789
825
790
- private void testVerificationOfV3SigWithV6KeyFails ()
826
+ /**
827
+ * A version 4 signature generated using the v6 key.
828
+ * This test verifies that the signature is properly rejected.
829
+ */
830
+ private void testVerificationOfV4SigWithV6KeyFails ()
791
831
throws IOException
792
832
{
793
833
ByteArrayInputStream bIn = new ByteArrayInputStream (ARMORED_KEY .getBytes (StandardCharsets .UTF_8 ));
0 commit comments