001/* 002 * nimbus-jose-jwt 003 * 004 * Copyright 2012-2016, Connect2id Ltd. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 007 * this file except in compliance with the License. You may obtain a copy of the 008 * License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software distributed 013 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 014 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 015 * specific language governing permissions and limitations under the License. 016 */ 017 018package com.nimbusds.jose.proc; 019 020 021import java.security.Key; 022import java.util.List; 023 024import com.nimbusds.jose.JWEHeader; 025import com.nimbusds.jose.KeySourceException; 026 027 028/** 029 * Interface for selecting key candidates for decrypting a JSON Web Encryption 030 * (JWE) object. Applications should utilise this interface or a similar 031 * framework to determine whether a received JWE object (or encrypted JWT) is 032 * eligible for {@link com.nimbusds.jose.JWEDecrypter decryption} and further 033 * processing. 034 * 035 * <p>The interface supports keys selection based on: 036 * 037 * <ul> 038 * <li>Recognised header parameters referencing the key (e.g. {@code kid}, 039 * {@code x5t}). 040 * <li>Additional {@link SecurityContext}, if required and set by the 041 * application (e.g. endpoint where the JWE object was received). 042 * </ul> 043 * 044 * <p>See JSON Web Signature (JWE), Appendix D. Notes on Key Selection for 045 * suggestions. 046 * 047 * <p>Possible key types: 048 * 049 * <ul> 050 * <li>{@link javax.crypto.SecretKey} for AES keys. 051 * <li>{@link java.security.interfaces.RSAPrivateKey} private RSA keys. 052 * <li>{@link java.security.interfaces.ECPrivateKey} private EC keys. 053 * </ul> 054 * 055 * @author Vladimir Dzhuvinov 056 * @version 2016-06-21 057 */ 058public interface JWEKeySelector <C extends SecurityContext> { 059 060 061 /** 062 * Selects key candidates for decrypting a JWE object. 063 * 064 * @param header The header of the JWE object. Must not be 065 * {@code null}. 066 * @param context Optional context of the JWE object, {@code null} if 067 * not required. 068 * 069 * @return The key candidates in trial order, empty list if none. 070 * 071 * @throws KeySourceException If a key source exception is encountered, 072 * e.g. on remote JWK retrieval. 073 */ 074 List<? extends Key> selectJWEKeys(final JWEHeader header, final C context) 075 throws KeySourceException; 076}