Package org.opendaylight.aaa.cert.impl
Class ODLKeyTool
- java.lang.Object
-
- org.opendaylight.aaa.cert.impl.ODLKeyTool
-
public class ODLKeyTool extends Object
ODLKeyTool implements the basic operations that manage the Java keyStores such as create, generate, add and delete certificates.- Author:
- mserngawy
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ODLKeyTool()
ODLKeyTool(String workingDirectory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyStore
addCertificate(KeyStore keyStore, String certificate, String alias, boolean deleteOld)
Add certificate to the given keystore.byte[]
convertKeystoreToBytes(KeyStore keyStore, String keystorePassword)
Convert the given java keystore object to byte array.KeyStore
createEmptyKeyStore(String keystorePassword)
Create empty keystore does not has private or public key.KeyStore
createKeyStoreWithSelfSignCert(String keyStoreName, String keystorePassword, String distinguishedName, String keyAlias, int validity)
Create a keystore that has self sign private/public keys using the default key algorithm (RSA), size (2048) and signing algorithm (SHA1WithRSAEncryption).KeyStore
createKeyStoreWithSelfSignCert(String keyStoreName, String keystorePassword, String distinguishedName, String keyAlias, int validity, String keyAlg, int keySize, String signAlg)
Create a keystore that has self sign private/public keys.boolean
exportKeystore(KeyStore keystore, String keystorePassword, String fileName)
Export the given keystore as a file under the working directory.String
generateCertificateReq(KeyStore keyStore, String keystorePassword, String keyAlias, String signAlg, boolean withTag)
Generate a certificate signing request based on the given keystore private/public key.String
getCertificate(KeyStore keyStore, String certAlias, boolean withTag)
Get a certificate as String based on the given alias.KeyStore
loadKeyStore(byte[] keyStoreBytes, String keystorePassword)
Load the keystore object from the given byte array.KeyStore
loadKeyStore(String keyStoreName, String keystorePassword)
Load the keystore from the working directory.
-
-
-
Constructor Detail
-
ODLKeyTool
protected ODLKeyTool()
-
ODLKeyTool
public ODLKeyTool(String workingDirectory)
-
-
Method Detail
-
addCertificate
public KeyStore addCertificate(KeyStore keyStore, String certificate, String alias, boolean deleteOld)
Add certificate to the given keystore.- Parameters:
keyStore
- java keystore objectcertificate
- to add as stringalias
- of the certificatedeleteOld
- true to delete the old certificate that has the same alias otherwise it will fail if there is a certificate has same given alias.- Returns:
- the given Keystore containing the certificate otherwise return null.
-
convertKeystoreToBytes
public byte[] convertKeystoreToBytes(KeyStore keyStore, String keystorePassword)
Convert the given java keystore object to byte array.- Parameters:
keyStore
- objectkeystorePassword
- the password of the given keystore- Returns:
- byte array
-
createKeyStoreWithSelfSignCert
public KeyStore createKeyStoreWithSelfSignCert(String keyStoreName, String keystorePassword, String distinguishedName, String keyAlias, int validity)
Create a keystore that has self sign private/public keys using the default key algorithm (RSA), size (2048) and signing algorithm (SHA1WithRSAEncryption).- Parameters:
keyStoreName
- the keystore namekeystorePassword
- the keystore passworddistinguishedName
- the generated key's Distinguished NamekeyAlias
- the private key aliasvalidity
- the key validity- Returns:
- keystore object
-
createKeyStoreWithSelfSignCert
public KeyStore createKeyStoreWithSelfSignCert(String keyStoreName, String keystorePassword, String distinguishedName, String keyAlias, int validity, String keyAlg, int keySize, String signAlg)
Create a keystore that has self sign private/public keys.- Parameters:
keyStoreName
- the keystore namekeystorePassword
- the keystore passworddistinguishedName
- the generated key's Distinguished NamekeyAlias
- the private key aliasvalidity
- the key validitykeyAlg
- the algorithm that will be used to generate the keykeySize
- the key sizesignAlg
- the signing algorithm- Returns:
- keystore object
-
createEmptyKeyStore
public KeyStore createEmptyKeyStore(String keystorePassword)
Create empty keystore does not has private or public key.- Parameters:
keystorePassword
- the keystore password- Returns:
- keystore object
-
exportKeystore
public boolean exportKeystore(KeyStore keystore, String keystorePassword, String fileName)
Export the given keystore as a file under the working directory.- Parameters:
keystore
- objectkeystorePassword
- the keystore passwordfileName
- of the keystore- Returns:
- true if successes to export the keystore
-
generateCertificateReq
public String generateCertificateReq(KeyStore keyStore, String keystorePassword, String keyAlias, String signAlg, boolean withTag)
Generate a certificate signing request based on the given keystore private/public key.- Parameters:
keyStore
- objectkeystorePassword
- the keystore passwordkeyAlias
- Alias of the given keystore's private key.signAlg
- the signing algorithmwithTag
- true to add the certificate request tag to the certificate request string.- Returns:
- certificate request as string.
-
getCertificate
public String getCertificate(KeyStore keyStore, String certAlias, boolean withTag)
Get a certificate as String based on the given alias.- Parameters:
keyStore
- keystore that has the certificatecertAlias
- certificate aliaswithTag
- true to add the certificate tag to the certificate string.- Returns:
- certificate as string.
-
loadKeyStore
public KeyStore loadKeyStore(byte[] keyStoreBytes, String keystorePassword)
Load the keystore object from the given byte array.- Parameters:
keyStoreBytes
- array of byte contain keystore objectkeystorePassword
- the keystore password- Returns:
- keystore object otherwise return null if it fails to load.
-
-