Search in sources :

Example 1 with UnsignedBinaryDocument

use of co.krypt.krypton.pgp.codesign.UnsignedBinaryDocument in project krypton-android by kryptco.

the class PGPCodesignTest method dataSigning_succeeds.

@Test
public void dataSigning_succeeds() throws Exception {
    final byte[] data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
    SSHKeyPairI kp1 = KeyManager.loadOrGenerateKeyPair(InstrumentationRegistry.getTargetContext(), KeyType.RSA, "test");
    PGPPublicKey pubkey = new PGPPublicKey(kp1, Collections.singletonList(new UserID("Kevin King", "kevin@krypt.co")));
    UnsignedBinaryDocument unsigned = new UnsignedBinaryDocument(data, kp1, HashAlgorithm.SHA512);
    SignedSignatureAttributes sig = unsigned.sign(kp1.pgpSign(HashAlgorithm.SHA512, SignableUtils.signableBytes(unsigned)));
    byte[] serializedSig = sig.serializedBytes();
    SignedSignatureAttributes parsedSig = SignedSignatureAttributes.parse(new DataInputStream(new ByteArrayInputStream(serializedSig)));
    Assert.assertTrue(parsedSig.attributes.attributes.hashAlgorithm == HashAlgorithm.SHA512);
    Assert.assertTrue(parsedSig.attributes.attributes.pkAlgorithm == PublicKeyAlgorithm.RSA_SIGN_ONLY);
    Assert.assertTrue(parsedSig.attributes.attributes.type == SignatureType.BINARY);
    Assert.assertFalse(parsedSig.attributes.attributes.unhashedSubpackets.issuer.header.type.critical);
}
Also used : UnsignedBinaryDocument(co.krypt.krypton.pgp.codesign.UnsignedBinaryDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) UserID(co.krypt.krypton.pgp.UserID) SignedSignatureAttributes(co.krypt.krypton.pgp.packet.SignedSignatureAttributes) SSHKeyPairI(co.krypt.krypton.crypto.SSHKeyPairI) PGPPublicKey(co.krypt.krypton.pgp.PGPPublicKey) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 2 with UnsignedBinaryDocument

use of co.krypt.krypton.pgp.codesign.UnsignedBinaryDocument in project krypton-android by kryptco.

the class PGPSignatureTest method signedBinaryDocumentHashPrefix_matches.

@Test
public void signedBinaryDocumentHashPrefix_matches() throws Exception {
    byte[] signatureBytes = AsciiArmor.parse(testSig1).data;
    SignedSignatureAttributes sig = SignedSignatureAttributes.parse(new DataInputStream(new ByteArrayInputStream(signatureBytes)));
    UnsignedBinaryDocument doc = new UnsignedBinaryDocument(signedData1.getBytes("UTF-8"), sig.attributes.attributes);
    Assert.assertTrue(SignableUtils.hashPrefix(sig.attributes.attributes.hashAlgorithm, doc) == sig.attributes.hashPrefix);
    ByteArrayOutputStream reserialized = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(reserialized);
    sig.serialize(out);
    out.close();
    Assert.assertTrue(Arrays.equals(reserialized.toByteArray(), signatureBytes));
}
Also used : UnsignedBinaryDocument(co.krypt.krypton.pgp.codesign.UnsignedBinaryDocument) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) SignedSignatureAttributes(co.krypt.krypton.pgp.packet.SignedSignatureAttributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

UnsignedBinaryDocument (co.krypt.krypton.pgp.codesign.UnsignedBinaryDocument)2 SignedSignatureAttributes (co.krypt.krypton.pgp.packet.SignedSignatureAttributes)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 Test (org.junit.Test)2 SSHKeyPairI (co.krypt.krypton.crypto.SSHKeyPairI)1 PGPPublicKey (co.krypt.krypton.pgp.PGPPublicKey)1 UserID (co.krypt.krypton.pgp.UserID)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1