List of usage examples for org.bouncycastle.asn1.x500 X500Name getRDNs
public RDN[] getRDNs(ASN1ObjectIdentifier attributeType)
From source file:net.maritimecloud.identityregistry.utils.CertificateUtil.java
License:Apache License
/** * Extract a value from the DN extracted from a certificate * //from w w w .j a va2 s . c om * @param x500name * @param style * @return */ public static String getElement(X500Name x500name, ASN1ObjectIdentifier style) { try { RDN cn = x500name.getRDNs(style)[0]; return valueToString(cn.getFirst().getValue()); } catch (ArrayIndexOutOfBoundsException e) { return null; } }
From source file:net.maritimecloud.pki.CertificateHandler.java
License:Apache License
/** * Extract a value from the DN extracted from a certificate * * @param x500name The full DN from certificate * @param objectId The Identifier to find * @return the value of the identifier, or null if not found. */// w ww.j a v a 2 s.co m public static String getElement(X500Name x500name, ASN1ObjectIdentifier objectId) { try { RDN cn = x500name.getRDNs(objectId)[0]; return valueToString(cn.getFirst().getValue()); } catch (ArrayIndexOutOfBoundsException e) { return null; } }
From source file:net.ripe.rpki.commons.crypto.x509cert.X509ResourceCertificateParser.java
License:BSD License
public boolean mayHaveOneValidSerialNumber(X500Name principal) { RDN[] serialNumbers = principal.getRDNs(BCStyle.SERIALNUMBER); return serialNumbers.length <= 1; }
From source file:net.ripe.rpki.commons.crypto.x509cert.X509ResourceCertificateParser.java
License:BSD License
private boolean hasOneValidCn(X500Name principal) { RDN[] cns = principal.getRDNs(BCStyle.CN); if (cns.length != 1) { return false; }/*from w w w . jav a 2 s . com*/ AttributeTypeAndValue firstCn = cns[0].getFirst(); if (firstCn == null) { return false; } ASN1Encodable firstCnValue = firstCn.getValue(); return firstCnValue != null && isPrintableString(firstCnValue); }
From source file:net.sf.keystore_explorer.crypto.csr.spkac.SpkacSubject.java
License:Open Source License
private String getRdn(X500Name name, ASN1ObjectIdentifier rdnOid) { RDN[] rdns = name.getRDNs(rdnOid); if (rdns.length > 0) { RDN rdn = rdns[0];/*from w w w. j a va2 s.c o m*/ String value = rdn.getFirst().getValue().toString(); return value; } return null; }
From source file:net.sf.keystore_explorer.crypto.x509.X500NameUtils.java
License:Open Source License
/** * Returns the (first) value of the (first) RDN of type rdnOid * * @param dn The X500Name//from ww w . j av a 2 s . c o m * @param rdnOid OID of wanted RDN * @return Value of requested RDN */ public static String getRdn(X500Name dn, ASN1ObjectIdentifier rdnOid) { if (dn == null || rdnOid == null) { return ""; } RDN[] rdns = dn.getRDNs(rdnOid); String value = ""; if (rdns.length > 0) { RDN rdn = rdns[0]; value = rdn.getFirst().getValue().toString(); } return value; }
From source file:net.sf.portecle.crypto.NameUtil.java
License:Open Source License
/** * Gets the common name from the given X500Name. * /*ww w . ja v a 2 s. c o m*/ * @param name the X.500 name * @return the common name, null if not found */ public static String getCommonName(X500Name name) { if (name == null) { return null; } RDN[] rdns = name.getRDNs(BCStyle.CN); if (rdns.length == 0) { return null; } return rdns[0].getFirst().getValue().toString(); }
From source file:no.difi.bcp.server.service.CertificateService.java
License:EUPL
@Transactional public Certificate insert(Participant participant, X509Certificate cert) throws CertificateEncodingException, CertificateValidationException { Report report = validator.validate(cert, SimpleReport.newInstance()); Optional.ofNullable(report.get(NorwegianOrganizationNumberRule.ORGANIZATION)) .filter(no -> String.format("9908:%s", no.getNumber()).equals(participant.getIdentifier())) .orElseThrow(// w ww .j a v a 2 s.c o m () -> new CertificateValidationException("Unable to verify ownership of certificate.")); CertificateResult certificateResult = report.get(OCSPRule.RESULT); X500Name x500name = new JcaX509CertificateHolder(cert).getSubject(); String name = IETFUtils.valueToString(x500name.getRDNs(BCStyle.O)[0].getFirst().getValue()); if (x500name.getRDNs(BCStyle.OU).length > 0) name = String.format("%s - %s", name, IETFUtils.valueToString(x500name.getRDNs(BCStyle.OU)[0].getFirst().getValue())); Certificate certificate = new Certificate(); certificate.setCertificate(cert.getEncoded()); certificate.setSerialNumber(cert.getSerialNumber().toString()); if (certificateResult != null) certificate.setOcspUri(certificateResult.getUri()); certificate.setExpiration(cert.getNotAfter().getTime()); certificate.setParticipant(participant); certificate.setName(name); certificate.setSubject(cert.getSubjectX500Principal().getName()); certificate.setIssuer(issuerService.createOrFetch(report)); save(certificate); return certificate; }
From source file:org.apache.jmeter.assertions.SMIMEAssertion.java
License:Apache License
/** * Extract email addresses from a certificate * /*from w w w . j a v a 2 s . com*/ * @param cert the X509 certificate holder * @return a List of all email addresses found * @throws CertificateException */ private static List<String> getEmailFromCert(X509CertificateHolder cert) throws CertificateException { List<String> res = new ArrayList<>(); X500Name subject = cert.getSubject(); for (RDN emails : subject.getRDNs(BCStyle.EmailAddress)) { for (AttributeTypeAndValue emailAttr : emails.getTypesAndValues()) { log.debug("Add email from RDN: " + IETFUtils.valueToString(emailAttr.getValue())); res.add(IETFUtils.valueToString(emailAttr.getValue())); } } Extension subjectAlternativeNames = cert.getExtension(Extension.subjectAlternativeName); if (subjectAlternativeNames != null) { for (GeneralName name : GeneralNames.getInstance(subjectAlternativeNames.getParsedValue()).getNames()) { if (name.getTagNo() == GeneralName.rfc822Name) { String email = IETFUtils.valueToString(name.getName()); log.debug("Add email from subjectAlternativeName: " + email); res.add(email); } } } return res; }
From source file:org.cesecore.certificates.ca.X509CATest.java
License:Open Source License
private static ASN1Encodable getValueFromDN(Certificate cert, ASN1ObjectIdentifier oid) { final X500Principal principal = ((X509Certificate) cert).getSubjectX500Principal(); final X500Name xname = X500Name.getInstance(principal.getEncoded()); final RDN rdn = xname.getRDNs(oid)[0]; return rdn.getTypesAndValues()[0].getValue(); }