WinCE patches
[openssl.git] / ssl / ssl_cert.c
index d78584715a7589a175a708b5c2a8a225c25ab04f..b0e20ed9417c4de22c5185da1bdcd286d7c86ccd 100644 (file)
  * OF THE POSSIBILITY OF SUCH DAMAGE.
  * ====================================================================
  */
+/* ====================================================================
+ * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
+ * ECC cipher suite support in OpenSSL originally developed by 
+ * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
+ */
 
 #include <stdio.h>
 
@@ -234,6 +239,15 @@ CERT *ssl_cert_dup(CERT *cert)
        ret->dh_tmp_cb = cert->dh_tmp_cb;
 #endif
 
+#ifndef OPENSSL_NO_ECDH
+       if (cert->ecdh_tmp)
+               {
+               EC_KEY_up_ref(cert->ecdh_tmp);
+               ret->ecdh_tmp = cert->ecdh_tmp;
+               }
+       ret->ecdh_tmp_cb = cert->ecdh_tmp_cb;
+#endif
+
        for (i = 0; i < SSL_PKEY_NUM; i++)
                {
                if (cert->pkeys[i].x509 != NULL)
@@ -268,7 +282,11 @@ CERT *ssl_cert_dup(CERT *cert)
                        case SSL_PKEY_DH_DSA:
                                /* We have a DH key. */
                                break;
-                               
+
+                       case SSL_PKEY_ECC:
+                               /* We have an ECC key */
+                               break;
+
                        default:
                                /* Can't happen. */
                                SSLerr(SSL_F_SSL_CERT_DUP, SSL_R_LIBRARY_BUG);
@@ -294,6 +312,10 @@ err:
        if (ret->dh_tmp != NULL)
                DH_free(ret->dh_tmp);
 #endif
+#ifndef OPENSSL_NO_ECDH
+       if (ret->ecdh_tmp != NULL)
+               EC_KEY_free(ret->ecdh_tmp);
+#endif
 
        for (i = 0; i < SSL_PKEY_NUM; i++)
                {
@@ -333,6 +355,9 @@ void ssl_cert_free(CERT *c)
 #ifndef OPENSSL_NO_DH
        if (c->dh_tmp) DH_free(c->dh_tmp);
 #endif
+#ifndef OPENSSL_NO_ECDH
+       if (c->ecdh_tmp) EC_KEY_free(c->ecdh_tmp);
+#endif
 
        for (i=0; i<SSL_PKEY_NUM; i++)
                {
@@ -439,6 +464,10 @@ void ssl_sess_cert_free(SESS_CERT *sc)
        if (sc->peer_dh_tmp != NULL)
                DH_free(sc->peer_dh_tmp);
 #endif
+#ifndef OPENSSL_NO_ECDH
+       if (sc->peer_ecdh_tmp != NULL)
+               EC_KEY_free(sc->peer_ecdh_tmp);
+#endif
 
        OPENSSL_free(sc);
        }
@@ -483,7 +512,11 @@ int ssl_verify_cert_chain(SSL *s,STACK_OF(X509) *sk)
                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
@@ -769,6 +802,7 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
        ret = 1;
 
 err:   
+       if (d) closedir(d);
        CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
        return ret;
        }
@@ -784,17 +818,37 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
        WIN32_FIND_DATA FindFileData;
        HANDLE hFind;
        int ret = 0;
+#ifdef OPENSSL_SYS_WINCE
+       WCHAR* wdir = NULL;
+#endif
 
        CRYPTO_w_lock(CRYPTO_LOCK_READDIR);
        
+#ifdef OPENSSL_SYS_WINCE
+       /* convert strings to UNICODE */
+       {
+               BOOL result = FALSE;
+               int i;
+               wdir = malloc((strlen(dir)+1)*2);
+               if (wdir == NULL)
+                       goto err_noclose;
+               for (i=0; i<(int)strlen(dir)+1; i++)
+                       wdir[i] = (short)dir[i];
+       }
+#endif
+
+#ifdef OPENSSL_SYS_WINCE
+       hFind = FindFirstFile(wdir, &FindFileData);
+#else
        hFind = FindFirstFile(dir, &FindFileData);
+#endif
        /* 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;
+               goto err_noclose;
                }
        
        do 
@@ -802,7 +856,11 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
                char buf[1024];
                int r;
                
+#ifdef OPENSSL_SYS_WINCE
+               if(strlen(dir)+_tcslen(FindFileData.cFileName)+2 > sizeof buf)
+#else
                if(strlen(dir)+strlen(FindFileData.cFileName)+2 > sizeof buf)
+#endif
                        {
                        SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG);
                        goto err;
@@ -815,10 +873,15 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
                        goto err;
                }
        while (FindNextFile(hFind, &FindFileData) != FALSE);
-       FindClose(hFind);
        ret = 1;
 
-err:   
+err:
+       FindClose(hFind);
+err_noclose:
+#ifdef OPENSSL_SYS_WINCE
+       if (wdir != NULL)
+               free(wdir);
+#endif
        CRYPTO_w_unlock(CRYPTO_LOCK_READDIR);
        return ret;
        }