Class KeyManagerRegistry


  • public final class KeyManagerRegistry
    extends java.lang.Object
    An internal API to register KeyManagers.

    The KeyManagerRegistry provides an API to register KeyManagers, ensuring FIPS compatibility. For registered managers, it gives access to the following operations:

    • Retrive KeyManagers
    • Constructor Detail

      • KeyManagerRegistry

        public KeyManagerRegistry()
    • Method Detail

      • globalInstance

        public static KeyManagerRegistry globalInstance()
        Returns the global instance.
      • resetGlobalInstanceTestOnly

        public static void resetGlobalInstanceTestOnly()
        Resets the global instance. Should only be used in tests. Not thread safe.
      • registerKeyManager

        public <P> void registerKeyManager​(KeyManager<P> manager,
                                           boolean newKeyAllowed)
                                    throws java.security.GeneralSecurityException
        Attempts to insert the given KeyManager into the object.
        Throws:
        java.security.GeneralSecurityException
      • registerKeyManagerWithFipsCompatibility

        public <P> void registerKeyManagerWithFipsCompatibility​(KeyManager<P> manager,
                                                                TinkFipsUtil.AlgorithmFipsCompatibility compatibility,
                                                                boolean newKeyAllowed)
                                                         throws java.security.GeneralSecurityException
        Attempts to insert the given KeyManager into the object; the caller guarantees that the given key manager satisfies the given FIPS compatibility.
        Throws:
        java.security.GeneralSecurityException
      • typeUrlExists

        public boolean typeUrlExists​(java.lang.String typeUrl)
      • getKeyManager

        public <P> KeyManager<P> getKeyManager​(java.lang.String typeUrl,
                                               java.lang.Class<P> primitiveClass)
                                        throws java.security.GeneralSecurityException
        Returns:
        a KeyManager for the given typeUrl and primitiveClass(if found and this key type supports this primitive).
        Throws:
        java.security.GeneralSecurityException
      • getUntypedKeyManager

        public KeyManager<?> getUntypedKeyManager​(java.lang.String typeUrl)
                                           throws java.security.GeneralSecurityException
        Returns:
        a KeyManager for the given typeUrl (if found).
        Throws:
        java.security.GeneralSecurityException
      • isNewKeyAllowed

        public boolean isNewKeyAllowed​(java.lang.String typeUrl)
      • isEmpty

        public boolean isEmpty()
      • restrictToFipsIfEmptyAndGlobalInstance

        public void restrictToFipsIfEmptyAndGlobalInstance()
                                                    throws java.security.GeneralSecurityException
        Restricts Tink to FIPS if this is the global instance.

        We make this a member method (instead of a static one which gets the global instance) because the call to "useOnlyFips" needs to happen under the same mutex lock which protects the registerKeyManager methods.

        Throws:
        java.security.GeneralSecurityException