Search in sources :

Example 1 with RegistryConfig

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

the class HybridConfigTest method aaaTestInitialization.

// This test must run first.
@Test
public void aaaTestInitialization() throws Exception {
    try {
        Registry.getCatalogue("tinkmac");
        fail("Expected GeneralSecurityException");
    } catch (GeneralSecurityException e) {
        assertThat(e.toString()).contains("no catalogue found");
        assertThat(e.toString()).contains("MacConfig.init()");
    }
    try {
        Registry.getCatalogue("tinkhybridencrypt");
        fail("Expected GeneralSecurityException");
    } catch (GeneralSecurityException e) {
        assertThat(e.toString()).contains("no catalogue found");
        assertThat(e.toString()).contains("HybridConfig.init()");
    }
    try {
        Registry.getCatalogue("tinkhybriddecrypt");
        fail("Expected GeneralSecurityException");
    } catch (GeneralSecurityException e) {
        assertThat(e.toString()).contains("no catalogue found");
        assertThat(e.toString()).contains("HybridConfig.init()");
    }
    // Get the config proto, now the catalogues should be present,
    // as init() was triggered by a static block.
    RegistryConfig unused = HybridConfig.TINK_1_1_0;
    Registry.getCatalogue("tinkmac");
    Registry.getCatalogue("tinkhybriddecrypt");
    Registry.getCatalogue("tinkhybridencrypt");
    // Running init() manually again should succeed.
    HybridConfig.init();
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) GeneralSecurityException(java.security.GeneralSecurityException) Test(org.junit.Test)

Example 2 with RegistryConfig

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

the class HybridConfigTest method testConfigContents1_0_0.

@Test
public void testConfigContents1_0_0() throws Exception {
    RegistryConfig config = HybridConfig.TINK_1_0_0;
    assertEquals(9, config.getEntryCount());
    assertEquals("TINK_HYBRID_1_0_0", config.getConfigName());
    TestUtil.verifyConfigEntry(config.getEntry(0), "TinkMac", "Mac", "type.googleapis.com/google.crypto.tink.HmacKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(1), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(2), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesEaxKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(3), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesGcmKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(4), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.ChaCha20Poly1305Key", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(5), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.KmsAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(6), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.KmsEnvelopeAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(7), "TinkHybridDecrypt", "HybridDecrypt", "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(8), "TinkHybridEncrypt", "HybridEncrypt", "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPublicKey", true, 0);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) Test(org.junit.Test)

Example 3 with RegistryConfig

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

the class HybridConfigTest method testConfigContents1_1_0.

@Test
public void testConfigContents1_1_0() throws Exception {
    RegistryConfig config = HybridConfig.TINK_1_1_0;
    assertEquals(9, config.getEntryCount());
    assertEquals("TINK_HYBRID_1_1_0", config.getConfigName());
    TestUtil.verifyConfigEntry(config.getEntry(0), "TinkMac", "Mac", "type.googleapis.com/google.crypto.tink.HmacKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(1), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(2), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesEaxKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(3), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.AesGcmKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(4), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.ChaCha20Poly1305Key", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(5), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.KmsAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(6), "TinkAead", "Aead", "type.googleapis.com/google.crypto.tink.KmsEnvelopeAeadKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(7), "TinkHybridDecrypt", "HybridDecrypt", "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(8), "TinkHybridEncrypt", "HybridEncrypt", "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPublicKey", true, 0);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) Test(org.junit.Test)

Example 4 with RegistryConfig

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

the class HybridDecryptCatalogueTest method testBasic.

@Test
public void testBasic() throws Exception {
    HybridDecryptCatalogue catalogue = new HybridDecryptCatalogue();
    // Check a single key type for decryption, incl. case-insensitve primitive name.
    String keyType = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey";
    {
        KeyManager<HybridDecrypt> manager = catalogue.getKeyManager(keyType, "HybridDecrypt", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    {
        KeyManager<HybridDecrypt> manager = catalogue.getKeyManager(keyType, "HyBRidDeCRYPt", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    {
        KeyManager<HybridDecrypt> manager = catalogue.getKeyManager(keyType, "HYBRIDDecRYPT", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    // Check all entries from the current HybridConfig.
    RegistryConfig config = HybridConfig.TINK_1_0_0;
    int count = 0;
    for (KeyTypeEntry entry : config.getEntryList()) {
        if ("HybridDecrypt".equals(entry.getPrimitiveName())) {
            count = count + 1;
            KeyManager<HybridDecrypt> manager = catalogue.getKeyManager(entry.getTypeUrl(), "hybriddecrypt", entry.getKeyManagerVersion());
            assertThat(manager.doesSupport(entry.getTypeUrl())).isTrue();
        }
    }
    assertEquals(1, count);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) HybridDecrypt(com.google.crypto.tink.HybridDecrypt) KeyTypeEntry(com.google.crypto.tink.proto.KeyTypeEntry) KeyManager(com.google.crypto.tink.KeyManager) Test(org.junit.Test)

Example 5 with RegistryConfig

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

the class HybridEncryptCatalogueTest method testBasic.

@Test
public void testBasic() throws Exception {
    HybridEncryptCatalogue catalogue = new HybridEncryptCatalogue();
    // Check a single key type for encryption, incl. case-insensitve primitive name.
    String keyType = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPublicKey";
    {
        KeyManager<HybridEncrypt> manager = catalogue.getKeyManager(keyType, "HybridEncrypt", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    {
        KeyManager<HybridEncrypt> manager = catalogue.getKeyManager(keyType, "HybRIdEncRYPt", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    {
        KeyManager<HybridEncrypt> manager = catalogue.getKeyManager(keyType, "HYBRIdeNCRYPT", 0);
        assertThat(manager.doesSupport(keyType)).isTrue();
    }
    // Check all entries from the current HybridConfig.
    RegistryConfig config = HybridConfig.TINK_1_0_0;
    int count = 0;
    for (KeyTypeEntry entry : config.getEntryList()) {
        if ("HybridEncrypt".equals(entry.getPrimitiveName())) {
            count = count + 1;
            KeyManager<HybridEncrypt> manager = catalogue.getKeyManager(entry.getTypeUrl(), "hybridencrypt", entry.getKeyManagerVersion());
            assertThat(manager.doesSupport(entry.getTypeUrl())).isTrue();
        }
    }
    assertEquals(1, count);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) KeyTypeEntry(com.google.crypto.tink.proto.KeyTypeEntry) KeyManager(com.google.crypto.tink.KeyManager) HybridEncrypt(com.google.crypto.tink.HybridEncrypt) Test(org.junit.Test)

Aggregations

RegistryConfig (com.google.crypto.tink.proto.RegistryConfig)27 Test (org.junit.Test)27 KeyManager (com.google.crypto.tink.KeyManager)8 KeyTypeEntry (com.google.crypto.tink.proto.KeyTypeEntry)8 GeneralSecurityException (java.security.GeneralSecurityException)7 Aead (com.google.crypto.tink.Aead)1 DeterministicAead (com.google.crypto.tink.DeterministicAead)1 HybridDecrypt (com.google.crypto.tink.HybridDecrypt)1 HybridEncrypt (com.google.crypto.tink.HybridEncrypt)1 Mac (com.google.crypto.tink.Mac)1 PublicKeySign (com.google.crypto.tink.PublicKeySign)1 PublicKeyVerify (com.google.crypto.tink.PublicKeyVerify)1 StreamingAead (com.google.crypto.tink.StreamingAead)1