Search in sources :

Example 6 with OpenPgpV4Fingerprint

use of org.pgpainless.key.OpenPgpV4Fingerprint 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);
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) PGPSecretKeyRing(org.bouncycastle.openpgp.PGPSecretKeyRing) Test(org.junit.Test)

Example 7 with OpenPgpV4Fingerprint

use of org.pgpainless.key.OpenPgpV4Fingerprint 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);
}
Also used : PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) PGPSecretKeyRing(org.bouncycastle.openpgp.PGPSecretKeyRing) Test(org.junit.Test)

Example 8 with OpenPgpV4Fingerprint

use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.

the class OpenPgpStoreTest method t11_key_fetchDateTest.

@Test
public void t11_key_fetchDateTest() throws IOException {
    Map<OpenPgpV4Fingerprint, Date> fetchDates1 = openPgpStoreInstance1.getPublicKeyFetchDates(alice);
    assertNotNull(fetchDates1);
    assertTrue(fetchDates1.isEmpty());
    Date date1 = new Date(85092830954L);
    fetchDates1.put(finger1, date1);
    openPgpStoreInstance1.setPublicKeyFetchDates(alice, fetchDates1);
    Map<OpenPgpV4Fingerprint, Date> fetchDates2 = openPgpStoreInstance1.getPublicKeyFetchDates(alice);
    assertNotNull(fetchDates2);
    assertFalse(fetchDates2.isEmpty());
    assertEquals(fetchDates1, fetchDates2);
    Map<OpenPgpV4Fingerprint, Date> fetchDates3 = openPgpStoreInstance2.getPublicKeyFetchDates(alice);
    assertNotNull(fetchDates3);
    assertEquals(fetchDates1, fetchDates3);
    openPgpStoreInstance1.setPublicKeyFetchDates(alice, null);
    openPgpStoreInstance2.setPublicKeyFetchDates(alice, null);
    assertNotNull(openPgpStoreInstance1.getPublicKeyFetchDates(alice));
    assertTrue(openPgpStoreInstance1.getPublicKeyFetchDates(alice).isEmpty());
}
Also used : OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) Date(java.util.Date) Test(org.junit.Test)

Example 9 with OpenPgpV4Fingerprint

use of org.pgpainless.key.OpenPgpV4Fingerprint in project Smack by igniterealtime.

the class OpenPgpStoreTest method t10_meta_emptyStoreTest.

/*
    OpenPgpMetadataStore
     */
@Test
public void t10_meta_emptyStoreTest() throws IOException {
    assertNotNull(openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice));
    assertTrue(openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice).isEmpty());
    Map<OpenPgpV4Fingerprint, Date> map = new HashMap<>();
    Date date1 = new Date(12354563423L);
    Date date2 = new Date(8274729879812L);
    map.put(finger1, date1);
    map.put(finger2, date2);
    openPgpStoreInstance1.setAnnouncedFingerprintsOf(alice, map);
    assertFalse(openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice).isEmpty());
    assertEquals(map, openPgpStoreInstance1.getAnnouncedFingerprintsOf(alice));
    assertTrue(openPgpStoreInstance1.getAnnouncedFingerprintsOf(bob).isEmpty());
    assertFalse(openPgpStoreInstance2.getAnnouncedFingerprintsOf(alice).isEmpty());
    assertEquals(map, openPgpStoreInstance2.getAnnouncedFingerprintsOf(alice));
    openPgpStoreInstance1.setAnnouncedFingerprintsOf(alice, Collections.emptyMap());
    openPgpStoreInstance2.setAnnouncedFingerprintsOf(alice, Collections.emptyMap());
}
Also used : HashMap(java.util.HashMap) OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) Date(java.util.Date) Test(org.junit.Test)

Example 10 with OpenPgpV4Fingerprint

use of org.pgpainless.key.OpenPgpV4Fingerprint 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));
}
Also used : OpenPgpV4Fingerprint(org.pgpainless.key.OpenPgpV4Fingerprint) PGPSecretKeyRing(org.bouncycastle.openpgp.PGPSecretKeyRing) Test(org.junit.Test)

Aggregations

OpenPgpV4Fingerprint (org.pgpainless.key.OpenPgpV4Fingerprint)28 Date (java.util.Date)11 PGPSecretKeyRing (org.bouncycastle.openpgp.PGPSecretKeyRing)11 PGPPublicKeyRing (org.bouncycastle.openpgp.PGPPublicKeyRing)8 Test (org.junit.Test)7 Test (org.junit.jupiter.api.Test)5 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 PGPPublicKeyRingCollection (org.bouncycastle.openpgp.PGPPublicKeyRingCollection)3 PainlessOpenPgpProvider (org.jivesoftware.smackx.ox.crypto.PainlessOpenPgpProvider)3 PublicKeysListElement (org.jivesoftware.smackx.ox.element.PublicKeysListElement)3 SecretkeyElement (org.jivesoftware.smackx.ox.element.SecretkeyElement)3 MissingUserIdOnKeyException (org.jivesoftware.smackx.ox.exception.MissingUserIdOnKeyException)3 OpenPgpStore (org.jivesoftware.smackx.ox.store.definition.OpenPgpStore)3 FileBasedOpenPgpStore (org.jivesoftware.smackx.ox.store.filebased.FileBasedOpenPgpStore)3 KeyRingInfo (org.pgpainless.key.info.KeyRingInfo)3 UnprotectedKeysProtector (org.pgpainless.key.protection.UnprotectedKeysProtector)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2