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);
}
}
Aggregations