use of org.bouncycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class X509Cert method uniqueExtensions.
private Collection<X509Extension> uniqueExtensions() {
final Map<ASN1ObjectIdentifier, X509Extension> unique = new LinkedHashMap<ASN1ObjectIdentifier, X509Extension>();
for (X509Extension current : this.extensions) {
final ASN1ObjectIdentifier oid = current.getRealObjectID();
final X509Extension existing = unique.get(oid);
if (existing == null) {
unique.put(oid, current);
continue;
}
// commonly used e.g. with subjectAltName || issuserAltName :
if ("2.5.29.17".equals(oid.getId()) || "2.5.29.18".equals(oid.getId())) {
final ASN1EncodableVector vec = new ASN1EncodableVector();
try {
GeneralName[] n1 = extRealNames(existing);
for (int i = 0; i < n1.length; i++) vec.add(n1[i]);
GeneralName[] n2 = extRealNames(current);
for (int i = 0; i < n2.length; i++) vec.add(n2[i]);
GeneralNames nn = GeneralNames.getInstance(new DLSequence(vec));
final X509Extension existingDup = existing.clone();
existingDup.setRealValue(nn);
unique.put(oid, existingDup);
} catch (IOException ex) {
throw getRuntime().newIOErrorFromException(ex);
}
continue;
}
// TODO do we need special care for any others here ?!?
final ASN1EncodableVector vec = new ASN1EncodableVector();
try {
final ASN1Encodable existingValue = existing.getRealValue();
if (existingValue instanceof ASN1Sequence) {
final ASN1Sequence seq = (ASN1Sequence) existingValue;
for (int i = 0; i < seq.size(); i++) {
vec.add(seq.getObjectAt(i));
}
} else {
vec.add(existingValue);
}
vec.add(current.getRealValue());
// existing.setRealValue( new DLSequence(vec) );
final X509Extension existingDup = existing.clone();
existingDup.setRealValue(new DLSequence(vec));
unique.put(oid, existingDup);
} catch (IOException ex) {
throw getRuntime().newIOErrorFromException(ex);
}
}
return unique.values();
}
use of org.bouncycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class X509Name method to_der.
@JRubyMethod
public RubyString to_der(final ThreadContext context) {
final Ruby runtime = context.runtime;
final DLSequence seq;
if (oids.size() > 0) {
ASN1EncodableVector vec = new ASN1EncodableVector();
ASN1EncodableVector sVec = new ASN1EncodableVector();
ASN1ObjectIdentifier lastOid = null;
for (int i = 0; i != oids.size(); i++) {
final ASN1ObjectIdentifier oid = oids.get(i);
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(oid);
// TODO DO NOT USE DL types !
// final String value = values.get(i);
// final int type = RubyNumeric.fix2int(types.get(i));
// v.add( convert(oid, value, type) );
v.add(values.get(i));
if (lastOid == null) {
sVec.add(new DLSequence(v));
} else {
vec.add(new DLSet(sVec));
sVec = new ASN1EncodableVector();
sVec.add(new DLSequence(v));
}
lastOid = oid;
}
vec.add(new DLSet(sVec));
seq = new DLSequence(vec);
} else {
seq = new DLSequence();
}
try {
return StringHelper.newString(runtime, seq.getEncoded(ASN1Encoding.DER));
} catch (IOException e) {
throw newNameError(runtime, e);
}
}
use of org.bouncycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class PKey method toDerRSAKey.
public static byte[] toDerRSAKey(RSAPublicKey pubKey, RSAPrivateCrtKey privKey) throws IOException {
ASN1EncodableVector vec = new ASN1EncodableVector();
if (pubKey != null && privKey == null) {
vec.add(new ASN1Integer(pubKey.getModulus()));
vec.add(new ASN1Integer(pubKey.getPublicExponent()));
} else {
vec.add(new ASN1Integer(BigInteger.ZERO));
vec.add(new ASN1Integer(privKey.getModulus()));
vec.add(new ASN1Integer(privKey.getPublicExponent()));
vec.add(new ASN1Integer(privKey.getPrivateExponent()));
vec.add(new ASN1Integer(privKey.getPrimeP()));
vec.add(new ASN1Integer(privKey.getPrimeQ()));
vec.add(new ASN1Integer(privKey.getPrimeExponentP()));
vec.add(new ASN1Integer(privKey.getPrimeExponentQ()));
vec.add(new ASN1Integer(privKey.getCrtCoefficient()));
}
return new DLSequence(vec).getEncoded();
}
use of org.bouncycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class RecipInfo method asASN1.
public ASN1Encodable asASN1() {
ASN1EncodableVector vector = new ASN1EncodableVector();
vector.add(new ASN1Integer(BigInteger.valueOf(getVersion())));
vector.add(issuerAndSerial.toASN1Primitive());
vector.add(keyEncAlgor.toASN1Primitive());
vector.add(encKey.toASN1Primitive());
return new DLSequence(vector);
}
use of org.bouncycastle.asn1.DLSequence in project jruby-openssl by jruby.
the class Signed method asASN1.
public ASN1Encodable asASN1() {
ASN1EncodableVector vector = new ASN1EncodableVector();
vector.add(new ASN1Integer(BigInteger.valueOf(version)));
vector.add(digestAlgorithmsToASN1Set());
if (contents == null) {
contents = PKCS7.newEmpty();
}
vector.add(contents.asASN1());
if (cert != null && cert.size() > 0) {
if (cert.size() > 1) {
vector.add(new DERTaggedObject(false, 0, certificatesToASN1Set()));
} else {
// Encode the signer certificate directly for OpenSSL compatibility.
// OpenSSL does not support multiple signer signature.
// And OpenSSL requires EXPLICIT tagging.
vector.add(new DERTaggedObject(true, 0, firstCertificatesToASN1()));
}
}
if (crl != null && crl.size() > 0) {
vector.add(new DERTaggedObject(false, 1, crlsToASN1Set()));
}
vector.add(signerInfosToASN1Set());
return new DLSequence(vector);
}
Aggregations