Search in sources :

Example 6 with KeyDataConfig

use of com.quorum.tessera.config.KeyDataConfig in project tessera by ConsenSys.

the class UnsupportedKeyPairValidatorTest method inlineViolationIfPrivateKeyConfigButNoPublicKey.

@Test
public void inlineViolationIfPrivateKeyConfigButNoPublicKey() {
    KeyDataConfig keyDataConfig = mock(KeyDataConfig.class);
    keyPair.setConfig(keyDataConfig);
    validator.isValid(keyPair, context);
    verify(context).buildConstraintViolationWithTemplate("{UnsupportedKeyPair.bothInlineKeysRequired.message}");
}
Also used : KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) Test(org.junit.Test)

Example 7 with KeyDataConfig

use of com.quorum.tessera.config.KeyDataConfig in project tessera by ConsenSys.

the class FilesystemKeyPairTest method getInlineKeypairReturnsKeysReadFromFile.

@Test
public void getInlineKeypairReturnsKeysReadFromFile() throws Exception {
    Path pubFile = Files.createTempFile(UUID.randomUUID().toString(), ".pub");
    Path privFile = Paths.get(getClass().getResource("/unlockedprivatekey.json").toURI());
    String pub = "public";
    Files.write(pubFile, pub.getBytes());
    FilesystemKeyPair filesystemKeyPair = new FilesystemKeyPair(pubFile, privFile, keyEncryptor);
    KeyDataConfig privKeyDataConfig = new KeyDataConfig(new PrivateKeyData("Wl+xSyXVuuqzpvznOS7dOobhcn4C5auxkFRi7yLtgtA=", null, null, null, null), PrivateKeyType.UNLOCKED);
    InlineKeypair expected = new InlineKeypair(pub, privKeyDataConfig, keyEncryptor);
    assertThat(filesystemKeyPair.getInlineKeypair()).isEqualToComparingFieldByFieldRecursively(expected);
    assertThat(filesystemKeyPair.getPublicKey()).isEqualTo(pub);
    assertThat(filesystemKeyPair.getPrivateKey()).isEqualTo("Wl+xSyXVuuqzpvznOS7dOobhcn4C5auxkFRi7yLtgtA=");
}
Also used : Path(java.nio.file.Path) KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 8 with KeyDataConfig

use of com.quorum.tessera.config.KeyDataConfig in project tessera by ConsenSys.

the class InlineKeypairTest method correctPasswordGetsCorrectKey.

@Test
public void correctPasswordGetsCorrectKey() {
    PrivateKeyData privateKeyData = mock(PrivateKeyData.class);
    final KeyDataConfig privKeyDataConfig = mock(KeyDataConfig.class);
    when(privKeyDataConfig.getPrivateKeyData()).thenReturn(privateKeyData);
    when(privKeyDataConfig.getType()).thenReturn(PrivateKeyType.LOCKED);
    char[] validPassword = "testpassword".toCharArray();
    PrivateKey privateKey = mock(PrivateKey.class);
    when(privateKey.encodeToBase64()).thenReturn("SUCCESS");
    when(keyEncryptor.decryptPrivateKey(privateKeyData, validPassword)).thenReturn(privateKey);
    final InlineKeypair result = new InlineKeypair("public", privKeyDataConfig, keyEncryptor);
    result.withPassword(validPassword);
    assertThat(result.getPrivateKey()).isEqualTo("SUCCESS");
}
Also used : KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) PrivateKey(com.quorum.tessera.encryption.PrivateKey) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 9 with KeyDataConfig

use of com.quorum.tessera.config.KeyDataConfig in project tessera by ConsenSys.

the class InlineKeypairTest method nullPasswordGivesNullKey.

@Test
public void nullPasswordGivesNullKey() {
    PrivateKeyData privateKeyData = mock(PrivateKeyData.class);
    final KeyDataConfig privKeyDataConfig = mock(KeyDataConfig.class);
    when(privKeyDataConfig.getPrivateKeyData()).thenReturn(privateKeyData);
    when(privKeyDataConfig.getType()).thenReturn(PrivateKeyType.LOCKED);
    final InlineKeypair result = new InlineKeypair("public", privKeyDataConfig, keyEncryptor);
    result.withPassword(null);
    assertThat(result.getPrivateKey()).isNull();
    verifyZeroInteractions(keyEncryptor);
}
Also used : KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) Test(org.junit.Test)

Example 10 with KeyDataConfig

use of com.quorum.tessera.config.KeyDataConfig in project tessera by ConsenSys.

the class FileKeyGeneratorTest method generateFromKeyDataLockedPrivateKey.

@Test
public void generateFromKeyDataLockedPrivateKey() throws IOException {
    when(passwordReader.requestUserPassword()).thenReturn("PASSWORD".toCharArray());
    final Path tempFolder = Files.createTempDirectory(UUID.randomUUID().toString());
    final String keyFilesName = tempFolder.resolve(UUID.randomUUID().toString()).toString();
    doReturn(keyPair).when(encryptor).generateNewKeys();
    final ArgonOptions argonOptions = new ArgonOptions("id", 1, 1, 1);
    final PrivateKeyData encryptedPrivateKey = new PrivateKeyData(null, null, null, null, argonOptions);
    doReturn(encryptedPrivateKey).when(keyEncryptor).encryptPrivateKey(any(PrivateKey.class), any(), eq(null));
    final PrivateKeyData encryptedKey = new PrivateKeyData(null, "snonce", "salt", "sbox", argonOptions);
    doReturn(encryptedKey).when(keyEncryptor).encryptPrivateKey(any(PrivateKey.class), any(), eq(null));
    final FilesystemKeyPair generated = generator.generate(keyFilesName, null, null);
    final KeyDataConfig pkd = generated.getInlineKeypair().getPrivateKeyConfig();
    assertThat(generated.getPublicKey()).isEqualTo("cHVibGljS2V5");
    assertThat(pkd.getSbox()).isEqualTo("sbox");
    assertThat(pkd.getSnonce()).isEqualTo("snonce");
    assertThat(pkd.getAsalt()).isEqualTo("salt");
    assertThat(pkd.getType()).isEqualTo(PrivateKeyType.LOCKED);
    verify(keyEncryptor).encryptPrivateKey(any(PrivateKey.class), any(), eq(null));
    verify(encryptor).generateNewKeys();
}
Also used : Path(java.nio.file.Path) KeyDataConfig(com.quorum.tessera.config.KeyDataConfig) ArgonOptions(com.quorum.tessera.config.ArgonOptions) PrivateKey(com.quorum.tessera.encryption.PrivateKey) PrivateKeyData(com.quorum.tessera.config.PrivateKeyData) FilesystemKeyPair(com.quorum.tessera.config.keypairs.FilesystemKeyPair) Test(org.junit.Test)

Aggregations

KeyDataConfig (com.quorum.tessera.config.KeyDataConfig)18 Test (org.junit.Test)17 PrivateKeyData (com.quorum.tessera.config.PrivateKeyData)13 Path (java.nio.file.Path)7 KeyData (com.quorum.tessera.config.KeyData)6 KeyEncryptor (com.quorum.tessera.config.keys.KeyEncryptor)3 PrivateKey (com.quorum.tessera.encryption.PrivateKey)3 FilesystemKeyPair (com.quorum.tessera.config.keypairs.FilesystemKeyPair)2 EncryptorException (com.quorum.tessera.encryption.EncryptorException)2 CliResult (com.quorum.tessera.cli.CliResult)1 ArgonOptions (com.quorum.tessera.config.ArgonOptions)1 KeyPair (com.quorum.tessera.encryption.KeyPair)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1