pith/smkeys.c
/*
 * Add the CACert Container contents into the CACert store.
 *
 * Returns > 0 for success, 0 for failure
 */
Add the CACert Container contents into the CACert store.
Returns > 0 for success, 0 for failure
Add the CACert Container contents into the CACert store . Returns > 0 for success 0 for failure
int
mem_add_extra_cacerts(char *contents, X509_LOOKUP *lookup)
{
    char *p, *q, *line, *certtext, *save_p;
    BIO  *in, *out;
    int   len, failed = 0;
    char *tempfile;
    char  iobuf[4096];
    if(contents && *contents){
	for(p = contents; *p != '\0';){
	    line = p;
	    while(*p && *p != '\n')
	      p++;
	    save_p = NULL;
	    if(*p == '\n'){
		save_p = p;
		*p++ = '\0';
	    }
	    if(strncmp(CACERTSTORELEADER, line, strlen(CACERTSTORELEADER)) == 0){
		certtext = strstr(p, "-----BEGIN");
		if(certtext != NULL){
		    if((q = strstr(certtext, CACERTSTORELEADER)) != NULL){
			p = q;
		    }
		    else{		
			q = certtext + strlen(certtext);
			p = q;
		    }
		    in = BIO_new_mem_buf(certtext, q-certtext);
		    if(in){
			tempfile = temp_nam(NULL, "az");
			out = NULL;
			if(tempfile)
			  out = BIO_new_file(tempfile, "w");
			if(out){
			    while((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
			      BIO_write(out, iobuf, len);
			    BIO_free(out);
			    if(!X509_LOOKUP_load_file(lookup, tempfile, X509_FILETYPE_PEM))
			      failed++;
			    fs_give((void **) &tempfile);
			}
			BIO_free(in);
		    }
		}
		else{
		    p = p + strlen(p);
		    q_status_message1(SM_ORDER | SM_DING, 3, 3, _("Error in cacert container, missing BEGIN, certtext=%s"), certtext);
		}
	    }
	    else{
		p = p + strlen(p);
                q_status_message1(SM_ORDER | SM_DING, 3, 3, _("Error in cacert container, missing separator, line=%s"), line);
	    }
	    if(save_p)
	      *save_p = '\n';
	}
    }
    return(!failed);
}
int mem_add_extra_cacerts ( char * contents , X509_LOOKUP * lookup ) { char * p , * q , * line , * certtext , * save_p ; BIO * in , * out ; int len , failed = 0 ; char * tempfile ; char iobuf [ 4096 ] ; if ( contents && * contents ) { for ( p = contents ; * p != ' \0 ' ; ) { line = p ; while ( * p && * p != ' \n ' ) p ++ ; save_p = NULL ; if ( * p == ' \n ' ) { save_p = p ; * p ++ = ' \0 ' ; } if ( strncmp ( CACERTSTORELEADER , line , strlen ( CACERTSTORELEADER ) ) == 0 ) { certtext = strstr ( p , " " ) ; if ( certtext != NULL ) { if ( ( q = strstr ( certtext , CACERTSTORELEADER ) ) != NULL ) { p = q ; } else { q = certtext + strlen ( certtext ) ; p = q ; } in = BIO_new_mem_buf ( certtext , q - certtext ) ; if ( in ) { tempfile = temp_nam ( NULL , " " ) ; out = NULL ; if ( tempfile ) out = BIO_new_file ( tempfile , " " ) ; if ( out ) { while ( ( len = BIO_read ( in , iobuf , sizeof ( iobuf ) ) ) > 0 ) BIO_write ( out , iobuf , len ) ; BIO_free ( out ) ; if ( ! X509_LOOKUP_load_file ( lookup , tempfile , X509_FILETYPE_PEM ) ) failed ++ ; fs_give ( ( void * * ) & tempfile ) ; } BIO_free ( in ) ; } } else { p = p + strlen ( p ) ; q_status_message1 ( SM_ORDER | SM_DING , 3 , 3 , _ ( " " ) , certtext ) ; } } else { p = p + strlen ( p ) ; q_status_message1 ( SM_ORDER | SM_DING , 3 , 3 , _ ( " " ) , line ) ; } if ( save_p ) * save_p = ' \n ' ; } } return ( ! failed ) ; }
Add the CACert Container contents into the CACert store.
Add the CACert Container contents into the CACert store .
/*
     * The most straight-forward way to do this is to write
     * the container contents to a temp file and then load the
     * contents of the file with X509_LOOKUP_load_file(), like
     * is done in add_certs_in_dir(). What we don't know is if
     * each file should consist of one cacert or if they can all
     * just be jammed together into one file. To be safe, we'll use
     * one file per and do each in a separate operation.
     */ /* look for separator line */ /* certtext is the content that should go in a file */ /* end of file */