2018-07-04 16:02:03 +02:00
|
|
|
package org.jivesoftware.smackx.ox;
|
2018-05-30 22:06:09 +02:00
|
|
|
|
2018-06-13 18:39:09 +02:00
|
|
|
import java.io.IOException;
|
2018-07-03 18:07:54 +02:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.logging.Logger;
|
2018-05-30 22:06:09 +02:00
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
import org.jivesoftware.smackx.ox.store.definition.OpenPgpStore;
|
2018-07-05 13:44:40 +02:00
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
import org.bouncycastle.openpgp.PGPException;
|
|
|
|
import org.bouncycastle.openpgp.PGPPublicKeyRing;
|
|
|
|
import org.bouncycastle.openpgp.PGPPublicKeyRingCollection;
|
2018-06-13 18:39:09 +02:00
|
|
|
import org.jxmpp.jid.BareJid;
|
2018-07-08 19:36:44 +02:00
|
|
|
import org.pgpainless.pgpainless.key.OpenPgpV4Fingerprint;
|
2018-05-30 22:06:09 +02:00
|
|
|
|
2018-07-03 18:07:54 +02:00
|
|
|
public class OpenPgpContact {
|
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
private final Logger LOGGER;
|
2018-05-30 22:06:09 +02:00
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
protected final BareJid jid;
|
|
|
|
protected final OpenPgpStore store;
|
2018-07-03 18:07:54 +02:00
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
public OpenPgpContact(BareJid jid, OpenPgpStore store) {
|
2018-06-20 12:45:05 +02:00
|
|
|
this.jid = jid;
|
2018-07-08 19:36:44 +02:00
|
|
|
this.store = store;
|
|
|
|
LOGGER = Logger.getLogger(OpenPgpContact.class.getName() + ":" + jid.toString());
|
2018-05-30 22:06:09 +02:00
|
|
|
}
|
|
|
|
|
2018-06-20 12:45:05 +02:00
|
|
|
public BareJid getJid() {
|
|
|
|
return jid;
|
2018-06-20 11:02:30 +02:00
|
|
|
}
|
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
public PGPPublicKeyRingCollection getAnyPublicKeys() throws IOException, PGPException {
|
|
|
|
return store.getPublicKeysOf(jid);
|
2018-07-03 18:07:54 +02:00
|
|
|
}
|
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
public PGPPublicKeyRingCollection getAnnouncedPublicKeys() throws IOException, PGPException {
|
|
|
|
PGPPublicKeyRingCollection anyKeys = getAnyPublicKeys();
|
|
|
|
Set<OpenPgpV4Fingerprint> announced = store.getAnnouncedFingerprintsOf(jid).keySet();
|
2018-07-03 18:07:54 +02:00
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
PGPPublicKeyRingCollection announcedKeysCollection = anyKeys;
|
|
|
|
for (PGPPublicKeyRing ring : anyKeys) {
|
2018-07-03 18:07:54 +02:00
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(ring.getPublicKey());
|
2018-07-03 18:07:54 +02:00
|
|
|
|
2018-07-08 19:36:44 +02:00
|
|
|
if (!announced.contains(fingerprint)) {
|
|
|
|
announcedKeysCollection = PGPPublicKeyRingCollection.removePublicKeyRing(announcedKeysCollection, ring);
|
2018-07-03 18:07:54 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-08 19:36:44 +02:00
|
|
|
return announcedKeysCollection;
|
2018-06-20 11:02:30 +02:00
|
|
|
}
|
2018-05-30 22:06:09 +02:00
|
|
|
}
|