List of usage examples for org.bouncycastle.asn1.util ASN1Dump dumpAsString
public static String dumpAsString(Object obj, boolean verbose)
From source file:de.fraunhofer.fokus.openeid.ca.ChipAuthenticationPublicKeyInfo.java
License:Open Source License
public ChipAuthenticationPublicKeyInfo(DERSequence chipInfoSequence) { DERObjectIdentifier derOid = (DERObjectIdentifier) chipInfoSequence.getObjectAt(0); oid = derOid.getId();/*w ww. j a v a2 s .c o m*/ DERSequence publicKey = (DERSequence) chipInfoSequence.getObjectAt(1); logger.info(ASN1Dump.dumpAsString(publicKey, true)); algorithmIdentifier = (DERSequence) publicKey.getObjectAt(0); DERBitString encodedKey = (DERBitString) publicKey.getObjectAt(1); encodedPublicKey = encodedKey.getBytes(); if (chipInfoSequence.size() > 2) { DERInteger derKeyId = (DERInteger) chipInfoSequence.getObjectAt(2); keyId = derKeyId.getValue().intValue(); } }
From source file:de.fraunhofer.fokus.openeid.ca.SignedData.java
License:Open Source License
@Override public String toString() { return ASN1Dump.dumpAsString(signedData, true); }
From source file:de.fraunhofer.fokus.openeid.eac.EfFile.java
License:Open Source License
public String dump() { // return DERDump.dumpAsString(file); return ASN1Dump.dumpAsString(file, true); }
From source file:de.fraunhofer.fokus.openeid.structure.SequenceData.java
License:Open Source License
@Override public String toString() { return ASN1Dump.dumpAsString(dataSequence, true); }
From source file:net.wstech2.me.httpsclient.CertificateValidatorUtils.java
License:Apache License
/** * /*from w ww . ja v a2s. c o m*/ * Prints common certificate informations like signature, signature * algorithm, subject and issuer details, etc. * * @param cert * The X509CertificateStructure containing the information that * will be printed. * */ public static void printCertificateDetails(org.bouncycastle.asn1.x509.Certificate cert) { HttpsConnectionUtils.logDebug( "BEGIN CERTIFICATE DUMP FOR:[[" + CertificateValidatorUtils.extractCommonName(cert, true) + "]]"); HttpsConnectionUtils.logDebug("Certificate Signature:[[" + cert.getSignature().toString() + "]]"); HttpsConnectionUtils.logDebug( "Certificate Signature Algorithm OID:[[" + cert.getSignatureAlgorithm().getAlgorithm() + "]]"); HttpsConnectionUtils.logDebug("Certificate Subject Info:[[" + cert.getSubject().toString() + "]]"); HttpsConnectionUtils .logDebug("Certificate Subject common name (CN):[[" + extractCommonName(cert, false) + "]]"); HttpsConnectionUtils .logDebug("Certificate Subject short common name (CN):[[" + extractCommonName(cert, true) + "]]"); HttpsConnectionUtils.logDebug("Certificate Issuer Info:[[" + cert.getIssuer() + "]]"); HttpsConnectionUtils.logDebug("Certificate Start Date:[[" + cert.getStartDate().getTime() + "]]"); HttpsConnectionUtils.logDebug("Certificate End Date:[[" + cert.getEndDate().getTime() + "]]"); HttpsConnectionUtils.logDebug("Certificate ASN.1 Dump:[[" + ASN1Dump.dumpAsString(cert, true) + "]]"); HttpsConnectionUtils.logDebug( "END CERTIFICATE DUMP FOR:[[" + CertificateValidatorUtils.extractCommonName(cert, true) + "]]"); }
From source file:net.wstech2.me.httpsclient.CertificateValidatorUtils.java
License:Apache License
/** * /*from w w w . ja v a2 s . c o m*/ * Inspected and display various informations from the Certificate passed as * parameter. Keys are presented in HEX values and ASN1 structures dumped * using ASN1Dump.dumpAsString. * * This method is intended for debug purposes only. * * * @param cert * The X509CertificateStructure to be inspected. * */ public static void dumpCertificateInfo(org.bouncycastle.asn1.x509.Certificate cert) { boolean valid = false; TBSCertificate tbs = cert.getTBSCertificate(); RSAEngine engine = new RSAEngine(); SHA1Digest digest = new SHA1Digest(); GenericSigner signer = new GenericSigner((engine), digest); RSAPublicKey signingKey; try { signingKey = RSAPublicKey.getInstance(cert.getSubjectPublicKeyInfo().parsePublicKey()); HttpsConnectionUtils.logDebug("Public Key:[[" + cert.getSubjectPublicKeyInfo().parsePublicKey() + "]]"); RSAKeyParameters keySpec = new RSAKeyParameters(false, signingKey.getModulus(), signingKey.getPublicExponent()); signer.init(false, keySpec); HttpsConnectionUtils.logDebug("TBS DER object:[[" + tbs.getEncoded("DER") + "]]"); signer.update(tbs.getEncoded(), 0, tbs.getEncoded().length); valid = signer.verifySignature(cert.getSignature().getBytes()); HttpsConnectionUtils.logDebug("signer.verifySignature:[[" + valid + "]]"); SHA1Digest d2 = new SHA1Digest(); d2.update(tbs.getEncoded("DER"), 0, tbs.getEncoded("DER").length); byte[] hash = new byte[d2.getDigestSize()]; d2.doFinal(hash, 0); HttpsConnectionUtils.logDebug("tbs.getDEREncoded() HASH:[[" + new String(Hex.encode(hash)) + "]]"); DEROctetString asn1Hash = new DEROctetString(hash); HttpsConnectionUtils.logDebug( "ASN1 DEROctetString hash:[[" + new String(Hex.encode(asn1Hash.getEncoded("DER"))) + "]]"); d2 = new SHA1Digest(); d2.update(cert.getEncoded(), 0, cert.getEncoded().length); hash = new byte[d2.getDigestSize()]; d2.doFinal(hash, 0); HttpsConnectionUtils.logDebug("cert.getEncoded() HASH:[[" + new String(Hex.encode(hash)) + "]]"); byte[] signature = cert.getSignature().getBytes(); HttpsConnectionUtils .logDebug("cert.getSignature().getBytes():[[" + new String(Hex.encode(signature)) + "]]"); PKCS1Encoding engine2 = new PKCS1Encoding(new RSAEngine()); engine2.init(false, keySpec); byte[] decryptedHash = engine2.processBlock(signature, 0, signature.length); HttpsConnectionUtils.logDebug("decryptedHash:[[" + new String(Hex.encode(decryptedHash)) + "]]"); ASN1Object o = ASN1Primitive.fromByteArray(decryptedHash); HttpsConnectionUtils.logDebug( "decryptedHash.getDEREncoded():[[" + new String(Hex.encode(o.getEncoded("DER"))) + "]]"); HttpsConnectionUtils.logDebug( "ASN1Dump.dumpAsString(decryptedHash,true):[[" + ASN1Dump.dumpAsString(o, true) + "]]"); HttpsConnectionUtils.logDebug("engine.getInputBlockSize():[[" + engine2.getInputBlockSize() + "]]"); HttpsConnectionUtils.logDebug("engine.getOutputBlockSize():[[" + engine2.getOutputBlockSize() + "]]"); ASN1Sequence asn1SignSeq = (ASN1Sequence) ASN1Sequence.fromByteArray(decryptedHash); HttpsConnectionUtils .logDebug("Signature ASN1 Sequence:[[" + ASN1Dump.dumpAsString(asn1SignSeq, true) + "]]"); AlgorithmIdentifier algorithm = AlgorithmIdentifier.getInstance(asn1SignSeq.getObjectAt(0)); HttpsConnectionUtils.logDebug("AlgorithmIdentifier:[[" + ASN1Dump.dumpAsString(algorithm, true) + "]]"); DEROctetString signedHash = (DEROctetString) DEROctetString.getInstance(asn1SignSeq.getObjectAt(1)); HttpsConnectionUtils.logDebug("signedHash:[[" + ASN1Dump.dumpAsString(signedHash, true) + "]]"); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.cesecore.certificates.certificate.certextensions.QcStatementTest.java
License:Open Source License
@Test public void testQcStatement() throws CertificateExtensionException, IOException { CertificateProfile prof = new CertificateProfile(CertificateProfileConstants.CERTPROFILE_FIXED_ENDUSER); prof.setUseQCStatement(true);/* w w w. j a v a 2 s .c o m*/ prof.setUseQCEtsiQCCompliance(true); prof.setUseQCEtsiSignatureDevice(true); prof.setQCEtsiType("0.4.0.1862.1.6.1"); prof.setQCEtsiPds(Arrays.asList(new PKIDisclosureStatement("http://qcs.localhost/QcPDS", "en"))); QcStatement statement = new QcStatement(); byte[] value = statement.getValueEncoded(null, null, prof, null, null, null); @SuppressWarnings("resource") final String dump = ASN1Dump.dumpAsString(new ASN1InputStream(value).readObject(), true); log.info(dump); // Hex dump can be used in Custom Certificate Extensions log.info(new String(Hex.encode(value))); // Dump included IDs final ASN1Sequence seq = (ASN1Sequence) ASN1Sequence.fromByteArray(value); // This is just a loop to get all the statement IDs in the QcStatements extension, so we can view them and count them ArrayList<String> oids = new ArrayList<>(); for (int i = 0; i < seq.size(); i++) { final QCStatement qc = QCStatement.getInstance(seq.getObjectAt(i)); final ASN1ObjectIdentifier oid = qc.getStatementId(); if (oid != null) { oids.add(oid.getId()); } else { fail("QC statements have empty statement"); } } log.info(oids); // Check that all OIDs we set exist assertEquals("Not all QC statement Ids were included", 4, oids.size()); assertTrue(oids.contains(ETSIQCObjectIdentifiers.id_etsi_qcs_QcCompliance.getId())); assertTrue(oids.contains(ETSIQCObjectIdentifiers.id_etsi_qcs_QcSSCD.getId())); assertTrue(oids.contains("0.4.0.1862.1.6")); // ETSIQCObjectIdentifiers.id_etsi_qcs_QcType assertTrue(oids.contains("0.4.0.1862.1.5")); // ETSIQCObjectIdentifiers.id_etsi_qcs_QcPds // Check the values we set assertEquals("0.4.0.1862.1.6.1", QCStatementExtension.getStatementStringValue(seq, "0.4.0.1862.1.6", 0)); assertEquals("[http://qcs.localhost/QcPDS, en]", QCStatementExtension.getStatementStringValue(seq, "0.4.0.1862.1.5", 0)); }
From source file:org.cesecore.certificates.certificate.certextensions.standard.DocumentTypeList.java
License:Open Source License
@Override public ASN1Encodable getValue(final EndEntityInformation subject, final CA ca, final CertificateProfile certProfile, final PublicKey userPublicKey, final PublicKey caPublicKey, CertificateValidity val) { ArrayList<String> docTypes = certProfile.getDocumentTypeList(); if (docTypes.size() == 0) { if (log.isDebugEnabled()) { log.debug("No DocumentTypeList to make a certificate extension"); }//from w w w. j a v a2 s . c o m return null; } ASN1EncodableVector vec = new ASN1EncodableVector(); // version vec.add(new ASN1Integer(0)); // Add SET OF DocumentType Iterator<String> itr = docTypes.iterator(); while (itr.hasNext()) { String type = itr.next(); vec.add(new DERSet(new ASN1Encodable[] { new DERPrintableString(type) })); } ASN1Object gn = new DERSequence(vec); if (log.isDebugEnabled()) { log.debug("Constructed DocumentTypeList:"); log.debug(ASN1Dump.dumpAsString(gn, true)); } return gn; }
From source file:org.jboss.as.test.integration.security.common.negotiation.KerberosTestUtils.java
License:Open Source License
/** * Dumps ASN.1 object as String from given byte array. * * @param data/*w w w. ja va 2 s. co m*/ */ public static String dumpAsn1Obj(byte[] data) throws IOException { if (data == null) return null; try (ASN1InputStream bIn = new ASN1InputStream(new ByteArrayInputStream(data))) { return ASN1Dump.dumpAsString(bIn.readObject(), true); } catch (Exception e) { LOGGER.debug("ASN1Dump failed", e); return "[Unable to dump ASN.1: " + Base64.getEncoder().encodeToString(data) + " ]"; } }
From source file:org.signserver.module.mrtdsodsigner.MRTDSODSignerUnitTest.java
License:Open Source License
public void test04LdsConfigVersion17_ok() throws Exception { // DG1, DG2 and default values Map<Integer, byte[]> dataGroups1 = new LinkedHashMap<Integer, byte[]>(); dataGroups1.put(1, digestHelper("Dummy Value 1".getBytes(), "SHA256")); dataGroups1.put(2, digestHelper("Dummy Value 2".getBytes(), "SHA256")); final SODFile sod = signHelper(WORKER1, 12, dataGroups1, false, "SHA256", "SHA256withRSA"); // ASN.1 Dump SODFile ASN1InputStream in = new ASN1InputStream(new ByteArrayInputStream(sod.getEncoded())); ASN1Object object = in.readObject(); LOG.info("Object: " + ASN1Dump.dumpAsString(object, true)); // // ANS.1 Dump LDSSecurityObject // in = new ASN1InputStream(new ByteArrayInputStream(sod.getSecurityObject())); // object = in.readObject(); // LOG.info("LDSSecurityObject: " + ASN1Dump.dumpAsString(object, true)); assertNull("LDS version", sod.getLdsVersion()); assertNull("Unicode version", sod.getUnicodeVersion()); }