Example usage for java.security NoSuchAlgorithmException getMessage

List of usage examples for java.security NoSuchAlgorithmException getMessage

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.kuali.kra.s2s.service.impl.GrantsGovConnectorServiceImpl.java

/**
 * This method is to confgiure KeyStore and Truststore for Grants.Gov webservice client
 * @param tlsConfig// www  .j a  v a 2 s.c  o  m
 * @param alias
 * @param mulitCampusEnabled
 * @throws S2SException
 */
protected void configureKeyStoreAndTrustStore(TLSClientParameters tlsConfig, String alias,
        boolean mulitCampusEnabled) throws S2SException {
    KeyStore keyStore = S2SCertificateReader.getKeyStore();
    KeyManagerFactory keyManagerFactory;
    try {
        keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        if (alias != null && mulitCampusEnabled) {
            KeyStore keyStoreAlias;
            keyStoreAlias = KeyStore.getInstance(JKS_TYPE);
            Certificate[] certificates = keyStore.getCertificateChain(alias);
            Key key = keyStore.getKey(alias, s2SUtilService.getProperty(KEYSTORE_PASSWORD).toCharArray());
            keyStoreAlias.load(null, null);
            keyStoreAlias.setKeyEntry(alias, key, s2SUtilService.getProperty(KEYSTORE_PASSWORD).toCharArray(),
                    certificates);
            keyManagerFactory.init(keyStoreAlias, s2SUtilService.getProperty(KEYSTORE_PASSWORD).toCharArray());
        } else {
            keyManagerFactory.init(keyStore, s2SUtilService.getProperty(KEYSTORE_PASSWORD).toCharArray());
        }
        KeyManager[] km = keyManagerFactory.getKeyManagers();
        tlsConfig.setKeyManagers(km);
        KeyStore trustStore = S2SCertificateReader.getTrustStore();
        TrustManagerFactory trustManagerFactory = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(trustStore);
        TrustManager[] tm = trustManagerFactory.getTrustManagers();
        tlsConfig.setTrustManagers(tm);
    } catch (NoSuchAlgorithmException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    } catch (KeyStoreException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    } catch (UnrecoverableKeyException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    } catch (CertificateException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    } catch (IOException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    }
}

From source file:securitytools.veracode.VeracodeClient.java

/**
 * Constructs a new VeracodeClient using the specified configuration.
 *     //from w w w.  j  a v  a2 s  . c om
 * @param credentials Credentials used to access Veracode services.   
 * @param clientConfiguration Client configuration for options such as proxy
 * settings, user-agent header, and network timeouts.
 */
public VeracodeClient(VeracodeCredentials credentials, ClientConfiguration clientConfiguration) {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(TARGET), credentials);

    AuthCache authCache = new BasicAuthCache();
    authCache.put(TARGET, new BasicScheme());

    context = HttpClientContext.create();
    context.setCredentialsProvider(credentialsProvider);
    context.setAuthCache(authCache);

    try {
        client = HttpClientFactory.build(clientConfiguration);
    } catch (NoSuchAlgorithmException nsae) {
        throw new VeracodeClientException(nsae.getMessage(), nsae);
    }
}

From source file:com.plotsquared.iserver.core.Worker.java

private Worker() {
    if (CoreConfig.contentMd5) {
        MessageDigest temporary = null;
        try {//from w  ww.  j a v a  2 s. c om
            temporary = MessageDigest.getInstance("MD5");
        } catch (final NoSuchAlgorithmException e) {
            Message.MD5_DIGEST_NOT_FOUND.log(e.getMessage());
        }
        messageDigestMd5 = temporary;
        encoder = new BASE64Encoder();
    } else {
        messageDigestMd5 = null;
        encoder = null;
    }

    if (CoreConfig.gzip) {
        this.reusableGzipOutputStream = new ReusableGzipOutputStream();
    } else {
        this.reusableGzipOutputStream = null;
    }

    this.workerProcedureInstance = Server.getInstance().getProcedure().getInstance();
    this.server = (Server) Server.getInstance();
}

