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}");
}
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=");
}
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");
}
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);
}
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();
}
Aggregations