[Openswan dev] bug in openswan-2.1.0rc1/programs/pluto/whack.c
Niki Waibel
niki.waibel at newlogic.com
Fri Mar 19 16:28:01 CET 2004
problem:
if i use x509 certs and keypairs with passphrases + %prompt in /etc/ipsec.secrets
the passphrase is never accepted.
===
# ipsec auto --rereadsecrets
040 need passphrase for '/etc/ipsec.d/private/testKey.pem'
Secret enter:
003 no passphrase entered, aborted
003 "/etc/ipsec.secrets" line 2: error loading RSA private key file
040 need passphrase for '/etc/ipsec.d/private/testKey.pem'
Secret enter:
sh: line 4: 1061 Segmentation fault ipsec whack --rereadsecrets
===
analysis:
the problematic function is get_secret. you can find it in
./programs/pluto/whack.c. it seems that this part:
===
case RC_ENTERSECRET:
if(!gotxauthpass)
{
xauthpasslen = get_secret(xauthpass
, sizeof(xauthpass));
}
===
is wrong. it is a bit stange to me that the var ``xauthpass'' is used. i am
not using the XAUTH feature ... anyway, sizeof(xauthpass) seems to be zero...
i think this should be:
xauthpasslen = get_secret(xauthpass, 128);
and -- the funktion itself should look like this:
===
static size_t
get_secret(char *buf, size_t bufsize)
{
const char *secret;
int len;
fflush(stdout);
usleep(20000); /* give fflush time for flushing */
secret = getpass("Secret enter: ");
secret = (secret == NULL) ? "" : secret;
strncpy(buf, secret, bufsize);
len = strlen(buf) + 1;
return len;
}
===
patch:
===
diff -u -r openswan-2.1.0rc1.orig/programs/pluto/whack.c openswan-2.1.0rc1/programs/pluto/whack.c
--- openswan-2.1.0rc1.orig/programs/pluto/whack.c 2004-02-09 23:00:53.000000000 +0100
+++ openswan-2.1.0rc1/programs/pluto/whack.c 2004-03-19 17:05:34.313319440 +0100
@@ -666,8 +666,8 @@
fflush(stdout);
usleep(20000); /* give fflush time for flushing */
- buf = getpass("Secret enter: ");
- secret = (buf == NULL)? "" : buf;
+ secret = getpass("Secret enter: ");
+ secret = (secret == NULL) ? "" : secret;
strncpy(buf, secret, bufsize);
@@ -1651,7 +1651,7 @@
if(!gotxauthpass)
{
xauthpasslen = get_secret(xauthpass
- , sizeof(xauthpass));
+ , 128);
}
send_reply(sock, xauthpass, xauthpasslen);
break;
===
in addition:
===
GETPASS(3) Linux Programmer's Manual GETPASS(3)
NAME
getpass - get a password
SYNOPSIS
#include <unistd.h>
char *getpass( const char * prompt );
DESCRIPTION
This function is obsolete. Do not use it.
The getpass() function opens /dev/tty (the controlling terminal of the
process), outputs the string prompt, turns off echoing, reads one line
(the "password"), restores the terminal state and closes /dev/tty
again.
===
note ---> ``This function is obsolete. Do not use it.''
hope this helps, niki
More information about the Dev
mailing list