@Test(expected = LoginFailureException.class) public void testCreateUserAuthenticationFailure() throws Exception { final S3Session session = new S3Session( new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials( "key", "secret" ))); session.setSignatureVersion(S3Protocol.AuthenticationHeaderSignatureVersion.AWS4HMACSHA256); session.open(Proxy.DIRECT, new DisabledHostKeyCallback(), new DisabledLoginCallback()); session.login(Proxy.DIRECT, new DisabledLoginCallback(), new DisabledCancelCallback()); new KMSEncryptionFeature(session, new DisabledX509TrustManager(), new DefaultX509KeyManager()).getKeys(new Path("test-eu-west-1-cyberduck", EnumSet.of(Path.Type.volume)), new DisabledLoginCallback()); session.close(); }
@Override public Set<Algorithm> getKeys(final Path file, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); final Set<Algorithm> keys = super.getKeys(container, prompt); if(container.isRoot()) { return keys; } try { keys.addAll(this.authenticated(new Authenticated<Set<Algorithm>>() { @Override public Set<Algorithm> call() throws BackgroundException { final AWSKMS client = client(container); try { final Map<String, String> aliases = new HashMap<String, String>(); for(AliasListEntry entry : client.listAliases().getAliases()) { aliases.put(entry.getTargetKeyId(), entry.getAliasName()); } final Set<Algorithm> keys = new HashSet<Algorithm>(); for(KeyListEntry entry : client.listKeys().getKeys()) { keys.add(new AliasedAlgorithm(entry, aliases.get(entry.getKeyId()))); } return keys; } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read AWS KMS configuration", e); } finally { client.shutdown(); } } }, prompt)); } catch(AccessDeniedException e) { log.warn(String.format("Ignore failure reading keys from KMS. %s", e.getMessage())); keys.add(SSE_KMS_DEFAULT); } return keys; }
KMSEncryptionFeature extends S3EncryptionFeature { @Override public Set<Algorithm> getKeys(final Path file, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); final Set<Algorithm> keys = super.getKeys(container, prompt); if(container.isRoot()) { return keys; } try { keys.addAll(this.authenticated(new Authenticated<Set<Algorithm>>() { @Override public Set<Algorithm> call() throws BackgroundException { final AWSKMS client = client(container); try { final Map<String, String> aliases = new HashMap<String, String>(); for(AliasListEntry entry : client.listAliases().getAliases()) { aliases.put(entry.getTargetKeyId(), entry.getAliasName()); } final Set<Algorithm> keys = new HashSet<Algorithm>(); for(KeyListEntry entry : client.listKeys().getKeys()) { keys.add(new AliasedAlgorithm(entry, aliases.get(entry.getKeyId()))); } return keys; } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read AWS KMS configuration", e); } finally { client.shutdown(); } } }, prompt)); } catch(AccessDeniedException e) { log.warn(String.format("Ignore failure reading keys from KMS. %s", e.getMessage())); keys.add(SSE_KMS_DEFAULT); } return keys; } }
KMSEncryptionFeature extends S3EncryptionFeature { @Override public Set<Algorithm> getKeys(final Path file, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); final Set<Algorithm> keys = super.getKeys(container, prompt); if(container.isRoot()) { return keys; } try { keys.addAll(this.authenticated(new Authenticated<Set<Algorithm>>() { @Override public Set<Algorithm> call() throws BackgroundException { final AWSKMS client = client(container); try { final Map<String, String> aliases = new HashMap<String, String>(); for(AliasListEntry entry : client.listAliases().getAliases()) { aliases.put(entry.getTargetKeyId(), entry.getAliasName()); } final Set<Algorithm> keys = new HashSet<Algorithm>(); for(KeyListEntry entry : client.listKeys().getKeys()) { keys.add(new AliasedAlgorithm(entry, aliases.get(entry.getKeyId()))); } return keys; } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read AWS KMS configuration", e); } finally { client.shutdown(); } } }, prompt)); } catch(AccessDeniedException e) { log.warn(String.format("Ignore failure reading keys from KMS. %s", e.getMessage())); keys.add(SSE_KMS_DEFAULT); } return keys; } KMSEncryptionFeature(final S3Session session, final X509TrustManager trust, final X509KeyManager key); }
KMSEncryptionFeature extends S3EncryptionFeature { @Override public Set<Algorithm> getKeys(final Path file, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); final Set<Algorithm> keys = super.getKeys(container, prompt); if(container.isRoot()) { return keys; } try { keys.addAll(this.authenticated(new Authenticated<Set<Algorithm>>() { @Override public Set<Algorithm> call() throws BackgroundException { final AWSKMS client = client(container); try { final Map<String, String> aliases = new HashMap<String, String>(); for(AliasListEntry entry : client.listAliases().getAliases()) { aliases.put(entry.getTargetKeyId(), entry.getAliasName()); } final Set<Algorithm> keys = new HashSet<Algorithm>(); for(KeyListEntry entry : client.listKeys().getKeys()) { keys.add(new AliasedAlgorithm(entry, aliases.get(entry.getKeyId()))); } return keys; } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read AWS KMS configuration", e); } finally { client.shutdown(); } } }, prompt)); } catch(AccessDeniedException e) { log.warn(String.format("Ignore failure reading keys from KMS. %s", e.getMessage())); keys.add(SSE_KMS_DEFAULT); } return keys; } KMSEncryptionFeature(final S3Session session, final X509TrustManager trust, final X509KeyManager key); @Override Algorithm getDefault(final Path file); @Override Algorithm getEncryption(final Path file); @Override Set<Algorithm> getKeys(final Path file, final LoginCallback prompt); }
KMSEncryptionFeature extends S3EncryptionFeature { @Override public Set<Algorithm> getKeys(final Path file, final LoginCallback prompt) throws BackgroundException { final Path container = containerService.getContainer(file); final Set<Algorithm> keys = super.getKeys(container, prompt); if(container.isRoot()) { return keys; } try { keys.addAll(this.authenticated(new Authenticated<Set<Algorithm>>() { @Override public Set<Algorithm> call() throws BackgroundException { final AWSKMS client = client(container); try { final Map<String, String> aliases = new HashMap<String, String>(); for(AliasListEntry entry : client.listAliases().getAliases()) { aliases.put(entry.getTargetKeyId(), entry.getAliasName()); } final Set<Algorithm> keys = new HashSet<Algorithm>(); for(KeyListEntry entry : client.listKeys().getKeys()) { keys.add(new AliasedAlgorithm(entry, aliases.get(entry.getKeyId()))); } return keys; } catch(AmazonClientException e) { throw new AmazonServiceExceptionMappingService().map("Cannot read AWS KMS configuration", e); } finally { client.shutdown(); } } }, prompt)); } catch(AccessDeniedException e) { log.warn(String.format("Ignore failure reading keys from KMS. %s", e.getMessage())); keys.add(SSE_KMS_DEFAULT); } return keys; } KMSEncryptionFeature(final S3Session session, final X509TrustManager trust, final X509KeyManager key); @Override Algorithm getDefault(final Path file); @Override Algorithm getEncryption(final Path file); @Override Set<Algorithm> getKeys(final Path file, final LoginCallback prompt); static final Algorithm SSE_KMS_DEFAULT; }