/** * 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()); } }
/** * 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; } }
private String getKeyPassword() { if (keyStore.getType().equalsIgnoreCase(KeystoreType.PKCS12.toString())) { tlsConfig.setKeyPassword(null); return null; } else { String result = tlsConfig.getKeyPassword(); if (StringUtils.isEmpty(result)) { if (differentKeyAndKeyStorePassword) { result = passwordUtil.generatePassword(); } else { result = getKeyStorePassword(); } tlsConfig.setKeyPassword(result); } return result; } }
/** * 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; }
"key store of type '" + keyStore.getType() + "' provider '" + keyStore.getProvider() + "': " + getKeyStore().getLocation());
"trust store of type '" + trustStore.getType() + "' provider '" + trustStore.getProvider() + "': " + getTrustStore().getLocation());
private String getKey(String inputKey) { if ("PKCS12".equals(keyStore.getType())) { // workaround for https://bugs.openjdk.java.net/browse/JDK-8079616: return inputKey.toLowerCase(Locale.ROOT); } return inputKey; }
/** * Get KeyStore's type. * * @return KeyStore's type */ public KeyStoreType getType() { return KeyStoreType.resolveJce(keyStore.getType()); }
@Nonnull public static KeyStore getSimiliarKeyStore (@Nonnull final KeyStore aOther) throws KeyStoreException { return KeyStore.getInstance (aOther.getType (), aOther.getProvider ()); }
@Override public String toString() { try { return ks.getType() + " contains alias " + keyAlias + ": " + ks.containsAlias(keyAlias); } catch(KeyStoreException kse) { return "Unable to get keystore information: " + kse; } } }
/** * 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()); } }
/** * 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()); } }
private void createLastModifiedNode(DefaultMutableTreeNode parentNode, String alias) throws CryptoException { try { KeyStore keyStore = currentState.getKeyStore(); if (KeyStoreType.resolveJce(keyStore.getType()) != KeyStoreType.PKCS12) { String lastModified = MessageFormat.format(res.getString("DProperties.properties.LastModified"), StringUtils.formatDate(keyStore.getCreationDate(alias))); parentNode.add(new DefaultMutableTreeNode(lastModified)); } } catch (ProviderException e) { // some keystore types do not provide creation dates for their entries => simply create no node } catch (KeyStoreException e) { throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), e); } }
public void saveKeyStore(KeyStore keystore, CallbackHandler storePassHandler, ObjectHandle handle) throws NoSuchAlgorithmException, CertificateException, UnknownContainerException{ try { String storeType = keystore.getType(); byte[] bs = KeyStoreService.toByteArray(keystore, handle.getName(), storePassHandler); KeystoreData keystoreData = KeystoreData.newBuilder().setType(storeType).setKeystore(ByteString.copyFrom(bs)).build(); blobStoreConnection.putBlob(handle, keystoreData.toByteArray()); } catch (IOException e) { throw new IllegalStateException(e); } }
public void saveKeyStoreWithAttributes(KeyStore keystore, Map<String, String> attributes, CallbackHandler storePassHandler, ObjectHandle handle) throws NoSuchAlgorithmException, CertificateException, UnknownContainerException{ try { String storeType = keystore.getType(); byte[] bs = KeyStoreService.toByteArray(keystore, handle.getName(), storePassHandler); KeystoreData keystoreData = KeystoreData.newBuilder() .setType(storeType) .setKeystore(ByteString.copyFrom(bs)) .putAllAttributes(attributes) .build(); blobStoreConnection.putBlob(handle, keystoreData.toByteArray()); } catch (IOException e) { throw new IllegalStateException(e); } }
@Override public void saveKeyStore(KeyStore keystore, CallbackHandler storePassHandler, ObjectHandle handle) { String storeType = keystore.getType(); byte[] bs = KeyStoreService.toByteArray(keystore, handle.getName(), storePassHandler); BucketPath bucketPath = BucketPath.fromHandle(handle); Payload payload = new SimplePayloadImpl(bs); payload.getStorageMetadata().getUserMetadata().put(KEYSTORE_TYPE_KEY, storeType); extendedStoreConnection.putBlob(bucketPath, payload); }
@Override public void saveKeyStoreWithAttributes(KeyStore keystore, UserMetaData userMetaData, CallbackHandler storePassHandler, ObjectHandle handle) { String storeType = keystore.getType(); byte[] bs = KeyStoreService.toByteArray(keystore, handle.getName(), storePassHandler); BucketPath bucketPath = BucketPath.fromHandle(handle); SimpleStorageMetadataImpl simpleStorageMetadataImpl = new SimpleStorageMetadataImpl(); simpleStorageMetadataImpl.getUserMetadata().put(KEYSTORE_TYPE_KEY, storeType); simpleStorageMetadataImpl.addUserMetadata(userMetaData); SimplePayloadImpl payload = new SimplePayloadImpl(simpleStorageMetadataImpl, bs); extendedStoreConnection.putBlob(bucketPath, payload); }
public void mapIntoEntity(StsKeyStore keyStore, KeyStoreEntity persistentKeyStore) { byte[] bytes = KeyStoreService.toByteArray(keyStore.getKeyStore(), keystoreName, keyPassHandler); persistentKeyStore.setName(keystoreName); persistentKeyStore.setKeystore(bytes); persistentKeyStore.setType(keyStore.getKeyStore().getType()); persistentKeyStore.setLastUpdate(convert(keyStore.getLastUpdate())); Map<String, KeyEntryAttributesEntity> mappedEntryAttributes = mapToEntityMap(keyStore.getKeyEntries()); persistentKeyStore.setEntries(mappedEntryAttributes); }