List of usage examples for org.bouncycastle.x509.extension X509ExtensionUtil getSubjectAlternativeNames
public static Collection getSubjectAlternativeNames(X509Certificate cert) throws CertificateParsingException
From source file:br.gov.jfrj.siga.cd.CertificadoUtil.java
License:Open Source License
/** * Recupera as propriedades ICP/Brasil-Pessoa Fsica (email e CPF) * //from www . ja v a 2 s . c o m * @param cert * @return * @throws IOException * @throws CertificateParsingException */ public static Properties recuperarPropriedadesNomesAlteranativos(X509Certificate cert) throws IOException, CertificateParsingException { Properties props = new Properties(); Pair<ASN1ObjectIdentifier, String> otherName; Iterator<?> subjectAltNamesIt = X509ExtensionUtil.getSubjectAlternativeNames(cert).iterator(); while (subjectAltNamesIt.hasNext()) { List<?> altName = (List<?>) subjectAltNamesIt.next(); int type = ((Integer) altName.get(0)).intValue(); if (type == GeneralName.rfc822Name) { String email = (String) altName.get(1); props.put("email", email); } else if (type == GeneralName.otherName) { otherName = getOtherName((DLSequence) altName.get(1)); props.put(otherName.first.getId(), otherName.second); } } // for (List<?> subjectAlternativeName : cert.getSubjectAlternativeNames()) { // String email; // @SuppressWarnings("unused") // int pos; // // // O primeiro elemento um Integer com o valor 0 = otherName, 1 // // = // // rfc822name etc. // // O segundo valor um byte array ou uma String. Veja o javadoc // // de // // getSubjectAlternativeNames. // switch (((Number) subjectAlternativeName.get(0)).intValue()) { // case 0: // OtherName - contm CPF, CNPJ etc. // // o OID fica em otherName.first // Collection collection = X509ExtensionUtil.getSubjectAlternativeNames(cert); // otherName = getOtherName((byte[]) subjectAlternativeName.get(1)); // props.put(otherName.first.getId(), otherName.second); // break; // case 1: // rfc822Name - usado para email // email = (String) subjectAlternativeName.get(1); // props.put("email", email); // break; // default: // break; // } // } return props; }
From source file:me.yanaga.opes.CertificadoDigital.java
License:Apache License
private static CpfCnpj extractCnpj(Certificate[] certs) { X509Certificate[] certificates = (X509Certificate[]) certs; for (X509Certificate certificate : certificates) { try {//from w w w . ja v a 2s .co m for (Object obj : X509ExtensionUtil.getSubjectAlternativeNames(certificate)) { if (obj instanceof List) { List values = (List) obj; if (values.get(1) instanceof DLSequence) { DLSequence seq = (DLSequence) values.get(1); ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) seq.getObjectAt(0); if (OID_CNPJ.equals(oid)) { ASN1TaggedObject tagged = (ASN1TaggedObject) seq.getObjectAt(1); ASN1Object derObj = tagged.getObject(); try { String s = new String(derObj.getEncoded()); return CpfCnpj.of(s); } catch (IOException e) { e.printStackTrace(); } } } } } } catch (CertificateParsingException e) { throw new IllegalArgumentException("Erro ao extrair CNPJ do CertificadoDigital", e); } } return null; }
From source file:org.opcfoundation.ua.transport.security.BcCertificateProvider.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public Collection<List<?>> getSubjectAlternativeNames(X509Certificate cert) throws CertificateParsingException { return X509ExtensionUtil.getSubjectAlternativeNames(cert); }
From source file:org.opcfoundation.ua.utils.BouncyCastleUtils.java
License:Open Source License
@SuppressWarnings("unchecked") public static Collection<List<?>> getSubjectAlternativeNames(X509Certificate cert) throws CertificateParsingException { return X509ExtensionUtil.getSubjectAlternativeNames(cert); // try { // byte[] ext = cert.getExtensionValue(SUBJECT_ALT_NAME_OID); // if (ext == null) // return null; // DerValue val = new DerValue(ext); // byte[] data = val.getOctetString(); // //from w w w . j a v a2 s .c o m // SubjectAlternativeNameExtension subjectAltNameExt = new SubjectAlternativeNameExtension( // Boolean.FALSE, data); // // GeneralNames names; // try { // names = (GeneralNames) subjectAltNameExt // .get(SubjectAlternativeNameExtension.SUBJECT_NAME); // } catch (IOException ioe) { // // should not occur // return Collections.<List<?>> emptySet(); // } // return makeAltNames(names); // } catch (IOException ioe) { // CertificateParsingException cpe = new CertificateParsingException(); // cpe.initCause(ioe); // throw cpe; // } }