List of usage examples for java.security.cert Certificate getType
public final String getType()
From source file:org.ejbca.ui.web.RequestHelper.java
public static String getFileNameFromCertNoEnding(Certificate cacert, String defaultname) throws NoSuchFieldException { String dnpart = null;/* w ww .j a va 2s .co m*/ if (StringUtils.equals(cacert.getType(), "CVC")) { CardVerifiableCertificate cvccert = (CardVerifiableCertificate) cacert; String car = "car"; CAReferenceField carf = cvccert.getCVCertificate().getCertificateBody().getAuthorityReference(); if (carf != null) { car = carf.getConcatenated(); } String chr = "chr"; HolderReferenceField chrf = cvccert.getCVCertificate().getCertificateBody().getHolderReference(); if (chrf != null) { chr = chrf.getConcatenated(); } dnpart = car + "_" + chr; } else { String dn = CertTools.getSubjectDN(cacert); dnpart = CertTools.getPartFromDN(dn, "CN"); if (dnpart == null) { dnpart = CertTools.getPartFromDN(dn, "SN"); } if (dnpart == null) { dnpart = CertTools.getPartFromDN(dn, "O"); } } if (dnpart == null) { dnpart = defaultname; } if (log.isDebugEnabled()) { log.debug("dnpart: " + dnpart); } // Strip whitespace though String filename = dnpart.replaceAll("\\W", ""); return filename; }
From source file:org.cesecore.certificates.util.AlgorithmTools.java
/** * Simple methods that returns the signature algorithm value from the certificate. Not usable for setting signature algorithms names in EJBCA, * only for human presentation.//from w w w . j a va 2 s . com * * @return Signature algorithm name from the certificate as a human readable string, for example SHA1WithRSA. */ public static String getCertSignatureAlgorithmNameAsString(Certificate cert) { String certSignatureAlgorithm = null; if (cert instanceof X509Certificate) { X509Certificate x509cert = (X509Certificate) cert; certSignatureAlgorithm = x509cert.getSigAlgName(); if (log.isDebugEnabled()) { log.debug("certSignatureAlgorithm is: " + certSignatureAlgorithm); } } else if (StringUtils.equals(cert.getType(), "CVC")) { CardVerifiableCertificate cvccert = (CardVerifiableCertificate) cert; CVCPublicKey cvcpk; try { cvcpk = cvccert.getCVCertificate().getCertificateBody().getPublicKey(); OIDField oid = cvcpk.getObjectIdentifier(); certSignatureAlgorithm = AlgorithmUtil.getAlgorithmName(oid); } catch (NoSuchFieldException e) { log.error("NoSuchFieldException: ", e); } } // Try to make it easier to display some signature algorithms that cert.getSigAlgName() does not have a good string for. if (certSignatureAlgorithm.equalsIgnoreCase("1.2.840.113549.1.1.10")) { // Figure out if it is SHA1 or SHA256 // If we got this value we should have a x509 cert if (cert instanceof X509Certificate) { X509Certificate x509cert = (X509Certificate) cert; certSignatureAlgorithm = x509cert.getSigAlgName(); byte[] params = x509cert.getSigAlgParams(); if ((params != null) && (params.length == 2)) { certSignatureAlgorithm = AlgorithmConstants.SIGALG_SHA1_WITH_RSA_AND_MGF1; } else { certSignatureAlgorithm = AlgorithmConstants.SIGALG_SHA256_WITH_RSA_AND_MGF1; } } } // SHA256WithECDSA does not work to be translated in JDK5. if (certSignatureAlgorithm.equalsIgnoreCase("1.2.840.10045.4.3.2")) { certSignatureAlgorithm = AlgorithmConstants.SIGALG_SHA256_WITH_ECDSA; } // GOST3410 if (isGost3410Enabled() && certSignatureAlgorithm.equalsIgnoreCase(CesecoreConfiguration.getOidGost3410())) { certSignatureAlgorithm = AlgorithmConstants.SIGALG_GOST3411_WITH_ECGOST3410; } // DSTU4145 if (isDstu4145Enabled() && certSignatureAlgorithm.startsWith(CesecoreConfiguration.getOidDstu4145() + ".")) { certSignatureAlgorithm = AlgorithmConstants.SIGALG_GOST3411_WITH_DSTU4145; } return certSignatureAlgorithm; }
From source file:com.ct855.util.HttpsClientUtil.java
private void print_https_cert(HttpsURLConnection con) { if (con != null) { try {//from www . j av a 2s. c o m System.out.println("Response Code : " + con.getResponseCode()); System.out.println("Cipher Suite : " + con.getCipherSuite()); System.out.println("\n"); Certificate[] certs = con.getServerCertificates(); for (Certificate cert : certs) { System.out.println("Cert Type : " + cert.getType()); System.out.println("Cert Hash Code : " + cert.hashCode()); System.out.println("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm()); System.out.println("Cert Public Key Format : " + cert.getPublicKey().getFormat()); System.out.println("\n"); } } catch (SSLPeerUnverifiedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.lockss.util.TestKeyStoreUtil.java
void assertPubKs(File file, String pass, List<String> hosts) throws Exception { KeyStore ks = loadKeyStore("jceks", file, pass); List aliases = ListUtil.fromIterator(new EnumerationIterator(ks.aliases())); assertEquals(hosts.size(), aliases.size()); for (String host : hosts) { String alias = host + ".crt"; Certificate cert = ks.getCertificate(alias); assertNotNull(cert);/*from ww w.j a v a 2 s .c o m*/ assertEquals("X.509", cert.getType()); } }
From source file:org.lockss.util.TestKeyStoreUtil.java
void assertPrivateKs(File file, String pass, String alias) throws Exception { KeyStore ks = loadKeyStore("jceks", file, alias); List aliases = ListUtil.fromIterator(new EnumerationIterator(ks.aliases())); assertEquals(2, aliases.size());/*from w w w .j av a2s .co m*/ Certificate cert = ks.getCertificate(alias + ".crt"); assertNotNull(cert); assertEquals("X.509", cert.getType()); assertTrue(ks.isKeyEntry(alias + ".key")); assertTrue(ks.isCertificateEntry(alias + ".crt")); Key key = ks.getKey(alias + ".key", pass.toCharArray()); assertNotNull(key); assertEquals("RSA", key.getAlgorithm()); }
From source file:com.github.technosf.posterer.models.impl.KeyStoreBeanTest.java
private void test509Cert(String alias, int serial) { Certificate cert = classUnderTest.getCertificate(alias); assertNotNull(cert);/* w w w. j a v a 2s.c o m*/ assertEquals(cert.getType(), "X.509"); X509Certificate x509 = (X509Certificate) cert; assertEquals(x509.getSerialNumber().intValue(), serial); }
From source file:org.wso2.carbon.certificate.mgt.core.impl.CertificateManagementServiceImplTests.java
@Test(description = "This test case tests retrieval of CA Certificate from the keystore") public void testGetCACertificate() throws KeystoreException { CertificateManagementServiceImpl instance = CertificateManagementServiceImpl.getInstance(); Certificate caCertificate = instance.getCACertificate(); Assert.assertNotNull(caCertificate); Assert.assertEquals(caCertificate.getType(), CertificateManagementConstants.X_509); log.info("GetCACertificate Test Successful"); }
From source file:org.wso2.carbon.certificate.mgt.core.impl.CertificateManagementServiceImplTests.java
@Test(description = "This test case tests retrieval of RA Certificate from the keystore") public void testGetRACertificate() throws KeystoreException { Certificate raCertificate = managementService.getRACertificate(); Assert.assertNotNull(raCertificate); Assert.assertEquals(raCertificate.getType(), CertificateManagementConstants.X_509); log.info("GetRACertificate Test Successful"); }
From source file:mitm.common.hibernate.CertificateArrayUserType.java
private Certificate cloneCertificate(Certificate original) throws CertificateException, NoSuchProviderException, SecurityFactoryFactoryException { byte[] encodedCert = original.getEncoded(); String certificateType = original.getType(); CertificateFactory factory = SecurityFactoryFactory.getSecurityFactory() .createCertificateFactory(certificateType); Certificate copy = factory.generateCertificate(new ByteArrayInputStream(encodedCert)); return copy;/* w w w . ja v a 2 s .co m*/ }
From source file:org.wso2.carbon.certificate.mgt.core.impl.CertificateManagementServiceImplTests.java
@Test(description = "This test case tests retrieval of a Certificate from the keystore from the Alias") public void testGetCertificateByAlias() throws KeystoreException, DeviceManagementException { X509Certificate x509Certificate = null; //generate and save a certificate x509Certificate = managementService.generateX509Certificate(); //initialize DeviceConfigurationManager DeviceConfigurationManager.getInstance().initConfig(); Certificate certificateByAlias = managementService .getCertificateByAlias(x509Certificate.getSerialNumber().toString()); Assert.assertNotNull(certificateByAlias); Assert.assertEquals(certificateByAlias.getType(), CertificateManagementConstants.X_509); log.info("GetCertificateByAlias Test Successful"); }