Search in sources :

Example 6 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class HashicorpVaultKeyGeneratorTest method setUp.

@Before
public void setUp() {
    this.encryptor = mock(Encryptor.class);
    this.keyVaultService = mock(KeyVaultService.class);
    final KeyPair keyPair = new KeyPair(pub, priv);
    when(encryptor.generateNewKeys()).thenReturn(keyPair);
    this.hashicorpVaultKeyGenerator = new HashicorpVaultKeyGenerator(encryptor, keyVaultService);
}
Also used : KeyVaultService(com.quorum.tessera.key.vault.KeyVaultService) KeyPair(com.quorum.tessera.encryption.KeyPair) HashicorpVaultKeyPair(com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair) Encryptor(com.quorum.tessera.encryption.Encryptor) Before(org.junit.Before)

Example 7 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class EllipticalCurveEncryptorTest method generateNewKeys.

@Test
public void generateNewKeys() throws Exception {
    KeyPair keyPair = encryptor.generateNewKeys();
    assertThat(keyPair).isNotNull();
    assertThat(keyPair.getPublicKey()).isNotNull();
    assertThat(keyPair.getPrivateKey()).isNotNull();
    LOGGER.info("Public key size: {}", keyPair.getPublicKey().getKeyBytes().length);
    LOGGER.info("Private key size: {}", keyPair.getPrivateKey().getKeyBytes().length);
    String b64encodedPrivateKey = Base64.getEncoder().encodeToString(keyPair.getPrivateKey().getKeyBytes());
    LOGGER.info("base64 encoded private key: {}", b64encodedPrivateKey);
    LOGGER.info("base64 encoded private key length: {}", b64encodedPrivateKey.length());
    String b64encodedPublicKey = Base64.getEncoder().encodeToString(keyPair.getPublicKey().getKeyBytes());
    LOGGER.info("base64 encoded public key: {}", b64encodedPublicKey);
    LOGGER.info("base64 encoded public key length: {}", b64encodedPublicKey.length());
}
Also used : KeyPair(com.quorum.tessera.encryption.KeyPair) Test(org.junit.Test)

Example 8 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class EllipticalCurveEncryptorTest method computeSharedKey.

@Test
public void computeSharedKey() {
    KeyPair keyPair1 = encryptor.generateNewKeys();
    KeyPair keyPair2 = encryptor.generateNewKeys();
    SharedKey sharedPub1Priv2 = encryptor.computeSharedKey(keyPair1.getPublicKey(), keyPair2.getPrivateKey());
    SharedKey sharedPriv1Pub2 = encryptor.computeSharedKey(keyPair2.getPublicKey(), keyPair1.getPrivateKey());
    assertEquals(sharedPub1Priv2, sharedPriv1Pub2);
    LOGGER.info("SharedKey: {}", sharedPriv1Pub2.encodeToBase64());
}
Also used : KeyPair(com.quorum.tessera.encryption.KeyPair) SharedKey(com.quorum.tessera.encryption.SharedKey) Test(org.junit.Test)

Example 9 with KeyPair

use of com.quorum.tessera.encryption.KeyPair in project tessera by ConsenSys.

the class AWSSecretManagerKeyGenerator method generate.

@Override
public AWSKeyPair generate(String filename, ArgonOptions encryptionOptions, KeyVaultOptions keyVaultOptions) {
    final KeyPair keys = this.encryptor.generateNewKeys();
    final StringBuilder publicId = new StringBuilder();
    final StringBuilder privateId = new StringBuilder();
    if (filename != null) {
        final Path path = Paths.get(filename);
        final String secretId = path.getFileName().toString();
        if (!secretId.matches("^[0-9a-zA-Z\\-/_+=.@]*$")) {
            throw new UnsupportedCharsetException("Generated key ID for AWS Secret Manager can contain only 0-9, a-z, A-Z and /_+=.@- characters");
        }
        publicId.append(secretId);
        privateId.append(secretId);
    }
    publicId.append("Pub");
    privateId.append("Key");
    saveKeyInSecretManager(publicId.toString(), keys.getPublicKey());
    saveKeyInSecretManager(privateId.toString(), keys.getPrivateKey());
    return new AWSKeyPair(publicId.toString(), privateId.toString());
}
Also used : Path(java.nio.file.Path) KeyPair(com.quorum.tessera.encryption.KeyPair) AWSKeyPair(com.quorum.tessera.config.keypairs.AWSKeyPair) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) AWSKeyPair(com.quorum.tessera.config.keypairs.AWSKeyPair)

Example 10 with KeyPair

use of com.quorum.tessera.encryption.KeyPair 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)

Aggregations

KeyPair (com.quorum.tessera.encryption.KeyPair)21 Test (org.junit.Test)11 KeyVaultService (com.quorum.tessera.key.vault.KeyVaultService)7 Encryptor (com.quorum.tessera.encryption.Encryptor)5 KeyVaultServiceFactory (com.quorum.tessera.key.vault.KeyVaultServiceFactory)4 Before (org.junit.Before)4 Config (com.quorum.tessera.config.Config)3 AWSKeyPair (com.quorum.tessera.config.keypairs.AWSKeyPair)3 AzureVaultKeyPair (com.quorum.tessera.config.keypairs.AzureVaultKeyPair)3 HashicorpVaultKeyPair (com.quorum.tessera.config.keypairs.HashicorpVaultKeyPair)3 EnvironmentVariableProvider (com.quorum.tessera.config.util.EnvironmentVariableProvider)3 Path (java.nio.file.Path)3 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)2 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)2 KeyData (com.quorum.tessera.config.KeyData)1 KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)1 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)1 ConfigKeyPair (com.quorum.tessera.config.keypairs.ConfigKeyPair)1 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)1 SharedKey (com.quorum.tessera.encryption.SharedKey)1