use of com.github.zhenwei.core.asn1.ASN1Primitive 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.ASN1Primitive in project pdf-sign-check by spapas.
the class CRLVerifier method getCrlDistributionPoints.
/**
* Extracts all CRL distribution point URLs from the "CRL Distribution
* Point" extension in a X.509 certificate. If CRL distribution point
* extension is unavailable, returns an empty list.
* @param cert
* @return List of CRL distribution point URLs.
* @throws java.io.IOException
*/
public static List<String> getCrlDistributionPoints(X509Certificate cert) throws IOException {
byte[] crldpExt = cert.getExtensionValue(Extension.cRLDistributionPoints.getId());
if (crldpExt == null) {
return new ArrayList<>();
}
ASN1Primitive derObjCrlDP;
try (ASN1InputStream oAsnInStream = new ASN1InputStream(crldpExt)) {
derObjCrlDP = oAsnInStream.readObject();
}
if (!(derObjCrlDP instanceof ASN1OctetString)) {
LOG.warn("CRL distribution points for certificate subject " + cert.getSubjectX500Principal().getName() + " should be an octet string, but is " + derObjCrlDP);
return new ArrayList<>();
}
ASN1OctetString dosCrlDP = (ASN1OctetString) derObjCrlDP;
byte[] crldpExtOctets = dosCrlDP.getOctets();
ASN1Primitive derObj2;
try (ASN1InputStream oAsnInStream2 = new ASN1InputStream(crldpExtOctets)) {
derObj2 = oAsnInStream2.readObject();
}
CRLDistPoint distPoint = CRLDistPoint.getInstance(derObj2);
List<String> crlUrls = new ArrayList<>();
for (DistributionPoint dp : distPoint.getDistributionPoints()) {
DistributionPointName dpn = dp.getDistributionPoint();
// Look for URIs in fullName
if (dpn != null && dpn.getType() == DistributionPointName.FULL_NAME) {
// Look for an URI
for (GeneralName genName : GeneralNames.getInstance(dpn.getName()).getNames()) {
if (genName.getTagNo() == GeneralName.uniformResourceIdentifier) {
String url = ASN1IA5String.getInstance(genName.getName()).getString();
crlUrls.add(url);
}
}
}
}
return crlUrls;
}
use of com.github.zhenwei.core.asn1.ASN1Primitive in project Falcon-File-Transfer-Optimizer by arif-zaman.
the class ProxyCertInfoTest method testParseProxyCertInfo.
public void testParseProxyCertInfo() throws Exception {
ProxyPolicy policy = new ProxyPolicy(testOid, testPolicy);
ProxyCertInfo info = new ProxyCertInfo(3, policy);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(info);
ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
ASN1InputStream dIn = new ASN1InputStream(bIn);
ASN1Primitive obj = dIn.readObject();
assertTrue(obj instanceof ASN1Sequence);
ProxyCertInfo testInfo = new ProxyCertInfo((ASN1Sequence) obj);
assertEquals(3, testInfo.getPathLenConstraint());
assertEquals(testPolicy, testInfo.getProxyPolicy().getPolicyAsString());
assertEquals(testOid, testInfo.getProxyPolicy().getPolicyLanguage());
}
use of com.github.zhenwei.core.asn1.ASN1Primitive in project Falcon-File-Transfer-Optimizer by arif-zaman.
the class ProxyCertInfoTest method testCreateProxyCertInfo2.
public void testCreateProxyCertInfo2() throws Exception {
ProxyPolicy policy = new ProxyPolicy(testOid, testPolicy);
ProxyCertInfo info = new ProxyCertInfo(policy);
assertEquals(Integer.MAX_VALUE, info.getPathLenConstraint());
assertEquals(testPolicy, info.getProxyPolicy().getPolicyAsString());
assertEquals(testOid, info.getProxyPolicy().getPolicyLanguage());
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
DEROutputStream dOut = new DEROutputStream(bOut);
dOut.writeObject(info);
ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
ASN1InputStream dIn = new ASN1InputStream(bIn);
ASN1Primitive obj = dIn.readObject();
ProxyCertInfo testInfo = new ProxyCertInfo((ASN1Sequence) obj);
assertEquals(Integer.MAX_VALUE, testInfo.getPathLenConstraint());
assertEquals(testPolicy, testInfo.getProxyPolicy().getPolicyAsString());
assertEquals(testOid, testInfo.getProxyPolicy().getPolicyLanguage());
}
use of com.github.zhenwei.core.asn1.ASN1Primitive in project Falcon-File-Transfer-Optimizer by arif-zaman.
the class BouncyCastleUtil method getExtensionValue.
/**
* Retrieves the actual value of the X.509 extension.
*
* @param certExtValue the DER-encoded OCTET string value of the extension.
* @return the decoded/actual value of the extension (the octets).
*/
public static byte[] getExtensionValue(byte[] certExtValue) throws IOException {
ByteArrayInputStream inStream = new ByteArrayInputStream(certExtValue);
ASN1InputStream derInputStream = new ASN1InputStream(inStream);
ASN1Primitive object = derInputStream.readObject();
if (object instanceof ASN1OctetString) {
return ((ASN1OctetString) object).getOctets();
} else {
throw new IOException(i18n.getMessage("octectExp"));
}
}
Aggregations