Search in sources :

Example 16 with Keyset

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

the class CompareKeysetsTest method testCompareKeysets_twoKeys_equal.

@Test
public void testCompareKeysets_twoKeys_equal() throws Exception {
    Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    Keyset keyset2 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    CompareKeysets.compareKeysets(keyset1, keyset2);
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Test(org.junit.Test)

Example 17 with Keyset

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

the class CompareKeysetsTest method testCompareKeysets_twoKeysDifferentPrimary_throws.

@Test
public void testCompareKeysets_twoKeysDifferentPrimary_throws() throws Exception {
    Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    Keyset keyset2 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).addKey(aesGcmKey(KEY_1, 18, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(18).build();
    try {
        CompareKeysets.compareKeysets(keyset1, keyset2);
        fail();
    } catch (Exception e) {
    // expected.
    }
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Test(org.junit.Test)

Example 18 with Keyset

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

the class CompareKeysetsTest method testCompareKeysets_singleKeyDifferentKeyMaterial_throws.

@Test
public void testCompareKeysets_singleKeyDifferentKeyMaterial_throws() throws Exception {
    Keyset keyset1 = Keyset.newBuilder().addKey(aesGcmKey(KEY_0, 17, KeyStatusType.ENABLED, OutputPrefixType.TINK)).setPrimaryKeyId(17).build();
    Keyset.Key key = keyset1.getKey(0);
    Keyset keyset2 = Keyset.newBuilder().addKey(Keyset.Key.newBuilder(key).setKeyData(KeyData.newBuilder(key.getKeyData()).setKeyMaterialType(KeyMaterialType.UNKNOWN_KEYMATERIAL))).setPrimaryKeyId(17).build();
    try {
        CompareKeysets.compareKeysets(keyset1, keyset2);
        fail();
    } catch (Exception e) {
    // expected.
    }
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) Test(org.junit.Test)

Example 19 with Keyset

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

the class RotateKeysetCommandTest method testRotateCleartext_shouldAddNewKey.

@Test
public void testRotateCleartext_shouldAddNewKey() throws Exception {
    // Create an input stream containing a cleartext keyset.
    String masterKeyUri = null;
    String credentialPath = null;
    InputStream inputStream = TinkeyUtil.createKeyset(existingTemplate, INPUT_FORMAT, masterKeyUri, credentialPath);
    // Add a new key to the existing keyset.
    Keyset keyset = addNewKeyToKeyset(OUTPUT_FORMAT, inputStream, INPUT_FORMAT, masterKeyUri, credentialPath, newTemplate).read();
    assertThat(keyset.getKeyCount()).isEqualTo(2);
    assertThat(keyset.getPrimaryKeyId()).isEqualTo(keyset.getKey(1).getKeyId());
    TestUtil.assertHmacKey(existingTemplate, keyset.getKey(0));
    TestUtil.assertHmacKey(newTemplate, keyset.getKey(1));
}
Also used : EncryptedKeyset(com.google.crypto.tink.proto.EncryptedKeyset) Keyset(com.google.crypto.tink.proto.Keyset) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 20 with Keyset

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

the class AddKeyCommandTest method testAddCleartext_shouldAddNewKey.

@Test
public void testAddCleartext_shouldAddNewKey() throws Exception {
    // Create an input stream containing a cleartext keyset.
    String masterKeyUri = null;
    String credentialPath = null;
    InputStream inputStream = TinkeyUtil.createKeyset(existingTemplate, INPUT_FORMAT, masterKeyUri, credentialPath);
    // Add a new key to the existing keyset.
    Keyset keyset = addNewKeyToKeyset(OUTPUT_FORMAT, inputStream, INPUT_FORMAT, masterKeyUri, credentialPath, newTemplate).read();
    assertThat(keyset.getKeyCount()).isEqualTo(2);
    assertThat(keyset.getPrimaryKeyId()).isEqualTo(keyset.getKey(0).getKeyId());
    TestUtil.assertHmacKey(existingTemplate, keyset.getKey(0));
    TestUtil.assertHmacKey(newTemplate, keyset.getKey(1));
}
Also used : EncryptedKeyset(com.google.crypto.tink.proto.EncryptedKeyset) Keyset(com.google.crypto.tink.proto.Keyset) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

Keyset (com.google.crypto.tink.proto.Keyset)108 Test (org.junit.Test)81 GeneralSecurityException (java.security.GeneralSecurityException)22 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)17 KeysetHandle (com.google.crypto.tink.KeysetHandle)17 KeyData (com.google.crypto.tink.proto.KeyData)17 KeyTemplate (com.google.crypto.tink.KeyTemplate)12 EncryptedKeyset (com.google.crypto.tink.proto.EncryptedKeyset)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ByteString (com.google.protobuf.ByteString)10 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)10 Key (com.google.crypto.tink.proto.Keyset.Key)9 JsonObject (com.google.gson.JsonObject)9 AesGcmKey (com.google.crypto.tink.proto.AesGcmKey)8 KeysetReader (com.google.crypto.tink.KeysetReader)7 IOException (java.io.IOException)7 AesEaxKey (com.google.crypto.tink.proto.AesEaxKey)6 AesGcmKeyFormat (com.google.crypto.tink.proto.AesGcmKeyFormat)6 Enums (com.google.crypto.tink.subtle.Enums)6 KeyHandle (com.google.crypto.tink.tinkkey.KeyHandle)6