comparison cli-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
32 * The chosen [encryption | MAC | compression] algorithm to each 32 * The chosen [encryption | MAC | compression] algorithm to each
33 * direction MUST be the first algorithm on the client's list 33 * direction MUST be the first algorithm on the client's list
34 * that is also on the server's list. 34 * that is also on the server's list.
35 */ 35 */
36 algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[], 36 algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[],
37 int *goodguess) { 37 enum kexguess2_used *kexguess2, int *goodguess) {
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 TRACE(("cli_buf_match_algo: %s", algolist)) 51 TRACE(("cli_buf_match_algo: %s", algolist))
50 if (len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) { 52 if (len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) {
70 if (count >= MAX_PROPOSED_ALGO) { 72 if (count >= MAX_PROPOSED_ALGO) {
71 break; 73 break;
72 } 74 }
73 } 75 }
74 76
77 if (kexguess2 && *kexguess2 == KEXGUESS2_LOOK) {
78 for (i = 0; i < count; i++)
79 {
80 if (strcmp(remotealgos[i], KEXGUESS2_ALGO_NAME) == 0) {
81 *kexguess2 = KEXGUESS2_YES;
82 break;
83 }
84 }
85 if (*kexguess2 == KEXGUESS2_LOOK) {
86 *kexguess2 = KEXGUESS2_NO;
87 }
88 }
89
75 /* iterate and find the first match */ 90 /* iterate and find the first match */
76 91
77 for (j = 0; localalgos[j].name != NULL; j++) { 92 for (j = 0; localalgos[j].name != NULL; j++) {
78 if (localalgos[j].usable) { 93 if (localalgos[j].usable) {
79 len = strlen(localalgos[j].name); 94 len = strlen(localalgos[j].name);
80 for (i = 0; i < count; i++) { 95 for (i = 0; i < count; i++) {
81 if (len == strlen(remotealgos[i]) 96 if (len == strlen(remotealgos[i])
82 && strncmp(localalgos[j].name, 97 && strncmp(localalgos[j].name,
83 remotealgos[i], len) == 0) { 98 remotealgos[i], len) == 0) {
84 if (i == 0 && j == 0) { 99 if (goodguess && kexguess2) {
85 /* was a good guess */ 100 if (*kexguess2 == KEXGUESS2_YES) {
86 *goodguess = 1; 101 if (j == 0) {
102 *goodguess = 1;
103 }
104 } else {
105 if (i == 0 && j == 0) {
106 *goodguess = 1;
107 }
108 }
87 } 109 }
88 ret = &localalgos[j]; 110 ret = &localalgos[j];
89 goto out; 111 goto out;
90 } 112 }
91 } 113 }