@Test public void testCreate() throws Exception { final Path home = new Path("/vault", EnumSet.of(Path.Type.directory)); final NullSession session = new NullSession(new Host(new TestProtocol())) { @Override @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if(type == Directory.class) { return (T) new Directory() { @Override public Path mkdir(final Path folder, final String region, final TransferStatus status) { assertTrue(folder.equals(home) || folder.isChild(home)); return folder; } @Override public Directory withWriter(final Write writer) { return this; } }; } return super._getFeature(type); } }; final CryptoVault vault = new CryptoVault( home); vault.create(session, null, new VaultCredentials("test"), new DisabledPasswordStore()); }
public synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain, final int version) throws BackgroundException { final CryptorProvider provider = Cryptors.version1(FastSecureRandomProvider.get().provide()); final Host bookmark = session.getHost(); if(credentials.isSaved()) { try { keychain.addPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword()); } catch(LocalAccessDeniedException e) { log.error(String.format("Failure %s saving credentials for %s in password store", e, bookmark)); } } final String passphrase = credentials.getPassword(); final KeyFile masterKeyFileContent = provider.createNew().writeKeysToMasterkeyFile(passphrase, pepper, version); if(log.isDebugEnabled()) { log.debug(String.format("Write master key to %s", masterkey)); } final Directory directory = session._getFeature(Directory.class); final TransferStatus status = new TransferStatus(); final Encryption encryption = session.getFeature(Encryption.class); if(encryption != null) { status.setEncryption(encryption.getDefault(home)); } final Redundancy redundancy = session.getFeature(Redundancy.class); if(redundancy != null) { status.setStorageClass(redundancy.getDefault()); } final Path vault = directory.mkdir(home, region, status); new ContentWriter(session).write(masterkey, masterKeyFileContent.serialize()); this.open(KeyFile.parse(masterKeyFileContent.serialize()), passphrase); final Path secondLevel = directoryProvider.toEncrypted(session, home.attributes().getDirectoryId(), home); final Path firstLevel = secondLevel.getParent(); final Path dataDir = firstLevel.getParent(); if(log.isDebugEnabled()) { log.debug(String.format("Create vault root directory at %s", secondLevel)); } directory.mkdir(dataDir, region, status); directory.mkdir(firstLevel, region, status); directory.mkdir(secondLevel, region, status); return vault; }
CryptoVault implements Vault { public synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain, final int version) throws BackgroundException { final CryptorProvider provider = Cryptors.version1(FastSecureRandomProvider.get().provide()); final Host bookmark = session.getHost(); if(credentials.isSaved()) { try { keychain.addPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword()); } catch(LocalAccessDeniedException e) { log.error(String.format("Failure %s saving credentials for %s in password store", e, bookmark)); } } final String passphrase = credentials.getPassword(); final KeyFile masterKeyFileContent = provider.createNew().writeKeysToMasterkeyFile(passphrase, pepper, version); if(log.isDebugEnabled()) { log.debug(String.format("Write master key to %s", masterkey)); } final Directory directory = session._getFeature(Directory.class); final TransferStatus status = new TransferStatus(); final Encryption encryption = session.getFeature(Encryption.class); if(encryption != null) { status.setEncryption(encryption.getDefault(home)); } final Redundancy redundancy = session.getFeature(Redundancy.class); if(redundancy != null) { status.setStorageClass(redundancy.getDefault()); } final Path vault = directory.mkdir(home, region, status); new ContentWriter(session).write(masterkey, masterKeyFileContent.serialize()); this.open(KeyFile.parse(masterKeyFileContent.serialize()), passphrase); final Path secondLevel = directoryProvider.toEncrypted(session, home.attributes().getDirectoryId(), home); final Path firstLevel = secondLevel.getParent(); final Path dataDir = firstLevel.getParent(); if(log.isDebugEnabled()) { log.debug(String.format("Create vault root directory at %s", secondLevel)); } directory.mkdir(dataDir, region, status); directory.mkdir(firstLevel, region, status); directory.mkdir(secondLevel, region, status); return vault; } }
CryptoVault implements Vault { public synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain, final int version) throws BackgroundException { final CryptorProvider provider = Cryptors.version1(FastSecureRandomProvider.get().provide()); final Host bookmark = session.getHost(); if(credentials.isSaved()) { try { keychain.addPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword()); } catch(LocalAccessDeniedException e) { log.error(String.format("Failure %s saving credentials for %s in password store", e, bookmark)); } } final String passphrase = credentials.getPassword(); final KeyFile masterKeyFileContent = provider.createNew().writeKeysToMasterkeyFile(passphrase, pepper, version); if(log.isDebugEnabled()) { log.debug(String.format("Write master key to %s", masterkey)); } final Directory directory = session._getFeature(Directory.class); final TransferStatus status = new TransferStatus(); final Encryption encryption = session.getFeature(Encryption.class); if(encryption != null) { status.setEncryption(encryption.getDefault(home)); } final Redundancy redundancy = session.getFeature(Redundancy.class); if(redundancy != null) { status.setStorageClass(redundancy.getDefault()); } final Path vault = directory.mkdir(home, region, status); new ContentWriter(session).write(masterkey, masterKeyFileContent.serialize()); this.open(KeyFile.parse(masterKeyFileContent.serialize()), passphrase); final Path secondLevel = directoryProvider.toEncrypted(session, home.attributes().getDirectoryId(), home); final Path firstLevel = secondLevel.getParent(); final Path dataDir = firstLevel.getParent(); if(log.isDebugEnabled()) { log.debug(String.format("Create vault root directory at %s", secondLevel)); } directory.mkdir(dataDir, region, status); directory.mkdir(firstLevel, region, status); directory.mkdir(secondLevel, region, status); return vault; } CryptoVault(final Path home);  CryptoVault(final Path home, final String masterkey);  CryptoVault(final Path home, final String masterkey, final byte[] pepper); }
CryptoVault implements Vault { public synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain, final int version) throws BackgroundException { final CryptorProvider provider = Cryptors.version1(FastSecureRandomProvider.get().provide()); final Host bookmark = session.getHost(); if(credentials.isSaved()) { try { keychain.addPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword()); } catch(LocalAccessDeniedException e) { log.error(String.format("Failure %s saving credentials for %s in password store", e, bookmark)); } } final String passphrase = credentials.getPassword(); final KeyFile masterKeyFileContent = provider.createNew().writeKeysToMasterkeyFile(passphrase, pepper, version); if(log.isDebugEnabled()) { log.debug(String.format("Write master key to %s", masterkey)); } final Directory directory = session._getFeature(Directory.class); final TransferStatus status = new TransferStatus(); final Encryption encryption = session.getFeature(Encryption.class); if(encryption != null) { status.setEncryption(encryption.getDefault(home)); } final Redundancy redundancy = session.getFeature(Redundancy.class); if(redundancy != null) { status.setStorageClass(redundancy.getDefault()); } final Path vault = directory.mkdir(home, region, status); new ContentWriter(session).write(masterkey, masterKeyFileContent.serialize()); this.open(KeyFile.parse(masterKeyFileContent.serialize()), passphrase); final Path secondLevel = directoryProvider.toEncrypted(session, home.attributes().getDirectoryId(), home); final Path firstLevel = secondLevel.getParent(); final Path dataDir = firstLevel.getParent(); if(log.isDebugEnabled()) { log.debug(String.format("Create vault root directory at %s", secondLevel)); } directory.mkdir(dataDir, region, status); directory.mkdir(firstLevel, region, status); directory.mkdir(secondLevel, region, status); return vault; } CryptoVault(final Path home);  CryptoVault(final Path home, final String masterkey);  CryptoVault(final Path home, final String masterkey, final byte[] pepper); synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain, final int version); @Override synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain); @Override synchronized CryptoVault load(final Session<?> session, final PasswordCallback prompt, final PasswordStore keychain); @Override synchronized void close(); synchronized boolean isUnlocked(); @Override State getState(); @Override boolean contains(final Path file); @Override Path encrypt(final Session<?> session, final Path file); @Override Path encrypt(final Session<?> session, final Path file, boolean metadata); Path encrypt(final Session<?> session, final Path file, final String directoryId, boolean metadata); @Override Path decrypt(final Session<?> session, final Path file); @Override long toCiphertextSize(final long cleartextFileSize); @Override long toCleartextSize(final long ciphertextFileSize); Path getHome(); Path getMasterkey(); FileHeaderCryptor getFileHeaderCryptor(); FileContentCryptor getFileContentCryptor(); CryptorCache getFileNameCryptor(); CryptoFilename getFilenameProvider(); CryptoDirectory getDirectoryProvider(); int numberOfChunks(final long cleartextFileSize); @Override @SuppressWarnings("unchecked") T getFeature(final Session<?> session, final Class<T> type, final T delegate); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
CryptoVault implements Vault { public synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain, final int version) throws BackgroundException { final CryptorProvider provider = Cryptors.version1(FastSecureRandomProvider.get().provide()); final Host bookmark = session.getHost(); if(credentials.isSaved()) { try { keychain.addPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl(), credentials.getPassword()); } catch(LocalAccessDeniedException e) { log.error(String.format("Failure %s saving credentials for %s in password store", e, bookmark)); } } final String passphrase = credentials.getPassword(); final KeyFile masterKeyFileContent = provider.createNew().writeKeysToMasterkeyFile(passphrase, pepper, version); if(log.isDebugEnabled()) { log.debug(String.format("Write master key to %s", masterkey)); } final Directory directory = session._getFeature(Directory.class); final TransferStatus status = new TransferStatus(); final Encryption encryption = session.getFeature(Encryption.class); if(encryption != null) { status.setEncryption(encryption.getDefault(home)); } final Redundancy redundancy = session.getFeature(Redundancy.class); if(redundancy != null) { status.setStorageClass(redundancy.getDefault()); } final Path vault = directory.mkdir(home, region, status); new ContentWriter(session).write(masterkey, masterKeyFileContent.serialize()); this.open(KeyFile.parse(masterKeyFileContent.serialize()), passphrase); final Path secondLevel = directoryProvider.toEncrypted(session, home.attributes().getDirectoryId(), home); final Path firstLevel = secondLevel.getParent(); final Path dataDir = firstLevel.getParent(); if(log.isDebugEnabled()) { log.debug(String.format("Create vault root directory at %s", secondLevel)); } directory.mkdir(dataDir, region, status); directory.mkdir(firstLevel, region, status); directory.mkdir(secondLevel, region, status); return vault; } CryptoVault(final Path home);  CryptoVault(final Path home, final String masterkey);  CryptoVault(final Path home, final String masterkey, final byte[] pepper); synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain, final int version); @Override synchronized Path create(final Session<?> session, final String region, final VaultCredentials credentials, final PasswordStore keychain); @Override synchronized CryptoVault load(final Session<?> session, final PasswordCallback prompt, final PasswordStore keychain); @Override synchronized void close(); synchronized boolean isUnlocked(); @Override State getState(); @Override boolean contains(final Path file); @Override Path encrypt(final Session<?> session, final Path file); @Override Path encrypt(final Session<?> session, final Path file, boolean metadata); Path encrypt(final Session<?> session, final Path file, final String directoryId, boolean metadata); @Override Path decrypt(final Session<?> session, final Path file); @Override long toCiphertextSize(final long cleartextFileSize); @Override long toCleartextSize(final long ciphertextFileSize); Path getHome(); Path getMasterkey(); FileHeaderCryptor getFileHeaderCryptor(); FileContentCryptor getFileContentCryptor(); CryptorCache getFileNameCryptor(); CryptoFilename getFilenameProvider(); CryptoDirectory getDirectoryProvider(); int numberOfChunks(final long cleartextFileSize); @Override @SuppressWarnings("unchecked") T getFeature(final Session<?> session, final Class<T> type, final T delegate); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); static final int VAULT_VERSION_DEPRECATED; static final int VAULT_VERSION; static final String DIR_PREFIX; }