@Test public void testLoadCancel() throws Exception { final NullSession session = new NullSession(new Host(new TestProtocol())) { @Override @SuppressWarnings("unchecked") public <T> T _getFeature(final Class<T> type) { if(type == Read.class) { return (T) new Read() { @Override public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) { final String masterKey = "{\n" + " \"scryptSalt\": \"NrC7QGG/ouc=\",\n" + " \"scryptCostParam\": 16384,\n" + " \"scryptBlockSize\": 8,\n" + " \"primaryMasterKey\": \"Q7pGo1l0jmZssoQh9rXFPKJE9NIXvPbL+HcnVSR9CHdkeR8AwgFtcw==\",\n" + " \"hmacMasterKey\": \"xzBqT4/7uEcQbhHFLC0YmMy4ykVKbuvJEA46p1Xm25mJNuTc20nCbw==\",\n" + " \"versionMac\": \"hlNr3dz/CmuVajhaiGyCem9lcVIUjDfSMLhjppcXOrM=\",\n" + " \"version\": 5\n" + "}"; return IOUtils.toInputStream(masterKey, Charset.defaultCharset()); } @Override public boolean offset(final Path file) { return false; } }; } return super._getFeature(type); } }; final CryptoVault vault = new CryptoVault( new Path("/", EnumSet.of(Path.Type.directory))); try { vault.load(session, new DisabledPasswordCallback() { @Override public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) throws LoginCanceledException { throw new LoginCanceledException(); } }, new DisabledPasswordStore()); fail(); } catch(LoginCanceledException e) { } }
@Override public synchronized CryptoVault load(final Session<?> session, final PasswordCallback prompt, final PasswordStore keychain) throws BackgroundException { if(this.isUnlocked()) { log.warn(String.format("Skip unlock of open vault %s", this)); return this; } if(log.isDebugEnabled()) { log.debug(String.format("Attempt to read master key from %s", masterkey)); } final String json = new ContentReader(session).read(masterkey); if(log.isDebugEnabled()) { log.debug(String.format("Read master key %s", masterkey)); } final KeyFile masterKeyFileContent; try { masterKeyFileContent = KeyFile.parse(json.getBytes()); } catch(JsonParseException | IllegalArgumentException | IllegalStateException e) { throw new VaultException(String.format("Failure reading vault master key file %s", masterkey.getName()), e); } final Host bookmark = session.getHost(); String passphrase = keychain.getPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); if(null == passphrase) { passphrase = keychain.getPassword(String.format("Cryptomator Passphrase %s", bookmark.getHostname()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); } this.unlock(session, masterkey, masterKeyFileContent, passphrase, bookmark, prompt, MessageFormat.format(LocaleFactory.localizedString("Provide your passphrase to unlock the Cryptomator Vault {0}", "Cryptomator"), home.getName()), keychain); return this; }
CryptoVault implements Vault { @Override public synchronized CryptoVault load(final Session<?> session, final PasswordCallback prompt, final PasswordStore keychain) throws BackgroundException { if(this.isUnlocked()) { log.warn(String.format("Skip unlock of open vault %s", this)); return this; } if(log.isDebugEnabled()) { log.debug(String.format("Attempt to read master key from %s", masterkey)); } final String json = new ContentReader(session).read(masterkey); if(log.isDebugEnabled()) { log.debug(String.format("Read master key %s", masterkey)); } final KeyFile masterKeyFileContent; try { masterKeyFileContent = KeyFile.parse(json.getBytes()); } catch(JsonParseException | IllegalArgumentException | IllegalStateException e) { throw new VaultException(String.format("Failure reading vault master key file %s", masterkey.getName()), e); } final Host bookmark = session.getHost(); String passphrase = keychain.getPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); if(null == passphrase) { passphrase = keychain.getPassword(String.format("Cryptomator Passphrase %s", bookmark.getHostname()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); } this.unlock(session, masterkey, masterKeyFileContent, passphrase, bookmark, prompt, MessageFormat.format(LocaleFactory.localizedString("Provide your passphrase to unlock the Cryptomator Vault {0}", "Cryptomator"), home.getName()), keychain); return this; } }
CryptoVault implements Vault { @Override public synchronized CryptoVault load(final Session<?> session, final PasswordCallback prompt, final PasswordStore keychain) throws BackgroundException { if(this.isUnlocked()) { log.warn(String.format("Skip unlock of open vault %s", this)); return this; } if(log.isDebugEnabled()) { log.debug(String.format("Attempt to read master key from %s", masterkey)); } final String json = new ContentReader(session).read(masterkey); if(log.isDebugEnabled()) { log.debug(String.format("Read master key %s", masterkey)); } final KeyFile masterKeyFileContent; try { masterKeyFileContent = KeyFile.parse(json.getBytes()); } catch(JsonParseException | IllegalArgumentException | IllegalStateException e) { throw new VaultException(String.format("Failure reading vault master key file %s", masterkey.getName()), e); } final Host bookmark = session.getHost(); String passphrase = keychain.getPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); if(null == passphrase) { passphrase = keychain.getPassword(String.format("Cryptomator Passphrase %s", bookmark.getHostname()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); } this.unlock(session, masterkey, masterKeyFileContent, passphrase, bookmark, prompt, MessageFormat.format(LocaleFactory.localizedString("Provide your passphrase to unlock the Cryptomator Vault {0}", "Cryptomator"), home.getName()), keychain); return this; } CryptoVault(final Path home);  CryptoVault(final Path home, final String masterkey);  CryptoVault(final Path home, final String masterkey, final byte[] pepper); }
CryptoVault implements Vault { @Override public synchronized CryptoVault load(final Session<?> session, final PasswordCallback prompt, final PasswordStore keychain) throws BackgroundException { if(this.isUnlocked()) { log.warn(String.format("Skip unlock of open vault %s", this)); return this; } if(log.isDebugEnabled()) { log.debug(String.format("Attempt to read master key from %s", masterkey)); } final String json = new ContentReader(session).read(masterkey); if(log.isDebugEnabled()) { log.debug(String.format("Read master key %s", masterkey)); } final KeyFile masterKeyFileContent; try { masterKeyFileContent = KeyFile.parse(json.getBytes()); } catch(JsonParseException | IllegalArgumentException | IllegalStateException e) { throw new VaultException(String.format("Failure reading vault master key file %s", masterkey.getName()), e); } final Host bookmark = session.getHost(); String passphrase = keychain.getPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); if(null == passphrase) { passphrase = keychain.getPassword(String.format("Cryptomator Passphrase %s", bookmark.getHostname()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); } this.unlock(session, masterkey, masterKeyFileContent, passphrase, bookmark, prompt, MessageFormat.format(LocaleFactory.localizedString("Provide your passphrase to unlock the Cryptomator Vault {0}", "Cryptomator"), home.getName()), keychain); return this; } 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 { @Override public synchronized CryptoVault load(final Session<?> session, final PasswordCallback prompt, final PasswordStore keychain) throws BackgroundException { if(this.isUnlocked()) { log.warn(String.format("Skip unlock of open vault %s", this)); return this; } if(log.isDebugEnabled()) { log.debug(String.format("Attempt to read master key from %s", masterkey)); } final String json = new ContentReader(session).read(masterkey); if(log.isDebugEnabled()) { log.debug(String.format("Read master key %s", masterkey)); } final KeyFile masterKeyFileContent; try { masterKeyFileContent = KeyFile.parse(json.getBytes()); } catch(JsonParseException | IllegalArgumentException | IllegalStateException e) { throw new VaultException(String.format("Failure reading vault master key file %s", masterkey.getName()), e); } final Host bookmark = session.getHost(); String passphrase = keychain.getPassword(String.format("Cryptomator Passphrase (%s)", bookmark.getCredentials().getUsername()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); if(null == passphrase) { passphrase = keychain.getPassword(String.format("Cryptomator Passphrase %s", bookmark.getHostname()), new DefaultUrlProvider(bookmark).toUrl(masterkey).find(DescriptiveUrl.Type.provider).getUrl()); } this.unlock(session, masterkey, masterKeyFileContent, passphrase, bookmark, prompt, MessageFormat.format(LocaleFactory.localizedString("Provide your passphrase to unlock the Cryptomator Vault {0}", "Cryptomator"), home.getName()), keychain); return this; } 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; }