001package com.nimbusds.jose.proc;
002
003
004import java.io.IOException;
005import java.security.Key;
006import java.util.List;
007
008import com.nimbusds.jose.JWEHeader;
009import com.nimbusds.jose.KeySourceException;
010
011
012/**
013 * Interface for selecting key candidates for decrypting a JSON Web Encryption
014 * (JWE) object. Applications should utilise this interface or a similar
015 * framework to determine whether a received JWE object (or encrypted JWT) is
016 * eligible for {@link com.nimbusds.jose.JWEDecrypter decryption} and further 
017 * processing.
018 *
019 * <p>The key selection should be based on application specific criteria, such
020 * as recognised header parameters referencing the key (e.g. {@code kid},
021 * {@code x5t}) and / or the JWE object {@link SecurityContext}.
022 *
023 * <p>See JSON Web Signature (JWE), Appendix D. Notes on Key Selection for
024 * suggestions.
025 *
026 * <p>Possible key types:
027 *
028 * <ul>
029 *     <li>{@link javax.crypto.SecretKey} for AES keys.
030 *     <li>{@link java.security.interfaces.RSAPrivateKey} private RSA keys.
031 *     <li>{@link java.security.interfaces.ECPrivateKey} private EC keys.
032 * </ul>
033 *
034 * @author Vladimir Dzhuvinov
035 * @version 2016-06-21
036 */
037public interface JWEKeySelector <C extends SecurityContext> {
038
039
040        /**
041         * Selects key candidates for decrypting a JWE object.
042         *
043         * @param header  The header of the JWE object. Must not be
044         *                {@code null}.
045         * @param context Optional context of the JWE object, {@code null} if
046         *                not required.
047         *
048         * @return The key candidates in trial order, empty list if none.
049         *
050         * @throws IOException If a key source exception is encountered, e.g.
051         *                     on remote JWK retrieval.
052         */
053        List<? extends Key> selectJWEKeys(final JWEHeader header, final C context)
054                throws KeySourceException;
055}