@Test public void ifNoVaultIdProvidedThenSuffixOnlyIsUsed() { azureVaultKeyGenerator.generate(null, null, null); final ArgumentCaptor<AzureSetSecretData> captor = ArgumentCaptor.forClass(AzureSetSecretData.class); verify(keyVaultService, times(2)).setSecret(captor.capture()); List<AzureSetSecretData> capturedArgs = captor.getAllValues(); assertThat(capturedArgs).hasSize(2); AzureSetSecretData expectedDataPub = new AzureSetSecretData("Pub", pub.encodeToBase64()); AzureSetSecretData expectedDataPriv = new AzureSetSecretData("Key", priv.encodeToBase64()); assertThat(capturedArgs) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrder(expectedDataPub, expectedDataPriv); verifyNoMoreInteractions(keyVaultService); }
@Override public AzureVaultKeyPair generate( String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) { final KeyPair keys = this.nacl.generateNewKeys(); final StringBuilder publicId = new StringBuilder(); final StringBuilder privateId = new StringBuilder(); if (filename != null) { final Path path = Paths.get(filename); final String keyVaultId = path.getFileName().toString(); if (!keyVaultId.matches("^[0-9a-zA-Z\\-]*$")) { throw new UnsupportedCharsetException( "Generated key ID for Azure Key Vault can contain only 0-9, a-z, A-Z and - characters"); } publicId.append(keyVaultId); privateId.append(keyVaultId); } publicId.append("Pub"); privateId.append("Key"); saveKeyInVault(publicId.toString(), keys.getPublicKey()); saveKeyInVault(privateId.toString(), keys.getPrivateKey()); return new AzureVaultKeyPair(publicId.toString(), privateId.toString(), null, null); }
AzureVaultKeyGenerator implements KeyGenerator { @Override public AzureVaultKeyPair generate( String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) { final KeyPair keys = this.nacl.generateNewKeys(); final StringBuilder publicId = new StringBuilder(); final StringBuilder privateId = new StringBuilder(); if (filename != null) { final Path path = Paths.get(filename); final String keyVaultId = path.getFileName().toString(); if (!keyVaultId.matches("^[0-9a-zA-Z\\-]*$")) { throw new UnsupportedCharsetException( "Generated key ID for Azure Key Vault can contain only 0-9, a-z, A-Z and - characters"); } publicId.append(keyVaultId); privateId.append(keyVaultId); } publicId.append("Pub"); privateId.append("Key"); saveKeyInVault(publicId.toString(), keys.getPublicKey()); saveKeyInVault(privateId.toString(), keys.getPrivateKey()); return new AzureVaultKeyPair(publicId.toString(), privateId.toString(), null, null); } }
AzureVaultKeyGenerator implements KeyGenerator { @Override public AzureVaultKeyPair generate( String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) { final KeyPair keys = this.nacl.generateNewKeys(); final StringBuilder publicId = new StringBuilder(); final StringBuilder privateId = new StringBuilder(); if (filename != null) { final Path path = Paths.get(filename); final String keyVaultId = path.getFileName().toString(); if (!keyVaultId.matches("^[0-9a-zA-Z\\-]*$")) { throw new UnsupportedCharsetException( "Generated key ID for Azure Key Vault can contain only 0-9, a-z, A-Z and - characters"); } publicId.append(keyVaultId); privateId.append(keyVaultId); } publicId.append("Pub"); privateId.append("Key"); saveKeyInVault(publicId.toString(), keys.getPublicKey()); saveKeyInVault(privateId.toString(), keys.getPrivateKey()); return new AzureVaultKeyPair(publicId.toString(), privateId.toString(), null, null); } AzureVaultKeyGenerator(
            final Encryptor nacl, KeyVaultService<AzureSetSecretData, AzureGetSecretData> keyVaultService); }
AzureVaultKeyGenerator implements KeyGenerator { @Override public AzureVaultKeyPair generate( String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) { final KeyPair keys = this.nacl.generateNewKeys(); final StringBuilder publicId = new StringBuilder(); final StringBuilder privateId = new StringBuilder(); if (filename != null) { final Path path = Paths.get(filename); final String keyVaultId = path.getFileName().toString(); if (!keyVaultId.matches("^[0-9a-zA-Z\\-]*$")) { throw new UnsupportedCharsetException( "Generated key ID for Azure Key Vault can contain only 0-9, a-z, A-Z and - characters"); } publicId.append(keyVaultId); privateId.append(keyVaultId); } publicId.append("Pub"); privateId.append("Key"); saveKeyInVault(publicId.toString(), keys.getPublicKey()); saveKeyInVault(privateId.toString(), keys.getPrivateKey()); return new AzureVaultKeyPair(publicId.toString(), privateId.toString(), null, null); } AzureVaultKeyGenerator(
            final Encryptor nacl, KeyVaultService<AzureSetSecretData, AzureGetSecretData> keyVaultService); @Override AzureVaultKeyPair generate(
            String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions); }
AzureVaultKeyGenerator implements KeyGenerator { @Override public AzureVaultKeyPair generate( String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) { final KeyPair keys = this.nacl.generateNewKeys(); final StringBuilder publicId = new StringBuilder(); final StringBuilder privateId = new StringBuilder(); if (filename != null) { final Path path = Paths.get(filename); final String keyVaultId = path.getFileName().toString(); if (!keyVaultId.matches("^[0-9a-zA-Z\\-]*$")) { throw new UnsupportedCharsetException( "Generated key ID for Azure Key Vault can contain only 0-9, a-z, A-Z and - characters"); } publicId.append(keyVaultId); privateId.append(keyVaultId); } publicId.append("Pub"); privateId.append("Key"); saveKeyInVault(publicId.toString(), keys.getPublicKey()); saveKeyInVault(privateId.toString(), keys.getPrivateKey()); return new AzureVaultKeyPair(publicId.toString(), privateId.toString(), null, null); } AzureVaultKeyGenerator(
            final Encryptor nacl, KeyVaultService<AzureSetSecretData, AzureGetSecretData> keyVaultService); @Override AzureVaultKeyPair generate(
            String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions);  }