Search in sources :

Example 1 with KeysetInfo

use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.

the class UtilTest method testGetKeysetInfo.

/**
 * Tests that getKeysetInfo doesn't contain key material.
 */
@Test
public void testGetKeysetInfo() throws Exception {
    String keyValue = "01234567890123456";
    Keyset keyset = TestUtil.createKeyset(TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes("UTF-8"), 16), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK));
    assertTrue(keyset.toString().contains(keyValue));
    KeysetInfo keysetInfo = Util.getKeysetInfo(keyset);
    assertFalse(keysetInfo.toString().contains(keyValue));
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) KeysetInfo(com.google.crypto.tink.proto.KeysetInfo) Test(org.junit.Test)

Example 2 with KeysetInfo

use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.

the class CreateKeysetCommandTest method testCreateEncrypted_shouldCreateNewKeyset.

private void testCreateEncrypted_shouldCreateNewKeyset(String outFormat) throws Exception {
    // Create an encrypted keyset.
    String masterKeyUri = TestUtil.RESTRICTED_CRYPTO_KEY_URI;
    String credentialPath = TestUtil.SERVICE_ACCOUNT_FILE;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    CreateKeysetCommand.create(outputStream, outFormat, masterKeyUri, credentialPath, KEY_TEMPLATE);
    EncryptedKeyset encryptedKeyset = TinkeyUtil.createKeysetReader(new ByteArrayInputStream(outputStream.toByteArray()), outFormat).readEncrypted();
    KeysetInfo keysetInfo = encryptedKeyset.getKeysetInfo();
    assertThat(keysetInfo.getKeyInfoCount()).isEqualTo(1);
    TestUtil.assertKeyInfo(KEY_TEMPLATE, keysetInfo.getKeyInfo(0));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) EncryptedKeyset(com.google.crypto.tink.proto.EncryptedKeyset) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeysetInfo(com.google.crypto.tink.proto.KeysetInfo)

Example 3 with KeysetInfo

use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.

the class AddKeyCommandTest method testAddEncrypted_shouldAddNewKey.

@Test
public void testAddEncrypted_shouldAddNewKey() throws Exception {
    // Create an input stream containing an encrypted keyset.
    String masterKeyUri = TestUtil.RESTRICTED_CRYPTO_KEY_URI;
    String credentialPath = TestUtil.SERVICE_ACCOUNT_FILE;
    InputStream inputStream = TinkeyUtil.createKeyset(EXISTING_TEMPLATE, INPUT_FORMAT, masterKeyUri, credentialPath);
    EncryptedKeyset encryptedKeyset = addNewKeyToKeyset(OUTPUT_FORMAT, inputStream, INPUT_FORMAT, masterKeyUri, credentialPath, NEW_TEMPLATE).readEncrypted();
    KeysetInfo keysetInfo = encryptedKeyset.getKeysetInfo();
    assertThat(keysetInfo.getKeyInfoCount()).isEqualTo(2);
    assertThat(keysetInfo.getPrimaryKeyId()).isEqualTo(keysetInfo.getKeyInfo(0).getKeyId());
    TestUtil.assertKeyInfo(EXISTING_TEMPLATE, keysetInfo.getKeyInfo(0));
    TestUtil.assertKeyInfo(NEW_TEMPLATE, keysetInfo.getKeyInfo(0));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EncryptedKeyset(com.google.crypto.tink.proto.EncryptedKeyset) KeysetInfo(com.google.crypto.tink.proto.KeysetInfo) Test(org.junit.Test)

Example 4 with KeysetInfo

use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.

the class ListKeysetCommand method list.

/**
 * Lists all keys in the keyset in {@code inputStream} (using {@code credentialPath} to
 * decrypt if it is encrypted). This command doesn't output actual key material.
 */
public static void list(InputStream inputStream, String inFormat, String masterKeyUri, String credentialPath) throws Exception {
    KeysetHandle handle = TinkeyUtil.getKeysetHandle(inputStream, inFormat, masterKeyUri, credentialPath);
    KeysetInfo keysetInfo = handle.getKeysetInfo();
    System.out.println(keysetInfo.toString());
}
Also used : KeysetHandle(com.google.crypto.tink.KeysetHandle) KeysetInfo(com.google.crypto.tink.proto.KeysetInfo)

Example 5 with KeysetInfo

use of com.google.crypto.tink.proto.KeysetInfo in project tink by google.

the class RotateKeysetCommandTest method testRotateEncrypted_shouldAddNewKey.

@Test
public void testRotateEncrypted_shouldAddNewKey() throws Exception {
    // Create an input stream containing an encrypted keyset.
    String masterKeyUri = TestUtil.RESTRICTED_CRYPTO_KEY_URI;
    String credentialPath = TestUtil.SERVICE_ACCOUNT_FILE;
    InputStream inputStream = TinkeyUtil.createKeyset(EXISTING_TEMPLATE, INPUT_FORMAT, masterKeyUri, credentialPath);
    EncryptedKeyset encryptedKeyset = addNewKeyToKeyset(OUTPUT_FORMAT, inputStream, INPUT_FORMAT, masterKeyUri, credentialPath, NEW_TEMPLATE).readEncrypted();
    KeysetInfo keysetInfo = encryptedKeyset.getKeysetInfo();
    assertThat(keysetInfo.getKeyInfoCount()).isEqualTo(2);
    assertThat(keysetInfo.getPrimaryKeyId()).isEqualTo(keysetInfo.getKeyInfo(1).getKeyId());
    TestUtil.assertKeyInfo(EXISTING_TEMPLATE, keysetInfo.getKeyInfo(0));
    TestUtil.assertKeyInfo(NEW_TEMPLATE, keysetInfo.getKeyInfo(0));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EncryptedKeyset(com.google.crypto.tink.proto.EncryptedKeyset) KeysetInfo(com.google.crypto.tink.proto.KeysetInfo) Test(org.junit.Test)

Aggregations

KeysetInfo (com.google.crypto.tink.proto.KeysetInfo)5 EncryptedKeyset (com.google.crypto.tink.proto.EncryptedKeyset)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 KeysetHandle (com.google.crypto.tink.KeysetHandle)1 Keyset (com.google.crypto.tink.proto.Keyset)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1