Search in sources :

Example 1 with SDSExceptionMappingService

use of ch.cyberduck.core.sds.SDSExceptionMappingService in project cyberduck by iterate-ch.

the class TripleCryptReadFeature method read.

@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback) throws BackgroundException {
    try {
        final FileKey key = new NodesApi(session.getClient()).requestUserFileKey(Long.parseLong(nodeid.getVersionId(file, new DisabledListProgressListener())), null, null);
        final EncryptedFileKey encFileKey = TripleCryptConverter.toCryptoEncryptedFileKey(key);
        try {
            final UserKeyPair userKeyPair = this.getUserKeyPair(encFileKey);
            final PlainFileKey plainFileKey = Crypto.decryptFileKey(encFileKey, userKeyPair.getUserPrivateKey(), this.unlock(callback, userKeyPair).getPassword());
            return new TripleCryptDecryptingInputStream(proxy.read(file, status, callback), Crypto.createFileDecryptionCipher(plainFileKey), CryptoUtils.stringToByteArray(plainFileKey.getTag()));
        } catch (InvalidFileKeyException e) {
            log.warn(String.format("Failure %s  decrypting file key for %s. Invalidate cache", e, file));
            session.resetUserKeyPairs();
            final UserKeyPair userKeyPair = this.getUserKeyPair(encFileKey);
            final PlainFileKey plainFileKey = Crypto.decryptFileKey(encFileKey, userKeyPair.getUserPrivateKey(), this.unlock(callback, userKeyPair).getPassword());
            return new TripleCryptDecryptingInputStream(proxy.read(file, status, callback), Crypto.createFileDecryptionCipher(plainFileKey), CryptoUtils.stringToByteArray(plainFileKey.getTag()));
        }
    } catch (ApiException e) {
        throw new SDSExceptionMappingService(nodeid).map("Download {0} failed", e, file);
    } catch (CryptoException e) {
        throw new TripleCryptExceptionMappingService().map("Download {0} failed", e, file);
    }
}
Also used : UserKeyPair(com.dracoon.sdk.crypto.model.UserKeyPair) EncryptedFileKey(com.dracoon.sdk.crypto.model.EncryptedFileKey) PlainFileKey(com.dracoon.sdk.crypto.model.PlainFileKey) FileKey(ch.cyberduck.core.sds.io.swagger.client.model.FileKey) NodesApi(ch.cyberduck.core.sds.io.swagger.client.api.NodesApi) InvalidFileKeyException(com.dracoon.sdk.crypto.error.InvalidFileKeyException) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) SDSExceptionMappingService(ch.cyberduck.core.sds.SDSExceptionMappingService) EncryptedFileKey(com.dracoon.sdk.crypto.model.EncryptedFileKey) CryptoException(com.dracoon.sdk.crypto.error.CryptoException) PlainFileKey(com.dracoon.sdk.crypto.model.PlainFileKey) ApiException(ch.cyberduck.core.sds.io.swagger.client.ApiException)

Aggregations

DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 SDSExceptionMappingService (ch.cyberduck.core.sds.SDSExceptionMappingService)1 ApiException (ch.cyberduck.core.sds.io.swagger.client.ApiException)1 NodesApi (ch.cyberduck.core.sds.io.swagger.client.api.NodesApi)1 FileKey (ch.cyberduck.core.sds.io.swagger.client.model.FileKey)1 CryptoException (com.dracoon.sdk.crypto.error.CryptoException)1 InvalidFileKeyException (com.dracoon.sdk.crypto.error.InvalidFileKeyException)1 EncryptedFileKey (com.dracoon.sdk.crypto.model.EncryptedFileKey)1 PlainFileKey (com.dracoon.sdk.crypto.model.PlainFileKey)1 UserKeyPair (com.dracoon.sdk.crypto.model.UserKeyPair)1