[yast-commit] r66150 - in /trunk/ca-management/src: YaPI/CaManagement.pm request.ycp
Author: mcalmer Date: Thu Sep 29 12:25:50 2011 New Revision: 66150 URL: http://svn.opensuse.org/viewcvs/yast?rev=66150&view=rev Log: implement export request (bnc#717224) Modified: trunk/ca-management/src/YaPI/CaManagement.pm trunk/ca-management/src/request.ycp Modified: trunk/ca-management/src/YaPI/CaManagement.pm URL: http://svn.opensuse.org/viewcvs/yast/trunk/ca-management/src/YaPI/CaManagement.pm?rev=66150&r1=66149&r2=66150&view=diff ============================================================================== --- trunk/ca-management/src/YaPI/CaManagement.pm (original) +++ trunk/ca-management/src/YaPI/CaManagement.pm Thu Sep 29 12:25:50 2011 @@ -123,6 +123,10 @@ Export a CRL to a file or returns it in different formats +$bool = ExportRequest($valueMap) + + Export a Request to a file + $bool = Verify($valueMap) verify a certificate @@ -417,6 +421,7 @@ use URI::Escape; use X500::DN; use MIME::Base64; +use File::Copy; #use Digest::MD5 qw(md5_hex); #use Date::Calc qw( Date_to_Time Add_Delta_DHMS Today_and_Now); @@ -3514,6 +3519,109 @@ } =item * +C<$bool = ExportRequest($valueMap)> + +Export a request to a file + +In I<$valueMap> you can define the following keys: + +* caName (required) + +* caPassword (required) + +* request (required) + +* destinationFile (required) + +The function return true on success. + +=cut +BEGIN { $TYPEINFO{ExportRequest} = ["function", "any", ["map", "string", "any"]]; } +sub ExportRequest { + my $self = shift; + my $data = shift; + my $caName = ""; + my $request = ""; + my $destinationFile = undef; + + # checking requires + if (!defined $data->{'caName'}) { + # parameter check failed + return $self->SetError(summary => __("Invalid value for parameter 'caName'."), + code => "PARAM_CHECK_FAILED"); + } + $caName = $data->{"caName"}; + + if (!defined $data->{'caPasswd'}) { + # parameter check failed + return $self->SetError(summary => __("Invalid value for parameter 'caPasswd'."), + code => "PARAM_CHECK_FAILED"); + } + + if (! defined $data->{'request'}) { + # parameter check failed + return $self->SetError(summary => __("Invalid value for parameter 'request'."), + code => "PARAM_CHECK_FAILED"); + } + $request = $data->{"request"}; + + if (! defined $data->{'destinationFile'}) { + return $self->SetError(summary => sprintf(__("Cannot parse destinationFile %s."), + $data->{'destinationFile'}), + description => "Please enter an absolute path and no special characters as filename.", + code => "PARAM_CHECK_FAILED"); + } + $data->{'destinationFile'} =~ /^(\/.+\/)[A-Za-z0-9-_.]+$/; + if (not defined $1) { + # parameter check failed + return $self->SetError(summary => sprintf(__("Cannot parse destinationFile %s."), + $data->{'destinationFile'}), + description => "Please enter an absolute path and no special characters as filename.", + code => "PARAM_CHECK_FAILED"); + } + my $ret = SCR->Read(".target.dir", ["$1", undef] ); + if (not defined $ret) { + return $self->SetError(summary => __("Directory does not exist."), + description => "'$1' does not exist.", + code => "DIR_DOES_NOT_EXIST"); + } + $destinationFile = $data->{'destinationFile'}; + + my $ca = undef; + eval { + + if( defined $data->{'repository'}) { + + $ca = new LIMAL::CaMgm::CA($data->{"caName"}, $data->{'caPasswd'}, + $data->{"repository"}); + } else { + + $ca = new LIMAL::CaMgm::CA($data->{"caName"}, $data->{'caPasswd'}); + + } + }; + if($@) { + + return $self->SetError( summary => __("Initializing the CA failed."), + description => YaST::caUtils->exception2String($@), + code => "LIMAL_CALL_FAILED"); + } + + my $repository = "$CAM_ROOT"; + $repository = $data->{'repository'} if defined $data->{'repository'}; + + my $origPath = "$repository/$caName/req/$request.req"; + my $size = SCR->Read(".target.size", $origPath); + if ($size <= 0) { + return $self->SetError(summary => __("Request not found in")." '$origPath'", + code => "FILE_DOES_NOT_EXIST"); + } + copy($origPath, $destinationFile) or return $self->SetError(summary => __("Copy Request failed"), + code => "LIMAL_CALL_FAILED"); + return 1; +} + +=item * C<$file = ExportCertificate($valueMap)> Export a certificate to a file or returns it in different formats. Modified: trunk/ca-management/src/request.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/ca-management/src/request.ycp?rev=66150&r1=66149&r2=66150&view=diff ============================================================================== --- trunk/ca-management/src/request.ycp (original) +++ trunk/ca-management/src/request.ycp Thu Sep 29 12:25:50 2011 @@ -25,18 +25,18 @@ import "Wizard"; import "Label"; import "Popup"; - + textdomain "ca-management"; - + include "ca-management/signRequest.ycp"; - + define list<string> requestID = []; // help text 1/6 string requestHelptext = _("<p>First, see a list view with all available requests of this CA. The columns are the DN of the request including the e-mail address.</p>"); - // help text 2/6 + // help text 2/6 requestHelptext = requestHelptext + _("<p>Select one of the requests and execute some actions.</p>"); - // help text 3/6 + // help text 3/6 requestHelptext = requestHelptext + _("<p><b>View</b> opens a window with a text representation of the complete request.</p>"); // help text 4/6 requestHelptext = requestHelptext + _("<p>You can also <b>Sign</b>, <b>Delete</b>, or <b>Export</b> a request.</p>"); @@ -54,7 +54,7 @@ map aliases = $[ "new_certinit" : ``(new_cert_init ("Client Request")), - "new_certSaveDef" : ``(new_cert_save_default ()), + "new_certSaveDef" : ``(new_cert_save_default ()), "new_cert1" : ``(new_cert1 ("Client Request")), "new_cert2" : ``(new_cert2 ("Client Request")), "new_cert3" : ``(new_cert3 ("Client Request")), @@ -78,7 +78,7 @@ map aliases = $[ "new_certinit" : ``(new_cert_init ("Server Request")), - "new_certSaveDef" : ``(new_cert_save_default ()), + "new_certSaveDef" : ``(new_cert_save_default ()), "new_cert1" : ``(new_cert1 ("Server Request")), "new_cert2" : ``(new_cert2 ("Server Request")), "new_cert3" : ``(new_cert3 ("Server Request")), @@ -102,7 +102,7 @@ map aliases = $[ "new_certinit" : ``(new_cert_init ("Sub CA Request")), - "new_certSaveDef" : ``(new_cert_save_default ()), + "new_certSaveDef" : ``(new_cert_save_default ()), "new_cert1" : ``(new_cert1 ("Sub CA Request")), "new_cert2" : ``(new_cert2 ("Sub CA Request")), "new_cert3" : ``(new_cert3 ("Sub CA Request")), @@ -116,9 +116,9 @@ UI::CloseDialog(); return ret; - } + } + - /** * Signing new Request sequence * @param kind (`signClient,`signServer,`signCA) @@ -130,23 +130,23 @@ $["req_init" : ``(signRequestInit ("Client Request")), "req_sign1" : ``(signRequest1 ("Client Request")), "req_sign2" : ``(signRequest2 ("Client Request")), - "req_advanced" : ``(new_cert_advanced (false, "Sign Request")), + "req_advanced" : ``(new_cert_advanced (false, "Sign Request")), ], `signServer: $["req_init" : ``(signRequestInit ("Server Request")), "req_sign1" : ``(signRequest1 ("Server Request")), "req_sign2" : ``(signRequest2 ("Server Request")), - "req_advanced" : ``(new_cert_advanced (false, "Sign Request")), + "req_advanced" : ``(new_cert_advanced (false, "Sign Request")), ], `signCA: $["req_init" : ``(signRequestInit ("CA Request")), "req_sign1" : ``(signRequest1 ("CA Request")), "req_sign2" : ``(signRequest2 ("CA Request")), - "req_advanced" : ``(new_cert_advanced (false, "Sign Request")), + "req_advanced" : ``(new_cert_advanced (false, "Sign Request")), ] ]; - - + + map requestSequence = $[ "ws_start" : "req_init", "req_init" : $[ @@ -169,18 +169,18 @@ "req_advanced" : $[ `abort : `abort, `back : "req_sign2" - ], + ], ]; Wizard::CreateDialog(); Wizard::SetDesktopTitleAndIcon("ca_mgm"); symbol ret = WizardSequencer(aliases[kind]:$[], requestSequence); - + UI::CloseDialog(); return ret; } - + /** * showLongRequestDescription - description of a request in textform @@ -193,10 +193,10 @@ "caPasswd":getPassword(CAname), "request":Request, "type":"plain"]); - + y2milestone("ReadRequest(%1,%2): %3", CAname, Request, ret); ret = "<pre>" + ret + "</pre>"; - + if (ret == nil) { showErrorCaManagement (); @@ -220,10 +220,10 @@ UI::SetFocus (`id(`ok)); UI::UserInput (); - UI::CloseDialog (); - } + UI::CloseDialog (); + } } - + /** * Creates request items * @@ -235,7 +235,7 @@ integer i = 0; requestID = []; - + list<map> ret = (list<map>) YaPI::CaManagement::ReadRequestList ($["caName":currentCA, "caPasswd":getPassword(currentCA)]); if (ret == nil) { @@ -243,10 +243,10 @@ return nil; } y2milestone("ReadRequestList(%1): %2", currentCA, ret); - + foreach (map element, ret, ``{ - result = add (result, `item (`id (i), + result = add (result, `item (`id (i), element["commonName"]:"", element["emailAddress"]:"", element["organizationName"]:"", @@ -262,11 +262,11 @@ } /** - * Dialog Tab - request - + * Dialog Tab - request - * @return term for requests of a selected CA */ - term getRequestTab () { - list<term> certTermList = getRequestList (CaMgm::currentCA); + term getRequestTab () { + list<term> certTermList = getRequestList (CaMgm::currentCA); if (certTermList == nil) { return nil; @@ -285,7 +285,7 @@ _("State"), _("Country"), _("Generate Time")), certTermList), `HSpacing (1) - ), + ), `HBox ( `HSpacing (1), `RichText(`id(`textinfo),""), @@ -297,11 +297,11 @@ `HSpacing (1), `MenuButton( _("Add"), [ - `item(`id(`addCARequest), _("Add Sub-CA Request") ), + `item(`id(`addCARequest), _("Add Sub-CA Request") ), `item(`id(`addServerRequest), _("Add Server Request") ), `item(`id(`addClientRequest), _("Add Client Request") ) ] - ), + ), `HStretch(), `MenuButton(`id(`request), _("&Request"), @@ -314,8 +314,8 @@ `item(`id(`signServer), _("As Server Certificate") ), `item(`id(`signCA), _("As CA Certificate") ) ]), - `item(`id(`delete), _("&Delete") ) //, - //`item(`id(`exportFile), _("Export to File") ) + `item(`id(`delete), _("&Delete") ), + `item(`id(`exportFile), _("Export to File") ) ] ), `HSpacing (1) @@ -324,17 +324,17 @@ ); return contents; } - + /** * Initialize the tab of the dialog */ void initRequestTab () { boolean anyitems = UI::QueryWidget (`id (`table), `CurrentItem) != nil; UI::ChangeWidget (`id (`request), `Enabled, anyitems); - + integer id = (integer) UI::QueryWidget (`id (`table), `CurrentItem); CaMgm::currentRequest = (string) requestID[id]:""; - + if (anyitems) { map ret = (map) YaPI::CaManagement::ReadRequest ($["caName":CaMgm::currentCA, @@ -346,9 +346,9 @@ // Add generation time to map term itemTerm = (term) UI::QueryWidget(`id(`table), `Item(id)); ret = add (ret, "date", itemTerm[8]:""); - + UI::ChangeWidget( `id(`textinfo), `Value, getRequestDescription (ret, false)); - } + } } @@ -362,12 +362,12 @@ { initRequestTab (); } - + if (ui == `view) { showLongRequestDescription (CaMgm::currentCA, - CaMgm::currentRequest); - } + CaMgm::currentRequest); + } if(ui == `reqcpw) { // we need to fake a certificate name @@ -399,32 +399,48 @@ || ui == `signCA) { signRequestSequence (ui); - ui = `again; + ui = `again; } if (ui == `exportFile) { - Popup::Error(_("Currently not supported.")); + //Popup::Error(_("Currently not supported.")); + string newreqfile = UI::AskForSaveFileName( ".", "*", _("Save as") ); + if (newreqfile != nil && newreqfile != "") + { + string ret = (string) YaPI::CaManagement::ExportRequest ($[ "caName": CaMgm::currentCA, + "caPasswd": getPassword(CaMgm::currentCA), + "request": CaMgm::currentRequest, + "destinationFile": newreqfile]); + if (ret != nil && ret == "1") + { + Popup::Message(_("Saved to file successfully")); + } + else + { + showErrorCaManagement(); + } + } } if (ui == `import) { importRequestFromDisk (CaMgm::currentCA); - ui = `again; + ui = `again; } if (ui == `addCARequest) { newCARequestSequence (); - ui = `again; - } + ui = `again; + } if (ui == `addServerRequest) { newServerRequestSequence (); - ui = `again; + ui = `again; } if (ui == `addClientRequest) { newClientRequestSequence (); - ui = `again; - } + ui = `again; + } return (symbol)ui; } -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org
participants (1)
-
mcalmer@svn2.opensuse.org