[Continuation] Cannot list all the packets tags within a PGP signature.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Continuation] Cannot list all the packets tags within a PGP signature.

Denis BEURIVE
Hello,

I've tried to find out what's wrong with my code. But the more I dig, the more it looks weird.

I made a compressed or an uncompressed signature: it does not change the result. Thus the problem does not come from the compression.

I decoded the packet by hand. You can find the description of the whole procedure here : https://github.com/denis-beurive/bouncy-castle-examples/blob/master/doc/pgp-packet.md

It seems that BC overestimates the length of a Literal Data Packet (tag=11).

The length of the second packet payload is 39 bytes (no doubt about that). However, BC seems to consider that it is 39+41 = 80 bytes.

Note : Please note that I find 41 bytes, because the only way to find a packet with a tag value of 20 is to find a packet that starts with "0xD4": "0b11010100" (new packet format, with the 6 least significant bits 010100).


I also tried this code with PGP documents that don't contain Literal Data Packet (like a key ring), and it behaves perfectly :
int tag, index=1;
while (((tag = pgpObjectsStreamReader.nextPacketTag()) != -1)) {
System.out.println(String.format(" - [%d] tag = %d", index++, tag));
Packet p = pgpObjectsStreamReader.readPacket();
if (null == p) break;
}
However, with the signature, it bugs.

Do these details ring any bells ?

Regards,

Denis
Reply | Threaded
Open this post in threaded view
|

Re: [Continuation] Cannot list all the packets tags within a PGP signature.

David Hook-3

It's important to remember that the OpenPGP API is a streaming one. Where a packet does not read fully contained you need to read the packet contents as well - the parser will tell you what's coming, but it wont always read the data.

Regards,

David

On 1/5/20 3:56 am, Denis BEURIVE wrote:
Hello,

I've tried to find out what's wrong with my code. But the more I dig, the more it looks weird.

I made a compressed or an uncompressed signature: it does not change the result. Thus the problem does not come from the compression.

I decoded the packet by hand. You can find the description of the whole procedure here : https://github.com/denis-beurive/bouncy-castle-examples/blob/master/doc/pgp-packet.md

It seems that BC overestimates the length of a Literal Data Packet (tag=11).

The length of the second packet payload is 39 bytes (no doubt about that). However, BC seems to consider that it is 39+41 = 80 bytes.

Note : Please note that I find 41 bytes, because the only way to find a packet with a tag value of 20 is to find a packet that starts with "0xD4": "0b11010100" (new packet format, with the 6 least significant bits 010100).


I also tried this code with PGP documents that don't contain Literal Data Packet (like a key ring), and it behaves perfectly :
int tag, index=1;
while (((tag = pgpObjectsStreamReader.nextPacketTag()) != -1)) {
    System.out.println(String.format("  - [%d] tag = %d", index++, tag));
    Packet p = pgpObjectsStreamReader.readPacket();
    if (null == p) break;
}
However, with the signature, it bugs.

Do these details ring any bells ?

Regards,

Denis


Reply | Threaded
Open this post in threaded view
|

Re: [Continuation] Cannot list all the packets tags within a PGP signature.

Denis BEURIVE

Hello,

For the record, the problem was that when the parser hits a "compressed data packet" (tag 8), then the parser input stream needs to be reassigned.

The compressed data packet body is made of e sequence of packets (https://tools.ietf.org/html/rfc4880#section-5.6)

I published an example here.

Regards.

 


Le sam. 2 mai 2020 à 08:59, David Hook <[hidden email]> a écrit :

It's important to remember that the OpenPGP API is a streaming one. Where a packet does not read fully contained you need to read the packet contents as well - the parser will tell you what's coming, but it wont always read the data.

Regards,

David

On 1/5/20 3:56 am, Denis BEURIVE wrote:
Hello,

I've tried to find out what's wrong with my code. But the more I dig, the more it looks weird.

I made a compressed or an uncompressed signature: it does not change the result. Thus the problem does not come from the compression.

I decoded the packet by hand. You can find the description of the whole procedure here : https://github.com/denis-beurive/bouncy-castle-examples/blob/master/doc/pgp-packet.md

It seems that BC overestimates the length of a Literal Data Packet (tag=11).

The length of the second packet payload is 39 bytes (no doubt about that). However, BC seems to consider that it is 39+41 = 80 bytes.

Note : Please note that I find 41 bytes, because the only way to find a packet with a tag value of 20 is to find a packet that starts with "0xD4": "0b11010100" (new packet format, with the 6 least significant bits 010100).


I also tried this code with PGP documents that don't contain Literal Data Packet (like a key ring), and it behaves perfectly :
int tag, index=1;
while (((tag = pgpObjectsStreamReader.nextPacketTag()) != -1)) {
    System.out.println(String.format("  - [%d] tag = %d", index++, tag));
    Packet p = pgpObjectsStreamReader.readPacket();
    if (null == p) break;
}
However, with the signature, it bugs.

Do these details ring any bells ?

Regards,

Denis