Ikey: Allow secret key backups

This commit is contained in:
Paul Schaub 2020-09-28 13:33:51 +02:00
parent 49eb137acb
commit 94d213b8dd
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
4 changed files with 38 additions and 5 deletions

View File

@ -65,7 +65,7 @@ public final class IkeyManager extends Manager {
public void startListeners() { public void startListeners() {
PepManager.getInstanceFor(connection()) PepManager.getInstanceFor(connection())
.addPepEventListener(IkeyConstants.IKEY_NODE, IkeyElement.class, pepEventListener); .addPepEventListener(IkeyConstants.SUBORDINATES_NODE, IkeyElement.class, pepEventListener);
} }
public void stopListeners() { public void stopListeners() {
@ -86,7 +86,7 @@ public final class IkeyManager extends Manager {
throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException, throws InterruptedException, PubSubException.NotALeafNodeException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
PepManager.getInstanceFor(connection()) PepManager.getInstanceFor(connection())
.publish(IkeyConstants.IKEY_NODE, new PayloadItem<>(ikeyElement)); .publish(IkeyConstants.SUBORDINATES_NODE, new PayloadItem<>(ikeyElement));
} }
public IkeyElement fetchIkeyElementOf(EntityBareJid jid) public IkeyElement fetchIkeyElementOf(EntityBareJid jid)
@ -107,7 +107,7 @@ public final class IkeyManager extends Manager {
throws PubSubException.NotALeafNodeException, SmackException.NoResponseException, throws PubSubException.NotALeafNodeException, SmackException.NoResponseException,
SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException,
PubSubException.NotAPubSubNodeException { PubSubException.NotAPubSubNodeException {
LeafNode node = pubSubManager.getLeafNode(IkeyConstants.IKEY_NODE); LeafNode node = pubSubManager.getLeafNode(IkeyConstants.SUBORDINATES_NODE);
List<PayloadItem<IkeyElement>> items = node.getItems(1); List<PayloadItem<IkeyElement>> items = node.getItems(1);
if (items.isEmpty()) { if (items.isEmpty()) {
return null; return null;

View File

@ -3,5 +3,6 @@ package org.jivesoftware.smackx.ikey.util;
public class IkeyConstants { public class IkeyConstants {
public static final String NAMESPACE = "urn:xmpp:ikey:0"; public static final String NAMESPACE = "urn:xmpp:ikey:0";
public static final String IKEY_NODE = NAMESPACE + ":ikey"; public static final String SUBORDINATES_NODE = NAMESPACE + ":subordinates";
public static final String SUPERORDINATE_NODE = NAMESPACE + ":superordinate";
} }

View File

@ -1,14 +1,23 @@
package org.jivesoftware.smackx.ikey_ox; package org.jivesoftware.smackx.ikey_ox;
import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.jivesoftware.smack.Manager; import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.ikey.IkeyManager; import org.jivesoftware.smackx.ikey.IkeyManager;
import org.jivesoftware.smackx.ikey.element.IkeyElement; import org.jivesoftware.smackx.ikey.element.IkeyElement;
import org.jivesoftware.smackx.ikey.element.SubordinateElement; import org.jivesoftware.smackx.ikey.element.SubordinateElement;
import org.jivesoftware.smackx.ikey.element.SubordinateListElement; import org.jivesoftware.smackx.ikey.element.SubordinateListElement;
import org.jivesoftware.smackx.ikey.element.SuperordinateElement; import org.jivesoftware.smackx.ikey.element.SuperordinateElement;
import org.jivesoftware.smackx.ikey.mechanism.IkeySignatureCreationMechanism; import org.jivesoftware.smackx.ikey.mechanism.IkeySignatureCreationMechanism;
import org.jivesoftware.smackx.ox.OpenPgpSecretKeyBackupPassphrase;
import org.jivesoftware.smackx.ox.element.SecretkeyElement;
import org.jivesoftware.smackx.ox.util.OpenPgpPubSubUtil;
import org.jivesoftware.smackx.ox.util.SecretKeyBackupHelper;
import org.jivesoftware.smackx.pep.PepManager;
import org.jivesoftware.smackx.pubsub.PubSubException;
import org.pgpainless.key.protection.SecretKeyRingProtector; import org.pgpainless.key.protection.SecretKeyRingProtector;
import java.io.IOException; import java.io.IOException;
@ -17,6 +26,8 @@ import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import static org.jivesoftware.smackx.ikey.util.IkeyConstants.SUPERORDINATE_NODE;
public final class OxIkeyManager extends Manager { public final class OxIkeyManager extends Manager {
private static final Map<XMPPConnection, OxIkeyManager> INSTANCES = new WeakHashMap<>(); private static final Map<XMPPConnection, OxIkeyManager> INSTANCES = new WeakHashMap<>();
@ -37,6 +48,21 @@ public final class OxIkeyManager extends Manager {
return manager; return manager;
} }
public SecretkeyElement fetchSecretIdentityKey()
throws InterruptedException, PubSubException.NotALeafNodeException,
XMPPException.XMPPErrorException, SmackException.NotConnectedException,
SmackException.NoResponseException {
return OpenPgpPubSubUtil.fetchSecretKey(PepManager.getInstanceFor(connection()), SUPERORDINATE_NODE);
}
public void depositSecretIdentityKey(PGPSecretKeyRing secretKey, OpenPgpSecretKeyBackupPassphrase passphrase)
throws InterruptedException, SmackException.NoResponseException,
SmackException.NotConnectedException, SmackException.FeatureNotSupportedException,
XMPPException.XMPPErrorException, PubSubException.NotALeafNodeException, IOException, PGPException {
SecretkeyElement secretkeyElement = SecretKeyBackupHelper.createSecretkeyElement(secretKey.getEncoded(), passphrase);
OpenPgpPubSubUtil.depositSecretKey(connection(), secretkeyElement, SUPERORDINATE_NODE);
}
public IkeyElement createOxIkeyElement(PGPSecretKeyRing secretKeys, public IkeyElement createOxIkeyElement(PGPSecretKeyRing secretKeys,
SecretKeyRingProtector keyRingProtector, SecretKeyRingProtector keyRingProtector,
SubordinateElement... subordinateElements) throws IOException { SubordinateElement... subordinateElements) throws IOException {
@ -46,4 +72,10 @@ public final class OxIkeyManager extends Manager {
new Date(), Arrays.asList(subordinateElements)); new Date(), Arrays.asList(subordinateElements));
return ikeyManager.createIkeyElement(mechanism, superordinateElement, subordinateListElement); return ikeyManager.createIkeyElement(mechanism, superordinateElement, subordinateListElement);
} }
public boolean deleteSecretIdentityKeyNode()
throws XMPPException.XMPPErrorException, SmackException.NotConnectedException,
InterruptedException, SmackException.NoResponseException {
return OpenPgpPubSubUtil.deleteSecretKeyNode(PepManager.getInstanceFor(connection()), SUPERORDINATE_NODE);
}
} }

@ -1 +1 @@
Subproject commit 1c822dcaa4d4cb92d8b2d048f49bb69885143d56 Subproject commit 5c40669a73ad2daabd3c0a303e97f02dea62f8a6