use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.
the class PEMInputOutput method writeX509Aux.
public static void writeX509Aux(final Writer _out, final X509AuxCertificate cert) throws IOException {
BufferedWriter out = makeBuffered(_out);
final byte[] encoding;
final int encLen;
try {
if (cert.aux == null) {
encoding = cert.getEncoded();
encLen = encoding.length;
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] enc = cert.getEncoded();
baos.write(enc, 0, enc.length);
final X509Aux aux = cert.aux;
ASN1EncodableVector a1 = new ASN1EncodableVector();
if (aux.trust.size() > 0) {
ASN1EncodableVector a2 = new ASN1EncodableVector();
for (String trust : aux.trust) {
a2.add(new ASN1ObjectIdentifier(trust));
}
a1.add(new DLSequence(a2));
}
if (aux.reject.size() > 0) {
ASN1EncodableVector a2 = new ASN1EncodableVector();
for (String reject : aux.reject) {
a2.add(new ASN1ObjectIdentifier(reject));
}
a1.add(new DERTaggedObject(0, new DLSequence(a2)));
}
if (aux.alias != null) {
a1.add(new DERUTF8String(aux.alias));
}
if (aux.keyid != null) {
a1.add(new DEROctetString(aux.keyid));
}
if (aux.other.size() > 0) {
ASN1EncodableVector a2 = new ASN1EncodableVector();
for (ASN1Primitive other : aux.other) a2.add(other);
a1.add(new DERTaggedObject(1, new DLSequence(a2)));
}
enc = new DLSequence(a1).getEncoded();
baos.write(enc, 0, enc.length);
encoding = baos.buffer();
encLen = baos.size();
}
} catch (CertificateEncodingException e) {
throw new IOException("problem with encoding object in write_X509_AUX", e);
}
out.write(BEF_G + PEM_STRING_X509_TRUSTED + AFT);
out.newLine();
writeEncoded(out, encoding, encLen);
out.write(BEF_E + PEM_STRING_X509_TRUSTED + AFT);
out.newLine();
out.flush();
}
use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.
the class X509ExtensionFactory method parseAuthorityKeyIdentifier.
private ASN1Sequence parseAuthorityKeyIdentifier(final ThreadContext context, final String valuex) {
final ASN1EncodableVector vec = new ASN1EncodableVector();
for (String value : valuex.split(",")) {
// e.g. "keyid:always,issuer:always"
if (value.startsWith("keyid:")) {
// keyid:always
ASN1Encodable publicKeyIdentifier = new DEROctetString(publicKeyIdentifier(context));
vec.add(new DERTaggedObject(false, 0, publicKeyIdentifier));
} else if (value.startsWith("issuer:")) {
// issuer:always
GeneralName issuerName = new GeneralName(authorityCertIssuer(context));
vec.add(new DERTaggedObject(false, 1, new GeneralNames(issuerName)));
BigInteger issuerSerial = getIssuerSerialNumber(context);
if (issuerSerial != null) {
vec.add(new DERTaggedObject(false, 2, new ASN1Integer(issuerSerial)));
}
}
}
return new DERSequence(vec);
}
use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.
the class PKCS7 method asASN1.
public ASN1Encodable asASN1() {
ASN1EncodableVector vector = new ASN1EncodableVector();
ASN1ObjectIdentifier contentType;
if (data == null) {
// OpenSSL behavior
contentType = new ASN1ObjectIdentifier(EMPTY_PKCS7_OID);
} else {
contentType = ASN1Registry.nid2obj(getType());
}
vector.add(contentType);
if (data != null) {
vector.add(new DERTaggedObject(0, data.asASN1()));
}
return new DLSequence(vector);
}
use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.
the class SignerInfoWithPkey method toASN1Object.
/**
* Produce an object suitable for an ASN1OutputStream.
* <pre>
* SignerInfo ::= SEQUENCE {
* version Version,
* issuerAndSerialNumber IssuerAndSerialNumber,
* digestAlgorithm DigestAlgorithmIdentifier,
* authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL,
* digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
* encryptedDigest EncryptedDigest,
* unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
* }
*
* EncryptedDigest ::= OCTET STRING
*
* DigestAlgorithmIdentifier ::= AlgorithmIdentifier
*
* DigestEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
* </pre>
*/
public ASN1Encodable toASN1Object() {
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(version);
v.add(issuerAndSerialNumber);
v.add(digAlgorithm);
if (authenticatedAttributes != null) {
v.add(new DERTaggedObject(false, 0, authenticatedAttributes));
}
v.add(digEncryptionAlgorithm);
v.add(encryptedDigest);
if (unauthenticatedAttributes != null) {
v.add(new DERTaggedObject(false, 1, unauthenticatedAttributes));
}
return new DLSequence(v);
}
use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.
the class EncContent method asASN1.
public ASN1Encodable asASN1() {
ASN1EncodableVector vector = new ASN1EncodableVector();
vector.add(ASN1Registry.nid2obj(contentType).toASN1Primitive());
vector.add(algorithm.toASN1Primitive());
if (encData != null) {
vector.add(new DERTaggedObject(false, 0, encData));
}
return new DLSequence(vector);
}
Aggregations