Puttygen patch for entering passphrases from command line
If you want to use Putty's key generation program Puttygen from a command line, you can use the Unix version. However, as specified in the documentation, it is still required to enter password manually. That behaviour can not be circumvented by redirection either. A small patch (attached) is developed to introduce the option -N for specifying a new passphrase from the command line:
>puttygen --help
PuTTYgen unidentified build, Mar 2 2011 22:53:04
Usage: puttygen ( keyfile | -t type )
...
-N new passphrase
...
Show code
--- cmdgen.c 2007-03-13 15:43:14.000000000 +0100
+++ cmdgen.option-N.c 2011-03-02 22:52:17.587125000 +0100
@@ -127,7 +127,7 @@
void usage(int standalone)
{
fprintf(stderr,
- "Usage: puttygen ( keyfile | -t type [ -b bits ] )\n"
+ "Usage: puttygen ( keyfile | -t type [ -b bits ] ) [ -N passphrase ]\n"
" [ -C comment ] [ -P ] [ -q ]\n"
" [ -o output-keyfile ] [ -O type | -l | -L"
" | -p ]\n");
@@ -150,6 +150,7 @@
" -C change or specify key comment\n"
" -P change key passphrase\n"
" -q quiet: do not display progress bar\n"
+ " -N new passphrase\n"
" -O specify output type:\n"
" private output PuTTY private key format\n"
" private-openssh export OpenSSH private key\n"
@@ -265,6 +266,7 @@
int bits = 1024;
char *comment = NULL, *origcomment = NULL;
int change_passphrase = FALSE;
+ int new_passphrase = FALSE;
int errs = FALSE, nogo = FALSE;
int intype = SSH_KEYTYPE_UNOPENABLE;
int sshver = 0;
@@ -387,6 +389,7 @@
case 'C':
case 'O':
case 'o':
+ case 'N':
/*
* Option requiring parameter.
*/
@@ -443,6 +446,9 @@
case 'o':
outfile = p;
break;
+ case 'N':
+ passphrase = strdup(p);
+ new_passphrase = TRUE;
}
p = NULL; /* prevent continued processing */
break;
@@ -818,7 +824,7 @@
* Prompt for a new passphrase if we have been asked to, or if
* we have just generated a key.
*/
- if (change_passphrase || keytype != NOKEYGEN) {
+ if (change_passphrase || !(keytype == NOKEYGEN || new_passphrase)) {
prompts_t *p = new_prompts(NULL);
int ret;
NB! the patch allows passphrases without spaces only.