66 #ifdef OPENSSL_SYS_WIN32
75 #include <sys/prctl.h>
80 #ifdef OPENSSL_SYS_NETWARE
82 # define __int64 long long
89 #include "../../e_os.h"
95 #ifdef OPENSSL_NO_FP_API
97 #include "../buffer/bss_file.c"
100 #ifdef OPENSSL_SYS_NETWARE
101 #define TEST_SERVER_CERT "/openssl/apps/server.pem"
102 #define TEST_CLIENT_CERT "/openssl/apps/client.pem"
104 #define TEST_SERVER_CERT "../../apps/server.pem"
105 #define TEST_CLIENT_CERT "../../apps/client.pem"
108 #define MAX_THREAD_NUMBER 100
128 #if defined(OPENSSL_SYS_NETWARE)
129 static MPKMutex *lock_cs;
130 static MPKSema ThreadSem;
131 static long *lock_count;
137 static char *cipher=NULL;
148 static const char rnd_seed[] =
"string to make the random number generator think it has entropy";
150 int doit(
char *ctx[4]);
151 static void print_stats(FILE *
fp,
SSL_CTX *ctx)
153 fprintf(fp,
"%4ld items in the session cache\n",
155 fprintf(fp,
"%4d client connects (SSL_connect())\n",
157 fprintf(fp,
"%4d client connects that finished\n",
159 fprintf(fp,
"%4d server connects (SSL_accept())\n",
161 fprintf(fp,
"%4d server connects that finished\n",
168 static void sv_usage(
void)
170 fprintf(stderr,
"usage: ssltest [args ...]\n");
171 fprintf(stderr,
"\n");
172 fprintf(stderr,
" -server_auth - check server certificate\n");
173 fprintf(stderr,
" -client_auth - do client authentication\n");
174 fprintf(stderr,
" -v - more output\n");
175 fprintf(stderr,
" -CApath arg - PEM format directory of CA's\n");
176 fprintf(stderr,
" -CAfile arg - PEM format file of CA's\n");
177 fprintf(stderr,
" -threads arg - number of threads\n");
178 fprintf(stderr,
" -loops arg - number of 'connections', per thread\n");
179 fprintf(stderr,
" -reconnect - reuse session-id's\n");
180 fprintf(stderr,
" -stats - server session-id cache stats\n");
181 fprintf(stderr,
" -cert arg - server certificate/key\n");
182 fprintf(stderr,
" -ccert arg - client certificate/key\n");
183 fprintf(stderr,
" -ssl3 - just SSLv3n\n");
186 int main(
int argc,
char *argv[])
188 char *CApath=NULL,*CAfile=NULL;
203 if (bio_stdout == NULL)
210 if (strcmp(*argv,
"-server_auth") == 0)
212 else if (strcmp(*argv,
"-client_auth") == 0)
214 else if (strcmp(*argv,
"-reconnect") == 0)
216 else if (strcmp(*argv,
"-stats") == 0)
218 else if (strcmp(*argv,
"-ssl3") == 0)
220 else if (strcmp(*argv,
"-ssl2") == 0)
222 else if (strcmp(*argv,
"-CApath") == 0)
224 if (--argc < 1)
goto bad;
227 else if (strcmp(*argv,
"-CAfile") == 0)
229 if (--argc < 1)
goto bad;
232 else if (strcmp(*argv,
"-cert") == 0)
234 if (--argc < 1)
goto bad;
237 else if (strcmp(*argv,
"-ccert") == 0)
239 if (--argc < 1)
goto bad;
242 else if (strcmp(*argv,
"-threads") == 0)
244 if (--argc < 1)
goto bad;
250 else if (strcmp(*argv,
"-loops") == 0)
252 if (--argc < 1)
goto bad;
258 fprintf(stderr,
"unknown option %s\n",*argv);
273 cipher=getenv(
"SSL_CIPHER");
280 if ((c_ctx == NULL) || (s_ctx == NULL))
314 fprintf(stderr,
"SSL_load_verify_locations\n");
321 fprintf(stderr,
"client authentication\n");
328 fprintf(stderr,
"server authentication\n");
340 fprintf(stderr,
"Client SSL_CTX stats then free it\n");
341 print_stats(stderr,c_ctx);
346 fprintf(stderr,
"Server SSL_CTX stats then free it\n");
347 print_stats(stderr,s_ctx);
350 fprintf(stderr,
"-----\n");
351 lh_stats(SSL_CTX_sessions(s_ctx),stderr);
352 fprintf(stderr,
"-----\n");
356 fprintf(stderr,
"-----\n");
359 fprintf(stderr,
"done free\n");
376 ctx[0]=(
char *)ssl_ctx[0];
377 ctx[1]=(
char *)ssl_ctx[1];
381 ctx[2]=(
char *)
SSL_new(ssl_ctx[0]);
382 ctx[3]=(
char *)
SSL_new(ssl_ctx[1]);
402 fprintf(stdout,
"error[%d] %lu - %d\n",
413 # ifdef OPENSSL_SYS_NETWARE
414 MPKSemaphoreSignal(ThreadSem);
422 static char cbuf[200],sbuf[200];
449 if ((s_ssl == NULL) || (c_ssl == NULL))
goto err;
453 if ((s_to_c == NULL) || (c_to_s == NULL))
goto err;
457 if ((c_bio == NULL) || (s_bio == NULL))
goto err;
480 if ((i && s_r) || s_w) do_server=1;
483 if ((i && c_r) || c_w) do_client=1;
488 printf(
"server waiting in SSL_accept - %s\n",
491 printf(
"server:SSL_write()\n");
493 printf(
"server:SSL_read()\n");
499 printf(
"client waiting in SSL_connect - %s\n",
502 printf(
"client:SSL_write()\n");
504 printf(
"client:SSL_read()\n");
507 if (!do_client && !do_server)
509 fprintf(stdout,
"ERROR IN STARTUP\n");
512 if (do_client && !(done &
C_DONE))
516 i=
BIO_write(c_bio,
"hello from client\n",18);
530 fprintf(stderr,
"ERROR in CLIENT\n");
537 fprintf(stderr,
"SSL CLIENT STARTUP FAILED\n");
562 fprintf(stderr,
"ERROR in CLIENT\n");
569 fprintf(stderr,
"SSL CLIENT STARTUP FAILED\n");
576 fprintf(stdout,
"CLIENT:from server:");
577 fwrite(cbuf,1,i,stdout);
584 if (do_server && !(done &
S_DONE))
602 fprintf(stderr,
"ERROR in SERVER\n");
609 fprintf(stderr,
"SSL SERVER STARTUP FAILED\n");
617 fprintf(stdout,
"SERVER:from client:");
618 fwrite(sbuf,1,i,stdout);
625 i=
BIO_write(s_bio,
"hello from server\n",18);
639 fprintf(stderr,
"ERROR in SERVER\n");
646 fprintf(stderr,
"SSL SERVER STARTUP FAILED\n");
658 if ((done & S_DONE) && (done & C_DONE))
break;
659 # if defined(OPENSSL_SYS_NETWARE)
660 ThreadSwitchWithDelay();
668 fprintf(stdout,
"DONE\n");
691 if (c_to_s != NULL)
BIO_free(c_to_s);
692 if (s_to_c != NULL)
BIO_free(s_to_c);
710 fprintf(stderr,
"depth=%d %s\n",
713 fprintf(stderr,
"depth=%d error=%d %s\n",
720 #define THREAD_STACK_SIZE (16*1024)
722 #ifdef OPENSSL_SYS_WIN32
724 static HANDLE *lock_cs;
733 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
746 CloseHandle(lock_cs[i]);
754 WaitForSingleObject(lock_cs[type],INFINITE);
758 ReleaseMutex(lock_cs[type]);
769 SYSTEMTIME start,end;
774 GetSystemTime(&start);
777 thread_handle[i]=CreateThread(NULL,
779 (LPTHREAD_START_ROUTINE)
ndoit,
790 j=(thread_number < (i+50))?(thread_number-i):50;
792 if (WaitForMultipleObjects(j,
793 (CONST HANDLE *)&(thread_handle[i]),TRUE,INFINITE)
796 fprintf(stderr,
"WaitForMultipleObjects failed:%d\n",GetLastError());
802 if (start.wDayOfWeek > end.wDayOfWeek) end.wDayOfWeek+=7;
803 ret=(end.wDayOfWeek-start.wDayOfWeek)*24;
805 ret=(ret+end.wHour-start.wHour)*60;
806 ret=(ret+end.wMinute-start.wMinute)*60;
807 ret=(ret+end.wSecond-start.wSecond);
808 ret+=(end.wMilliseconds-start.wMilliseconds)/1000.0;
810 printf(
"win32 threads done - %.3f seconds\n",ret);
817 static mutex_t *lock_cs;
819 static long *lock_count;
831 mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
844 fprintf(stderr,
"cleanup\n");
849 mutex_destroy(&(lock_cs[i]));
855 fprintf(stderr,
"done cleanup\n");
862 fprintf(stderr,
"thread=%4d mode=%s lock=%s %s:%d\n",
874 if (mode & CRYPTO_LOCK)
881 mutex_lock(&(lock_cs[type]));
887 mutex_unlock(&(lock_cs[type]));
900 thr_setconcurrency(thread_number);
913 thr_join(thread_ctx[i],NULL,NULL);
916 printf(
"solaris threads done (%d,%d)\n",
924 ret=(
unsigned long)thr_self();
932 static usptr_t *arena;
933 static usema_t **lock_cs;
940 strcpy(filename,
"/tmp/mttest.XXXXXX");
943 usconfig(CONF_STHREADIOOFF);
944 usconfig(CONF_STHREADMALLOCOFF);
945 usconfig(CONF_INITUSERS,100);
946 usconfig(CONF_LOCKTYPE,US_DEBUGPLUS);
947 arena=usinit(filename);
953 lock_cs[i]=usnewsema(arena,1);
969 sprintf(buf,
"%2d:",i);
970 usdumpsema(lock_cs[i],stdout,buf);
971 usfreesema(lock_cs[i],arena);
978 if (mode & CRYPTO_LOCK)
980 printf(
"lock %d\n",type);
981 uspsema(lock_cs[type]);
985 printf(
"unlock %d\n",type);
986 usvsema(lock_cs[type]);
1001 thread_ctx[i]=sproc((
void (*)())ndoit,
1002 PR_SADDR|PR_SFDS,(
void *)ssl_ctx);
1005 printf(
"reaping\n");
1011 printf(
"irix threads done (%d,%d)\n",
1019 ret=(
unsigned long)getpid();
1026 static pthread_mutex_t *lock_cs;
1027 static long *lock_count;
1038 pthread_mutex_init(&(lock_cs[i]),NULL);
1050 fprintf(stderr,
"cleanup\n");
1053 pthread_mutex_destroy(&(lock_cs[i]));
1054 fprintf(stderr,
"%8ld:%s\n",lock_count[i],
1060 fprintf(stderr,
"done cleanup\n");
1067 fprintf(stderr,
"thread=%4d mode=%s lock=%s %s:%d\n",
1069 (mode&CRYPTO_LOCK)?
"l":
"u",
1078 if (mode & CRYPTO_LOCK)
1080 pthread_mutex_lock(&(lock_cs[type]));
1085 pthread_mutex_unlock(&(lock_cs[type]));
1103 pthread_create(&(thread_ctx[i]), NULL,
1104 (
void *(*)())ndoit, (
void *)ssl_ctx);
1107 printf(
"reaping\n");
1110 pthread_join(thread_ctx[i],NULL);
1113 printf(
"pthreads threads done (%d,%d)\n",
1121 ret=(
unsigned long)pthread_self();
1129 #ifdef OPENSSL_SYS_NETWARE
1140 lock_cs[i]=MPKMutexAlloc(
"OpenSSL mutex");
1143 ThreadSem = MPKSemaphoreAlloc(
"OpenSSL mttest semaphore", 0 );
1155 fprintf(stdout,
"thread_cleanup\n");
1159 MPKMutexFree(lock_cs[i]);
1165 MPKSemaphoreFree(ThreadSem);
1167 fprintf(stdout,
"done cleanup\n");
1172 if (mode & CRYPTO_LOCK)
1174 MPKMutexLock(lock_cs[type]);
1178 MPKMutexUnlock(lock_cs[type]);
1192 ThreadSwitchWithDelay();
1195 printf(
"reaping\n");
1200 MPKSemaphoreWait(ThreadSem);
1202 printf(
"netware threads done (%d,%d)\n",
1210 ret=(
unsigned long)GetThreadID();
1219 static BLocker** lock_cs;
1220 static long* lock_count;
1243 fprintf(stderr,
"cleanup\n");
1247 fprintf(stderr,
"%8ld:%s\n",lock_count[i],
1253 fprintf(stderr,
"done cleanup\n");
1259 fprintf(stderr,
"thread=%4d mode=%s lock=%s %s:%d\n",
1261 (mode&CRYPTO_LOCK)?
"l":
"u",
1264 if (mode & CRYPTO_LOCK)
1266 lock_cs[
type]->Lock();
1271 lock_cs[
type]->Unlock();
1286 thread_ctx[i] = spawn_thread((thread_func)ndoit,
1287 NULL, B_NORMAL_PRIORITY, (
void *)ssl_ctx);
1288 resume_thread(thread_ctx[i]);
1291 printf(
"waiting...\n");
1295 wait_for_thread(thread_ctx[i], &result);
1298 printf(
"beos threads done (%d,%d)\n",
1306 ret=(
unsigned long)find_thread(NULL);