X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fthreads%2Fmttest.c;h=eba7aa8a6ebcc432533ab522a295ad9afddf64a4;hb=1a9d60d2e3b02d5e1954fc71c92bf3a6af691495;hp=be395f2bc4adaccd35a5f568894e334aa9c5164d;hpb=58964a492275ca9a59a0cd9c8155cb2491b4b909;p=oweals%2Fopenssl.git diff --git a/crypto/threads/mttest.c b/crypto/threads/mttest.c index be395f2bc4..eba7aa8a6e 100644 --- a/crypto/threads/mttest.c +++ b/crypto/threads/mttest.c @@ -63,7 +63,7 @@ #ifdef LINUX #include #endif -#ifdef WIN32 +#ifdef OPENSSL_SYS_WIN32 #include #endif #ifdef SOLARIS @@ -74,27 +74,40 @@ #include #include #endif -#include "lhash.h" -#include "crypto.h" -#include "buffer.h" -#include "../e_os.h" -#include "x509.h" -#include "ssl.h" -#include "err.h" - -#ifdef NO_FP_API +#ifdef PTHREADS +#include +#endif +#ifdef OPENSSL_SYS_NETWARE +#if !defined __int64 +# define __int64 long long +#endif +#include +#endif +#include +#include +#include +#include "../../e_os.h" +#include +#include +#include +#include + +#ifdef OPENSSL_NO_FP_API #define APPS_WIN16 -#include "../crypto/buffer/bss_file.c" +#include "../buffer/bss_file.c" #endif -#define TEST_SERVER_CERT "../apps/server.pem" -#define TEST_CLIENT_CERT "../apps/client.pem" +#ifdef OPENSSL_SYS_NETWARE +#define TEST_SERVER_CERT "/openssl/apps/server.pem" +#define TEST_CLIENT_CERT "/openssl/apps/client.pem" +#else +#define TEST_SERVER_CERT "../../apps/server.pem" +#define TEST_CLIENT_CERT "../../apps/client.pem" +#endif #define MAX_THREAD_NUMBER 100 -#ifndef NOPROTO -int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, - int error,char *arg); +int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *xs); void thread_setup(void); void thread_cleanup(void); void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); @@ -103,26 +116,19 @@ void irix_locking_callback(int mode,int type,char *file,int line); void solaris_locking_callback(int mode,int type,char *file,int line); void win32_locking_callback(int mode,int type,char *file,int line); void pthreads_locking_callback(int mode,int type,char *file,int line); +void netware_locking_callback(int mode,int type,char *file,int line); +void beos_locking_callback(int mode,int type,const char *file,int line); unsigned long irix_thread_id(void ); unsigned long solaris_thread_id(void ); unsigned long pthreads_thread_id(void ); +unsigned long netware_thread_id(void ); +unsigned long beos_thread_id(void ); -#else -int MS_CALLBACK verify_callback(); -void thread_setup(); -void thread_cleanup(); -void do_threads(); - -void irix_locking_callback(); -void solaris_locking_callback(); -void win32_locking_callback(); -void pthreads_locking_callback(); - -unsigned long irix_thread_id(); -unsigned long solaris_thread_id(); -unsigned long pthreads_thread_id(); - +#if defined(OPENSSL_SYS_NETWARE) +static MPKMutex *lock_cs; +static MPKSema ThreadSem; +static long *lock_count; #endif BIO *bio_err=NULL; @@ -139,15 +145,10 @@ int number_of_loops=10; int reconnect=0; int cache_stats=0; -#ifndef NOPROTO -int doit(char *ctx[4]); -#else -int doit(); -#endif +static const char rnd_seed[] = "string to make the random number generator think it has entropy"; -static void print_stats(fp,ctx) -FILE *fp; -SSL_CTX *ctx; +int doit(char *ctx[4]); +static void print_stats(FILE *fp, SSL_CTX *ctx) { fprintf(fp,"%4ld items in the session cache\n", SSL_CTX_sess_number(ctx)); @@ -164,7 +165,7 @@ SSL_CTX *ctx; fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx)); } -static void sv_usage() +static void sv_usage(void) { fprintf(stderr,"usage: ssltest [args ...]\n"); fprintf(stderr,"\n"); @@ -182,9 +183,7 @@ static void sv_usage() fprintf(stderr," -ssl3 - just SSLv3n\n"); } -int main(argc, argv) -int argc; -char *argv[]; +int main(int argc, char *argv[]) { char *CApath=NULL,*CAfile=NULL; int badop=0; @@ -197,6 +196,8 @@ char *argv[]; char *ccert=TEST_CLIENT_CERT; SSL_METHOD *ssl_method=SSLv23_method(); + RAND_seed(rnd_seed, sizeof rnd_seed); + if (bio_err == NULL) bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); if (bio_stdout == NULL) @@ -268,10 +269,11 @@ bad: goto end; } - if (cipher == NULL) cipher=getenv("SSL_CIPHER"); + if (cipher == NULL && OPENSSL_issetugid() == 0) + cipher=getenv("SSL_CIPHER"); SSL_load_error_strings(); - SSLeay_add_ssl_algorithms(); + OpenSSL_add_ssl_algorithms(); c_ctx=SSL_CTX_new(ssl_method); s_ctx=SSL_CTX_new(ssl_method); @@ -286,8 +288,15 @@ bad: SSL_CTX_set_session_cache_mode(c_ctx, SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); - SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM); - SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM); + if (!SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM)) + { + ERR_print_errors(bio_err); + } + else if (!SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM)) + { + ERR_print_errors(bio_err); + goto end; + } if (client_auth) { @@ -358,8 +367,7 @@ end: #define C_DONE 1 #define S_DONE 2 -int ndoit(ssl_ctx) -SSL_CTX *ssl_ctx[2]; +int ndoit(SSL_CTX *ssl_ctx[2]) { int i; int ret; @@ -402,11 +410,13 @@ SSL_CTX *ssl_ctx[2]; SSL_free((SSL *)ctx[2]); SSL_free((SSL *)ctx[3]); } +# ifdef OPENSSL_SYS_NETWARE + MPKSemaphoreSignal(ThreadSem); +# endif return(0); } -int doit(ctx) -char *ctx[4]; +int doit(char *ctx[4]) { SSL_CTX *s_ctx,*c_ctx; static char cbuf[200],sbuf[200]; @@ -518,6 +528,7 @@ char *ctx[4]; else { fprintf(stderr,"ERROR in CLIENT\n"); + ERR_print_errors_fp(stderr); return(1); } } @@ -549,6 +560,7 @@ char *ctx[4]; else { fprintf(stderr,"ERROR in CLIENT\n"); + ERR_print_errors_fp(stderr); return(1); } } @@ -644,6 +656,9 @@ char *ctx[4]; } if ((done & S_DONE) && (done & C_DONE)) break; +# if defined(OPENSSL_SYS_NETWARE) + ThreadSwitchWithDelay(); +# endif } SSL_set_shutdown(c_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN); @@ -681,38 +696,39 @@ err: return(0); } -int MS_CALLBACK verify_callback(ok, xs, xi, depth, error, arg) -int ok; -X509 *xs; -X509 *xi; -int depth; -int error; -char *arg; +int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx) { - char buf[256]; + char *s, buf[256]; if (verbose) { - X509_NAME_oneline(X509_get_subject_name(xs),buf,256); - if (ok) - fprintf(stderr,"depth=%d %s\n",depth,buf); - else - fprintf(stderr,"depth=%d error=%d %s\n",depth,error,buf); + s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert), + buf,256); + if (s != NULL) + { + if (ok) + fprintf(stderr,"depth=%d %s\n", + ctx->error_depth,buf); + else + fprintf(stderr,"depth=%d error=%d %s\n", + ctx->error_depth,ctx->error,buf); + } } return(ok); } #define THREAD_STACK_SIZE (16*1024) -#ifdef WIN32 +#ifdef OPENSSL_SYS_WIN32 -static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; +static HANDLE *lock_cs; -void thread_setup() +void thread_setup(void) { int i; - for (i=0; ireferences,c_ctx->references); } -unsigned long solaris_thread_id() +unsigned long solaris_thread_id(void) { unsigned long ret; @@ -915,9 +930,9 @@ unsigned long solaris_thread_id() static usptr_t *arena; -static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; +static usema_t **lock_cs; -void thread_setup() +void thread_setup(void) { int i; char filename[20]; @@ -932,7 +947,8 @@ void thread_setup() arena=usinit(filename); unlink(filename); - for (i=0; ireferences,c_ctx->references); } -unsigned long irix_thread_id() +unsigned long irix_thread_id(void) { unsigned long ret; @@ -1011,14 +1023,16 @@ unsigned long irix_thread_id() #ifdef PTHREADS -static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; -static long lock_count[CRYPTO_NUM_LOCKS]; +static pthread_mutex_t *lock_cs; +static long *lock_count; -void thread_setup() +void thread_setup(void) { int i; - for (i=0; ireferences,c_ctx->references); + s_ctx->references,c_ctx->references); } -unsigned long pthreads_thread_id() +unsigned long pthreads_thread_id(void) { unsigned long ret; @@ -1113,3 +1126,185 @@ unsigned long pthreads_thread_id() +#ifdef OPENSSL_SYS_NETWARE + +void thread_setup(void) +{ + int i; + + lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(MPKMutex)); + lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long)); + for (i=0; ireferences,c_ctx->references); +} + +unsigned long netware_thread_id(void) +{ + unsigned long ret; + + ret=(unsigned long)GetThreadID(); + return(ret); +} +#endif /* NETWARE */ + +#ifdef BEOS_THREADS + +#include + +static BLocker** lock_cs; +static long* lock_count; + +void thread_setup(void) + { + int i; + + lock_cs=(BLocker**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(BLocker*)); + lock_count=(long*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long)); + for (i=0; iLock(); + lock_count[type]++; + } + else + { + lock_cs[type]->Unlock(); + } + } + +void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) + { + SSL_CTX *ssl_ctx[2]; + thread_id thread_ctx[MAX_THREAD_NUMBER]; + int i; + + ssl_ctx[0]=s_ctx; + ssl_ctx[1]=c_ctx; + + for (i=0; ireferences,c_ctx->references); + } + +unsigned long beos_thread_id(void) + { + unsigned long ret; + + ret=(unsigned long)find_thread(NULL); + return(ret); + } + +#endif /* BEOS_THREADS */