|
11 | 11 | import java.util.Date; |
12 | 12 | import java.util.Iterator; |
13 | 13 |
|
14 | | -import org.bouncycastle.bcpg.ArmoredInputStream; |
15 | | -import org.bouncycastle.bcpg.CompressionAlgorithmTags; |
16 | | -import org.bouncycastle.bcpg.HashAlgorithmTags; |
17 | | -import org.bouncycastle.bcpg.PublicKeyAlgorithmTags; |
18 | | -import org.bouncycastle.bcpg.SignatureSubpacket; |
19 | | -import org.bouncycastle.bcpg.SignatureSubpacketInputStream; |
20 | | -import org.bouncycastle.bcpg.SignatureSubpacketTags; |
21 | | -import org.bouncycastle.bcpg.SymmetricKeyAlgorithmTags; |
| 14 | +import org.bouncycastle.bcpg.*; |
22 | 15 | import org.bouncycastle.bcpg.sig.IntendedRecipientFingerprint; |
23 | 16 | import org.bouncycastle.bcpg.sig.IssuerFingerprint; |
24 | 17 | import org.bouncycastle.bcpg.sig.KeyFlags; |
|
45 | 38 | import org.bouncycastle.openpgp.PGPV3SignatureGenerator; |
46 | 39 | import org.bouncycastle.openpgp.bc.BcPGPObjectFactory; |
47 | 40 | import org.bouncycastle.openpgp.jcajce.JcaPGPObjectFactory; |
| 41 | +import org.bouncycastle.openpgp.operator.PGPContentSignerBuilder; |
| 42 | +import org.bouncycastle.openpgp.operator.PGPContentVerifierBuilderProvider; |
48 | 43 | import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator; |
| 44 | +import org.bouncycastle.openpgp.operator.bc.BcPGPContentSignerBuilder; |
49 | 45 | import org.bouncycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider; |
50 | 46 | import org.bouncycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; |
51 | 47 | import org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder; |
@@ -762,6 +758,7 @@ public void performTest() |
762 | 758 | testSignatureTarget(); |
763 | 759 | testUserAttributeEncoding(); |
764 | 760 | testExportNonExportableSignature(); |
| 761 | + testRejectionOfIllegalSignatureType0xFF(); |
765 | 762 | } |
766 | 763 |
|
767 | 764 | private void testUserAttributeEncoding() |
@@ -1367,6 +1364,55 @@ public void testExportNonExportableSignature() |
1367 | 1364 | isTrue(nonExportableSig.getEncoded(true).length == 0); |
1368 | 1365 | } |
1369 | 1366 |
|
| 1367 | + private void testRejectionOfIllegalSignatureType0xFF() |
| 1368 | + throws PGPException, IOException |
| 1369 | + { |
| 1370 | + PGPSecretKeyRing pgpPriv = new PGPSecretKeyRing(rsaKeyRing, new JcaKeyFingerprintCalculator()); |
| 1371 | + PGPSecretKey secretKey = pgpPriv.getSecretKey(); |
| 1372 | + PGPPrivateKey pgpPrivKey = secretKey.extractPrivateKey(new JcePBESecretKeyDecryptorBuilder().setProvider("BC").build(rsaPass)); |
| 1373 | + |
| 1374 | + PGPContentSignerBuilder sigBuilder = new BcPGPContentSignerBuilder( |
| 1375 | + PublicKeyAlgorithmTags.RSA_GENERAL, HashAlgorithmTags.SHA512); |
| 1376 | + PGPSignatureGenerator generator = new PGPSignatureGenerator(sigBuilder); |
| 1377 | + try |
| 1378 | + { |
| 1379 | + generator.init(0xFF, pgpPrivKey); |
| 1380 | + fail("Generating signature of type 0xff MUST fail."); |
| 1381 | + } |
| 1382 | + catch (PGPException e) |
| 1383 | + { |
| 1384 | + // Expected |
| 1385 | + } |
| 1386 | + |
| 1387 | + PGPV3SignatureGenerator generatorV3 = new PGPV3SignatureGenerator(sigBuilder); |
| 1388 | + try |
| 1389 | + { |
| 1390 | + generatorV3.init(0xFF, pgpPrivKey); |
| 1391 | + fail("Generating V3 signature of type 0xff MUST fail."); |
| 1392 | + } |
| 1393 | + catch (PGPException e) |
| 1394 | + { |
| 1395 | + // Expected |
| 1396 | + } |
| 1397 | + |
| 1398 | + PGPContentVerifierBuilderProvider verifBuilder = new BcPGPContentVerifierBuilderProvider(); |
| 1399 | + |
| 1400 | + // signature of type 0xff (illegal) |
| 1401 | + byte[] hexSig = Hex.decode("889c04ff010a000605026655fdbe000a0910b3c272c907c7f7b2133604008dc801695e0905a21a03b832dfd576d66dc23a6ac8715128aaa5cee941b36660efd3c47618c5e880b2dc5e8a34638f10061ae6a9724a2306b66eeb4aec79b49ce4ec48f6de0b5119fc7911e9e2a7677bc4a1f6dd783ce15949457872246e0b415c6f8e3390da90597b059009dcc64723adbc45530a1db0ef70fcffbfc97af6b6"); |
| 1402 | + ByteArrayInputStream bIn = new ByteArrayInputStream(hexSig); |
| 1403 | + BCPGInputStream pIn = new BCPGInputStream(bIn); |
| 1404 | + PGPSignature s = new PGPSignature(pIn); |
| 1405 | + try |
| 1406 | + { |
| 1407 | + s.init(verifBuilder, secretKey.getPublicKey()); |
| 1408 | + fail("Verifying signature of type 0xff MUST fail."); |
| 1409 | + } |
| 1410 | + catch (PGPException e) |
| 1411 | + { |
| 1412 | + // expected |
| 1413 | + } |
| 1414 | + } |
| 1415 | + |
1370 | 1416 | private PGPSignatureList readSignatures(String armored) |
1371 | 1417 | throws IOException |
1372 | 1418 | { |
|
0 commit comments