use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoVaultTest method testCleartextSizeCiphertextCalculation.
@Test
public void testCleartextSizeCiphertextCalculation() 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 TransferStatus status) {
assertTrue(folder.equals(home) || folder.isChild(home));
return folder;
}
@Override
public boolean isSupported(final Path workdir, final String name) {
throw new UnsupportedOperationException();
}
@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());
for (int i = 0; i < 26000000; i++) {
assertEquals(i, vault.toCleartextSize(0L, vault.toCiphertextSize(0L, i)));
}
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoVaultTest method testLoadInvalidPassphrase.
@Test
public void testLoadInvalidPassphrase() 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" + " \"version\": 999,\n" + " \"scryptSalt\": \"RVAAirkArDU=\",\n" + " \"scryptCostParam\": 32768,\n" + " \"scryptBlockSize\": 8,\n" + " \"primaryMasterKey\": \"+03NkJNWVsJ9Tb1CTpKhXyfINzjDirFFI+iJLOWIOySyxB+abpx34Q==\",\n" + " \"hmacMasterKey\": \"aMoDtn7Y6kIXxyHo2zl47p5jCYTlRnfx3l3AMgULmIDSYAxVAraSgg==\",\n" + " \"versionMac\": \"FzirA8UhwCmS5RsC4JvxbO+ZBxaCbIkzqD2Ocagd+A8=\"\n" + "}";
return IOUtils.toInputStream(masterKey, Charset.defaultCharset());
}
@Override
public boolean offset(final Path file) {
return false;
}
};
}
return super._getFeature(type);
}
};
final AtomicBoolean prompt = new AtomicBoolean();
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 {
if (!prompt.get()) {
assertEquals("Provide your passphrase to unlock the Cryptomator Vault /", reason);
prompt.set(true);
return new VaultCredentials("null");
} else {
assertEquals("Failure to decrypt master key file. Provide your passphrase to unlock the Cryptomator Vault /.", reason);
throw new LoginCanceledException();
}
}
}, new DisabledPasswordStore());
fail();
} catch (LoginCanceledException e) {
//
}
assertTrue(prompt.get());
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoVaultTest method testCleartextSize.
@Test
public void testCleartextSize() 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 TransferStatus status) {
assertTrue(folder.equals(home) || folder.isChild(home));
return folder;
}
@Override
public boolean isSupported(final Path workdir, final String name) {
throw new UnsupportedOperationException();
}
@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());
// zero ciphertextFileSize
try {
vault.toCleartextSize(0L, 0);
fail();
} catch (CryptoInvalidFilesizeException e) {
}
// ciphertextFileSize == headerSize
assertEquals(0L, vault.toCleartextSize(0L, vault.getFileHeaderCryptor().headerSize()));
// ciphertextFileSize == headerSize + 1
try {
vault.toCleartextSize(0L, vault.toCleartextSize(0L, vault.getFileHeaderCryptor().headerSize()) + 1);
fail();
} catch (CryptoInvalidFilesizeException e) {
}
// ciphertextFileSize == headerSize + chunkHeaderSize + 1
assertEquals(1L, vault.toCleartextSize(0L, vault.getFileHeaderCryptor().headerSize() + 48 + 1));
// ciphertextFileSize == headerSize + (32768 + chunkHeaderSize) + (1 + chunkHeaderSize) + 1
assertEquals(32769L, vault.toCleartextSize(0L, vault.getFileHeaderCryptor().headerSize() + (32768 + 48) + (1 + 48)));
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoVaultTest method testLoadEmptyPassword.
@Test
public void testLoadEmptyPassword() 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) {
return new VaultCredentials(null);
}
}, new DisabledPasswordStore());
fail();
} catch (LoginCanceledException e) {
//
}
}
use of ch.cyberduck.core.NullSession in project cyberduck by iterate-ch.
the class CryptoWriteFeatureTest method testCiphertextSize.
@Test
public void testCiphertextSize() 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 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());
int headerSize = vault.getFileHeaderCryptor().headerSize();
// zero file size
assertEquals(headerSize, vault.toCiphertextSize(0L, 0));
// one-byte file
assertEquals(headerSize + 48 + 1, vault.toCiphertextSize(0L, 1));
// file with chunk size length
assertEquals(headerSize + vault.getFileContentCryptor().ciphertextChunkSize(), vault.toCiphertextSize(0L, vault.getFileContentCryptor().cleartextChunkSize()));
// file with chunk size length + 1
assertEquals(headerSize + vault.getFileContentCryptor().ciphertextChunkSize() + 48 + 1, vault.toCiphertextSize(0L, vault.getFileContentCryptor().cleartextChunkSize() + 1));
// file with 2 * chunk size length
assertEquals(headerSize + 2 * vault.getFileContentCryptor().ciphertextChunkSize(), vault.toCiphertextSize(0L, 2 * vault.getFileContentCryptor().cleartextChunkSize()));
// file with 2 * chunk size length + 100
assertEquals(headerSize + 2 * vault.getFileContentCryptor().ciphertextChunkSize() + 48 + 100, vault.toCiphertextSize(0L, 2 * vault.getFileContentCryptor().cleartextChunkSize() + 100));
}
Aggregations