diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/openpgp/BasicOpenPgpInstantMessagingIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/openpgp/BasicOpenPgpInstantMessagingIntegrationTest.java index 1d6497b12..5e918aeb8 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/openpgp/BasicOpenPgpInstantMessagingIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/openpgp/BasicOpenPgpInstantMessagingIntegrationTest.java @@ -31,7 +31,7 @@ import org.jivesoftware.smackx.ox.OpenPgpManager; import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint; import org.jivesoftware.smackx.ox.bouncycastle.FileBasedPainlessOpenPgpStore; import org.jivesoftware.smackx.ox.bouncycastle.PainlessOpenPgpProvider; -import org.jivesoftware.smackx.ox.chat.OpenPgpContact; +import org.jivesoftware.smackx.ox.OpenPgpContact; import org.jivesoftware.smackx.ox.element.SigncryptElement; import org.jivesoftware.smackx.ox.listener.OxMessageListener; import org.jivesoftware.smackx.ox.util.PubSubDelegate; @@ -110,16 +110,11 @@ public class BasicOpenPgpInstantMessagingIntegrationTest extends AbstractOpenPgp aliceOpenPgp.announceSupportAndPublish(); bobOpenPgp.announceSupportAndPublish(); - LOGGER.log(Level.INFO, "Request metadata of bob"); - aliceOpenPgp.requestMetadataUpdate(bob); - LOGGER.log(Level.INFO, "Request metadata of alice"); - bobOpenPgp.requestMetadataUpdate(alice); - OpenPgpContact bobForAlice = aliceOpenPgp.getOpenPgpContact(bob.asEntityBareJidIfPossible()); OpenPgpContact aliceForBob = bobOpenPgp.getOpenPgpContact(alice.asEntityBareJidIfPossible()); - assertTrue(bobForAlice.getFingerprints().getActiveKeys().contains(bobFingerprint)); - assertTrue(aliceForBob.getFingerprints().getActiveKeys().contains(aliceFingerprint)); + assertTrue(bobForAlice.getActiveKeys().contains(bobFingerprint)); + assertTrue(aliceForBob.getActiveKeys().contains(aliceFingerprint)); aliceInstantMessaging.sendOxMessage(bobForAlice, body); diff --git a/smack-openpgp-bouncycastle/src/test/java/org/jivesoftware/smackx/ox/bouncycastle/DryOxEncryptionTest.java b/smack-openpgp-bouncycastle/src/test/java/org/jivesoftware/smackx/ox/bouncycastle/DryOxEncryptionTest.java index 4f90fc306..28a9ed89a 100644 --- a/smack-openpgp-bouncycastle/src/test/java/org/jivesoftware/smackx/ox/bouncycastle/DryOxEncryptionTest.java +++ b/smack-openpgp-bouncycastle/src/test/java/org/jivesoftware/smackx/ox/bouncycastle/DryOxEncryptionTest.java @@ -37,7 +37,7 @@ import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.util.FileUtils; import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint; import org.jivesoftware.smackx.ox.TestKeys; -import org.jivesoftware.smackx.ox.chat.OpenPgpContact; +import org.jivesoftware.smackx.ox.OpenPgpContact; import org.jivesoftware.smackx.ox.element.OpenPgpContentElement; import org.jivesoftware.smackx.ox.element.OpenPgpElement; import org.jivesoftware.smackx.ox.element.PubkeyElement; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OXInstantMessagingManager.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OXInstantMessagingManager.java index bd284f966..6d18fa0ba 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OXInstantMessagingManager.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OXInstantMessagingManager.java @@ -28,18 +28,17 @@ import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.chat2.ChatManager; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smackx.disco.ServiceDiscoveryManager; import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement; import org.jivesoftware.smackx.hints.element.StoreHint; -import org.jivesoftware.smackx.ox.chat.OpenPgpContact; import org.jivesoftware.smackx.ox.element.SigncryptElement; import org.jivesoftware.smackx.ox.exception.MissingOpenPgpKeyPairException; import org.jivesoftware.smackx.ox.exception.SmackOpenPgpException; import org.jivesoftware.smackx.ox.listener.OxMessageListener; import org.jivesoftware.smackx.ox.listener.internal.SigncryptElementReceivedListener; - import org.jxmpp.jid.BareJid; /** @@ -138,6 +137,8 @@ public final class OXInstantMessagingManager extends Manager implements Signcryp StoreHint.set(message); message.setBody("This message is encrypted using XEP-0374: OpenPGP for XMPP: Instant Messaging."); - contact.send(connection(), message, payload); + contact.addSignedEncryptedPayloadTo(message, payload); + + ChatManager.getInstanceFor(connection()).chatWith(contact.getJid().asEntityBareJidIfPossible()).send(message); } } diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpContact.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpContact.java similarity index 66% rename from smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpContact.java rename to smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpContact.java index 56e14ea1f..42c906c30 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpContact.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpContact.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smackx.ox.chat; +package org.jivesoftware.smackx.ox; import java.io.IOException; import java.util.Collections; @@ -29,16 +29,12 @@ import java.util.logging.Logger; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smack.chat2.ChatManager; import org.jivesoftware.smack.packet.ExtensionElement; import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.util.MultiMap; import org.jivesoftware.smack.util.stringencoder.Base64; import org.jivesoftware.smackx.eme.element.ExplicitMessageEncryptionElement; import org.jivesoftware.smackx.hints.element.StoreHint; -import org.jivesoftware.smackx.ox.OpenPgpManager; -import org.jivesoftware.smackx.ox.OpenPgpProvider; -import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint; import org.jivesoftware.smackx.ox.element.OpenPgpContentElement; import org.jivesoftware.smackx.ox.element.OpenPgpElement; import org.jivesoftware.smackx.ox.element.PubkeyElement; @@ -50,7 +46,6 @@ import org.jivesoftware.smackx.ox.exception.MissingUserIdOnKeyException; import org.jivesoftware.smackx.ox.exception.SmackOpenPgpException; import org.jivesoftware.smackx.ox.util.DecryptedBytesAndMetadata; import org.jivesoftware.smackx.ox.util.PubSubDelegate; - import org.jxmpp.jid.BareJid; import org.jxmpp.jid.Jid; import org.xmlpull.v1.XmlPullParserException; @@ -67,18 +62,41 @@ public class OpenPgpContact { private Map availableKeys = null; private final Map unfetchableKeys = new HashMap<>(); + /** + * Create a OpenPgpContact. + * + * @param cryptoProvider {@link OpenPgpProvider} + * @param jid {@link BareJid} of the contact + * @param connection our authenticated {@link XMPPConnection} + */ public OpenPgpContact(OpenPgpProvider cryptoProvider, BareJid jid, XMPPConnection connection) { this.jid = jid; this.cryptoProvider = cryptoProvider; this.connection = connection; + + try { + this.updateKeys(); + } catch (SmackOpenPgpException | InterruptedException | XMPPException.XMPPErrorException | SmackException e) { + LOGGER.log(Level.WARNING, "Initial key update for contact " + getJid() + " failed.", e); + } } + /** + * Return the {@link BareJid} of the contact. + * + * @return jid + */ public BareJid getJid() { return jid; } + /** + * Return a {@link Map} of the announced keys of the contact and their last update dates. + * + * @return announced keys + */ public Map getAnnouncedKeys() { if (announcedKeys == null) { announcedKeys = cryptoProvider.getStore().getAnnouncedKeysFingerprints(getJid()); @@ -86,6 +104,15 @@ public class OpenPgpContact { return announcedKeys; } + /** + * Return a {@link Map} of all locally available keys of the contact. + * + * Note: This list might contain keys which are no longer associated to the contact. + * For encryption please use {@link #getActiveKeys()} instead. + * + * @return available keys + * @throws SmackOpenPgpException if we cannot read the locally available keys for some reason + */ public Map getAvailableKeys() throws SmackOpenPgpException { if (availableKeys == null) { availableKeys = cryptoProvider.getStore().getAvailableKeysFingerprints(getJid()); @@ -93,21 +120,47 @@ public class OpenPgpContact { return availableKeys; } + /** + * Return a {@link Map} of all the keys which cannot be fetched and the reason why this is. + * + * @return unfetched keys + */ public Map getUnfetchableKeys() { return unfetchableKeys; } + /** + * Return a {@link Set} of all active keys of this contact. + * Active keys are keys which are announced, not revoked or otherwise invalidated and locally available. + * + * @return active keys. + * @throws SmackOpenPgpException if we cannot access the keys of the contact. + */ public Set getActiveKeys() throws SmackOpenPgpException { Set fingerprints = getAvailableKeys().keySet(); fingerprints.retainAll(getAnnouncedKeys().keySet()); return fingerprints; } + /** + * Fetch the metadata node to get a {@link PublicKeysListElement} and update any missing or outdated keys. + * + * @throws InterruptedException + * @throws XMPPException.XMPPErrorException + * @throws SmackException + * @throws SmackOpenPgpException + */ public void updateKeys() throws InterruptedException, XMPPException.XMPPErrorException, SmackException, SmackOpenPgpException { updateKeys(PubSubDelegate.fetchPubkeysList(connection, getJid())); } + /** + * Update any missing or outdated keys based on the given {@link PublicKeysListElement}. + * + * @param metadata + * @throws SmackOpenPgpException + */ public void updateKeys(PublicKeysListElement metadata) throws SmackOpenPgpException { storePublishedDevices(metadata); @@ -130,6 +183,17 @@ public class OpenPgpContact { } } + /** + * Update the key identified by the {@code fingerprint}. + * + * @param fingerprint fingerprint of the key + * @throws InterruptedException + * @throws XMPPException.XMPPErrorException + * @throws SmackException + * @throws IOException + * @throws MissingUserIdOnKeyException + * @throws SmackOpenPgpException + */ public void updateKey(OpenPgpV4Fingerprint fingerprint) throws InterruptedException, XMPPException.XMPPErrorException, SmackException, IOException, MissingUserIdOnKeyException, SmackOpenPgpException { @@ -148,6 +212,15 @@ public class OpenPgpContact { } } + /** + * Import a public key. + * + * @param data OpenPgp keys byte representation. + * @return the fingerprint of the imported key. + * @throws SmackOpenPgpException + * @throws MissingUserIdOnKeyException + * @throws IOException + */ private OpenPgpV4Fingerprint importPublicKey(byte[] data) throws SmackOpenPgpException, MissingUserIdOnKeyException, IOException { OpenPgpV4Fingerprint fingerprint = cryptoProvider.importPublicKey(getJid(), data); @@ -155,6 +228,13 @@ public class OpenPgpContact { return fingerprint; } + /** + * Process an incoming {@link PublicKeysListElement} and store the contained {@link OpenPgpV4Fingerprint}s and + * their publication dates in local storage. + * + * @param element publicKeysListElement + * @return {@link Map} with the contents of the element + */ public Map storePublishedDevices(PublicKeysListElement element) { Map announcedKeys = new HashMap<>(); @@ -170,6 +250,14 @@ public class OpenPgpContact { return announcedKeys; } + /** + * Get all keys to which a message sent to the contact would be encrypted to. + * Those are all active keys of the contact as well as our own active keys. + * + * @return encryption keys + * @throws SmackOpenPgpException if we cannot read the contacts keys or our own keys. + * @throws SmackException.NotLoggedInException if we are not logged in. + */ private MultiMap getEncryptionKeys() throws SmackOpenPgpException, SmackException.NotLoggedInException { OpenPgpSelf self = getSelf(); @@ -189,10 +277,28 @@ public class OpenPgpContact { return recipientsKeys; } + /** + * Get our OpenPgpSelf. + * The {@link OpenPgpSelf} contains all our fingerprints. + * + * @return openPgpSelf + * @throws SmackException.NotLoggedInException + */ private OpenPgpSelf getSelf() throws SmackException.NotLoggedInException { return OpenPgpManager.getInstanceFor(connection).getOpenPgpSelf(); } + /** + * Encrypt a message to a contact and ourselves and sign it with our signing key. + * The payload will be wrapped in a {@link SigncryptElement} before encryption. + * + * @param payload the payload we want to encrypt. + * @return {@link OpenPgpElement} containing the encrypted, signed {@link SigncryptElement}. + * @throws IOException IO is dangerous + * @throws SmackOpenPgpException OpenPgp is brittle + * @throws MissingOpenPgpKeyPairException if we cannot read our signing key pair + * @throws SmackException.NotLoggedInException if we are not logged in. + */ public OpenPgpElement encryptAndSign(List payload) throws IOException, SmackOpenPgpException, MissingOpenPgpKeyPairException, SmackException.NotLoggedInException { @@ -218,6 +324,17 @@ public class OpenPgpContact { return new OpenPgpElement(Base64.encodeToString(encryptedBytes)); } + /** + * Create a signed and encrypted {@link SigncryptElement} containing the {@code payload} and append it as a + * {@link OpenPgpElement} to the {@code message}. + * + * @param message {@link Message} which will transport the payload. + * @param payload payload that will be encrypted and signed. + * @throws IOException IO is dangerous. + * @throws SmackOpenPgpException OpenPGP is brittle. + * @throws MissingOpenPgpKeyPairException if we cannot access our signing key. + * @throws SmackException.NotLoggedInException if we are not logged in. + */ public void addSignedEncryptedPayloadTo(Message message, List payload) throws IOException, SmackOpenPgpException, MissingOpenPgpKeyPairException, SmackException.NotLoggedInException { @@ -237,36 +354,16 @@ public class OpenPgpContact { } - public void send(XMPPConnection connection, Message message, List payload) - throws MissingOpenPgpKeyPairException, SmackException.NotConnectedException, InterruptedException, - SmackOpenPgpException, IOException, SmackException.NotLoggedInException { - MultiMap fingerprints = getEncryptionKeys(); - - SigncryptElement preparedPayload = new SigncryptElement( - Collections.singleton(getJid()), - payload); - - OpenPgpElement encryptedPayload; - byte[] encryptedMessage; - - // Encrypt the payload - try { - encryptedMessage = cryptoProvider.signAndEncrypt( - preparedPayload, - getSelf().getSigningKey(), - fingerprints); - } catch (MissingOpenPgpPublicKeyException e) { - throw new AssertionError("Missing OpenPGP public key, even though this should not happen here.", e); - } - - encryptedPayload = new OpenPgpElement(Base64.encodeToString(encryptedMessage)); - - // Add encrypted payload to message - message.addExtension(encryptedPayload); - - ChatManager.getInstanceFor(connection).chatWith(getJid().asEntityBareJidIfPossible()).send(message); - } - + /** + * Process an incoming {@link OpenPgpElement} and return the decrypted and verified {@link OpenPgpContentElement}. + * + * @param element possibly encrypted, possibly signed {@link OpenPgpElement}. + * @return decrypted {@link OpenPgpContentElement} + * @throws XmlPullParserException if the decrypted message does not represent valid XML. + * @throws MissingOpenPgpKeyPairException if we are missing the public key counterpart of the key that signed the message. + * @throws SmackOpenPgpException if the message cannot be decrypted and or verified. + * @throws IOException IO is dangerous + */ public OpenPgpContentElement receive(OpenPgpElement element) throws XmlPullParserException, MissingOpenPgpKeyPairException, SmackOpenPgpException, IOException { byte[] decoded = Base64.decode(element.getEncryptedBase64MessageContent()); diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpManager.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpManager.java index e2d719766..75a33f872 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpManager.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpManager.java @@ -49,8 +49,6 @@ import org.jivesoftware.smackx.ox.callback.AskForBackupCodeCallback; import org.jivesoftware.smackx.ox.callback.DisplayBackupCodeCallback; import org.jivesoftware.smackx.ox.callback.SecretKeyBackupSelectionCallback; import org.jivesoftware.smackx.ox.callback.SecretKeyRestoreSelectionCallback; -import org.jivesoftware.smackx.ox.chat.OpenPgpContact; -import org.jivesoftware.smackx.ox.chat.OpenPgpSelf; import org.jivesoftware.smackx.ox.element.CryptElement; import org.jivesoftware.smackx.ox.element.OpenPgpContentElement; import org.jivesoftware.smackx.ox.element.OpenPgpElement; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpMessage.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpMessage.java similarity index 91% rename from smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpMessage.java rename to smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpMessage.java index c2e96c399..7f9870604 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpMessage.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpMessage.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jivesoftware.smackx.ox.chat; +package org.jivesoftware.smackx.ox; import java.io.IOException; import java.nio.charset.Charset; @@ -54,23 +54,24 @@ public class OpenPgpMessage { private final String element; private final State state; + private final Metadata metadata; private OpenPgpContentElement openPgpContentElement; /** * Constructor. * - * @param state state of the content element. + * @param metadata Metadata about the encryption * @param content XML representation of the decrypted {@link OpenPgpContentElement}. */ - public OpenPgpMessage(State state, String content) { - this.state = Objects.requireNonNull(state); + public OpenPgpMessage(String content, Metadata metadata) { + this.metadata = Objects.requireNonNull(metadata); + this.state = Objects.requireNonNull(metadata.getState()); this.element = Objects.requireNonNull(content); } public OpenPgpMessage(byte[] bytes, Metadata metadata) { - this.element = new String(bytes, Charset.forName("UTF-8")); - this.state = metadata.getState(); + this(new String(Objects.requireNonNull(bytes), Charset.forName("UTF-8")), metadata); } /** @@ -126,6 +127,10 @@ public class OpenPgpMessage { return state; } + public Metadata getMetadata() { + return metadata; + } + public static class Metadata { private final Long encryptionKeyId; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpSelf.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpSelf.java similarity index 73% rename from smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpSelf.java rename to smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpSelf.java index 139d40574..9b6368de1 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpSelf.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/OpenPgpSelf.java @@ -1,8 +1,6 @@ -package org.jivesoftware.smackx.ox.chat; +package org.jivesoftware.smackx.ox; import org.jivesoftware.smack.XMPPConnection; -import org.jivesoftware.smackx.ox.OpenPgpProvider; -import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint; import org.jxmpp.jid.BareJid; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpFingerprints.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpFingerprints.java deleted file mode 100644 index c6f50fd92..000000000 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/OpenPgpFingerprints.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * - * Copyright 2018 Paul Schaub. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jivesoftware.smackx.ox.chat; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.jivesoftware.smack.util.Objects; -import org.jivesoftware.smackx.ox.OpenPgpV4Fingerprint; - -import org.jxmpp.jid.BareJid; - -/** - * Metadata about a contacts OpenPGP fingerprints. - */ -public class OpenPgpFingerprints { - - private final BareJid jid; - private final Set announcedKeys; - private final Set availableKeys; - private final Map unfetchableKeys; - - /** - * Constructor. - * - * @param announcedKeys keys the contact currently announces via their metadata node. - * @param availableKeys keys which contain the contacts {@link BareJid} as user ID. - * @param unfetchableKeys keys that are announced, but cannot be fetched fro PubSub. - */ - public OpenPgpFingerprints(BareJid jid, - Set announcedKeys, - Set availableKeys, - Map unfetchableKeys) { - this.jid = jid; - this.announcedKeys = Collections.unmodifiableSet(Objects.requireNonNull(announcedKeys, - "Set of announced keys MUST NOT be null.")); - this.availableKeys = Collections.unmodifiableSet(Objects.requireNonNull(availableKeys, - "Set of available keys MUST NOT be null.")); - this.unfetchableKeys = Collections.unmodifiableMap(Objects.requireNonNull(unfetchableKeys, - "Map of unfetchable keys MUST NOT be null.")); - } - - /** - * Return the {@link BareJid} of the user. - * @return jid - */ - public BareJid getJid() { - return jid; - } - - /** - * Return a {@link Set} of {@link OpenPgpV4Fingerprint}s, which the contact in question announced via their - * metadata node. - * - * @see - * XEP-0373 ยง4.2 about the Public Key Metadata Node - * - * @return announced keys. - */ - public Set getAnnouncedKeys() { - return announcedKeys; - } - - /** - * Return a {@link Set} of {@link OpenPgpV4Fingerprint}s, which are available in the local key ring, which contain - * the users {@link BareJid} as user-id (eg. "xmpp:juliet@capulet.lit"). - *
- * Note: As everybody can publish a key with an arbitrary user-id, the keys contained in the result set MAY be keys - * of an potential attacker. NEVER use these keys for encryption without collating them with the users announced - * keys. - * - * @return locally available keys with users user-id. - */ - public Set getAvailableKeys() { - return availableKeys; - } - - /** - * Return a {@link Map}, which maps {@link OpenPgpV4Fingerprint}s which the user announced, but that cannot be fetched - * via PubSub to {@link Throwable}s which were thrown when we tried to fetch them. - * - * @return unfetchable keys. - */ - public Map getUnfetchableKeys() { - return unfetchableKeys; - } - - /** - * Return a {@link Set} of {@link OpenPgpV4Fingerprint}s, which are both announced, as well as available. - * It is recommended to use those keys for encryption. - * - * @return active keys. - */ - public Set getActiveKeys() { - Set active = new HashSet<>(); - for (OpenPgpV4Fingerprint fingerprint : getAvailableKeys()) { - if (getAnnouncedKeys().contains(fingerprint)) { - active.add(fingerprint); - } - } - return Collections.unmodifiableSet(active); - } -} diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/package-info.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/package-info.java deleted file mode 100644 index add1442bc..000000000 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/chat/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * - * Copyright 2018 Paul Schaub. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Chat related classes for XEP-0373: OpenPGP for XMPP. - */ -package org.jivesoftware.smackx.ox.chat; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/OxMessageListener.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/OxMessageListener.java index 43d91ea54..4310af1de 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/OxMessageListener.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/OxMessageListener.java @@ -17,7 +17,7 @@ package org.jivesoftware.smackx.ox.listener; import org.jivesoftware.smack.packet.Message; -import org.jivesoftware.smackx.ox.chat.OpenPgpContact; +import org.jivesoftware.smackx.ox.OpenPgpContact; import org.jivesoftware.smackx.ox.element.OpenPgpElement; import org.jivesoftware.smackx.ox.element.SigncryptElement; diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/CryptElementReceivedListener.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/CryptElementReceivedListener.java index 9b4caf6e2..1722394b0 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/CryptElementReceivedListener.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/CryptElementReceivedListener.java @@ -17,7 +17,7 @@ package org.jivesoftware.smackx.ox.listener.internal; import org.jivesoftware.smack.packet.Message; -import org.jivesoftware.smackx.ox.chat.OpenPgpContact; +import org.jivesoftware.smackx.ox.OpenPgpContact; import org.jivesoftware.smackx.ox.element.CryptElement; public interface CryptElementReceivedListener { diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/SignElementReceivedListener.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/SignElementReceivedListener.java index d03a7a803..62fccfb9c 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/SignElementReceivedListener.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/SignElementReceivedListener.java @@ -17,7 +17,7 @@ package org.jivesoftware.smackx.ox.listener.internal; import org.jivesoftware.smack.packet.Message; -import org.jivesoftware.smackx.ox.chat.OpenPgpContact; +import org.jivesoftware.smackx.ox.OpenPgpContact; import org.jivesoftware.smackx.ox.element.SignElement; public interface SignElementReceivedListener { diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/SigncryptElementReceivedListener.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/SigncryptElementReceivedListener.java index 53a4961c6..5cf5f1ba9 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/SigncryptElementReceivedListener.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/listener/internal/SigncryptElementReceivedListener.java @@ -17,7 +17,7 @@ package org.jivesoftware.smackx.ox.listener.internal; import org.jivesoftware.smack.packet.Message; -import org.jivesoftware.smackx.ox.chat.OpenPgpContact; +import org.jivesoftware.smackx.ox.OpenPgpContact; import org.jivesoftware.smackx.ox.element.SigncryptElement; public interface SigncryptElementReceivedListener { diff --git a/smack-openpgp/src/test/java/org/jivesoftware/smackx/ox/OpenPgpFingerprintsTest.java b/smack-openpgp/src/test/java/org/jivesoftware/smackx/ox/OpenPgpFingerprintsTest.java deleted file mode 100644 index c3a903da4..000000000 --- a/smack-openpgp/src/test/java/org/jivesoftware/smackx/ox/OpenPgpFingerprintsTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * - * Copyright 2018 Paul Schaub. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jivesoftware.smackx.ox; - -import static junit.framework.TestCase.assertEquals; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import org.jivesoftware.smack.test.util.SmackTestSuite; -import org.jivesoftware.smackx.ox.chat.OpenPgpFingerprints; - -import org.junit.Test; -import org.jxmpp.jid.JidTestUtil; - -public class OpenPgpFingerprintsTest extends SmackTestSuite { - - private static final OpenPgpV4Fingerprint fingerprint1 = new OpenPgpV4Fingerprint("47696d6d6520323020636861726163746572730a"); - private static final OpenPgpV4Fingerprint fingerprint2 = new OpenPgpV4Fingerprint("492e206e6565642e20656173746572656767730a"); - private static final OpenPgpV4Fingerprint fingerprint3 = new OpenPgpV4Fingerprint("4d6f7265206f66207468656d21204d6f7265210a"); - - @Test - public void activeKeysTest() { - Set announced = new HashSet<>(); - announced.add(fingerprint1); - announced.add(fingerprint2); - - Set available = new HashSet<>(); - available.add(fingerprint2); - available.add(fingerprint3); - - OpenPgpFingerprints fingerprints = new OpenPgpFingerprints( - JidTestUtil.BARE_JID_1, - announced, - available, - new HashMap()); - - assertEquals(announced, fingerprints.getAnnouncedKeys()); - assertEquals(available, fingerprints.getAvailableKeys()); - assertEquals(JidTestUtil.BARE_JID_1, fingerprints.getJid()); - assertEquals(0, fingerprints.getUnfetchableKeys().size()); - - Set active = new HashSet<>(); - active.add(fingerprint2); - - assertEquals(active, fingerprints.getActiveKeys()); - } -}