comparison cinst/mozilla.c @ 235:0c4d65a7cd14

Started to write input parser. Strange problems with b64 decode seemingly to accept invalid input?
author Sascha Wilde <wilde@intevation.de>
date Fri, 28 Mar 2014 13:04:59 +0100
parents 774e944c395b
children dd417a2ff9cd 74d6e33c7d38
comparison
equal deleted inserted replaced
232:774e944c395b 235:0c4d65a7cd14
28 * Success messages are written to stdout. Errors to stderr. For logging 28 * Success messages are written to stdout. Errors to stderr. For logging
29 * purposes each installation / removal of a certificate will be reported 29 * purposes each installation / removal of a certificate will be reported
30 * with the profile name that it modified. 30 * with the profile name that it modified.
31 * 31 *
32 */ 32 */
33
34 /**
35 * @brief Needs to eb defined to get strnlen()
36 */
37 #define _POSIX_C_SOURCE 200809L
38
39 /* REMOVEME: */
40 #include <unistd.h>
33 41
34 #include <dirent.h> 42 #include <dirent.h>
35 #include <cert.h> 43 #include <cert.h>
36 #include <certt.h> 44 #include <certt.h>
37 #include <nss.h> 45 #include <nss.h>
322 330
323 331
324 int 332 int
325 main () 333 main ()
326 { 334 {
335 char inpl[LINEBUFLEN];
336 size_t inpllen;
337 char *dercert;
338 size_t dercertlen;
327 char **pdirs; 339 char **pdirs;
340 bool parserr = true;
328 pdirs = 341 pdirs =
329 get_all_profile_dirs(); 342 get_all_profile_dirs();
343
330 if (pdirs != NULL) 344 if (pdirs != NULL)
331 { 345 {
346 while ( fgets(inpl, LINEBUFLEN, stdin) != NULL )
347 {
348 inpllen = strnlen(inpl, LINEBUFLEN);
349 /* Validate input line:
350 * - must be (much) longer than 3 characters
351 * - must start with "*:"
352 */
353 if ((inpllen > 3) && (inpl[1] == ':'))
354 /* Now parse Input */
355 switch(inpl[0])
356 {
357 case 'R':
358 parserr = true;
359 DEBUGPRINTF("Removing Certificate: %s", &inpl[2]);
360 if ( str_base64_decode(&dercert, &dercertlen,
361 &inpl[2], inpllen-2) == 0 )
362 {
363 DEBUGPRINTF("Successfully b64 decoded cert: '");
364 write(2, dercert, dercertlen);
365 fprintf(stderr,"'\n");
366 parserr = false;
367 }
368 else
369 DEBUGPRINTF("Base64 decoded failed!\n'");
370 break;
371 case 'I':
372 DEBUGPRINTF("Installing Certificate: %s", &inpl[2]);
373 parserr = false;
374 break;
375 default:
376 parserr = true;
377 }
378 else
379 {
380 parserr = true;
381 }
382
383 if (parserr)
384 {
385 DEBUGPRINTF("FATAL: Invalid input: %s\n", inpl);
386 exit(ERR_MOZ_INVALID_INPUT);
387 }
388 }
389
332 for (int i=0; pdirs[i] != NULL; i++) 390 for (int i=0; pdirs[i] != NULL; i++)
333 { 391 {
334 puts(pdirs[i]); 392 puts(pdirs[i]);
335 nss_list_certs(pdirs[i]); 393 nss_list_certs(pdirs[i]);
336 } 394 }

http://wald.intevation.org/projects/trustbridge/