Example usage for java.security KeyStoreException getMessage

List of usage examples for java.security KeyStoreException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.commonjava.ssl.util.KeyStoreManager.java

public static KeyStore create(String keystoreType) throws SSLToolsException {
    try {/*from  w  w w.j a v a  2  s  .  c o m*/
        return KeyStore.getInstance(keystoreType);
    } catch (KeyStoreException e) {
        throw new SSLToolsException("Failed to create KeyStore instance: %s", e, e.getMessage());
    }
}

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

public static KeyStore getKeyStore() throws S2SException {
    if (keyStore != null)
        return keyStore;
    try {/*from   ww w .  j  ava2  s.  com*/
        keyStore = KeyStore.getInstance(JKS_TYPE);
        keyStore.load(new FileInputStream(getS2SUtilService().getProperty(KEYSTORE_LOCATION)),
                getS2SUtilService().getProperty(KEYSTORE_PASSWORD).toCharArray());
    } catch (KeyStoreException e) {
        keyStore = null;
        LOG.error("Error while creating Keystore with cert " + KEYSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_KEYSTORE_CREATION, e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        keyStore = null;
        LOG.error("JCE provider doesnt support certificate algorithm " + KEYSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_KEYSTORE_NO_ALGORITHM, e.getMessage());
    } catch (CertificateException e) {
        keyStore = null;
        LOG.error("Error while creating keystore " + KEYSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_KEYSTORE_BAD_CERTIFICATE, e.getMessage());
    } catch (FileNotFoundException e) {
        keyStore = null;
        LOG.error("File not found " + KEYSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_KEYSTORE_NOT_FOUND, e.getMessage());
    } catch (IOException e) {
        keyStore = null;
        LOG.error("IO Exception while reading keystore file " + KEYSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_KEYSTORE_CANNOT_READ, e.getMessage());
    }
    return keyStore;
}

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

public static KeyStore getTrustStore() throws S2SException {
    if (trustStore != null)
        return trustStore;
    try {//from   www  .j  av  a2 s.  c  o  m
        trustStore = KeyStore.getInstance(JKS_TYPE);
        trustStore.load(new FileInputStream(getS2SUtilService().getProperty(TRUSTSTORE_LOCATION)),
                getS2SUtilService().getProperty(TRUSTSTORE_PASSWORD).toCharArray());
    } catch (KeyStoreException e) {
        trustStore = null;
        LOG.error("Error while creating Keystore with cert " + TRUSTSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_TRUSTSTORE_CREATION, e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        trustStore = null;
        LOG.error("JCE provider doesnt support certificate algorithm " + TRUSTSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_TRUSTSTORE_NO_ALGORITHM, e.getMessage());
    } catch (CertificateException e) {
        trustStore = null;
        LOG.error("Error while creating keystore " + TRUSTSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_TRUSTSTORE_BAD_CERTIFICATE, e.getMessage());
    } catch (FileNotFoundException e) {
        trustStore = null;
        LOG.error("File not found " + TRUSTSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_TRUSTSTORE_NOT_FOUND, e.getMessage());
    } catch (IOException e) {
        trustStore = null;
        LOG.error("IO Exception while reading keystore file " + TRUSTSTORE_LOCATION, e);
        throw new S2SException(KeyConstants.ERROR_S2S_TRUSTSTORE_CANNOT_READ, e.getMessage());
    }
    return trustStore;
}

From source file:org.viafirma.nucleo.validacion.KeyStoreLoader.java

/**
 * Recupera el camino completo para el certificado con el alias indicado.
 * /*  ww  w  .  j  ava  2  s. c o m*/
 * @param alias
 *            Alias del certificado del que deseamos recuperar el alias.
 * @return ChainCertificate del alias indicado
 * @throws ExcepcionErrorInterno
 */
public static List<Certificate> getCertificateChain(String alias) throws ExcepcionErrorInterno {
    try {
        return Arrays.asList(loadDefaultKeyStore().getCertificateChain(alias));
    } catch (KeyStoreException e) {
        throw new ExcepcionErrorInterno(e.getMessage());
    } catch (ExcepcionErrorInterno e) {
        throw e;
    }
}

From source file:org.viafirma.nucleo.validacion.KeyStoreLoader.java

/**
 * Recupera el certificado con el alias indicado.
 * /* w  w  w  .j  av a 2  s.  c o  m*/
 * @param alias
 *            Alias del certificado deseado.
 * @return Certificado con el alias indicado
 * @throws ExcepcionErrorInterno
 */
public static X509Certificate getCertificate(String alias) throws ExcepcionErrorInterno {
    try {
        return (X509Certificate) loadDefaultKeyStore().getCertificate(alias);
    } catch (KeyStoreException e) {
        throw new ExcepcionErrorInterno(e.getMessage());
    } catch (ExcepcionErrorInterno e) {
        throw e;
    } catch (ClassCastException e) {
        throw new ExcepcionErrorInterno("El alias indicado no pertenece a un certificado X509.");
    }
}

From source file:cn.mrdear.pay.util.RSAUtils.java

/**
 * ?//from w  w  w.  j a v  a2s .c  om
 * 
 * @param type
 *            
 * @param inputStream
 *            ?
 * @param password
 *            ?
 * @return 
 */
public static Key getKey(String type, InputStream inputStream, String password) {
    Assert.isNotEmpty(type);
    Assert.notNull(inputStream);

    try {
        KeyStore keyStore = KeyStore.getInstance(type, PROVIDER);
        keyStore.load(inputStream, password != null ? password.toCharArray() : null);
        String alias = keyStore.aliases().hasMoreElements() ? keyStore.aliases().nextElement() : null;
        return keyStore.getKey(alias, password != null ? password.toCharArray() : null);
    } catch (KeyStoreException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (CertificateException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    } catch (UnrecoverableKeyException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.piusvelte.taplock.server.TapLockServer.java

protected static KeyStore getKeyStore() {
    KeyStore ks = null;/*  w  w  w  . j  a  v  a2s  .com*/
    try {
        ks = KeyStore.getInstance("BKS");
    } catch (KeyStoreException e) {
        writeLog("getKeyStore: " + e.getMessage());
    }
    return ks;
}

From source file:org.riksa.a3.fragment.KeyListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_keylist, container, false);
    try {//w w w. j  a v a2  s  .  com
        keyChain = KeyChain.getInstance(getActivity());
        keyChain.addListener(keyChainListener);
    } catch (KeyStoreException e) {
        log.error(e.getMessage(), e);
        Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
        getActivity().finish();
    }
    return view;
}

From source file:com.appfirst.communication.AFHttpClient.java

public DefaultHttpClient getAFHttpClient() {
    try {/*ww  w . j a va 2  s  .co m*/
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        try {
            trustStore.load(null, null);
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        SSLSocketFactory sf = new AFSSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));
        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
        return new DefaultHttpClient(ccm, params);
    } catch (NoSuchAlgorithmException nsae) {
        Log.e(TAG, nsae.getMessage());
        return new DefaultHttpClient();
    } catch (KeyManagementException kme) {
        Log.e(TAG, kme.getMessage());
        return new DefaultHttpClient();
    } catch (KeyStoreException kse) {
        Log.e(TAG, kse.getMessage());
        return new DefaultHttpClient();
    } catch (UnrecoverableKeyException uke) {
        Log.e(TAG, uke.getMessage());
        return new DefaultHttpClient();
    }
}

From source file:org.alfresco.extension.countersign.action.executer.ContentSignatureActionExecuter.java

@Override
protected void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) {
    NodeService nodeService = serviceRegistry.getNodeService();
    ContentService contentService = serviceRegistry.getContentService();
    byte[] sigBytes;

    if (nodeService.exists(actionedUponNodeRef) == false) {
        return;//from   www. ja  v a 2  s .  c  om
    }

    String location = (String) ruleAction.getParameterValue(PARAM_LOCATION);
    String geolocation = (String) ruleAction.getParameterValue(PARAM_GEOLOCATION);
    String reason = (String) ruleAction.getParameterValue(PARAM_REASON);
    String keyPassword = (String) ruleAction.getParameterValue(PARAM_KEY_PASSWORD);

    // get a hash of the document
    InputStream contentStream = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT)
            .getContentInputStream();

    try {
        // get the user's private key
        String user = AuthenticationUtil.getRunAsUser();
        SignatureProvider signatureProvider = signatureProviderFactory.getSignatureProvider(user);
        KeyStore keystore = signatureProvider.getUserKeyStore(keyPassword);
        PrivateKey key = (PrivateKey) keystore.getKey(alias, keyPassword.toCharArray());

        // compute the document hash
        byte[] hash = signatureProvider.computeHash(contentStream);

        // sign the hash
        sigBytes = signatureProvider.signHash(hash, keyPassword);

        // create a "signature" node and associate it with the signed doc
        NodeRef sig = addSignatureNodeAssociation(actionedUponNodeRef, location, reason, "none",
                new java.util.Date(), geolocation, -1, "none");

        // save the signature
        ContentWriter writer = contentService.getWriter(sig, ContentModel.PROP_CONTENT, true);
        writer.putContent(new ByteArrayInputStream(sigBytes));

        // also save the expected hash in the signature
        nodeService.setProperty(sig, CounterSignSignatureModel.PROP_DOCHASH, new String(hash));
    } catch (UnrecoverableKeyException uke) {
        throw new AlfrescoRuntimeException(uke.getMessage());
    } catch (KeyStoreException kse) {
        throw new AlfrescoRuntimeException(kse.getMessage());
    } catch (NoSuchAlgorithmException nsae) {
        throw new AlfrescoRuntimeException(nsae.getMessage());
    } catch (Exception e) {
        throw new AlfrescoRuntimeException(e.getMessage());
    }
}