Search in sources :

Example 16 with RegistryConfig

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

the class MacConfigTest method testConfigContents1_1_0.

@Test
public void testConfigContents1_1_0() throws Exception {
    RegistryConfig config = MacConfig.TINK_1_1_0;
    assertEquals(1, config.getEntryCount());
    assertEquals("TINK_MAC_1_1_0", config.getConfigName());
    TestUtil.verifyConfigEntry(config.getEntry(0), "TinkMac", "Mac", "type.googleapis.com/google.crypto.tink.HmacKey", true, 0);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) Test(org.junit.Test)

Example 17 with RegistryConfig

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

the class TinkConfigTest method testConfigContentsVersion1_1_0.

@Test
public void testConfigContentsVersion1_1_0() throws Exception {
    RegistryConfig config = TinkConfig.TINK_1_1_0;
    assertEquals(16, config.getEntryCount());
    assertEquals("TINK_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);
    TestUtil.verifyConfigEntry(config.getEntry(9), "TinkPublicKeySign", "PublicKeySign", "type.googleapis.com/google.crypto.tink.EcdsaPrivateKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(10), "TinkPublicKeySign", "PublicKeySign", "type.googleapis.com/google.crypto.tink.Ed25519PrivateKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(11), "TinkPublicKeyVerify", "PublicKeyVerify", "type.googleapis.com/google.crypto.tink.EcdsaPublicKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(12), "TinkPublicKeyVerify", "PublicKeyVerify", "type.googleapis.com/google.crypto.tink.Ed25519PublicKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(13), "TinkDeterministicAead", "DeterministicAead", "type.googleapis.com/google.crypto.tink.AesSivKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(14), "TinkStreamingAead", "StreamingAead", "type.googleapis.com/google.crypto.tink.AesCtrHmacStreamingKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(15), "TinkStreamingAead", "StreamingAead", "type.googleapis.com/google.crypto.tink.AesGcmHkdfStreamingKey", true, 0);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) Test(org.junit.Test)

Example 18 with RegistryConfig

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

the class TinkConfigTest method aaaTestInitialization.

@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("tinkaead");
        fail("Expected GeneralSecurityException");
    } catch (GeneralSecurityException e) {
        assertThat(e.toString()).contains("no catalogue found");
        assertThat(e.toString()).contains("AeadConfig.init()");
    }
    try {
        Registry.getCatalogue("tinkhybriddecrypt");
        fail("Expected GeneralSecurityException");
    } catch (GeneralSecurityException e) {
        assertThat(e.toString()).contains("no catalogue found");
        assertThat(e.toString()).contains("HybridConfig.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("tinkpublickeysign");
        fail("Expected GeneralSecurityException");
    } catch (GeneralSecurityException e) {
        assertThat(e.toString()).contains("no catalogue found");
        assertThat(e.toString()).contains("SignatureConfig.init()");
    }
    try {
        Registry.getCatalogue("tinkpublickeyverify");
        fail("Expected GeneralSecurityException");
    } catch (GeneralSecurityException e) {
        assertThat(e.toString()).contains("no catalogue found");
        assertThat(e.toString()).contains("SignatureConfig.init()");
    }
    // Get the config proto, now the catalogues should be present,
    // as init()'s were triggered by static block in referenced Config-classes.
    RegistryConfig unused = TinkConfig.TINK_1_1_0;
    Registry.getCatalogue("tinkmac");
    Registry.getCatalogue("tinkaead");
    Registry.getCatalogue("tinkdeterministicaead");
    Registry.getCatalogue("tinkhybridencrypt");
    Registry.getCatalogue("tinkhybriddecrypt");
    Registry.getCatalogue("tinkpublickeysign");
    Registry.getCatalogue("tinkpublickeyverify");
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) GeneralSecurityException(java.security.GeneralSecurityException) Test(org.junit.Test)

Example 19 with RegistryConfig

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

the class StreamingAeadCatalogueTest method testBasic.

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

Example 20 with RegistryConfig

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

the class StreamingAeadConfigTest method testConfigContents.

@Test
public void testConfigContents() throws Exception {
    RegistryConfig config = StreamingAeadConfig.TINK_1_1_0;
    assertEquals(2, config.getEntryCount());
    assertEquals("TINK_STREAMINGAEAD_1_1_0", config.getConfigName());
    TestUtil.verifyConfigEntry(config.getEntry(0), "TinkStreamingAead", "StreamingAead", "type.googleapis.com/google.crypto.tink.AesCtrHmacStreamingKey", true, 0);
    TestUtil.verifyConfigEntry(config.getEntry(1), "TinkStreamingAead", "StreamingAead", "type.googleapis.com/google.crypto.tink.AesGcmHkdfStreamingKey", true, 0);
}
Also used : RegistryConfig(com.google.crypto.tink.proto.RegistryConfig) 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