mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-02 08:52:07 +01:00
Compare commits
No commits in common. "6266f046821ec2f8c287dec27a7b6e97a1b88be9" and "d74f19e26a03a445292af9f67077422cdc959566" have entirely different histories.
6266f04682
...
d74f19e26a
9 changed files with 19 additions and 22 deletions
|
@ -77,7 +77,6 @@ public class FormNode extends NodeExtension {
|
|||
return;
|
||||
}
|
||||
|
||||
xml.rightAngleBracket();
|
||||
xml.append(configForm);
|
||||
xml.closeElement(this);
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ public class OXSecretKeyBackupIntegrationTest extends AbstractOpenPgpIntegration
|
|||
|
||||
OpenPgpStore beforeStore = new FileBasedOpenPgpStore(beforePath);
|
||||
beforeStore.setKeyRingProtector(new UnprotectedKeysProtector());
|
||||
PainlessOpenPgpProvider beforeProvider = new PainlessOpenPgpProvider(beforeStore);
|
||||
PainlessOpenPgpProvider beforeProvider = new PainlessOpenPgpProvider(aliceConnection, beforeStore);
|
||||
openPgpManager = OpenPgpManager.getInstanceFor(aliceConnection);
|
||||
openPgpManager.setOpenPgpProvider(beforeProvider);
|
||||
|
||||
|
@ -155,7 +155,7 @@ public class OXSecretKeyBackupIntegrationTest extends AbstractOpenPgpIntegration
|
|||
|
||||
FileBasedOpenPgpStore afterStore = new FileBasedOpenPgpStore(afterPath);
|
||||
afterStore.setKeyRingProtector(new UnprotectedKeysProtector());
|
||||
PainlessOpenPgpProvider afterProvider = new PainlessOpenPgpProvider(afterStore);
|
||||
PainlessOpenPgpProvider afterProvider = new PainlessOpenPgpProvider(aliceConnection, afterStore);
|
||||
openPgpManager.setOpenPgpProvider(afterProvider);
|
||||
|
||||
OpenPgpV4Fingerprint fingerprint = openPgpManager.restoreSecretKeyServerBackup(new AskForBackupCodeCallback() {
|
||||
|
|
|
@ -114,8 +114,8 @@ public class OXInstantMessagingIntegrationTest extends AbstractOpenPgpIntegratio
|
|||
FileBasedOpenPgpStore bobStore = new FileBasedOpenPgpStore(bobStorePath);
|
||||
bobStore.setKeyRingProtector(new UnprotectedKeysProtector());
|
||||
|
||||
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceStore);
|
||||
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobStore);
|
||||
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceConnection, aliceStore);
|
||||
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobConnection, bobStore);
|
||||
|
||||
aliceOpenPgp = OpenPgpManager.getInstanceFor(aliceConnection);
|
||||
bobOpenPgp = OpenPgpManager.getInstanceFor(bobConnection);
|
||||
|
|
|
@ -520,7 +520,7 @@ public final class OpenPgpManager extends Manager {
|
|||
*/
|
||||
public OpenPgpMessage decryptOpenPgpElement(OpenPgpElement element, OpenPgpContact sender)
|
||||
throws SmackException.NotLoggedInException, IOException, PGPException {
|
||||
return provider.decryptAndOrVerify(getAuthenticatedConnectionOrThrow(), element, getOpenPgpSelf(), sender);
|
||||
return provider.decryptAndOrVerify(element, getOpenPgpSelf(), sender);
|
||||
}
|
||||
|
||||
private void incomingChatMessageListener(final EntityBareJid from, final Message message, Chat chat) {
|
||||
|
|
|
@ -19,7 +19,6 @@ package org.jivesoftware.smackx.ox.crypto;
|
|||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smackx.ox.OpenPgpContact;
|
||||
import org.jivesoftware.smackx.ox.OpenPgpMessage;
|
||||
import org.jivesoftware.smackx.ox.OpenPgpSelf;
|
||||
|
@ -97,13 +96,12 @@ public interface OpenPgpProvider {
|
|||
* @param element signed and or encrypted {@link OpenPgpElement}.
|
||||
* @param self our OpenPGP identity.
|
||||
* @param sender OpenPGP identity of the sender.
|
||||
* @param connection XMPP connection used to fetch any missing keys.
|
||||
*
|
||||
* @return decrypted message as {@link OpenPgpMessage}.
|
||||
*
|
||||
* @throws IOException IO is dangerous
|
||||
* @throws PGPException PGP is brittle
|
||||
*/
|
||||
OpenPgpMessage decryptAndOrVerify(XMPPConnection connection, OpenPgpElement element, OpenPgpSelf self, OpenPgpContact sender)
|
||||
OpenPgpMessage decryptAndOrVerify(OpenPgpElement element, OpenPgpSelf self, OpenPgpContact sender)
|
||||
throws IOException, PGPException;
|
||||
}
|
||||
|
|
|
@ -51,9 +51,11 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
|||
|
||||
private static final Logger LOGGER = Logger.getLogger(PainlessOpenPgpProvider.class.getName());
|
||||
|
||||
private final XMPPConnection connection;
|
||||
private final OpenPgpStore store;
|
||||
|
||||
public PainlessOpenPgpProvider(OpenPgpStore store) {
|
||||
public PainlessOpenPgpProvider(XMPPConnection connection, OpenPgpStore store) {
|
||||
this.connection = Objects.requireNonNull(connection);
|
||||
this.store = Objects.requireNonNull(store);
|
||||
}
|
||||
|
||||
|
@ -156,7 +158,7 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public OpenPgpMessage decryptAndOrVerify(XMPPConnection connection, OpenPgpElement element, final OpenPgpSelf self, final OpenPgpContact sender) throws IOException, PGPException {
|
||||
public OpenPgpMessage decryptAndOrVerify(OpenPgpElement element, final OpenPgpSelf self, final OpenPgpContact sender) throws IOException, PGPException {
|
||||
ByteArrayOutputStream plainText = new ByteArrayOutputStream();
|
||||
InputStream cipherText = element.toInputStream();
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.DummyConnection;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
|
@ -83,10 +82,8 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
|
|||
aliceStore.setKeyRingProtector(new UnprotectedKeysProtector());
|
||||
bobStore.setKeyRingProtector(new UnprotectedKeysProtector());
|
||||
|
||||
XMPPConnection bobConnection = new DummyConnection();
|
||||
|
||||
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceStore);
|
||||
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobStore);
|
||||
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(new DummyConnection(), aliceStore);
|
||||
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(new DummyConnection(), bobStore);
|
||||
|
||||
PGPKeyRing aliceKeys = aliceStore.generateKeyRing(alice);
|
||||
PGPKeyRing bobKeys = bobStore.generateKeyRing(bob);
|
||||
|
@ -137,7 +134,7 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
|
|||
encrypted = aliceProvider.signAndEncrypt(signcryptElement, aliceSelf, Collections.singleton(bobForAlice));
|
||||
|
||||
// Decrypt and Verify
|
||||
decrypted = bobProvider.decryptAndOrVerify(bobConnection, encrypted.getElement(), bobSelf, aliceForBob);
|
||||
decrypted = bobProvider.decryptAndOrVerify(encrypted.getElement(), bobSelf, aliceForBob);
|
||||
|
||||
OpenPgpV4Fingerprint decryptionFingerprint = decrypted.getMetadata().getDecryptionFingerprint();
|
||||
assertTrue(bobSelf.getSecretKeys().contains(decryptionFingerprint.getKeyId()));
|
||||
|
@ -157,7 +154,7 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
|
|||
// Encrypt
|
||||
encrypted = aliceProvider.encrypt(cryptElement, aliceSelf, Collections.singleton(bobForAlice));
|
||||
|
||||
decrypted = bobProvider.decryptAndOrVerify(bobConnection, encrypted.getElement(), bobSelf, aliceForBob);
|
||||
decrypted = bobProvider.decryptAndOrVerify(encrypted.getElement(), bobSelf, aliceForBob);
|
||||
|
||||
decryptionFingerprint = decrypted.getMetadata().getDecryptionFingerprint();
|
||||
assertTrue(bobSelf.getSecretKeys().contains(decryptionFingerprint.getKeyId()));
|
||||
|
@ -177,7 +174,7 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
|
|||
// Sign
|
||||
encrypted = aliceProvider.sign(signElement, aliceSelf);
|
||||
|
||||
decrypted = bobProvider.decryptAndOrVerify(bobConnection, encrypted.getElement(), bobSelf, aliceForBob);
|
||||
decrypted = bobProvider.decryptAndOrVerify(encrypted.getElement(), bobSelf, aliceForBob);
|
||||
|
||||
assertNull(decrypted.getMetadata().getDecryptionFingerprint());
|
||||
assertTrue(decrypted.getMetadata().getVerifiedSignatureKeyFingerprints().contains(aliceFingerprint));
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.security.NoSuchProviderException;
|
|||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.jivesoftware.smack.DummyConnection;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
|
||||
import org.jivesoftware.smackx.ox.crypto.PainlessOpenPgpProvider;
|
||||
|
@ -78,7 +79,7 @@ public class SecretKeyBackupHelperTest extends SmackTestSuite {
|
|||
|
||||
// Prepare store and provider and so on...
|
||||
FileBasedOpenPgpStore store = new FileBasedOpenPgpStore(basePath);
|
||||
PainlessOpenPgpProvider provider = new PainlessOpenPgpProvider(store);
|
||||
PainlessOpenPgpProvider provider = new PainlessOpenPgpProvider(new DummyConnection(), store);
|
||||
|
||||
// Generate and import key
|
||||
PGPKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("xmpp:alice@wonderland.lit");
|
||||
|
|
|
@ -79,8 +79,8 @@ public class OXInstantMessagingManagerTest extends SmackTestSuite {
|
|||
FileBasedOpenPgpStore aliceStore = new FileBasedOpenPgpStore(new File(basePath, "alice"));
|
||||
FileBasedOpenPgpStore bobStore = new FileBasedOpenPgpStore(new File(basePath, "bob"));
|
||||
|
||||
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceStore);
|
||||
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobStore);
|
||||
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceCon, aliceStore);
|
||||
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobCon, bobStore);
|
||||
|
||||
OpenPgpManager aliceOpenPgp = OpenPgpManager.getInstanceFor(aliceCon);
|
||||
OpenPgpManager bobOpenPgp = OpenPgpManager.getInstanceFor(bobCon);
|
||||
|
|
Loading…
Reference in a new issue