List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:es.mityc.javasign.certificate.ocsp.OwnSSLProtocolSocketFactory.java
private SSLContext createSSLContext() throws IOException { try {/*from ww w. j a va2s . c o m*/ KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; if (sslManager != null) { KeyManager km = sslManager.getKeyManager(); if (km != null) { keymanagers = new KeyManager[] { km }; } TrustManager tm = sslManager.getTrustManager(); if (tm != null) { trustmanagers = new TrustManager[] { tm }; } } SSLContext sslcontext = SSLContext.getInstance("SSL"); sslcontext.init(keymanagers, trustmanagers, null); return sslcontext; } catch (NoSuchAlgorithmException ex) { LOG.error(ex.getMessage(), ex); throw new IOException(ex.getMessage()); } catch (KeyManagementException ex) { LOG.error(ex.getMessage(), ex); throw new IOException(ex.getMessage()); } }
From source file:org.apache.streams.components.http.provider.SimpleHttpProvider.java
@Override public void prepare(Object configurationObject) { mapper = StreamsJacksonMapper.getInstance(); uriBuilder = new URIBuilder().setScheme(this.configuration.getProtocol()) .setHost(this.configuration.getHostname()).setPort(this.configuration.getPort().intValue()) .setPath(this.configuration.getResourcePath()); SSLContextBuilder builder = new SSLContextBuilder(); SSLConnectionSocketFactory sslsf = null; try {// w ww. ja v a2 s. c o m builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); sslsf = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); } catch (NoSuchAlgorithmException e) { LOGGER.warn(e.getMessage()); } catch (KeyManagementException e) { LOGGER.warn(e.getMessage()); } catch (KeyStoreException e) { LOGGER.warn(e.getMessage()); } httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); executor = Executors.newSingleThreadExecutor(); }
From source file:be.fedict.eid.applet.service.impl.handler.SignCertificatesDataMessageHandler.java
private void verifySignature(String signatureAlgoName, byte[] signatureData, PublicKey publicKey, HttpServletRequest request, byte[]... data) throws ServletException { Signature signature;//from w w w.j ava 2 s .c o m try { signature = Signature.getInstance(signatureAlgoName); } catch (NoSuchAlgorithmException e) { throw new ServletException("algo error: " + e.getMessage(), e); } try { signature.initVerify(publicKey); } catch (InvalidKeyException e) { throw new ServletException("key error: " + e.getMessage(), e); } try { for (byte[] dataItem : data) { signature.update(dataItem); } boolean result = signature.verify(signatureData); if (false == result) { AuditService auditService = this.auditServiceLocator.locateService(); if (null != auditService) { String remoteAddress = request.getRemoteAddr(); auditService.identityIntegrityError(remoteAddress); } throw new ServletException("signature incorrect"); } } catch (SignatureException e) { throw new ServletException("signature error: " + e.getMessage(), e); } }
From source file:cc.abstra.trantor.security.ssl.OwnSSLProtocolSocketFactory.java
private SSLContext createSSLContext() throws IOException { try {/* ww w. j av a 2 s .c om*/ KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; if (sslManager != null) { KeyManager km = sslManager.getKeyManager(); if (km != null) { keymanagers = new KeyManager[] { km }; } TrustManager tm = sslManager.getTrustManager(); if (tm != null) { trustmanagers = new TrustManager[] { tm }; } } SSLContext sslcontext = SSLContext.getInstance("SSL"); sslcontext.init(keymanagers, trustmanagers, null); sslcontext.getClientSessionContext().setSessionTimeout(SSL_TIME_OUT); return sslcontext; } catch (NoSuchAlgorithmException ex) { LOG.error(ex.getMessage(), ex); throw new IOException(ex.getMessage()); } catch (KeyManagementException ex) { LOG.error(ex.getMessage(), ex); throw new IOException(ex.getMessage()); } }
From source file:edu.vt.middleware.crypt.CryptProvider.java
/** * <p>This creates a <code>MessageDigest</code> using the supplied algorithm * name.</p>// ww w . ja va2 s. c o m * * @param algorithm <code>String</code> name * * @return <code>MessageDigest</code> * * @throws CryptException if the algorithm is not available from any * provider or the provider is not available in the environment */ public static MessageDigest getMessageDigest(final String algorithm) throws CryptException { final Log logger = LogFactory.getLog(CryptProvider.class); MessageDigest digest = null; for (int i = 0; i < providers.length; i++) { try { digest = MessageDigest.getInstance(algorithm, providers[i]); } catch (NoSuchAlgorithmException e) { if (logger.isDebugEnabled()) { logger.debug("Could not find algorithm " + algorithm + " in " + providers[i]); } } catch (NoSuchProviderException e) { if (logger.isDebugEnabled()) { logger.debug("Could not find provider " + providers[i]); } } finally { if (digest != null) { break; } } } if (digest == null) { try { digest = MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { if (logger.isDebugEnabled()) { logger.debug("Could not find algorithm " + algorithm); } throw new CryptException(e.getMessage()); } } return digest; }
From source file:edu.vt.middleware.crypt.CryptProvider.java
/** * <p>This finds a <code>Signature</code> using the known providers and the * supplied parameters.</p>/* w w w. j a v a2 s .c o m*/ * * @param digestAlgorithm <code>String</code> name * @param algorithm <code>String</code> name * @param padding <code>String</code> name * * @return <code>Signature</code> * * @throws CryptException if the algorithm is not available from any * provider or if the provider is not available in the environment */ public static Signature getSignature(final String digestAlgorithm, final String algorithm, final String padding) throws CryptException { final Log logger = LogFactory.getLog(CryptProvider.class); Signature sig = null; String transformation = null; if (digestAlgorithm != null && padding != null) { transformation = digestAlgorithm + "/" + algorithm + "/" + padding; } else if (digestAlgorithm != null) { transformation = digestAlgorithm + "/" + algorithm; } else { transformation = algorithm; } for (int i = 0; i < providers.length; i++) { try { sig = Signature.getInstance(transformation, providers[i]); } catch (NoSuchAlgorithmException e) { if (logger.isDebugEnabled()) { logger.debug("Could not find algorithm " + algorithm + " in " + providers[i]); } } catch (NoSuchProviderException e) { if (logger.isDebugEnabled()) { logger.debug("Could not find provider " + providers[i]); } } finally { if (sig != null) { break; } } } if (sig == null) { try { sig = Signature.getInstance(transformation); } catch (NoSuchAlgorithmException e) { if (logger.isDebugEnabled()) { logger.debug("Could not find algorithm " + algorithm); } throw new CryptException(e.getMessage()); } } return sig; }
From source file:org.apache.sling.cassandra.resource.provider.CassandraResourceProvider.java
private boolean deleteResource(ResourceResolver resourceResolver, String path) throws PersistenceException { try {//from ww w . j a v a 2 s .c o m String key = getrowID(path); if (key == null) { return false; } String _cf = CassandraResourceProviderUtil.getColumnFamilySector(path); createColumnFamily(_cf, this.getKeyspace(), new StringSerializer()); StringSerializer se = new StringSerializer(); CqlQuery<String, String, String> cqlQuery = new CqlQuery<String, String, String>(keyspace, se, se, se); String query = "delete FROM " + _cf + " where KEY = '" + key + "';"; cqlQuery.setQuery(query); QueryResult<CqlRows<String, String, String>> result = cqlQuery.execute(); } catch (NoSuchAlgorithmException e) { throw new PersistenceException(e.getMessage()); } catch (UnsupportedEncodingException e) { throw new PersistenceException(e.getMessage()); } return true; }
From source file:com.mgmtp.jfunk.web.ssl.JFunkSSLSocketFactory.java
private SSLContext createSSLContext() { try {/* ww w . j a v a 2s. c o m*/ KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; if (this.keyStoreUrl != null) { KeyStore keystore = createStore(this.keyStoreUrl, this.keyStorePassword, this.keyStoreType); if (log.isDebugEnabled()) { for (Enumeration<String> aliases = keystore.aliases(); aliases.hasMoreElements();) { String alias = aliases.nextElement(); Certificate[] certs = keystore.getCertificateChain(alias); if (certs != null) { log.debug("Certificate chain '{}':", alias); for (int i = 0; i < certs.length; ++i) { if (certs[i] instanceof X509Certificate) { log.debug(" Certificate {}:", i + 1); logCertificate((X509Certificate) certs[i]); } } } } } keymanagers = createKeyManagers(keystore, this.keyStorePassword); } if (this.trustStoreUrl != null) { KeyStore keystore = createStore(this.trustStoreUrl, this.trustStorePassword, this.trustStoreType); if (log.isDebugEnabled()) { for (Enumeration<String> aliases = keystore.aliases(); aliases.hasMoreElements();) { String alias = aliases.nextElement(); log.debug("Trusted certificate '{}':", alias); Certificate trustedcert = keystore.getCertificate(alias); if (trustedcert instanceof X509Certificate) { logCertificate((X509Certificate) trustedcert); } } } trustmanagers = createTrustManagers(keystore); } SSLContext context = SSLContext.getInstance("SSL"); context.init(keymanagers, trustmanagers, null); return context; } catch (NoSuchAlgorithmException e) { throw new JFunkException("Unsupported algorithm exception: " + e.getMessage(), e); } catch (KeyStoreException e) { throw new JFunkException("Keystore exception: " + e.getMessage(), e); } catch (GeneralSecurityException e) { throw new JFunkException("Key management exception: " + e.getMessage(), e); } catch (IOException e) { throw new JFunkException("I/O error reading key store/trust store file: " + e.getMessage(), e); } }
From source file:be.fedict.commons.eid.consumer.BeIDIntegrity.java
/** * Verifies an authentication signature. * //from www . j a va 2 s. co m * @param toBeSigned * @param signatureValue * @param authnCertificate * @return */ public boolean verifyAuthnSignature(final byte[] toBeSigned, final byte[] signatureValue, final X509Certificate authnCertificate) { final PublicKey publicKey = authnCertificate.getPublicKey(); boolean result; try { result = this.verifySignature(signatureValue, publicKey, toBeSigned); } catch (final InvalidKeyException ikex) { LOG.warn("invalid key: " + ikex.getMessage(), ikex); return false; } catch (final NoSuchAlgorithmException nsaex) { LOG.warn("no such algo: " + nsaex.getMessage(), nsaex); return false; } catch (final SignatureException sigex) { LOG.warn("signature error: " + sigex.getMessage(), sigex); return false; } return result; }
From source file:opendap.dap.http.EasySSLProtocolSocketFactory.java
private SSLContext createSSLContext() throws HTTPException { try {//from w w w . ja v a 2s . c om KeyManager[] keymanagers = null; KeyStore keystore = null; KeyStore truststore = null; TrustManager[] trustmanagers = null; String keypassword = getpassword("key"); String keypath = getstorepath("key"); String trustpassword = getpassword("trust"); String trustpath = getstorepath("trust"); keystore = buildstore(keypath, keypassword, "key"); if (keystore != null) { KeyManagerFactory kmfactory = KeyManagerFactory.getInstance("SunX509"); kmfactory.init(keystore, keypassword.toCharArray()); keymanagers = kmfactory.getKeyManagers(); } truststore = buildstore(trustpath, trustpassword, "trust"); if (truststore != null) { //TrustManagerFactory trfactory = TrustManagerFactory.getInstance("SunX509"); //trfactory.init(truststore, trustpassword.toCharArray()); //trustmanagers = trfactory.getTrustManagers(); trustmanagers = new TrustManager[] { new EasyX509TrustManager(truststore) }; } SSLContext sslcontext = SSLContext.getInstance("SSL"); sslcontext.init(keymanagers, trustmanagers, null); return sslcontext; } catch (NoSuchAlgorithmException e) { throw new HTTPException("Unsupported algorithm exception: " + e.getMessage()); } catch (KeyStoreException e) { throw new HTTPException("Keystore exception: " + e.getMessage()); } catch (GeneralSecurityException e) { throw new HTTPException("Key management exception: " + e.getMessage()); } catch (IOException e) { throw new HTTPException("I/O error reading keystore/truststore file: " + e.getMessage()); } }