use of ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator in project cyberduck by iterate-ch.
the class GraphWriteFeatureTest method testWrite.
@Test
public void testWrite() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 1048576;
final byte[] content = RandomUtils.nextBytes(length);
status.setLength(content.length);
final Path home = new OneDriveHomeFinderService().find();
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<Void> writer = new CryptoWriteFeature<Void>(session, new GraphWriteFeature(session, fileid), cryptomator);
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
out.close();
assertTrue(new CryptoFindFeature(session, new GraphFindFeature(session, fileid), cryptomator).find(test));
final PathAttributes attributes = new CryptoListService(session, new GraphItemListService(session, fileid), cryptomator).list(test.getParent(), new DisabledListProgressListener()).find(new SimplePathPredicate(test)).attributes();
assertEquals(content.length, attributes.getSize());
assertEquals(content.length, new CryptoWriteFeature<>(session, new GraphWriteFeature(session, fileid), cryptomator).append(test, status.withRemote(attributes)).size, 0L);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new GraphReadFeature(session, fileid), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(status, status).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new GraphDeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator in project cyberduck by iterate-ch.
the class SwiftWriteFeatureTest method testWrite.
@Test
public void testWrite() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 1048576;
final byte[] content = RandomUtils.nextBytes(length);
status.setLength(content.length);
final Path home = new Path("test.cyberduck.ch", EnumSet.of(Path.Type.volume, Path.Type.directory));
home.attributes().setRegion("IAD");
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 SwiftRegionService regionService = new SwiftRegionService(session);
final CryptoWriteFeature<StorageObject> writer = new CryptoWriteFeature<StorageObject>(session, new SwiftWriteFeature(session, regionService), cryptomator);
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
out.close();
assertTrue(new CryptoFindFeature(session, new SwiftFindFeature(session), cryptomator).find(test));
assertEquals(content.length, new CryptoListService(session, new SwiftListService(session, regionService), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
assertEquals(content.length, writer.append(test, status.withRemote(new PathAttributes().withSize(content.length))).size, 0L);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new SwiftReadFeature(session, regionService), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(status, status).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new SwiftDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
session.close();
}
use of ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator in project cyberduck by iterate-ch.
the class FTPWriteFeatureTest method testWrite.
@Test
public void testWrite() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 1048576;
final byte[] content = RandomUtils.nextBytes(length);
status.setLength(content.length);
final Path home = new DefaultHomeFinderService(session).find();
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<Void> writer = new CryptoWriteFeature<>(session, new FTPWriteFeature(session), cryptomator);
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
status.setLength(content.length);
final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
out.close();
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
final PathAttributes attr = new CryptoAttributesFeature(session, new FTPAttributesFinderFeature(session), cryptomator).find(test);
assertEquals(content.length, new CryptoListService(session, new FTPListService(session, null, TimeZone.getDefault()), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
assertEquals(content.length, new CryptoWriteFeature<>(session, new FTPWriteFeature(session), cryptomator).append(test, status.withRemote(attr)).size, 0L);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new FTPReadFeature(session), cryptomator).read(test, new TransferStatus(), new DisabledConnectionCallback());
new StreamCopier(status, status).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new FTPDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
use of ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator in project cyberduck by iterate-ch.
the class CryptoCopyFeature method copy.
@Override
public Path copy(final Path source, final Path copy, final TransferStatus status, final ConnectionCallback callback, final StreamListener listener) throws BackgroundException {
if (vault.contains(copy)) {
// Write header to be reused in writer
final FileHeader header = vault.getFileHeaderCryptor().create();
status.setHeader(vault.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RotatingNonceGenerator(vault.numberOfChunks(status.getLength())));
}
if (vault.contains(source) && vault.contains(copy)) {
return vault.decrypt(session, proxy.withTarget(target).copy(vault.contains(source) ? vault.encrypt(session, source) : source, vault.contains(copy) ? vault.encrypt(session, copy) : copy, status, callback, listener));
} else {
// Copy files from or into vault requires to pass through encryption features
final Path target = new DefaultCopyFeature(session).withTarget(this.target).copy(vault.contains(source) ? vault.encrypt(session, source) : source, vault.contains(copy) ? vault.encrypt(session, copy) : copy, status, callback, listener);
if (vault.contains(copy)) {
return vault.decrypt(session, target);
}
return target;
}
}
use of ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator in project cyberduck by iterate-ch.
the class DriveWriteFeatureTest method testWrite.
@Test
public void testWrite() throws Exception {
final TransferStatus status = new TransferStatus();
final int length = 1048576;
final byte[] content = RandomUtils.nextBytes(length);
status.setLength(content.length);
final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
final CryptoVault cryptomator = new CryptoVault(new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)));
final Path vault = cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
final DriveFileIdProvider fileid = new DriveFileIdProvider(session);
final CryptoWriteFeature<File> writer = new CryptoWriteFeature<>(session, new DriveWriteFeature(session, fileid), cryptomator);
final FileHeader header = cryptomator.getFileHeaderCryptor().create();
status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
final StatusOutputStream<File> out = writer.write(test, status, new DisabledConnectionCallback());
assertNotNull(out);
new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
out.close();
assertNotNull(out.getStatus());
assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
final PathAttributes attributes = new CryptoAttributesFeature(session, new DefaultAttributesFinderFeature(session), cryptomator).find(test);
assertEquals(content.length, attributes.getSize());
assertEquals(content.length, writer.append(test, status.withRemote(attributes)).size, 0L);
final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
final InputStream in = new CryptoReadFeature(session, new DriveReadFeature(session, fileid), cryptomator).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
new StreamCopier(status, status).transfer(in, buffer);
assertArrayEquals(content, buffer.toByteArray());
cryptomator.getFeature(session, Delete.class, new DriveDeleteFeature(session, fileid)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Aggregations