Author: lslezak Date: Thu Jan 10 15:51:56 2008 New Revision: 43535 URL: http://svn.opensuse.org/viewcvs/yast?rev=43535&view=rev Log: - implemented GPG key importing (incl. key file validation) Modified: trunk/packager/src/clients/repositories.ycp trunk/packager/src/include/key_manager_dialogs.ycp trunk/packager/src/modules/KeyManager.ycp Modified: trunk/packager/src/clients/repositories.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/packager/src/clients/repositories... ============================================================================== --- trunk/packager/src/clients/repositories.ycp (original) +++ trunk/packager/src/clients/repositories.ycp Thu Jan 10 15:51:56 2008 @@ -1065,7 +1065,7 @@ ], "keymgr" : $[ `next : "summary", - `abort : `abort + `abort : "summary" ], "type" : $[ `next : "edit", Modified: trunk/packager/src/include/key_manager_dialogs.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/packager/src/include/key_manager_... ============================================================================== --- trunk/packager/src/include/key_manager_dialogs.ycp (original) +++ trunk/packager/src/include/key_manager_dialogs.ycp Thu Jan 10 15:51:56 2008 @@ -84,7 +84,7 @@ `Left(`Label(sformat(_("Key ID: %1"), key["id"]:""))), `Left(`Label(sformat(_("Name: %1"), key["name"]:""))), `VSpacing(0.3), - `Left(`CheckBox(`id(`trusted), _("&Trusted"), key["trusted"]:false)), + `Left(`CheckBox(`id(`trusted), _("&The Key is Trusted"), key["trusted"]:false)), `VSpacing(0.2) ) ), @@ -118,16 +118,18 @@ return ret; } +// remember the details about the added key from AddGPGKey(), +// the details are displayed in NewKeySummary() +map<string,any> added_key = $[]; + symbol AddGPGKey() { - string filename = ""; - term contents = `VBox( `Frame(`id(`fr), _("Select a GPG Key"), `MarginBox(1, 0.3, `VBox( `HBox( - `TextEntry(`id(`file), Label::FileName(), filename), + `TextEntry(`id(`file), Label::FileName()), `VBox( `Label(""), `PushButton(`id(`browse), Label::BrowseButton()) @@ -150,17 +152,10 @@ help_text = help_text + _("<p> <b>Adding a New GPG Key</b><br> -To add a new GPG key, use <b>Add</b> and specify the path to the key file. +To add a new GPG key specify the path to the key file. +Check the <B>Trusted</B> check box if the key is trusted. </p>"); - // help, continued - help_text = help_text + _("<p> -<b>Modifying a GPG Key Status</b> -To modify the trusted flag, use <b>Edit</b>. To remove a GPG key, use -<b>Delete</b>. -</p> -"); - Wizard::SetNextButton(`next, Label::OKButton()); Wizard::SetContents(title, contents, help_text, true, true); @@ -183,12 +178,25 @@ } else if (ret == `next) { - // TODO: validate the entered file + // validate the entered file + string keyfile = (string) UI::QueryWidget(`id(`file), `Value); + y2internal("Entered: %1", keyfile); - boolean trusted = (boolean) UI::QueryWidget(`id(`trusted), `Value); + if (keyfile == nil || keyfile == "") + { + Report::Error(_("Enter a filename")); + UI::SetFocus(`id(`file)); + ret = `_dummy; + continue; + } - // TODO: add the key + boolean trusted = (boolean) UI::QueryWidget(`id(`trusted), `Value); + added_key = KeyManager::ImportFromFile(keyfile, trusted); + if (added_key == nil || size(added_key) == 0) + { + ret = `_dummy; + } } } @@ -199,6 +207,13 @@ return ret; } +// display details about the imported GPG key +symbol NewKeySummary() +{ + // TODO FIXME + return `next; +} + symbol KeySummary() { @@ -296,7 +311,8 @@ map<string,any> aliases = $[ "summary" : ``(KeySummary()), - "add" : [``(AddGPGKey()), true ] + "add" : [``(AddGPGKey()), true ], + "new_key_summary" : [``(NewKeySummary()), true ] ]; map sequence = $[ @@ -307,6 +323,10 @@ `add : "add" ], "add" : $[ + `next : "new_key_summary", + `abort : `abort + ], + "new_key_summary" : $[ `next : "summary", `abort : `abort ] Modified: trunk/packager/src/modules/KeyManager.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/packager/src/modules/KeyManager.y... ============================================================================== --- trunk/packager/src/modules/KeyManager.ycp (original) +++ trunk/packager/src/modules/KeyManager.ycp Thu Jan 10 15:51:56 2008 @@ -13,6 +13,10 @@ textdomain "packager"; module "KeyManager"; +import "Report"; +import "Directory"; +import "String"; + // the current state list<map<string,any> > known_keys = []; @@ -20,7 +24,7 @@ list<map<string,any> > deleted_keys = []; // keys to import from a file -list<map<string,any> > import_from_file = []; +list<string> import_from_file = []; boolean modified = false; @@ -111,8 +115,10 @@ // TODO import new keys - // update the current status + // all changes are saved, reset them Reset(); + + // update the current status Read(); return ret; @@ -206,18 +212,69 @@ /** * Import key from a file * @param file path to the file + * @param trusted true if the key is trusted + * @return map map with the key, nil when import fails (invalid key, not existing file, already imported key...) */ -global boolean ImportFromFile(string file) +global map<string,any> ImportFromFile(string file, boolean trusted) { - // TODO check whether the file is valid, copy the file to the tmpdir - string tmpfile = ""; + // check whether the file is valid, copy the file to the tmpdir + map<string,any> key = Pkg::CheckGPGKeyFile(file); + y2internal("File content: %1", key); - // store the import request for later use in Write() - import_from_file = add(import_from_file, $[ "file" : tmpfile ]); + if (key != nil && size(key) > 0) + { + // update the trusted flag + key["trusted"] = trusted; + } + else + { + Report::Error(sformat(_("File '%1' +doesn't contain a valid GPG key."), file)); + return nil; + } - // TODO add to the current config + boolean known = false; - return true; + // check whether the key is already known + foreach(map<string,any> k, known_keys, + { + if (k["id"]:"" == key["id"]:"") + { + known = true; + } + } + ); + + if (known) + { + // %1 is key ID (e.g. A84EDAE89C800ACA), %2 is key name (e.g. "SuSE Package Signing Key <build@suse.de>") + Report::Error(sformat(_("Key '%1' +'%2' +is already known, cannot be added again."), key["id"]:"", key["name"]:"")); + return nil; + } + + // copy the key to the temporary directory (in fact the keys are imported in Write()) + string tmpfile = sformat("%1/tmp_gpg_key.%2", Directory::tmpdir, size(known_keys)); + string command = sformat("/bin/cp -- '%1' '%2'", String::Quote(file), String::Quote(tmpfile)); + + y2internal("Copying the key: %1", command); + + integer out = (integer)SCR::Execute(.target.bash, command); + + if (out != 0) + { + Report::Error(_("Cannot copy the key to the temporary directory.")); + return nil; + } + + // store the import request + import_from_file = add(import_from_file, tmpfile); + + // add the new key to the current config + known_keys = add(known_keys, key); + + return key; } /* EOF */ -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org