use of com.github.zhenwei.core.asn1.DERTaggedObject in project staplr by pridiltal.
the class PdfPKCS7 method getSubject.
/**
* Get the "subject" from the TBSCertificate bytes that are passed in
* @param enc A TBSCertificate in a byte array
* @return a ASN1Primitive
*/
private static ASN1Primitive getSubject(byte[] enc) {
try {
ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc));
ASN1Sequence seq = (ASN1Sequence) in.readObject();
return (ASN1Primitive) seq.getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 5 : 4);
} catch (IOException e) {
throw new ExceptionConverter(e);
}
}
use of com.github.zhenwei.core.asn1.DERTaggedObject in project jcifs by codelibs.
the class NegTokenTarg method toByteArray.
@Override
public byte[] toByteArray() {
try {
ByteArrayOutputStream collector = new ByteArrayOutputStream();
ASN1OutputStream der = ASN1OutputStream.create(collector, ASN1Encoding.DER);
ASN1EncodableVector fields = new ASN1EncodableVector();
int res = getResult();
if (res != UNSPECIFIED_RESULT) {
fields.add(new DERTaggedObject(true, 0, new ASN1Enumerated(res)));
}
ASN1ObjectIdentifier mech = getMechanism();
if (mech != null) {
fields.add(new DERTaggedObject(true, 1, mech));
}
byte[] mechanismToken = getMechanismToken();
if (mechanismToken != null) {
fields.add(new DERTaggedObject(true, 2, new DEROctetString(mechanismToken)));
}
byte[] mechanismListMIC = getMechanismListMIC();
if (mechanismListMIC != null) {
fields.add(new DERTaggedObject(true, 3, new DEROctetString(mechanismListMIC)));
}
der.writeObject(new DERTaggedObject(true, 1, new DERSequence(fields)));
return collector.toByteArray();
} catch (IOException ex) {
throw new IllegalStateException(ex.getMessage());
}
}
use of com.github.zhenwei.core.asn1.DERTaggedObject in project netty by netty.
the class OcspUtils method ocspUri.
/**
* Returns the OCSP responder {@link URI} or {@code null} if it doesn't have one.
*/
public static URI ocspUri(X509Certificate certificate) throws IOException {
byte[] value = certificate.getExtensionValue(Extension.authorityInfoAccess.getId());
if (value == null) {
return null;
}
ASN1Primitive authorityInfoAccess = X509ExtensionUtil.fromExtensionValue(value);
if (!(authorityInfoAccess instanceof DLSequence)) {
return null;
}
DLSequence aiaSequence = (DLSequence) authorityInfoAccess;
DERTaggedObject taggedObject = findObject(aiaSequence, OCSP_RESPONDER_OID, DERTaggedObject.class);
if (taggedObject == null) {
return null;
}
if (taggedObject.getTagNo() != BERTags.OBJECT_IDENTIFIER) {
return null;
}
byte[] encoded = taggedObject.getEncoded();
int length = (int) encoded[1] & 0xFF;
String uri = new String(encoded, 2, length, CharsetUtil.UTF_8);
return URI.create(uri);
}
use of com.github.zhenwei.core.asn1.DERTaggedObject in project Conversations by siacs.
the class XmppDomainVerifier method parseOtherName.
private static Pair<String, String> parseOtherName(byte[] otherName) {
try {
ASN1Primitive asn1Primitive = ASN1Primitive.fromByteArray(otherName);
if (asn1Primitive instanceof DERTaggedObject) {
ASN1Primitive inner = ((DERTaggedObject) asn1Primitive).getObject();
if (inner instanceof DLSequence) {
DLSequence sequence = (DLSequence) inner;
if (sequence.size() >= 2 && sequence.getObjectAt(1) instanceof DERTaggedObject) {
String oid = sequence.getObjectAt(0).toString();
ASN1Primitive value = ((DERTaggedObject) sequence.getObjectAt(1)).getObject();
if (value instanceof DERUTF8String) {
return new Pair<>(oid, ((DERUTF8String) value).getString());
} else if (value instanceof DERIA5String) {
return new Pair<>(oid, ((DERIA5String) value).getString());
}
}
}
}
return null;
} catch (IOException e) {
return null;
}
}
use of com.github.zhenwei.core.asn1.DERTaggedObject in project wildfly by wildfly.
the class KerberosTestUtils method generateSpnegoTokenResp.
/**
* Generates SPNEGO response (to a "select mechanism challenge") with given bytes as the ticket for selected mechanism.
*
* @param ticket
* @return ASN.1 encoded SPNEGO response
*/
public static byte[] generateSpnegoTokenResp(byte[] ticket) throws IOException {
DEROctetString ourKerberosTicket = new DEROctetString(ticket);
// accept-incomplete
DERTaggedObject taggedNegState = new DERTaggedObject(0, new ASN1Enumerated(1));
DERTaggedObject taggedResponseToken = new DERTaggedObject(2, ourKerberosTicket);
ASN1EncodableVector v = new ASN1EncodableVector();
v.add(taggedNegState);
v.add(taggedResponseToken);
DERSequence seqNegTokenResp = new DERSequence(v);
DERTaggedObject taggedSpnego = new DERTaggedObject(1, seqNegTokenResp);
return taggedSpnego.getEncoded();
}
Aggregations