Mercurial > dropbear
comparison cli_algo.c @ 4:fe6bca95afa7
Makefile.in contains updated files required
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 01 Jun 2004 02:46:09 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 4:fe6bca95afa7 |
---|---|
1 /* | |
2 * Dropbear - a SSH2 server | |
3 * SSH client implementation | |
4 * | |
5 * Copyright (c) 2002,2003 Matt Johnston | |
6 * Copyright (c) 2004 by Mihnea Stoenescu | |
7 * All rights reserved. | |
8 * | |
9 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
10 * of this software and associated documentation files (the "Software"), to deal | |
11 * in the Software without restriction, including without limitation the rights | |
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
13 * copies of the Software, and to permit persons to whom the Software is | |
14 * furnished to do so, subject to the following conditions: | |
15 * | |
16 * The above copyright notice and this permission notice shall be included in | |
17 * all copies or substantial portions of the Software. | |
18 * | |
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
25 * SOFTWARE. */ | |
26 | |
27 #include "algo.h" | |
28 #include "dbutil.h" | |
29 | |
30 | |
31 /* | |
32 * The chosen [encryption | MAC | compression] algorithm to each | |
33 * direction MUST be the first algorithm on the client's list | |
34 * that is also on the server's list. | |
35 */ | |
36 algo_type * cli_buf_match_algo(buffer* buf, algo_type localalgos[]) { | |
37 | |
38 unsigned char * algolist = NULL; | |
39 unsigned char * remotealgos[MAX_PROPOSED_ALGO]; | |
40 unsigned int len; | |
41 unsigned int count, i, j; | |
42 algo_type * ret = NULL; | |
43 | |
44 /* get the comma-separated list from the buffer ie "algo1,algo2,algo3" */ | |
45 algolist = buf_getstring(buf, &len); | |
46 TRACE(("cli_buf_match_algo: %s", algolist)); | |
47 if (len > MAX_PROPOSED_ALGO*(MAX_NAME_LEN+1)) { | |
48 goto out; /* just a sanity check, no other use */ | |
49 } | |
50 | |
51 /* remotealgos will contain a list of the strings parsed out */ | |
52 /* We will have at least one string (even if it's just "") */ | |
53 remotealgos[0] = algolist; | |
54 count = 1; | |
55 /* Iterate through, replacing ','s with NULs, to split it into | |
56 * words. */ | |
57 for (i = 0; i < len; i++) { | |
58 if (algolist[i] == '\0') { | |
59 /* someone is trying something strange */ | |
60 goto out; | |
61 } | |
62 if (algolist[i] == ',') { | |
63 algolist[i] = '\0'; | |
64 remotealgos[count] = &algolist[i+1]; | |
65 count++; | |
66 } | |
67 if (count == MAX_PROPOSED_ALGO) { | |
68 break; | |
69 } | |
70 } | |
71 | |
72 /* iterate and find the first match */ | |
73 | |
74 for (j = 0; localalgos[j].name != NULL; j++) { | |
75 if (localalgos[j].usable) { | |
76 len = strlen(localalgos[j].name); | |
77 for (i = 0; i < count; i++) { | |
78 if (len == strlen(remotealgos[i]) | |
79 && strncmp(localalgos[j].name, | |
80 remotealgos[i], len) == 0) { | |
81 ret = &localalgos[j]; | |
82 goto out; | |
83 } | |
84 } | |
85 } | |
86 } | |
87 | |
88 out: | |
89 m_free(algolist); | |
90 return ret; | |
91 } | |
92 |