openSUSE / zypper

World's most powerful command line package manager
http://en.opensuse.org/Portal:Zypper
Other
405 stars 110 forks source link

Fix keylist pr 163 #511

Open arozyev opened 12 months ago

arozyev commented 12 months ago

This change fixes merging conflicts and add few style/code issues from PR#163

arozyev commented 12 months ago

Some more thoughts, suggestions and comments from @mlandres:

Revival of the keys command. That's a good idea. A few thoughts...

mlandres commented 11 months ago

Regarding the command description

*keys* (*lk*) ['options'] ['part-of-keyid-or-name'] ['key-filename'] ...::
  List all trusted keys or show detailed information about those specified as arguments,
  supports also keyfiles as argument.

*addkey* (*ak*) ['options'] 'url'...::
  Imports a new key into the trusted database, the file can be specified as a URL.

*removekey* (*rk*) ['options'] 'string' ::
  Remove specified key from the trusted database. The query string can be the beginning
  or end of the key ID, or any part of the key name.

I'd suggest to be more straight in how we build and describe the CLI. It should be well defined what role an argument should play on the commandline.

A keyID (longID/FPR) is expected to uniquely denote A GPGKEY (class zypp::PublicKey).

In zypp you'd call it a string id_r for which PublicKey::providesKey(id_r) && PublicKey::isSafeKeyId(id_r) returns true. Less technically it's the at least 16 byte long trailing portion of the fingerprint of the GPGKEY's primary key or one of it's subkeys. providesKey alone would also accept the exact 8 byte trailing portion (shortID) of the primary key's FPR for legacy reasons. That's at least how the code treats keyIDs.

The 'rule' to reject files with more than one key is just because people may not be aware that a file gpg-pubkey-7fac5991-4615767f.key may in fact contain an arbitrary number of keys. We had examples where this is the case. even in out own distros. OTOH tools like SUMA may use this to ship additional keys in case the repo has packages signed by keys others than the metadata signing key. We could add a specific option for this (key-from vs keys-file).

Common to all key commands might be: They refer to a pool of GPGKEYs, optionally use just a subset of it and perform some action with them. Just a draft:

command [options] [keyPool...] [keyFilter...]

list
  keyPool:
    --key-from  FILE    requiring FILE to contain just a singe key 
                        ( maybe list but warn and return !=0 )
    --keys-file FILE    all keys in FILE
    --trusted-keys  all trusted keys (in rpmdb)
    --available-keys    all keys in /var/cache/zypp/pubkeys, ...
    [default: --trusted-keys]
  keyFilter:
    keyID       key with ID
    --match NAME        keys matching NAME
    --all-matches   all keys in keyPool
    [default: --all-matches]

add
  keyPool:
    --key-from  FILE    requiring FILE to contain just a singe key
                        ( abort if not )
    --keys-file FILE    all keys in FILE
    --available-keys    all keys in /var/cache/zypp/pubkeys, ...
    [default: --available-keys]
  keyFilter:
    keyID       key with ID
    --match NAME        keys matching NAME
    --all-matches       all keys in keyPool
    [default: This is tricky...]
    I'd default to --all-matches unless --available-keys is active (explicit or default).
    In this case a filter must be specified.

remove
  keyPool:
    [fidxed: --trusted-keys]
  keyFilter:
    keyID       key with ID
    --match NAME        keys matching NAME
    --all-matches   all keys in keyPool
    [default: none]

For remove we could later think about whether to allow keyPool specs (key-from, keys-file) to remove the keys the files provide. Also a [not]-used-by-repos filter could be useful. Maybe a --repo ALIAS keyPool too. We just need to think about how we handle and communicate the case of missing or not up-to-data repo metadata.