comparison svr-algo.c @ 740:3062da90dab8 kexguess

Add kexguess2 behaviour
author Matt Johnston <matt@ucc.asn.au>
date Fri, 29 Mar 2013 23:29:48 +0800
parents 870c63519757
children
comparison
equal deleted inserted replaced
739:d44325108d0e 740:3062da90dab8
31 * also in localalgos[], or return NULL on failure. 31 * also in localalgos[], or return NULL on failure.
32 * (*goodguess) is set to 1 if the preferred client/server algos match, 32 * (*goodguess) is set to 1 if the preferred client/server algos match,
33 * 0 otherwise. This is used for checking if the kexalgo/hostkeyalgos are 33 * 0 otherwise. This is used for checking if the kexalgo/hostkeyalgos are
34 * guessed correctly */ 34 * guessed correctly */
35 algo_type * svr_buf_match_algo(buffer* buf, algo_type localalgos[], 35 algo_type * svr_buf_match_algo(buffer* buf, algo_type localalgos[],
36 int *goodguess) 36 enum kexguess2_used *kexguess2, int *goodguess)
37 { 37 {
38 38
39 unsigned char * algolist = NULL; 39 unsigned char * algolist = NULL;
40 unsigned char * remotealgos[MAX_PROPOSED_ALGO]; 40 unsigned char * remotealgos[MAX_PROPOSED_ALGO];
41 unsigned int len; 41 unsigned int len;
42 unsigned int count, i, j; 42 unsigned int count, i, j;
43 algo_type * ret = NULL; 43 algo_type * ret = NULL;
44 44
45 *goodguess = 0; 45 if (goodguess) {
46 *goodguess = 0;
47 }
46 48
47 /* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */ 49 /* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */
48 algolist = buf_getstring(buf, &len); 50 algolist = buf_getstring(buf, &len);
49 /* Debug this */ 51 /* Debug this */
50 TRACE(("buf_match_algo: %s", algolist)) 52 TRACE(("buf_match_algo: %s", algolist))
71 if (count >= MAX_PROPOSED_ALGO) { 73 if (count >= MAX_PROPOSED_ALGO) {
72 break; 74 break;
73 } 75 }
74 } 76 }
75 77
78 if (kexguess2 && *kexguess2 == KEXGUESS2_LOOK) {
79 for (i = 0; i < count; i++)
80 {
81 if (strcmp(remotealgos[i], KEXGUESS2_ALGO_NAME) == 0) {
82 *kexguess2 = KEXGUESS2_YES;
83 break;
84 }
85 }
86 if (*kexguess2 == KEXGUESS2_LOOK) {
87 *kexguess2 = KEXGUESS2_NO;
88 }
89 }
90
76 /* iterate and find the first match */ 91 /* iterate and find the first match */
77 for (i = 0; i < count; i++) { 92 for (i = 0; i < count; i++) {
78 93
79 len = strlen(remotealgos[i]); 94 len = strlen(remotealgos[i]);
80 95
81 for (j = 0; localalgos[j].name != NULL; j++) { 96 for (j = 0; localalgos[j].name != NULL; j++) {
82 if (localalgos[j].usable) { 97 if (localalgos[j].usable) {
83 if (len == strlen(localalgos[j].name) && 98 if (len == strlen(localalgos[j].name) &&
84 strncmp(localalgos[j].name, remotealgos[i], len) == 0) { 99 strncmp(localalgos[j].name, remotealgos[i], len) == 0) {
85 /* set if it was a good guess */ 100 /* set if it was a good guess */
86 if (i == 0 && j == 0) { 101 if (goodguess && kexguess2) {
87 *goodguess = 1; 102 if (*kexguess2 == KEXGUESS2_YES) {
103 if (i == 0) {
104 *goodguess = 1;
105 }
106
107 } else {
108 if (i == 0 && j == 0) {
109 *goodguess = 1;
110 }
111 }
88 } 112 }
89 /* set the algo to return */ 113 /* set the algo to return */
90 ret = &localalgos[j]; 114 ret = &localalgos[j];
91 goto out; 115 goto out;
92 } 116 }