use of org.bouncycastle.openpgp.PGPSecretKeyRing in project Smack by igniterealtime.
the class OpenPgpSelf method getSigningKeyRing.
/**
* Return the {@link PGPSecretKeyRing} which we will use to sign our messages.
* @return signing key
* @throws IOException IO is dangerous
* @throws PGPException PGP is brittle
*/
public PGPSecretKeyRing getSigningKeyRing() throws IOException, PGPException {
PGPSecretKeyRingCollection secretKeyRings = getSecretKeys();
if (secretKeyRings == null) {
return null;
}
PGPSecretKeyRing signingKeyRing = null;
for (PGPSecretKeyRing ring : secretKeyRings) {
if (signingKeyRing == null) {
signingKeyRing = ring;
continue;
}
if (ring.getPublicKey().getCreationTime().after(signingKeyRing.getPublicKey().getCreationTime())) {
signingKeyRing = ring;
}
}
return signingKeyRing;
}
use of org.bouncycastle.openpgp.PGPSecretKeyRing in project Smack by igniterealtime.
the class OpenPgpStoreTest method t06_key_keyReloadTest.
@Test
public void t06_key_keyReloadTest() throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, IOException, MissingUserIdOnKeyException {
PGPSecretKeyRing secretKeys = openPgpStoreInstance1.generateKeyRing(alice);
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys);
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
openPgpStoreInstance1.importSecretKey(alice, secretKeys);
openPgpStoreInstance1.importPublicKey(alice, publicKeys);
assertNotNull(openPgpStoreInstance2.getSecretKeysOf(alice));
assertNotNull(openPgpStoreInstance2.getPublicKeysOf(alice));
// Clean up
openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint);
openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint);
openPgpStoreInstance2.deletePublicKeyRing(alice, fingerprint);
openPgpStoreInstance2.deleteSecretKeyRing(alice, fingerprint);
}
use of org.bouncycastle.openpgp.PGPSecretKeyRing in project Smack by igniterealtime.
the class OpenPgpStoreTest method t02_key_importKeysTest.
@Test
public void t02_key_importKeysTest() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, MissingUserIdOnKeyException {
// Test for nullity of all possible values.
PGPSecretKeyRing secretKeys = openPgpStoreInstance1.generateKeyRing(alice);
PGPPublicKeyRing publicKeys = KeyRingUtils.publicKeyRingFrom(secretKeys);
assertNotNull(secretKeys);
assertNotNull(publicKeys);
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(secretKeys);
OpenPgpContact cAlice = openPgpStoreInstance1.getOpenPgpContact(alice);
assertNull(cAlice.getAnyPublicKeys());
assertEquals(fingerprint, new OpenPgpV4Fingerprint(secretKeys));
assertNull(openPgpStoreInstance1.getPublicKeysOf(alice));
assertNull(openPgpStoreInstance1.getSecretKeysOf(alice));
openPgpStoreInstance1.importPublicKey(alice, publicKeys);
assertArrayEquals(publicKeys.getEncoded(), openPgpStoreInstance1.getPublicKeysOf(alice).getEncoded());
assertNotNull(openPgpStoreInstance1.getPublicKeyRing(alice, fingerprint));
assertNull(openPgpStoreInstance1.getSecretKeysOf(alice));
cAlice = openPgpStoreInstance1.getOpenPgpContact(alice);
assertNotNull(cAlice.getAnyPublicKeys());
// Import keys a second time -> No change expected.
openPgpStoreInstance1.importPublicKey(alice, publicKeys);
assertArrayEquals(publicKeys.getEncoded(), openPgpStoreInstance1.getPublicKeysOf(alice).getEncoded());
openPgpStoreInstance1.importSecretKey(alice, secretKeys);
assertArrayEquals(secretKeys.getEncoded(), openPgpStoreInstance1.getSecretKeysOf(alice).getEncoded());
openPgpStoreInstance1.importSecretKey(alice, secretKeys);
assertNotNull(openPgpStoreInstance1.getSecretKeysOf(alice));
assertArrayEquals(secretKeys.getEncoded(), openPgpStoreInstance1.getSecretKeysOf(alice).getEncoded());
assertNotNull(openPgpStoreInstance1.getSecretKeyRing(alice, fingerprint));
assertArrayEquals(secretKeys.getEncoded(), openPgpStoreInstance1.getSecretKeyRing(alice, fingerprint).getEncoded());
assertArrayEquals(publicKeys.getEncoded(), openPgpStoreInstance1.getPublicKeyRing(alice, fingerprint).getEncoded());
// Clean up
openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint);
openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint);
}
use of org.bouncycastle.openpgp.PGPSecretKeyRing in project Smack by igniterealtime.
the class OpenPgpStoreTest method t00_deleteTest.
/*
OpenPgpKeyStore
*/
@Test
public void t00_deleteTest() throws IOException, PGPException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, MissingUserIdOnKeyException {
assertNull(openPgpStoreInstance1.getSecretKeysOf(alice));
assertNull(openPgpStoreInstance1.getPublicKeysOf(alice));
PGPSecretKeyRing keys = openPgpStoreInstance1.generateKeyRing(alice);
OpenPgpV4Fingerprint fingerprint = new OpenPgpV4Fingerprint(keys);
openPgpStoreInstance1.importSecretKey(alice, keys);
openPgpStoreInstance1.importPublicKey(alice, KeyRingUtils.publicKeyRingFrom(keys));
assertNotNull(openPgpStoreInstance1.getSecretKeysOf(alice));
assertNotNull(openPgpStoreInstance1.getPublicKeysOf(alice));
openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint);
openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint);
assertNull(openPgpStoreInstance1.getPublicKeysOf(alice));
assertNull(openPgpStoreInstance1.getSecretKeysOf(alice));
}
use of org.bouncycastle.openpgp.PGPSecretKeyRing in project Smack by igniterealtime.
the class OpenPgpStoreTest method t07_multipleKeysTest.
@Test
public void t07_multipleKeysTest() throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, IOException, MissingUserIdOnKeyException {
PGPSecretKeyRing one = openPgpStoreInstance1.generateKeyRing(alice);
PGPSecretKeyRing two = openPgpStoreInstance1.generateKeyRing(alice);
OpenPgpV4Fingerprint fingerprint1 = new OpenPgpV4Fingerprint(one);
OpenPgpV4Fingerprint fingerprint2 = new OpenPgpV4Fingerprint(two);
openPgpStoreInstance1.importSecretKey(alice, one);
openPgpStoreInstance1.importSecretKey(alice, two);
openPgpStoreInstance1.importPublicKey(alice, KeyRingUtils.publicKeyRingFrom(one));
openPgpStoreInstance1.importPublicKey(alice, KeyRingUtils.publicKeyRingFrom(two));
assertArrayEquals(one.getEncoded(), openPgpStoreInstance1.getSecretKeyRing(alice, fingerprint1).getEncoded());
assertArrayEquals(two.getEncoded(), openPgpStoreInstance1.getSecretKeyRing(alice, fingerprint2).getEncoded());
assertArrayEquals(one.getEncoded(), openPgpStoreInstance1.getSecretKeysOf(alice).getSecretKeyRing(fingerprint1.getKeyId()).getEncoded());
assertArrayEquals(KeyRingUtils.publicKeyRingFrom(one).getEncoded(), openPgpStoreInstance1.getPublicKeyRing(alice, fingerprint1).getEncoded());
// Cleanup
openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint1);
openPgpStoreInstance1.deletePublicKeyRing(alice, fingerprint2);
openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint1);
openPgpStoreInstance1.deleteSecretKeyRing(alice, fingerprint2);
}
Aggregations