use of co.krypt.krypton.pgp.packet.SignedSignatureAttributes in project krypton-android by kryptco.
the class CertifiedPublicKey method parse.
public static CertifiedPublicKey parse(DataInputStream in) throws InvalidPacketTagException, UnsupportedOldPacketLengthTypeException, UnsupportedNewFormatException, UnsupportedPublicKeyAlgorithmException, UnsupportedPublicKeyVersionException, InvalidEd25519PublicKeyFormatException, IOException, InvalidUTF8Exception, DuplicateSubpacketException, NoSuchAlgorithmException, UnsupportedHashAlgorithmException, InvalidSubpacketLengthException, UnsupportedCriticalSubpacketTypeException, UnsupportedSignatureVersionException {
PublicKeyPacket publicKeyPacket = null;
boolean lastPacketUserIDOrSignature = false;
List<Pair<UserIDPacket, List<SignedSignatureAttributes>>> identities = new LinkedList<>();
while (true) {
try {
PacketHeader header = PacketHeader.parse(in);
Log.d("PGP", "found packet with type " + header.tag.packetType.toString());
switch(header.tag.packetType) {
case SIGNATURE:
SignedSignatureAttributes signaturePacket = SignedSignatureAttributes.parse(header, in);
if (lastPacketUserIDOrSignature && identities.size() > 0) {
identities.get(identities.size() - 1).second.add(signaturePacket);
}
break;
case PUBLIC_KEY:
if (publicKeyPacket != null) {
// only accept first public key packet
in.skip(header.length.bodyLength);
continue;
}
publicKeyPacket = PublicKeyPacket.parse(header, in);
break;
case USER_ID:
identities.add(new Pair<UserIDPacket, List<SignedSignatureAttributes>>(UserIDPacket.parse(header, in), new LinkedList<SignedSignatureAttributes>()));
break;
default:
in.skip(header.length.bodyLength);
break;
}
lastPacketUserIDOrSignature = header.tag.packetType == PacketType.USER_ID || header.tag.packetType == PacketType.SIGNATURE;
} catch (EOFException e) {
break;
}
}
return new CertifiedPublicKey(publicKeyPacket, identities);
}
use of co.krypt.krypton.pgp.packet.SignedSignatureAttributes 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);
}
use of co.krypt.krypton.pgp.packet.SignedSignatureAttributes 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));
}
Aggregations