java.lang.Object
io.inverno.mod.security.jose.internal.jwk.AbstractJWK
All Implemented Interfaces:
JWK
Direct Known Subclasses:
AbstractX509JWK, GenericOCTJWK, GenericPBES2JWK

public abstract class AbstractJWK extends Object implements JWK

Base JSON Web Key implementation.

Since:
1.5
Author:
Jeremy Kuhn
  • Field Details

  • Constructor Details

  • Method Details

    • getDefaultThumbprintDigest

      public static MessageDigest getDefaultThumbprintDigest()

      Returns the default message digest to generate JWK thumbprint.

      Returns:
      a message digest
    • getKeyType

      public String getKeyType()
      Description copied from interface: JWK

      Returns the key type.

      Specified by:
      getKeyType in interface JWK
      Returns:
      the key type
    • getPublicKeyUse

      public String getPublicKeyUse()
      Description copied from interface: JWK

      Returns the public key use.

      Specified by:
      getPublicKeyUse in interface JWK
      Returns:
      the public key use
    • setPublicKeyUse

      public void setPublicKeyUse(String use)

      Sets the intended use of the public key: signature (sig) or encryption (enc).

      Parameters:
      use - the public key use
    • getKeyOperations

      public Set<String> getKeyOperations()
      Description copied from interface: JWK

      Returns the set of key operations.

      Specified by:
      getKeyOperations in interface JWK
      Returns:
      the set of key operations
    • setKeyOperations

      public void setKeyOperations(Set<String> key_ops)

      Sets the key operations for which the key is intended to be used.

      Parameters:
      key_ops - a set of key operations
    • getAlgorithm

      public String getAlgorithm()
      Description copied from interface: JWK

      Returns the algorithm intended for use with the key.

      Specified by:
      getAlgorithm in interface JWK
      Returns:
      the key algorithm
    • setAlgorithm

      public void setAlgorithm(String alg)

      Sets the algorithm intended for use with the key.

      Parameters:
      alg - the JWA algorithm
    • getKeyId

      public String getKeyId()
      Description copied from interface: JWK

      Returns the key id.

      Specified by:
      getKeyId in interface JWK
      Returns:
      the key id
    • setKeyId

      public void setKeyId(String kid)

      Sets the id of the key.

      Parameters:
      kid - the key id
    • getKey

      public Key getKey()

      Returns the key.

      Returns:
      a key
    • isTrusted

      public boolean isTrusted()
      Description copied from interface: JWK

      Determines whether this key is trusted.

      Untrusted keys are typically resolved from unsecured JOSE headers (e.g. no x5c, no x5u...), the are excluded when reading a JOSE object for obvious security reasons.

      Implementations can rely on trust stores or certificate paths validation to determine whether a key is trusted. It is also possible to explicitly trust a key by invoking the JWK.trust(). method.

      Specified by:
      isTrusted in interface JWK
      Returns:
      true if the key is trusted, false otherwise.
    • signer

      public JWASigner signer() throws JWKProcessingException
      Description copied from interface: JWK

      Returns a signer using this JWK.

      Specified by:
      signer in interface JWK
      Returns:
      a signer
      Throws:
      JWKProcessingException - if the JWK does not support signature operations (i.e. missing algorithm, algorithm is not a signature algorithm...)
    • signer

      public JWASigner signer(String alg) throws JWKProcessingException
      Description copied from interface: JWK

      Returns a signer using this JWK and the specified algorithm.

      Specified by:
      signer in interface JWK
      Parameters:
      alg - a JWA signature algorithm
      Returns:
      a signer
      Throws:
      JWKProcessingException - if the JWK does not support signature operations or if the specified algorithm is not a supported signature algorithm
    • checkSignature

      protected void checkSignature(JWAAlgorithm<?> algorithm) throws JWKProcessingException

      Checks that the key and the specified algorithm supports signature operations.

      Parameters:
      algorithm - a JWA algorithm
      Throws:
      JWKProcessingException - if the key and/or the specified algorithm do not support signature operations
    • cipher

      public JWACipher cipher() throws JWKProcessingException
      Description copied from interface: JWK

      Returns a cipher using this JWK.

      Specified by:
      cipher in interface JWK
      Returns:
      a cipher
      Throws:
      JWKProcessingException - if the JWK does not support encryption operations (i.e. missing algorithm, algorithm is not an encryption algorithm...)
    • cipher

      public JWACipher cipher(String alg) throws JWKProcessingException
      Description copied from interface: JWK

      Returns a cipher using this JWK and the specified algorithm.

      Specified by:
      cipher in interface JWK
      Parameters:
      alg - a JWA encryption algorithm
      Returns:
      a cipher
      Throws:
      JWKProcessingException - if the JWK does not support encryption operations or if the specified algorithm is not a supported encryption algorithm
    • checkEncryption

      protected void checkEncryption(JWAAlgorithm<?> algorithm) throws JWKProcessingException

      Checks that the key and the specified algorithm supports encryption operations.

      Parameters:
      algorithm - a JWA algorithm
      Throws:
      JWKProcessingException - if the key and/or the specified algorithm do not support encryption operations
    • keyManager

      public JWAKeyManager keyManager() throws JWKProcessingException
      Description copied from interface: JWK

      Returns a key manager using this JWK.

      Specified by:
      keyManager in interface JWK
      Returns:
      a key manager
      Throws:
      JWKProcessingException - if the JWK does not support key management operations (i.e. missing algorithm, algorithm is not a key management algorithm...)
    • keyManager

      public JWAKeyManager keyManager(String alg) throws JWKProcessingException
      Description copied from interface: JWK

      Returns a key manager using this JWK and the specified algorithm.

      Specified by:
      keyManager in interface JWK
      Parameters:
      alg - a JWA key management algorithm
      Returns:
      a key manager
      Throws:
      JWKProcessingException - if the JWK does not support key management operations or if the specified algorithm is not a supported key management algorithm
    • checkKeyManagement

      protected void checkKeyManagement(JWAAlgorithm<?> algorithm) throws JWKProcessingException

      Checks that the key and the specified algorithm supports key management operations.

      Parameters:
      algorithm - a JWA algorithm
      Throws:
      JWKProcessingException - if the key and/or the specified algorithm do not support key management operations
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface JWK
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface JWK
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object