Skip to content

Commit

Permalink
Extend tests for OnePassSignaturePacket
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Apr 22, 2024
1 parent 18c2eae commit 0d659b9
Showing 1 changed file with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,40 @@ public class OnePassSignaturePacketTest
extends SimpleTest
{

// Version 6 OnePassSignature packet
// extracted from https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-13.html#name-sample-inline-signed-messag
public static final byte[] OPS_V6 = Hex.decode("c44606010a1b2076495f50218890f7f5e2ee3c1822514f70500f551d86e5c921e404e34a53fbaccb186c4f0609a697e4d52dfa6c722b0c1f1e27c18a56708f6525ec27bad9acc901");
// Issuer of the message
public static byte[] ISSUER = Hex.decode("CB186C4F0609A697E4D52DFA6C722B0C1F1E27C18A56708F6525EC27BAD9ACC9");
// Salt used to generate the signature
public static byte[] SALT = Hex.decode("76495F50218890F7F5E2EE3C1822514F70500F551D86E5C921E404E34A53FBAC");

// Parse v6 OPS packet and compare its values to a known-good test vector
private void testParseV6OnePassSignaturePacket() throws IOException {
ByteArrayInputStream bIn = new ByteArrayInputStream(OPS_V6);
// Version 6 OnePassSignature packet
// extracted from https://www.ietf.org/archive/id/draft-ietf-openpgp-crypto-refresh-13.html#name-sample-inline-signed-messag
byte[] encOPS = Hex.decode("c44606010a1b2076495f50218890f7f5e2ee3c1822514f70500f551d86e5c921e404e34a53fbaccb186c4f0609a697e4d52dfa6c722b0c1f1e27c18a56708f6525ec27bad9acc901");
// Issuer of the message
byte[] issuerFp = Hex.decode("CB186C4F0609A697E4D52DFA6C722B0C1F1E27C18A56708F6525EC27BAD9ACC9");
// Salt used to generate the signature
byte[] salt = Hex.decode("76495F50218890F7F5E2EE3C1822514F70500F551D86E5C921E404E34A53FBAC");

ByteArrayInputStream bIn = new ByteArrayInputStream(encOPS);
BCPGInputStream pIn = new BCPGInputStream(bIn);

// Parse and compare the OnePassSignature packet
OnePassSignaturePacket ops = (OnePassSignaturePacket) pIn.readPacket();
isEquals("OPS packet MUST be of version 6",
OnePassSignaturePacket.VERSION_6, ops.getVersion());
isTrue("OPS packet issuer fingerprint mismatch",
Arrays.areEqual(ISSUER, ops.getFingerprint()));
Arrays.areEqual(issuerFp, ops.getFingerprint()));
isTrue("OPS packet key-ID mismatch",
// key-ID are the first 8 octets of the fingerprint
Hex.toHexString(issuerFp).startsWith(Long.toHexString(ops.getKeyID())));
isTrue("OPS packet salt mismatch",
Arrays.areEqual(SALT, ops.getSalt()));
Arrays.areEqual(salt, ops.getSalt()));
isTrue("OPS packet isContaining mismatch",
ops.isContaining());
}

private void testEncodeV6OPS() throws IOException {
ByteArrayInputStream bIn = new ByteArrayInputStream(OPS_V6);
BCPGInputStream pIn = new BCPGInputStream(bIn);
OnePassSignaturePacket ops = (OnePassSignaturePacket) pIn.readPacket();

ByteArrayOutputStream bOut = new ByteArrayOutputStream();
BCPGOutputStream pOut = new BCPGOutputStream(bOut, true);
ops.encode(pOut);
pOut.close();

isTrue("Encoding mismatch of OPS v6 packet",
Arrays.areEqual(OPS_V6, bOut.toByteArray()));
Arrays.areEqual(encOPS, bOut.toByteArray()));
}

@Override
Expand All @@ -60,7 +57,6 @@ public String getName() {
@Override
public void performTest() throws Exception {
testParseV6OnePassSignaturePacket();
testEncodeV6OPS();
}

public static void main(String[] args) {
Expand Down

0 comments on commit 0d659b9

Please sign in to comment.