001/** 002 * Copyright 2021 Emmanuel Bourg 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package net.jsign.jca; 018 019import java.security.GeneralSecurityException; 020import java.security.KeyStoreException; 021import java.security.UnrecoverableKeyException; 022import java.security.cert.Certificate; 023import java.util.List; 024 025/** 026 * Interface to a signing service. 027 * 028 * @since 4.0 029 */ 030public interface SigningService { 031 032 /** 033 * Returns the name of the service. 034 */ 035 String getName(); 036 037 /** 038 * Returns the certificate aliases available. 039 */ 040 List<String> aliases() throws KeyStoreException; 041 042 /** 043 * Returns the certificate chain for the alias specified. 044 * 045 * @param alias the name of the certificate 046 */ 047 Certificate[] getCertificateChain(String alias) throws KeyStoreException; 048 049 /** 050 * Returns the private key for the certificate alias specified. 051 * 052 * @param alias the name of the certificate 053 * @param password the secret required to access the key 054 */ 055 SigningServicePrivateKey getPrivateKey(String alias, char[] password) throws UnrecoverableKeyException; 056 057 /** 058 * Returns the private key for the certificate alias specified. 059 * 060 * @param alias the name of the certificate 061 */ 062 @Deprecated 063 default SigningServicePrivateKey getPrivateKey(String alias) throws UnrecoverableKeyException { 064 return getPrivateKey(alias, null); 065 } 066 067 /** 068 * Sign the data with the private key specified. 069 * 070 * @param privateKey the private key 071 * @param algorithm the signing algorithm (for example SHA256withRSA) 072 * @param data the data to be signed 073 */ 074 byte[] sign(SigningServicePrivateKey privateKey, String algorithm, byte[] data) throws GeneralSecurityException; 075}