org.bouncycastle.x509.extension.X509ExtensionUtil Java Examples

The following examples show how to use org.bouncycastle.x509.extension.X509ExtensionUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyIdentifierImpl.java    From SecuritySample with Apache License 2.0 6 votes vote down vote up
public KeyIdentifierImpl(X509Certificate cert) throws CertificateException, IOException {
    byte[] extVal = cert.getExtensionValue(Extension.authorityKeyIdentifier.getId());
    if (extVal == null) {
        lock = true;
        return;
    }
    AuthorityKeyIdentifier aki = AuthorityKeyIdentifier.getInstance(X509ExtensionUtil.fromExtensionValue(extVal));
    keyIdentifier = aki.getKeyIdentifier();
}
 
Example #2
Source File: CRLDistributionPointsImpl.java    From SecuritySample with Apache License 2.0 6 votes vote down vote up
public CRLDistributionPointsImpl(X509Certificate cert) throws CertificateException, IOException {
	URINames = new ArrayList<>();
	byte[] extVal = cert.getExtensionValue(Extension.cRLDistributionPoints.getId());
	if (extVal == null)
		return;
	CRLDistPoint crlDistPoint = CRLDistPoint.getInstance(X509ExtensionUtil.fromExtensionValue(extVal));
	DistributionPoint[] points = crlDistPoint.getDistributionPoints();
	for (DistributionPoint p : points) {
		GeneralNames tmp = p.getCRLIssuer();
		if (tmp != null) {
			GeneralName[] crlIssers = tmp.getNames();
			for (int i = 0; i < crlIssers.length; i++) {
				if (crlIssers[i].getTagNo() == GeneralName.uniformResourceIdentifier) {
					String issuerUrl = crlIssers[i].toString();
					URINames.add(issuerUrl);
				}
			}
		}
	}
}
 
Example #3
Source File: X509Util.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the list of alternative names of a given name type.
 * 
 * @param certificate the certificate to extract the alternative names from
 * @param nameTypes the name types
 * 
 * @return the alt names, of the given type, within the cert
 */
public static List getAltNames(X509Certificate certificate, Integer[] nameTypes) {
    Logger log = getLogger();
    if (certificate == null) {
        return null;
    }

    List<Object> names = new LinkedList<Object>();
    Collection<List<?>> altNames = null;
    try {
        altNames = X509ExtensionUtil.getSubjectAlternativeNames(certificate);
    } catch (CertificateParsingException e) {
        log.error("Encountered an problem trying to extract Subject Alternate "
                + "Name from supplied certificate: " + e);
        return names;
    }

    if (altNames != null) {
        // 0th position represents the alt name type
        // 1st position contains the alt name data
        for (List altName : altNames) {
            for (Integer nameType : nameTypes) {
                if (altName.get(0).equals(nameType)) {
                    names.add(convertAltNameType(nameType, altName.get(1)));
                    break;
                }
            }
        }
    }

    return names;
}
 
Example #4
Source File: BasicConstraintsImpl.java    From SecuritySample with Apache License 2.0 5 votes vote down vote up
public BasicConstraintsImpl(X509Certificate cert) throws CertificateException, IOException {
	byte[] extVal = cert.getExtensionValue(Extension.basicConstraints.getId());
	if (extVal == null)
		return;
	org.bouncycastle.asn1.x509.BasicConstraints bc = org.bouncycastle.asn1.x509.BasicConstraints
			.getInstance(X509ExtensionUtil.fromExtensionValue(extVal));
	isCA = bc.isCA();
	pathLen = bc.getPathLenConstraint();
}
 
Example #5
Source File: CertificatePoliciesImpl.java    From SecuritySample with Apache License 2.0 5 votes vote down vote up
public CertificatePoliciesImpl(X509Certificate cert) throws IOException {
	certificatePolicyIds = new ArrayList<>();
	byte[] extVal = cert.getExtensionValue(Extension.certificatePolicies.getId());
	if (extVal == null)
		return;
	org.bouncycastle.asn1.x509.CertificatePolicies cf = org.bouncycastle.asn1.x509.CertificatePolicies
			.getInstance(X509ExtensionUtil.fromExtensionValue(extVal));
	PolicyInformation[] information = cf.getPolicyInformation();
	for (PolicyInformation p : information) {
		ASN1ObjectIdentifier aIdentifier = p.getPolicyIdentifier();
		certificatePolicyIds.add(aIdentifier.getId());
	}
}
 
Example #6
Source File: ExtendedKeyUsageImpl.java    From SecuritySample with Apache License 2.0 5 votes vote down vote up
public ExtendedKeyUsageImpl(X509Certificate cert) throws IOException {
	keyPurposeIds = new ArrayList<>();
	byte[] extVal = cert.getExtensionValue(Extension.extendedKeyUsage.getId());
	if (extVal == null)
		return;
	org.bouncycastle.asn1.x509.ExtendedKeyUsage usage = org.bouncycastle.asn1.x509.ExtendedKeyUsage
			.getInstance(X509ExtensionUtil.fromExtensionValue(extVal));
	KeyPurposeId[] usages = usage.getUsages();
	for (int i = 0; i < usages.length; i++) {
		keyPurposeIds.add(usages[i].getId());
	}
}
 
Example #7
Source File: SubjectAlternativeNameImpl.java    From SecuritySample with Apache License 2.0 5 votes vote down vote up
public SubjectAlternativeNameImpl(X509Certificate cert) throws IOException {
	DNSNames = new ArrayList<>();
	byte[] extVal = cert.getExtensionValue(Extension.subjectAlternativeName.getId());
	if (extVal == null)
		return;
	GeneralNames gn = GeneralNames.getInstance(X509ExtensionUtil.fromExtensionValue(extVal));
	GeneralName[] names = gn.getNames();
	for (GeneralName name : names) {
		if (name.getTagNo() == GeneralName.dNSName) {
			String dns = name.getName().toString();
			DNSNames.add(dns);
		}
	}
}
 
Example #8
Source File: SubjectKeyIdentifierImpl.java    From SecuritySample with Apache License 2.0 5 votes vote down vote up
public SubjectKeyIdentifierImpl(X509Certificate cert) throws IOException {
    byte[] extVal = cert.getExtensionValue(Extension.subjectKeyIdentifier.getId());
    if (extVal == null) {
        lock = true;
        return;
    }
    org.bouncycastle.asn1.x509.SubjectKeyIdentifier identifier = org.bouncycastle.asn1.x509.SubjectKeyIdentifier
            .getInstance(X509ExtensionUtil.fromExtensionValue(extVal));
    keyIdentifier = identifier.getKeyIdentifier();
}
 
Example #9
Source File: CrlExtensionsUtils.java    From xades4j with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static BigInteger getCrlNumber(X509CRL crl) throws IOException
{
    byte[] crlNumEnc = crl.getExtensionValue(X509Extension.cRLNumber.getId());
    BigInteger crlNum = null;
    // XAdES 7.4.2: "The 'number' element is an optional hint ..."
    if (crlNumEnc != null)
    {
        ASN1Object derCrlNum = X509ExtensionUtil.fromExtensionValue(crlNumEnc);
        crlNum = CRLNumber.getInstance(derCrlNum).getCRLNumber();
    }
    return crlNum;
}