public class KeyStorer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
ALGORITHM |
private static int |
ITERATIONS
Parameters used to configure the Password Based Encryption of the keystore
|
private KeyDB |
keyDB |
private java.security.KeyStore |
keyStore |
private static java.lang.String |
KEYSTORE_FORMAT |
private static java.lang.String |
KEYSTORE_PASSWORD |
private static java.lang.String |
PASSWORD_PROTECTION_ALGORITHM |
private static java.lang.String |
PRIVATE_KEY_ALIAS |
private static int |
SALT_SIZE
Salt Size.
|
Constructor and Description |
---|
KeyStorer(DatabaseConnection databaseConnection)
Loads the keystore file and does setup using the database connection.
|
Modifier and Type | Method and Description |
---|---|
private byte[] |
createSalt()
Create a salt that is used to protect the data from rainbow/dictionary attacks
|
private void |
deleteAllPublicInfo(User updatedUser)
Delete user's salt, RSA public key and encrypted AES key .
|
private void |
deletePrivateKey(User oldUser)
Delete the user's RSA private key
|
private java.lang.String |
getAliasForPrivateKey(User user)
Returns the alias for the user's private key - the alias is used to store/fetch the key in the keystore.jks file
|
byte[] |
getEncryptedAESKey(User user)
Return user's encrypted AES key
|
java.security.KeyPair |
getKeyPair(User user)
Return the user's RSA key pair
|
private static java.io.InputStream |
getKeystoreFileInputStream() |
private java.io.OutputStream |
getKeystoreOutputStream()
Returns an output stream to the keystore.jks file
|
static java.io.InputStream |
getKeystoreResourceInputStream()
Gets an InputStream to the keystore resource
|
private java.security.KeyStore.PasswordProtection |
getPasswordProtection(java.lang.String password,
byte[] salt)
Return password protection used for the user in the keystore
|
private java.security.PrivateKey |
getPrivateKey(User user)
Return user's RSA private key
|
void |
storeAllKeys(java.security.KeyPair keyPair,
byte[] encryptedAESKey,
User user)
Store the user's key chain (RSA keypair, encrypted AES key and salt)
|
private void |
storePrivateKey(java.security.PrivateKey privateKey,
User user,
byte[] salt)
Store user's private key in the keystore.jks file
|
void |
updateAllKeys(java.security.KeyPair keyPair,
byte[] encryptedAesKey,
User oldUser,
User updatedUser)
Update user's keys (required when they change their password or username).
|
private static final int SALT_SIZE
private static final int ITERATIONS
private static final java.lang.String KEYSTORE_FORMAT
private static final java.lang.String ALGORITHM
private static final java.lang.String PRIVATE_KEY_ALIAS
private static final java.lang.String PASSWORD_PROTECTION_ALGORITHM
private static final java.lang.String KEYSTORE_PASSWORD
private java.security.KeyStore keyStore
private KeyDB keyDB
public KeyStorer(DatabaseConnection databaseConnection)
databaseConnection
- private static java.io.InputStream getKeystoreFileInputStream()
public java.security.KeyPair getKeyPair(User user) throws NoKeyPairPresentException, DatabaseException
user
- NoKeyPairPresentException
DatabaseException
private java.security.PrivateKey getPrivateKey(User user) throws NoSuchKeysFoundForUserException, DatabaseException, java.security.NoSuchAlgorithmException, java.security.UnrecoverableEntryException, java.security.KeyStoreException
user
- NoSuchKeysFoundForUserException
DatabaseException
java.security.NoSuchAlgorithmException
java.security.UnrecoverableEntryException
java.security.KeyStoreException
private java.lang.String getAliasForPrivateKey(User user)
user
- public byte[] getEncryptedAESKey(User user) throws DatabaseException, NoSuchKeysFoundForUserException
user
- DatabaseException
NoSuchKeysFoundForUserException
private java.security.KeyStore.PasswordProtection getPasswordProtection(java.lang.String password, byte[] salt)
password
- salt
- public static java.io.InputStream getKeystoreResourceInputStream()
private java.io.OutputStream getKeystoreOutputStream()
public void storeAllKeys(java.security.KeyPair keyPair, byte[] encryptedAESKey, User user) throws UserAlreadyHasKeysException
keyPair
- encryptedAESKey
- user
- UserAlreadyHasKeysException
private void storePrivateKey(java.security.PrivateKey privateKey, User user, byte[] salt) throws java.security.KeyStoreException
privateKey
- user
- salt
- java.security.KeyStoreException
private byte[] createSalt()
public void updateAllKeys(java.security.KeyPair keyPair, byte[] encryptedAesKey, User oldUser, User updatedUser)
keyPair
- encryptedAesKey
- oldUser
- updatedUser
- private void deleteAllPublicInfo(User updatedUser) throws NoSuchKeysFoundForUserException
updatedUser
- NoSuchKeysFoundForUserException
private void deletePrivateKey(User oldUser) throws java.security.KeyStoreException
oldUser
- java.security.KeyStoreException