Class DefaultEncryptionParametersResolver
- All Implemented Interfaces:
EncryptionParametersResolver,Resolver<EncryptionParameters,CriteriaSet>
EncryptionParametersResolver. The resolver delegates much of its functionality
to various lookup strategies and credential resolvers. Its main purpose is to compose the results.
The set of usable key transport and data encryption algorithms are determined by injected strategies. The set of
usable credentials are resolved by CredentialResolvers found from the EncryptionConfiguration
inside the input CriteriaSet. Therefore, the EncryptionConfigurationCriterion must be present
inside the criteria set, and the resolvers must be configured for any parameters to be returned.
Once the set of algorithms and credentials have been looked up and resolved. The key transport algorithms are tried in the order they are specified until a suitable, compatible, credential is found. It is expected asymmetric encryption keys will be resolved from the OpenID Providers keyset document, and symmetric keys will be derived from the client_secret (although any resolvers could be supplied, and hence this behaviour is not guaranteed).
Extra criterion are built and provided to the credential resolvers based on the key management mode described by the algorithms being tested.
Symmetric keys are expected to be returned in their final format. For example, symmetric keys derived from the client_secret are expected to be in a key format ready for decryption.
The following Criterion inputs are supported:
EncryptionConfigurationCriterion- requiredProviderMetadataCriterion- likely required for some downstream resolvers
- Since:
- 2.2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AlgorithmRegistryThe AlgorithmRegistry used when processing algorithm URIs.private BiFunction<CriteriaSet,Predicate<String>, List<String>> A lookup strategy to locate data encryption algorithms from the given criteria set and includesExcludes predicate.private BiFunction<CriteriaSet,Predicate<String>, List<String>> A lookup strategy to locate key encryption algorithms from the given criteria set and includesExcludes predicate.private final org.slf4j.LoggerLogger. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanbuildDirectEncryptionParameters(EncryptionParameters params, CriteriaSet criteria, List<EncryptionMethod> dataEncryptionAlgorithms, JWEAlgorithm algorithm) Build direct encryption parameters from the data encryption credentials input.private CriteriaSetbuildEncryptionKeyAlgorithmCriteria(CriteriaSet existingCriteria, JWEAlgorithm alg, EncryptionMethod enc) Build criterion for credential resolvers from the JWE 'enc' header.private booleanbuildKeyEncryptionOrAgreementParameters(EncryptionParameters params, CriteriaSet criteria, List<EncryptionMethod> dataEncryptionAlgorithms, JWEAlgorithm algorithm) Build key encryption parameters from the key transport encryption credentials input.private CriteriaSetbuildKeyManagmentAlgorithmCriteria(CriteriaSet existingCriteria, JWEAlgorithm alg, EncryptionMethod enc) Build criterion for credential resolvers from the JWE 'alg' header.private booleanbuildKeyWrappingParameters(EncryptionParameters params, CriteriaSet criteria, List<EncryptionMethod> dataEncryptionAlgorithms, JWEAlgorithm algorithm) Build key wrapping encryption parameters from the key transport encryption credentials input.protected booleancheckCredentialSupportsAlgorithm(Credential credential, JWEAlgorithm algorithm) Determine if the given credential matches the given algorithm.protected booleancheckCredentialSupportsEncryptionMethod(Credential credential, EncryptionMethod encMethod) Determine if the given credential supports the given encryption method.protected booleancheckKeyAlgorithmAndLength(Credential credential, String algorithm) Evaluate whether the specified credential is supported for use with the specified algorithm URI and the key length matches.private booleancheckKeyWithAlgorithm(JWKCredential credential, JWEAlgorithm algorithm) Check the credential supports the algorithm given.protected List<JWEAlgorithm>Convert the algorithms represented as Strings into NimbusAlgorithms for later comparison.protected List<EncryptionMethod>Convert the encryption methods represented as Strings into NimbusEncryptionMethods for later comparison.protected booleancredentialSupportsAlgorithm(Credential credential, String algorithm) Evaluate whether the specified credential is supported for use with the specified algorithm URI.Get theAlgorithmRegistryinstance used when resolving algorithm URIs.Get a predicate which evaluates whether a cryptographic algorithm is supported by the runtime environment.protected List<Credential>Get the effective list of data/content encryption credentials to consider.protected List<Credential>Get the effective list of key transport credentials to consider.getIncludeExcludePredicate(CriteriaSet criteria) Get a predicate which implements the effective configured include/exclude policy.protected booleanisDataEncryptionAlgorithm(String algorithm) Evaluate whether the specified algorithm is a data encryption algorithm.protected booleanisKeyEncryptionAlgorithm(String algorithm) Evaluate whether the specified algorithm is a key encryption or key wrapping algorithm.protected voidlogResult(EncryptionParameters params) Log the resolved parameters.resolve(CriteriaSet criteria) protected voidresolveAndPopulateCredentialsAndAlgorithms(EncryptionParameters params, CriteriaSet criteria, Predicate<String> includeExcludePredicate) Resolve and populate the data encryption and key transport credentials and algorithm URIs.protected CredentialResolverResolve and return the effectiveCredentialResolverused to resolve the content encryption key.protected voidresolveCredentialForSupportedAlgorithm(CriteriaSet criteria, List<JWEAlgorithm> keyTransportAlgorithms, List<EncryptionMethod> dataEncryptionAlgorithms, EncryptionParameters params) Resolve a credential (key) compatible with one-of the supported algorithms.protected EncryptionMethodresolveEncryptionMethod(List<EncryptionMethod> dataEncryptionAlgorithms) Return the first encryption method in the supported list, or null otherwise.protected CredentialResolverresolveKEKCredentialResolver(CriteriaSet criteria) Resolve and return the effectiveCredentialResolverused to encrypt/wrap content encryption keys.resolveSingle(CriteriaSet criteria) voidsetAlgorithmRegistry(AlgorithmRegistry registry) Set theAlgorithmRegistryinstance used when resolving algorithm URIs.voidsetDataEncryptionAlgorithmsLookupStrategy(BiFunction<CriteriaSet, Predicate<String>, List<String>> strategy) Set the data encryption algorithms lookup strategy to use.voidsetKeyTransportEncryptionAlgorithmsLookupStrategy(BiFunction<CriteriaSet, Predicate<String>, List<String>> strategy) Set the key transport encryption algorithms lookup strategy to use.protected booleanvalidate(EncryptionParameters params, boolean encryptionOptional) Validate that theEncryptionParametersinstance has all the required properties populated.Methods inherited from class org.opensaml.xmlsec.impl.AbstractSecurityParametersResolver
lookupKeyInfoGenerator, resolveAndPopulateIncludesExcludes, resolveEffectiveExcludes, resolveEffectiveIncludes, resolveIncludeExcludePrecedence, resolveIncludeExcludePredicate
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logLogger. -
algorithmRegistry
The AlgorithmRegistry used when processing algorithm URIs. -
dataEncryptionAlgorithmsLookupStrategy
@Nonnull private BiFunction<CriteriaSet,Predicate<String>, dataEncryptionAlgorithmsLookupStrategyList<String>> A lookup strategy to locate data encryption algorithms from the given criteria set and includesExcludes predicate. -
keyTransportEncryptionAlgorithmsLookupStrategy
@Nonnull private BiFunction<CriteriaSet,Predicate<String>, keyTransportEncryptionAlgorithmsLookupStrategyList<String>> A lookup strategy to locate key encryption algorithms from the given criteria set and includesExcludes predicate.
-
-
Constructor Details
-
DefaultEncryptionParametersResolver
public DefaultEncryptionParametersResolver()Constructor.
-
-
Method Details
-
setDataEncryptionAlgorithmsLookupStrategy
public void setDataEncryptionAlgorithmsLookupStrategy(BiFunction<CriteriaSet, Predicate<String>, List<String>> strategy) Set the data encryption algorithms lookup strategy to use.- Parameters:
strategy- the strategy to use.
-
setKeyTransportEncryptionAlgorithmsLookupStrategy
public void setKeyTransportEncryptionAlgorithmsLookupStrategy(BiFunction<CriteriaSet, Predicate<String>, List<String>> strategy) Set the key transport encryption algorithms lookup strategy to use.- Parameters:
strategy- the strategy to use.
-
getAlgorithmRegistry
Get theAlgorithmRegistryinstance used when resolving algorithm URIs. Defaults to the registry resolved viaAlgorithmSupport.getGlobalAlgorithmRegistry().- Returns:
- the algorithm registry instance
-
setAlgorithmRegistry
Set theAlgorithmRegistryinstance used when resolving algorithm URIs. Defaults to the registry resolved viaAlgorithmSupport.getGlobalAlgorithmRegistry().- Parameters:
registry- the new algorithm registry instance
-
logResult
Log the resolved parameters.- Parameters:
params- the resolved param
-
validate
Validate that theEncryptionParametersinstance has all the required properties populated.- Parameters:
params- the parameters instance to evaluateencryptionOptional- whether to consider invalid parameters to be a problem- Returns:
- true if parameters instance passes validation, false otherwise
-
checkCredentialSupportsAlgorithm
protected boolean checkCredentialSupportsAlgorithm(@Nonnull Credential credential, @Nonnull JWEAlgorithm algorithm) Determine if the given credential matches the given algorithm.For a credential to match, it must meet the following criteria:
- The credential must be a
JWKCredential - The credential must have a
UsageTypeofUsageType.ENCRYPTIONorUsageType.UNSPECIFIED - If the credentials JWEAlgorithm is present, the credential's algorithm must match to the input JWEAlgorithm. Else, the key's algorithm must match the JWE algorithm family.
- The credential's key must match the keylength required by that algorithm
- Parameters:
credential- the credential to match against the algorithmalgorithm- the algorithm the credential must support- Returns:
- true if the credential supports the given algorithm, false otherwise
- The credential must be a
-
checkCredentialSupportsEncryptionMethod
protected boolean checkCredentialSupportsEncryptionMethod(@Nonnull Credential credential, @Nonnull EncryptionMethod encMethod) Determine if the given credential supports the given encryption method.For a credential to match, it must meet the following criteria:
- The credential's key algorithm and key length must match that required by the encryption algorithm given
- Parameters:
credential- the credential to match against the algorithmencMethod- the encryption algorithm the credential must support- Returns:
- true if the credential supports the given algorithm, false otherwise
-
checkKeyWithAlgorithm
private boolean checkKeyWithAlgorithm(@Nonnull JWKCredential credential, @Nonnull JWEAlgorithm algorithm) Check the credential supports the algorithm given. If the exact algorithm the key supports is present, check that is identical to the algorithm supplied. If not, check the key algorithm is generally compatible with the algorithm family.- Parameters:
credential- the credential to checkalgorithm- the algorithm to check compatibility with- Returns:
- true of the key is compatible with the algorithm, false otherwise
-
resolveEncryptionMethod
@Nullable protected EncryptionMethod resolveEncryptionMethod(@Nonnull List<EncryptionMethod> dataEncryptionAlgorithms) Return the first encryption method in the supported list, or null otherwise.- Parameters:
dataEncryptionAlgorithms- the supported data encryption method- Returns:
- the first supported encryption method, or null.
-
convertStringAlgorithmURIsToJwkAlgorithms
@Nonnull protected List<JWEAlgorithm> convertStringAlgorithmURIsToJwkAlgorithms(@Nonnull List<String> algos) Convert the algorithms represented as Strings into NimbusAlgorithms for later comparison. This will preserve the order of the original list (Listis ordered).- Parameters:
algos- the algorithms to convert- Returns:
- the converted algorithms
-
convertStringEncryptionMethodURIsToEncryptionMethods
@Nonnull protected List<EncryptionMethod> convertStringEncryptionMethodURIsToEncryptionMethods(@Nonnull List<String> encMethods) Convert the encryption methods represented as Strings into NimbusEncryptionMethods for later comparison. This will preserve the order of the original list (Listis ordered).- Parameters:
encMethods- the encryption methods to convert- Returns:
- the converted encryption methods
-
getAlgorithmRuntimeSupportedPredicate
Get a predicate which evaluates whether a cryptographic algorithm is supported by the runtime environment.- Returns:
- the predicate
-
credentialSupportsAlgorithm
protected boolean credentialSupportsAlgorithm(@Nonnull Credential credential, @Nonnull @NotEmpty String algorithm) Evaluate whether the specified credential is supported for use with the specified algorithm URI.- Parameters:
credential- the credential to evaluatealgorithm- the algorithm URI to evaluate- Returns:
- true if credential may be used with the supplied algorithm URI, false otherwise
-
checkKeyAlgorithmAndLength
protected boolean checkKeyAlgorithmAndLength(@Nonnull Credential credential, @Nonnull @NotEmpty String algorithm) Evaluate whether the specified credential is supported for use with the specified algorithm URI and the key length matches.- Parameters:
credential- the credential to evaluatealgorithm- the algorithm URI to evaluate against- Returns:
- true if credential may be used with the supplied algorithm URI and the key length matches, false otherwise
-
isKeyEncryptionAlgorithm
Evaluate whether the specified algorithm is a key encryption or key wrapping algorithm.- Parameters:
algorithm- the algorithm URI to evaluate- Returns:
- true if is a key transport algorithm URI, false otherwise
-
isDataEncryptionAlgorithm
Evaluate whether the specified algorithm is a data encryption algorithm.- Parameters:
algorithm- the algorithm URI to evaluate- Returns:
- true if is a key transport algorithm URI, false otherwise
-