Class AbstractJWK
- All Implemented Interfaces:
JWK
- Direct Known Subclasses:
AbstractX509JWK,GenericOCTJWK,GenericPBES2JWK
Base JSON Web Key implementation.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe Algorithm parameter as defined by RFC7517 Section 4.4.protected final KeyThe underlying key.The Key Operations parameter as defined by RFC7517 Section 4.3.protected StringThe Key id parameter as defined by RFC7517 Section 4.5.protected final StringThe key type parameter as defined by RFC7517 Section 4.1.protected booleanIndicates whether the JWK can be trusted.protected StringThe Public Key Use parameter as defined by RFC7517 Section 4.2.Fields inherited from interface io.inverno.mod.security.jose.jwk.JWK
KEY_OP_DECRYPT, KEY_OP_DERIVE_BITS, KEY_OP_DERIVE_KEY, KEY_OP_ENCRYPT, KEY_OP_SIGN, KEY_OP_UNWRAP_KEY, KEY_OP_VERIFY, KEY_OP_WRAP_KEY, USE_ENC, USE_SIG -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractJWK(String kty) Creates an untrusted JWK.protectedAbstractJWK(String kty, Key key, boolean trusted) Creates a JWK with the specified key. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckEncryption(JWAAlgorithm<?> algorithm) Checks that the key and the specified algorithm supports encryption operations.protected voidcheckKeyManagement(JWAAlgorithm<?> algorithm) Checks that the key and the specified algorithm supports key management operations.protected voidcheckSignature(JWAAlgorithm<?> algorithm) Checks that the key and the specified algorithm supports signature operations.cipher()Returns a cipher using this JWK.Returns a cipher using this JWK and the specified algorithm.booleanReturns the algorithm intended for use with the key.static MessageDigestReturns the default message digest to generate JWK thumbprint.getKey()Returns the key.getKeyId()Returns the key id.Returns the set of key operations.Returns the key type.Returns the public key use.inthashCode()booleanDetermines whether this key is trusted.Returns a key manager using this JWK.keyManager(String alg) Returns a key manager using this JWK and the specified algorithm.voidsetAlgorithm(String alg) Sets the algorithm intended for use with the key.voidSets the id of the key.voidsetKeyOperations(Set<String> key_ops) Sets the key operations for which the key is intended to be used.voidsetPublicKeyUse(String use) Sets the intended use of the public key: signature (sig) or encryption (enc).signer()Returns a signer using this JWK.Returns a signer using this JWK and the specified algorithm.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface io.inverno.mod.security.jose.jwk.JWK
minify, supportsAlgorithm, toJWKThumbprint, toJWKThumbprint, toPublicJWK, trust
-
Field Details
-
key
The underlying key. -
kty
The key type parameter as defined by RFC7517 Section 4.1. -
use
The Public Key Use parameter as defined by RFC7517 Section 4.2. -
key_ops
The Key Operations parameter as defined by RFC7517 Section 4.3. -
alg
The Algorithm parameter as defined by RFC7517 Section 4.4. -
kid
The Key id parameter as defined by RFC7517 Section 4.5. -
trusted
protected boolean trustedIndicates whether the JWK can be trusted.
-
-
Constructor Details
-
AbstractJWK
Creates an untrusted JWK.
- Parameters:
kty- the key type- Throws:
JWKProcessingException- if the key type is blank
-
AbstractJWK
Creates a JWK with the specified key.
- Parameters:
kty- the key typekey- a keytrusted- true to create a trusted JWK, false otherwise- Throws:
JWKProcessingException- if the key type is blank
-
-
Method Details
-
getDefaultThumbprintDigest
Returns the default message digest to generate JWK thumbprint.
- Returns:
- a message digest
-
getKeyType
Description copied from interface:JWKReturns the key type.
- Specified by:
getKeyTypein interfaceJWK- Returns:
- the key type
-
getPublicKeyUse
Description copied from interface:JWKReturns the public key use.
- Specified by:
getPublicKeyUsein interfaceJWK- Returns:
- the public key use
-
setPublicKeyUse
Sets the intended use of the public key: signature (
sig) or encryption (enc).- Parameters:
use- the public key use
-
getKeyOperations
Description copied from interface:JWKReturns the set of key operations.
- Specified by:
getKeyOperationsin interfaceJWK- Returns:
- the set of key operations
-
setKeyOperations
Sets the key operations for which the key is intended to be used.
- Parameters:
key_ops- a set of key operations
-
getAlgorithm
Description copied from interface:JWKReturns the algorithm intended for use with the key.
- Specified by:
getAlgorithmin interfaceJWK- Returns:
- the key algorithm
-
setAlgorithm
Sets the algorithm intended for use with the key.
- Parameters:
alg- the JWA algorithm
-
getKeyId
Description copied from interface:JWKReturns the key id.
-
setKeyId
Sets the id of the key.
- Parameters:
kid- the key id
-
getKey
Returns the key.
- Returns:
- a key
-
isTrusted
public boolean isTrusted()Description copied from interface:JWKDetermines 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. -
signer
Description copied from interface:JWKReturns a signer using this JWK.
- Specified by:
signerin interfaceJWK- Returns:
- a signer
- Throws:
JWKProcessingException- if the JWK does not support signature operations (i.e. missing algorithm, algorithm is not a signature algorithm...)
-
signer
Description copied from interface:JWKReturns a signer using this JWK and the specified algorithm.
- Specified by:
signerin interfaceJWK- 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
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
Description copied from interface:JWKReturns a cipher using this JWK.
- Specified by:
cipherin interfaceJWK- Returns:
- a cipher
- Throws:
JWKProcessingException- if the JWK does not support encryption operations (i.e. missing algorithm, algorithm is not an encryption algorithm...)
-
cipher
Description copied from interface:JWKReturns a cipher using this JWK and the specified algorithm.
- Specified by:
cipherin interfaceJWK- 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
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
Description copied from interface:JWKReturns a key manager using this JWK.
- Specified by:
keyManagerin interfaceJWK- 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
Description copied from interface:JWKReturns a key manager using this JWK and the specified algorithm.
- Specified by:
keyManagerin interfaceJWK- 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
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() -
equals
-
toString
-