Main Page | Class List | Directories | File List | Class Members | File Members

crl2p7.c File Reference

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "apps.h"
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pkcs7.h>
#include <openssl/pem.h>
#include <openssl/objects.h>

Go to the source code of this file.

Defines

#define PROG   crl2pkcs7_main

Functions

static int add_certs_from_file (STACK_OF(X509)*stack, char *certfile)
int MAIN (int, char **)


Define Documentation

#define PROG   crl2pkcs7_main
 

Definition at line 77 of file crl2p7.c.


Function Documentation

static int add_certs_from_file STACK_OF(X509)*  stack,
char *  certfile
[static]
 

Definition at line 296 of file crl2p7.c.

References bio_err, BIO_free(), BIO_new(), BIO_printf(), BIO_read_filename, BIO_s_file(), sk_X509_INFO_free, sk_X509_INFO_num, sk_X509_INFO_shift, sk_X509_push, STACK_OF, X509_info_st::x509, and X509_INFO_free().

00297         {
00298         struct stat st;
00299         BIO *in=NULL;
00300         int count=0;
00301         int ret= -1;
00302         STACK_OF(X509_INFO) *sk=NULL;
00303         X509_INFO *xi;
00304 
00305         if ((stat(certfile,&st) != 0))
00306                 {
00307                 BIO_printf(bio_err,"unable to load the file, %s\n",certfile);
00308                 goto end;
00309                 }
00310 
00311         in=BIO_new(BIO_s_file());
00312         if ((in == NULL) || (BIO_read_filename(in,certfile) <= 0))
00313                 {
00314                 BIO_printf(bio_err,"error opening the file, %s\n",certfile);
00315                 goto end;
00316                 }
00317 
00318         /* This loads from a file, a stack of x509/crl/pkey sets */
00319         sk=PEM_X509_INFO_read_bio(in,NULL,NULL,NULL);
00320         if (sk == NULL) {
00321                 BIO_printf(bio_err,"error reading the file, %s\n",certfile);
00322                 goto end;
00323         }
00324 
00325         /* scan over it and pull out the CRL's */
00326         while (sk_X509_INFO_num(sk))
00327                 {
00328                 xi=sk_X509_INFO_shift(sk);
00329                 if (xi->x509 != NULL)
00330                         {
00331                         sk_X509_push(stack,xi->x509);
00332                         xi->x509=NULL;
00333                         count++;
00334                         }
00335                 X509_INFO_free(xi);
00336                 }
00337 
00338         ret=count;
00339 end:
00340         /* never need to OPENSSL_free x */
00341         if (in != NULL) BIO_free(in);
00342         if (sk != NULL) sk_X509_INFO_free(sk);
00343         return(ret);
00344         }

int MAIN int  ,
char ** 
 


© sourcejam.com 2005-2008