Pino Toscano
2015-May-11 17:30 UTC
[Libguestfs] [PATCH 1/3] builder: move gpg status parsing within import_keyfile
Parse the gpg status output directly within import_keyfile, returning just the key fingerprint. Just code motion, no actual behaviour changes. --- builder/sigchecker.ml | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/builder/sigchecker.ml b/builder/sigchecker.ml index 0c292fb..a1a4220 100644 --- a/builder/sigchecker.ml +++ b/builder/sigchecker.ml @@ -43,7 +43,17 @@ let import_keyfile ~gpg ~gpghome ~verbose keyfile let r = Sys.command cmd in if r <> 0 then error (f_"could not import public key\nUse the '-v' option and look for earlier error messages."); - status_file + let status = read_whole_file status_file in + let status = string_nsplit "\n" status in + let fingerprint = ref "" in + List.iter ( + fun line -> + let line = string_nsplit " " line in + match line with + | "[GNUPG:]" :: "IMPORT_OK" :: _ :: fp :: _ -> fingerprint := fp + | _ -> () + ) status; + !fingerprint let rec create ~verbose ~gpg ~gpgkey ~check_signature (* Create a temporary directory for gnupg. *) @@ -69,18 +79,7 @@ let rec create ~verbose ~gpg ~gpgkey ~check_signature | No_Key -> assert false | KeyFile kf -> - let status_file = import_keyfile gpg tmpdir verbose kf in - let status = read_whole_file status_file in - let status = string_nsplit "\n" status in - let fingerprint = ref "" in - List.iter ( - fun line -> - let line = string_nsplit " " line in - match line with - | "[GNUPG:]" :: "IMPORT_OK" :: _ :: fp :: _ -> fingerprint := fp - | _ -> () - ) status; - !fingerprint + import_keyfile gpg tmpdir verbose kf | Fingerprint fp -> let filename = Filename.temp_file "vbpubkey" ".asc" in unlink_on_exit filename; -- 2.1.0
Pino Toscano
2015-May-11 17:30 UTC
[Libguestfs] [PATCH 2/3] builder: trust the imported keys
In every SigChecker, trust by default the keys imported. This should make gpg happier when using the keys later, used only when validating the signatures of index files. --- builder/sigchecker.ml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/builder/sigchecker.ml b/builder/sigchecker.ml index a1a4220..b54977f 100644 --- a/builder/sigchecker.ml +++ b/builder/sigchecker.ml @@ -33,7 +33,7 @@ type t = { } (* Import the specified key file. *) -let import_keyfile ~gpg ~gpghome ~verbose keyfile +let import_keyfile ~gpg ~gpghome ~verbose ?(trust = true) keyfile let status_file = Filename.temp_file "vbstat" ".txt" in unlink_on_exit status_file; let cmd = sprintf "%s --homedir %s --status-file %s --import %s%s" @@ -45,14 +45,25 @@ let import_keyfile ~gpg ~gpghome ~verbose keyfile error (f_"could not import public key\nUse the '-v' option and look for earlier error messages."); let status = read_whole_file status_file in let status = string_nsplit "\n" status in + let key_id = ref "" in let fingerprint = ref "" in List.iter ( fun line -> let line = string_nsplit " " line in match line with | "[GNUPG:]" :: "IMPORT_OK" :: _ :: fp :: _ -> fingerprint := fp + | "[GNUPG:]" :: "IMPORTED" :: key :: _ -> key_id := key | _ -> () ) status; + if trust then ( + let cmd = sprintf "%s --homedir %s --trusted-key %s --list-keys%s" + gpg gpghome (quote !key_id) + (if verbose then "" else " >/dev/null 2>&1") in + if verbose then printf "%s\n%!" cmd; + let r = Sys.command cmd in + if r <> 0 then + error (f_"GPG failure: could not trust the imported key\nUse the '-v' option and look for earlier error messages."); + ); !fingerprint let rec create ~verbose ~gpg ~gpgkey ~check_signature -- 2.1.0
Pino Toscano
2015-May-11 17:30 UTC
[Libguestfs] [PATCH 3/3] builder: enable batch mode when validating non-verbose (RHBZ#1180170)
When running gpg to validate a signature, use also --batch in non-verbose mode to avoid the extra "Good signature" messages that are printed by gpg2 even in quiet mode. We are parsing the status output anyway to check the validation result, so this should be harmless (and the full gpg output is printed in verbose mode anyway). --- builder/sigchecker.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/sigchecker.ml b/builder/sigchecker.ml index b54977f..29f271b 100644 --- a/builder/sigchecker.ml +++ b/builder/sigchecker.ml @@ -159,7 +159,7 @@ and do_verify t args let cmd sprintf "%s --homedir %s --verify%s --status-file %s %s" t.gpg t.gpghome - (if t.verbose then "" else " -q --logger-file /dev/null") + (if t.verbose then "" else " --batch -q --logger-file /dev/null") (quote status_file) args in if t.verbose then printf "%s\n%!" cmd; let r = Sys.command cmd in -- 2.1.0
Richard W.M. Jones
2015-May-11 19:47 UTC
Re: [Libguestfs] [PATCH 3/3] builder: enable batch mode when validating non-verbose (RHBZ#1180170)
On Mon, May 11, 2015 at 07:30:34PM +0200, Pino Toscano wrote:> When running gpg to validate a signature, use also --batch in > non-verbose mode to avoid the extra "Good signature" messages that are > printed by gpg2 even in quiet mode. > We are parsing the status output anyway to check the validation result, > so this should be harmless (and the full gpg output is printed in > verbose mode anyway). > --- > builder/sigchecker.ml | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/builder/sigchecker.ml b/builder/sigchecker.ml > index b54977f..29f271b 100644 > --- a/builder/sigchecker.ml > +++ b/builder/sigchecker.ml > @@ -159,7 +159,7 @@ and do_verify t args > let cmd > sprintf "%s --homedir %s --verify%s --status-file %s %s" > t.gpg t.gpghome > - (if t.verbose then "" else " -q --logger-file /dev/null") > + (if t.verbose then "" else " --batch -q --logger-file /dev/null") > (quote status_file) args in > if t.verbose then printf "%s\n%!" cmd; > let r = Sys.command cmd in > -- > 2.1.0ACK series. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Maybe Matching Threads
- [PATCH v2 1/2] mllib: curl: add optional tmpdir parameter
- [PATCH 1/2] mllib: curl: add optional tmpdir parameter
- Re: [PATCH] Use Mkdtemp.temp_dir instead of Mkdtemp.mkdtemp
- [PATCH 2/2] builder: consolidate handling of temporary files/dirs
- [PATCH v2 2/2] builder: consolidate handling of temporary files/dirs