Skip to content

Commit

Permalink
Use read_stdin() instead of fgets() in certificate validation
Browse files Browse the repository at this point in the history
Now we can make read_stdin() do UTF-8 conversion for legacy environments...

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jul 28, 2014
1 parent ba9b58a commit 5f10185
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions main.c
Expand Up @@ -1266,9 +1266,8 @@ static int validate_peer_cert(void *_vpninfo, OPENCONNECT_X509 *peer_cert,
}

while (1) {
char buf[80];
char *details;
char *p;
char *response = NULL;

fprintf(stderr, _("\nCertificate from VPN server \"%s\" failed verification.\n"
"Reason: %s\n"), vpninfo->hostname, reason);
Expand All @@ -1278,13 +1277,12 @@ static int validate_peer_cert(void *_vpninfo, OPENCONNECT_X509 *peer_cert,

fprintf(stderr, _("Enter '%s' to accept, '%s' to abort; anything else to view: "),
_("yes"), _("no"));
if (!fgets(buf, sizeof(buf), stdin))

read_stdin(&response, 0);
if (!response)
return -EINVAL;
p = strchr(buf, '\n');
if (p)
*p = 0;

if (!strcasecmp(buf, _("yes"))) {
if (!strcasecmp(response, _("yes"))) {
struct accepted_cert *newcert = malloc(sizeof(*newcert) +
strlen(vpninfo->hostname) + 1);
if (newcert) {
Expand All @@ -1293,10 +1291,14 @@ static int validate_peer_cert(void *_vpninfo, OPENCONNECT_X509 *peer_cert,
strcpy(newcert->fingerprint, fingerprint);
strcpy(newcert->host, vpninfo->hostname);
}
free(response);
return 0;
}
if (!strcasecmp(buf, _("no")))
if (!strcasecmp(response, _("no"))) {
free(response);
return -EINVAL;
}
free(response);

details = openconnect_get_cert_details(vpninfo, peer_cert);
fputs(details, stderr);
Expand Down

0 comments on commit 5f10185

Please sign in to comment.