Class AesDrive

java.lang.Object
com.mku.fs.drive.VirtualDrive
com.mku.salmonfs.drive.AesDrive
Direct Known Subclasses:
AndroidDrive, Drive, HttpDrive, WSDrive

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 of IFile.
  • Constructor Details

    • AesDrive

      public AesDrive()
  • Method Details

    • initialize

      public void initialize(IFile realRoot, boolean createIfNotExists)
      Initialize a virtual drive at the directory path provided
      Parameters:
      realRoot - The root of the real directory
      createIfNotExists - 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 String getConfigFilename()
      Get the file name for the drive configuration.
      Returns:
      The file name.
    • setConfigFilename

      public static void setConfigFilename(String configFilename)
      Set the file name for the drive configuration.
      Parameters:
      configFilename - The file name
    • getAuthConfigFilename

      public static String getAuthConfigFilename()
      Get the file name for the authorization configuration .
      Returns:
      The file name.
    • setAuthConfigFilename

      public static void setAuthConfigFilename(String authConfigFilename)
      Set the file name for the authorization configuration .
      Parameters:
      authConfigFilename - The file name.
    • getVirtualDriveDirectoryName

      public static String getVirtualDriveDirectoryName()
      Get the directory name for the virtual drive.
      Returns:
      The directory name
    • setVirtualDriveDirectoryName

      public static void setVirtualDriveDirectoryName(String virtualDriveDirectoryName)
      Set the directory name for the virtual drive.
      Parameters:
      virtualDriveDirectoryName - The directory name
    • getExportDirectoryName

      public static String getExportDirectoryName()
      Get the directory name for exporting files.
      Returns:
      The directory name
    • setExportDirectoryName

      public static void setExportDirectoryName(String exportDirectoryName)
      Set the directory name for exporting files.
      Parameters:
      exportDirectoryName - The directory name.
    • getShareDirectoryName

      public static String getShareDirectoryName()
      Get the directory name for sharing files.
      Returns:
      The directory name.
    • setShareDirectoryName

      public static void setShareDirectoryName(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(String pass) throws IOException
      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 error
      SecurityException - Thrown if there is a security exception
      IntegrityException - 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 drive
      driveClassType - 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 drive
      driveClassType - The class type of the drive to open (ie: Drive.class)
      password - The password
      sequencer - 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 password
      sequencer - 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 sequence
      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:
      RuntimeException - If drive is not initialized.
    • getDefaultAuthConfigFilename

      public static 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:
    • getAuthId

      public 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 sequence
      AuthException - Thrown if there is an Authorization error
    • getRoot

      public AesFile getRoot()
      Return the virtual root directory of the drive.
      Specified by:
      getRoot in class VirtualDrive
      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 IOException
      Get the byte contents of a file from the real filesystem.
      Parameters:
      file - The file
      bufferSize - The buffer to be used when reading
      Returns:
      The contents of the file
      Throws:
      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 IOException
      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

      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 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:
      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.