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 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 JWS object was received). 042 * </ul> 043 * 044 * <p>See JSON Web Signature (JWS), Appendix D. Notes on Key Selection for 045 * suggestions. 046 * 047 * <p>For a key selector for signed JWTs that also uses the claims set (e.g. 048 * issuer ({@code iss}) claim) see 049 * {@link com.nimbusds.jwt.proc.JWTClaimsSetAwareJWSKeySelector}. 050 * 051 * <p>Possible key types: 052 * 053 * <ul> 054 * <li>{@link javax.crypto.SecretKey} for HMAC keys. 055 * <li>{@link java.security.interfaces.RSAPublicKey} public RSA keys. 056 * <li>{@link java.security.interfaces.ECPublicKey} public EC keys. 057 * </ul> 058 * 059 * @author Vladimir Dzhuvinov 060 * @version 2016-06-21 061 */ 062public interface JWSKeySelector<C extends SecurityContext> { 063 064 065 /** 066 * Selects key candidates for verifying a JWS object. 067 * 068 * @param header The header of the JWS object. Must not be 069 * {@code null}. 070 * @param context Optional context of the JWS object, {@code null} if 071 * not required. 072 * 073 * @return The key candidates in trial order, empty list if none. 074 * 075 * @throws KeySourceException If a key sourcing exception is 076 * encountered, e.g. on remote JWK 077 * retrieval. 078 */ 079 List<? extends Key> selectJWSKeys(final JWSHeader header, final C context) 080 throws KeySourceException; 081}