Cannot list all the packets tags within a PGP signature.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Cannot list all the packets tags within a PGP signature.

Denis BEURIVE
Hello,

I am stuck on a problem that seems pretty strange. I probably misused the Bouncy Castle API, but I cannot find what's wrong. I just try to list all the packets' tags within a PGP document (which is a PGP signature).


Here is the procedure:
  1. I sign a document using the Bouncy Castle API. I generate a file that contains the PGP signature.
  2. I use GPG to verify the signature. According to GPG, the signature is valid.
  3. I use GPG to print the structure of the signature. It contains 3 packets which tags are: 4, 11 and 2.
  4. Then I use the Bouncy Castle API to list the tags of the packets that composed the signature. I get: 4 and 11. However, the next tag found is 20 (???), and I get an exception telling me "java.io.IOException: invalid header encountered".

The detailed, well formatted, procedure that involves GPG is described here: https://github.com/denis-beurive/bouncy-castle-examples/tree/master/app-pgp-dump

The method used to list all the tags within a document is:
static private void listPacketTags(String inDocumentPath) throws IOException, PGPException {
ArmoredInputStream armoredinputStream = getArmoredInputStream(inDocumentPath);
PGPCompressedData data = new PGPCompressedData(armoredinputStream);
BCPGInputStream basicIn = new BCPGInputStream(data.getDataStream());

System.out.println(String.format("Tags for the PGP document \"%s\":", inDocumentPath));
int tag, index=1;
while (((tag = basicIn.nextPacketTag()) != -1)) {
System.out.println(String.format(" - [%d] tag = %d", index++, tag));
if (basicIn.readPacket() == null) break;
}
}

I can't figure out what goes wrong.

  • The signature is obviously well structured. Otherwise GPG could not verify it or dump its content.
  • The method I implemented to list the document packets seems OK. Indeed, the first 2 tags are correct. It could hardly be a coincidence.

Do you have any idea ?


Thanks,


Denis