From source file:gov.va.med.imaging.proxy.ssl.AuthSSLProtocolSocketFactory.java

private SSLContext createSSLContext() {
    try {/* w  w w .  ja v a 2 s.co  m*/
        KeyManager[] keymanagers = null;
        TrustManager[] trustmanagers = null;
        if (this.keystoreUrl != null) {
            KeyStore keystore = createKeyStore(this.keystoreUrl, this.keystorePassword);
            if (Logger.getLogger(AuthSSLProtocolSocketFactory.class).isDebugEnabled())
                logKeystoreContents("keystore", keystore);

            keymanagers = createKeyManagers(keystore, this.keystorePassword);
        }
        if (this.truststoreUrl != null) {
            KeyStore truststore = createKeyStore(this.truststoreUrl, this.truststorePassword);
            if (Logger.getLogger(AuthSSLProtocolSocketFactory.class).isDebugEnabled())
                logKeystoreContents("truststore", truststore);

            trustmanagers = createTrustManagers(truststore);
        }
        SSLContext sslcontext = SSLContext.getInstance("SSL");
        sslcontext.init(keymanagers, trustmanagers, null);
        return sslcontext;
    } catch (NoSuchAlgorithmException e) {
        Logger.getLogger(AuthSSLProtocolSocketFactory.class).error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Unsupported algorithm exception: " + e.getMessage());
    } catch (KeyStoreException e) {
        Logger.getLogger(AuthSSLProtocolSocketFactory.class).error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Keystore exception: " + e.getMessage());
    } catch (GeneralSecurityException e) {
        Logger.getLogger(AuthSSLProtocolSocketFactory.class).error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Key management exception: " + e.getMessage());
    } catch (IOException e) {
        Logger.getLogger(AuthSSLProtocolSocketFactory.class).error(e.getMessage(), e);
        throw new AuthSSLInitializationError("I/O error reading keystore/truststore file: " + e.getMessage());
    }
}

From source file:it.greenvulcano.gvesb.http.ssl.AuthSSLProtocolSocketFactory.java

private SSLContext createSSLContext() {
    try {//from w w  w  .ja v a 2s . c o m
        KeyManager[] keymanagers = null;
        TrustManager[] trustmanagers = null;
        if (this.keystoreID != null) {
            KeyStore keystore = createKeyStore(this.keystoreID);
            if (logger.isDebugEnabled()) {
                Enumeration<String> aliases = keystore.aliases();
                while (aliases.hasMoreElements()) {
                    String alias = aliases.nextElement();
                    Certificate[] certs = keystore.getCertificateChain(alias);
                    if (certs != null) {
                        logger.debug("Certificate chain '" + alias + "':");
                        for (int c = 0; c < certs.length; c++) {
                            if (certs[c] instanceof X509Certificate) {
                                X509Certificate cert = (X509Certificate) certs[c];
                                logger.debug(" Certificate " + (c + 1) + ":");
                                logger.debug("  Subject DN: " + cert.getSubjectDN());
                                logger.debug("  Signature Algorithm: " + cert.getSigAlgName());
                                logger.debug("  Valid from: " + cert.getNotBefore());
                                logger.debug("  Valid until: " + cert.getNotAfter());
                                logger.debug("  Issuer: " + cert.getIssuerDN());
                            }
                        }
                    }
                }
            }
            keymanagers = createKeyManagers(keystore, this.keyPassword);
        }
        if (this.truststoreID != null) {
            KeyStore keystore = createKeyStore(this.truststoreID);
            if (logger.isDebugEnabled()) {
                Enumeration<String> aliases = keystore.aliases();
                while (aliases.hasMoreElements()) {
                    String alias = aliases.nextElement();
                    logger.debug("Trusted certificate '" + alias + "':");
                    Certificate trustedcert = keystore.getCertificate(alias);
                    if (trustedcert != null && trustedcert instanceof X509Certificate) {
                        X509Certificate cert = (X509Certificate) trustedcert;
                        logger.debug("  Subject DN: " + cert.getSubjectDN());
                        logger.debug("  Signature Algorithm: " + cert.getSigAlgName());
                        logger.debug("  Valid from: " + cert.getNotBefore());
                        logger.debug("  Valid until: " + cert.getNotAfter());
                        logger.debug("  Issuer: " + cert.getIssuerDN());
                    }
                }
            }
            trustmanagers = createTrustManagers(keystore);
        }
        SSLContext sslctx = SSLContext.getInstance("SSL");
        sslctx.init(keymanagers, trustmanagers, null);
        return sslctx;
    } catch (NoSuchAlgorithmException e) {
        logger.error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Unsupported algorithm exception: " + e.getMessage());
    } catch (KeyStoreException e) {
        logger.error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Keystore exception: " + e.getMessage());
    } catch (GeneralSecurityException e) {
        logger.error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Key management exception: " + e.getMessage());
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new AuthSSLInitializationError("Error reading keystore/truststore file: " + e.getMessage());
    }
}

