use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.
the class PublicKeysListElementTest method providerTest.
@Test
public void providerTest() throws Exception {
String expected = "<public-keys-list xmlns='urn:xmpp:openpgp:0'>" + "<pubkey-metadata " + "v4-fingerprint='1357B01865B2503C18453D208CAC2A9678548E35' " + "date='2018-03-01T15:26:12.000+00:00'" + "/>" + "<pubkey-metadata " + "v4-fingerprint='67819B343B2AB70DED9320872C6464AF2A8E4C02' " + "date='1953-05-16T12:00:00.000+00:00'" + "/>" + "</public-keys-list>";
Date date1 = XmppDateTime.parseDate("2018-03-01T15:26:12.000+00:00");
Date date2 = XmppDateTime.parseDate("1953-05-16T12:00:00.000+00:00");
PublicKeysListElement.PubkeyMetadataElement child1 = new PublicKeysListElement.PubkeyMetadataElement(new OpenPgpV4Fingerprint("1357B01865B2503C18453D208CAC2A9678548E35"), date1);
PublicKeysListElement.PubkeyMetadataElement child2 = new PublicKeysListElement.PubkeyMetadataElement(new OpenPgpV4Fingerprint("67819B343B2AB70DED9320872C6464AF2A8E4C02"), date2);
PublicKeysListElement element = PublicKeysListElement.builder().addMetadata(child1).addMetadata(child2).build();
assertXmlSimilar(expected, element.toXML().toString());
XmlPullParser parser = TestUtils.getParser(expected);
PublicKeysListElement parsed = PublicKeysListElementProvider.TEST_INSTANCE.parse(parser);
assertEquals(element.getMetadata(), parsed.getMetadata());
}
use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.
the class PublicKeysListElementTest method listBuilderRefusesDuplicatesTest.
@Test
public void listBuilderRefusesDuplicatesTest() {
PublicKeysListElement.Builder builder = PublicKeysListElement.builder();
String fp40 = "49545320414c4c2041424f555420444120484558";
Date oneDate = new Date(12337883234L);
Date otherDate = new Date(8888348384L);
// Check if size of metadata is one after insert.
builder.addMetadata(new PublicKeysListElement.PubkeyMetadataElement(new OpenPgpV4Fingerprint(fp40), oneDate));
assertEquals(builder.build().getMetadata().size(), 1);
// Check if size is still one after inserting element with same fp.
builder.addMetadata(new PublicKeysListElement.PubkeyMetadataElement(new OpenPgpV4Fingerprint(fp40), otherDate));
assertEquals(builder.build().getMetadata().size(), 1);
}
use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.
the class SecretKeyBackupHelper method createSecretkeyElement.
/**
* Create a {@link SecretkeyElement} which contains the secret keys listed in {@code fingerprints} and is encrypted
* symmetrically using the {@code backupCode}.
*
* @param provider {@link OpenPgpProvider} for symmetric encryption.
* @param owner owner of the secret keys (usually our jid).
* @param fingerprints set of {@link OpenPgpV4Fingerprint}s of the keys which are going to be backed up.
* @param backupCode passphrase for symmetric encryption.
* @return {@link SecretkeyElement}
*
* @throws PGPException PGP is brittle
* @throws IOException IO is dangerous
* @throws MissingOpenPgpKeyException in case one of the keys whose fingerprint is in {@code fingerprints} is
* not accessible.
*/
public static SecretkeyElement createSecretkeyElement(OpenPgpProvider provider, BareJid owner, Set<OpenPgpV4Fingerprint> fingerprints, OpenPgpSecretKeyBackupPassphrase backupCode) throws PGPException, IOException, MissingOpenPgpKeyException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (OpenPgpV4Fingerprint fingerprint : fingerprints) {
PGPSecretKeyRing key = provider.getStore().getSecretKeyRing(owner, fingerprint);
if (key == null) {
throw new MissingOpenPgpKeyException(owner, fingerprint);
}
byte[] bytes = key.getEncoded();
buffer.write(bytes);
}
return createSecretkeyElement(buffer.toByteArray(), backupCode);
}
Aggregations