diff options
Diffstat (limited to 'src/lib/libcrypto/threads/mttest.c')
-rw-r--r-- | src/lib/libcrypto/threads/mttest.c | 122 |
1 files changed, 80 insertions, 42 deletions
diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c index 142623edda..24713a3157 100644 --- a/src/lib/libcrypto/threads/mttest.c +++ b/src/lib/libcrypto/threads/mttest.c | |||
@@ -74,26 +74,29 @@ | |||
74 | #include <ulocks.h> | 74 | #include <ulocks.h> |
75 | #include <sys/prctl.h> | 75 | #include <sys/prctl.h> |
76 | #endif | 76 | #endif |
77 | #ifdef PTHREADS | ||
78 | #include <pthread.h> | ||
79 | #endif | ||
77 | #include <openssl/lhash.h> | 80 | #include <openssl/lhash.h> |
78 | #include <openssl/crypto.h> | 81 | #include <openssl/crypto.h> |
79 | #include <openssl/buffer.h> | 82 | #include <openssl/buffer.h> |
80 | #include "../e_os.h" | 83 | #include "../../e_os.h" |
81 | #include <openssl/x509.h> | 84 | #include <openssl/x509.h> |
82 | #include <openssl/ssl.h> | 85 | #include <openssl/ssl.h> |
83 | #include <openssl/err.h> | 86 | #include <openssl/err.h> |
87 | #include <openssl/rand.h> | ||
84 | 88 | ||
85 | #ifdef NO_FP_API | 89 | #ifdef NO_FP_API |
86 | #define APPS_WIN16 | 90 | #define APPS_WIN16 |
87 | #include "../crypto/buffer/bss_file.c" | 91 | #include "../buffer/bss_file.c" |
88 | #endif | 92 | #endif |
89 | 93 | ||
90 | #define TEST_SERVER_CERT "../apps/server.pem" | 94 | #define TEST_SERVER_CERT "../../apps/server.pem" |
91 | #define TEST_CLIENT_CERT "../apps/client.pem" | 95 | #define TEST_CLIENT_CERT "../../apps/client.pem" |
92 | 96 | ||
93 | #define MAX_THREAD_NUMBER 100 | 97 | #define MAX_THREAD_NUMBER 100 |
94 | 98 | ||
95 | int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, | 99 | int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *xs); |
96 | int error,char *arg); | ||
97 | void thread_setup(void); | 100 | void thread_setup(void); |
98 | void thread_cleanup(void); | 101 | void thread_cleanup(void); |
99 | void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); | 102 | void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx); |
@@ -121,6 +124,8 @@ int number_of_loops=10; | |||
121 | int reconnect=0; | 124 | int reconnect=0; |
122 | int cache_stats=0; | 125 | int cache_stats=0; |
123 | 126 | ||
127 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; | ||
128 | |||
124 | int doit(char *ctx[4]); | 129 | int doit(char *ctx[4]); |
125 | static void print_stats(FILE *fp, SSL_CTX *ctx) | 130 | static void print_stats(FILE *fp, SSL_CTX *ctx) |
126 | { | 131 | { |
@@ -170,6 +175,8 @@ int main(int argc, char *argv[]) | |||
170 | char *ccert=TEST_CLIENT_CERT; | 175 | char *ccert=TEST_CLIENT_CERT; |
171 | SSL_METHOD *ssl_method=SSLv23_method(); | 176 | SSL_METHOD *ssl_method=SSLv23_method(); |
172 | 177 | ||
178 | RAND_seed(rnd_seed, sizeof rnd_seed); | ||
179 | |||
173 | if (bio_err == NULL) | 180 | if (bio_err == NULL) |
174 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | 181 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); |
175 | if (bio_stdout == NULL) | 182 | if (bio_stdout == NULL) |
@@ -244,7 +251,7 @@ bad: | |||
244 | if (cipher == NULL) cipher=getenv("SSL_CIPHER"); | 251 | if (cipher == NULL) cipher=getenv("SSL_CIPHER"); |
245 | 252 | ||
246 | SSL_load_error_strings(); | 253 | SSL_load_error_strings(); |
247 | SSLeay_add_ssl_algorithms(); | 254 | OpenSSL_add_ssl_algorithms(); |
248 | 255 | ||
249 | c_ctx=SSL_CTX_new(ssl_method); | 256 | c_ctx=SSL_CTX_new(ssl_method); |
250 | s_ctx=SSL_CTX_new(ssl_method); | 257 | s_ctx=SSL_CTX_new(ssl_method); |
@@ -259,8 +266,15 @@ bad: | |||
259 | SSL_CTX_set_session_cache_mode(c_ctx, | 266 | SSL_CTX_set_session_cache_mode(c_ctx, |
260 | SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); | 267 | SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER); |
261 | 268 | ||
262 | SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM); | 269 | if (!SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM)) |
263 | SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM); | 270 | { |
271 | ERR_print_errors(bio_err); | ||
272 | } | ||
273 | else if (!SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM)) | ||
274 | { | ||
275 | ERR_print_errors(bio_err); | ||
276 | goto end; | ||
277 | } | ||
264 | 278 | ||
265 | if (client_auth) | 279 | if (client_auth) |
266 | { | 280 | { |
@@ -489,6 +503,7 @@ int doit(char *ctx[4]) | |||
489 | else | 503 | else |
490 | { | 504 | { |
491 | fprintf(stderr,"ERROR in CLIENT\n"); | 505 | fprintf(stderr,"ERROR in CLIENT\n"); |
506 | ERR_print_errors_fp(stderr); | ||
492 | return(1); | 507 | return(1); |
493 | } | 508 | } |
494 | } | 509 | } |
@@ -520,6 +535,7 @@ int doit(char *ctx[4]) | |||
520 | else | 535 | else |
521 | { | 536 | { |
522 | fprintf(stderr,"ERROR in CLIENT\n"); | 537 | fprintf(stderr,"ERROR in CLIENT\n"); |
538 | ERR_print_errors_fp(stderr); | ||
523 | return(1); | 539 | return(1); |
524 | } | 540 | } |
525 | } | 541 | } |
@@ -652,18 +668,23 @@ err: | |||
652 | return(0); | 668 | return(0); |
653 | } | 669 | } |
654 | 670 | ||
655 | int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, | 671 | int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx) |
656 | int error, char *arg) | ||
657 | { | 672 | { |
658 | char buf[256]; | 673 | char *s, buf[256]; |
659 | 674 | ||
660 | if (verbose) | 675 | if (verbose) |
661 | { | 676 | { |
662 | X509_NAME_oneline(X509_get_subject_name(xs),buf,256); | 677 | s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert), |
663 | if (ok) | 678 | buf,256); |
664 | fprintf(stderr,"depth=%d %s\n",depth,buf); | 679 | if (s != NULL) |
665 | else | 680 | { |
666 | fprintf(stderr,"depth=%d error=%d %s\n",depth,error,buf); | 681 | if (ok) |
682 | fprintf(stderr,"depth=%d %s\n", | ||
683 | ctx->error_depth,buf); | ||
684 | else | ||
685 | fprintf(stderr,"depth=%d error=%d %s\n", | ||
686 | ctx->error_depth,ctx->error,buf); | ||
687 | } | ||
667 | } | 688 | } |
668 | return(ok); | 689 | return(ok); |
669 | } | 690 | } |
@@ -672,13 +693,14 @@ int MS_CALLBACK verify_callback(int ok, X509 *xs, X509 *xi, int depth, | |||
672 | 693 | ||
673 | #ifdef WIN32 | 694 | #ifdef WIN32 |
674 | 695 | ||
675 | static HANDLE lock_cs[CRYPTO_NUM_LOCKS]; | 696 | static HANDLE *lock_cs; |
676 | 697 | ||
677 | void thread_setup(void) | 698 | void thread_setup(void) |
678 | { | 699 | { |
679 | int i; | 700 | int i; |
680 | 701 | ||
681 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 702 | lock_cs=Malloc(CRYPTO_num_locks() * sizeof(HANDLE)); |
703 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
682 | { | 704 | { |
683 | lock_cs[i]=CreateMutex(NULL,FALSE,NULL); | 705 | lock_cs[i]=CreateMutex(NULL,FALSE,NULL); |
684 | } | 706 | } |
@@ -692,8 +714,9 @@ void thread_cleanup(void) | |||
692 | int i; | 714 | int i; |
693 | 715 | ||
694 | CRYPTO_set_locking_callback(NULL); | 716 | CRYPTO_set_locking_callback(NULL); |
695 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 717 | for (i=0; i<CRYPTO_num_locks(); i++) |
696 | CloseHandle(lock_cs[i]); | 718 | CloseHandle(lock_cs[i]); |
719 | Free(lock_cs); | ||
697 | } | 720 | } |
698 | 721 | ||
699 | void win32_locking_callback(int mode, int type, char *file, int line) | 722 | void win32_locking_callback(int mode, int type, char *file, int line) |
@@ -763,15 +786,17 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) | |||
763 | 786 | ||
764 | #ifdef SOLARIS | 787 | #ifdef SOLARIS |
765 | 788 | ||
766 | static mutex_t lock_cs[CRYPTO_NUM_LOCKS]; | 789 | static mutex_t *lock_cs; |
767 | /*static rwlock_t lock_cs[CRYPTO_NUM_LOCKS]; */ | 790 | /*static rwlock_t *lock_cs; */ |
768 | static long lock_count[CRYPTO_NUM_LOCKS]; | 791 | static long *lock_count; |
769 | 792 | ||
770 | void thread_setup(void) | 793 | void thread_setup(void) |
771 | { | 794 | { |
772 | int i; | 795 | int i; |
773 | 796 | ||
774 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 797 | lock_cs=Malloc(CRYPTO_num_locks() * sizeof(mutex_t)); |
798 | lock_count=Malloc(CRYPTO_num_locks() * sizeof(long)); | ||
799 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
775 | { | 800 | { |
776 | lock_count[i]=0; | 801 | lock_count[i]=0; |
777 | /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */ | 802 | /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */ |
@@ -787,31 +812,37 @@ void thread_cleanup(void) | |||
787 | int i; | 812 | int i; |
788 | 813 | ||
789 | CRYPTO_set_locking_callback(NULL); | 814 | CRYPTO_set_locking_callback(NULL); |
790 | fprintf(stderr,"cleanup\n"); | 815 | |
791 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 816 | fprintf(stderr,"cleanup\n"); |
817 | |||
818 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
792 | { | 819 | { |
793 | /* rwlock_destroy(&(lock_cs[i])); */ | 820 | /* rwlock_destroy(&(lock_cs[i])); */ |
794 | mutex_destroy(&(lock_cs[i])); | 821 | mutex_destroy(&(lock_cs[i])); |
795 | fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i)); | 822 | fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i)); |
796 | } | 823 | } |
797 | fprintf(stderr,"done cleanup\n"); | 824 | Free(lock_cs); |
825 | Free(lock_count); | ||
826 | |||
827 | fprintf(stderr,"done cleanup\n"); | ||
828 | |||
798 | } | 829 | } |
799 | 830 | ||
800 | void solaris_locking_callback(int mode, int type, char *file, int line) | 831 | void solaris_locking_callback(int mode, int type, char *file, int line) |
801 | { | 832 | { |
802 | #ifdef undef | 833 | #ifdef undef |
803 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", | 834 | fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n", |
804 | CRYPTO_thread_id(), | 835 | CRYPTO_thread_id(), |
805 | (mode&CRYPTO_LOCK)?"l":"u", | 836 | (mode&CRYPTO_LOCK)?"l":"u", |
806 | (type&CRYPTO_READ)?"r":"w",file,line); | 837 | (type&CRYPTO_READ)?"r":"w",file,line); |
807 | #endif | 838 | #endif |
808 | 839 | ||
809 | /* | 840 | /* |
810 | if (CRYPTO_LOCK_SSL_CERT == type) | 841 | if (CRYPTO_LOCK_SSL_CERT == type) |
811 | fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", | 842 | fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", |
812 | CRYPTO_thread_id(), | 843 | CRYPTO_thread_id(), |
813 | mode,file,line); | 844 | mode,file,line); |
814 | */ | 845 | */ |
815 | if (mode & CRYPTO_LOCK) | 846 | if (mode & CRYPTO_LOCK) |
816 | { | 847 | { |
817 | /* if (mode & CRYPTO_READ) | 848 | /* if (mode & CRYPTO_READ) |
@@ -871,7 +902,7 @@ unsigned long solaris_thread_id(void) | |||
871 | 902 | ||
872 | 903 | ||
873 | static usptr_t *arena; | 904 | static usptr_t *arena; |
874 | static usema_t *lock_cs[CRYPTO_NUM_LOCKS]; | 905 | static usema_t **lock_cs; |
875 | 906 | ||
876 | void thread_setup(void) | 907 | void thread_setup(void) |
877 | { | 908 | { |
@@ -888,7 +919,8 @@ void thread_setup(void) | |||
888 | arena=usinit(filename); | 919 | arena=usinit(filename); |
889 | unlink(filename); | 920 | unlink(filename); |
890 | 921 | ||
891 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 922 | lock_cs=Malloc(CRYPTO_num_locks() * sizeof(usema_t *)); |
923 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
892 | { | 924 | { |
893 | lock_cs[i]=usnewsema(arena,1); | 925 | lock_cs[i]=usnewsema(arena,1); |
894 | } | 926 | } |
@@ -902,7 +934,7 @@ void thread_cleanup(void) | |||
902 | int i; | 934 | int i; |
903 | 935 | ||
904 | CRYPTO_set_locking_callback(NULL); | 936 | CRYPTO_set_locking_callback(NULL); |
905 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 937 | for (i=0; i<CRYPTO_num_locks(); i++) |
906 | { | 938 | { |
907 | char buf[10]; | 939 | char buf[10]; |
908 | 940 | ||
@@ -910,6 +942,7 @@ void thread_cleanup(void) | |||
910 | usdumpsema(lock_cs[i],stdout,buf); | 942 | usdumpsema(lock_cs[i],stdout,buf); |
911 | usfreesema(lock_cs[i],arena); | 943 | usfreesema(lock_cs[i],arena); |
912 | } | 944 | } |
945 | Free(lock_cs); | ||
913 | } | 946 | } |
914 | 947 | ||
915 | void irix_locking_callback(int mode, int type, char *file, int line) | 948 | void irix_locking_callback(int mode, int type, char *file, int line) |
@@ -962,14 +995,16 @@ unsigned long irix_thread_id(void) | |||
962 | 995 | ||
963 | #ifdef PTHREADS | 996 | #ifdef PTHREADS |
964 | 997 | ||
965 | static pthread_mutex_t lock_cs[CRYPTO_NUM_LOCKS]; | 998 | static pthread_mutex_t *lock_cs; |
966 | static long lock_count[CRYPTO_NUM_LOCKS]; | 999 | static long *lock_count; |
967 | 1000 | ||
968 | void thread_setup(void) | 1001 | void thread_setup(void) |
969 | { | 1002 | { |
970 | int i; | 1003 | int i; |
971 | 1004 | ||
972 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 1005 | lock_cs=Malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); |
1006 | lock_count=Malloc(CRYPTO_num_locks() * sizeof(long)); | ||
1007 | for (i=0; i<CRYPTO_num_locks(); i++) | ||
973 | { | 1008 | { |
974 | lock_count[i]=0; | 1009 | lock_count[i]=0; |
975 | pthread_mutex_init(&(lock_cs[i]),NULL); | 1010 | pthread_mutex_init(&(lock_cs[i]),NULL); |
@@ -985,12 +1020,15 @@ void thread_cleanup(void) | |||
985 | 1020 | ||
986 | CRYPTO_set_locking_callback(NULL); | 1021 | CRYPTO_set_locking_callback(NULL); |
987 | fprintf(stderr,"cleanup\n"); | 1022 | fprintf(stderr,"cleanup\n"); |
988 | for (i=0; i<CRYPTO_NUM_LOCKS; i++) | 1023 | for (i=0; i<CRYPTO_num_locks(); i++) |
989 | { | 1024 | { |
990 | pthread_mutex_destroy(&(lock_cs[i])); | 1025 | pthread_mutex_destroy(&(lock_cs[i])); |
991 | fprintf(stderr,"%8ld:%s\n",lock_count[i], | 1026 | fprintf(stderr,"%8ld:%s\n",lock_count[i], |
992 | CRYPTO_get_lock_name(i)); | 1027 | CRYPTO_get_lock_name(i)); |
993 | } | 1028 | } |
1029 | Free(lock_cs); | ||
1030 | Free(lock_count); | ||
1031 | |||
994 | fprintf(stderr,"done cleanup\n"); | 1032 | fprintf(stderr,"done cleanup\n"); |
995 | } | 1033 | } |
996 | 1034 | ||
@@ -1045,7 +1083,7 @@ void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx) | |||
1045 | } | 1083 | } |
1046 | 1084 | ||
1047 | printf("pthreads threads done (%d,%d)\n", | 1085 | printf("pthreads threads done (%d,%d)\n", |
1048 | s_ctx->references,c_ctx->references); | 1086 | s_ctx->references,c_ctx->references); |
1049 | } | 1087 | } |
1050 | 1088 | ||
1051 | unsigned long pthreads_thread_id(void) | 1089 | unsigned long pthreads_thread_id(void) |