Package org.cryptomator.cryptofs
Class CryptoFileSystemProvider
- java.lang.Object
-
- java.nio.file.spi.FileSystemProvider
-
- org.cryptomator.cryptofs.CryptoFileSystemProvider
-
public class CryptoFileSystemProvider extends FileSystemProvider
A
FileSystemProviderforCryptoFileSystems.All
FileSysteminstances created byCryptoFileSystemProviderare instances ofCryptoFileSystem. UsageIt is recommended to use
newFileSystem(Path, CryptoFileSystemProperties)to create a CryptoFileSystem. To do this:Path storageLocation = Paths.get("/home/cryptobot/vault"); FileSystem fileSystem = CryptoFileSystemProvider.newFileSystem( storageLocation,cryptoFileSystemProperties().withPassword("password") .withFlags(FileSystemFlags.READONLY) .build());Afterwards you can use the created
FileSystemto create paths, do directory listings, create files and so on.To create a new FileSystem from a URI using
FileSystems.newFileSystem(URI, Map)you may have a look atCryptoFileSystemUri.
-
-
Constructor Summary
Constructors Constructor Description CryptoFileSystemProvider()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidchangePassphrase(Path pathToVault, String masterkeyFilename, byte[] pepper, CharSequence oldPassphrase, CharSequence newPassphrase)Changes the passphrase of a vault at the given path.static voidchangePassphrase(Path pathToVault, String masterkeyFilename, CharSequence oldPassphrase, CharSequence newPassphrase)Changes the passphrase of a vault at the given path.voidcheckAccess(Path cleartextPath, AccessMode... modes)static booleancontainsVault(Path pathToVault, String masterkeyFilename)Checks if the folder represented by the given path exists and contains a valid vault structure.voidcopy(Path cleartextSource, Path cleartextTarget, CopyOption... options)voidcreateDirectory(Path cleartextDir, FileAttribute<?>... attrs)voidcreateSymbolicLink(Path cleartextPath, Path target, FileAttribute<?>... attrs)voiddelete(Path cleartextPath)static byte[]exportRawKey(Path pathToVault, String masterkeyFilename, byte[] pepper, CharSequence passphrase)Exports the raw key for backup purposes or external key management.<V extends FileAttributeView>
VgetFileAttributeView(Path cleartextPath, Class<V> type, LinkOption... options)FileStoregetFileStore(Path cleartextPath)CryptoFileSystemgetFileSystem(URI uri)PathgetPath(URI uri)StringgetScheme()static voidinitialize(Path pathToVault, String masterkeyFilename, byte[] pepper, CharSequence passphrase)Creates a new vault at the given directory path.static voidinitialize(Path pathToVault, String masterkeyFilename, CharSequence passphrase)Creates a new vault at the given directory path.booleanisHidden(Path cleartextPath)booleanisSameFile(Path cleartextPath, Path cleartextPath2)voidmove(Path cleartextSource, Path cleartextTarget, CopyOption... options)AsynchronousFileChannelnewAsynchronousFileChannel(Path cleartextPath, Set<? extends OpenOption> options, ExecutorService executor, FileAttribute<?>... attrs)SeekableByteChannelnewByteChannel(Path cleartextPath, Set<? extends OpenOption> options, FileAttribute<?>... attrs)DirectoryStream<Path>newDirectoryStream(Path cleartextDir, DirectoryStream.Filter<? super Path> filter)FileChannelnewFileChannel(Path cleartextPath, Set<? extends OpenOption> optionsSet, FileAttribute<?>... attrs)CryptoFileSystemnewFileSystem(URI uri, Map<String,?> rawProperties)static CryptoFileSystemnewFileSystem(Path pathToVault, CryptoFileSystemProperties properties)Typesafe alternative toFileSystems.newFileSystem(URI, Map).<A extends BasicFileAttributes>
AreadAttributes(Path cleartextPath, Class<A> type, LinkOption... options)Map<String,Object>readAttributes(Path cleartextPath, String attributes, LinkOption... options)PathreadSymbolicLink(Path cleartextPath)static voidrestoreRawKey(Path pathToVault, String masterkeyFilename, byte[] rawKey, byte[] pepper, CharSequence passphrase)Imports a raw key from backup or external key management.voidsetAttribute(Path cleartextPath, String attribute, Object value, LinkOption... options)-
Methods inherited from class java.nio.file.spi.FileSystemProvider
createLink, deleteIfExists, installedProviders, newFileSystem, newInputStream, newOutputStream
-
-
-
-
Method Detail
-
newFileSystem
public static CryptoFileSystem newFileSystem(Path pathToVault, CryptoFileSystemProperties properties) throws FileSystemNeedsMigrationException, IOException
Typesafe alternative toFileSystems.newFileSystem(URI, Map). Default way to retrieve a CryptoFS instance.- Parameters:
pathToVault- Path to this vault's storage locationproperties- Parameters used during initialization of the file system- Returns:
- a new file system
- Throws:
FileSystemNeedsMigrationException- if the vault format needs to get updated andpropertiesdid not contain a flag for implicit migration.FileSystemCapabilityChecker.MissingCapabilityException- If the underlying filesystem lacks features required to store a vaultIOException- if an I/O error occurs creating the file system
-
initialize
public static void initialize(Path pathToVault, String masterkeyFilename, CharSequence passphrase) throws NotDirectoryException, IOException
Creates a new vault at the given directory path.- Parameters:
pathToVault- Path to a not yet existing directorymasterkeyFilename- Name of the masterkey filepassphrase- Passphrase that should be used to unlock the vault- Throws:
NotDirectoryException- If the given path is not an existing directory.FileSystemCapabilityChecker.MissingCapabilityException- If the underlying filesystem lacks features required to store a vaultIOException- If the vault structure could not be initialized due to I/O errors- Since:
- 1.3.0
-
initialize
public static void initialize(Path pathToVault, String masterkeyFilename, byte[] pepper, CharSequence passphrase) throws NotDirectoryException, IOException
Creates a new vault at the given directory path.- Parameters:
pathToVault- Path to a not yet existing directorymasterkeyFilename- Name of the masterkey filepepper- Application-specific pepper used during key derivationpassphrase- Passphrase that should be used to unlock the vault- Throws:
NotDirectoryException- If the given path is not an existing directory.FileSystemCapabilityChecker.MissingCapabilityException- If the underlying filesystem lacks features required to store a vaultIOException- If the vault structure could not be initialized due to I/O errors- Since:
- 1.3.2
-
containsVault
public static boolean containsVault(Path pathToVault, String masterkeyFilename)
Checks if the folder represented by the given path exists and contains a valid vault structure.- Parameters:
pathToVault- A directory pathmasterkeyFilename- Name of the masterkey file- Returns:
trueif the directory seems to contain a vault.- Since:
- 1.1.0
-
changePassphrase
public static void changePassphrase(Path pathToVault, String masterkeyFilename, CharSequence oldPassphrase, CharSequence newPassphrase) throws org.cryptomator.cryptolib.api.InvalidPassphraseException, FileSystemNeedsMigrationException, IOException
Changes the passphrase of a vault at the given path.- Parameters:
pathToVault- Vault directorymasterkeyFilename- Name of the masterkey fileoldPassphrase- Current passphrasenewPassphrase- Future passphrase- Throws:
org.cryptomator.cryptolib.api.InvalidPassphraseException- IfoldPassphrasecan not be used to unlock the vault.FileSystemNeedsMigrationException- if the vault format needs to get updated.IOException- If the masterkey could not be read or written.- Since:
- 1.1.0
- See Also:
changePassphrase(Path, String, byte[], CharSequence, CharSequence)
-
changePassphrase
public static void changePassphrase(Path pathToVault, String masterkeyFilename, byte[] pepper, CharSequence oldPassphrase, CharSequence newPassphrase) throws org.cryptomator.cryptolib.api.InvalidPassphraseException, FileSystemNeedsMigrationException, IOException
Changes the passphrase of a vault at the given path.- Parameters:
pathToVault- Vault directorymasterkeyFilename- Name of the masterkey filepepper- An application-specific pepper added to the salt during key-derivation (if applicable)oldPassphrase- Current passphrasenewPassphrase- Future passphrase- Throws:
org.cryptomator.cryptolib.api.InvalidPassphraseException- IfoldPassphrasecan not be used to unlock the vault.FileSystemNeedsMigrationException- if the vault format needs to get updated.IOException- If the masterkey could not be read or written.- Since:
- 1.4.0
-
exportRawKey
public static byte[] exportRawKey(Path pathToVault, String masterkeyFilename, byte[] pepper, CharSequence passphrase) throws org.cryptomator.cryptolib.api.InvalidPassphraseException, IOException
Exports the raw key for backup purposes or external key management.- Parameters:
pathToVault- Vault directorymasterkeyFilename- Name of the masterkey filepepper- An application-specific pepper added to the salt during key-derivation (if applicable)passphrase- Current passphrase- Returns:
- A 64 byte array consisting of 32 byte aes key and 32 byte mac key
- Throws:
org.cryptomator.cryptolib.api.InvalidPassphraseExceptionIOException- Since:
- 1.9.0
-
restoreRawKey
public static void restoreRawKey(Path pathToVault, String masterkeyFilename, byte[] rawKey, byte[] pepper, CharSequence passphrase) throws org.cryptomator.cryptolib.api.InvalidPassphraseException, IOException
Imports a raw key from backup or external key management.- Parameters:
pathToVault- Vault directorymasterkeyFilename- Name of the masterkey filepepper- An application-specific pepper added to the salt during key-derivation (if applicable)passphrase- Future passphrase- Throws:
org.cryptomator.cryptolib.api.InvalidPassphraseExceptionIOException- Since:
- 1.9.0
-
getScheme
public String getScheme()
- Specified by:
getSchemein classFileSystemProvider
-
newFileSystem
public CryptoFileSystem newFileSystem(URI uri, Map<String,?> rawProperties) throws IOException
- Specified by:
newFileSystemin classFileSystemProvider- Throws:
IOException
-
getFileSystem
public CryptoFileSystem getFileSystem(URI uri)
- Specified by:
getFileSystemin classFileSystemProvider
-
getPath
public Path getPath(URI uri)
- Specified by:
getPathin classFileSystemProvider
-
newAsynchronousFileChannel
public AsynchronousFileChannel newAsynchronousFileChannel(Path cleartextPath, Set<? extends OpenOption> options, ExecutorService executor, FileAttribute<?>... attrs) throws IOException
- Overrides:
newAsynchronousFileChannelin classFileSystemProvider- Throws:
IOException
-
newFileChannel
public FileChannel newFileChannel(Path cleartextPath, Set<? extends OpenOption> optionsSet, FileAttribute<?>... attrs) throws IOException
- Overrides:
newFileChannelin classFileSystemProvider- Throws:
IOException
-
newByteChannel
public SeekableByteChannel newByteChannel(Path cleartextPath, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException
- Specified by:
newByteChannelin classFileSystemProvider- Throws:
IOException
-
newDirectoryStream
public DirectoryStream<Path> newDirectoryStream(Path cleartextDir, DirectoryStream.Filter<? super Path> filter) throws IOException
- Specified by:
newDirectoryStreamin classFileSystemProvider- Throws:
IOException
-
createDirectory
public void createDirectory(Path cleartextDir, FileAttribute<?>... attrs) throws IOException
- Specified by:
createDirectoryin classFileSystemProvider- Throws:
IOException
-
delete
public void delete(Path cleartextPath) throws IOException
- Specified by:
deletein classFileSystemProvider- Throws:
IOException
-
copy
public void copy(Path cleartextSource, Path cleartextTarget, CopyOption... options) throws IOException
- Specified by:
copyin classFileSystemProvider- Throws:
IOException
-
move
public void move(Path cleartextSource, Path cleartextTarget, CopyOption... options) throws IOException
- Specified by:
movein classFileSystemProvider- Throws:
IOException
-
isSameFile
public boolean isSameFile(Path cleartextPath, Path cleartextPath2) throws IOException
- Specified by:
isSameFilein classFileSystemProvider- Throws:
IOException
-
isHidden
public boolean isHidden(Path cleartextPath) throws IOException
- Specified by:
isHiddenin classFileSystemProvider- Throws:
IOException
-
getFileStore
public FileStore getFileStore(Path cleartextPath) throws IOException
- Specified by:
getFileStorein classFileSystemProvider- Throws:
IOException
-
checkAccess
public void checkAccess(Path cleartextPath, AccessMode... modes) throws IOException
- Specified by:
checkAccessin classFileSystemProvider- Throws:
IOException
-
createSymbolicLink
public void createSymbolicLink(Path cleartextPath, Path target, FileAttribute<?>... attrs) throws IOException
- Overrides:
createSymbolicLinkin classFileSystemProvider- Throws:
IOException
-
readSymbolicLink
public Path readSymbolicLink(Path cleartextPath) throws IOException
- Overrides:
readSymbolicLinkin classFileSystemProvider- Throws:
IOException
-
getFileAttributeView
public <V extends FileAttributeView> V getFileAttributeView(Path cleartextPath, Class<V> type, LinkOption... options)
- Specified by:
getFileAttributeViewin classFileSystemProvider
-
readAttributes
public <A extends BasicFileAttributes> A readAttributes(Path cleartextPath, Class<A> type, LinkOption... options) throws IOException
- Specified by:
readAttributesin classFileSystemProvider- Throws:
IOException
-
readAttributes
public Map<String,Object> readAttributes(Path cleartextPath, String attributes, LinkOption... options) throws IOException
- Specified by:
readAttributesin classFileSystemProvider- Throws:
IOException
-
setAttribute
public void setAttribute(Path cleartextPath, String attribute, Object value, LinkOption... options) throws IOException
- Specified by:
setAttributein classFileSystemProvider- Throws:
IOException
-
-