@Override public PGPSecretKeyRing getSecretKeyRing(BareJid owner, OpenPgpV4Fingerprint fingerprint) throws IOException, PGPException { PGPSecretKeyRingCollection secretKeyRings = getSecretKeysOf(owner); if (secretKeyRings != null) { return secretKeyRings.getSecretKeyRing(fingerprint.getKeyId()); } return null; }
@Override public PGPPublicKeyRing getPublicKeyRing(BareJid owner, OpenPgpV4Fingerprint fingerprint) throws IOException, PGPException { PGPPublicKeyRingCollection publicKeyRings = getPublicKeysOf(owner); if (publicKeyRings != null) { return publicKeyRings.getPublicKeyRing(fingerprint.getKeyId()); } return null; }
@Override public void deleteSecretKeyRing(BareJid owner, OpenPgpV4Fingerprint fingerprint) throws IOException, PGPException { PGPSecretKeyRingCollection secretKeyRings = getSecretKeysOf(owner); if (secretKeyRings.contains(fingerprint.getKeyId())) { secretKeyRings = PGPSecretKeyRingCollection.removeSecretKeyRing(secretKeyRings, secretKeyRings.getSecretKeyRing(fingerprint.getKeyId())); if (!secretKeyRings.iterator().hasNext()) { secretKeyRings = null; } this.secretKeyRingCollections.put(owner, secretKeyRings); writeSecretKeysOf(owner, secretKeyRings); } }
@Override public void deletePublicKeyRing(BareJid owner, OpenPgpV4Fingerprint fingerprint) throws IOException, PGPException { PGPPublicKeyRingCollection publicKeyRings = getPublicKeysOf(owner); if (publicKeyRings.contains(fingerprint.getKeyId())) { publicKeyRings = PGPPublicKeyRingCollection.removePublicKeyRing(publicKeyRings, publicKeyRings.getPublicKeyRing(fingerprint.getKeyId())); if (!publicKeyRings.iterator().hasNext()) { publicKeyRings = null; } this.publicKeyRingCollections.put(owner, publicKeyRings); writePublicKeysOf(owner, publicKeyRings); } }
Date fetchDate = fetchDates.get(fingerprint); if (fetchDate != null && fingerprintsAndDates.get(fingerprint) != null && fetchDate.after(fingerprintsAndDates.get(fingerprint))) { LOGGER.log(Level.FINE, "Skip key " + Long.toHexString(fingerprint.getKeyId()) + " as we already have the most recent version. " + "Last announced: " + fingerprintsAndDates.get(fingerprint).toString() + " Last fetched: " + fetchDate.toString()); continue; fetchDates.put(fingerprint, new Date()); if (key == null) { LOGGER.log(Level.WARNING, "Public key " + Long.toHexString(fingerprint.getKeyId()) + " can not be imported: Is null"); unfetchableKeys.put(fingerprint, new NullPointerException("Public key is null.")); } catch (PubSubException.NotAPubSubNodeException | PubSubException.NotALeafNodeException | XMPPException.XMPPErrorException e) { LOGGER.log(Level.WARNING, "Error fetching public key " + Long.toHexString(fingerprint.getKeyId()), e); unfetchableKeys.put(fingerprint, e); } catch (PGPException | IOException e) { LOGGER.log(Level.WARNING, "Public key " + Long.toHexString(fingerprint.getKeyId()) + " can not be imported.", e); unfetchableKeys.put(fingerprint, e); } catch (MissingUserIdOnKeyException e) { LOGGER.log(Level.WARNING, "Public key " + Long.toHexString(fingerprint.getKeyId()) + " is missing the user-id \"xmpp:" + getJid() + "\". Refuse to import it.", e); unfetchableKeys.put(fingerprint, e);
@Test public void t07_multipleKeysTest() throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, IOException, MissingUserIdOnKeyException { PGPKeyRing one = openPgpStoreInstance1.generateKeyRing(alice); PGPKeyRing two = openPgpStoreInstance1.generateKeyRing(alice); OpenPgpV4Fingerprint fingerprint1 = new OpenPgpV4Fingerprint(one.getSecretKeys()); OpenPgpV4Fingerprint fingerprint2 = new OpenPgpV4Fingerprint(two.getSecretKeys()); openPgpStoreInstance1.importSecretKey(alice, one.getSecretKeys()); openPgpStoreInstance1.importSecretKey(alice, two.getSecretKeys()); openPgpStoreInstance1.importPublicKey(alice, one.getPublicKeys()); openPgpStoreInstance1.importPublicKey(alice, two.getPublicKeys()); assertTrue(Arrays.equals(one.getSecretKeys().getEncoded(), openPgpStoreInstance1.getSecretKeyRing(alice, fingerprint1).getEncoded())); assertTrue(Arrays.equals(two.getSecretKeys().getEncoded(), openPgpStoreInstance1.getSecretKeyRing(alice, fingerprint2).getEncoded())); assertTrue(Arrays.equals(one.getSecretKeys().getEncoded(), openPgpStoreInstance1.getSecretKeysOf(alice).getSecretKeyRing(fingerprint1.getKeyId()).getEncoded())); assertTrue(Arrays.equals(one.getPublicKeys().getEncoded(), openPgpStoreInstance1.getPublicKeyRing(alice, fingerprint1).getEncoded())); // Cleanup openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint1); openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint2); openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint1); openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint2); }
assertTrue(bobSelf.getSecretKeys().contains(decryptionFingerprint.getKeyId())); assertTrue(decrypted.getMetadata().getVerifiedSignaturesFingerprints().contains(aliceFingerprint)); assertTrue(bobSelf.getSecretKeys().contains(decryptionFingerprint.getKeyId())); assertTrue(decrypted.getMetadata().getVerifiedSignaturesFingerprints().isEmpty());
assertNotNull(bobSelf.getSigningKeyRing().getPublicKey(metadata.getDecryptionFingerprint().getKeyId()));