justinludwig / jpgpj

Java Pretty Good Privacy Jig
MIT License
75 stars 20 forks source link

Key doesn't have usage flags #37

Closed smirandamedallia closed 3 years ago

smirandamedallia commented 3 years ago

Hello Team - I tried loading the following public key using the below code but jpgpj thinks it is cannot be used for verification/encryption, the command line thinks otherwise

-----BEGIN PGP PUBLIC KEY BLOCK-----

mQGiBD8un+4RBACZg+XVXFhma5ifx7QU5gq0+oHZEzs4mKhA3AYktmPSgacvYlA6
HthbWgB/oHfcqL7+zVxooLxLj0wvs/3p6r24EJS7YSm7aRFBX0qA7ukUa72fESbP
IMDsfUPJ8I/ywRmrQqJqrE3sKgfCNq7FzYEA/aNVAMwo7oQg9RdfM3nNbwCg1Cq5
xMKIEL0feXRTpWS7YkUwsEkD/0hGqZkcVIen84TH2/FkbOdpLmhepu1r8wPVGn8H
o9GXhmSpPwDCQ15gB9UHUs1Saw4wdIAH9LlsmkyEya9mE3+ChEkHDhmsWOuf1LIr
t/6fYZzIvJfeLqvVWEXXqeOk3bvfkppGnbCtb8T5Ln1BryZd+wGfL567irGuvW8p
4gnzA/0QOH4nqI+zae+AWBldYuVEM3wZv4H6EU2YEhmrTPTYonwVlYYFhLAfZDfs
RLMV19KbzPzePLEPY4bxSbw8cKIOf3500/+VTD7rARmFnm5rje68xBs4B5Cijbdw
SQzKmsLYURr+QnuCOKIc7O88oFMFqpB9t2iDPfhvz7al5fabbbQhTWVkYWxsaWEg
WGZlciA8eGZlckBtZWRhbGxpYS5jb20+iFcEExECABcFAj8un+4FCwcKAwQDFQMC
AxYCAQIXgAAKCRDa/TuQnwnz79oiAKCRvMV4QeIz35ZuS2zja0pmwH+4lgCeIP26
R/V/TmVdAkMZFvk61xt1j+aIVwQTEQIAFwUCPy6f7wULBwoDBAMVAwIDFgIBAheA
AAoJENr9O5CfCfPvPdMAnRxPaSMtSuzSfT/X75cSPAPV/8d+AKCfv9z2lwARTBl0
D4ciQC71aYSpgrkBDQQ/Lp/zEAQAk8tKxjpIFSLVyM0eg1TemY6tJpmId2bf+Fb4
K2cA9rgj4KsTfx7DCCNn8USfmSThrsJtVis9DGLiWiOLOahfeg7qlfjfAOizEIbW
j3/XUwmZqI/y5WFeUppWo8r/HYhNzrr5AAzojwQqp0q2Qbo7NC8rWmk58gYT3IQX
PIiFezcAAwUD/R9928A/0r0UkmkRnBnbUW5hCc7A66e1Y70NB7mcQIBN/JXFYfoX
XMtc54tbnN7LCms30+lvOtvcEZyKmVKIHWkQP4Si9vjEH2RVnMxPSLCq4f9TciIx
Y+NX4ZonCQQuaS/JvbxQgfzAu6gs65lroEEdNisX1myuOXrS7UgoC4YdiEUEGBEC
AAYFAj8un/MACgkQ2v07kJ8J8+/XuACXcNiHWSSAzgg5edXbCMyb2yVBngCguq7n
I5DvXe1p8OGEvv89i/pnUqo=
=Oxhy
-----END PGP PUBLIC KEY BLOCK-----

Using the command line following is displayed

gpg --homedir . pub.key
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
pub   dsa1024 2003-08-04 [SCA]
      18674E841FAA870667950F40DAFD3B909F09F3EF
uid           XXXXXXXXXX <xxx@xxxxxxx.com>
sub   elg1024 2003-08-04 [E]

Using the below code to read the key

Key pubKey = new Key(new File("pub.key"));
        System.out.println(pubKey);
        pubKey.getSubkeys().forEach(sub -> {
            System.out.println(sub.getFingerprint());
            System.out.println("usable for: ");
            System.out.println("sign: " + sub.isUsableForSigning());
            System.out.println("verify: " + sub.isUsableForVerification());
            System.out.println("encryption: " + sub.isUsableForEncryption());
            System.out.println("decryption: " + sub.isUsableForDecryption());
        });
pub    9F09F3EF XXXXXXXXXX <xxx@xxxxxxx.com>
pub    5100C799
18674E841FAA870667950F40DAFD3B909F09F3EF
usable for: 
sign: false
verify: true
encryption: false
decryption: false
CCD406BFCF464CCC57EA030B0A074AC65100C799
usable for: 
sign: false
verify: false
encryption: true
decryption: false

Let me know how this should be handled since it is resulting in the Decryptor failing since it cannot find the appropriate verification key in the Ring

justinludwig commented 3 years ago

@mariuszmagdziarz pointed out in issue #22 that older PGP software didn't include usage flags when generating keys. Looks like that's the case for this key. Try loading it with the org.c02e.jpgpj.key.KeyForVerification class instead of the base Key class.

smirandamedallia commented 3 years ago

Thanks