Add 'void *' argument to app_verify_callback.
[openssl.git] / ssl / ssl_cert.c
index 7f4739d10880fbf7d2d806cdf30f541681ff4b91..1a873d2cb73b131fd24877a90da027716a060726 100644 (file)
 
 #include <stdio.h>
 
-#include "openssl/e_os.h"
+#include "e_os.h"
 #ifndef NO_SYS_TYPES_H
 # include <sys/types.h>
 #endif
 #include <dirent.h>
 #endif
 
+#if defined(WIN32)
+#include <windows.h>
+#endif
+
 #ifdef NeXT
 #include <sys/dir.h>
 #define dirent direct
@@ -190,8 +194,8 @@ CERT *ssl_cert_dup(CERT *cert)
 #ifndef OPENSSL_NO_RSA
        if (cert->rsa_tmp != NULL)
                {
+               RSA_up_ref(cert->rsa_tmp);
                ret->rsa_tmp = cert->rsa_tmp;
-               CRYPTO_add(&ret->rsa_tmp->references, 1, CRYPTO_LOCK_RSA);
                }
        ret->rsa_tmp_cb = cert->rsa_tmp_cb;
 #endif
@@ -455,7 +459,11 @@ int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
                return(0);
 
        x=sk_X509_value(sk,0);
-       X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk);
+       if(!X509_STORE_CTX_init(&ctx,s->ctx->cert_store,x,sk))
+               {
+               SSLerr(SSL_F_SSL_VERIFY_CERT_CHAIN,ERR_R_X509_LIB);
+               return(0);
+               }
        if (SSL_get_verify_depth(s) >= 0)
                X509_STORE_CTX_set_depth(&ctx, SSL_get_verify_depth(s));
        X509_STORE_CTX_set_ex_data(&ctx,SSL_get_ex_data_X509_STORE_CTX_idx(),s);
@@ -471,8 +479,15 @@ int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
 
        X509_STORE_CTX_purpose_inherit(&ctx, i, s->purpose, s->trust);
 
+       if (s->verify_callback)
+               X509_STORE_CTX_set_verify_cb(&ctx, s->verify_callback);
+
        if (s->ctx->app_verify_callback != NULL)
+#if 1 /* new with OpenSSL 0.9.7 */
+               i=s->ctx->app_verify_callback(&ctx, s->ctx->app_verify_arg); 
+#else
                i=s->ctx->app_verify_callback(&ctx); /* should pass app_verify_arg */
+#endif
        else
                {
 #ifndef OPENSSL_NO_X509_VERIFY
@@ -717,7 +732,7 @@ err:
 
 #ifndef OPENSSL_SYS_WIN32
 #ifndef OPENSSL_SYS_VMS                /* XXXX This may be fixed in the future */
-#ifndef MAC_OS_pre_X
+#ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! */
 
 int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
                                       const char *dir)
@@ -764,4 +779,52 @@ err:
 
 #endif
 #endif
+
+#else
+
+int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
+                                      const char *dir)
+       {
+       WIN32_FIND_DATA FindFileData;
+       HANDLE hFind;
+       int ret = 0;
+
+       CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
+       
+       hFind = FindFirstFile(dir, &FindFileData);
+       /* Note that a side effect is that the CAs will be sorted by name */
+       if(hFind == INVALID_HANDLE_VALUE)
+               {
+               SYSerr(SYS_F_OPENDIR, get_last_sys_error());
+               ERR_add_error_data(3, "opendir('", dir, "')");
+               SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK, ERR_R_SYS_LIB);
+               goto err;
+               }
+       
+       do 
+               {
+               char buf[1024];
+               int r;
+               
+               if(strlen(dir)+strlen(FindFileData.cFileName)+2 > sizeof buf)
+                       {
+                       SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
+                       goto err;
+                       }
+               
+               r = BIO_snprintf(buf,sizeof buf,"%s/%s",dir,FindFileData.cFileName);
+               if (r <= 0 || r >= sizeof buf)
+                       goto err;
+               if(!SSL_add_file_cert_subjects_to_stack(stack,buf))
+                       goto err;
+               }
+       while (FindNextFile(hFind, &FindFileData) != FALSE);
+       FindClose(hFind);
+       ret = 1;
+
+err:   
+       CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
+       return ret;
+       }
+
 #endif