/** * Create a new {@code AtomicLoadKeyStore} wrapping a {@link KeyStore} of the type specified. * * @param type the type of {@link KeyStore} to be wrapped * @param provider the provide to use to create the {@link KeyStore} * @return the new {@code AtomicLoadKeyStore} instance * @throws KeyStoreException If there is a problem creating the {@link KeyStore} * @throws NoSuchProviderException if the provider specified can not be found. */ public static AtomicLoadKeyStore newInstance(final String type, final String provider) throws KeyStoreException, NoSuchProviderException { KeyStore keyStore = provider != null ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type); final Provider resolvedProvider = keyStore.getProvider(); return newInstance(type, resolvedProvider); }
/** * Construct a new instance. * * @param delegate the delegate {@code KeyStore} (must not be {@code null}) */ public WrappingPasswordKeyStore(final KeyStore delegate) { super(new WrappingPasswordKeyStoreSpiImpl(delegate), delegate.getProvider(), delegate.getType()); } }
void init(String cryptographicAlgorithm, String keyAlias, KeyStore keyStore, char[] keyPassword, KeyStore dataKeyStore) throws CredentialStoreException { if (cryptographicAlgorithm == null) cryptographicAlgorithm = DEFAULT_CRYPTOGRAPHIC_ALGORITHM; storageSecretKeyStore = keyStore; this.dataKeyStore = dataKeyStore; try { fetchStorageSecretKey(keyAlias, keyPassword); Provider provider = keyStore.getProvider(); try { encrypt = Cipher.getInstance(cryptographicAlgorithm, provider); } catch (NoSuchAlgorithmException e) { // fallback to any provider of desired algorithm encrypt = Cipher.getInstance(cryptographicAlgorithm); } try { decrypt = Cipher.getInstance(cryptographicAlgorithm, provider); } catch (NoSuchAlgorithmException e) { // fallback to any provider of desired algorithm decrypt = Cipher.getInstance(cryptographicAlgorithm); } } catch (NoSuchAlgorithmException | NoSuchPaddingException | UnrecoverableEntryException | KeyStoreException | IOException | CertificateException e) { throw new CredentialStoreException(e); } }
/** * Wrap an existing initialised {@link KeyStore} with an wrapper to filter which aliases can be returned. * * @param toWrap the {@link KeyStore} to wrap. * @return the filtering wrapper around the {@link KeyStore} * @throws NoSuchAlgorithmException * @throws CertificateException * @throws IOException * @throws IllegalArgumentException if the {@link KeyStore} being wrapped is {@code null} */ public static KeyStore filteringKeyStore(final KeyStore toWrap, final Predicate<String> aliasPredicate) throws NoSuchAlgorithmException, CertificateException, IOException { Assert.checkNotNullParam("toWrap", toWrap); KeyStore keyStore = new FilteringKeyStore(new FilteringKeyStoreSpi(toWrap, aliasPredicate), toWrap.getProvider(), toWrap.getType()); keyStore.load(null, null); return keyStore; }
/** * Wrap an existing initialised {@link KeyStore} with an unmodifiable wrapper. * * Note: References are held to the underlying {@link KeyStore} can still be modified and changes will still be visible in * the representation returned here. * * @param toWrap the {@link KeyStore} to wrap. * @return the unmodifiable wrapper around the {@link KeyStore} * @throws NoSuchAlgorithmException * @throws CertificateException * @throws IOException * @throws IllegalArgumentException if the {@link KeyStore} being wrapped is {@code null} */ public static KeyStore unmodifiableKeyStore(final KeyStore toWrap) throws NoSuchAlgorithmException, CertificateException, IOException { Assert.checkNotNullParam("toWrap", toWrap); KeyStore keyStore = new UnmodifiableKeyStore(new UnmodifiableKeyStoreSpi(toWrap), toWrap.getProvider(), toWrap.getType()); keyStore.load(null, null); return keyStore; } }
/** * Wrap an existing initialised {@link KeyStore} with a wrapper to track if it is modified. * * @param toWrap the {@link KeyStore} to wrap * @return the wrapper around the {@link KeyStore} * @throws NoSuchAlgorithmException if the keystore could not be loaded due to a missing algorithm * @throws CertificateException if the keystore could not be loaded due to a certificate problem * @throws IOException if the keystore could not be loaded due to an I/O problem * @throws IllegalArgumentException if the {@link KeyStore} being wrapped is {@code null} */ public static ModifyTrackingKeyStore modifyTrackingKeyStore(final KeyStore toWrap) throws NoSuchAlgorithmException, CertificateException, IOException { Assert.checkNotNullParam("toWrap", toWrap); ModifyTrackingKeyStore keyStore = new ModifyTrackingKeyStore(new ModifyTrackingKeyStoreSpi(toWrap), toWrap.getProvider(), toWrap.getType()); keyStore.load(null, null); return keyStore; }
context.addInfo( "key store of type '" + keyStore.getType() + "' provider '" + keyStore.getProvider() + "': " + getKeyStore().getLocation());
context.addInfo( "trust store of type '" + trustStore.getType() + "' provider '" + trustStore.getProvider() + "': " + getTrustStore().getLocation());
public Provider getProvider() { return store.getProvider(); }
String alias = "Alias to my PK"; char[] pass = "MyPassword".toCharArray(); KeyStore ks = KeyStore.getInstance("Windows-MY"); ks.load(null, pass); Provider p = ks.getProvider(); Signature sig = Signature.getInstance("SHA1withRSA",p); PrivateKey key = (PrivateKey) ks.getKey(alias, pass) sig.initSign(key); sig.update("Testing".getBytes()); sig.sign();
@Nonnull public static KeyStore getSimiliarKeyStore (@Nonnull final KeyStore aOther) throws KeyStoreException { return KeyStore.getInstance (aOther.getType (), aOther.getProvider ()); }
/** * Create a new {@code AtomicLoadKeyStore} wrapping a {@link KeyStore} of the type specified. * * @param type the type of {@link KeyStore} to be wrapped * @param provider the provide to use to create the {@link KeyStore} * @return the new {@code AtomicLoadKeyStore} instance * @throws KeyStoreException If there is a problem creating the {@link KeyStore} * @throws NoSuchProviderException if the provider specified can not be found. */ public static AtomicLoadKeyStore newInstance(final String type, final String provider) throws KeyStoreException, NoSuchProviderException { KeyStore keyStore = provider != null ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type); final Provider resolvedProvider = keyStore.getProvider(); return newInstance(type, resolvedProvider); }
/** * Create a new {@code AtomicLoadKeyStore} wrapping a {@link KeyStore} of the type specified. * * @param type the type of {@link KeyStore} to be wrapped * @param provider the provide to use to create the {@link KeyStore} * @return the new {@code AtomicLoadKeyStore} instance * @throws KeyStoreException If there is a problem creating the {@link KeyStore} * @throws NoSuchProviderException if the provider specified can not be found. */ public static AtomicLoadKeyStore newInstance(final String type, final String provider) throws KeyStoreException, NoSuchProviderException { KeyStore keyStore = provider != null ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type); final Provider resolvedProvider = keyStore.getProvider(); return newInstance(type, resolvedProvider); }
/** * Create a new {@code AtomicLoadKeyStore} wrapping a {@link KeyStore} of the type specified. * * @param type the type of {@link KeyStore} to be wrapped * @param provider the provide to use to create the {@link KeyStore} * @return the new {@code AtomicLoadKeyStore} instance * @throws KeyStoreException If there is a problem creating the {@link KeyStore} * @throws NoSuchProviderException if the provider specified can not be found. */ public static AtomicLoadKeyStore newInstance(final String type, final String provider) throws KeyStoreException, NoSuchProviderException { KeyStore keyStore = provider != null ? KeyStore.getInstance(type, provider) : KeyStore.getInstance(type); final Provider resolvedProvider = keyStore.getProvider(); return newInstance(type, resolvedProvider); }
@SuppressWarnings("unchecked") private static void printKeyStoreInfo(KeyStore keystore) throws KeyStoreException { log.debug("Provider : " + keystore.getProvider().getName()); log.debug("Type : " + keystore.getType()); log.debug("Size : " + keystore.size()); Enumeration en = keystore.aliases(); while (en.hasMoreElements()) { System.out.println("Alias: " + en.nextElement()); } }
/** * Construct a new instance. * * @param delegate the delegate {@code KeyStore} (must not be {@code null}) */ public WrappingPasswordKeyStore(final KeyStore delegate) { super(new WrappingPasswordKeyStoreSpiImpl(delegate), delegate.getProvider(), delegate.getType()); } }
@Override protected void performRuntime(ModelNode result, ModelNode operation, KeyStoreService keyStoreService) throws OperationFailedException { populateProvider(result, keyStoreService.getValue().getProvider(), false); } });
/** * Construct a new instance. * * @param delegate the delegate {@code KeyStore} (must not be {@code null}) */ public WrappingPasswordKeyStore(final KeyStore delegate) { super(new WrappingPasswordKeyStoreSpiImpl(delegate), delegate.getProvider(), delegate.getType()); } }
/** * Construct a new instance. * * @param delegate the delegate {@code KeyStore} (must not be {@code null}) */ public WrappingPasswordKeyStore(final KeyStore delegate) { super(new WrappingPasswordKeyStoreSpiImpl(delegate), delegate.getProvider(), delegate.getType()); } }
@Test public void testExplicitProvider() throws Exception { factoryBean.setLocation(SSLTestConstants.KEYSTORE_JKS_RESOURCE); KeyStore keyStore = factoryBean.createKeyStore(); factoryBean.setProvider(keyStore.getProvider().getName()); assertNotNull(factoryBean.createKeyStore()); }