Search in sources :

Example 66 with X509KeyManager

use of javax.net.ssl.X509KeyManager in project fdroidclient by f-droid.

the class LocalRepoKeyStore method addToStore.

private void addToStore(String alias, KeyPair kp, Certificate cert) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException {
    Certificate[] chain = { cert };
    keyStore.setKeyEntry(alias, kp.getPrivate(), "".toCharArray(), chain);
    keyStore.store(new FileOutputStream(keyStoreFile), "".toCharArray());
    /*
         * After adding an entry to the keystore we need to create a fresh
         * KeyManager by reinitializing the KeyManagerFactory with the new key
         * store content and then rewrapping the default KeyManager with our own
         */
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    keyManagerFactory.init(keyStore, "".toCharArray());
    KeyManager defaultKeyManager = keyManagerFactory.getKeyManagers()[0];
    KeyManager wrappedKeyManager = new KerplappKeyManager((X509KeyManager) defaultKeyManager);
    keyManagers = new KeyManager[] { wrappedKeyManager };
}
Also used : FileOutputStream(java.io.FileOutputStream) X509KeyManager(javax.net.ssl.X509KeyManager) KeyManager(javax.net.ssl.KeyManager) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

X509KeyManager (javax.net.ssl.X509KeyManager)66 KeyManager (javax.net.ssl.KeyManager)32 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)22 IOException (java.io.IOException)18 X509Certificate (java.security.cert.X509Certificate)17 KeyStore (java.security.KeyStore)16 SSLContext (javax.net.ssl.SSLContext)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 MethodSource (org.junit.jupiter.params.provider.MethodSource)12 GeneralSecurityException (java.security.GeneralSecurityException)8 CertificateException (java.security.cert.CertificateException)8 X509TrustManager (javax.net.ssl.X509TrustManager)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)7 PrivateKey (java.security.PrivateKey)7 TrustManager (javax.net.ssl.TrustManager)7 X509ExtendedKeyManager (javax.net.ssl.X509ExtendedKeyManager)7 UnifiedX509KeyManager (com.sun.enterprise.security.ssl.manager.UnifiedX509KeyManager)4 KeyFactory (java.security.KeyFactory)4 KeyPair (java.security.KeyPair)4 KeyPairGenerator (java.security.KeyPairGenerator)4