|
2 | 2 |
|
3 | 3 | import java.io.IOException; |
4 | 4 |
|
| 5 | +import org.bouncycastle.asn1.ASN1EncodableVector; |
| 6 | +import org.bouncycastle.asn1.DERSequence; |
5 | 7 | import org.bouncycastle.asn1.crmf.PKIPublicationInfo; |
6 | 8 | import org.bouncycastle.asn1.crmf.SinglePubInfo; |
7 | 9 | import org.bouncycastle.asn1.x500.X500Name; |
@@ -70,6 +72,57 @@ public void performTest() |
70 | 72 | isTrue(null == pkiPubInfo.getPubInfos()); |
71 | 73 |
|
72 | 74 | encEqualTest(pkiPubInfo); |
| 75 | + |
| 76 | + rejectionTests(); |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * RFC 4211 sec. 6.3: pubInfos MUST NOT be present if the action is dontPublish, and the field |
| 81 | + * is SEQUENCE SIZE (1..MAX), so a present one is never empty. Both are rejected on parsing and |
| 82 | + * on construction. |
| 83 | + */ |
| 84 | + private void rejectionTests() |
| 85 | + throws IOException |
| 86 | + { |
| 87 | + ASN1EncodableVector v = new ASN1EncodableVector(); |
| 88 | + |
| 89 | + v.add(PKIPublicationInfo.dontPublish); |
| 90 | + v.add(new DERSequence(new SinglePubInfo(SinglePubInfo.dontCare, null))); |
| 91 | + |
| 92 | + try |
| 93 | + { |
| 94 | + PKIPublicationInfo.getInstance(new DERSequence(v).getEncoded()); |
| 95 | + fail("no exception on dontPublish with pubInfos"); |
| 96 | + } |
| 97 | + catch (IllegalArgumentException e) |
| 98 | + { |
| 99 | + isEquals("pubInfos must be absent if action is dontPublish", e.getMessage()); |
| 100 | + } |
| 101 | + |
| 102 | + v = new ASN1EncodableVector(); |
| 103 | + |
| 104 | + v.add(PKIPublicationInfo.pleasePublish); |
| 105 | + v.add(new DERSequence()); |
| 106 | + |
| 107 | + try |
| 108 | + { |
| 109 | + PKIPublicationInfo.getInstance(new DERSequence(v).getEncoded()); |
| 110 | + fail("no exception on an empty pubInfos"); |
| 111 | + } |
| 112 | + catch (IllegalArgumentException e) |
| 113 | + { |
| 114 | + isEquals("pubInfos must contain at least one SinglePubInfo", e.getMessage()); |
| 115 | + } |
| 116 | + |
| 117 | + try |
| 118 | + { |
| 119 | + new PKIPublicationInfo(new SinglePubInfo[0]); |
| 120 | + fail("no exception on an empty pubInfo array"); |
| 121 | + } |
| 122 | + catch (IllegalArgumentException e) |
| 123 | + { |
| 124 | + isEquals("pubInfos must contain at least one SinglePubInfo", e.getMessage()); |
| 125 | + } |
73 | 126 | } |
74 | 127 |
|
75 | 128 | private void encEqualTest(PKIPublicationInfo pubInfo) |
|
0 commit comments