-static X509 *load_cert(char *file)
-{
- BIO *in;
- X509 *cert;
- if(!(in = BIO_new_file(file, "r"))) return NULL;
- cert = PEM_read_bio_X509(in, NULL, NULL,NULL);
- BIO_free(in);
- return cert;
-}
-
-static EVP_PKEY *load_key(char *file)
-{
- BIO *in;
- EVP_PKEY *key;
- if(!(in = BIO_new_file(file, "r"))) return NULL;
- key = PEM_read_bio_PrivateKey(in, NULL, NULL,NULL);
- BIO_free(in);
- return key;
-}
-
-static STACK_OF(X509) *load_certs(char *file)
-{
- BIO *in;
- int i;
- STACK_OF(X509) *othercerts;
- STACK_OF(X509_INFO) *allcerts;
- X509_INFO *xi;
- if(!(in = BIO_new_file(file, "r"))) return NULL;
- othercerts = sk_X509_new(NULL);
- if(!othercerts) return NULL;
- allcerts = PEM_X509_INFO_read_bio(in, NULL, NULL, NULL);
- for(i = 0; i < sk_X509_INFO_num(allcerts); i++) {
- xi = sk_X509_INFO_value (allcerts, i);
- if (xi->x509) {
- sk_X509_push(othercerts, xi->x509);
- xi->x509 = NULL;
- }
- }
- sk_X509_INFO_pop_free(allcerts, X509_INFO_free);
- BIO_free(in);
- return othercerts;
-}
-
-static X509_STORE *setup_verify(char *CAfile, char *CApath)
-{
- X509_STORE *store;
- X509_LOOKUP *lookup;
- if(!(store = X509_STORE_new())) goto end;
- lookup=X509_STORE_add_lookup(store,X509_LOOKUP_file());
- if (lookup == NULL) goto end;
- if (CAfile) {
- if(!X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM)) {
- BIO_printf(bio_err, "Error loading file %s\n", CAfile);
- goto end;
- }
- } else X509_LOOKUP_load_file(lookup,NULL,X509_FILETYPE_DEFAULT);
-
- lookup=X509_STORE_add_lookup(store,X509_LOOKUP_hash_dir());
- if (lookup == NULL) goto end;
- if (CApath) {
- if(!X509_LOOKUP_add_dir(lookup,CApath,X509_FILETYPE_PEM)) {
- BIO_printf(bio_err, "Error loading directory %s\n", CApath);
- goto end;
- }
- } else X509_LOOKUP_add_dir(lookup,NULL,X509_FILETYPE_DEFAULT);
-
- ERR_clear_error();
- return store;
- end:
- X509_STORE_free(store);
- return NULL;
-}
-
-int save_certs(char *signerfile, STACK_OF(X509) *signers)
-{