use of com.unboundid.asn1.ASN1Set 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 com.unboundid.asn1.ASN1Set in project jruby-openssl by jruby.
the class Signed method algorithmIdentifiersFromASN1Set.
private static Set<AlgorithmIdentifier> algorithmIdentifiersFromASN1Set(ASN1Encodable content) {
ASN1Set set = (ASN1Set) content;
Set<AlgorithmIdentifier> result = new HashSet<AlgorithmIdentifier>();
for (Enumeration<?> e = set.getObjects(); e.hasMoreElements(); ) {
result.add(AlgorithmIdentifier.getInstance(e.nextElement()));
}
return result;
}
use of com.unboundid.asn1.ASN1Set in project jruby-openssl by jruby.
the class X509Request method initialize.
@JRubyMethod(name = "initialize", rest = true, visibility = Visibility.PRIVATE)
public IRubyObject initialize(final ThreadContext context, final IRubyObject[] args) {
final Ruby runtime = context.runtime;
if (Arity.checkArgumentCount(runtime, args, 0, 1) == 0)
return this;
try {
request = new PKCS10Request(StringHelper.readX509PEM(context, args[0]));
} catch (RuntimeException e) {
debugStackTrace(runtime, e);
throw newRequestError(runtime, "invalid certificate request data", e);
}
final String algorithm;
final byte[] encoded;
try {
final PublicKey pkey = request.generatePublicKey();
algorithm = pkey.getAlgorithm();
encoded = pkey.getEncoded();
} catch (IOException e) {
throw newRequestError(runtime, e);
} catch (GeneralSecurityException e) {
throw newRequestError(runtime, e);
}
final RubyString enc = RubyString.newString(runtime, encoded);
if ("RSA".equalsIgnoreCase(algorithm)) {
this.public_key = newPKeyImplInstance(context, "RSA", enc);
} else if ("DSA".equalsIgnoreCase(algorithm)) {
this.public_key = newPKeyImplInstance(context, "DSA", enc);
} else {
throw runtime.newNotImplementedError("public key algorithm: " + algorithm);
}
this.subject = newName(context, request.getSubject());
final Attribute[] attrs = request.getAttributes();
try {
// final RubyModule _ASN1 = _ASN1(runtime);
if (attrs != null) {
for (final Attribute attr : attrs) {
final ASN1ObjectIdentifier type = attr.getAttrType();
final ASN1Set values = attr.getAttrValues();
attributes.add(newAttribute(context, type, values));
}
}
} catch (IOException e) {
throw newRequestError(runtime, e);
}
return this;
}
use of com.unboundid.asn1.ASN1Set 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 com.unboundid.asn1.ASN1Set in project xipki by xipki.
the class CaUtil method getExtensions.
public static Extensions getExtensions(CertificationRequestInfo csr) {
notNull(csr, "csr");
ASN1Set attrs = csr.getAttributes();
for (int i = 0; i < attrs.size(); i++) {
Attribute attr = Attribute.getInstance(attrs.getObjectAt(i));
if (PKCSObjectIdentifiers.pkcs_9_at_extensionRequest.equals(attr.getAttrType())) {
return Extensions.getInstance(attr.getAttributeValues()[0]);
}
}
return null;
}
Aggregations