Search in sources :

Example 6 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class AzureVaultKeyGenerator method generate.

@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);
}
Also used : Path(java.nio.file.Path) KeyPair(com.quorum.tessera.encryption.KeyPair) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair)

Example 7 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class ValidationTest method azureKeyPairIdsDisallowedCharactersCreateViolation.

@Test
public void azureKeyPairIdsDisallowedCharactersCreateViolation() {
    String keyVaultId = "invalid_@!£$%^~^&_id";
    AzureVaultKeyPair keyPair = new AzureVaultKeyPair(keyVaultId, keyVaultId, null, null);
    Set<ConstraintViolation<AzureVaultKeyPair>> violations = validator.validate(keyPair);
    assertThat(violations).hasSize(2);
    assertThat(violations).extracting("messageTemplate").containsExactly("Azure Key Vault key IDs can only contain alphanumeric characters and dashes (-)", "Azure Key Vault key IDs can only contain alphanumeric characters and dashes (-)");
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Example 8 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class ValidationTest method azureKeyPairKeyVersionMustBe32CharsLong.

@Test
public void azureKeyPairKeyVersionMustBe32CharsLong() {
    String is32Chars = "12345678901234567890123456789012";
    AzureVaultKeyPair keyPair = new AzureVaultKeyPair("id", "id", is32Chars, is32Chars);
    Set<ConstraintViolation<AzureVaultKeyPair>> violations = validator.validate(keyPair);
    assertThat(violations).hasSize(0);
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Example 9 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class ValidationTest method azureKeyPairKeyVersionLongerThan32CharsCreatesViolation.

@Test
public void azureKeyPairKeyVersionLongerThan32CharsCreatesViolation() {
    String is33Chars = "123456789012345678901234567890123";
    AzureVaultKeyPair keyPair = new AzureVaultKeyPair("id", "id", is33Chars, is33Chars);
    Set<ConstraintViolation<AzureVaultKeyPair>> violations = validator.validate(keyPair);
    assertThat(violations).hasSize(2);
    assertThat(violations).extracting("messageTemplate").containsExactly("length must be 32 characters", "length must be 32 characters");
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Example 10 with AzureVaultKeyPair

use of com.quorum.tessera.config.keypairs.AzureVaultKeyPair in project tessera by ConsenSys.

the class ValidationTest method azureKeyPairIdsAllowedCharacterSetIsAlphanumericAndDash.

@Test
public void azureKeyPairIdsAllowedCharacterSetIsAlphanumericAndDash() {
    String keyVaultId = "0123456789-abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    AzureVaultKeyPair keyPair = new AzureVaultKeyPair(keyVaultId, keyVaultId, null, null);
    Set<ConstraintViolation<AzureVaultKeyPair>> violations = validator.validate(keyPair);
    assertThat(violations).hasSize(0);
}
Also used : ConstraintViolation(jakarta.validation.ConstraintViolation) AzureVaultKeyPair(com.quorum.tessera.config.keypairs.AzureVaultKeyPair) Test(org.junit.Test)

Aggregations

AzureVaultKeyPair (com.quorum.tessera.config.keypairs.AzureVaultKeyPair)11 Test (org.junit.Test)9 ConstraintViolation (jakarta.validation.ConstraintViolation)8 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)2 KeyPair (com.quorum.tessera.encryption.KeyPair)2 DefaultKeyVaultConfig (com.quorum.tessera.config.DefaultKeyVaultConfig)1 KeyConfiguration (com.quorum.tessera.config.KeyConfiguration)1 KeyVaultConfig (com.quorum.tessera.config.KeyVaultConfig)1 AWSKeyPair (com.quorum.tessera.config.keypairs.AWSKeyPair)1 HashicorpVaultKeyPair (com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair)1 KeyVaultService (com.quorum.tessera.key.vault.KeyVaultService)1 KeyVaultServiceFactory (com.quorum.tessera.key.vault.KeyVaultServiceFactory)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1