Package com.mku.salmonfs.drive
Class AesDrive
- java.lang.Object
-
- com.mku.fs.drive.VirtualDrive
-
- com.mku.salmonfs.drive.AesDrive
-
public abstract class AesDrive extends VirtualDrive
Abstract class provides an encrypted VirtualDrive that can be extended for use with any filesystem ie disk, net, cloud, etc. Each drive implementation needs a corresponding implementation ofIFile
.
-
-
Constructor Summary
Constructors Constructor Description AesDrive()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Lock the drive and close associated resources.IFile
createConfigFile(IFile realRoot)
Create the config file for this drive.static AesDrive
createDrive(IFile dir, java.lang.Class<?> driveClassType, java.lang.String password, INonceSequencer sequencer)
Create a new drive in the provided location.static java.lang.String
getAuthConfigFilename()
Get the file name for the authorization configuration .java.lang.String
getAuthId()
Get the authorization ID for the current device.byte[]
getAuthIdBytes()
Get the device authorization byte array for the current drive.byte[]
getBytesFromRealFile(IFile file, int bufferSize)
Get the byte contents of a file from the real filesystem.IFile
getConfigFile(IFile realRoot)
Get the config file for this drive.static java.lang.String
getConfigFilename()
Get the file name for the drive configuration.static java.lang.String
getDefaultAuthConfigFilename()
Get the default auth config filename.int
getDefaultFileChunkSize()
Return the default file chunk sizeprotected DriveConfig
getDriveConfig()
Return the configuration properties of this drive.byte[]
getDriveId()
Get the drive ID.IFile
getExportDir()
Return the default external export dir that all file can be exported to.static java.lang.String
getExportDirectoryName()
Get the directory name for exporting files.DriveKey
getKey()
Return the encryption key that is used for encryption / decryptionbyte[]
getNextNonce()
Get the next nonce from the sequencer.IFile
getRealRoot()
Return the real root directory of the drive.AesFile
getRoot()
Return the virtual root directory of the drive.INonceSequencer
getSequencer()
Get the nonce sequencer used for the current drive.static java.lang.String
getShareDirectoryName()
Get the directory name for sharing files.static java.lang.String
getVirtualDriveDirectoryName()
Get the directory name for the virtual drive.protected AesFile
getVirtualFile(IFile file)
Get the virtual encrypted AesFile backed by an IFile.boolean
hasConfig()
Return true if the drive is already created and has a configuration file.protected void
initFS()
Initialize the drive virtual filesystem.void
initialize(IFile realRoot, boolean createIfNotExists)
Initialize a virtual drive at the directory path providedstatic AesDrive
openDrive(IFile dir, java.lang.Class<?> driveClassType, java.lang.String password)
Set the drive location to an external directory.static AesDrive
openDrive(IFile dir, java.lang.Class<?> driveClassType, java.lang.String password, INonceSequencer sequencer)
Set the drive location to an external directory.void
revokeAuthorization()
Revoke authorization for this device.static void
setAuthConfigFilename(java.lang.String authConfigFilename)
Set the file name for the authorization configuration .static void
setConfigFilename(java.lang.String configFilename)
Set the file name for the drive configuration.void
setDefaultFileChunkSize(int fileChunkSize)
Set the default file chunk size to be used with hash integrity.static void
setExportDirectoryName(java.lang.String exportDirectoryName)
Set the directory name for exporting files.void
setPassword(java.lang.String pass)
Change the user password.void
setSequencer(INonceSequencer sequencer)
Set the nonce sequencer used for the current drive.static void
setShareDirectoryName(java.lang.String shareDirectoryName)
Set the directory name for exporting files.static void
setVirtualDriveDirectoryName(java.lang.String virtualDriveDirectoryName)
Set the directory name for the virtual drive.-
Methods inherited from class com.mku.fs.drive.VirtualDrive
getPrivateDir, onUnlockError, onUnlockSuccess
-
-
-
-
Method Detail
-
initialize
public void initialize(IFile realRoot, boolean createIfNotExists)
Initialize a virtual drive at the directory path provided- Parameters:
realRoot
- The root of the real directorycreateIfNotExists
- Create the drive if it does not exist
-
getVirtualFile
protected AesFile getVirtualFile(IFile file)
Get the virtual encrypted AesFile backed by an IFile.- Parameters:
file
- The real file.- Returns:
- The virtual file
-
getConfigFilename
public static java.lang.String getConfigFilename()
Get the file name for the drive configuration.- Returns:
- The file name.
-
setConfigFilename
public static void setConfigFilename(java.lang.String configFilename)
Set the file name for the drive configuration.- Parameters:
configFilename
- The file name
-
getAuthConfigFilename
public static java.lang.String getAuthConfigFilename()
Get the file name for the authorization configuration .- Returns:
- The file name.
-
setAuthConfigFilename
public static void setAuthConfigFilename(java.lang.String authConfigFilename)
Set the file name for the authorization configuration .- Parameters:
authConfigFilename
- The file name.
-
getVirtualDriveDirectoryName
public static java.lang.String getVirtualDriveDirectoryName()
Get the directory name for the virtual drive.- Returns:
- The directory name
-
setVirtualDriveDirectoryName
public static void setVirtualDriveDirectoryName(java.lang.String virtualDriveDirectoryName)
Set the directory name for the virtual drive.- Parameters:
virtualDriveDirectoryName
- The directory name
-
getExportDirectoryName
public static java.lang.String getExportDirectoryName()
Get the directory name for exporting files.- Returns:
- The directory name
-
setExportDirectoryName
public static void setExportDirectoryName(java.lang.String exportDirectoryName)
Set the directory name for exporting files.- Parameters:
exportDirectoryName
- The directory name.
-
getShareDirectoryName
public static java.lang.String getShareDirectoryName()
Get the directory name for sharing files.- Returns:
- The directory name.
-
setShareDirectoryName
public static void setShareDirectoryName(java.lang.String shareDirectoryName)
Set the directory name for exporting files.- Parameters:
shareDirectoryName
- The directory name.
-
getDefaultFileChunkSize
public int getDefaultFileChunkSize()
Return the default file chunk size- Returns:
- The default chunk size.
-
setDefaultFileChunkSize
public void setDefaultFileChunkSize(int fileChunkSize)
Set the default file chunk size to be used with hash integrity.- Parameters:
fileChunkSize
- The file chunk size
-
getKey
public DriveKey getKey()
Return the encryption key that is used for encryption / decryption- Returns:
- The drive key
-
setPassword
public void setPassword(java.lang.String pass) throws java.io.IOException
Change the user password.- Parameters:
pass
- The new password.- Throws:
java.io.IOException
- Thrown if there is an IO error.AuthException
- Thrown if there is an Authorization errorSecurityException
- Thrown if there is a security exceptionIntegrityException
- Thrown if the data are corrupt or tampered with.SequenceException
- Thrown if there is an error with the nonce sequence
-
initFS
protected void initFS()
Initialize the drive virtual filesystem.
-
openDrive
public static AesDrive openDrive(IFile dir, java.lang.Class<?> driveClassType, java.lang.String password) throws java.io.IOException
Set the drive location to an external directory. This requires you previously use SetDriveClass() to provide a class for the drive- Parameters:
dir
- The directory path that will be used for storing the contents of the drivedriveClassType
- The class type of the drive to open (ie: Drive.class)password
- The password- Returns:
- The drive
- Throws:
java.io.IOException
- Thrown if there is an IO error.
-
openDrive
public static AesDrive openDrive(IFile dir, java.lang.Class<?> driveClassType, java.lang.String password, INonceSequencer sequencer) throws java.io.IOException
Set the drive location to an external directory. This requires you previously use SetDriveClass() to provide a class for the drive- Parameters:
dir
- The directory path that will be used for storing the contents of the drivedriveClassType
- The class type of the drive to open (ie: Drive.class)password
- The passwordsequencer
- The sequencer to use for this drive- Returns:
- The drive
- Throws:
java.io.IOException
- Thrown if there is an IO error.
-
createDrive
public static AesDrive createDrive(IFile dir, java.lang.Class<?> driveClassType, java.lang.String password, INonceSequencer sequencer) throws java.io.IOException
Create a new drive in the provided location.- Parameters:
dir
- Directory to store the drive configuration and virtual filesystem.driveClassType
- The class type of the drive to create (ie: Drive.class)password
- The passwordsequencer
- The sequencer to use for this drive- Returns:
- The newly created drive.
- Throws:
IntegrityException
- Thrown if the data are corrupt or tampered with.SequenceException
- Thrown if there is an error with the nonce sequencejava.io.IOException
- Thrown if there is an IO error.
-
getAuthIdBytes
public byte[] getAuthIdBytes()
Get the device authorization byte array for the current drive.- Returns:
- A byte array containing device authorization id.
- Throws:
java.lang.RuntimeException
- If drive is not initialized.
-
getDefaultAuthConfigFilename
public static java.lang.String getDefaultAuthConfigFilename()
Get the default auth config filename.- Returns:
- The default auth config filename
-
revokeAuthorization
public void revokeAuthorization()
Revoke authorization for this device. This will effectively terminate write operations on the current disk by the current device. Warning: If you need to authorize write operations to the device again you will need to have another device to export an authorization config file and reimport it.- See Also:
- Salmon README.md
-
getAuthId
public java.lang.String getAuthId()
Get the authorization ID for the current device.- Returns:
- The authorization id.
- Throws:
SequenceException
- Thrown if there is an error with the nonce sequenceAuthException
- Thrown if there is an Authorization error
-
getRoot
public AesFile getRoot()
Return the virtual root directory of the drive.- Specified by:
getRoot
in classVirtualDrive
- Returns:
- The virtual root directory of the drive
- Throws:
AuthException
- Thrown if there is an Authorization error
-
getRealRoot
public IFile getRealRoot()
Return the real root directory of the drive.- Returns:
- The real root directory of the drive
-
getNextNonce
public byte[] getNextNonce()
Get the next nonce from the sequencer. This advanced the sequencer so unique nonce are used.- Returns:
- The next nonce
-
getBytesFromRealFile
public byte[] getBytesFromRealFile(IFile file, int bufferSize) throws java.io.IOException
Get the byte contents of a file from the real filesystem.- Parameters:
file
- The filebufferSize
- The buffer to be used when reading- Returns:
- The contents of the file
- Throws:
java.io.IOException
- Thrown if there is an IO error.
-
getExportDir
public IFile getExportDir()
Return the default external export dir that all file can be exported to.- Returns:
- The file on the real filesystem.
-
getDriveConfig
protected DriveConfig getDriveConfig() throws java.io.IOException
Return the configuration properties of this drive.- Returns:
- The drive configuration.
- Throws:
java.io.IOException
- Thrown if there is an IO error.
-
hasConfig
public boolean hasConfig()
Return true if the drive is already created and has a configuration file.- Returns:
- True if already created
-
getDriveId
public byte[] getDriveId()
Get the drive ID.- Returns:
- The drive ID
-
close
public void close()
Lock the drive and close associated resources.
-
getSequencer
public INonceSequencer getSequencer()
Get the nonce sequencer used for the current drive.- Returns:
- The nonce sequencer
-
setSequencer
public void setSequencer(INonceSequencer sequencer)
Set the nonce sequencer used for the current drive.- Parameters:
sequencer
- The nonce sequencer
-
createConfigFile
public IFile createConfigFile(IFile realRoot) throws java.io.IOException
Create the config file for this drive. By default the config file is placed in the real root of the vault. You can override this with your own location, make sure you also override getConfigFile().- Parameters:
realRoot
- The real root directory of the vault- Returns:
- The config file that was created
- Throws:
java.io.IOException
- If there was a problem creating the file.
-
getConfigFile
public IFile getConfigFile(IFile realRoot)
Get the config file for this drive. By default the config file is placed in the real root of the vault. You can override this with your own location.- Parameters:
realRoot
- The real root directory of the vault- Returns:
- The config file that will be used for this drive.
-
-