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.JWSHeader; 025import com.nimbusds.jose.KeySourceException; 026 027 028/** 029 * Interface for selecting key candidates for verifying a JSON Web Signature 030 * (JWS) object. Applications should utilise this interface or a similar 031 * framework to determine whether a received JWS object (or signed JWT) is 032 * eligible for {@link com.nimbusds.jose.JWSVerifier verification} and further 033 * processing. 034 * 035 * <p>The key selection should be based on application specific criteria, such 036 * as recognised header parameters referencing the key (e.g. {@code kid}, 037 * {@code x5t}) and / or the JWS object {@link SecurityContext}. 038 * 039 * <p>See JSON Web Signature (JWS), Appendix D. Notes on Key Selection for 040 * suggestions. 041 * 042 * <p>Possible key types: 043 * 044 * <ul> 045 * <li>{@link javax.crypto.SecretKey} for HMAC keys. 046 * <li>{@link java.security.interfaces.RSAPublicKey} public RSA keys. 047 * <li>{@link java.security.interfaces.ECPublicKey} public EC keys. 048 * </ul> 049 * 050 * @author Vladimir Dzhuvinov 051 * @version 2016-06-21 052 */ 053public interface JWSKeySelector<C extends SecurityContext> { 054 055 056 /** 057 * Selects key candidates for verifying a JWS object. 058 * 059 * @param header The header of the JWS object. Must not be 060 * {@code null}. 061 * @param context Optional context of the JWS object, {@code null} if 062 * not required. 063 * 064 * @return The key candidates in trial order, empty list if none. 065 * 066 * @throws KeySourceException If a key sourcing exception is 067 * encountered, e.g. on remote JWK 068 * retrieval. 069 */ 070 List<? extends Key> selectJWSKeys(final JWSHeader header, final C context) 071 throws KeySourceException; 072}