Package org.eclipse.ease.sign
Class PerformSignature
java.lang.Object
org.eclipse.ease.sign.PerformSignature
public class PerformSignature extends Object
Class containing methods to perform signature. Methods include loading of keystore, private key and performing signature to provided file.
-
Constructor Summary
Constructors Constructor Description PerformSignature()
-
Method Summary
Modifier and Type Method Description static String
createSignature(KeyStore keyStore, InputStream dataStream, String alias, String privateKeyPass, String provider, String messageDigestAlgo)
Initializes private key and gets signature of provided file.static Collection<String>
getAliases(KeyStore keyStore)
Gets all aliases from keystore.static String
getCertificate(KeyStore keyStore, String alias, boolean canAttachSelfSign)
Obtains certificate for corresponding alias.static KeyStore
loadKeyStore(InputStream inputStream, String type, String provider, String keyStorePass)
Checks keystore of given type and provider can be instantiated and if so, instantiates keystore.
-
Constructor Details
-
PerformSignature
public PerformSignature()
-
-
Method Details
-
loadKeyStore
public static KeyStore loadKeyStore(InputStream inputStream, String type, String provider, String keyStorePass) throws ScriptSignatureException, UnrecoverableKeyException, IOExceptionChecks keystore of given type and provider can be instantiated and if so, instantiates keystore. Then, loads the keyStore from file using provided password.- Parameters:
inputStream
- provide inputStream of keystoretype
- name type of the keystore like JKS, JCEKS, PKCS12, PKCS12S2. Providenull
or empty string or 'default' to set default typeprovider
- name provider of the keystore like SUN, SUNRsaSign, SUNJCE, etc. Providenull
or empty string or 'preferred' to let system take decisionkeyStorePass
- provide password to unlock keystore- Returns:
- instance of keystore if loaded properly
- Throws:
ScriptSignatureException
- when exception can be recovered without closing the application. For e.g., arguments provided for keystore or password are invalid, keystore file can't be read, etc.UnrecoverableKeyException
- when password for keystore is incorrectIOException
- when there is an error loading keystore because of IO of format problem
-
getAliases
Gets all aliases from keystore.- Parameters:
keyStore
- provide keystore instance to read aliases- Returns:
- collection of string of aliases in keystore or
null
if keystore is not loaded properly
-
getCertificate
public static String getCertificate(KeyStore keyStore, String alias, boolean canAttachSelfSign) throws ScriptSignatureExceptionObtains certificate for corresponding alias.- Parameters:
keyStore
- provide instance of loaded keystorealias
- provide alias of which certificate is requiredcanAttachSelfSign
- tell whether to allow to attach self-signed certificate- Returns:
- certificate chain in Base64 String format, each certificate separated by colon(:) or
null
if keystore is not initialized properly - Throws:
ScriptSignatureException
- if alias can't be found or certificate can't be loaded
-
createSignature
public static String createSignature(KeyStore keyStore, InputStream dataStream, String alias, String privateKeyPass, String provider, String messageDigestAlgo) throws ScriptSignatureException, UnrecoverableKeyExceptionInitializes private key and gets signature of provided file.- Parameters:
keyStore
- provide instance of loaded keystoredataStream
- give input stream of the script which is to be signedalias
- give alias corresponding to private key used to sign fileprivateKeyPass
- provide password protecting the private keyprovider
- give provider used to perform signature. Providenull
or empty string or 'preferred' to let system take decisionmessageDigestAlgo
- name the message-digest algorithm to perform signature. Providenull
or empty string or 'default' to chose default algorithm- Returns:
- provider of signature and signature in string Base64 format separated by colon(:) or
null
if keystore not initialized properly - Throws:
ScriptSignatureException
- if alias or privateKeyPass isnull
, signature can't be performed, password to alias is wrong, parameters for private key are wrongUnrecoverableKeyException
- when password for alias is incorrect
-