1
0
Fork 0
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.

9 changed files with 19 additions and 22 deletions

View file

@ -77,7 +77,6 @@ public class FormNode extends NodeExtension {
return; return;
} }
xml.rightAngleBracket();
xml.append(configForm); xml.append(configForm);
xml.closeElement(this); xml.closeElement(this);
} }

View file

@ -122,7 +122,7 @@ public class OXSecretKeyBackupIntegrationTest extends AbstractOpenPgpIntegration
OpenPgpStore beforeStore = new FileBasedOpenPgpStore(beforePath); OpenPgpStore beforeStore = new FileBasedOpenPgpStore(beforePath);
beforeStore.setKeyRingProtector(new UnprotectedKeysProtector()); beforeStore.setKeyRingProtector(new UnprotectedKeysProtector());
PainlessOpenPgpProvider beforeProvider = new PainlessOpenPgpProvider(beforeStore); PainlessOpenPgpProvider beforeProvider = new PainlessOpenPgpProvider(aliceConnection, beforeStore);
openPgpManager = OpenPgpManager.getInstanceFor(aliceConnection); openPgpManager = OpenPgpManager.getInstanceFor(aliceConnection);
openPgpManager.setOpenPgpProvider(beforeProvider); openPgpManager.setOpenPgpProvider(beforeProvider);
@ -155,7 +155,7 @@ public class OXSecretKeyBackupIntegrationTest extends AbstractOpenPgpIntegration
FileBasedOpenPgpStore afterStore = new FileBasedOpenPgpStore(afterPath); FileBasedOpenPgpStore afterStore = new FileBasedOpenPgpStore(afterPath);
afterStore.setKeyRingProtector(new UnprotectedKeysProtector()); afterStore.setKeyRingProtector(new UnprotectedKeysProtector());
PainlessOpenPgpProvider afterProvider = new PainlessOpenPgpProvider(afterStore); PainlessOpenPgpProvider afterProvider = new PainlessOpenPgpProvider(aliceConnection, afterStore);
openPgpManager.setOpenPgpProvider(afterProvider); openPgpManager.setOpenPgpProvider(afterProvider);
OpenPgpV4Fingerprint fingerprint = openPgpManager.restoreSecretKeyServerBackup(new AskForBackupCodeCallback() { OpenPgpV4Fingerprint fingerprint = openPgpManager.restoreSecretKeyServerBackup(new AskForBackupCodeCallback() {

View file

@ -114,8 +114,8 @@ public class OXInstantMessagingIntegrationTest extends AbstractOpenPgpIntegratio
FileBasedOpenPgpStore bobStore = new FileBasedOpenPgpStore(bobStorePath); FileBasedOpenPgpStore bobStore = new FileBasedOpenPgpStore(bobStorePath);
bobStore.setKeyRingProtector(new UnprotectedKeysProtector()); bobStore.setKeyRingProtector(new UnprotectedKeysProtector());
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceStore); PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceConnection, aliceStore);
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobStore); PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobConnection, bobStore);
aliceOpenPgp = OpenPgpManager.getInstanceFor(aliceConnection); aliceOpenPgp = OpenPgpManager.getInstanceFor(aliceConnection);
bobOpenPgp = OpenPgpManager.getInstanceFor(bobConnection); bobOpenPgp = OpenPgpManager.getInstanceFor(bobConnection);

View file

@ -520,7 +520,7 @@ public final class OpenPgpManager extends Manager {
*/ */
public OpenPgpMessage decryptOpenPgpElement(OpenPgpElement element, OpenPgpContact sender) public OpenPgpMessage decryptOpenPgpElement(OpenPgpElement element, OpenPgpContact sender)
throws SmackException.NotLoggedInException, IOException, PGPException { 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) { private void incomingChatMessageListener(final EntityBareJid from, final Message message, Chat chat) {

View file

@ -19,7 +19,6 @@ package org.jivesoftware.smackx.ox.crypto;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.ox.OpenPgpContact; import org.jivesoftware.smackx.ox.OpenPgpContact;
import org.jivesoftware.smackx.ox.OpenPgpMessage; import org.jivesoftware.smackx.ox.OpenPgpMessage;
import org.jivesoftware.smackx.ox.OpenPgpSelf; import org.jivesoftware.smackx.ox.OpenPgpSelf;
@ -97,13 +96,12 @@ public interface OpenPgpProvider {
* @param element signed and or encrypted {@link OpenPgpElement}. * @param element signed and or encrypted {@link OpenPgpElement}.
* @param self our OpenPGP identity. * @param self our OpenPGP identity.
* @param sender OpenPGP identity of the sender. * @param sender OpenPGP identity of the sender.
* @param connection XMPP connection used to fetch any missing keys.
* *
* @return decrypted message as {@link OpenPgpMessage}. * @return decrypted message as {@link OpenPgpMessage}.
* *
* @throws IOException IO is dangerous * @throws IOException IO is dangerous
* @throws PGPException PGP is brittle * @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; throws IOException, PGPException;
} }

View file

@ -51,9 +51,11 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
private static final Logger LOGGER = Logger.getLogger(PainlessOpenPgpProvider.class.getName()); private static final Logger LOGGER = Logger.getLogger(PainlessOpenPgpProvider.class.getName());
private final XMPPConnection connection;
private final OpenPgpStore store; private final OpenPgpStore store;
public PainlessOpenPgpProvider(OpenPgpStore store) { public PainlessOpenPgpProvider(XMPPConnection connection, OpenPgpStore store) {
this.connection = Objects.requireNonNull(connection);
this.store = Objects.requireNonNull(store); this.store = Objects.requireNonNull(store);
} }
@ -156,7 +158,7 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
} }
@Override @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(); ByteArrayOutputStream plainText = new ByteArrayOutputStream();
InputStream cipherText = element.toInputStream(); InputStream cipherText = element.toInputStream();