From source file:org.kuali.kra.s2s.service.impl.S2SConnectorServiceBase.java

/**
 * This method is to confgiure KeyStore and Truststore for Grants.Gov webservice client
 * @param tlsConfig/*from   w  ww.ja  v a 2 s.co  m*/
 * @param alias
 * @param mulitCampusEnabled
 * @throws S2SException
 */
protected void configureKeyStoreAndTrustStore(TLSClientParameters tlsConfig, String alias,
        boolean mulitCampusEnabled) throws S2SException {
    KeyStore keyStore = s2sCertificateReader.getKeyStore();
    KeyManagerFactory keyManagerFactory;
    try {
        keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        if (alias != null && mulitCampusEnabled) {
            KeyStore keyStoreAlias;
            keyStoreAlias = KeyStore.getInstance(s2sCertificateReader.getJksType());
            Certificate[] certificates = keyStore.getCertificateChain(alias);
            Key key = keyStore.getKey(alias,
                    s2SUtilService.getProperty(s2sCertificateReader.getKeyStorePassword()).toCharArray());
            keyStoreAlias.load(null, null);
            keyStoreAlias.setKeyEntry(alias, key,
                    s2SUtilService.getProperty(s2sCertificateReader.getKeyStorePassword()).toCharArray(),
                    certificates);
            keyManagerFactory.init(keyStoreAlias,
                    s2SUtilService.getProperty(s2sCertificateReader.getKeyStorePassword()).toCharArray());
        } else {
            keyManagerFactory.init(keyStore,
                    s2SUtilService.getProperty(s2sCertificateReader.getKeyStorePassword()).toCharArray());
        }
        KeyManager[] km = keyManagerFactory.getKeyManagers();
        tlsConfig.setKeyManagers(km);
        KeyStore trustStore = s2sCertificateReader.getTrustStore();
        TrustManagerFactory trustManagerFactory = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(trustStore);
        TrustManager[] tm = trustManagerFactory.getTrustManagers();
        tlsConfig.setTrustManagers(tm);
    } catch (NoSuchAlgorithmException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    } catch (KeyStoreException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    } catch (UnrecoverableKeyException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    } catch (CertificateException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    } catch (IOException e) {
        LOG.error(e);
        throw new S2SException(KeyConstants.ERROR_KEYSTORE_CONFIG, e.getMessage());
    }
}

From source file:org.jfrog.teamcity.agent.BaseBuildInfoExtractor.java

