mattosaurus / PgpCore

.NET Core class library for using PGP
MIT License
244 stars 98 forks source link

Unable to call GetUserIds on class EncyptionKeys for public key #181

Closed nikbra closed 2 years ago

nikbra commented 2 years ago

Example :

PgpPublicKey GetUserIds();

Result in 0 user id's from version 5.6.0 and later.

Does work in version 5.5.0 but not in later versions.

mattosaurus commented 2 years ago

So the GetUserIds method comes from the Bouncy Castle repository and doesn't seem to have changed in 8 years.

https://github.com/bcgit/bc-csharp/blob/93b32a75656955faf7996d0f3e0ed391968d2ac6/crypto/src/openpgp/PgpPublicKey.cs#L527-L540

I'm getting user IDs returned from the method using the most recent version of PgpCore so can't replicate this myself.

The most obvious answer is that you're using a key that's been created without a user but if that's not the case are you able to share a public key that's lets me replicate this and I'll take a look. I probably don't need the private key or password but they might make things easier if you're able to generate me a full set.

nikbra commented 2 years ago

@mattosaurus , here is a link to a public pgp key from Swedish Handelsbanken. Should have a user : SHB/PGP-NYCKEL6

Here is a public link to the pgp key : handelsbanken_public_pgpkey_6_tcm72-152126.zip

mattosaurus commented 2 years ago

Ah, this is to do with the changes made to the EncryptionKeys object to help it pick the correct key for each scenario (encrypting/signing/etc).

As part of this we changed how the PublicKey property was set. Previously it was just the first key in the keyring, now it's the first encryptable key in the keyring. In your case the encryption key doesn't have any user IDs but the master key does which would have been picked first previously (but wasn't always valid for encryption).

You can get the desired user ID from MasterKey.GetUserIds(). To avoid confusion I'll probably flag the PublicKeys and PublicKey properties as obsolete and remove them in a future version.

nikbra commented 2 years ago

@mattosaurus , thanks for the help. It works for us now. You can close this