diff --git a/README.md b/README.md index f012b4b1049a40010871bbb88eef645d2a8ccd4b..339280b28fa16151d760c93b9b132e79098bf4db 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,9 @@ runtime with Tink, so that Tink "knows" the desired implementations. Here's how you can register all implementations of all primitives in Tink for Java 1.1.0: ```java - import com.google.crypto.tink.Config; import com.google.crypto.tink.config.TinkConfig; - Config.register(TinkConfig.TINK_1_1_0); + TinkConfig.register(); ``` After implementations of primitives have been registered, the basic use of Tink diff --git a/docs/JAVA-HOWTO.md b/docs/JAVA-HOWTO.md index 9390bd41205c7784b22fcf69d03107f412b64968..172594c7d0cff2863c8553f6804c186c6f45bc72 100644 --- a/docs/JAVA-HOWTO.md +++ b/docs/JAVA-HOWTO.md @@ -109,19 +109,17 @@ For example, if you want to use all implementations of all primitives in Tink 1.0.0, the initialization would look as follows: ```java - import com.google.crypto.tink.Config; import com.google.crypto.tink.config.TinkConfig; - Config.register(TinkConfig.TINK_1_1_0); + TinkConfig.register(); ``` To use only implementations of the AEAD primitive: ```java - import com.google.crypto.tink.Config; import com.google.crypto.tink.aead.AeadConfig; - Config.register(AeadConfig.TINK_1_1_0); + AeadConfig.register(); ``` For custom initialization the registration proceeds directly via diff --git a/examples/helloworld/java/src/main/java/com/helloworld/HelloWorld.java b/examples/helloworld/java/src/main/java/com/helloworld/HelloWorld.java index b706e048178953ad11c9c81ef106320660679ee9..72c5a35e2061eb75f3d53e2bc56bcb525a2366a7 100644 --- a/examples/helloworld/java/src/main/java/com/helloworld/HelloWorld.java +++ b/examples/helloworld/java/src/main/java/com/helloworld/HelloWorld.java @@ -14,7 +14,6 @@ package com.helloworld; -import com.google.crypto.tink.Config; import com.google.crypto.tink.aead.AeadConfig; import java.security.GeneralSecurityException; import org.kohsuke.args4j.CmdLineException; @@ -28,7 +27,7 @@ import org.kohsuke.args4j.CmdLineParser; public final class HelloWorld { public static void main(String[] args) throws Exception { // Register all AEAD key types with the Tink runtime. - Config.register(AeadConfig.TINK_1_0_0); + AeadConfig.register(); Commands commands = new Commands(); CmdLineParser parser = new CmdLineParser(commands); diff --git a/java/src/main/java/com/google/crypto/tink/Config.java b/java/src/main/java/com/google/crypto/tink/Config.java index 2b469447759ed11fb50b6d9ba57fb41fab9f30ad..6696c98b4feb30abbde039441e87af5641791ad8 100644 --- a/java/src/main/java/com/google/crypto/tink/Config.java +++ b/java/src/main/java/com/google/crypto/tink/Config.java @@ -33,7 +33,7 @@ import java.security.GeneralSecurityException; * <h3>Usage</h3> * * <pre>{@code - * RegistryConfig registryConfig = ...; // AeadConfig.TINK_1_1_0 + * RegistryConfig registryConfig = ...; * Config.register(registryConfig); * }</pre> * diff --git a/java/src/main/java/com/google/crypto/tink/Registry.java b/java/src/main/java/com/google/crypto/tink/Registry.java index 16970ab6501abbbe44fffa511f05f1e12e83ffb2..c147d5b5e4b3029e4cef8871d8fb244fb2afea2a 100644 --- a/java/src/main/java/com/google/crypto/tink/Registry.java +++ b/java/src/main/java/com/google/crypto/tink/Registry.java @@ -46,13 +46,13 @@ import java.util.logging.Logger; * <p>To initialize the Registry with all key managers in Tink 1.0.0, one can do as follows: * * <pre>{@code - * Config.register(TinkConfig.TINK_1_0_0); + * TinkConfig.register(); * }</pre> * * <p>Here's how to register only {@link Aead} key managers: * * <pre>{@code - * Config.register(AeadConfig.TINK_1_0_0); + * AeadConfig.register(); * }</pre> * * <p>After the Registry has been initialized, one can use {@link @@ -84,7 +84,7 @@ public final class Registry { * Resets the registry. * * <p>After reset the registry is empty, i.e. it contains no key managers. Thus one might need to - * call {@code XyzConfig.init()} to re-install the catalogues. + * call {@code XyzConfig.register()} to re-install the catalogues. * * <p>This method is intended for testing. */ @@ -140,22 +140,22 @@ public final class Registry { if (catalogue == null) { String error = String.format("no catalogue found for %s. ", catalogueName); if (catalogueName.toLowerCase().startsWith("tinkaead")) { - error += "Maybe call AeadConfig.init()."; + error += "Maybe call AeadConfig.register()."; } if (catalogueName.toLowerCase().startsWith("tinkdeterministicaead")) { - error += "Maybe call DeterministicAeadConfig.init()."; + error += "Maybe call DeterministicAeadConfig.register()."; } else if (catalogueName.toLowerCase().startsWith("tinkstreamingaead")) { - error += "Maybe call StreamingAeadConfig.init()."; + error += "Maybe call StreamingAeadConfig.register()."; } else if (catalogueName.toLowerCase().startsWith("tinkhybriddecrypt") || catalogueName.toLowerCase().startsWith("tinkhybridencrypt")) { - error += "Maybe call HybridConfig.init()."; + error += "Maybe call HybridConfig.register()."; } else if (catalogueName.toLowerCase().startsWith("tinkmac")) { - error += "Maybe call MacConfig.init()."; + error += "Maybe call MacConfig.register()."; } else if (catalogueName.toLowerCase().startsWith("tinkpublickeysign") || catalogueName.toLowerCase().startsWith("tinkpublickeyverify")) { - error += "Maybe call SignatureConfig.init()."; + error += "Maybe call SignatureConfig.register()."; } else if (catalogueName.toLowerCase().startsWith("tink")) { - error += "Maybe call TinkConfig.init()."; + error += "Maybe call TinkConfig.register()."; } throw new GeneralSecurityException(error); } diff --git a/java/src/main/java/com/google/crypto/tink/aead/AeadConfig.java b/java/src/main/java/com/google/crypto/tink/aead/AeadConfig.java index ba4f0cf9120a311277612521c6103c8e5cf8c7e2..07c90bb99c028df542be9cee11f705950b09aee8 100644 --- a/java/src/main/java/com/google/crypto/tink/aead/AeadConfig.java +++ b/java/src/main/java/com/google/crypto/tink/aead/AeadConfig.java @@ -26,10 +26,10 @@ import java.security.GeneralSecurityException; * Static methods and constants for registering with the {@link Registry} all instances of {@link * com.google.crypto.tink.Aead} key types supported in a particular release of Tink. * - * <p>To register all Aead key types provided in Tink release 1.1.0 one can do: + * <p>To register all Aead key types provided in the latest Tink version one can do: * * <pre>{@code - * Config.register(AeadConfig.TINK_1_1_0); + * AeadConfig.register(); * }</pre> * * <p>For more information on how to obtain and use instances of Aead, see {@link AeadFactory}. @@ -47,27 +47,58 @@ public final class AeadConfig { private static final String CATALOGUE_NAME = "TinkAead"; private static final String PRIMITIVE_NAME = "Aead"; - public static final RegistryConfig TINK_1_0_0 = RegistryConfig.newBuilder() - .mergeFrom(MacConfig.TINK_1_0_0) - .addEntry(Config.getTinkKeyTypeEntry( - CATALOGUE_NAME, PRIMITIVE_NAME, "AesCtrHmacAeadKey", 0, true)) - .addEntry(Config.getTinkKeyTypeEntry( - CATALOGUE_NAME, PRIMITIVE_NAME, "AesEaxKey", 0, true)) - .addEntry(Config.getTinkKeyTypeEntry( - CATALOGUE_NAME, PRIMITIVE_NAME, "AesGcmKey", 0, true)) - .addEntry(Config.getTinkKeyTypeEntry( - CATALOGUE_NAME, PRIMITIVE_NAME, "ChaCha20Poly1305Key", 0, true)) - .addEntry(Config.getTinkKeyTypeEntry( - CATALOGUE_NAME, PRIMITIVE_NAME, "KmsAeadKey", 0, true)) - .addEntry(Config.getTinkKeyTypeEntry( - CATALOGUE_NAME, PRIMITIVE_NAME, "KmsEnvelopeAeadKey", 0, true)) - .setConfigName("TINK_AEAD_1_0_0") - .build(); + /** @deprecated */ + @Deprecated + public static final RegistryConfig TINK_1_0_0 = + RegistryConfig.newBuilder() + .mergeFrom(MacConfig.TINK_1_0_0) + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "AesCtrHmacAeadKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry(CATALOGUE_NAME, PRIMITIVE_NAME, "AesEaxKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry(CATALOGUE_NAME, PRIMITIVE_NAME, "AesGcmKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "ChaCha20Poly1305Key", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry(CATALOGUE_NAME, PRIMITIVE_NAME, "KmsAeadKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "KmsEnvelopeAeadKey", 0, true)) + .setConfigName("TINK_AEAD_1_0_0") + .build(); - /** @since 1.1.0 */ + /** + * @deprecated + * @since 1.1.0 + */ + @Deprecated public static final RegistryConfig TINK_1_1_0 = RegistryConfig.newBuilder().mergeFrom(TINK_1_0_0).setConfigName("TINK_AEAD_1_1_0").build(); + public static final RegistryConfig LATEST = + RegistryConfig.newBuilder() + .mergeFrom(MacConfig.LATEST) + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "AesCtrHmacAeadKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry(CATALOGUE_NAME, PRIMITIVE_NAME, "AesEaxKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry(CATALOGUE_NAME, PRIMITIVE_NAME, "AesGcmKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "ChaCha20Poly1305Key", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry(CATALOGUE_NAME, PRIMITIVE_NAME, "KmsAeadKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "KmsEnvelopeAeadKey", 0, true)) + .setConfigName("TINK_AEAD") + .build(); + static { try { init(); @@ -77,28 +108,46 @@ public final class AeadConfig { } /** - * Tries to register with the {@link Registry} all instances of - * {@link com.google.crypto.tink.Catalogue} needed to handle Aead key types supported in Tink. + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} and {@link com.google.crypto.tink.KeyManager} needed to + * handle Aead key types supported in Tink. * * <p>Because Aead key types depend on {@link com.google.crypto.tink.Mac} key types, this method - * also registers all Mac catalogues. + * also registers all Mac catalogues and key managers. + * + * @deprecated use {@link #register} */ + @Deprecated public static void init() throws GeneralSecurityException { + register(); + } + + /** + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} and {@link com.google.crypto.tink.KeyManager} needed to + * handle Aead key types supported in Tink. + * + * <p>Because Aead key types depend on {@link com.google.crypto.tink.Mac} key types, this method + * also registers all Mac catalogues and key managers. + */ + public static void register() throws GeneralSecurityException { + // The order of these calls matters. + MacConfig.register(); Registry.addCatalogue(CATALOGUE_NAME, new AeadCatalogue()); - MacConfig.init(); + Config.register(LATEST); } /** - * Registers with the {@code Registry} all Aead key types released with the latest version - * of Tink. + * Registers with the {@code Registry} all Aead key types released with the latest version of + * Tink. * * <p>Deprecated-yet-still-supported key types are registered in so-called "no new key"-mode, * which allows for usage of existing keys forbids generation of new key material. * - * @deprecated use {@link Config#register} + * @deprecated use {@link #register} */ @Deprecated public static void registerStandardKeyTypes() throws GeneralSecurityException { - Config.register(TINK_1_1_0); + register(); } } diff --git a/java/src/main/java/com/google/crypto/tink/config/TinkConfig.java b/java/src/main/java/com/google/crypto/tink/config/TinkConfig.java index 7b98301368faa071d98c16df4b48219619b7f137..c55935c27c1e786e140c93edf2bc1fe2d2833455 100644 --- a/java/src/main/java/com/google/crypto/tink/config/TinkConfig.java +++ b/java/src/main/java/com/google/crypto/tink/config/TinkConfig.java @@ -27,15 +27,17 @@ import java.security.GeneralSecurityException; * Static methods and constants for registering with the {@link com.google.crypto.tink.Registry} all * instances of all key types supported in a particular release of Tink. * - * <p>To register all key types provided in Tink release 1.1.0 one can do: + * <p>To register all key types provided in the latest Tink version one can do: * * <pre>{@code - * Config.register(TinkConfig.TINK_1_1_0); + * TinkConfig.register(); * }</pre> * * @since 1.0.0 */ public final class TinkConfig { + /** @deprecated */ + @Deprecated public static final RegistryConfig TINK_1_0_0 = RegistryConfig.newBuilder() .mergeFrom( @@ -44,7 +46,11 @@ public final class TinkConfig { .setConfigName("TINK_1_0_0") .build(); - /** @since 1.1.0 */ + /** + * @deprecated + * @since 1.1.0 + */ + @Deprecated public static final RegistryConfig TINK_1_1_0 = RegistryConfig.newBuilder() .mergeFrom( @@ -55,13 +61,35 @@ public final class TinkConfig { .setConfigName("TINK_1_1_0") .build(); + public static final RegistryConfig LATEST = + RegistryConfig.newBuilder() + .mergeFrom(HybridConfig.LATEST) // include AeadConfig.TINK_1_0_0 and MacConfig.TINK_1_0_0 + .mergeFrom(SignatureConfig.LATEST) + .mergeFrom(DeterministicAeadConfig.LATEST) + .mergeFrom(StreamingAeadConfig.LATEST) + .setConfigName("TINK") + .build(); + /** - * Tries to register with the {@link com.google.crypto.tink.Registry} all instances of {@link - * com.google.crypto.tink.Catalogue} needed to handle all key types supported in Tink. + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} and {@link com.google.crypto.tink.KeyManager} needed to + * handle all key types supported in Tink. + * + * @deprecated use {@link #register} */ + @Deprecated public static void init() throws GeneralSecurityException { - DeterministicAeadConfig.init(); - HybridConfig.init(); // includes Aead and Mac - SignatureConfig.init(); + register(); + } + + /** + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} and {@link com.google.crypto.tink.KeyManager} needed to + * handle all key types supported in Tink. + */ + public static void register() throws GeneralSecurityException { + DeterministicAeadConfig.register(); + HybridConfig.register(); // includes Aead and Mac + SignatureConfig.register(); } } diff --git a/java/src/main/java/com/google/crypto/tink/daead/DeterministicAeadConfig.java b/java/src/main/java/com/google/crypto/tink/daead/DeterministicAeadConfig.java index ee2ac3affd6713014d702f08e5a2bff08a8f5a4e..0625446557fa76505161406e9d63c4f27093fc76 100644 --- a/java/src/main/java/com/google/crypto/tink/daead/DeterministicAeadConfig.java +++ b/java/src/main/java/com/google/crypto/tink/daead/DeterministicAeadConfig.java @@ -25,10 +25,10 @@ import java.security.GeneralSecurityException; * Static methods and constants for registering with the {@link Registry} all instances of {@link * com.google.crypto.tink.DeterministicAead} key types supported in a particular release of Tink. * - * <p>To register all DeterministicAead key types provided in Tink release 1.1.0 one can do: + * <p>To register all DeterministicAead key types provided in the latest Tink version one can do: * * <pre>{@code - * Config.register(DeterministicAeadConfig.TINK_1_1_0); + * DeterministicAeadConfig.register(); * }</pre> * * <p>For more information on how to obtain and use instances of DeterministicAead, see {@link @@ -42,6 +42,8 @@ public final class DeterministicAeadConfig { private static final String CATALOGUE_NAME = "TinkDeterministicAead"; private static final String PRIMITIVE_NAME = "DeterministicAead"; + /** @deprecated */ + @Deprecated public static final RegistryConfig TINK_1_1_0 = RegistryConfig.newBuilder() .addEntry( @@ -49,6 +51,13 @@ public final class DeterministicAeadConfig { .setConfigName("TINK_DETERMINISTIC_AEAD_1_1_0") .build(); + public static final RegistryConfig LATEST = + RegistryConfig.newBuilder() + .addEntry( + Config.getTinkKeyTypeEntry(CATALOGUE_NAME, PRIMITIVE_NAME, "AesSivKey", 0, true)) + .setConfigName("TINK_DETERMINISTIC_AEAD") + .build(); + static { try { init(); @@ -64,8 +73,24 @@ public final class DeterministicAeadConfig { * * <p>Because DeterministicAead key types depend on {@link com.google.crypto.tink.Mac} key types, * this method also registers all Mac catalogues. + * + * @deprecated use {@link #register} */ + @Deprecated public static void init() throws GeneralSecurityException { + register(); + } + + /** + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} needed to handle DeterministicAead key types supported in + * Tink. + * + * <p>Because DeterministicAead key types depend on {@link com.google.crypto.tink.Mac} key types, + * this method also registers all Mac catalogues. + */ + public static void register() throws GeneralSecurityException { Registry.addCatalogue(CATALOGUE_NAME, new DeterministicAeadCatalogue()); + Config.register(LATEST); } } diff --git a/java/src/main/java/com/google/crypto/tink/hybrid/HybridConfig.java b/java/src/main/java/com/google/crypto/tink/hybrid/HybridConfig.java index c88c301aad0f5dcdf846ece55805a7836bed7d65..a78703133b38c05f292c4ad921db600e5792238e 100644 --- a/java/src/main/java/com/google/crypto/tink/hybrid/HybridConfig.java +++ b/java/src/main/java/com/google/crypto/tink/hybrid/HybridConfig.java @@ -27,11 +27,11 @@ import java.security.GeneralSecurityException; * com.google.crypto.tink.HybridEncrypt} and {@link com.google.crypto.tink.HybridDecrypt} key types * supported in a particular release of Tink. * - * <p>To register all HybridEncrypt and HybridDecrypt key types provided in Tink release 1.0.0 one - * can do: + * <p>To register all HybridEncrypt and HybridDecrypt key types provided in the latest Tink version + * one can do: * * <pre>{@code - * Config.register(HybridConfig.TINK_1_1_0); + * HybridConfig.register(); * }</pre> * * <p>For more information on how to obtain and use instances of HybridEncrypt or HybridDecrypt, see @@ -47,6 +47,8 @@ public final class HybridConfig { private static final String HYBRID_ENCRYPT_CATALOGUE_NAME = "TinkHybridEncrypt"; private static final String HYBRID_DECRYPT_CATALOGUE_NAME = "TinkHybridDecrypt"; + /** @deprecated */ + @Deprecated public static final RegistryConfig TINK_1_0_0 = RegistryConfig.newBuilder() .mergeFrom(AeadConfig.TINK_1_0_0) @@ -67,10 +69,34 @@ public final class HybridConfig { .setConfigName("TINK_HYBRID_1_0_0") .build(); - /** @since 1.1.0 */ + /** + * @deprecated + * @since 1.1.0 + */ + @Deprecated public static final RegistryConfig TINK_1_1_0 = RegistryConfig.newBuilder().mergeFrom(TINK_1_0_0).setConfigName("TINK_HYBRID_1_1_0").build(); + public static final RegistryConfig LATEST = + RegistryConfig.newBuilder() + .mergeFrom(AeadConfig.LATEST) + .addEntry( + Config.getTinkKeyTypeEntry( + HYBRID_DECRYPT_CATALOGUE_NAME, + "HybridDecrypt", + "EciesAeadHkdfPrivateKey", + 0, + true)) + .addEntry( + Config.getTinkKeyTypeEntry( + HYBRID_ENCRYPT_CATALOGUE_NAME, + "HybridEncrypt", + "EciesAeadHkdfPublicKey", + 0, + true)) + .setConfigName("TINK_HYBRID") + .build(); + static { try { init(); @@ -87,10 +113,28 @@ public final class HybridConfig { * <p>Because HybridDecrypt and HybridEncrypt key types depend on {@link * com.google.crypto.tink.Aead} and {@link com.google.crypto.tink.Mac} key types, this method also * registers all Aead and Mac catalogues. + * + * @deprecated use {@link #register} */ + @Deprecated public static void init() throws GeneralSecurityException { + register(); + } + + /** + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} needed to handle HybridDecrypt and HybridEncrypt key types + * supported in Tink. + * + * <p>Because HybridDecrypt and HybridEncrypt key types depend on {@link + * com.google.crypto.tink.Aead} and {@link com.google.crypto.tink.Mac} key types, this method also + * registers all Aead and Mac catalogues. + */ + public static void register() throws GeneralSecurityException { + // The order of these calls matters. + AeadConfig.register(); // includes Mac Registry.addCatalogue(HYBRID_ENCRYPT_CATALOGUE_NAME, new HybridEncryptCatalogue()); Registry.addCatalogue(HYBRID_DECRYPT_CATALOGUE_NAME, new HybridDecryptCatalogue()); - AeadConfig.init(); // includes Mac + Config.register(LATEST); } } diff --git a/java/src/main/java/com/google/crypto/tink/mac/MacConfig.java b/java/src/main/java/com/google/crypto/tink/mac/MacConfig.java index 599a158bf3effdc8f36b0b51acf6f0c97ce4d2f6..753e3dc8138ebbe9ea923b13be63df610ef2bd4b 100644 --- a/java/src/main/java/com/google/crypto/tink/mac/MacConfig.java +++ b/java/src/main/java/com/google/crypto/tink/mac/MacConfig.java @@ -25,10 +25,10 @@ import java.security.GeneralSecurityException; * Static methods and constants for registering with the {@link Registry} all instances of {@link * com.google.crypto.tink.Mac} key types supported in a particular release of Tink. * - * <p>To register all Mac key types provided in Tink release 1.1.0 one can do: + * <p>To register all Mac key types provided in the latest Tink version one can do: * * <pre>{@code - * Config.register(MacConfig.TINK_1_1_0); + * MacConfig.register(); * }</pre> * * <p>For more information on how to obtain and use instances of Mac, see {@link MacFactory}. @@ -41,16 +41,25 @@ public final class MacConfig { private static final String CATALOGUE_NAME = "TinkMac"; private static final String PRIMITIVE_NAME = "Mac"; + /** @deprecated */ + @Deprecated public static final RegistryConfig TINK_1_0_0 = RegistryConfig.newBuilder() .setConfigName("TINK_MAC_1_0_0") .addEntry(Config.getTinkKeyTypeEntry(CATALOGUE_NAME, PRIMITIVE_NAME, "HmacKey", 0, true)) .build(); - /** @since 1.1.0 */ + /** + * @deprecated + * @since 1.1.0 + */ + @Deprecated public static final RegistryConfig TINK_1_1_0 = RegistryConfig.newBuilder().mergeFrom(TINK_1_0_0).setConfigName("TINK_MAC_1_1_0").build(); + public static final RegistryConfig LATEST = + RegistryConfig.newBuilder().mergeFrom(TINK_1_0_0).setConfigName("TINK_MAC").build(); + static { try { init(); @@ -61,10 +70,24 @@ public final class MacConfig { /** * Tries to register with the {@link Registry} all instances of {@link - * com.google.crypto.tink.Catalogue} needed to handle Mac key types supported in Tink. + * com.google.crypto.tink.Catalogue} and {@link com.google.crypto.tink.KeyManager} needed to + * handle Mac key types supported in Tink. + * + * @deprecated use {@link #register} */ + @Deprecated public static void init() throws GeneralSecurityException { + register(); + } + + /** + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} and {@link com.google.crypto.tink.KeyManager} needed to + * handle Mac key types supported in Tink. + */ + public static void register() throws GeneralSecurityException { Registry.addCatalogue(CATALOGUE_NAME, new MacCatalogue()); + Config.register(LATEST); } /** @@ -73,10 +96,10 @@ public final class MacConfig { * <p>Deprecated-yet-still-supported key types are registered in so-called "no new key"-mode, * which allows for usage of existing keys forbids generation of new key material. * - * @deprecated use {@link Config#register} + * @deprecated use {@link #register} */ @Deprecated public static void registerStandardKeyTypes() throws GeneralSecurityException { - Config.register(TINK_1_1_0); + register(); } } diff --git a/java/src/main/java/com/google/crypto/tink/signature/SignatureConfig.java b/java/src/main/java/com/google/crypto/tink/signature/SignatureConfig.java index 038a07fb84379f881026f4fb661b53e9650350e6..57ed01ed0092e8043c6e0896f73c55771f603c07 100644 --- a/java/src/main/java/com/google/crypto/tink/signature/SignatureConfig.java +++ b/java/src/main/java/com/google/crypto/tink/signature/SignatureConfig.java @@ -26,11 +26,11 @@ import java.security.GeneralSecurityException; * com.google.crypto.tink.PublicKeySign} and {@link com.google.crypto.tink.PublicKeyVerify} key * types supported in a particular release of Tink. * - * <p>To register all PublicKeySign and PublicKeyVerify key types provided in Tink release 1.1.0 one - * can do: + * <p>To register all PublicKeySign and PublicKeyVerify key types provided in the latest Tink + * version one can do: * * <pre>{@code - * Config.register(HybridConfig.TINK_1_1_0); + * SignatureConfig.init(); * }</pre> * * <p>For more information on how to obtain and use instances of PublicKeySign or PublicKeyVerify, @@ -46,6 +46,8 @@ public final class SignatureConfig { private static final String PUBLIC_KEY_SIGN_CATALOGUE_NAME = "TinkPublicKeySign"; private static final String PUBLIC_KEY_VERIFY_CATALOGUE_NAME = "TinkPublicKeyVerify"; + /** @deprecated */ + @Deprecated public static final RegistryConfig TINK_1_0_0 = RegistryConfig.newBuilder() .setConfigName("TINK_SIGNATURE_1_0_0") @@ -63,13 +65,34 @@ public final class SignatureConfig { PUBLIC_KEY_VERIFY_CATALOGUE_NAME, "PublicKeyVerify", "Ed25519PublicKey", 0, true)) .build(); - /** @since 1.1.0 */ + /** + * @deprecated + * @since 1.1.0 + */ + @Deprecated public static final RegistryConfig TINK_1_1_0 = RegistryConfig.newBuilder() .mergeFrom(TINK_1_0_0) .setConfigName("TINK_SIGNATURE_1_1_0") .build(); + public static final RegistryConfig LATEST = + RegistryConfig.newBuilder() + .setConfigName("TINK_SIGNATURE") + .addEntry( + Config.getTinkKeyTypeEntry( + PUBLIC_KEY_SIGN_CATALOGUE_NAME, "PublicKeySign", "EcdsaPrivateKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + PUBLIC_KEY_SIGN_CATALOGUE_NAME, "PublicKeySign", "Ed25519PrivateKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + PUBLIC_KEY_VERIFY_CATALOGUE_NAME, "PublicKeyVerify", "EcdsaPublicKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + PUBLIC_KEY_VERIFY_CATALOGUE_NAME, "PublicKeyVerify", "Ed25519PublicKey", 0, true)) + .build(); + static { try { init(); @@ -82,9 +105,22 @@ public final class SignatureConfig { * Tries to register with the {@link Registry} all instances of {@link * com.google.crypto.tink.Catalogue} needed to handle PublicKeySign and PublicKeyVerify key types * supported in Tink. + * + * @deprecated use {@link #register} */ + @Deprecated public static void init() throws GeneralSecurityException { + register(); + } + + /** + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} needed to handle PublicKeySign and PublicKeyVerify key types + * supported in Tink. + */ + public static void register() throws GeneralSecurityException { Registry.addCatalogue(PUBLIC_KEY_SIGN_CATALOGUE_NAME, new PublicKeySignCatalogue()); Registry.addCatalogue(PUBLIC_KEY_VERIFY_CATALOGUE_NAME, new PublicKeyVerifyCatalogue()); + Config.register(LATEST); } } diff --git a/java/src/main/java/com/google/crypto/tink/streamingaead/StreamingAeadConfig.java b/java/src/main/java/com/google/crypto/tink/streamingaead/StreamingAeadConfig.java index 09e4bb87b19229d4a91fafbcf2e6c957dd48dfd0..8f24c3e8e15997383638ab3ce9b9b0737f8a5681 100644 --- a/java/src/main/java/com/google/crypto/tink/streamingaead/StreamingAeadConfig.java +++ b/java/src/main/java/com/google/crypto/tink/streamingaead/StreamingAeadConfig.java @@ -25,10 +25,10 @@ import java.security.GeneralSecurityException; * Static methods and constants for registering with the {@link Registry} all instances of {@link * com.google.crypto.tink.StreamingAead} key types supported in a particular release of Tink. * - * <p>To register all StreamingAead key types provided in Tink release 1.1.0 one can do: + * <p>To register all StreamingAead key types provided in the latest Tink version one can do: * * <pre>{@code - * Config.register(StreamingAeadConfig.TINK_1_1_0); + * StreamingAeadConfig.init(); * }</pre> * * <p>For more information on how to obtain and use instances of StreamingAead, see {@link @@ -45,13 +45,29 @@ public final class StreamingAeadConfig { private static final String CATALOGUE_NAME = "TinkStreamingAead"; private static final String PRIMITIVE_NAME = "StreamingAead"; - public static final RegistryConfig TINK_1_1_0 = RegistryConfig.newBuilder() - .addEntry(Config.getTinkKeyTypeEntry( - CATALOGUE_NAME, PRIMITIVE_NAME, "AesCtrHmacStreamingKey", 0, true)) - .addEntry(Config.getTinkKeyTypeEntry( - CATALOGUE_NAME, PRIMITIVE_NAME, "AesGcmHkdfStreamingKey", 0, true)) - .setConfigName("TINK_STREAMINGAEAD_1_1_0") - .build(); + /** @deprecated */ + @Deprecated + public static final RegistryConfig TINK_1_1_0 = + RegistryConfig.newBuilder() + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "AesCtrHmacStreamingKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "AesGcmHkdfStreamingKey", 0, true)) + .setConfigName("TINK_STREAMINGAEAD_1_1_0") + .build(); + + public static final RegistryConfig LATEST = + RegistryConfig.newBuilder() + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "AesCtrHmacStreamingKey", 0, true)) + .addEntry( + Config.getTinkKeyTypeEntry( + CATALOGUE_NAME, PRIMITIVE_NAME, "AesGcmHkdfStreamingKey", 0, true)) + .setConfigName("TINK_STREAMINGAEAD") + .build(); static { try { @@ -62,11 +78,22 @@ public final class StreamingAeadConfig { } /** - * Tries to register with the {@link Registry} all instances of - * {@link com.google.crypto.tink.Catalogue} needed to handle StreamingAead key types - * supported in Tink. + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} needed to handle StreamingAead key types supported in Tink. + * + * @deprecated use {@link #register} */ + @Deprecated public static void init() throws GeneralSecurityException { + register(); + } + + /** + * Tries to register with the {@link Registry} all instances of {@link + * com.google.crypto.tink.Catalogue} needed to handle StreamingAead key types supported in Tink. + */ + public static void register() throws GeneralSecurityException { Registry.addCatalogue(CATALOGUE_NAME, new StreamingAeadCatalogue()); + Config.register(LATEST); } } diff --git a/java/src/test/java/com/google/crypto/tink/CleartextKeysetHandleTest.java b/java/src/test/java/com/google/crypto/tink/CleartextKeysetHandleTest.java index 40c19ffc6fff72585e46134d5d4d8af99a698aaf..2634775db92b2ae430eb3d4d8313bb90f595057b 100644 --- a/java/src/test/java/com/google/crypto/tink/CleartextKeysetHandleTest.java +++ b/java/src/test/java/com/google/crypto/tink/CleartextKeysetHandleTest.java @@ -39,7 +39,7 @@ import org.junit.runners.JUnit4; public class CleartextKeysetHandleTest { @BeforeClass public static void setUp() throws GeneralSecurityException { - Config.register(TinkConfig.TINK_1_0_0); + TinkConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/KeysetManagerTest.java b/java/src/test/java/com/google/crypto/tink/KeysetManagerTest.java index f85dda8972eb525ea4e912770da8e821f94e3a10..59a4cbc91bacf129c7c2f4ae4a2d4a798aa55179 100644 --- a/java/src/test/java/com/google/crypto/tink/KeysetManagerTest.java +++ b/java/src/test/java/com/google/crypto/tink/KeysetManagerTest.java @@ -38,7 +38,7 @@ import org.junit.runners.JUnit4; public class KeysetManagerTest { @BeforeClass public static void setUp() throws GeneralSecurityException { - Config.register(TinkConfig.TINK_1_0_0); + TinkConfig.register(); } private Key createEnabledKey(int keyId) { diff --git a/java/src/test/java/com/google/crypto/tink/NoSecretKeysetHandleTest.java b/java/src/test/java/com/google/crypto/tink/NoSecretKeysetHandleTest.java index 7a192cd9dbb2eb775a6fc75e879417d1a909eed7..2cd3d4f0f2bfd5857a4f9bdc7a9a484420e22d80 100644 --- a/java/src/test/java/com/google/crypto/tink/NoSecretKeysetHandleTest.java +++ b/java/src/test/java/com/google/crypto/tink/NoSecretKeysetHandleTest.java @@ -34,7 +34,7 @@ import org.junit.runners.JUnit4; public class NoSecretKeysetHandleTest { @BeforeClass public static void setUp() throws GeneralSecurityException { - Config.register(TinkConfig.TINK_1_0_0); + TinkConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/aead/AeadConfigTest.java b/java/src/test/java/com/google/crypto/tink/aead/AeadConfigTest.java index 99b251945d95630d90768aff1ab31ddf3fe3ffdf..e102f046460aa8249c23c08f639225b155bdba39 100644 --- a/java/src/test/java/com/google/crypto/tink/aead/AeadConfigTest.java +++ b/java/src/test/java/com/google/crypto/tink/aead/AeadConfigTest.java @@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.Registry; import com.google.crypto.tink.TestUtil; import com.google.crypto.tink.proto.RegistryConfig; @@ -47,23 +46,37 @@ public class AeadConfigTest { fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("MacConfig.init()"); + assertThat(e.toString()).contains("MacConfig.register()"); } try { Registry.getCatalogue("tinkaead"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("AeadConfig.init()"); + assertThat(e.toString()).contains("AeadConfig.register()"); } - // Get the config proto, now the catalogues should be present, - // as init() was triggered by a static block. - RegistryConfig unused = AeadConfig.TINK_1_1_0; + + // Before registration, key manager should be absent. + String typeUrl = "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey"; + try { + Registry.getKeyManager(typeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + + // Initialize the config. + AeadConfig.register(); + + // Now the catalogues should be present. Registry.getCatalogue("tinkmac"); Registry.getCatalogue("tinkaead"); + // After registration the key manager should be present. + Registry.getKeyManager(typeUrl); + // Running init() manually again should succeed. - AeadConfig.init(); + AeadConfig.register(); } @Test @@ -181,16 +194,59 @@ public class AeadConfigTest { } @Test - public void testRegistration() throws Exception { - String typeUrl = "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey"; - try { - Registry.getKeyManager(typeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - // After registration the key manager should be present. - Config.register(AeadConfig.TINK_1_1_0); - Registry.getKeyManager(typeUrl); + public void testConfigContents_LATEST() throws Exception { + RegistryConfig config = AeadConfig.LATEST; + assertEquals(7, config.getEntryCount()); + assertEquals("TINK_AEAD", 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); } } diff --git a/java/src/test/java/com/google/crypto/tink/aead/AeadFactoryTest.java b/java/src/test/java/com/google/crypto/tink/aead/AeadFactoryTest.java index 5ffdaf20060fa4ca33a7b6b543e44094c2c92cdc..97ec67afc2619fa4b7beecab173feb9784873e76 100644 --- a/java/src/test/java/com/google/crypto/tink/aead/AeadFactoryTest.java +++ b/java/src/test/java/com/google/crypto/tink/aead/AeadFactoryTest.java @@ -22,11 +22,10 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.crypto.tink.Aead; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.TestUtil; -import com.google.crypto.tink.config.TinkConfig; +import com.google.crypto.tink.daead.DeterministicAeadConfig; import com.google.crypto.tink.proto.KeyStatusType; import com.google.crypto.tink.proto.Keyset.Key; import com.google.crypto.tink.proto.OutputPrefixType; @@ -46,7 +45,8 @@ public class AeadFactoryTest { @BeforeClass public static void setUp() throws Exception { - Config.register(TinkConfig.TINK_1_1_0); + AeadConfig.register(); + DeterministicAeadConfig.register(); // need this for testInvalidKeyMaterial. } @Test diff --git a/java/src/test/java/com/google/crypto/tink/aead/AesCtrHmacAeadKeyManagerTest.java b/java/src/test/java/com/google/crypto/tink/aead/AesCtrHmacAeadKeyManagerTest.java index eefacb46e59eec1e43424e16f4a6bc1bdabc6c5e..b18aef67cfeb6c3f386cd288f4a12ea268f56ef2 100644 --- a/java/src/test/java/com/google/crypto/tink/aead/AesCtrHmacAeadKeyManagerTest.java +++ b/java/src/test/java/com/google/crypto/tink/aead/AesCtrHmacAeadKeyManagerTest.java @@ -19,7 +19,6 @@ package com.google.crypto.tink.aead; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.proto.AesCtrHmacAeadKey; import com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat; import com.google.crypto.tink.proto.KeyData; @@ -38,7 +37,7 @@ import org.junit.runners.JUnit4; public class AesCtrHmacAeadKeyManagerTest { @BeforeClass public static void setUp() throws Exception { - Config.register(AeadConfig.TINK_1_0_0); + AeadConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/aead/AesEaxKeyManagerTest.java b/java/src/test/java/com/google/crypto/tink/aead/AesEaxKeyManagerTest.java index 5c69028ae0752b8cc99314a438f95c5132173d89..ae99c1710befcf20603bf022e0d414afa480a82a 100644 --- a/java/src/test/java/com/google/crypto/tink/aead/AesEaxKeyManagerTest.java +++ b/java/src/test/java/com/google/crypto/tink/aead/AesEaxKeyManagerTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.crypto.tink.Aead; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.TestUtil; @@ -50,7 +49,7 @@ import org.junit.runners.JUnit4; public class AesEaxKeyManagerTest { @BeforeClass public static void setUp() throws GeneralSecurityException { - Config.register(AeadConfig.TINK_1_0_0); + AeadConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/aead/AesGcmKeyManagerTest.java b/java/src/test/java/com/google/crypto/tink/aead/AesGcmKeyManagerTest.java index 8d218d36885d2a259c3c036359f0c0fc01c8df0b..f304155c4330e1fadecf03bc1c393b6b81f10f9b 100644 --- a/java/src/test/java/com/google/crypto/tink/aead/AesGcmKeyManagerTest.java +++ b/java/src/test/java/com/google/crypto/tink/aead/AesGcmKeyManagerTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import com.google.crypto.tink.Aead; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.TestUtil; @@ -47,7 +46,7 @@ import org.junit.runners.JUnit4; public class AesGcmKeyManagerTest { @BeforeClass public static void setUp() throws GeneralSecurityException { - Config.register(AeadConfig.TINK_1_0_0); + AeadConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/aead/ChaCha20Poly1305KeyManagerTest.java b/java/src/test/java/com/google/crypto/tink/aead/ChaCha20Poly1305KeyManagerTest.java index 33f181ab12c69fb5005b05696b013244964d5173..325b23cf8cc9511ecaf0342b9de508cd0b2cc231 100644 --- a/java/src/test/java/com/google/crypto/tink/aead/ChaCha20Poly1305KeyManagerTest.java +++ b/java/src/test/java/com/google/crypto/tink/aead/ChaCha20Poly1305KeyManagerTest.java @@ -19,7 +19,6 @@ package com.google.crypto.tink.aead; import static org.junit.Assert.assertEquals; import com.google.crypto.tink.Aead; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.TestUtil; @@ -39,7 +38,7 @@ import org.junit.runners.JUnit4; public class ChaCha20Poly1305KeyManagerTest { @BeforeClass public static void setUp() throws GeneralSecurityException { - Config.register(AeadConfig.TINK_1_0_0); + AeadConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/aead/KmsAeadKeyManagerTest.java b/java/src/test/java/com/google/crypto/tink/aead/KmsAeadKeyManagerTest.java index 29ee3bb37a8acae85e7ab98417e8dee5481cf6eb..36e2f0c0237e7f90e6cd796e1bd4ac95e2531f7c 100644 --- a/java/src/test/java/com/google/crypto/tink/aead/KmsAeadKeyManagerTest.java +++ b/java/src/test/java/com/google/crypto/tink/aead/KmsAeadKeyManagerTest.java @@ -16,7 +16,6 @@ package com.google.crypto.tink.aead; -import com.google.crypto.tink.Config; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.KmsClient; import com.google.crypto.tink.KmsClients; @@ -34,7 +33,7 @@ public class KmsAeadKeyManagerTest { public void setUp() throws Exception { KmsClient kmsClient = new GcpKmsClient().withCredentials(TestUtil.SERVICE_ACCOUNT_FILE); KmsClients.add(kmsClient); - Config.register(AeadConfig.TINK_1_0_0); + AeadConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/aead/KmsEnvelopeAeadKeyManagerTest.java b/java/src/test/java/com/google/crypto/tink/aead/KmsEnvelopeAeadKeyManagerTest.java index 271f2841afa97bfa07884d9c6ab2dba2a6c64353..620055cb8f1de6685d482b013b801394581f09e3 100644 --- a/java/src/test/java/com/google/crypto/tink/aead/KmsEnvelopeAeadKeyManagerTest.java +++ b/java/src/test/java/com/google/crypto/tink/aead/KmsEnvelopeAeadKeyManagerTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.fail; import com.google.crypto.tink.Aead; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.KmsClients; @@ -45,7 +44,7 @@ public class KmsEnvelopeAeadKeyManagerTest { public static void setUp() throws Exception { KmsClients.add(new GcpKmsClient() .withCredentials(TestUtil.SERVICE_ACCOUNT_FILE)); - Config.register(AeadConfig.TINK_1_0_0); + AeadConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/config/TinkConfigTest.java b/java/src/test/java/com/google/crypto/tink/config/TinkConfigTest.java index 8896457c638d37dfadff3ef0709b591c7227bf71..d9908bfa4b8c1894b8214191ecc6a066ce7052df 100644 --- a/java/src/test/java/com/google/crypto/tink/config/TinkConfigTest.java +++ b/java/src/test/java/com/google/crypto/tink/config/TinkConfigTest.java @@ -45,46 +45,91 @@ public class TinkConfigTest { fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("MacConfig.init()"); + assertThat(e.toString()).contains("MacConfig.register()"); } try { Registry.getCatalogue("tinkaead"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("AeadConfig.init()"); + assertThat(e.toString()).contains("AeadConfig.register()"); } try { Registry.getCatalogue("tinkhybriddecrypt"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("HybridConfig.init()"); + assertThat(e.toString()).contains("HybridConfig.register()"); } try { Registry.getCatalogue("tinkhybridencrypt"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("HybridConfig.init()"); + assertThat(e.toString()).contains("HybridConfig.register()"); } try { Registry.getCatalogue("tinkpublickeysign"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("SignatureConfig.init()"); + assertThat(e.toString()).contains("SignatureConfig.register()"); } try { Registry.getCatalogue("tinkpublickeyverify"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("SignatureConfig.init()"); + assertThat(e.toString()).contains("SignatureConfig.register()"); } - // 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; + + String macTypeUrl = "type.googleapis.com/google.crypto.tink.HmacKey"; + String aeadTypeUrl = "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey"; + String daeadTypeUrl = "type.googleapis.com/google.crypto.tink.AesSivKey"; + String hybridTypeUrl = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey"; + String signTypeUrl = "type.googleapis.com/google.crypto.tink.EcdsaPrivateKey"; + String streamingAeadTypeUrl = "type.googleapis.com/google.crypto.tink.AesCtrHmacStreamingKey"; + try { + Registry.getKeyManager(macTypeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + try { + Registry.getKeyManager(aeadTypeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + try { + Registry.getKeyManager(daeadTypeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + try { + Registry.getKeyManager(hybridTypeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + try { + Registry.getKeyManager(signTypeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + try { + Registry.getKeyManager(streamingAeadTypeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + + // Initialize the config. + TinkConfig.register(); + + // Now the catalogues should be present. Registry.getCatalogue("tinkmac"); Registry.getCatalogue("tinkaead"); Registry.getCatalogue("tinkdeterministicaead"); @@ -92,6 +137,15 @@ public class TinkConfigTest { Registry.getCatalogue("tinkhybriddecrypt"); Registry.getCatalogue("tinkpublickeysign"); Registry.getCatalogue("tinkpublickeyverify"); + + // After registration the key managers should be present. + Config.register(TinkConfig.TINK_1_1_0); + Registry.getKeyManager(macTypeUrl); + Registry.getKeyManager(aeadTypeUrl); + Registry.getKeyManager(daeadTypeUrl); + Registry.getKeyManager(hybridTypeUrl); + Registry.getKeyManager(signTypeUrl); + Registry.getKeyManager(streamingAeadTypeUrl); } @Test @@ -312,58 +366,4 @@ public class TinkConfigTest { true, 0); } - - @Test - public void testRegistration() throws Exception { - String macTypeUrl = "type.googleapis.com/google.crypto.tink.HmacKey"; - String aeadTypeUrl = "type.googleapis.com/google.crypto.tink.AesCtrHmacAeadKey"; - String daeadTypeUrl = "type.googleapis.com/google.crypto.tink.AesSivKey"; - String hybridTypeUrl = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey"; - String signTypeUrl = "type.googleapis.com/google.crypto.tink.EcdsaPrivateKey"; - String streamingAeadTypeUrl = "type.googleapis.com/google.crypto.tink.AesCtrHmacStreamingKey"; - try { - Registry.getKeyManager(macTypeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - try { - Registry.getKeyManager(aeadTypeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - try { - Registry.getKeyManager(daeadTypeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - try { - Registry.getKeyManager(hybridTypeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - try { - Registry.getKeyManager(signTypeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - try { - Registry.getKeyManager(streamingAeadTypeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - // After registration the key managers should be present. - Config.register(TinkConfig.TINK_1_1_0); - Registry.getKeyManager(macTypeUrl); - Registry.getKeyManager(aeadTypeUrl); - Registry.getKeyManager(daeadTypeUrl); - Registry.getKeyManager(hybridTypeUrl); - Registry.getKeyManager(signTypeUrl); - Registry.getKeyManager(streamingAeadTypeUrl); - } } diff --git a/java/src/test/java/com/google/crypto/tink/daead/AesSivKeyManagerTest.java b/java/src/test/java/com/google/crypto/tink/daead/AesSivKeyManagerTest.java index 362f75ebc5fe5e7813d5ff529ee35d617843d3fd..86930e693b4a5d1cfc3065598a6b13057e14ac97 100644 --- a/java/src/test/java/com/google/crypto/tink/daead/AesSivKeyManagerTest.java +++ b/java/src/test/java/com/google/crypto/tink/daead/AesSivKeyManagerTest.java @@ -19,7 +19,6 @@ package com.google.crypto.tink.daead; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.DeterministicAead; import com.google.crypto.tink.KeysetHandle; @@ -49,8 +48,7 @@ public class AesSivKeyManagerTest { @BeforeClass public static void setUp() throws GeneralSecurityException { - DeterministicAeadConfig.init(); - Config.register(DeterministicAeadConfig.TINK_1_1_0); + DeterministicAeadConfig.register(); } @Before diff --git a/java/src/test/java/com/google/crypto/tink/daead/DeterministicAeadConfigTest.java b/java/src/test/java/com/google/crypto/tink/daead/DeterministicAeadConfigTest.java index e6b782300ff9b7905b8008b47340ce24158fa070..fae44b056eef5ffd4d8c888f372569c4526bf698 100644 --- a/java/src/test/java/com/google/crypto/tink/daead/DeterministicAeadConfigTest.java +++ b/java/src/test/java/com/google/crypto/tink/daead/DeterministicAeadConfigTest.java @@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.Registry; import com.google.crypto.tink.TestUtil; import com.google.crypto.tink.proto.RegistryConfig; @@ -47,19 +46,34 @@ public class DeterministicAeadConfigTest { fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("DeterministicAeadConfig.init()"); + assertThat(e.toString()).contains("DeterministicAeadConfig.register()"); } - // Get the config proto, now the catalogues should be present, - // as init() was triggered by a static block. + + // Before registration, the key manager should be absent. + String typeUrl = "type.googleapis.com/google.crypto.tink.AesSivKey"; + try { + Registry.getKeyManager(typeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + + // Initialize the config. + DeterministicAeadConfig.register(); + + // Now the catalogues should be present. RegistryConfig unused = DeterministicAeadConfig.TINK_1_1_0; Registry.getCatalogue("tinkdeterministicaead"); + // After registration, the key manager should be present. + Registry.getKeyManager(typeUrl); + // Running init() manually again should succeed. - DeterministicAeadConfig.init(); + DeterministicAeadConfig.register(); } @Test - public void testConfigContents() throws Exception { + public void testConfigContents_1_1_0() throws Exception { RegistryConfig config = DeterministicAeadConfig.TINK_1_1_0; assertEquals(1, config.getEntryCount()); assertEquals("TINK_DETERMINISTIC_AEAD_1_1_0", config.getConfigName()); @@ -74,16 +88,17 @@ public class DeterministicAeadConfigTest { } @Test - public void testRegistration() throws Exception { - String typeUrl = "type.googleapis.com/google.crypto.tink.AesSivKey"; - try { - Registry.getKeyManager(typeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - // After registration the key manager should be present. - Config.register(DeterministicAeadConfig.TINK_1_1_0); - Registry.getKeyManager(typeUrl); + public void testConfigContents_LATEST() throws Exception { + RegistryConfig config = DeterministicAeadConfig.LATEST; + assertEquals(1, config.getEntryCount()); + assertEquals("TINK_DETERMINISTIC_AEAD", config.getConfigName()); + + TestUtil.verifyConfigEntry( + config.getEntry(0), + "TinkDeterministicAead", + "DeterministicAead", + "type.googleapis.com/google.crypto.tink.AesSivKey", + true, + 0); } } diff --git a/java/src/test/java/com/google/crypto/tink/daead/DeterministicAeadFactoryTest.java b/java/src/test/java/com/google/crypto/tink/daead/DeterministicAeadFactoryTest.java index c52c68144ee038a1af379b7240b66dda7b505502..e31983260e19f20e03c1f9fe93314a9b9e0441ed 100644 --- a/java/src/test/java/com/google/crypto/tink/daead/DeterministicAeadFactoryTest.java +++ b/java/src/test/java/com/google/crypto/tink/daead/DeterministicAeadFactoryTest.java @@ -21,12 +21,11 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.DeterministicAead; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.TestUtil; -import com.google.crypto.tink.config.TinkConfig; +import com.google.crypto.tink.aead.AeadConfig; import com.google.crypto.tink.proto.KeyStatusType; import com.google.crypto.tink.proto.Keyset.Key; import com.google.crypto.tink.proto.OutputPrefixType; @@ -47,7 +46,8 @@ public class DeterministicAeadFactoryTest { @BeforeClass public static void setUp() throws Exception { - Config.register(TinkConfig.TINK_1_1_0); + AeadConfig.register(); // need this for testInvalidKeyMaterial. + DeterministicAeadConfig.register(); } @Before diff --git a/java/src/test/java/com/google/crypto/tink/hybrid/HybridConfigTest.java b/java/src/test/java/com/google/crypto/tink/hybrid/HybridConfigTest.java index 4951c22ac4e6447e1f99d5b9f416434ea112f1ab..c88629cf23d46b4337d78590bcd85fe80bf11d34 100644 --- a/java/src/test/java/com/google/crypto/tink/hybrid/HybridConfigTest.java +++ b/java/src/test/java/com/google/crypto/tink/hybrid/HybridConfigTest.java @@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.Registry; import com.google.crypto.tink.TestUtil; import com.google.crypto.tink.proto.RegistryConfig; @@ -47,31 +46,43 @@ public class HybridConfigTest { fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("MacConfig.init()"); + assertThat(e.toString()).contains("MacConfig.register()"); } try { Registry.getCatalogue("tinkhybridencrypt"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("HybridConfig.init()"); + assertThat(e.toString()).contains("HybridConfig.register()"); } try { Registry.getCatalogue("tinkhybriddecrypt"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("HybridConfig.init()"); + assertThat(e.toString()).contains("HybridConfig.register()"); } - // 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; + + String typeUrl = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey"; + try { + Registry.getKeyManager(typeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + + // Initialize the config. + HybridConfig.register(); + + // Now the catalogues should be present. Registry.getCatalogue("tinkmac"); Registry.getCatalogue("tinkhybriddecrypt"); Registry.getCatalogue("tinkhybridencrypt"); + Registry.getKeyManager(typeUrl); + // Running init() manually again should succeed. - HybridConfig.init(); + HybridConfig.register(); } @Test @@ -217,16 +228,73 @@ public class HybridConfigTest { } @Test - public void testRegistration() throws Exception { - String typeUrl = "type.googleapis.com/google.crypto.tink.EciesAeadHkdfPrivateKey"; - try { - Registry.getKeyManager(typeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - // After registration the key manager should be present. - Config.register(HybridConfig.TINK_1_1_0); - Registry.getKeyManager(typeUrl); + public void testConfigContents_LATEST() throws Exception { + RegistryConfig config = HybridConfig.LATEST; + assertEquals(9, config.getEntryCount()); + assertEquals("TINK_HYBRID", 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); } } diff --git a/java/src/test/java/com/google/crypto/tink/hybrid/HybridEncryptFactoryTest.java b/java/src/test/java/com/google/crypto/tink/hybrid/HybridEncryptFactoryTest.java index 6c8e9b2a72c1317fe0f038625822096ccee8d64a..02d1d65836000e89e47996190af41a8067f331dc 100644 --- a/java/src/test/java/com/google/crypto/tink/hybrid/HybridEncryptFactoryTest.java +++ b/java/src/test/java/com/google/crypto/tink/hybrid/HybridEncryptFactoryTest.java @@ -18,12 +18,12 @@ package com.google.crypto.tink.hybrid; import static org.junit.Assert.assertArrayEquals; -import com.google.crypto.tink.Config; import com.google.crypto.tink.HybridDecrypt; import com.google.crypto.tink.HybridEncrypt; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.TestUtil; import com.google.crypto.tink.aead.AeadKeyTemplates; +import com.google.crypto.tink.daead.DeterministicAeadConfig; import com.google.crypto.tink.proto.EcPointFormat; import com.google.crypto.tink.proto.EciesAeadHkdfPrivateKey; import com.google.crypto.tink.proto.EllipticCurveType; @@ -44,7 +44,8 @@ import org.junit.runners.JUnit4; public class HybridEncryptFactoryTest { @BeforeClass public static void setUp() throws Exception { - Config.register(HybridConfig.TINK_1_0_0); + HybridConfig.register(); + DeterministicAeadConfig.register(); // need this for testInvalidKeyMaterial. } @Test diff --git a/java/src/test/java/com/google/crypto/tink/mac/MacConfigTest.java b/java/src/test/java/com/google/crypto/tink/mac/MacConfigTest.java index 2fd0565deb0e546f57f17ec05e2db4161c3d94fe..d7b7040b9ae4b2503870ee002e697c81939b35f1 100644 --- a/java/src/test/java/com/google/crypto/tink/mac/MacConfigTest.java +++ b/java/src/test/java/com/google/crypto/tink/mac/MacConfigTest.java @@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.Registry; import com.google.crypto.tink.TestUtil; import com.google.crypto.tink.proto.RegistryConfig; @@ -47,16 +46,29 @@ public class MacConfigTest { fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("MacConfig.init()"); + assertThat(e.toString()).contains("MacConfig.register()"); } - // Get the config proto, now the catalogues should be present, - // as init() was triggered by a static block. - RegistryConfig unused = MacConfig.TINK_1_1_0; + + String typeUrl = "type.googleapis.com/google.crypto.tink.HmacKey"; + try { + Registry.getKeyManager(typeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + + // Initialize the config. + MacConfig.register(); + + // Now the catalogues should be present. Registry.getCatalogue("tinkmac"); Registry.getCatalogue("tinkmac"); + // After registration the key manager should be present. + Registry.getKeyManager(typeUrl); + // Running init() manually again should succeed. - MacConfig.init(); + MacConfig.register(); } @Test @@ -90,16 +102,17 @@ public class MacConfigTest { } @Test - public void testRegistration() throws Exception { - String typeUrl = "type.googleapis.com/google.crypto.tink.HmacKey"; - try { - Registry.getKeyManager(typeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - // After registration the key manager should be present. - Config.register(MacConfig.TINK_1_1_0); - Registry.getKeyManager(typeUrl); + public void testConfigContents_LATEST() throws Exception { + RegistryConfig config = MacConfig.LATEST; + assertEquals(1, config.getEntryCount()); + assertEquals("TINK_MAC", config.getConfigName()); + + TestUtil.verifyConfigEntry( + config.getEntry(0), + "TinkMac", + "Mac", + "type.googleapis.com/google.crypto.tink.HmacKey", + true, + 0); } } diff --git a/java/src/test/java/com/google/crypto/tink/mac/MacFactoryTest.java b/java/src/test/java/com/google/crypto/tink/mac/MacFactoryTest.java index e554d5d796fa6a68ac0d6b3b328c9b522bd67a21..fedaf68f6ed8c1cd80211ca7568e89e1308415f1 100644 --- a/java/src/test/java/com/google/crypto/tink/mac/MacFactoryTest.java +++ b/java/src/test/java/com/google/crypto/tink/mac/MacFactoryTest.java @@ -21,12 +21,11 @@ import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.Mac; import com.google.crypto.tink.TestUtil; -import com.google.crypto.tink.config.TinkConfig; +import com.google.crypto.tink.daead.DeterministicAeadConfig; import com.google.crypto.tink.proto.KeyStatusType; import com.google.crypto.tink.proto.Keyset.Key; import com.google.crypto.tink.proto.OutputPrefixType; @@ -48,7 +47,8 @@ public class MacFactoryTest { @BeforeClass public static void setUp() throws Exception { - Config.register(TinkConfig.TINK_1_1_0); + MacConfig.register(); + DeterministicAeadConfig.register(); // need this for testInvalidKeyMaterial. } @Test diff --git a/java/src/test/java/com/google/crypto/tink/signature/PublicKeySignFactoryTest.java b/java/src/test/java/com/google/crypto/tink/signature/PublicKeySignFactoryTest.java index 81d195e2b67587243797848a6d8a4b29633a112a..3fbd16bc1f632160b00de52f3b9ebca25aa73b85 100644 --- a/java/src/test/java/com/google/crypto/tink/signature/PublicKeySignFactoryTest.java +++ b/java/src/test/java/com/google/crypto/tink/signature/PublicKeySignFactoryTest.java @@ -19,7 +19,6 @@ package com.google.crypto.tink.signature; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.CryptoFormat; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.PublicKeySign; @@ -48,8 +47,7 @@ public class PublicKeySignFactoryTest { @Before public void setUp() throws Exception { - Config.register(SignatureConfig.TINK_1_0_0); - ; + SignatureConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/signature/PublicKeyVerifyFactoryTest.java b/java/src/test/java/com/google/crypto/tink/signature/PublicKeyVerifyFactoryTest.java index c8dd897aff93aed232072cfcbc0768376e43e86a..6219fa160ad0cdcb61f1038e9e8fbe60dd33c102 100644 --- a/java/src/test/java/com/google/crypto/tink/signature/PublicKeyVerifyFactoryTest.java +++ b/java/src/test/java/com/google/crypto/tink/signature/PublicKeyVerifyFactoryTest.java @@ -18,7 +18,6 @@ package com.google.crypto.tink.signature; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.PublicKeySign; import com.google.crypto.tink.PublicKeyVerify; @@ -45,8 +44,7 @@ public class PublicKeyVerifyFactoryTest { @Before public void setUp() throws Exception { - Config.register(SignatureConfig.TINK_1_0_0); - ; + SignatureConfig.register(); } @Test diff --git a/java/src/test/java/com/google/crypto/tink/signature/SignatureConfigTest.java b/java/src/test/java/com/google/crypto/tink/signature/SignatureConfigTest.java index d2f3d69111a54d632c7fa4df28e83d6c35e52556..fa7900b7d36a0d79404d1d5a3ee3a72de2862746 100644 --- a/java/src/test/java/com/google/crypto/tink/signature/SignatureConfigTest.java +++ b/java/src/test/java/com/google/crypto/tink/signature/SignatureConfigTest.java @@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.Registry; import com.google.crypto.tink.TestUtil; import com.google.crypto.tink.proto.RegistryConfig; @@ -47,23 +46,35 @@ public class SignatureConfigTest { fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("SignatureConfig.init()"); + assertThat(e.toString()).contains("SignatureConfig.registe"); } try { Registry.getCatalogue("tinkpublickeyverify"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("SignatureConfig.init()"); + assertThat(e.toString()).contains("SignatureConfig.registe"); } - // Get the config proto, now the catalogues should be present, - // as init() was triggered by a static block. - RegistryConfig unused = SignatureConfig.TINK_1_1_0; + String typeUrl = "type.googleapis.com/google.crypto.tink.EcdsaPrivateKey"; + try { + Registry.getKeyManager(typeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + + // Initialize the config. + SignatureConfig.register(); + + // Now the catalogues should be present. Registry.getCatalogue("tinkpublickeysign"); Registry.getCatalogue("tinkpublickeyverify"); + // After registration the key manager should be present. + Registry.getKeyManager(typeUrl); + // Running init() manually again should succeed. - SignatureConfig.init(); + SignatureConfig.register(); } @Test @@ -139,16 +150,38 @@ public class SignatureConfigTest { } @Test - public void testRegistration() throws Exception { - String typeUrl = "type.googleapis.com/google.crypto.tink.EcdsaPrivateKey"; - try { - Registry.getKeyManager(typeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - // After registration the key manager should be present. - Config.register(SignatureConfig.TINK_1_1_0); - Registry.getKeyManager(typeUrl); + public void testConfigContents_LATEST() throws Exception { + RegistryConfig config = SignatureConfig.LATEST; + assertEquals(4, config.getEntryCount()); + assertEquals("TINK_SIGNATURE", config.getConfigName()); + + TestUtil.verifyConfigEntry( + config.getEntry(0), + "TinkPublicKeySign", + "PublicKeySign", + "type.googleapis.com/google.crypto.tink.EcdsaPrivateKey", + true, + 0); + TestUtil.verifyConfigEntry( + config.getEntry(1), + "TinkPublicKeySign", + "PublicKeySign", + "type.googleapis.com/google.crypto.tink.Ed25519PrivateKey", + true, + 0); + TestUtil.verifyConfigEntry( + config.getEntry(2), + "TinkPublicKeyVerify", + "PublicKeyVerify", + "type.googleapis.com/google.crypto.tink.EcdsaPublicKey", + true, + 0); + TestUtil.verifyConfigEntry( + config.getEntry(3), + "TinkPublicKeyVerify", + "PublicKeyVerify", + "type.googleapis.com/google.crypto.tink.Ed25519PublicKey", + true, + 0); } } diff --git a/java/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadConfigTest.java b/java/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadConfigTest.java index d2b2fa766cac295ff28f4c165f71e8526f86ea7f..eea87a24befadd8d37093eeab886cca258813af0 100644 --- a/java/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadConfigTest.java +++ b/java/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadConfigTest.java @@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.Registry; import com.google.crypto.tink.TestUtil; import com.google.crypto.tink.proto.RegistryConfig; @@ -47,26 +46,38 @@ public class StreamingAeadConfigTest { fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("StreamingAeadConfig.init()"); + assertThat(e.toString()).contains("StreamingAeadConfig.register()"); } try { Registry.getCatalogue("TinkStreamingAead"); fail("Expected GeneralSecurityException"); } catch (GeneralSecurityException e) { assertThat(e.toString()).contains("no catalogue found"); - assertThat(e.toString()).contains("StreamingAeadConfig.init()"); + assertThat(e.toString()).contains("StreamingAeadConfig.register()"); } - // Get the config proto, now the catalogues should be present, - // as init() was triggered by a static block. - RegistryConfig unused = StreamingAeadConfig.TINK_1_1_0; + String typeUrl = "type.googleapis.com/google.crypto.tink.AesCtrHmacStreamingKey"; + try { + Registry.getKeyManager(typeUrl); + fail("Expected GeneralSecurityException"); + } catch (GeneralSecurityException e) { + assertThat(e.toString()).contains("No key manager found"); + } + + // Initialize the config. + StreamingAeadConfig.register(); + + // Now the catalogues should be present. Registry.getCatalogue("TinkStreamingAead"); + // After registration the key manager should be present. + Registry.getKeyManager(typeUrl); + // Running init() manually again should succeed. - StreamingAeadConfig.init(); + StreamingAeadConfig.register(); } @Test - public void testConfigContents() throws Exception { + public void testConfigContents_1_1_0() throws Exception { RegistryConfig config = StreamingAeadConfig.TINK_1_1_0; assertEquals(2, config.getEntryCount()); assertEquals("TINK_STREAMINGAEAD_1_1_0", config.getConfigName()); @@ -88,16 +99,24 @@ public class StreamingAeadConfigTest { } @Test - public void testRegistration() throws Exception { - String typeUrl = "type.googleapis.com/google.crypto.tink.AesCtrHmacStreamingKey"; - try { - Registry.getKeyManager(typeUrl); - fail("Expected GeneralSecurityException"); - } catch (GeneralSecurityException e) { - assertThat(e.toString()).contains("No key manager found"); - } - // After registration the key manager should be present. - Config.register(StreamingAeadConfig.TINK_1_1_0); - Registry.getKeyManager(typeUrl); + public void testConfigContents_LATEST() throws Exception { + RegistryConfig config = StreamingAeadConfig.LATEST; + assertEquals(2, config.getEntryCount()); + assertEquals("TINK_STREAMINGAEAD", 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); } } diff --git a/java/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadFactoryTest.java b/java/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadFactoryTest.java index ff1005ddd170e881c4e0719c87710dcdcba66c02..36b3e48dfdd0983a5588d7204bd07bba3ac60af7 100644 --- a/java/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadFactoryTest.java +++ b/java/src/test/java/com/google/crypto/tink/streamingaead/StreamingAeadFactoryTest.java @@ -19,12 +19,11 @@ package com.google.crypto.tink.streamingaead; import static com.google.crypto.tink.TestUtil.assertExceptionContains; import static org.junit.Assert.fail; -import com.google.crypto.tink.Config; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.StreamingAead; import com.google.crypto.tink.StreamingTestUtil; import com.google.crypto.tink.TestUtil; -import com.google.crypto.tink.config.TinkConfig; +import com.google.crypto.tink.daead.DeterministicAeadConfig; import com.google.crypto.tink.proto.KeyStatusType; import com.google.crypto.tink.proto.Keyset.Key; import com.google.crypto.tink.proto.OutputPrefixType; @@ -44,8 +43,8 @@ public class StreamingAeadFactoryTest { @BeforeClass public static void setUp() throws Exception { - StreamingAeadConfig.init(); - Config.register(TinkConfig.TINK_1_1_0); + StreamingAeadConfig.register(); + DeterministicAeadConfig.register(); // need this for testInvalidKeyMaterial. } @Test diff --git a/tools/testing/java/com/google/crypto/tink/testing/CliUtil.java b/tools/testing/java/com/google/crypto/tink/testing/CliUtil.java index dd1519cd75e41e27d57f3e1117f1a13764b34e00..d267498a44c981edb499945e197529b76258cf01 100644 --- a/tools/testing/java/com/google/crypto/tink/testing/CliUtil.java +++ b/tools/testing/java/com/google/crypto/tink/testing/CliUtil.java @@ -18,7 +18,6 @@ package com.google.crypto.tink.testing; import com.google.crypto.tink.BinaryKeysetReader; import com.google.crypto.tink.CleartextKeysetHandle; -import com.google.crypto.tink.Config; import com.google.crypto.tink.KeysetHandle; import com.google.crypto.tink.config.TinkConfig; import java.io.ByteArrayOutputStream; @@ -53,7 +52,7 @@ public class CliUtil { * In case of errors throws an exception. */ public static void initTink() throws GeneralSecurityException { - Config.register(TinkConfig.TINK_1_1_0); + TinkConfig.register(); } /** diff --git a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/Tinkey.java b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/Tinkey.java index ee6bee59a849f32cbbf5a5902f1764899a3ff204..728ce1df8be2fca39185ee98a8615f714c9fe003 100644 --- a/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/Tinkey.java +++ b/tools/tinkey/src/main/java/com/google/crypto/tink/tinkey/Tinkey.java @@ -16,7 +16,6 @@ package com.google.crypto.tink.tinkey; -import com.google.crypto.tink.Config; import com.google.crypto.tink.config.TinkConfig; import org.kohsuke.args4j.CmdLineException; import org.kohsuke.args4j.CmdLineParser; @@ -26,7 +25,7 @@ import org.kohsuke.args4j.CmdLineParser; */ public final class Tinkey { public static void main(String[] args) throws Exception { - Config.register(TinkConfig.TINK_1_1_0); + TinkConfig.register(); TinkeyCommands commands = new TinkeyCommands(); CmdLineParser parser = new CmdLineParser(commands);