1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-26 06:12:06 +01:00

Improve logging of tests

This commit is contained in:
Paul Schaub 2020-04-11 11:35:48 +02:00
parent 1828ea21e5
commit ba6e850f6f
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 24 additions and 24 deletions

View file

@ -32,7 +32,6 @@ import org.bouncycastle.openpgp.PGPException;
import org.bouncycastle.openpgp.PGPPublicKeyRing; import org.bouncycastle.openpgp.PGPPublicKeyRing;
import org.bouncycastle.openpgp.PGPSecretKeyRing; import org.bouncycastle.openpgp.PGPSecretKeyRing;
import org.bouncycastle.util.io.Streams; import org.bouncycastle.util.io.Streams;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.pgpainless.PGPainless; import org.pgpainless.PGPainless;
import org.pgpainless.algorithm.KeyFlag; import org.pgpainless.algorithm.KeyFlag;
@ -64,7 +63,6 @@ public class EncryptDecryptTest {
"Unfold the imagined happiness that both\n" + "Unfold the imagined happiness that both\n" +
"Receive in either by this dear encounter."; "Receive in either by this dear encounter.";
@Ignore
@Test @Test
public void freshKeysRsaToElGamalTest() public void freshKeysRsaToElGamalTest()
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
@ -77,17 +75,15 @@ public class EncryptDecryptTest {
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Ignore
@Test @Test
public void freshKeysRsaToRsaTest() public void freshKeysRsaToRsaTest()
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._4096); PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._4096); PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Ignore
@Test @Test
public void freshKeysEcToEcTest() public void freshKeysEcToEcTest()
throws IOException, PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { throws IOException, PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
@ -97,21 +93,19 @@ public class EncryptDecryptTest {
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Ignore
@Test @Test
public void freshKeysEcToRsaTest() public void freshKeysEcToRsaTest()
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
PGPKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit"); PGPKeyRing sender = PGPainless.generateKeyRing().simpleEcKeyRing("romeo@montague.lit");
PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._4096); PGPKeyRing recipient = PGPainless.generateKeyRing().simpleRsaKeyRing("juliet@capulet.lit", RsaLength._3072);
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);
} }
@Ignore
@Test @Test
public void freshKeysRsaToEcTest() public void freshKeysRsaToEcTest()
throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException { throws PGPException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, IOException {
PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._4096); PGPKeyRing sender = PGPainless.generateKeyRing().simpleRsaKeyRing("romeo@montague.lit", RsaLength._3072);
PGPKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit"); PGPKeyRing recipient = PGPainless.generateKeyRing().simpleEcKeyRing("juliet@capulet.lit");
encryptDecryptForSecretKeyRings(sender, recipient); encryptDecryptForSecretKeyRings(sender, recipient);

View file

@ -19,6 +19,8 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bouncycastle.bcpg.ArmoredOutputStream; import org.bouncycastle.bcpg.ArmoredOutputStream;
import org.bouncycastle.openpgp.PGPException; import org.bouncycastle.openpgp.PGPException;
@ -29,30 +31,32 @@ import org.pgpainless.key.collection.PGPKeyRing;
public class GenerateKeyTest { public class GenerateKeyTest {
private static final Logger LOGGER = Logger.getLogger(GenerateKeyTest.class.getName());
@Test @Test
public void generateKey() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException { public void generateKey() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, PGPException, IOException {
PGPKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("cryptie@encrypted.key", "password123"); PGPKeyRing keyRing = PGPainless.generateKeyRing().simpleEcKeyRing("fresh@encrypted.key", "password123");
print(keyRing.getPublicKeys().getPublicKey().getUserIDs().next());
print(new OpenPgpV4Fingerprint(keyRing.getPublicKeys()));
print(keyRing.getPublicKeys().getPublicKey().getKeyID());
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ArmoredOutputStream armor = new ArmoredOutputStream(bytes); ArmoredOutputStream armor = new ArmoredOutputStream(bytes);
keyRing.getPublicKeys().encode(armor); keyRing.getPublicKeys().encode(armor);
armor.close(); armor.close();
print(new String(bytes.toByteArray())); String publicKey = new String(bytes.toByteArray());
bytes = new ByteArrayOutputStream(); bytes = new ByteArrayOutputStream();
armor = new ArmoredOutputStream(bytes); armor = new ArmoredOutputStream(bytes);
keyRing.getSecretKeys().encode(armor); keyRing.getSecretKeys().encode(armor);
armor.close(); armor.close();
print(new String(bytes.toByteArray())); String privateKey = new String(bytes.toByteArray());
}
public void print(Object obj) { LOGGER.log(Level.INFO, String.format("Generated random fresh EC key ring.\n" +
// CHECKSTYLE:OFF "User-ID: %s\n" +
System.out.println(obj); "Fingerprint: %s\n" +
// CHECKSTYLE:ON "Key-ID: %s\n" +
"%s\n" +
"%s\n", keyRing.getPublicKeys().getPublicKey().getUserIDs().next(),
new OpenPgpV4Fingerprint(keyRing.getPublicKeys()),
keyRing.getPublicKeys().getPublicKey().getKeyID(),
publicKey, privateKey));
} }
} }

View file

@ -47,7 +47,8 @@ public class SymmetricEncryptionTest {
@Test @Test
public void testSymmetricEncryptionDecryption() throws IOException, PGPException { public void testSymmetricEncryptionDecryption() throws IOException, PGPException {
byte[] plain = message.getBytes(); byte[] plain = message.getBytes();
Passphrase passphrase = new Passphrase("choose_a_better_password_please".toCharArray()); String password = "choose_a_better_password_please";
Passphrase passphrase = new Passphrase(password.toCharArray());
byte[] enc = PGPainless.encryptWithPassword(plain, passphrase, SymmetricKeyAlgorithm.AES_128); byte[] enc = PGPainless.encryptWithPassword(plain, passphrase, SymmetricKeyAlgorithm.AES_128);
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
ArmoredOutputStream armor = new ArmoredOutputStream(out); ArmoredOutputStream armor = new ArmoredOutputStream(out);
@ -56,7 +57,8 @@ public class SymmetricEncryptionTest {
armor.close(); armor.close();
// Print cipher text for validation with GnuPG. // Print cipher text for validation with GnuPG.
LOGGER.log(Level.INFO, new String(out.toByteArray())); LOGGER.log(Level.INFO, String.format("Use ciphertext below for manual validation with GnuPG " +
"(passphrase = '%s').\n\n%s", password, new String(out.toByteArray())));
byte[] plain2 = PGPainless.decryptWithPassword(enc, passphrase); byte[] plain2 = PGPainless.decryptWithPassword(enc, passphrase);
assertArrayEquals(plain, plain2); assertArrayEquals(plain, plain2);