summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2002-01-22 23:34:12 +1100
committerDamien Miller <djm@mindrot.org>2002-01-22 23:34:12 +1100
commit49d795c647fb4c0d2dcbb3a5fcfe109984cdac15 (patch)
treec6678c4ddce34ee72e085ade04d83d7da4397fd6
parentdf64a682f17fc12ca0ae80e6331cbb89b77bd35b (diff)
- markus@cvs.openbsd.org 2002/01/21 15:13:51
[sshconnect.c] use read_passphrase+ECHO in confirm(), allows use of ssh-askpass for hostkey confirm.
-rw-r--r--ChangeLog6
-rw-r--r--sshconnect.c84
2 files changed, 43 insertions, 47 deletions
diff --git a/ChangeLog b/ChangeLog
index 3689b1d89..018364ad3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -211,6 +211,10 @@
211 [sshd.8] 211 [sshd.8]
212 clarify Allow(Groups|Users) and Deny(Groups|Users); suggestion from 212 clarify Allow(Groups|Users) and Deny(Groups|Users); suggestion from
213 allard@oceanpark.com; ok markus@ 213 allard@oceanpark.com; ok markus@
214 - markus@cvs.openbsd.org 2002/01/21 15:13:51
215 [sshconnect.c]
216 use read_passphrase+ECHO in confirm(), allows use of ssh-askpass
217 for hostkey confirm.
214 218
21520020121 21920020121
216 - (djm) Rework ssh-rand-helper: 220 - (djm) Rework ssh-rand-helper:
@@ -7358,4 +7362,4 @@
7358 - Wrote replacements for strlcpy and mkdtemp 7362 - Wrote replacements for strlcpy and mkdtemp
7359 - Released 1.0pre1 7363 - Released 1.0pre1
7360 7364
7361$Id: ChangeLog,v 1.1782 2002/01/22 12:33:45 djm Exp $ 7365$Id: ChangeLog,v 1.1783 2002/01/22 12:34:12 djm Exp $
diff --git a/sshconnect.c b/sshconnect.c
index 785c9dbe2..511fe8f39 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -13,7 +13,7 @@
13 */ 13 */
14 14
15#include "includes.h" 15#include "includes.h"
16RCSID("$OpenBSD: sshconnect.c,v 1.118 2001/12/19 07:18:56 deraadt Exp $"); 16RCSID("$OpenBSD: sshconnect.c,v 1.119 2002/01/21 15:13:51 markus Exp $");
17 17
18#include <openssl/bn.h> 18#include <openssl/bn.h>
19 19
@@ -31,6 +31,7 @@ RCSID("$OpenBSD: sshconnect.c,v 1.118 2001/12/19 07:18:56 deraadt Exp $");
31#include "readconf.h" 31#include "readconf.h"
32#include "atomicio.h" 32#include "atomicio.h"
33#include "misc.h" 33#include "misc.h"
34#include "readpass.h"
34 35
35char *client_version_string = NULL; 36char *client_version_string = NULL;
36char *server_version_string = NULL; 37char *server_version_string = NULL;
@@ -488,40 +489,24 @@ ssh_exchange_identification(void)
488static int 489static int
489confirm(const char *prompt) 490confirm(const char *prompt)
490{ 491{
491 char buf[1024]; 492 const char *msg, *again = "Please type 'yes' or 'no': ";
492 FILE *f; 493 char *p;
493 int retval = -1; 494 int ret = -1;
494 495
495 if (options.batch_mode) 496 if (options.batch_mode)
496 return 0; 497 return 0;
497 if (isatty(STDIN_FILENO)) 498 for (msg = prompt;;msg = again) {
498 f = stdin; 499 p = read_passphrase(msg, RP_ECHO);
499 else 500 if (p == NULL ||
500 f = fopen(_PATH_TTY, "rw"); 501 (p[0] == '\0') || (p[0] == '\n') ||
501 if (f == NULL) 502 strncasecmp(p, "no", 2) == 0)
502 return 0; 503 ret = 0;
503 fflush(stdout); 504 if (strncasecmp(p, "yes", 3) == 0)
504 fprintf(stderr, "%s", prompt); 505 ret = 1;
505 while (1) { 506 if (p)
506 if (fgets(buf, sizeof(buf), f) == NULL) { 507 xfree(p);
507 fprintf(stderr, "\n"); 508 if (ret != -1)
508 strlcpy(buf, "no", sizeof buf); 509 return ret;
509 }
510 /* Remove newline from response. */
511 if (strchr(buf, '\n'))
512 *strchr(buf, '\n') = 0;
513 if (strcmp(buf, "yes") == 0)
514 retval = 1;
515 else if (strcmp(buf, "no") == 0)
516 retval = 0;
517 else
518 fprintf(stderr, "Please type 'yes' or 'no': ");
519
520 if (retval != -1) {
521 if (f != stdin)
522 fclose(f);
523 return retval;
524 }
525 } 510 }
526} 511}
527 512
@@ -543,7 +528,8 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
543 int local = 0, host_ip_differ = 0; 528 int local = 0, host_ip_differ = 0;
544 int salen; 529 int salen;
545 char ntop[NI_MAXHOST]; 530 char ntop[NI_MAXHOST];
546 int host_line, ip_line; 531 char msg[1024];
532 int len, host_line, ip_line;
547 const char *host_file = NULL, *ip_file = NULL; 533 const char *host_file = NULL, *ip_file = NULL;
548 534
549 /* 535 /*
@@ -688,18 +674,16 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
688 goto fail; 674 goto fail;
689 } else if (options.strict_host_key_checking == 2) { 675 } else if (options.strict_host_key_checking == 2) {
690 /* The default */ 676 /* The default */
691 char prompt[1024];
692 fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX); 677 fp = key_fingerprint(host_key, SSH_FP_MD5, SSH_FP_HEX);
693 snprintf(prompt, sizeof(prompt), 678 snprintf(msg, sizeof(msg),
694 "The authenticity of host '%.200s (%s)' can't be " 679 "The authenticity of host '%.200s (%s)' can't be "
695 "established.\n" 680 "established.\n"
696 "%s key fingerprint is %s.\n" 681 "%s key fingerprint is %s.\n"
697 "Are you sure you want to continue connecting " 682 "Are you sure you want to continue connecting "
698 "(yes/no)? ", host, ip, type, fp); 683 "(yes/no)? ", host, ip, type, fp);
699 xfree(fp); 684 xfree(fp);
700 if (!confirm(prompt)) { 685 if (!confirm(msg))
701 goto fail; 686 goto fail;
702 }
703 } 687 }
704 if (options.check_host_ip && ip_status == HOST_NEW) { 688 if (options.check_host_ip && ip_status == HOST_NEW) {
705 snprintf(hostline, sizeof(hostline), "%s,%s", host, ip); 689 snprintf(hostline, sizeof(hostline), "%s,%s", host, ip);
@@ -803,20 +787,28 @@ check_host_key(char *host, struct sockaddr *hostaddr, Key *host_key,
803 787
804 if (options.check_host_ip && host_status != HOST_CHANGED && 788 if (options.check_host_ip && host_status != HOST_CHANGED &&
805 ip_status == HOST_CHANGED) { 789 ip_status == HOST_CHANGED) {
806 log("Warning: the %s host key for '%.200s' " 790 snprintf(msg, sizeof(msg),
807 "differs from the key for the IP address '%.128s'", 791 "Warning: the %s host key for '%.200s' "
808 type, host, ip); 792 "differs from the key for the IP address '%.128s'"
809 if (host_status == HOST_OK) 793 "\nOffending key for IP in %s:%d",
810 log("Matching host key in %s:%d", host_file, host_line); 794 type, host, ip, ip_file, ip_line);
811 log("Offending key for IP in %s:%d", ip_file, ip_line); 795 if (host_status == HOST_OK) {
796 len = strlen(msg);
797 snprintf(msg + len, sizeof(msg) - len,
798 "\nMatching host key in %s:%d",
799 host_file, host_line);
800 }
812 if (options.strict_host_key_checking == 1) { 801 if (options.strict_host_key_checking == 1) {
802 log(msg);
813 error("Exiting, you have requested strict checking."); 803 error("Exiting, you have requested strict checking.");
814 goto fail; 804 goto fail;
815 } else if (options.strict_host_key_checking == 2) { 805 } else if (options.strict_host_key_checking == 2) {
816 if (!confirm("Are you sure you want " 806 strlcat(msg, "\nAre you sure you want "
817 "to continue connecting (yes/no)? ")) { 807 "to continue connecting (yes/no)? ", sizeof(msg));
808 if (!confirm(msg))
818 goto fail; 809 goto fail;
819 } 810 } else {
811 log(msg);
820 } 812 }
821 } 813 }
822 814