Search in sources :

Example 21 with KeyStore

use of java.security.KeyStore in project vert.x by eclipse.

the class KeyStoreHelper method getKeyMgrFactory.

public KeyManagerFactory getKeyMgrFactory(VertxInternal vertx) throws Exception {
    KeyManagerFactory fact = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    fact.getProvider();
    KeyStore ks = loadStore(vertx);
    fact.init(ks, password != null ? password.toCharArray() : null);
    return fact;
}
Also used : KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 22 with KeyStore

use of java.security.KeyStore in project vert.x by eclipse.

the class KeyStoreHelper method getTrustMgrFactory.

public TrustManagerFactory getTrustMgrFactory(VertxInternal vertx) throws Exception {
    TrustManagerFactory fact = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    KeyStore ts = loadStore(vertx);
    fact.init(ts);
    return fact;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyStore(java.security.KeyStore)

Example 23 with KeyStore

use of java.security.KeyStore in project buck by facebook.

the class ApkBuilderStep method createKeystoreProperties.

private PrivateKeyAndCertificate createKeystoreProperties() throws IOException, KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
    KeyStore keystore = KeyStore.getInstance(JARSIGNER_KEY_STORE_TYPE);
    KeystoreProperties keystoreProperties = keystorePropertiesSupplier.get();
    InputStream inputStream = filesystem.getInputStreamForRelativePath(pathToKeystore);
    char[] keystorePassword = keystoreProperties.getStorepass().toCharArray();
    try {
        keystore.load(inputStream, keystorePassword);
    } catch (IOException | NoSuchAlgorithmException | CertificateException e) {
        throw new HumanReadableException(e, "%s is an invalid keystore.", pathToKeystore);
    }
    String alias = keystoreProperties.getAlias();
    char[] keyPassword = keystoreProperties.getKeypass().toCharArray();
    Key key = keystore.getKey(alias, keyPassword);
    // key can be null if alias/password is incorrect.
    if (key == null) {
        throw new HumanReadableException("The keystore [%s] key.alias [%s] does not exist or does not identify a key-related " + "entry", pathToKeystore, alias);
    }
    Certificate certificate = keystore.getCertificate(alias);
    return new PrivateKeyAndCertificate((PrivateKey) key, (X509Certificate) certificate);
}
Also used : InputStream(java.io.InputStream) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStore(java.security.KeyStore) HumanReadableException(com.facebook.buck.util.HumanReadableException) Key(java.security.Key) PrivateKey(java.security.PrivateKey) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 24 with KeyStore

use of java.security.KeyStore in project Libraries-for-Android-Developers by eoecn.

the class MySSLSocketFactory method getKeystore.

/**
	 * Gets a Default KeyStore
	 * 
	 * @return KeyStore
	 */
public static KeyStore getKeystore() {
    KeyStore trustStore = null;
    try {
        trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        trustStore.load(null, null);
    } catch (Throwable t) {
        t.printStackTrace();
    }
    return trustStore;
}
Also used : KeyStore(java.security.KeyStore)

Example 25 with KeyStore

use of java.security.KeyStore in project Libraries-for-Android-Developers by eoecn.

the class MySSLSocketFactory method getKeystoreOfCA.

/**
     * Gets a KeyStore containing the Certificate
     * 
     * @param cert InputStream of the Certificate
     * @return KeyStore
     */
public static KeyStore getKeystoreOfCA(InputStream cert) {
    // Load CAs from an InputStream
    InputStream caInput = null;
    Certificate ca = null;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        caInput = new BufferedInputStream(cert);
        ca = (Certificate) cf.generateCertificate(caInput);
    } catch (CertificateException e1) {
        e1.printStackTrace();
    } finally {
        try {
            caInput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    // Create a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = null;
    try {
        keyStore = KeyStore.getInstance(keyStoreType);
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", (java.security.cert.Certificate) ca);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return keyStore;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

KeyStore (java.security.KeyStore)738 IOException (java.io.IOException)190 X509Certificate (java.security.cert.X509Certificate)189 FileInputStream (java.io.FileInputStream)163 KeyStoreException (java.security.KeyStoreException)151 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)138 InputStream (java.io.InputStream)125 Certificate (java.security.cert.Certificate)124 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)119 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)114 SSLContext (javax.net.ssl.SSLContext)112 PrivateKey (java.security.PrivateKey)94 CertificateException (java.security.cert.CertificateException)94 File (java.io.File)82 ByteArrayInputStream (java.io.ByteArrayInputStream)75 CertificateFactory (java.security.cert.CertificateFactory)75 Key (java.security.Key)61 UnrecoverableKeyException (java.security.UnrecoverableKeyException)55 TrustManager (javax.net.ssl.TrustManager)47 KeyManagementException (java.security.KeyManagementException)40