Search in sources :

Example 1 with KeyRingInfo

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;
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) PGPPublicKeyRingCollection(org.bouncycastle.openpgp.PGPPublicKeyRingCollection) KeyRingInfo(org.pgpainless.key.info.KeyRingInfo) OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) Date(java.util.Date)

Example 2 with KeyRingInfo

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);
}
Also used : KeyRingInfo(org.pgpainless.key.info.KeyRingInfo) PGPSecretKeyRingCollection(org.bouncycastle.openpgp.PGPSecretKeyRingCollection) OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) MissingUserIdOnKeyException(org.jivesoftware.smackx.ox.exception.MissingUserIdOnKeyException)

Example 3 with KeyRingInfo

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);
}
Also used : PGPPublicKeyRingCollection(org.bouncycastle.openpgp.PGPPublicKeyRingCollection) KeyRingInfo(org.pgpainless.key.info.KeyRingInfo) OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) MissingUserIdOnKeyException(org.jivesoftware.smackx.ox.exception.MissingUserIdOnKeyException)

Aggregations

OpenPgpV4Fingerprint (org.pgpainless.key.OpenPgpV4Fingerprint)3 KeyRingInfo (org.pgpainless.key.info.KeyRingInfo)3 PGPPublicKeyRingCollection (org.bouncycastle.openpgp.PGPPublicKeyRingCollection)2 MissingUserIdOnKeyException (org.jivesoftware.smackx.ox.exception.MissingUserIdOnKeyException)2 Date (java.util.Date)1 PGPPublicKeyRing (org.bouncycastle.openpgp.PGPPublicKeyRing)1 PGPSecretKeyRingCollection (org.bouncycastle.openpgp.PGPSecretKeyRingCollection)1