|
36 | 36 | import java.util.Iterator;
|
37 | 37 | import java.util.List;
|
38 | 38 | import java.util.TimeZone;
|
39 |
| - |
40 | 39 | import java.security.MessageDigest;
|
41 | 40 | import java.security.PrivateKey;
|
42 | 41 | import java.security.PublicKey;
|
|
66 | 65 | import org.bouncycastle.asn1.pkcs.IssuerAndSerialNumber;
|
67 | 66 | import org.bouncycastle.asn1.x500.X500Name;
|
68 | 67 | import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
|
69 |
| - |
| 68 | +import org.bouncycastle.pkcs.PKCSException; |
70 | 69 | import org.jruby.ext.openssl.SecurityHelper;
|
71 | 70 | import org.jruby.ext.openssl.x509store.Name;
|
72 | 71 | import org.jruby.ext.openssl.x509store.Store;
|
@@ -130,26 +129,32 @@ public static PKCS7 newEmpty() {
|
130 | 129 | public static PKCS7 fromASN1(ASN1Encodable obj) throws PKCS7Exception {
|
131 | 130 | PKCS7 p7 = new PKCS7();
|
132 | 131 |
|
133 |
| - int size = ((ASN1Sequence) obj).size(); |
134 |
| - if (size == 0) { |
135 |
| - return p7; |
136 |
| - } |
137 |
| - |
138 |
| - ASN1ObjectIdentifier contentType = (ASN1ObjectIdentifier) (((ASN1Sequence) obj).getObjectAt(0)); |
139 |
| - if ( EMPTY_PKCS7_OID.equals( contentType.getId() ) ) { |
140 |
| - // OpenSSL behavior |
141 |
| - p7.setType(ASN1Registry.NID_undef); |
142 |
| - } |
143 |
| - else { |
144 |
| - final int nid = ASN1Registry.oid2nid(contentType); |
| 132 | + try { |
| 133 | + int size = ((ASN1Sequence) obj).size(); |
| 134 | + if (size == 0) { |
| 135 | + return p7; |
| 136 | + } |
| 137 | + ASN1ObjectIdentifier contentType = (ASN1ObjectIdentifier) (((ASN1Sequence) obj).getObjectAt(0)); |
| 138 | + if ( EMPTY_PKCS7_OID.equals( contentType.getId() ) ) { |
| 139 | + // OpenSSL behavior |
| 140 | + p7.setType(ASN1Registry.NID_undef); |
| 141 | + } |
| 142 | + else { |
| 143 | + final int nid = ASN1Registry.oid2nid(contentType); |
145 | 144 |
|
146 |
| - ASN1Encodable content = size == 1 ? (ASN1Encodable) null : ((ASN1Sequence) obj).getObjectAt(1); |
| 145 | + ASN1Encodable content = size == 1 ? (ASN1Encodable) null : ((ASN1Sequence) obj).getObjectAt(1); |
147 | 146 |
|
148 |
| - if (content != null && content instanceof ASN1TaggedObject && ((ASN1TaggedObject) content).getTagNo() == 0) { |
149 |
| - content = ((ASN1TaggedObject) content).getObject(); |
| 147 | + if (content != null && content instanceof ASN1TaggedObject && ((ASN1TaggedObject) content).getTagNo() == 0) { |
| 148 | + content = ((ASN1TaggedObject) content).getObject(); |
| 149 | + } |
| 150 | + p7.initiateWith(nid, content); |
150 | 151 | }
|
151 |
| - p7.initiateWith(nid, content); |
152 | 152 | }
|
| 153 | + // somewhere the object does not obey to be PKCS7 object |
| 154 | + catch (ClassCastException e) { |
| 155 | + throw new IllegalArgumentException("not a PKCS7 Object"); |
| 156 | + } |
| 157 | + |
153 | 158 | return p7;
|
154 | 159 | }
|
155 | 160 |
|
|
0 commit comments