Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get ID / email after import? #150

Open
rathboma opened this issue Jan 14, 2022 · 2 comments
Open

How to get ID / email after import? #150

rathboma opened this issue Jan 14, 2022 · 2 comments

Comments

@rathboma
Copy link

Hey folks,

Firstly - THANK YOU for making this library. Amazing work and I don't know what I'd do without it.

I'm building a system in which users can upload their (private) gpg keys for signing files.
So they give me a mycompany.key private key.

Using this, I can successfully run GPGME::Key.import(File.open('mycompany.key')), but...how do I identify the key after that?

This gives me a ImportResult, but I can't find any sort of ID / Email field on that object I can use....

Any ideas? Sorry if this is a dumb question, I'm not super experienced with the GPG utils

@Carlgo11
Copy link

Carlgo11 commented Jun 3, 2023

I realize this is a very old ticket but I came across the same issue and thought someone else might too in the future.

What you're going to want to do is get the imports objects from the ImportResult and then get the fingerprint from that.

Example:

imports = GPGME::Key.import(key).imports
fingerprints = imports.map(&:fpr)

You'll end up with an array of strings representing the fingerprints (SHA2) of all imported keys.

With that information, you can then fetch the actual keys as Key objects using:

keys = fingerprints.map { |fpr| GPGME::Key.find(fpr) }

@kernelsmith
Copy link

@rathboma take a look at https://github.com/ueno/ruby-gpgme/blob/master/lib/gpgme/misc.rb#L65
you can call imports as @Carlgo11 suggested, but depending on what you want to do exactly, you might be able to use

    considered, imported, unchanged
    new_user_ids, new_sub_keys, new_signatures
    not_imported,  imports

In GPG speak, when you import keys, they are checked before being imported, so if you import 5 keys, 5 keys will be considered and if they're already imported and nothing has changed, they're considered "unchanged". If some of the 5 keys are new and import w/o any errors, they are considered "imported". In your case, you may want new_signatures and/or new_user_ids, but I didn't check that those methods do exactly what you need, so YMMV

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants