001/*******************************************************************************
002 * Copyright 2014 The MITRE Corporation
003 *   and the MIT Kerberos and Internet Trust Consortium
004 * 
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 * 
009 *   http://www.apache.org/licenses/LICENSE-2.0
010 * 
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 ******************************************************************************/
017package org.mitre.jwt.encryption.service;
018
019import java.util.Collection;
020import java.util.Map;
021
022import com.nimbusds.jose.EncryptionMethod;
023import com.nimbusds.jose.JWEAlgorithm;
024import com.nimbusds.jose.JWEObject;
025import com.nimbusds.jose.jwk.JWK;
026
027/**
028 * @author wkim
029 *
030 */
031public interface JwtEncryptionAndDecryptionService {
032
033        /**
034         * Encrypts the JWT in place with the default encrypter.
035         * If an arbitrary payload is used, then pass in a JWEObject.
036         * Otherwise, if JWT claims are the payload, then use the JWEObject subclass EncryptedJWT instead.
037         * @param jwt
038         */
039        public void encryptJwt(JWEObject jwt);
040
041        /**
042         * Decrypts the JWT in place with the default decrypter.
043         *  If an arbitrary payload is used, then pass in a JWEObject.
044         *  Otherwise, if JWT claims are the payload, then use the JWEObject subclass EncryptedJWT instead.
045         * @param jwt
046         */
047        public void decryptJwt(JWEObject jwt);
048
049        /**
050         * Get all public keys for this service, mapped by their Key ID
051         */
052        public Map<String, JWK> getAllPublicKeys();
053
054        /**
055         * Get the list of all encryption algorithms supported by this service.
056         * @return
057         */
058        public Collection<JWEAlgorithm> getAllEncryptionAlgsSupported();
059
060        /**
061         * Get the list of all encryption methods supported by this service.
062         * @return
063         */
064        public Collection<EncryptionMethod> getAllEncryptionEncsSupported();
065
066        /**
067         * TODO add functionality for encrypting and decrypting using a specified key id.
068         * Example: public void encryptJwt(EncryptedJWT jwt, String kid);
069         */
070}