Search in sources :

Example 56 with NullSession

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)));
    }
}
Also used : Path(ch.cyberduck.core.Path) Write(ch.cyberduck.core.features.Write) TestProtocol(ch.cyberduck.core.TestProtocol) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) Directory(ch.cyberduck.core.features.Directory) Test(org.junit.Test)

Example 57 with NullSession

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());
}
Also used : Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) NullInputStream(org.apache.commons.io.input.NullInputStream) InputStream(java.io.InputStream) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Read(ch.cyberduck.core.features.Read) LoginOptions(ch.cyberduck.core.LoginOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) Credentials(ch.cyberduck.core.Credentials) Test(org.junit.Test)

Example 58 with NullSession

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)));
}
Also used : Path(ch.cyberduck.core.Path) Write(ch.cyberduck.core.features.Write) TestProtocol(ch.cyberduck.core.TestProtocol) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) Directory(ch.cyberduck.core.features.Directory) Test(org.junit.Test)

Example 59 with NullSession

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) {
    // 
    }
}
Also used : Path(ch.cyberduck.core.Path) TestProtocol(ch.cyberduck.core.TestProtocol) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) NullInputStream(org.apache.commons.io.input.NullInputStream) InputStream(java.io.InputStream) LoginCanceledException(ch.cyberduck.core.exception.LoginCanceledException) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) Read(ch.cyberduck.core.features.Read) LoginOptions(ch.cyberduck.core.LoginOptions) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ConnectionCallback(ch.cyberduck.core.ConnectionCallback) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) Credentials(ch.cyberduck.core.Credentials) Test(org.junit.Test)

Example 60 with NullSession

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));
}
Also used : Path(ch.cyberduck.core.Path) Write(ch.cyberduck.core.features.Write) TestProtocol(ch.cyberduck.core.TestProtocol) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) NullSession(ch.cyberduck.core.NullSession) Host(ch.cyberduck.core.Host) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) Directory(ch.cyberduck.core.features.Directory) Test(org.junit.Test)

Aggregations

Host (ch.cyberduck.core.Host)128 NullSession (ch.cyberduck.core.NullSession)128 TestProtocol (ch.cyberduck.core.TestProtocol)128 Test (org.junit.Test)127 Path (ch.cyberduck.core.Path)118 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)81 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)69 NullLocal (ch.cyberduck.core.NullLocal)59 ListProgressListener (ch.cyberduck.core.ListProgressListener)40 AttributedList (ch.cyberduck.core.AttributedList)32 DisabledUploadSymlinkResolver (ch.cyberduck.core.transfer.symlink.DisabledUploadSymlinkResolver)27 Local (ch.cyberduck.core.Local)24 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)24 ConnectionCallback (ch.cyberduck.core.ConnectionCallback)19 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)18 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)17 Session (ch.cyberduck.core.Session)17 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)17 HashMap (java.util.HashMap)14 LocalAttributes (ch.cyberduck.core.LocalAttributes)13