Top Description Fields Constructors Methods
org.apache.derby.impl.store.raw.data

public Class EncryptOrDecryptData

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.shared.common.error.StandardException, org.apache.derby.iapi.store.raw.data.RawContainerHandle, org.apache.derby.iapi.store.raw.ContainerKey, .LockingPolicy, .ContainerHandle, org.apache.derby.iapi.store.raw.xact.RawTransaction, org.apache.derby.iapi.store.access.TransactionController, org.apache.derby.io.StorageFactory, .StorageFile

This class is used to encrypt all the containers in the data segment with a new encryption key when password/key is changed or when an existing database is reconfigured for encryption. Encryption of existing data in the data segments is done by doing the following: Find all the containers in data segment (seg0) and encrypt all of them with the new encryption key, the process for each container is: 1.Write a log record to indicate that the container is getting encrypted. 2.Read all the pages of the container through the page cache and encrypt each page with new encryption key and then write to a temporary file(n.dat) in the data segment itself. 3. Rename the current container file (c.dat) to another file (o.dat) 4. Rename the new encrypted version of the file (n<cid).dat) to be the current container file (c.dat). 5. All the old version of the container (o.dat) files are removed after a successful checkpoint with a new key or on a rollback.

Field Summary

Modifier and TypeField and Description
private int
private StorageFile
private StorageFile
private BaseDataFileFactory
private static final int
private static final int
private static final int
private StorageFactory

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
decryptAllContainers(RawTransaction
the transaction that is used for the decryption operation
t
)

Finds all the all the containers stored in the data directory and decrypts them.

public void
encryptAllContainers(RawTransaction
the transaction that is used for the encryption operation
t
)

Find all the all the containers stored in the data directory and encrypt them.

private void
encryptOrDecryptAllContainers(RawTransaction
transaction used for the cryptographic operation
t
,
boolean
tells whether to encrypt or decrypt
doEncrypt
)

Encrypts or decrypts all containers in the database data directory.

private void
encryptOrDecryptContainer(RawTransaction
transaction that used to perform the cryptographic operation
t
,
ContainerKey
the key of the container that is being encrypted/decrypted
ckey
,
boolean
tells whether to encrypt or decrypt
doEncrypt
)

Encrypts or decrypts the specified container.

private StorageFile
getFile(ContainerKey containerId, boolean old)

Get file handle to a container file that is used to keep temporary versions of the container file.

private StorageFile
getFile(String ctrFileName)

private String
getFilePath(ContainerKey containerId, boolean old)

Get path to a container file that is used to keep temporary versions of the container file.

private boolean
private synchronized boolean
private synchronized boolean
private synchronized boolean
privRename(StorageFile fromFile, StorageFile destFile)

public void
removeOldVersionOfContainers()

Removes old versions of the containers after a cryptographic operation on the database.

pack-priv void
public Boolean
run()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actionCodeback to summary
private int actionCode
actionDestStorageFileback to summary
private StorageFile actionDestStorageFile
actionStorageFileback to summary
private StorageFile actionStorageFile
dataFactoryback to summary
private BaseDataFileFactory dataFactory
STORAGE_FILE_DELETE_ACTIONback to summary
private static final int STORAGE_FILE_DELETE_ACTION
STORAGE_FILE_EXISTS_ACTIONback to summary
private static final int STORAGE_FILE_EXISTS_ACTION
STORAGE_FILE_RENAME_ACTIONback to summary
private static final int STORAGE_FILE_RENAME_ACTION
storageFactoryback to summary
private StorageFactory storageFactory

Constructor Detail

EncryptOrDecryptDataback to summary
public EncryptOrDecryptData(BaseDataFileFactory dataFactory)

Method Detail

decryptAllContainersback to summary
public void decryptAllContainers(RawTransaction t) throws StandardException

Finds all the all the containers stored in the data directory and decrypts them.

Parameters
t:RawTransaction

the transaction that is used for the decryption operation

Exceptions
StandardException:
Standard Derby error policy
encryptAllContainersback to summary
public void encryptAllContainers(RawTransaction t) throws StandardException

Find all the all the containers stored in the data directory and encrypt them.

Parameters
t:RawTransaction

the transaction that is used for the encryption operation

Exceptions
StandardException:
Standard Derby error policy
encryptOrDecryptAllContainersback to summary
private void encryptOrDecryptAllContainers(RawTransaction t, boolean doEncrypt) throws StandardException

Encrypts or decrypts all containers in the database data directory.

Parameters
t:RawTransaction

transaction used for the cryptographic operation

doEncrypt:boolean

tells whether to encrypt or decrypt

Exceptions
StandardException:
Standard Derby error policy
encryptOrDecryptContainerback to summary
private void encryptOrDecryptContainer(RawTransaction t, ContainerKey ckey, boolean doEncrypt) throws StandardException

Encrypts or decrypts the specified container.

Parameters
t:RawTransaction

transaction that used to perform the cryptographic operation

ckey:ContainerKey

the key of the container that is being encrypted/decrypted

doEncrypt:boolean

tells whether to encrypt or decrypt

Exceptions
StandardException:
Standard Derby error policy
getFileback to summary
private StorageFile getFile(ContainerKey containerId, boolean old)

Get file handle to a container file that is used to keep temporary versions of the container file.

getFileback to summary
private StorageFile getFile(String ctrFileName)
getFilePathback to summary
private String getFilePath(ContainerKey containerId, boolean old)

Get path to a container file that is used to keep temporary versions of the container file.

isOldContainerFileback to summary
private boolean isOldContainerFile(String fileName)
privDeleteback to summary
private synchronized boolean privDelete(StorageFile file)
privExistsback to summary
private synchronized boolean privExists(StorageFile file)
privRenameback to summary
private synchronized boolean privRename(StorageFile fromFile, StorageFile destFile)
removeOldVersionOfContainersback to summary
public void removeOldVersionOfContainers() throws StandardException

Removes old versions of the containers after a cryptographic operation on the database.

restoreContainerback to summary
pack-priv void restoreContainer(ContainerKey containerId) throws StandardException
runback to summary
public Boolean run()