mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-08 20:11:08 +01:00
Add test
This commit is contained in:
parent
63e98cb4d6
commit
e23cf88082
4 changed files with 84 additions and 7 deletions
|
|
@ -239,12 +239,11 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
|||
}
|
||||
}
|
||||
|
||||
return decryptImpl(bytes, secretKeyRings, protector, trustedKeyIds, trustedKeys);
|
||||
return decryptImpl(bytes, secretKeyRings, protector, trustedKeys);
|
||||
}
|
||||
|
||||
DecryptedBytesAndMetadata decryptImpl(byte[] bytes, PGPSecretKeyRingCollection decryptionKeys,
|
||||
SecretKeyRingProtector protector,
|
||||
Set<Long> trustedKeyIds,
|
||||
Set<PGPPublicKeyRing> verificationKeys)
|
||||
throws SmackOpenPgpException, IOException {
|
||||
|
||||
|
|
@ -255,7 +254,7 @@ public class PainlessOpenPgpProvider implements OpenPgpProvider {
|
|||
fromEncrypted = PGPainless.createDecryptor()
|
||||
.onInputStream(encryptedBytes)
|
||||
.decryptWith(decryptionKeys, protector)
|
||||
.verifyWith(trustedKeyIds, verificationKeys)
|
||||
.verifyWith(verificationKeys)
|
||||
.ignoreMissingPublicKeys()
|
||||
.build();
|
||||
} catch (IOException | PGPException e) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
package org.jivesoftware.smackx.ox.bouncycastle;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.NoSuchProviderException;
|
||||
import java.security.Security;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
|
||||
import de.vanitasvitae.crypto.pgpainless.PGPainless;
|
||||
import de.vanitasvitae.crypto.pgpainless.key.UnprotectedKeysProtector;
|
||||
import de.vanitasvitae.crypto.pgpainless.key.generation.type.length.RsaLength;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.openpgp.PGPException;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
public class FileBasedPainlessOpenPgpStoreTest extends SmackTestSuite {
|
||||
|
||||
private static final File basePath;
|
||||
private static final BareJid alice;
|
||||
private static final BareJid bob;
|
||||
|
||||
static {
|
||||
String userHome = System.getProperty("user.home");
|
||||
if (userHome != null) {
|
||||
File f = new File(userHome);
|
||||
basePath = new File(f, ".config/smack-integration-test/ox/painless_ox_store");
|
||||
} else {
|
||||
basePath = new File("painless_ox_store");
|
||||
}
|
||||
|
||||
try {
|
||||
alice = JidCreate.bareFrom("alice@wonderland.lit");
|
||||
bob = JidCreate.bareFrom("bob@builder.tv");
|
||||
} catch (XmppStringprepException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storeSecretKeyRingsTest()
|
||||
throws PGPException, NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException,
|
||||
IOException {
|
||||
FileBasedPainlessOpenPgpStore store = new FileBasedPainlessOpenPgpStore(basePath, new UnprotectedKeysProtector());
|
||||
|
||||
PGPSecretKeyRing secretKey = PGPainless.generateKeyRing().simpleRsaKeyRing("xmpp:" + alice.toString(), RsaLength._3072);
|
||||
PGPSecretKeyRingCollection saving = new PGPSecretKeyRingCollection(Collections.singleton(secretKey));
|
||||
store.storeSecretKeyRing(alice, saving);
|
||||
|
||||
PGPSecretKeyRingCollection restored = store.getSecretKeyRings(alice);
|
||||
|
||||
assertTrue(Arrays.equals(saving.getEncoded(), restored.getEncoded()));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue