View Issue Details

IDProjectCategoryView StatusLast Update
0000266fileGeneralpublic2021-06-08 18:13
Reporterj2j Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version5.40 
Summary0000266: False hits by Magdir/pgp-binary-keys
Descriptionwhen i run file command version 5.40 on some files with -k option i
often get also misidentification messages starting with "OpenPGP". See
appended output OpenPGP-bad-k.txt.

When looking inside sources i see that such messages are triggered by
magic lines inside Magdir/pgp-binary-keys. These magic lines should
identify OpenPGP files.

The above mentioned examples are handled by starting lines like
 0 ubyte&0xFC =0x94 OpenPGP Secret Key
 >&-1 use primary_key_length_old

After inspecting just one byte print a message starting with "OpenPGP
Secret Key" and then do some additional check by calling sub routine
like primary_key_length_old. Obviously checking only 1 byte is not
sufficient. So non PGP examples with starting byte 95h like
mathemusic, PEDE and samples starting with 97h like Event.Tdf,
RIRE6.SPL, Rx.GS and Welcome.Snd are misidentified.

The consistence check is done later by sub routine
pgp_binary_key_pk_check which checks for valid versions range (2-7)
and valid time stamps (after 1990).

The correct way would be to check some possible PGP packets for valid
version and time stamp. If this succeeds then afterwards display some
message text.

Furthermore the samples starting with 97h are also described inside
Magdir/pgp in a more unreliable way by line starting with
 0 byte 0x97 PGP Secret Sub-key -

So when check and describing part is done by Magdir/pgp-binary-keys
then remove the lines from Magdir/pgp.

Furthermore with --extension option the 31 byte string pgp/gpg/pkr/asd
is shown. For public "foo" extension pkr is used whereas for secret
"foo" the extension "skr" is used. So skr file is missing in the
following magic line: !:ext pgp/gpg/pkr/asd And when doing effort in
inspecting PGP packet for "OpenPGP Public Key" and "OpenPGP Secret
Key" then it would be a good thing to display afterwards the right
file name extension ( pkr or skr).

Furthermore the extension asd is listed as a possibility. As far as i
know i no PGP or related file exist with that extension.

My misidentified examples are stored in appended archive
OpenPGP-bad.zip.
TagsPGP

Activities

j2j

2021-05-20 22:01

reporter  

OpenPGP-bad-k.txt (578 bytes)   
OpenPGP-bad.zip (66,795 bytes)

neal

2021-05-29 21:27

reporter   ~0003608

(I wrote pgp-binary-keys.)

Thanks for the thorough report. I tested a lot of true positives (a large portion of the SKS dump), but it seems I failed to test enough false positives. The code checks a lot of bits, so it should be unambiguous. I suspect the problem is that I just emit "OpenPGP Secret Key" too early.

As for the file extensions, I'm only aware of .pgp and .gpg. The other variants existed in the old version of the code, so I kept them assuming that they used to be used.

I'll take a look in the next few days.

neal

2021-06-08 18:12

reporter   ~0003612

The issue identifies three problems:

  1. Descriptions in pgp-binary-key are printed too eagerly.

  2. Descriptions in pgp (PGP Secret Sub-key) are printed too eagerly.

  3. The extensions listed in pgp-binary-key are wrong.

I've fixed one as j2j suggested. Unfortunately, I can't figure out how to distinguish public and secret keys anymore, because the first byte of the file is not accessible from a function ("use").

The other patch fixes 3. I've changed it to only report pgp and gpg as valid extensions. I've never actually seen srk, prk or adf used in practice and I've been doing PGP stuff for nearly a decade.

neal

2021-06-08 18:13

reporter   ~0003613

(I'll take a look at pgp and prune the secret subkey detection and some other stuff that is not actually useful in practice.)

Issue History

Date Modified Username Field Change
2021-05-20 22:01 j2j New Issue
2021-05-20 22:01 j2j File Added: OpenPGP-bad-k.txt
2021-05-20 22:01 j2j File Added: OpenPGP-bad.zip
2021-05-20 22:01 j2j Tag Attached: PGP
2021-05-29 21:27 neal Note Added: 0003608
2021-06-08 18:12 neal File Added: 0001-Show-information-about-a-PGP-key-only-if-we-have-a-s.patch
2021-06-08 18:12 neal File Added: 0002-For-binary-PGP-keys-only-use-the-pgp-and-gpg-extensi.patch
2021-06-08 18:12 neal Note Added: 0003612
2021-06-08 18:13 neal Note Added: 0003613