use of org.pgpainless.key.info.KeyRingInfo in project Smack by igniterealtime.
the class OpenPgpContact method getAnnouncedPublicKeys.
/**
* Return any announced public keys. This is the set returned by {@link #getAnyPublicKeys()} with non-announced
* keys and keys which lack a user-id with the contacts jid removed.
*
* @return announced keys of the contact
*
* @throws IOException IO is dangerous
* @throws PGPException PGP is brittle
*/
public PGPPublicKeyRingCollection getAnnouncedPublicKeys() throws IOException, PGPException {
PGPPublicKeyRingCollection anyKeys = getAnyPublicKeys();
Map<OpenPgpV4Fingerprint, Date> announced = store.getAnnouncedFingerprintsOf(jid);
PGPPublicKeyRingCollection announcedKeysCollection = null;
for (OpenPgpV4Fingerprint announcedFingerprint : announced.keySet()) {
PGPPublicKeyRing ring = anyKeys.getPublicKeyRing(announcedFingerprint.getKeyId());
if (ring == null)
continue;
if (!new KeyRingInfo(ring).isUserIdValid("xmpp:" + getJid().toString())) {
LOGGER.log(Level.WARNING, "Ignore key " + Long.toHexString(ring.getPublicKey().getKeyID()) + " as it lacks the user-id \"xmpp" + getJid().toString() + "\"");
continue;
}
if (announcedKeysCollection == null) {
announcedKeysCollection = new PGPPublicKeyRingCollection(Collections.singleton(ring));
} else {
announcedKeysCollection = PGPPublicKeyRingCollection.addPublicKeyRing(announcedKeysCollection, ring);
}
}
return announcedKeysCollection;
}
use of org.pgpainless.key.info.KeyRingInfo in project Smack by igniterealtime.
the class AbstractOpenPgpKeyStore method importSecretKey.
@Override
public void importSecretKey(BareJid owner, PGPSecretKeyRing secretKeys) throws IOException, PGPException, MissingUserIdOnKeyException {
if (!new KeyRingInfo(secretKeys).isUserIdValid("xmpp:" + owner.toString())) {
throw new MissingUserIdOnKeyException(owner, new OpenPgpV4Fingerprint(secretKeys));
}
PGPSecretKeyRingCollection secretKeyRings = getSecretKeysOf(owner);
try {
if (secretKeyRings != null) {
secretKeyRings = PGPSecretKeyRingCollection.addSecretKeyRing(secretKeyRings, secretKeys);
} else {
secretKeyRings = new PGPSecretKeyRingCollection(Collections.singleton(secretKeys));
}
} catch (IllegalArgumentException e) {
LOGGER.log(Level.INFO, "Skipping secret key ring " + Long.toHexString(secretKeys.getPublicKey().getKeyID()) + " as it is already in the key ring of " + owner.toString());
}
this.secretKeyRingCollections.put(owner, secretKeyRings);
writeSecretKeysOf(owner, secretKeyRings);
}
use of org.pgpainless.key.info.KeyRingInfo in project Smack by igniterealtime.
the class AbstractOpenPgpKeyStore method importPublicKey.
@Override
public void importPublicKey(BareJid owner, PGPPublicKeyRing publicKeys) throws IOException, PGPException, MissingUserIdOnKeyException {
if (!new KeyRingInfo(publicKeys).isUserIdValid("xmpp:" + owner.toString())) {
throw new MissingUserIdOnKeyException(owner, new OpenPgpV4Fingerprint(publicKeys));
}
PGPPublicKeyRingCollection publicKeyRings = getPublicKeysOf(owner);
try {
if (publicKeyRings != null) {
publicKeyRings = PGPPublicKeyRingCollection.addPublicKeyRing(publicKeyRings, publicKeys);
} else {
publicKeyRings = new PGPPublicKeyRingCollection(Collections.singleton(publicKeys));
}
} catch (IllegalArgumentException e) {
LOGGER.log(Level.FINE, "Skipping public key ring " + Long.toHexString(publicKeys.getPublicKey().getKeyID()) + " as it is already in the key ring of " + owner.toString(), e);
}
this.publicKeyRingCollections.put(owner, publicKeyRings);
writePublicKeysOf(owner, publicKeyRings);
}
Aggregations