50 lines
2.2 KiB
Java
50 lines
2.2 KiB
Java
|
package org.jivesoftware.smackx.ikey_ox;
|
||
|
|
||
|
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||
|
import org.jivesoftware.smack.Manager;
|
||
|
import org.jivesoftware.smack.XMPPConnection;
|
||
|
import org.jivesoftware.smackx.ikey.IkeyManager;
|
||
|
import org.jivesoftware.smackx.ikey.element.IkeyElement;
|
||
|
import org.jivesoftware.smackx.ikey.element.SubordinateElement;
|
||
|
import org.jivesoftware.smackx.ikey.element.SubordinateListElement;
|
||
|
import org.jivesoftware.smackx.ikey.element.SuperordinateElement;
|
||
|
import org.jivesoftware.smackx.ikey.mechanism.IkeySignatureCreationMechanism;
|
||
|
import org.pgpainless.key.protection.SecretKeyRingProtector;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.Date;
|
||
|
import java.util.Map;
|
||
|
import java.util.WeakHashMap;
|
||
|
|
||
|
public final class OxIkeyManager extends Manager {
|
||
|
|
||
|
private static final Map<XMPPConnection, OxIkeyManager> INSTANCES = new WeakHashMap<>();
|
||
|
|
||
|
private final IkeyManager ikeyManager;
|
||
|
|
||
|
private OxIkeyManager(XMPPConnection connection) {
|
||
|
super(connection);
|
||
|
this.ikeyManager = IkeyManager.getInstanceFor(connection);
|
||
|
}
|
||
|
|
||
|
public static OxIkeyManager getInstanceFor(XMPPConnection connection) {
|
||
|
OxIkeyManager manager = INSTANCES.get(connection);
|
||
|
if (manager == null) {
|
||
|
manager = new OxIkeyManager(connection);
|
||
|
INSTANCES.put(connection, manager);
|
||
|
}
|
||
|
return manager;
|
||
|
}
|
||
|
|
||
|
public IkeyElement createOxIkeyElement(PGPSecretKeyRing secretKeys,
|
||
|
SecretKeyRingProtector keyRingProtector,
|
||
|
SubordinateElement... subordinateElements) throws IOException {
|
||
|
IkeySignatureCreationMechanism mechanism = new OxIkeySignatureCreationMechanism(secretKeys, keyRingProtector);
|
||
|
SuperordinateElement superordinateElement = new SuperordinateElement(secretKeys.getPublicKey().getEncoded());
|
||
|
SubordinateListElement subordinateListElement = new SubordinateListElement(connection().getUser().asEntityBareJid(),
|
||
|
new Date(), Arrays.asList(subordinateElements));
|
||
|
return ikeyManager.createIkeyElement(mechanism, superordinateElement, subordinateListElement);
|
||
|
}
|
||
|
}
|