// check if this is a external key encryption and
// if it replace the current verify key file with
// the old copy.
StorageFile verifyKeyFile =
storageFactory.newStorageFile(
Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE);
if (privExists(verifyKeyFile))
{
StorageFile oldVerifyKeyFile =
storageFactory.newStorageFile(
RawStoreFactory.CRYPTO_OLD_EXTERNAL_KEY_VERIFY_FILE);
if (privExists(oldVerifyKeyFile))
{
if(!privCopyFile(oldVerifyKeyFile, verifyKeyFile))
throw StandardException.
newException(SQLState.RAWSTORE_ERROR_COPYING_FILE,
oldVerifyKeyFile, verifyKeyFile);
// only incase of re-encryption there should
// be old verify key file.
reEncryption = true;
}else
{
// remove the verify key file.
if (!privDelete(verifyKeyFile))
throw StandardException.newException(
SQLState.UNABLE_TO_DELETE_FILE,
verifyKeyFile);
}
} else
{
// database enrypted with boot password.
// replace the current encryption key with the old key
// in the service.properties file.
// retreive the old encryption key
String OldKeyString =
properties.getProperty(RawStoreFactory.OLD_ENCRYPTED_KEY);
if (OldKeyString != null) {
// set the current encrypted key to the old one.
properties.put(RawStoreFactory.ENCRYPTED_KEY,
OldKeyString);
// only incase of re-encryption there should
// be old encryted key .
reEncryption = true;
}
}
if (!reEncryption) {
// crash occured when database was getting reconfigured
// for encryption , all encryption properties should be
// removed from service.properties
// common props for external key or password.
properties.remove(Attribute.DATA_ENCRYPTION);
properties.remove(RawStoreFactory.LOG_ENCRYPT_ALGORITHM_VERSION);
properties.remove(RawStoreFactory.DATA_ENCRYPT_ALGORITHM_VERSION);
properties.remove(RawStoreFactory.ENCRYPTION_BLOCKSIZE);
// properties specific to password based encryption.
properties.remove(Attribute.CRYPTO_KEY_LENGTH);
properties.remove(Attribute.CRYPTO_PROVIDER);
properties.remove(Attribute.CRYPTO_ALGORITHM);
properties.remove(RawStoreFactory.ENCRYPTED_KEY);
}
if (SanityManager.DEBUG) {
crashOnDebugFlag(
TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_REVERTING_KEY,
reEncryption);
}
} // end of UNDO
if (dbEncryptionStatus == RawStoreFactory.DB_ENCRYPTION_IN_CLEANUP)
{
// remove all the old versions of the containers.
dataFactory.removeOldVersionOfContainers(true);
}
if (SanityManager.DEBUG) {
crashOnDebugFlag(
TEST_REENCRYPT_CRASH_BEFORE_RECOVERY_FINAL_CLEANUP,
reEncryption);
}
// either the (re) encryption was complete ,
// or undone (except for rollback that needs to be
// done by the recovery). Remove re-encryption specific
// flags from the service.properties and old copy
// of the verify key file.
// delete the old verify key file , if it exists.
StorageFile oldVerifyKeyFile =
storageFactory.newStorageFile(
RawStoreFactory.CRYPTO_OLD_EXTERNAL_KEY_VERIFY_FILE);
if (privExists(oldVerifyKeyFile))
{
if (!privDelete(oldVerifyKeyFile))