protected Map<String, String> getArtifactChecksumMap(String artifactPath) {
    Map<String, String> mapToReturn = null;

    if (calculatedChecksumCache.containsKey(artifactPath)) {
        mapToReturn = calculatedChecksumCache.get(artifactPath);
    } else {//from www . j  a  v a  2  s.  c  om
        File artifactFile = new File(artifactPath);
        if (artifactFile.exists()) {
            try {
                Map<String, String> checksums = FileChecksumCalculator.calculateChecksums(artifactFile, "sha1",
                        "md5");
                if (!checksums.isEmpty()) {
                    calculatedChecksumCache.put(artifactPath, checksums);
                }
                mapToReturn = checksums;
            } catch (NoSuchAlgorithmException nsae) {
                String errorMessage = "Error while calculating the checksum of " + artifactPath + " ("
                        + nsae.getMessage() + ") Please view the build agent log for further details.";
                logger.message(errorMessage);
                Loggers.AGENT.error(errorMessage, nsae);
            } catch (IOException ioe) {
                String errorMessage = "Error while calculating the checksum of " + artifactPath + " ("
                        + ioe.getMessage() + ") Please view the build agent log for further details.";
                logger.message(errorMessage);
                Loggers.AGENT.error(errorMessage, ioe);
            }
        } else {
            String errorMessage = "File not found. Skipping checksum calculation of " + artifactPath;
            Loggers.AGENT.warn(errorMessage);
        }
    }

    if (mapToReturn == null) {
        return Maps.newHashMap();
    }
    return mapToReturn;
}

From source file:org.escabe.trakt.TraktAPI.java

/**
 * Encodes p as SHA1 Hash./*  w  w  w.j  av  a  2  s . c o  m*/
 * @param p   Password.
 * @return   SHA1 encoded password.
 */
private String EncodePassword(String p) {
    MessageDigest sha;
    try {
        sha = MessageDigest.getInstance("SHA-1");
        sha.update(p.getBytes("iso-8859-1"));
        byte[] hash = sha.digest();
        p = "";
        for (int i = 0; i < hash.length; i++) {
            //FIX for http://code.google.com/p/trakt-app/issues/detail?id=1
            p = String.format("%s%02x", p, hash[i] & 0xFF);
        }
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        Log.e(TAG, e.getMessage());
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        Log.e(TAG, e.getMessage());
    }
    return p;
}

From source file:be.fedict.eid.applet.service.impl.handler.IdentityDataMessageHandler.java

private void verifySignature(String signAlgo, byte[] signatureData, PublicKey publicKey,
        HttpServletRequest request, byte[]... data) throws ServletException {
    Signature signature;/*from  w  ww. j  av a  2 s  .co m*/
    try {
        signature = Signature.getInstance(signAlgo);
    } 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) {
        AuditService auditService = this.auditServiceLocator.locateService();
        if (null != auditService) {
            String remoteAddress = request.getRemoteAddr();
            auditService.identityIntegrityError(remoteAddress);
        }
        throw new ServletException("signature error: " + e.getMessage(), e);
    }
}

From source file:org.apache.jmeter.protocol.oauth.sampler.PrivateKeyReader.java

/**
 * Read the PEM file and return the key//from www.j  a v a2  s  .co  m
 * 
 * @return
 * @throws IOException
 */
private PrivateKey read() throws IOException {

    String line;

    KeyFactory factory;
    try {
        factory = KeyFactory.getInstance("RSA"); //$NON-NLS-1$
    } catch (NoSuchAlgorithmException e) {
        throw new IOException("JCE error: " + e.getMessage()); //$NON-NLS-1$
    }

    while ((line = server.readLine(fileName)) != null) {
        if (line.indexOf(P1_BEGIN_MARKER) != -1) {
            byte[] keyBytes = readKeyMaterial(P1_END_MARKER);
            RSAPrivateCrtKeySpec keySpec = getRSAKeySpec(keyBytes);

            try {
                return factory.generatePrivate(keySpec);
            } catch (InvalidKeySpecException e) {
                throw new IOException("Invalid PKCS#1 PEM file: " + e.getMessage()); //$NON-NLS-1$
            }
        }

        if (line.indexOf(P8_BEGIN_MARKER) != -1) {
            byte[] keyBytes = readKeyMaterial(P8_END_MARKER);
            EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);

            try {
                return factory.generatePrivate(keySpec);
            } catch (InvalidKeySpecException e) {
                throw new IOException("Invalid PKCS#8 PEM file: " + e.getMessage()); //$NON-NLS-1$
            }
        }

    }

    throw new IOException("Invalid PEM file: no begin marker"); //$NON-NLS-1$
}