@@ -68,6 +68,9 @@ public void performTest()
68
68
verifyV6BinarySignature ();
69
69
verifyV6InlineSignature ();
70
70
verifyV6CleartextSignature ();
71
+
72
+ verifyingSignatureWithMismatchedSaltSizeFails ();
73
+ verifyingOPSWithMismatchedSaltSizeFails ();
71
74
}
72
75
73
76
private void verifyV6DirectKeySignatureTestVector ()
@@ -211,6 +214,84 @@ private void verifyV6CleartextSignature()
211
214
isTrue ("Signature MUST verify successfully" , sig .verify ());
212
215
}
213
216
217
+ private void verifyingSignatureWithMismatchedSaltSizeFails ()
218
+ throws IOException
219
+ {
220
+ // v6 signature made using SHA512 with 16 instead of 32 bytes of salt.
221
+ String armoredSig = "-----BEGIN PGP SIGNATURE-----\n " +
222
+ "Version: BCPG v@RELEASE_NAME@\n " +
223
+ "\n " +
224
+ "wogGABsKAAAAKSKhBssYbE8GCaaX5NUt+mxyKwwfHifBilZwj2Ul7Ce62azJBYJm\n " +
225
+ "gXv9AAAAAGHvEIB9K2RLSK++vMVKnivhTgBBHon1f/feri7mJOAYfGm8vOzgbc/8\n " +
226
+ "/zeeT3ZY+EK3q6RQ6W0nolelQejFuy1w9duC8/1U/oTD6iSi1pRAEm4M\n " +
227
+ "=mBNb\n " +
228
+ "-----END PGP SIGNATURE-----" ;
229
+
230
+ ByteArrayInputStream bIn = new ByteArrayInputStream (ARMORED_KEY .getBytes (StandardCharsets .UTF_8 ));
231
+ ArmoredInputStream aIn = new ArmoredInputStream (bIn );
232
+ BCPGInputStream pIn = new BCPGInputStream (aIn );
233
+ PGPObjectFactory objFac = new BcPGPObjectFactory (pIn );
234
+ PGPSecretKeyRing secretKeys = (PGPSecretKeyRing ) objFac .nextObject ();
235
+ PGPPublicKey signingPubKey = secretKeys .getPublicKey ();
236
+
237
+ bIn = new ByteArrayInputStream (armoredSig .getBytes (StandardCharsets .UTF_8 ));
238
+ aIn = new ArmoredInputStream (bIn );
239
+ pIn = new BCPGInputStream (aIn );
240
+ objFac = new BcPGPObjectFactory (pIn );
241
+ PGPSignatureList sigList = (PGPSignatureList ) objFac .nextObject ();
242
+ PGPSignature binarySig = sigList .get (0 );
243
+
244
+ try
245
+ {
246
+ binarySig .init (new BcPGPContentVerifierBuilderProvider (), signingPubKey );
247
+ fail ("Init'ing verification of signature with mismatched salt size MUST fail." );
248
+ }
249
+ catch (PGPException e )
250
+ {
251
+ // expected
252
+ }
253
+ }
254
+
255
+ private void verifyingOPSWithMismatchedSaltSizeFails ()
256
+ throws IOException
257
+ {
258
+ // v6 signature made using SHA512 with 16 instead of 32 bytes of salt.
259
+ String armoredMsg = "-----BEGIN PGP MESSAGE-----\n " +
260
+ "\n " +
261
+ "xDYGAQobEKM41oT/St9iR6qxoR2RndzLGGxPBgmml+TVLfpscisMHx4nwYpWcI9l\n " +
262
+ "JewnutmsyQDLFHUAAAAAAEhlbGxvLCBXb3JsZCEKwogGARsKAAAAKSKhBssYbE8G\n " +
263
+ "CaaX5NUt+mxyKwwfHifBilZwj2Ul7Ce62azJBYJmgXv9AAAAAHU6EKM41oT/St9i\n " +
264
+ "R6qxoR2RndzKyHgSHsO9QIzLibxeWtny69R0srOsJVFr153JlXSlUojGxv00QvlY\n " +
265
+ "z90jECs8awk7vCeJxTHrHFL01Xy5sTsN\n " +
266
+ "-----END PGP MESSAGE-----" ;
267
+
268
+ ByteArrayInputStream bIn = new ByteArrayInputStream (ARMORED_KEY .getBytes (StandardCharsets .UTF_8 ));
269
+ ArmoredInputStream aIn = new ArmoredInputStream (bIn );
270
+ BCPGInputStream pIn = new BCPGInputStream (aIn );
271
+ PGPObjectFactory objFac = new BcPGPObjectFactory (pIn );
272
+ PGPSecretKeyRing secretKeys = (PGPSecretKeyRing ) objFac .nextObject ();
273
+ PGPPublicKey signingPubKey = secretKeys .getPublicKey ();
274
+
275
+ bIn = new ByteArrayInputStream (armoredMsg .getBytes (StandardCharsets .UTF_8 ));
276
+ aIn = new ArmoredInputStream (bIn );
277
+ pIn = new BCPGInputStream (aIn );
278
+ objFac = new BcPGPObjectFactory (pIn );
279
+
280
+ PGPOnePassSignatureList opsList = (PGPOnePassSignatureList ) objFac .nextObject ();
281
+ isEquals ("There MUST be exactly 1 OPS" , 1 , opsList .size ());
282
+ PGPOnePassSignature ops = opsList .get (0 );
283
+
284
+ try
285
+ {
286
+ ops .init (new BcPGPContentVerifierBuilderProvider (), signingPubKey );
287
+ fail ("Init'ing verification of OPS with mismatched salt size MUST fail." );
288
+ }
289
+ catch (PGPException e )
290
+ {
291
+ // expected.
292
+ }
293
+ }
294
+
214
295
public static void main (String [] args )
215
296
{
216
297
runTest (new PGPV6SignatureTest ());
0 commit comments