From e7c2181516b82938a709d17b74729f118a1eb1e2 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 27 Jun 2018 16:20:55 +0200 Subject: [PATCH] Adapt latest pgpainless changes --- .../bouncycastle/PainlessOpenPgpProvider.java | 19 ++++++++++++++----- .../smackx/ox/OpenPgpProvider.java | 9 +++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/PainlessOpenPgpProvider.java b/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/PainlessOpenPgpProvider.java index b8eef2ef7..e5ac63a32 100644 --- a/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/PainlessOpenPgpProvider.java +++ b/smack-openpgp-bouncycastle/src/main/java/org/jivesoftware/smackx/ox/bouncycastle/PainlessOpenPgpProvider.java @@ -149,7 +149,6 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider { @Override public byte[] sign(SignElement element, OpenPgpV4Fingerprint signingKeyFingerprint) throws MissingOpenPgpKeyPairException, IOException, SmackOpenPgpException { - InputStream fromPlain = element.toInputStream(); PGPSecretKeyRing signingKeyRing; try { signingKeyRing = store.getSecretKeyRings(owner).getSecretKeyRing(signingKeyFingerprint.getKeyId()); @@ -157,17 +156,23 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider { throw new MissingOpenPgpKeyPairException(owner, signingKeyFingerprint, e); } + return signImpl(element, signingKeyRing, store.getSecretKeyProtector()); + } + + byte[] signImpl(SignElement element, PGPSecretKeyRing signingKey, SecretKeyRingProtector secretKeyRingProtector) + throws IOException, SmackOpenPgpException { ByteArrayOutputStream toSigned = new ByteArrayOutputStream(); OutputStream signer; try { signer = PGPainless.createEncryptor().onOutputStream(toSigned) .doNotEncrypt() - .signWith(store.getSecretKeyProtector(), signingKeyRing) + .signWith(secretKeyRingProtector, signingKey) .noArmor(); } catch (PGPException e) { throw new SmackOpenPgpException(e); } + InputStream fromPlain = element.toInputStream(); Streams.pipeAll(fromPlain, signer); fromPlain.close(); @@ -178,16 +183,20 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider { @Override public byte[] encrypt(CryptElement element, MultiMap encryptionKeyFingerprints) - throws MissingOpenPgpPublicKeyException, IOException, SmackOpenPgpException { + throws IOException, SmackOpenPgpException { PGPPublicKeyRing[] allRecipientsKeys = getEncryptionKeys(encryptionKeyFingerprints); + return encryptImpl(element, allRecipientsKeys); + } + byte[] encryptImpl(CryptElement element, PGPPublicKeyRing[] encryptionKeys) + throws IOException, SmackOpenPgpException { InputStream fromPlain = element.toInputStream(); ByteArrayOutputStream encrypted = new ByteArrayOutputStream(); OutputStream encryptor; try { encryptor = PGPainless.createEncryptor() .onOutputStream(encrypted) - .toRecipients(allRecipientsKeys) + .toRecipients(encryptionKeys) .usingSecureAlgorithms() .doNotSign() .noArmor(); @@ -260,7 +269,7 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider { try { fromEncrypted = PGPainless.createDecryptor() .onInputStream(encryptedBytes) - .decryptWith(decryptionKeys, protector) + .decryptWith(protector, decryptionKeys) .verifyWith(verificationKeys) .ignoreMissingPublicKeys() .build(); diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpProvider.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpProvider.java index 0d8aeadb8..8b3b087c5 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpProvider.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpProvider.java @@ -121,6 +121,15 @@ public interface OpenPgpProvider { byte[] symmetricallyEncryptWithPassword(byte[] bytes, String password) throws SmackOpenPgpException, IOException; + /** + * Decrypt a symmetrically encrypted array of data using the provided password. + * + * @param bytes symmetrically encrypted data + * @param password password for decryption + * @return decrypted data + * @throws SmackOpenPgpException if the password is incorrect + * @throws IOException io is dangerous + */ byte[] symmetricallyDecryptWithPassword(byte[] bytes, String password) throws SmackOpenPgpException, IOException; /**