use of ch.cyberduck.core.vault.VaultCredentials in project cyberduck by iterate-ch.
the class S3MultipartUploadServiceTest method testUploadWithBulk.
@Test
public void testUploadWithBulk() throws Exception {
// 5L * 1024L * 1024L
final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final TransferStatus writeStatus = new TransferStatus();
final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
writeStatus.setLength(content.length);
final CryptoBulkFeature<Map<TransferItem, TransferStatus>> bulk = new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new S3DefaultDeleteFeature(session), cryptomator);
bulk.pre(Transfer.Type.upload, Collections.singletonMap(new TransferItem(test), writeStatus), new DisabledConnectionCallback());
final CryptoUploadFeature m = new CryptoUploadFeature<>(session, new S3MultipartUploadService(session, new S3WriteFeature(session), 5L * 1024L * 1024L, 5), new S3WriteFeature(session), cryptomator);
final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
IOUtils.write(content, local.getOutputStream(false));
m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), writeStatus, null);
assertTrue(writeStatus.isComplete());
assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(test).getSize());
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final TransferStatus readStatus = new TransferStatus().withLength(content.length);
final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
new StreamCopier(readStatus, readStatus).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
local.delete();
}
use of ch.cyberduck.core.vault.VaultCredentials in project cyberduck by iterate-ch.
the class S3MultipartWriteFeatureTest method testWrite.
@Test
public void testWrite() throws Exception {
final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final CryptoWriteFeature feature = new CryptoWriteFeature<>(session, new S3MultipartWriteFeature(session), cryptomator);
final byte[] content = RandomUtils.nextBytes(6 * 1024 * 1024);
final TransferStatus writeStatus = new TransferStatus();
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
writeStatus.setNonces(new RandomNonceGenerator());
writeStatus.setLength(-1L);
final StatusOutputStream out = feature.write(test, writeStatus, new DisabledConnectionCallback());
final ByteArrayInputStream in = new ByteArrayInputStream(content);
final TransferStatus progress = new TransferStatus();
final BytecountStreamListener count = new BytecountStreamListener();
new StreamCopier(new TransferStatus(), progress).withListener(count).transfer(in, out);
assertEquals(content.length, count.getSent());
assertEquals(content.length, count.getRecv());
assertNotNull(out.getStatus());
assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
final byte[] compare = new byte[content.length];
final InputStream stream = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
IOUtils.readFully(stream, compare);
stream.close();
assertArrayEquals(content, compare);
cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.vault.VaultCredentials in project cyberduck by iterate-ch.
the class S3ObjectListServiceTest method testListCryptomator.
@Test
public void testListCryptomator() throws Exception {
final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
assertTrue(new CryptoListService(session, new S3ObjectListService(session), cryptomator).list(vault, new DisabledListProgressListener()).isEmpty());
new CryptoTouchFeature<>(session, new S3TouchFeature(session), new S3WriteFeature(session), cryptomator).touch(test, new TransferStatus());
assertEquals(test, new CryptoListService(session, new S3ObjectListService(session), cryptomator).list(vault, new DisabledListProgressListener()).get(0));
cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.vault.VaultCredentials in project cyberduck by iterate-ch.
the class S3SingleUploadServiceTest method testUploadVault.
@Test
public void testUploadVault() throws Exception {
final Path home = new Path("test-eu-central-1-cyberduck", EnumSet.of(Path.Type.volume, Path.Type.directory));
final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
final CryptoVault cryptomator = new CryptoVault(vault);
cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
final int length = 5242880;
final byte[] content = RandomUtils.nextBytes(length);
IOUtils.write(content, local.getOutputStream(false));
final TransferStatus writeStatus = new TransferStatus();
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
writeStatus.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
writeStatus.setLength(content.length);
final BytecountStreamListener count = new BytecountStreamListener();
final CryptoUploadFeature m = new CryptoUploadFeature<>(session, new S3SingleUploadService(session, new S3WriteFeature(session)), new S3WriteFeature(session), cryptomator);
m.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), count, writeStatus, null);
assertEquals(content.length, count.getSent());
assertTrue(writeStatus.isComplete());
assertTrue(new CryptoFindFeature(session, new S3FindFeature(session), cryptomator).find(test));
assertEquals(content.length, new CryptoAttributesFeature(session, new S3AttributesFinderFeature(session), cryptomator).find(test).getSize());
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final TransferStatus readStatus = new TransferStatus().withLength(content.length);
final InputStream in = new CryptoReadFeature(session, new S3ReadFeature(session), cryptomator).read(test, readStatus, new DisabledConnectionCallback());
new StreamCopier(readStatus, readStatus).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new S3DefaultDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
local.delete();
}
use of ch.cyberduck.core.vault.VaultCredentials in project cyberduck by iterate-ch.
the class BrowserController method createEncryptedVaultButtonClicked.
@Action
public void createEncryptedVaultButtonClicked(final ID sender) {
final Location feature = pool.getFeature(Location.class);
final VaultController sheet = new VaultController(this.getWorkdirFromSelection(), this.getSelectedPath(), cache, feature != null ? feature.getLocations() : Collections.emptySet(), feature != null ? feature.getDefault() : Location.unknown, new VaultController.Callback() {
@Override
public void callback(final Path folder, final String region, final VaultCredentials passphrase) {
background(new WorkerBackgroundAction<>(BrowserController.this, pool, new CreateVaultWorker(region, passphrase, PasswordStoreFactory.get(), VaultFactory.get(folder, new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.masterkey.filename"), new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.config.filename"), new HostPreferences(pool.getHost()).getProperty("cryptomator.vault.pepper").getBytes(StandardCharsets.UTF_8))) {
@Override
public void cleanup(final Path vault) {
reload(workdir, Collections.singletonList(folder), Collections.singletonList(folder));
}
}));
}
});
sheet.beginSheet(this);
}
Aggregations