Search in sources :

Example 1 with CertifiedPublicKey

use of co.krypt.krypton.pgp.publickey.CertifiedPublicKey in project krypton-android by kryptco.

the class PGPPublicKeyTest method publicKey3_parses.

@Test
public void publicKey3_parses() throws Exception {
    CertifiedPublicKey pk = CertifiedPublicKey.parse(new DataInputStream(new ByteArrayInputStream(AsciiArmor.parse(testPubKey3).data)));
    Assert.assertTrue(pk.publicKeyPacket.attributes.algorithm == PublicKeyAlgorithm.ED25519);
    Assert.assertTrue(pk.identities.size() == 1);
    Assert.assertTrue(pk.identities.get(0).second.size() == 1);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertifiedPublicKey(co.krypt.krypton.pgp.publickey.CertifiedPublicKey) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 2 with CertifiedPublicKey

use of co.krypt.krypton.pgp.publickey.CertifiedPublicKey in project krypton-android by kryptco.

the class PGPSignatureTest method signedPublicKeyHashPrefixAndReserializedBytes_match.

@Test
public void signedPublicKeyHashPrefixAndReserializedBytes_match() throws Exception {
    byte[] signedKeyData = AsciiArmor.parse(testPubKey2).data;
    CertifiedPublicKey pk = CertifiedPublicKey.parse(new DataInputStream(new ByteArrayInputStream(signedKeyData)));
    SignatureAttributesWithoutHashPrefix att = pk.identities.get(0).second.get(0).attributes.attributes;
    UnsignedPublicKeySelfCertification certification = new UnsignedPublicKeySelfCertification(pk.publicKeyPacket, pk.identities.get(0).first.userID, att.getHashAlgorithm(), att.hashedSubpackets.created.created, // this pubkey has no flags
    null);
    Assert.assertTrue(SignableUtils.hashPrefix(att.hashAlgorithm, certification) == pk.identities.get(0).second.get(0).attributes.hashPrefix);
    ByteArrayOutputStream reserialized = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(reserialized);
    pk.publicKeyPacket.serialize(out);
    pk.identities.get(0).first.serialize(out);
    pk.identities.get(0).second.get(0).serialize(out);
    out.close();
    Assert.assertTrue(Arrays.equals(reserialized.toByteArray(), signedKeyData));
}
Also used : SignatureAttributesWithoutHashPrefix(co.krypt.krypton.pgp.packet.SignatureAttributesWithoutHashPrefix) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) CertifiedPublicKey(co.krypt.krypton.pgp.publickey.CertifiedPublicKey) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) UnsignedPublicKeySelfCertification(co.krypt.krypton.pgp.publickey.UnsignedPublicKeySelfCertification) Test(org.junit.Test)

Example 3 with CertifiedPublicKey

use of co.krypt.krypton.pgp.publickey.CertifiedPublicKey in project krypton-android by kryptco.

the class PGPPublicKeyTest method publicKey1_parses.

@Test
public void publicKey1_parses() throws Exception {
    CertifiedPublicKey pk = CertifiedPublicKey.parse(new DataInputStream(new ByteArrayInputStream(AsciiArmor.parse(testPubKey1).data)));
    Assert.assertTrue(pk.publicKeyPacket.attributes.algorithm == PublicKeyAlgorithm.RSA_ENCRYPT_OR_SIGN);
    Assert.assertTrue(pk.identities.size() == 1);
    Assert.assertTrue(pk.identities.get(0).second.size() == 2);
    Assert.assertTrue(Arrays.equals(pk.publicKeyPacket.fingerprint(), Base16.decode("F7A83D5CE65C42817A4AB7647A1037F5EF07891E")));
    long keyID = pk.publicKeyPacket.keyID();
    ByteArrayOutputStream keyIDBuf = new ByteArrayOutputStream();
    DataOutputStream keyIDOut = new DataOutputStream(keyIDBuf);
    keyIDOut.writeLong(keyID);
    keyIDOut.close();
    Assert.assertTrue(Arrays.equals(keyIDBuf.toByteArray(), Base16.decode("7A1037F5EF07891E")));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) CertifiedPublicKey(co.krypt.krypton.pgp.publickey.CertifiedPublicKey) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 4 with CertifiedPublicKey

use of co.krypt.krypton.pgp.publickey.CertifiedPublicKey in project krypton-android by kryptco.

the class PGPPublicKeyTest method publicKey2_parses.

@Test
public void publicKey2_parses() throws Exception {
    CertifiedPublicKey pk = CertifiedPublicKey.parse(new DataInputStream(new ByteArrayInputStream(AsciiArmor.parse(testPubKey2).data)));
    Assert.assertTrue(pk.publicKeyPacket.attributes.algorithm == PublicKeyAlgorithm.RSA_SIGN_ONLY);
    Assert.assertTrue(pk.identities.size() == 1);
    Assert.assertTrue(pk.identities.get(0).second.size() == 1);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertifiedPublicKey(co.krypt.krypton.pgp.publickey.CertifiedPublicKey) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 5 with CertifiedPublicKey

use of co.krypt.krypton.pgp.publickey.CertifiedPublicKey in project krypton-android by kryptco.

the class PGPPublicKeyTest method publicKey4_pkUserIDAndIncompleteSignature_parsesPartialIdentity.

@Test
public void publicKey4_pkUserIDAndIncompleteSignature_parsesPartialIdentity() throws Exception {
    CertifiedPublicKey pk = CertifiedPublicKey.parse(new DataInputStream(new ByteArrayInputStream(AsciiArmor.parse(testPubKey4).data)));
    Assert.assertTrue(pk.publicKeyPacket.attributes.algorithm == PublicKeyAlgorithm.ED25519);
    Assert.assertTrue(pk.identities.size() == 1);
    Assert.assertTrue(pk.identities.get(0).second.size() == 0);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) CertifiedPublicKey(co.krypt.krypton.pgp.publickey.CertifiedPublicKey) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

CertifiedPublicKey (co.krypt.krypton.pgp.publickey.CertifiedPublicKey)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)6 Test (org.junit.Test)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 KeyType (co.krypt.krypton.crypto.KeyType)1 SSHKeyPairI (co.krypt.krypton.crypto.SSHKeyPairI)1 PGPPublicKey (co.krypt.krypton.pgp.PGPPublicKey)1 UserID (co.krypt.krypton.pgp.UserID)1 SignatureAttributesWithoutHashPrefix (co.krypt.krypton.pgp.packet.SignatureAttributesWithoutHashPrefix)1 UnsignedPublicKeySelfCertification (co.krypt.krypton.pgp.publickey.UnsignedPublicKeySelfCertification)1