From 079e324fe06fc9d35028f7c05e1a5cdd7924fba7 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Mon, 28 Sep 2020 13:33:15 +0200 Subject: [PATCH] OpenPgpPubSubUtil: Allow custom nodes for secret key backup --- .../smackx/ox/util/OpenPgpPubSubUtil.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/util/OpenPgpPubSubUtil.java b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/util/OpenPgpPubSubUtil.java index 0e418d80b..d60d61b25 100644 --- a/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/util/OpenPgpPubSubUtil.java +++ b/smack-openpgp/src/main/java/org/jivesoftware/smackx/ox/util/OpenPgpPubSubUtil.java @@ -344,11 +344,18 @@ public class OpenPgpPubSubUtil { throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException, SmackException.FeatureNotSupportedException { + depositSecretKey(connection, element, PEP_NODE_SECRET_KEY); + } + + public static void depositSecretKey(XMPPConnection connection, SecretkeyElement element, String nodeName) + throws SmackException.FeatureNotSupportedException, XMPPException.XMPPErrorException, + SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException, + PubSubException.NotALeafNodeException { if (!OpenPgpManager.serverSupportsSecretKeyBackups(connection)) { throw new SmackException.FeatureNotSupportedException("http://jabber.org/protocol/pubsub#access-whitelist"); } PubSubManager pm = PepManager.getInstanceFor(connection).getPepPubSubManager(); - LeafNode secretKeyNode = pm.getOrCreateLeafNode(PEP_NODE_SECRET_KEY); + LeafNode secretKeyNode = pm.getOrCreateLeafNode(nodeName); OpenPgpPubSubUtil.changeAccessModelIfNecessary(secretKeyNode, AccessModel.whitelist); secretKeyNode.publish(new PayloadItem<>(element)); @@ -372,8 +379,14 @@ public class OpenPgpPubSubUtil { public static SecretkeyElement fetchSecretKey(PepManager pepManager) throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException { + return fetchSecretKey(pepManager, PEP_NODE_SECRET_KEY); + } + + public static SecretkeyElement fetchSecretKey(PepManager pepManager, String nodeName) + throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, + SmackException.NotConnectedException, SmackException.NoResponseException { PubSubManager pm = pepManager.getPepPubSubManager(); - LeafNode secretKeyNode = pm.getOrCreateLeafNode(PEP_NODE_SECRET_KEY); + LeafNode secretKeyNode = pm.getOrCreateLeafNode(nodeName); List> list = secretKeyNode.getItems(1); if (list.size() == 0) { LOGGER.log(Level.INFO, "No secret key published!"); @@ -397,8 +410,14 @@ public class OpenPgpPubSubUtil { public static boolean deleteSecretKeyNode(PepManager pepManager) throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException { + return deleteSecretKeyNode(pepManager, PEP_NODE_SECRET_KEY); + } + + public static boolean deleteSecretKeyNode(PepManager pepManager, String nodeName) + throws XMPPException.XMPPErrorException, SmackException.NotConnectedException, + InterruptedException, SmackException.NoResponseException { PubSubManager pm = pepManager.getPepPubSubManager(); - return pm.deleteNode(PEP_NODE_SECRET_KEY); + return pm.deleteNode(nodeName); } /**