use of com.github.zhenwei.core.asn1.ASN1Encodable in project ca3sCore by kuehne-trustable-de.
the class CertificateUtil method getSANList.
public Set<GeneralName> getSANList(Pkcs10RequestHolder p10ReqHolder) {
Set<GeneralName> generalNameSet = new HashSet<>();
for (Attribute attr : p10ReqHolder.getReqAttributes()) {
if (PKCSObjectIdentifiers.pkcs_9_at_extensionRequest.equals(attr.getAttrType())) {
ASN1Set valueSet = attr.getAttrValues();
LOG.debug("ExtensionRequest / AttrValues has {} elements", valueSet.size());
for (ASN1Encodable asn1Enc : valueSet) {
DERSequence derSeq = (DERSequence) asn1Enc;
LOG.debug("ExtensionRequest / DERSequence has {} elements", derSeq.size());
LOG.debug("ExtensionRequest / DERSequence[0] is a {}", derSeq.getObjectAt(0).getClass().getName());
DERSequence derSeq2 = (DERSequence) derSeq.getObjectAt(0);
LOG.debug("ExtensionRequest / DERSequence2 has {} elements", derSeq2.size());
LOG.debug("ExtensionRequest / DERSequence2[0] is a {}", derSeq2.getObjectAt(0).getClass().getName());
ASN1ObjectIdentifier objId = (ASN1ObjectIdentifier) (derSeq2.getObjectAt(0));
if (Extension.subjectAlternativeName.equals(objId)) {
DEROctetString derStr = (DEROctetString) derSeq2.getObjectAt(1);
GeneralNames names = GeneralNames.getInstance(derStr.getOctets());
LOG.debug("Attribute value SAN" + names);
LOG.debug("SAN values #" + names.getNames().length);
for (GeneralName gnSAN : names.getNames()) {
LOG.debug("GN " + gnSAN.toString());
generalNameSet.add(gnSAN);
}
} else {
LOG.info("Unexpected Extensions Attribute value " + objId.getId());
}
}
}
}
return generalNameSet;
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project identity-credential by google.
the class Util method signatureDerToCose.
/*
* From RFC 8152 section 8.1 ECDSA:
*
* The signature algorithm results in a pair of integers (R, S). These
* integers will be the same length as the length of the key used for
* the signature process. The signature is encoded by converting the
* integers into byte strings of the same length as the key size. The
* length is rounded up to the nearest byte and is left padded with zero
* bits to get to the correct length. The two integers are then
* concatenated together to form a byte string that is the resulting
* signature.
*/
private static byte[] signatureDerToCose(byte[] signature, int keySize) {
ASN1Primitive asn1;
try {
asn1 = new ASN1InputStream(new ByteArrayInputStream(signature)).readObject();
} catch (IOException e) {
throw new IllegalArgumentException("Error decoding DER signature", e);
}
if (!(asn1 instanceof ASN1Sequence)) {
throw new IllegalArgumentException("Not a ASN1 sequence");
}
ASN1Encodable[] asn1Encodables = ((ASN1Sequence) asn1).toArray();
if (asn1Encodables.length != 2) {
throw new IllegalArgumentException("Expected two items in sequence");
}
if (!(asn1Encodables[0].toASN1Primitive() instanceof ASN1Integer)) {
throw new IllegalArgumentException("First item is not an integer");
}
BigInteger r = ((ASN1Integer) asn1Encodables[0].toASN1Primitive()).getValue();
if (!(asn1Encodables[1].toASN1Primitive() instanceof ASN1Integer)) {
throw new IllegalArgumentException("Second item is not an integer");
}
BigInteger s = ((ASN1Integer) asn1Encodables[1].toASN1Primitive()).getValue();
byte[] rBytes = stripLeadingZeroes(r.toByteArray());
byte[] sBytes = stripLeadingZeroes(s.toByteArray());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
for (int n = 0; n < keySize - rBytes.length; n++) {
baos.write(0x00);
}
baos.write(rBytes);
for (int n = 0; n < keySize - sBytes.length; n++) {
baos.write(0x00);
}
baos.write(sBytes);
} catch (IOException e) {
e.printStackTrace();
return null;
}
return baos.toByteArray();
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project TLS-Scanner by tls-attacker.
the class OcspProbe method prepareNonceExtension.
private byte[] prepareNonceExtension() {
Asn1Sequence innerExtensionSequence = new Asn1Sequence();
Asn1ObjectIdentifier oid = new Asn1ObjectIdentifier();
oid.setValue(NONCE.getOID());
Asn1Sequence extensionSequence = new Asn1Sequence();
innerExtensionSequence.addChild(oid);
Asn1EncapsulatingOctetString encapsulatingOctetString = new Asn1EncapsulatingOctetString();
// Nonce
Asn1PrimitiveOctetString nonceOctetString = new Asn1PrimitiveOctetString();
Random rand = new Random(STAPLED_NONCE_RANDOM_SEED);
BigInteger nonce = new BigInteger(STAPLED_NONCE_RANDOM_BIT_LENGTH, rand);
nonceOctetString.setValue(nonce.toByteArray());
encapsulatingOctetString.addChild(nonceOctetString);
innerExtensionSequence.addChild(encapsulatingOctetString);
extensionSequence.addChild(innerExtensionSequence);
List<Asn1Encodable> asn1Encodables = new LinkedList<>();
asn1Encodables.add(extensionSequence);
Asn1Encoder asn1Encoder = new Asn1Encoder(asn1Encodables);
return asn1Encoder.encode();
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project wildfly-elytron by wildfly-security.
the class X500DirectoryAttribute method encodeTo.
public void encodeTo(final ASN1Encoder encoder) {
encoder.startSequence();
encoder.encodeObjectIdentifier(attributeType);
encoder.startSet();
for (ASN1Encodable value : values) {
value.encodeTo(encoder);
}
encoder.endSet();
encoder.endSequence();
}
use of com.github.zhenwei.core.asn1.ASN1Encodable in project mercury by yellow013.
the class OcspUtils method findObject.
private static <T> T findObject(DLSequence sequence, ASN1ObjectIdentifier oid, Class<T> type) {
for (ASN1Encodable element : sequence) {
if (!(element instanceof DLSequence)) {
continue;
}
DLSequence subSequence = (DLSequence) element;
if (subSequence.size() != 2) {
continue;
}
ASN1Encodable key = subSequence.getObjectAt(0);
ASN1Encodable value = subSequence.getObjectAt(1);
if (key.equals(oid) && type.isInstance(value)) {
return type.cast(value);
}
}
return null;
}
Aggregations