From 5701962a6d7ff55afc5a0cf3f6352290a72fb632 Mon Sep 17 00:00:00 2001 From: Elio Maldonado Date: Tue, 4 Nov 2008 04:15:39 +0000 Subject: [PATCH] Pass acess passwords to keutil using specially formatted file and key encryption password via command line, no need to save the cert to a file on makeca --- genkey.pl | 101 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 39 deletions(-) diff --git a/genkey.pl b/genkey.pl index 532abd0..335c627 100644 --- a/genkey.pl +++ b/genkey.pl @@ -139,10 +139,18 @@ GetOptions('test|t' => \$test_mode, 'gdb' => \$gdb, 'makeca' => \$ca_mode) or usage(); usage() unless @ARGV != 0; + +if $genreq_mode && $renew && !$nss) { +print STDERR <$tmpPasswordFile")) { - Newt::newtWinMessage("Error", "Close", + # + # Write password to a file with lines formatted as: + # NSS Certificate DB:access_passphrase + # PEM Token #0:ca_key_access_passphrase + # PEM Token #1:server_key_access_passphrase + # + my $passwordLine = $nss + ? "NSS Certificate DB" : $cacert ? "PEM Token #0:" : "PEM Token #1:"; + $passwordLine .= "$passwd\n"; + if ($tmpPasswordFile) { + # append to existing file + if (!open(SESAME, ">>$tmpPasswordFile")) { + Newt::newtWinMessage("Error", "Close", + "Unable to append passphrase to $tmpPasswordFile". + "\n\nPress return to continue"); + return "Back"; + } + } else { + # write to a new file + $tmpPasswordFile = ".passwordfile.".$$; + if (!open (SESAME, ">$tmpPasswordFile")) { + Newt::newtWinMessage("Error", "Close", "Unable to save passphrase to $tmpPasswordFile". "\n\nPress return to continue"); - $tmpPasswordFile = ''; # mark it as never created - return "Back"; + $tmpPasswordFile = ''; # mark it as never created + return "Back"; + } } - print SESAME $passwd; + print SESAME $passwordLine; close(SESAME); # This file will be deleted on program exit. return "Next"; } +# Prompts for a module or key access password. +# The argument indicates wheter the password is to +# access the nss module access or for access to the key +# to be loaded from a pem file into a PEM module token. sub moduleAccesPasswordWindow -{ +{ + my ($what) = @_; + # either "module" or "key" + my $message = <Add(0, 0, Newt::Textbox(70, 5, 0, $message)); - my $checkbox = Newt::Checkbox("Module access password if any"); + my $checkbox = Newt::Checkbox($what." access password if any"); $panel->Add(0, 1, $checkbox); $panel->Add(0, 2, NextBackCancelButton()); @@ -738,10 +771,10 @@ EOT return $ret if ($ret eq "Back" or $ret eq "Cancel" or $plain == 1); - $panel = Newt::Panel(1, 3, "Enter the module passphrase"); + $panel = Newt::Panel(1, 3, "Enter the $what passphrase"); $message = <Add(0, 0, Newt::Textbox(70, 5, 0, $message)); $subp = Newt::Panel(2,2); @@ -788,8 +821,10 @@ EOT # module acces password instead. sub passwordWindow { - return moduleAccesPasswordWindow() if $nss; - return "Next" if $renew; + if ($nss || $renew) { + # nss module access password or key password + return moduleAccesPasswordWindow($nss ? "module" : "key"); + } my $message = <