use of org.gudy.bouncycastle.asn1.ASN1Encodable in project jruby-openssl by jruby.
the class OCSPSingleResponse method extensions.
@JRubyMethod(name = "extensions")
public IRubyObject extensions() {
Ruby runtime = getRuntime();
Extensions exts = bcSingleResponse.getSingleExtensions();
if (exts == null)
return RubyArray.newEmptyArray(runtime);
ASN1ObjectIdentifier[] extOIDs = exts.getExtensionOIDs();
RubyArray retExts = runtime.newArray(extOIDs.length);
for (ASN1ObjectIdentifier extOID : extOIDs) {
Extension ext = exts.getExtension(extOID);
ASN1Encodable extAsn1 = ext.getParsedValue();
X509Extension retExt = X509Extension.newExtension(runtime, extOID, extAsn1, ext.isCritical());
retExts.append(retExt);
}
return retExts;
}
use of org.gudy.bouncycastle.asn1.ASN1Encodable in project jruby-openssl by jruby.
the class EncContent method fromASN1.
/**
* EncryptedContentInfo ::= SEQUENCE {
* contentType ContentType,
* contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier,
* encryptedContent [0] IMPLICIT EncryptedContent OPTIONAL }
*
* EncryptedContent ::= OCTET STRING
*/
public static EncContent fromASN1(final ASN1Encodable content) {
final ASN1Sequence sequence = (ASN1Sequence) content;
ASN1ObjectIdentifier contentType = (ASN1ObjectIdentifier) (sequence.getObjectAt(0));
final EncContent ec = new EncContent();
ec.setContentType(ASN1Registry.oid2nid(contentType));
ec.setAlgorithm(AlgorithmIdentifier.getInstance(sequence.getObjectAt(1)));
if (sequence.size() > 2 && sequence.getObjectAt(2) instanceof ASN1TaggedObject && ((ASN1TaggedObject) (sequence.getObjectAt(2))).getTagNo() == 0) {
ASN1Encodable ee = ((ASN1TaggedObject) (sequence.getObjectAt(2))).getObject();
if (ee instanceof ASN1Sequence && ((ASN1Sequence) ee).size() > 0) {
ByteList combinedOctets = new ByteList();
Enumeration enm = ((ASN1Sequence) ee).getObjects();
while (enm.hasMoreElements()) {
byte[] octets = ((ASN1OctetString) enm.nextElement()).getOctets();
combinedOctets.append(octets);
}
ec.setEncData(new DEROctetString(combinedOctets.bytes()));
} else {
ec.setEncData((ASN1OctetString) ee);
}
}
return ec;
}
use of org.gudy.bouncycastle.asn1.ASN1Encodable in project jruby-openssl by jruby.
the class Envelope method recipientInfosFromASN1Set.
private static Collection<RecipInfo> recipientInfosFromASN1Set(ASN1Encodable content) {
ASN1Set set = (ASN1Set) content;
Collection<RecipInfo> result = new ArrayList<RecipInfo>();
for (Enumeration<?> e = set.getObjects(); e.hasMoreElements(); ) {
result.add(RecipInfo.fromASN1((ASN1Encodable) e.nextElement()));
}
return result;
}
use of org.gudy.bouncycastle.asn1.ASN1Encodable in project jruby-openssl by jruby.
the class Signed method fromASN1.
/**
* SignedData ::= SEQUENCE {
* version Version,
* digestAlgorithms DigestAlgorithmIdentifiers,
* contentInfo ContentInfo,
* certificates [0] IMPLICIT ExtendedCertificatesAndCertificates OPTIONAL,
* crls [1] IMPLICIT CertificateRevocationLists OPTIONAL,
* signerInfos SignerInfos }
*
* Version ::= INTEGER
*
* DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
*
* SignerInfos ::= SET OF SignerInfo
*/
public static Signed fromASN1(ASN1Encodable content) throws PKCS7Exception {
ASN1Sequence sequence = (ASN1Sequence) content;
ASN1Integer version = (ASN1Integer) sequence.getObjectAt(0);
ASN1Set digestAlgos = (ASN1Set) sequence.getObjectAt(1);
ASN1Encodable contentInfo = sequence.getObjectAt(2);
ASN1Encodable certificates = null;
ASN1Encodable crls = null;
int index = 3;
ASN1Encodable tmp = sequence.getObjectAt(index);
if ((tmp instanceof ASN1TaggedObject) && ((ASN1TaggedObject) tmp).getTagNo() == 0) {
certificates = ((ASN1TaggedObject) tmp).getObject();
index++;
}
tmp = sequence.getObjectAt(index);
if ((tmp instanceof ASN1TaggedObject) && ((ASN1TaggedObject) tmp).getTagNo() == 1) {
crls = ((ASN1TaggedObject) tmp).getObject();
index++;
}
ASN1Set signerInfos = (ASN1Set) sequence.getObjectAt(index);
Signed signed = new Signed();
signed.setVersion(version.getValue().intValue());
signed.setMdAlgs(algorithmIdentifiersFromASN1Set(digestAlgos));
signed.setContents(PKCS7.fromASN1(contentInfo));
if (certificates != null) {
signed.setCert(certificatesFromASN1Set(certificates));
}
if (crls != null) {
throw new RuntimeException("TODO: implement CRL part");
}
signed.setSignerInfo(signerInfosFromASN1Set(signerInfos));
return signed;
}
use of org.gudy.bouncycastle.asn1.ASN1Encodable in project jruby-openssl by jruby.
the class PKCS7 method fromASN1.
/**
* ContentInfo ::= SEQUENCE {
* contentType ContentType,
* content [0] EXPLICIT ANY DEFINED BY contentType OPTIONAL }
*
* ContentType ::= OBJECT IDENTIFIER
*/
public static PKCS7 fromASN1(ASN1Encodable obj) throws PKCS7Exception {
PKCS7 p7 = new PKCS7();
try {
int size = ((ASN1Sequence) obj).size();
if (size == 0) {
return p7;
}
ASN1ObjectIdentifier contentType = (ASN1ObjectIdentifier) (((ASN1Sequence) obj).getObjectAt(0));
if (EMPTY_PKCS7_OID.equals(contentType.getId())) {
// OpenSSL behavior
p7.setType(ASN1Registry.NID_undef);
} else {
final int nid = ASN1Registry.oid2nid(contentType);
ASN1Encodable content = size == 1 ? (ASN1Encodable) null : ((ASN1Sequence) obj).getObjectAt(1);
if (content != null && content instanceof ASN1TaggedObject && ((ASN1TaggedObject) content).getTagNo() == 0) {
content = ((ASN1TaggedObject) content).getObject();
}
p7.initiateWith(nid, content);
}
}// somewhere the object does not obey to be PKCS7 object
catch (ClassCastException e) {
throw new IllegalArgumentException("not a PKCS7 Object");
}
return p7;
}
Aggregations