List of usage examples for org.bouncycastle.asn1 ASN1InputStream ASN1InputStream
public ASN1InputStream(byte[] input)
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
private static DLSequence getEncodedIssuer(final byte[] enc) { try {//from w ww .ja v a 2 s. co m final ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(enc)); final ASN1Sequence seq = (ASN1Sequence) in.readObject(); return (DLSequence) seq.getObjectAt(seq.getObjectAt(0) instanceof DERTaggedObject ? 3 : 2); } catch (final IOException e) { return null; } }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
private void buildCerts(ASN1EncodableVector body, List<X509Certificate> chain) throws IOException, CertificateEncodingException { // -------- Certificados ASN1EncodableVector certVector = new ASN1EncodableVector(); for (X509Certificate next : chain) { ASN1InputStream tempstream = new ASN1InputStream(new ByteArrayInputStream(next.getEncoded())); certVector.add(tempstream.readObject()); // 5 CERT (SEQ) }/* ww w . java 2s .c om*/ final DERSet dercertificates = new DERSet(certVector); // 4 SET body.add(new DERTaggedObject(false, 0, dercertificates)); // 3 CS }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
private void buildCerts(ASN1EncodableVector body, X509Certificate certContent) throws IOException, CertificateEncodingException { // -------- Certificados ASN1EncodableVector certVector = new ASN1EncodableVector(); ASN1InputStream tempstream = new ASN1InputStream(new ByteArrayInputStream(certContent.getEncoded())); certVector.add(tempstream.readObject()); // 5 CERT (SEQ) final DERSet dercertificates = new DERSet(certVector); // 4 SET body.add(new DERTaggedObject(false, 0, dercertificates)); // 3 CS }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
public static String extractHashId(byte[] sign) throws Exception { String ret = null;// w w w . j a v a 2s.co m ASN1InputStream is = new ASN1InputStream(new ByteArrayInputStream(sign)); ASN1Primitive topLevel = is.readObject(); LOG.debug("top level:" + topLevel.getClass().getName()); if (topLevel instanceof org.bouncycastle.asn1.DLSequence) { DLSequence topLevelDLS = (DLSequence) topLevel; if (topLevelDLS.size() == 2) { ASN1Encodable level1 = topLevelDLS.getObjectAt(1); LOG.debug("level1:" + level1.getClass().getName()); if (level1 instanceof org.bouncycastle.asn1.DERTaggedObject) { DERTaggedObject level1TO = (DERTaggedObject) level1; ASN1Primitive level2 = level1TO.getObject(); LOG.debug("level2:" + level2.getClass().getName()); if (level2 instanceof org.bouncycastle.asn1.DERSequence) { DERSequence level2DS = (DERSequence) level2; LOG.debug("level2 len:" + level2DS.size()); ASN1Encodable level3_1 = level2DS.getObjectAt(1); LOG.debug("level3_1:" + level3_1.getClass().getName()); if (level3_1 instanceof org.bouncycastle.asn1.DERSet) { DERSet level3_1Set = (DERSet) level3_1; ASN1Encodable level4_1 = level3_1Set.getObjectAt(0); LOG.debug("level4_1:" + level4_1.getClass().getName()); if (level4_1 instanceof org.bouncycastle.asn1.DERSequence) { DERSequence level4_1Seq = (DERSequence) level4_1; ASN1Encodable level5_0 = level4_1Seq.getObjectAt(0); LOG.debug("level5_0:" + level5_0.getClass().getName()); if (level5_0 instanceof org.bouncycastle.asn1.ASN1ObjectIdentifier) { ASN1ObjectIdentifier level5_0Seq = (ASN1ObjectIdentifier) level5_0; LOG.debug(level5_0Seq.toString()); ret = level5_0Seq.toString(); } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } return ret; }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
public static byte[] extractSignature(byte[] sign) throws Exception { byte[] ret = null; ASN1InputStream is = new ASN1InputStream(new ByteArrayInputStream(sign)); ASN1Primitive topLevel = is.readObject(); LOG.debug("top level:" + topLevel.getClass().getName()); if (topLevel instanceof org.bouncycastle.asn1.DLSequence) { DLSequence topLevelDLS = (DLSequence) topLevel; if (topLevelDLS.size() == 2) { ASN1Encodable level1 = topLevelDLS.getObjectAt(1); LOG.debug("level1:" + level1.getClass().getName()); if (level1 instanceof org.bouncycastle.asn1.DERTaggedObject) { DERTaggedObject level1TO = (DERTaggedObject) level1; ASN1Primitive level2 = level1TO.getObject(); LOG.debug("level2:" + level2.getClass().getName()); if (level2 instanceof org.bouncycastle.asn1.DERSequence) { DERSequence level2DS = (DERSequence) level2; LOG.debug("level2 len:" + level2DS.size()); ASN1Encodable level3_4 = level2DS.getObjectAt(level2DS.size() - 1); LOG.debug("level3_4:" + level3_4.getClass().getName()); if (level3_4 instanceof org.bouncycastle.asn1.DERSet) { DERSet level3_4DS = (DERSet) level3_4; ASN1Encodable level3_4_0 = level3_4DS.getObjectAt(0); LOG.debug("level3_4_0:" + level3_4_0.getClass().getName()); if (level3_4_0 instanceof org.bouncycastle.asn1.DERSequence) { DERSequence level3_4_0DS = (DERSequence) level3_4_0; LOG.debug("level3_4_0DS len:" + level3_4_0DS.size()); ASN1Encodable signature = level3_4_0DS.getObjectAt(level3_4_0DS.size() - 1); LOG.debug("signature:" + signature.getClass().getName()); if (signature instanceof org.bouncycastle.asn1.DEROctetString) { DEROctetString signDOS = (DEROctetString) signature; ret = signDOS.getOctets(); }/*from ww w . j av a 2 s. co m*/ } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } return ret; }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
public static DERTaggedObject extractDTOSignPolicyOid(byte[] sign, SignCompare signCompare) throws Exception { DERTaggedObject ret = null;//from w ww .j a v a2 s.c om ASN1InputStream is = new ASN1InputStream(new ByteArrayInputStream(sign)); ASN1Primitive topLevel = is.readObject(); LOG.debug("top level:" + topLevel.getClass().getName()); if (topLevel instanceof org.bouncycastle.asn1.DLSequence) { DLSequence topLevelDLS = (DLSequence) topLevel; if (topLevelDLS.size() == 2) { ASN1Encodable level1 = topLevelDLS.getObjectAt(1); LOG.debug("level1:" + level1.getClass().getName()); if (level1 instanceof org.bouncycastle.asn1.DERTaggedObject) { DERTaggedObject level1TO = (DERTaggedObject) level1; ASN1Primitive level2 = level1TO.getObject(); LOG.debug("level2:" + level2.getClass().getName()); if (level2 instanceof org.bouncycastle.asn1.DERSequence) { DERSequence level2DS = (DERSequence) level2; LOG.debug("level2 len:" + level2DS.size()); signCompare.setNumCerts(extractCertCount(level2DS)); ret = extractSignedAttributes(level2DS); } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } return ret; }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
public static void extractSignCompare2(byte[] sign, SignCompare2 signCompare) throws Exception { saveDebug(sign);/*from w w w. j ava2 s . c om*/ DERTaggedObject ret = null; ASN1InputStream is = new ASN1InputStream(new ByteArrayInputStream(sign)); ASN1Primitive topLevel = is.readObject(); LOG.debug("top level:" + topLevel.getClass().getName()); if (topLevel instanceof org.bouncycastle.asn1.DLSequence) { DLSequence topLevelDLS = (DLSequence) topLevel; if (topLevelDLS.size() == 2) { ASN1Encodable level1 = topLevelDLS.getObjectAt(1); LOG.debug("level1:" + level1.getClass().getName()); if (level1 instanceof org.bouncycastle.asn1.DERTaggedObject) { DERTaggedObject level1TO = (DERTaggedObject) level1; ASN1Primitive level2 = level1TO.getObject(); LOG.debug("level2:" + level2.getClass().getName()); if (level2 instanceof org.bouncycastle.asn1.DERSequence) { DERSequence level2DS = (DERSequence) level2; LOG.debug("level2 len:" + level2DS.size()); signCompare.setNumCerts(extractCertCount(level2DS)); ret = extractSignedAttributes(level2DS); } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } // return ret; }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
public static List<byte[]> extractCertList(byte[] sign) throws Exception { List<byte[]> ret = null; ASN1InputStream is = new ASN1InputStream(new ByteArrayInputStream(sign)); ASN1Primitive topLevel = is.readObject(); LOG.debug("top level:" + topLevel.getClass().getName()); if (topLevel instanceof org.bouncycastle.asn1.DLSequence) { DLSequence topLevelDLS = (DLSequence) topLevel; if (topLevelDLS.size() == 2) { ASN1Encodable level1 = topLevelDLS.getObjectAt(1); LOG.debug("level1:" + level1.getClass().getName()); if (level1 instanceof org.bouncycastle.asn1.DERTaggedObject) { DERTaggedObject level1TO = (DERTaggedObject) level1; ASN1Primitive level2 = level1TO.getObject(); LOG.debug("level2:" + level2.getClass().getName()); if (level2 instanceof org.bouncycastle.asn1.DERSequence) { DERSequence level2DS = (DERSequence) level2; LOG.debug("level2 len:" + level2DS.size()); ret = extractCertArray(level2DS); } else { throw new Exception("DER enconding error"); }// w ww . ja v a 2 s. co m } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } } else { throw new Exception("DER enconding error"); } return ret; }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
public static SignPolicyRef extractVerifyRefence(byte[] policy) throws IOException, ParseException { SignPolicyRef ret = new SignPolicyRef(); ASN1InputStream is = new ASN1InputStream(new ByteArrayInputStream(policy)); ASN1Primitive topLevel = is.readObject(); // SignaturePolicy ::= SEQUENCE { // signPolicyHashAlg AlgorithmIdentifier, // signPolicyInfo SignPolicyInfo, // signPolicyHash SignPolicyHash OPTIONAL } if (topLevel instanceof DLSequence) { DLSequence topLevelDLS = (DLSequence) topLevel; ASN1Encodable dseqL10 = topLevelDLS.getObjectAt(0); ASN1Encodable psHashAlg = null;//from w ww .j a v a2 s . com if (dseqL10 instanceof DLSequence) { DLSequence dseqL10DLS = (DLSequence) dseqL10; psHashAlg = dseqL10DLS.getObjectAt(0); } else if (dseqL10 instanceof ASN1ObjectIdentifier) { psHashAlg = (ASN1ObjectIdentifier) dseqL10; } else return null; if (psHashAlg instanceof ASN1ObjectIdentifier) { ASN1ObjectIdentifier psHashAlgOid = (ASN1ObjectIdentifier) psHashAlg; ret.setPsHashAlg(psHashAlgOid.toString()); } ASN1Encodable dseqL11 = topLevelDLS.getObjectAt(1); if (dseqL11 instanceof DLSequence) { // SignPolicyInfo ::= SEQUENCE { DLSequence dseqL11DLS = (DLSequence) dseqL11; ASN1Encodable psOid = dseqL11DLS.getObjectAt(0); // signPolicyIdentifier SignPolicyId, // 2.16.76.1.7.1.6.2.1 if (psOid instanceof ASN1ObjectIdentifier) { ASN1ObjectIdentifier psOidOid = (ASN1ObjectIdentifier) psOid; ret.setPsOid(psOidOid.toString()); } ASN1Encodable dateOfIssue = dseqL11DLS.getObjectAt(1); // dateOfIssue GeneralizedTime, // 2012-03-22 if (dateOfIssue instanceof ASN1GeneralizedTime) { ASN1GeneralizedTime dateOfIssueGT = (ASN1GeneralizedTime) dateOfIssue; ret.setDateOfIssue(dateOfIssueGT.getDate()); } ASN1Encodable policyIssuerName = dseqL11DLS.getObjectAt(2); // policyIssuerName PolicyIssuerName, // C=BR, O=ICP-Brasil, OU=Instituto Nacional de Tecnologia da // Informacao // - ITI if (policyIssuerName instanceof DLSequence) { DLSequence policyIssuerNameDLSeq = (DLSequence) policyIssuerName; ASN1Encodable policyIssuerName2 = policyIssuerNameDLSeq.getObjectAt(0); if (policyIssuerName2 instanceof DERTaggedObject) { DERTaggedObject policyIssuerName2DTO = (DERTaggedObject) policyIssuerName2; ASN1Primitive polIssuerNameObj = policyIssuerName2DTO.getObject(); if (polIssuerNameObj instanceof DEROctetString) { String polIssuerNameStr = new String(((DEROctetString) polIssuerNameObj).getOctets()); ret.setPolIssuerName(polIssuerNameStr); } } } ASN1Encodable fieldOfApplication = dseqL11DLS.getObjectAt(3); // fieldOfApplication FieldOfApplication, // Este tipo de assinatura deve ser utilizado em aplicacoes ou // processos // de negocio nos quais a assinatura digital agrega seguranca a // autenticacao de entidades e verificacao de integridade, // permitindo // sua validacao durante o prazo de, validade dos certificados // dos // signatarios. Uma vez que nao sao usados carimbos do tempo, a // validacao posterior so sera possivel se existirem referencias // temporais que identifiquem o momento em que ocorreu a // assinatura // digital. Nessas situacoes, deve existir legislacao especifica // ou um // acordo previo entre as partes definindo as referencias a // serem // utilizadas. Segundo esta PA, e permitido o emprego de // multiplas // assinaturas. if (fieldOfApplication instanceof DEROctetString) { DERUTF8String fieldOfApplicationDUS = (DERUTF8String) fieldOfApplication; ret.setFieldOfApplication(fieldOfApplicationDUS.getString()); } // signatureValidationPolicy SignatureValidationPolicy, // signPolExtensions SignPolExtensions OPTIONAL // SignatureValidationPolicy ::= SEQUENCE { ASN1Encodable signatureValidationPolicy = dseqL11DLS.getObjectAt(4); if (signatureValidationPolicy instanceof DLSequence) { DLSequence signatureValidationPolicyDLS = (DLSequence) signatureValidationPolicy; // signingPeriod SigningPeriod, // NotBefore 2012-03-22 // NotAfter 2023-06-21 ASN1Encodable signingPeriod = signatureValidationPolicyDLS.getObjectAt(0); if (signingPeriod instanceof DLSequence) { DLSequence signingPeriodDLS = (DLSequence) signingPeriod; ASN1Encodable notBefore = signingPeriodDLS.getObjectAt(0); if (notBefore instanceof ASN1GeneralizedTime) { ASN1GeneralizedTime notBeforeAGT = (ASN1GeneralizedTime) notBefore; ret.setNotBefore(notBeforeAGT.getDate()); } ASN1Encodable notAfter = signingPeriodDLS.getObjectAt(1); if (notAfter instanceof ASN1GeneralizedTime) { ASN1GeneralizedTime notAfterAGT = (ASN1GeneralizedTime) notAfter; ret.setNotAfter(notAfterAGT.getDate()); } } // // commonRules CommonRules, ASN1Encodable commonRules = getAt(signatureValidationPolicyDLS, 1); if (commonRules instanceof DLSequence) { DLSequence commonRulesDLS = (DLSequence) commonRules; // CommonRules ::= SEQUENCE { // signerAndVeriferRules [0] SignerAndVerifierRules // OPTIONAL, // signingCertTrustCondition [1] // SigningCertTrustCondition OPTIONAL, // timeStampTrustCondition [2] TimestampTrustCondition // OPTIONAL, // attributeTrustCondition [3] AttributeTrustCondition // OPTIONAL, // algorithmConstraintSet [4] AlgorithmConstraintSet // OPTIONAL, // signPolExtensions [5] SignPolExtensions OPTIONAL // } ASN1Encodable signerAndVeriferRules = getAt(commonRulesDLS, 0); // SignerAndVerifierRules ::= SEQUENCE { // signerRules SignerRules, // verifierRules VerifierRules } if (signerAndVeriferRules instanceof DERTaggedObject) { DERTaggedObject signerAndVeriferRulesDTO = (DERTaggedObject) signerAndVeriferRules; ASN1Encodable signerAndVeriferRulesTmp = signerAndVeriferRulesDTO.getObject(); if (signerAndVeriferRulesTmp instanceof DERSequence) { DERSequence signerAndVeriferRulesDERSeq = (DERSequence) signerAndVeriferRulesTmp; ASN1Encodable signerRules = getAt(signerAndVeriferRulesDERSeq, 0); if (signerRules instanceof DERSequence) { DERSequence signerRulesDERSeq = (DERSequence) signerRules; // SignerRules ::= SEQUENCE { // externalSignedData BOOLEAN OPTIONAL, // -- True if signed data is external to CMS // structure // -- False if signed data part of CMS // structure // -- not present if either allowed // mandatedSignedAttr CMSAttrs, // -- Mandated CMS signed attributes // 1.2.840.113549.1.9.3 // 1.2.840.113549.1.9.4 // 1.2.840.113549.1.9.16.2.15 // 1.2.840.113549.1.9.16.2.47 // mandatedUnsignedAttr CMSAttrs, // <empty sequence> // -- Mandated CMS unsigned attributed // mandatedCertificateRef [0] CertRefReq // DEFAULT signerOnly, // (1) // -- Mandated Certificate Reference // mandatedCertificateInfo [1] CertInfoReq // DEFAULT none, // -- Mandated Certificate Info // signPolExtensions [2] SignPolExtensions // OPTIONAL} // CMSAttrs ::= SEQUENCE OF OBJECT // IDENTIFIER ASN1Encodable mandatedSignedAttr = getAt(signerRulesDERSeq, 0); if (mandatedSignedAttr instanceof DERSequence) { DERSequence mandatedSignedAttrDERSeq = (DERSequence) mandatedSignedAttr; for (int i = 0; i < mandatedSignedAttrDERSeq.size(); i++) { ASN1Encodable at = getAt(mandatedSignedAttrDERSeq, i); ret.addMandatedSignedAttr(at.toString()); } } ASN1Encodable mandatedUnsignedAttr = getAt(signerRulesDERSeq, 1); if (mandatedUnsignedAttr instanceof DERSequence) { DERSequence mandatedUnsignedAttrDERSeq = (DERSequence) mandatedUnsignedAttr; } ASN1Encodable mandatedCertificateRef = getAt(signerRulesDERSeq, 2); if (mandatedCertificateRef instanceof DERTaggedObject) { DERTaggedObject mandatedCertificateRefDERSeq = (DERTaggedObject) mandatedCertificateRef; // CertRefReq ::= ENUMERATED { // signerOnly (1), // -- Only reference to signer cert // mandated // fullpath (2) // // -- References for full cert path up // to a trust point required // } ASN1Encodable mandatedCertificateRefTmp = mandatedCertificateRefDERSeq .getObject(); ASN1Enumerated mandatedCertificateRefEnum = (ASN1Enumerated) mandatedCertificateRefTmp; BigInteger valEnum = mandatedCertificateRefEnum.getValue(); int mandatedCertificateRefInt = valEnum.intValue(); ret.setMandatedCertificateRef(mandatedCertificateRefInt); int x = 0; } } ASN1Encodable verifierRules = getAt(signerAndVeriferRulesDERSeq, 1); if (verifierRules instanceof DERSequence) { DERSequence verifierRulesDERSeq = (DERSequence) verifierRules; } } } ASN1Encodable signingCertTrustCondition = getAt(commonRulesDLS, 1); if (signingCertTrustCondition instanceof DERTaggedObject) { DERTaggedObject signingCertTrustConditionDTO = (DERTaggedObject) signingCertTrustCondition; ASN1Encodable signingCertTrustConditionTmp = signingCertTrustConditionDTO.getObject(); if (signingCertTrustConditionTmp instanceof DERSequence) { DERSequence signingCertTrustConditionDERSeq = (DERSequence) signingCertTrustConditionTmp; } } ASN1Encodable timeStampTrustCondition = getAt(commonRulesDLS, 2); if (timeStampTrustCondition instanceof DERTaggedObject) { DERTaggedObject timeStampTrustConditionDTO = (DERTaggedObject) timeStampTrustCondition; ASN1Encodable timeStampTrustConditionTmp = timeStampTrustConditionDTO.getObject(); if (timeStampTrustConditionTmp instanceof DERSequence) { DERSequence timeStampTrustConditionDERSeq = (DERSequence) timeStampTrustConditionTmp; } } ASN1Encodable attributeTrustCondition = getAt(commonRulesDLS, 3); if (attributeTrustCondition instanceof DERTaggedObject) { DERTaggedObject attributeTrustConditionDTO = (DERTaggedObject) attributeTrustCondition; ASN1Encodable attributeTrustConditionTmp = attributeTrustConditionDTO.getObject(); if (attributeTrustConditionTmp instanceof DERSequence) { DERSequence attributeTrustConditionDERSeq = (DERSequence) attributeTrustConditionTmp; } } // ***************************** ASN1Encodable algorithmConstraintSet = getAt(commonRulesDLS, 4); ASN1Encodable signPolExtensions = getAt(commonRulesDLS, 5); } // commitmentRules CommitmentRules, ASN1Encodable commitmentRules = getAt(signatureValidationPolicyDLS, 2); if (commitmentRules instanceof DLSequence) { } // signPolExtensions SignPolExtensions // OPTIONAL ASN1Encodable signPolExtensions = getAt(signatureValidationPolicyDLS, 3); if (signPolExtensions instanceof DLSequence) { } // } } } } // CertInfoReq ::= ENUMERATED { // none (0) , // -- No mandatory requirements // signerOnly (1) , // -- Only reference to signer cert mandated // fullpath (2) // -- References for full cert path up to a // -- trust point mandated // } is.close(); return ret; }
From source file:bluecrystal.bcdeps.helper.DerEncoder.java
License:Open Source License
public static Map<String, String> createSanMap(byte[] extensionValue, int index) { Map<String, String> ret = new HashMap<String, String>(); try {/*from w ww. j a va 2s .com*/ if (extensionValue == null) { return null; } ASN1InputStream oAsnInStream = new ASN1InputStream(new ByteArrayInputStream(extensionValue)); ASN1Primitive derObjCP = oAsnInStream.readObject(); DLSequence derSeq = (DLSequence) derObjCP; // int seqLen = derSeq.size(); ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) derSeq.getObjectAt(0); String sanOid = oid.getId(); DERTaggedObject derTO = (DERTaggedObject) derSeq.getObjectAt(1); // int tag = derTO.getTagNo(); ASN1Primitive derObjA = derTO.getObject(); DERTaggedObject derTO2 = (DERTaggedObject) derObjA; // int tag2 = derTO2.getTagNo(); ASN1Primitive derObjB = derTO2.getObject(); String contentStr = ""; if (derObjB instanceof DEROctetString) { DEROctetString derOCStr = (DEROctetString) derObjB; contentStr = new String(derOCStr.getOctets(), "UTF8"); } else if (derObjB instanceof DERPrintableString) { DERPrintableString derOCStr = (DERPrintableString) derObjB; contentStr = new String(derOCStr.getOctets(), "UTF8"); } else { System.err.println("FORMAT OF SAN: UNRECOGNIZED -> " + derObjB.getClass().getCanonicalName()); } LOG.debug(sanOid + " -> " + contentStr); String value = ""; String name = ""; if (sanOid.compareTo(PF_PF_ID) == 0 || sanOid.compareTo(PJ_PF_ID) == 0) { value = contentStr.substring(BIRTH_DATE_INI, BIRTH_DATE_LEN); if (isValidValue(value)) { name = String.format(CertConstants.BIRTH_DATE_D, index); ret.put(name, value); } value = contentStr.substring(CPF_INI, CPF_LEN); if (isValidValue(value)) { name = String.format(CertConstants.CPF_D, index); ret.put(name, value); } value = contentStr.substring(PIS_INI, PIS_LEN); if (isValidValue(value)) { name = String.format(CertConstants.PIS_D, index); ret.put(name, value); } value = contentStr.substring(RG_INI, RG_LEN); if (isValidValue(value)) { name = String.format(CertConstants.RG_D, index); ret.put(name, value); } int rgOrgUfLen = RG_ORG_UF_LEN > contentStr.length() ? contentStr.length() : RG_ORG_UF_LEN; if (rgOrgUfLen > RG_ORG_UF_INI) { value = contentStr.substring(RG_ORG_UF_INI, rgOrgUfLen); String rgOrg = value.substring(0, value.length() - 2); String rgUf = value.substring(value.length() - 2, value.length()); if (isValidValue(rgOrg)) { name = String.format(CertConstants.RG_ORG_D, index); ret.put(name, rgOrg); } if (isValidValue(rgUf)) { name = String.format(CertConstants.RG_UF_D, index); ret.put(name, rgUf); } } } else if (sanOid.compareTo(PERSON_NAME_OID) == 0) { value = contentStr; if (isValidValue(value)) { name = String.format(CertConstants.PERSON_NAME_D, index); ret.put(name, value); } } else if (sanOid.compareTo(CNPJ_OID) == 0) { name = String.format(CERT_TYPE_FMT, index); ret.put(name, ICP_BRASIL_PJ); value = contentStr; if (isValidValue(value)) { name = String.format(CertConstants.CNPJ_D, index); ret.put(name, value); } } else if (sanOid.compareTo(ELEITOR_OID) == 0) { name = String.format(CERT_TYPE_FMT, index); ret.put(name, ICP_BRASIL_PF); value = contentStr.substring(ELEITOR_INI, ELEITOR_LEN); if (isValidValue(value)) { name = String.format(CertConstants.ELEITOR_D, index); ret.put(name, value); } int zonaLen = ZONA_LEN > contentStr.length() ? contentStr.length() : ZONA_LEN; if (zonaLen > ZONA_LEN) { value = contentStr.substring(ZONA_INI, zonaLen); if (isValidValue(value)) { name = String.format(CertConstants.ZONA_D, index); ret.put(name, value); } } int secaoLen = SECAO_LEN > contentStr.length() ? contentStr.length() : SECAO_LEN; if (secaoLen > SECAO_LEN) { value = contentStr.substring(SECAO_INI, SECAO_LEN); if (isValidValue(value)) { name = String.format(CertConstants.SECAO_D, index); ret.put(name, value); } } } else if (sanOid.compareTo(PF_PF_INSS_OID) == 0 || sanOid.compareTo(PJ_PF_INSS_OID) == 0) { value = contentStr.substring(INSS_INI, INSS_LEN); if (isValidValue(value)) { name = String.format(CertConstants.INSS_D, index); ret.put(name, value); } } else if (sanOid.compareTo(OAB_OID) == 0) { value = contentStr.substring(OAB_REG_INI, OAB_REG_LEN); if (isValidValue(value)) { name = String.format(CertConstants.OAB_REG_D, index); ret.put(name, value); } value = contentStr.substring(OAB_UF_INI, OAB_UF_LEN); if (isValidValue(value)) { name = String.format(CertConstants.OAB_UF_D, index); ret.put(name, value); } } else if (sanOid.startsWith(PROFESSIONAL_OID)) { value = contentStr; if (isValidValue(value)) { name = String.format(CertConstants.PROFESSIONAL_D, index); ret.put(name, value); } } else if (sanOid.startsWith(UPN)) { value = contentStr; if (isValidValue(value)) { name = String.format(CertConstants.UPN_D, index); ret.put(name, value); } } else { System.err.println("SAN:OTHER NAME NOT RECOGNIZED"); } } catch (Exception e) { e.printStackTrace(); } return ret; }