comparison common-algo.c @ 684:c37857676924 insecure-nocrypto

Merge in "-m"/"-c" code
author Matt Johnston <matt@ucc.asn.au>
date Thu, 17 May 2012 08:09:19 +0800
parents a4b7627b3157 63f8d6c469cf
children 983a817f8e41
comparison
equal deleted inserted replaced
681:a4b7627b3157 684:c37857676924
278 } 278 }
279 279
280 return DROPBEAR_FAILURE; 280 return DROPBEAR_FAILURE;
281 } 281 }
282 282
283
284
285 /* Output a comma separated list of algorithms to a buffer */ 283 /* Output a comma separated list of algorithms to a buffer */
286 void buf_put_algolist(buffer * buf, algo_type localalgos[]) { 284 void buf_put_algolist(buffer * buf, algo_type localalgos[]) {
287 285
288 unsigned int i, len; 286 unsigned int i, len;
289 unsigned int donefirst = 0; 287 unsigned int donefirst = 0;
300 } 298 }
301 } 299 }
302 buf_putstring(buf, algolist->data, algolist->len); 300 buf_putstring(buf, algolist->data, algolist->len);
303 buf_free(algolist); 301 buf_free(algolist);
304 } 302 }
303
304 #ifdef ENABLE_USER_ALGO_LIST
305
306 char *
307 algolist_string(algo_type algos[])
308 {
309 char *ret_list;
310 buffer *b = buf_new(200);
311 buf_put_algolist(b, algos);
312 buf_setpos(b, b->len);
313 buf_putbyte(b, '\0');
314 buf_setpos(b, 4);
315 ret_list = m_strdup(buf_getptr(b, b->len - b->pos));
316 buf_free(b);
317 return ret_list;
318 }
319
320 static algo_type*
321 check_algo(const char* algo_name, algo_type *algos)
322 {
323 algo_type *a;
324 for (a = algos; a->name != NULL; a++)
325 {
326 if (strcmp(a->name, algo_name) == 0)
327 {
328 return a;
329 }
330 }
331
332 return NULL;
333 }
334
335 static void
336 try_add_algo(const char *algo_name, algo_type *algos,
337 const char *algo_desc, algo_type * new_algos, int *num_ret)
338 {
339 algo_type *match_algo = check_algo(algo_name, algos);
340 if (!match_algo)
341 {
342 dropbear_log(LOG_WARNING, "This Dropbear program does not support '%s' %s algorithm", algo_name, algo_desc);
343 return;
344 }
345
346 new_algos[*num_ret] = *match_algo;
347 (*num_ret)++;
348 }
349
350 /* Checks a user provided comma-separated algorithm list for available
351 * options. Any that are not acceptable are removed in-place. Returns the
352 * number of valid algorithms. */
353 int
354 check_user_algos(const char* user_algo_list, algo_type * algos,
355 const char *algo_desc)
356 {
357 algo_type new_algos[MAX_PROPOSED_ALGO];
358 /* this has two passes. first we sweep through the given list of
359 * algorithms and mark them as usable=2 in the algo_type[] array... */
360 int num_ret = 0;
361 char *work_list = m_strdup(user_algo_list);
362 char *last_name = work_list;
363 char *c;
364 for (c = work_list; *c; c++)
365 {
366 if (*c == ',')
367 {
368 *c = '\0';
369 try_add_algo(last_name, algos, algo_desc, new_algos, &num_ret);
370 last_name = c++;
371 }
372 }
373 try_add_algo(last_name, algos, algo_desc, new_algos, &num_ret);
374 m_free(work_list);
375
376 new_algos[num_ret].name = NULL;
377
378 /* Copy one more as a blank delimiter */
379 memcpy(algos, new_algos, sizeof(*new_algos) * (num_ret+1));
380 return num_ret;
381 }
382 #endif // ENABLE_USER_ALGO_LIST