Package com.mku.salmonfs.drive
Class AesDrive
java.lang.Object
com.mku.fs.drive.VirtualDrive
com.mku.salmonfs.drive.AesDrive
- Direct Known Subclasses:
AndroidDrive,Drive,HttpDrive,WSDrive
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 of
IFile.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Lock the drive and close associated resources.createConfigFile(IFile realRoot) Create the config file for this drive.static AesDrivecreateDrive(IFile dir, Class<?> driveClassType, String password, INonceSequencer sequencer) Create a new drive in the provided location.static StringGet the file name for the authorization configuration .Get the authorization ID for the current device.byte[]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.getConfigFile(IFile realRoot) Get the config file for this drive.static StringGet the file name for the drive configuration.static StringGet the default auth config filename.intReturn the default file chunk sizeprotected DriveConfigReturn the configuration properties of this drive.byte[]Get the drive ID.Return the default external export dir that all file can be exported to.static StringGet the directory name for exporting files.getKey()Return the encryption key that is used for encryption / decryptionbyte[]Get the next nonce from the sequencer.Return the real root directory of the drive.getRoot()Return the virtual root directory of the drive.Get the nonce sequencer used for the current drive.static StringGet the directory name for sharing files.static StringGet the directory name for the virtual drive.protected AesFilegetVirtualFile(IFile file) Get the virtual encrypted AesFile backed by an IFile.booleanReturn true if the drive is already created and has a configuration file.protected voidinitFS()Initialize the drive virtual filesystem.voidinitialize(IFile realRoot, boolean createIfNotExists) Initialize a virtual drive at the directory path providedstatic AesDriveSet the drive location to an external directory.static AesDriveopenDrive(IFile dir, Class<?> driveClassType, String password, INonceSequencer sequencer) Set the drive location to an external directory.voidRevoke authorization for this device.static voidsetAuthConfigFilename(String authConfigFilename) Set the file name for the authorization configuration .static voidsetConfigFilename(String configFilename) Set the file name for the drive configuration.voidsetDefaultFileChunkSize(int fileChunkSize) Set the default file chunk size to be used with hash integrity.static voidsetExportDirectoryName(String exportDirectoryName) Set the directory name for exporting files.voidsetPassword(String pass) Change the user password.voidsetSequencer(INonceSequencer sequencer) Set the nonce sequencer used for the current drive.static voidsetShareDirectoryName(String shareDirectoryName) Set the directory name for exporting files.static voidsetVirtualDriveDirectoryName(String virtualDriveDirectoryName) Set the directory name for the virtual drive.Methods inherited from class com.mku.fs.drive.VirtualDrive
getPrivateDir, onUnlockError, onUnlockSuccess
-
Constructor Details
-
AesDrive
public AesDrive()
-
-
Method Details
-
initialize
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
Get the virtual encrypted AesFile backed by an IFile.- Parameters:
file- The real file.- Returns:
- The virtual file
-
getConfigFilename
Get the file name for the drive configuration.- Returns:
- The file name.
-
setConfigFilename
Set the file name for the drive configuration.- Parameters:
configFilename- The file name
-
getAuthConfigFilename
Get the file name for the authorization configuration .- Returns:
- The file name.
-
setAuthConfigFilename
Set the file name for the authorization configuration .- Parameters:
authConfigFilename- The file name.
-
getVirtualDriveDirectoryName
Get the directory name for the virtual drive.- Returns:
- The directory name
-
setVirtualDriveDirectoryName
Set the directory name for the virtual drive.- Parameters:
virtualDriveDirectoryName- The directory name
-
getExportDirectoryName
Get the directory name for exporting files.- Returns:
- The directory name
-
setExportDirectoryName
Set the directory name for exporting files.- Parameters:
exportDirectoryName- 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
Return the encryption key that is used for encryption / decryption- Returns:
- The drive key
-
setPassword
Change the user password.- Parameters:
pass- The new password.- Throws:
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, Class<?> driveClassType, String password) throws 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:
IOException- Thrown if there is an IO error.
-
openDrive
public static AesDrive openDrive(IFile dir, Class<?> driveClassType, String password, INonceSequencer sequencer) throws 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:
IOException- Thrown if there is an IO error.
-
createDrive
public static AesDrive createDrive(IFile dir, Class<?> driveClassType, String password, INonceSequencer sequencer) throws 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 sequenceIOException- 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:
RuntimeException- If drive is not initialized.
-
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:
-
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
Return the virtual root directory of the drive.- Specified by:
getRootin classVirtualDrive- Returns:
- The virtual root directory of the drive
- Throws:
AuthException- Thrown if there is an Authorization error
-
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
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:
IOException- Thrown if there is an IO error.
-
getExportDir
Return the default external export dir that all file can be exported to.- Returns:
- The file on the real filesystem.
-
getDriveConfig
Return the configuration properties of this drive.- Returns:
- The drive configuration.
- Throws:
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
Get the nonce sequencer used for the current drive.- Returns:
- The nonce sequencer
-
setSequencer
Set the nonce sequencer used for the current drive.- Parameters:
sequencer- The nonce sequencer
-
createConfigFile
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:
IOException- If there was a problem creating the file.
-
getConfigFile
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.
-