List of usage examples for java.security.cert CertificateException getMessage
public String getMessage()
From source file:org.wso2.carbon.identity.application.authenticator.passive.sts.manager.STSAgentKeyStoreCredential.java
private static void readX509Credentials(ExternalIdPConfig externalIdPConfig) throws PassiveSTSException { externalIdPConfig.getIdPName();//from w w w . j av a2 s. c om IdentityProvider identityProvider = externalIdPConfig.getIdentityProvider(); X509Certificate x509Certificate = null; try { x509Certificate = (X509Certificate) IdentityApplicationManagementUtil .decodeCertificate(identityProvider.getCertificate()); entityCertificate = x509Certificate; publicKey = x509Certificate.getPublicKey(); } catch (CertificateException e) { log.error(e.getMessage(), e); throw new PassiveSTSException("Error occurred while decoding public certificate of Identity Provider " + identityProvider.getIdentityProviderName()); } }
From source file:be.fedict.trust.BelgianTrustValidatorFactory.java
private static X509Certificate loadCertificate(String resourceName) { LOG.debug("loading certificate: " + resourceName); Thread currentThread = Thread.currentThread(); ClassLoader classLoader = currentThread.getContextClassLoader(); InputStream certificateInputStream = classLoader.getResourceAsStream(resourceName); if (null == certificateInputStream) { throw new IllegalArgumentException("resource not found: " + resourceName); }//from w w w . j av a 2 s . c o m try { CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate certificate = (X509Certificate) certificateFactory .generateCertificate(certificateInputStream); return certificate; } catch (CertificateException e) { throw new RuntimeException("X509 error: " + e.getMessage(), e); } }
From source file:cn.mrdear.pay.util.RSAUtils.java
/** * ??/*from w ww.ja v a 2 s . c o m*/ * * @param type * * @param inputStream * ? * @return ? */ public static Certificate getCertificate(String type, InputStream inputStream) { Assert.isNotEmpty(type); Assert.notNull(inputStream); try { CertificateFactory certificateFactory = CertificateFactory.getInstance(type, PROVIDER); return certificateFactory.generateCertificate(inputStream); } catch (CertificateException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:be.fedict.eid.applet.service.signer.time.TSPTimeStampService.java
private static X509Certificate loadCertificate(String resourceName) { LOG.debug("loading certificate: " + resourceName); Thread currentThread = Thread.currentThread(); ClassLoader classLoader = currentThread.getContextClassLoader(); InputStream certificateInputStream = classLoader.getResourceAsStream(resourceName); if (null == certificateInputStream) { throw new IllegalArgumentException("resource not found: " + resourceName); }// w ww. j ava2 s . c om try { CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); return (X509Certificate) certificateFactory.generateCertificate(certificateInputStream); } catch (CertificateException e) { throw new RuntimeException("X509 error: " + e.getMessage(), e); } }
From source file:com.vangent.hieos.services.sts.util.STSUtil.java
/** * * @param base64Text/* w w w.ja v a2 s .co m*/ * @return * @throws STSException */ public static X509Certificate getCertificate(String base64Text) throws STSException { try { byte[] base64Bytes = base64Text.getBytes(); byte[] decodedBytes = Base64.decodeBase64(base64Bytes); ByteArrayInputStream bs = new ByteArrayInputStream(decodedBytes); CertificateFactory cf; cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(bs); return cert; } catch (CertificateException ex) { throw new STSException("Unable to create X509Certificate: " + ex.getMessage()); } }
From source file:org.exoplatform.services.videocall.AuthService.java
protected static TrustManager[] getTrustManagers(InputStream trustStoreFile, String trustStorePassword) throws Exception { CertificateFactory certificateFactory = null; try {/*from ww w.j a v a 2 s .c o m*/ certificateFactory = CertificateFactory.getInstance("X.509"); } catch (CertificateException e) { if (LOG.isErrorEnabled()) { LOG.error("Could not initialize the certificate " + e.getMessage()); } } Certificate caCert = null; try { caCert = certificateFactory.generateCertificate(trustStoreFile); } catch (CertificateException e) { if (LOG.isErrorEnabled()) { LOG.error("Bad key or certificate in " + trustStoreFile, e.getMessage()); } } KeyStore trustStore = null; try { trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); } catch (KeyStoreException e) { if (LOG.isErrorEnabled()) { LOG.error("Java implementation cannot manipulate " + KeyStore.getDefaultType() + " keystores"); } } catch (NoSuchAlgorithmException e) { if (LOG.isErrorEnabled()) { LOG.error("Could not initialize truststore ", e); } } catch (CertificateException e) { if (LOG.isErrorEnabled()) { LOG.error("Could not initialize truststore ", e); } } catch (IOException e) { if (LOG.isErrorEnabled()) { LOG.error("Could not initialize truststore ", e); } } try { trustStore.setCertificateEntry("CA", caCert); } catch (KeyStoreException e) { if (LOG.isErrorEnabled()) { LOG.error(trustStoreFile + " cannot be used as a CA", e); } } TrustManagerFactory tmf = null; try { tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); tmf.init(trustStore); } catch (NoSuchAlgorithmException e) { if (LOG.isErrorEnabled()) { LOG.error("Java implementation cannot manipulate " + KeyStore.getDefaultType() + " trusts", e); } } catch (KeyStoreException e) { LOG.error("Java implementation cannot manipulate " + KeyStore.getDefaultType() + " trusts", e); } return tmf.getTrustManagers(); }
From source file:org.ejbca.core.protocol.ocsp.OCSPUtil.java
public static Hashtable getCertificatesFromDirectory(String certificateDir) throws IOException { // read all files from trustDir, expect that they are PEM formatted certificates CertTools.installBCProvider();//w w w . java 2 s .c o m File dir = new File(certificateDir); Hashtable trustedCerts = new Hashtable(); if (dir == null || dir.isDirectory() == false) { m_log.error(dir.getCanonicalPath() + " is not a directory."); throw new IllegalArgumentException(dir.getCanonicalPath() + " is not a directory."); } File files[] = dir.listFiles(); if (files == null || files.length == 0) { String errMsg = intres.getLocalizedMessage("ocsp.errornotrustfiles", dir.getCanonicalPath()); m_log.error(errMsg); } for (int i = 0; i < files.length; i++) { final String fileName = files[i].getCanonicalPath(); // Read the file, don't stop completely if one file has errors in it try { byte[] bytes = FileTools.getBytesFromPEM(FileTools.readFiletoBuffer(fileName), CertTools.BEGIN_CERTIFICATE, CertTools.END_CERTIFICATE); X509Certificate cert = (X509Certificate) CertTools.getCertfromByteArray(bytes); String key = cert.getIssuerDN() + ";" + cert.getSerialNumber().toString(16); trustedCerts.put(key, cert); } catch (CertificateException e) { String errMsg = intres.getLocalizedMessage("ocsp.errorreadingfile", fileName, "trustDir", e.getMessage()); m_log.error(errMsg, e); } catch (IOException e) { String errMsg = intres.getLocalizedMessage("ocsp.errorreadingfile", fileName, "trustDir", e.getMessage()); m_log.error(errMsg, e); } } return trustedCerts; }
From source file:be.fedict.eid.tsl.BelgianTrustServiceListFactory.java
private static X509Certificate loadCertificateFromResource(String resourceName) { Thread currentThread = Thread.currentThread(); ClassLoader classLoader = currentThread.getContextClassLoader(); InputStream certificateInputStream = classLoader.getResourceAsStream(resourceName); if (null == certificateInputStream) { throw new IllegalArgumentException("could not load certificate resource: " + resourceName); }/*from ww w .j av a2 s .c o m*/ try { CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); X509Certificate certificate = (X509Certificate) certificateFactory .generateCertificate(certificateInputStream); return certificate; } catch (CertificateException e) { throw new RuntimeException("certificate factory error: " + e.getMessage(), e); } }
From source file:be.fgov.kszbcss.rhq.websphere.connector.security.DelegatingTrustManager.java
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { try {// w ww . jav a2 s . co m TrustStoreManager.getInstance().getTrustManager().checkServerTrusted(chain, authType); log.info("Accepted server certificate for " + chain[0].getSubjectDN()); } catch (CertificateException ex) { log.error("Rejected server certificate for " + chain[0].getSubjectDN() + ": " + ex.getMessage()); throw ex; } }
From source file:org.codice.ddf.catalog.transformer.zip.TestZipValidator.java
@Before public void setUp() { zipValidator = new ZipValidator(); zipValidator/*from www . ja v a 2s . c om*/ .setSignaturePropertiesPath(TestZipValidator.class.getResource("/signature.properties").getPath()); zipValidator.init(); try { KeyStore trustStore = KeyStore.getInstance(System.getProperty("javax.net.ssl.keyStoreType")); InputStream trustFIS = TestZipValidator.class.getResourceAsStream("/serverKeystore.jks"); try { trustStore.load(trustFIS, "changeit".toCharArray()); } catch (CertificateException e) { fail(e.getMessage()); } finally { IOUtils.closeQuietly(trustFIS); } merlin = new Merlin( PropertiesLoader .loadProperties(TestZipValidator.class.getResource("/signature.properties").getPath()), ZipValidator.class.getClassLoader(), null); } catch (Exception e) { fail(e.getMessage()); } }