View file

@ -30,7 +30,6 @@ import java.util.Date;
import java.util.List; import java.util.List;
import org.jivesoftware.smack.DummyConnection; import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.test.util.SmackTestSuite;
@ -83,10 +82,8 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
aliceStore.setKeyRingProtector(new UnprotectedKeysProtector()); aliceStore.setKeyRingProtector(new UnprotectedKeysProtector());
bobStore.setKeyRingProtector(new UnprotectedKeysProtector()); bobStore.setKeyRingProtector(new UnprotectedKeysProtector());
XMPPConnection bobConnection = new DummyConnection(); PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(new DummyConnection(), aliceStore);
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(new DummyConnection(), bobStore);
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceStore);
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobStore);
PGPKeyRing aliceKeys = aliceStore.generateKeyRing(alice); PGPKeyRing aliceKeys = aliceStore.generateKeyRing(alice);
PGPKeyRing bobKeys = bobStore.generateKeyRing(bob); PGPKeyRing bobKeys = bobStore.generateKeyRing(bob);
@ -137,7 +134,7 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
encrypted = aliceProvider.signAndEncrypt(signcryptElement, aliceSelf, Collections.singleton(bobForAlice)); encrypted = aliceProvider.signAndEncrypt(signcryptElement, aliceSelf, Collections.singleton(bobForAlice));
// Decrypt and Verify // Decrypt and Verify
decrypted = bobProvider.decryptAndOrVerify(bobConnection, encrypted.getElement(), bobSelf, aliceForBob); decrypted = bobProvider.decryptAndOrVerify(encrypted.getElement(), bobSelf, aliceForBob);
OpenPgpV4Fingerprint decryptionFingerprint = decrypted.getMetadata().getDecryptionFingerprint(); OpenPgpV4Fingerprint decryptionFingerprint = decrypted.getMetadata().getDecryptionFingerprint();
assertTrue(bobSelf.getSecretKeys().contains(decryptionFingerprint.getKeyId())); assertTrue(bobSelf.getSecretKeys().contains(decryptionFingerprint.getKeyId()));
@ -157,7 +154,7 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
// Encrypt // Encrypt
encrypted = aliceProvider.encrypt(cryptElement, aliceSelf, Collections.singleton(bobForAlice)); 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(); decryptionFingerprint = decrypted.getMetadata().getDecryptionFingerprint();
assertTrue(bobSelf.getSecretKeys().contains(decryptionFingerprint.getKeyId())); assertTrue(bobSelf.getSecretKeys().contains(decryptionFingerprint.getKeyId()));
@ -177,7 +174,7 @@ public class PainlessOpenPgpProviderTest extends SmackTestSuite {
// Sign // Sign
encrypted = aliceProvider.sign(signElement, aliceSelf); encrypted = aliceProvider.sign(signElement, aliceSelf);
decrypted = bobProvider.decryptAndOrVerify(bobConnection, encrypted.getElement(), bobSelf, aliceForBob); decrypted = bobProvider.decryptAndOrVerify(encrypted.getElement(), bobSelf, aliceForBob);
assertNull(decrypted.getMetadata().getDecryptionFingerprint()); assertNull(decrypted.getMetadata().getDecryptionFingerprint());
assertTrue(decrypted.getMetadata().getVerifiedSignatureKeyFingerprints().contains(aliceFingerprint)); assertTrue(decrypted.getMetadata().getVerifiedSignatureKeyFingerprints().contains(aliceFingerprint));

View file

@ -27,6 +27,7 @@ import java.security.NoSuchProviderException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.test.util.SmackTestSuite; import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smackx.ox.crypto.PainlessOpenPgpProvider; import org.jivesoftware.smackx.ox.crypto.PainlessOpenPgpProvider;
@ -78,7 +79,7 @@ public class SecretKeyBackupHelperTest extends SmackTestSuite {
// Prepare store and provider and so on... // Prepare store and provider and so on...
FileBasedOpenPgpStore store = new FileBasedOpenPgpStore(basePath); FileBasedOpenPgpStore store = new FileBasedOpenPgpStore(basePath);
PainlessOpenPgpProvider provider = new PainlessOpenPgpProvider(store); PainlessOpenPgpProvider provider = new PainlessOpenPgpProvider(new DummyConnection(), store);
// Generate and import key // Generate and import key
PGPKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("xmpp:alice@wonderland.lit"); PGPKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("xmpp:alice@wonderland.lit");

View file

@ -79,8 +79,8 @@ public class OXInstantMessagingManagerTest extends SmackTestSuite {
FileBasedOpenPgpStore aliceStore = new FileBasedOpenPgpStore(new File(basePath, "alice")); FileBasedOpenPgpStore aliceStore = new FileBasedOpenPgpStore(new File(basePath, "alice"));
FileBasedOpenPgpStore bobStore = new FileBasedOpenPgpStore(new File(basePath, "bob")); FileBasedOpenPgpStore bobStore = new FileBasedOpenPgpStore(new File(basePath, "bob"));
PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceStore); PainlessOpenPgpProvider aliceProvider = new PainlessOpenPgpProvider(aliceCon, aliceStore);
PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobStore); PainlessOpenPgpProvider bobProvider = new PainlessOpenPgpProvider(bobCon, bobStore);
OpenPgpManager aliceOpenPgp = OpenPgpManager.getInstanceFor(aliceCon); OpenPgpManager aliceOpenPgp = OpenPgpManager.getInstanceFor(aliceCon);
OpenPgpManager bobOpenPgp = OpenPgpManager.getInstanceFor(bobCon); OpenPgpManager bobOpenPgp = OpenPgpManager.getInstanceFor(bobCon);