56 |
|
* [including the GNU Public Licence.] |
57 |
|
*/ |
58 |
|
|
59 |
– |
#include <stdio.h> |
59 |
|
#include <stdlib.h> |
60 |
|
#include <string.h> |
61 |
|
#include <errno.h> |
85 |
|
#include <openssl/lhash.h> |
86 |
|
#include <openssl/crypto.h> |
87 |
|
#include <openssl/buffer.h> |
89 |
– |
#include "../../e_os.h" |
88 |
|
#include <openssl/x509.h> |
89 |
|
#include <openssl/ssl.h> |
90 |
|
#include <openssl/err.h> |
91 |
|
#include <openssl/rand.h> |
92 |
|
|
95 |
– |
#ifdef OPENSSL_NO_FP_API |
96 |
– |
# define APPS_WIN16 |
97 |
– |
# include "../buffer/bss_file.c" |
98 |
– |
#endif |
99 |
– |
|
93 |
|
#ifdef OPENSSL_SYS_NETWARE |
94 |
|
# define TEST_SERVER_CERT "/openssl/apps/server.pem" |
95 |
|
# define TEST_CLIENT_CERT "/openssl/apps/client.pem" |
100 |
|
|
101 |
|
#define MAX_THREAD_NUMBER 100 |
102 |
|
|
103 |
< |
int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *xs); |
103 |
> |
int verify_callback(int ok, X509_STORE_CTX *xs); |
104 |
|
void thread_setup(void); |
105 |
|
void thread_cleanup(void); |
106 |
|
void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx); |
107 |
|
|
108 |
< |
void irix_locking_callback(int mode, int type, char *file, int line); |
109 |
< |
void solaris_locking_callback(int mode, int type, char *file, int line); |
110 |
< |
void win32_locking_callback(int mode, int type, char *file, int line); |
111 |
< |
void pthreads_locking_callback(int mode, int type, char *file, int line); |
112 |
< |
void netware_locking_callback(int mode, int type, char *file, int line); |
108 |
> |
void irix_locking_callback(int mode, int type, const char *file, int line); |
109 |
> |
void solaris_locking_callback(int mode, int type, const char *file, int line); |
110 |
> |
void win32_locking_callback(int mode, int type, const char *file, int line); |
111 |
> |
void pthreads_locking_callback(int mode, int type, const char *file, int line); |
112 |
> |
void netware_locking_callback(int mode, int type, const char *file, int line); |
113 |
|
void beos_locking_callback(int mode, int type, const char *file, int line); |
114 |
|
|
115 |
< |
unsigned long irix_thread_id(void); |
116 |
< |
unsigned long solaris_thread_id(void); |
117 |
< |
unsigned long pthreads_thread_id(void); |
118 |
< |
unsigned long netware_thread_id(void); |
119 |
< |
unsigned long beos_thread_id(void); |
115 |
> |
void irix_thread_id(CRYPTO_THREADID *tid); |
116 |
> |
void solaris_thread_id(CRYPTO_THREADID *tid); |
117 |
> |
void pthreads_thread_id(CRYPTO_THREADID *tid); |
118 |
> |
void netware_thread_id(CRYPTO_THREADID *tid); |
119 |
> |
void beos_thread_id(CRYPTO_THREADID *tid); |
120 |
|
|
121 |
|
#if defined(OPENSSL_SYS_NETWARE) |
122 |
|
static MPKMutex *lock_cs; |
142 |
|
"string to make the random number generator think it has entropy"; |
143 |
|
|
144 |
|
int doit(char *ctx[4]); |
145 |
< |
static void print_stats(FILE *fp, SSL_CTX *ctx) |
145 |
> |
static void print_stats(BIO *bio, SSL_CTX *ctx) |
146 |
|
{ |
147 |
< |
fprintf(fp, "%4ld items in the session cache\n", |
148 |
< |
SSL_CTX_sess_number(ctx)); |
149 |
< |
fprintf(fp, "%4d client connects (SSL_connect())\n", |
150 |
< |
SSL_CTX_sess_connect(ctx)); |
151 |
< |
fprintf(fp, "%4d client connects that finished\n", |
152 |
< |
SSL_CTX_sess_connect_good(ctx)); |
153 |
< |
fprintf(fp, "%4d server connects (SSL_accept())\n", |
154 |
< |
SSL_CTX_sess_accept(ctx)); |
155 |
< |
fprintf(fp, "%4d server connects that finished\n", |
156 |
< |
SSL_CTX_sess_accept_good(ctx)); |
157 |
< |
fprintf(fp, "%4d session cache hits\n", SSL_CTX_sess_hits(ctx)); |
158 |
< |
fprintf(fp, "%4d session cache misses\n", SSL_CTX_sess_misses(ctx)); |
159 |
< |
fprintf(fp, "%4d session cache timeouts\n", SSL_CTX_sess_timeouts(ctx)); |
147 |
> |
BIO_printf(bio, "%4ld items in the session cache\n", |
148 |
> |
SSL_CTX_sess_number(ctx)); |
149 |
> |
BIO_printf(bio, "%4d client connects (SSL_connect())\n", |
150 |
> |
SSL_CTX_sess_connect(ctx)); |
151 |
> |
BIO_printf(bio, "%4d client connects that finished\n", |
152 |
> |
SSL_CTX_sess_connect_good(ctx)); |
153 |
> |
BIO_printf(bio, "%4d server connects (SSL_accept())\n", |
154 |
> |
SSL_CTX_sess_accept(ctx)); |
155 |
> |
BIO_printf(bio, "%4d server connects that finished\n", |
156 |
> |
SSL_CTX_sess_accept_good(ctx)); |
157 |
> |
BIO_printf(bio, "%4d session cache hits\n", SSL_CTX_sess_hits(ctx)); |
158 |
> |
BIO_printf(bio, "%4d session cache misses\n", SSL_CTX_sess_misses(ctx)); |
159 |
> |
BIO_printf(bio, "%4d session cache timeouts\n", SSL_CTX_sess_timeouts(ctx)); |
160 |
|
} |
161 |
|
|
162 |
|
static void sv_usage(void) |
163 |
|
{ |
164 |
< |
fprintf(stderr, "usage: ssltest [args ...]\n"); |
165 |
< |
fprintf(stderr, "\n"); |
166 |
< |
fprintf(stderr, " -server_auth - check server certificate\n"); |
167 |
< |
fprintf(stderr, " -client_auth - do client authentication\n"); |
168 |
< |
fprintf(stderr, " -v - more output\n"); |
169 |
< |
fprintf(stderr, " -CApath arg - PEM format directory of CA's\n"); |
170 |
< |
fprintf(stderr, " -CAfile arg - PEM format file of CA's\n"); |
171 |
< |
fprintf(stderr, " -threads arg - number of threads\n"); |
172 |
< |
fprintf(stderr, " -loops arg - number of 'connections', per thread\n"); |
173 |
< |
fprintf(stderr, " -reconnect - reuse session-id's\n"); |
174 |
< |
fprintf(stderr, " -stats - server session-id cache stats\n"); |
175 |
< |
fprintf(stderr, " -cert arg - server certificate/key\n"); |
176 |
< |
fprintf(stderr, " -ccert arg - client certificate/key\n"); |
177 |
< |
fprintf(stderr, " -ssl3 - just SSLv3n\n"); |
164 |
> |
BIO_printf(bio_err, "usage: ssltest [args ...]\n"); |
165 |
> |
BIO_printf(bio_err, "\n"); |
166 |
> |
BIO_printf(bio_err, " -server_auth - check server certificate\n"); |
167 |
> |
BIO_printf(bio_err, " -client_auth - do client authentication\n"); |
168 |
> |
BIO_printf(bio_err, " -v - more output\n"); |
169 |
> |
BIO_printf(bio_err, " -CApath arg - PEM format directory of CA's\n"); |
170 |
> |
BIO_printf(bio_err, " -CAfile arg - PEM format file of CA's\n"); |
171 |
> |
BIO_printf(bio_err, " -threads arg - number of threads\n"); |
172 |
> |
BIO_printf(bio_err, " -loops arg - number of 'connections', per thread\n"); |
173 |
> |
BIO_printf(bio_err, " -reconnect - reuse session-id's\n"); |
174 |
> |
BIO_printf(bio_err, " -stats - server session-id cache stats\n"); |
175 |
> |
BIO_printf(bio_err, " -cert arg - server certificate/key\n"); |
176 |
> |
BIO_printf(bio_err, " -ccert arg - client certificate/key\n"); |
177 |
> |
BIO_printf(bio_err, " -ssl3 - just SSLv3n\n"); |
178 |
|
} |
179 |
|
|
180 |
|
int main(int argc, char *argv[]) |
188 |
|
SSL_CTX *c_ctx = NULL; |
189 |
|
char *scert = TEST_SERVER_CERT; |
190 |
|
char *ccert = TEST_CLIENT_CERT; |
191 |
< |
SSL_METHOD *ssl_method = SSLv23_method(); |
191 |
> |
const SSL_METHOD *ssl_method = SSLv23_method(); |
192 |
|
|
193 |
|
RAND_seed(rnd_seed, sizeof rnd_seed); |
194 |
|
|
195 |
|
if (bio_err == NULL) |
196 |
< |
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); |
196 |
> |
bio_err = BIO_new_fd(2, BIO_NOCLOSE); |
197 |
|
if (bio_stdout == NULL) |
198 |
< |
bio_stdout = BIO_new_fp(stdout, BIO_NOCLOSE); |
198 |
> |
bio_stdout = BIO_new_fd(1, BIO_NOCLOSE); |
199 |
|
argc--; |
200 |
|
argv++; |
201 |
|
|
243 |
|
if (number_of_loops == 0) |
244 |
|
number_of_loops = 1; |
245 |
|
} else { |
246 |
< |
fprintf(stderr, "unknown option %s\n", *argv); |
246 |
> |
BIO_printf(bio_err, "unknown option %s\n", *argv); |
247 |
|
badop = 1; |
248 |
|
break; |
249 |
|
} |
277 |
|
SSL_SESS_CACHE_SERVER); |
278 |
|
|
279 |
|
if (!SSL_CTX_use_certificate_file(s_ctx, scert, SSL_FILETYPE_PEM)) { |
280 |
+ |
BIO_printf(bio_err, "SSL_CTX_use_certificate_file (%s)\n", scert); |
281 |
|
ERR_print_errors(bio_err); |
282 |
+ |
goto end; |
283 |
|
} else |
284 |
|
if (!SSL_CTX_use_RSAPrivateKey_file(s_ctx, scert, SSL_FILETYPE_PEM)) { |
285 |
+ |
BIO_printf(bio_err, "SSL_CTX_use_RSAPrivateKey_file (%s)\n", scert); |
286 |
|
ERR_print_errors(bio_err); |
287 |
|
goto end; |
288 |
|
} |
296 |
|
(!SSL_CTX_set_default_verify_paths(s_ctx)) || |
297 |
|
(!SSL_CTX_load_verify_locations(c_ctx, CAfile, CApath)) || |
298 |
|
(!SSL_CTX_set_default_verify_paths(c_ctx))) { |
299 |
< |
fprintf(stderr, "SSL_load_verify_locations\n"); |
299 |
> |
BIO_printf(bio_err, "SSL_load_verify_locations\n"); |
300 |
|
ERR_print_errors(bio_err); |
301 |
|
goto end; |
302 |
|
} |
303 |
|
|
304 |
|
if (client_auth) { |
305 |
< |
fprintf(stderr, "client authentication\n"); |
305 |
> |
BIO_printf(bio_err, "client authentication\n"); |
306 |
|
SSL_CTX_set_verify(s_ctx, |
307 |
|
SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, |
308 |
|
verify_callback); |
309 |
|
} |
310 |
|
if (server_auth) { |
311 |
< |
fprintf(stderr, "server authentication\n"); |
311 |
> |
BIO_printf(bio_err, "server authentication\n"); |
312 |
|
SSL_CTX_set_verify(c_ctx, SSL_VERIFY_PEER, verify_callback); |
313 |
|
} |
314 |
|
|
318 |
|
end: |
319 |
|
|
320 |
|
if (c_ctx != NULL) { |
321 |
< |
fprintf(stderr, "Client SSL_CTX stats then free it\n"); |
322 |
< |
print_stats(stderr, c_ctx); |
321 |
> |
BIO_printf(bio_err, "Client SSL_CTX stats then free it\n"); |
322 |
> |
print_stats(bio_err, c_ctx); |
323 |
|
SSL_CTX_free(c_ctx); |
324 |
|
} |
325 |
|
if (s_ctx != NULL) { |
326 |
< |
fprintf(stderr, "Server SSL_CTX stats then free it\n"); |
327 |
< |
print_stats(stderr, s_ctx); |
326 |
> |
BIO_printf(bio_err, "Server SSL_CTX stats then free it\n"); |
327 |
> |
print_stats(bio_err, s_ctx); |
328 |
|
if (cache_stats) { |
329 |
< |
fprintf(stderr, "-----\n"); |
330 |
< |
lh_stats(SSL_CTX_sessions(s_ctx), stderr); |
331 |
< |
fprintf(stderr, "-----\n"); |
332 |
< |
/*- lh_node_stats(SSL_CTX_sessions(s_ctx),stderr); |
333 |
< |
fprintf(stderr,"-----\n"); */ |
334 |
< |
lh_node_usage_stats(SSL_CTX_sessions(s_ctx), stderr); |
335 |
< |
fprintf(stderr, "-----\n"); |
329 |
> |
BIO_printf(bio_err, "-----\n"); |
330 |
> |
lh_SSL_SESSION_stats_bio(SSL_CTX_sessions(s_ctx), bio_err); |
331 |
> |
BIO_printf(bio_err, "-----\n"); |
332 |
> |
/*- lh_SSL_SESSION_node_stats_bio(SSL_CTX_sessions(s_ctx),bio_err); |
333 |
> |
BIO_printf(bio_err,"-----\n"); */ |
334 |
> |
lh_SSL_SESSION_node_usage_stats_bio(SSL_CTX_sessions(s_ctx), bio_err); |
335 |
> |
BIO_printf(bio_err, "-----\n"); |
336 |
|
} |
337 |
|
SSL_CTX_free(s_ctx); |
338 |
< |
fprintf(stderr, "done free\n"); |
338 |
> |
BIO_printf(bio_err, "done free\n"); |
339 |
|
} |
340 |
|
exit(ret); |
341 |
|
return (0); |
351 |
|
int i; |
352 |
|
int ret; |
353 |
|
char *ctx[4]; |
354 |
+ |
CRYPTO_THREADID thread_id; |
355 |
|
|
356 |
|
ctx[0] = (char *)ssl_ctx[0]; |
357 |
|
ctx[1] = (char *)ssl_ctx[1]; |
364 |
|
ctx[3] = NULL; |
365 |
|
} |
366 |
|
|
367 |
< |
fprintf(stdout, "started thread %lu\n", CRYPTO_thread_id()); |
367 |
> |
CRYPTO_THREADID_current(&thread_id); |
368 |
> |
BIO_printf(bio_stdout, "started thread %lu\n", |
369 |
> |
CRYPTO_THREADID_hash(&thread_id)); |
370 |
|
for (i = 0; i < number_of_loops; i++) { |
371 |
< |
/*- fprintf(stderr,"%4d %2d ctx->ref (%3d,%3d)\n", |
372 |
< |
CRYPTO_thread_id(),i, |
373 |
< |
ssl_ctx[0]->references, |
374 |
< |
ssl_ctx[1]->references); */ |
371 |
> |
/*- BIO_printf(bio_err,"%4d %2d ctx->ref (%3d,%3d)\n", |
372 |
> |
CRYPTO_THREADID_hash(&thread_id),i, |
373 |
> |
ssl_ctx[0]->references, |
374 |
> |
ssl_ctx[1]->references); */ |
375 |
|
/* pthread_delay_np(&tm); */ |
376 |
|
|
377 |
|
ret = doit(ctx); |
378 |
|
if (ret != 0) { |
379 |
< |
fprintf(stdout, "error[%d] %lu - %d\n", |
380 |
< |
i, CRYPTO_thread_id(), ret); |
379 |
> |
BIO_printf(bio_stdout, "error[%d] %lu - %d\n", |
380 |
> |
i, CRYPTO_THREADID_hash(&thread_id), ret); |
381 |
|
return (ret); |
382 |
|
} |
383 |
|
} |
384 |
< |
fprintf(stdout, "DONE %lu\n", CRYPTO_thread_id()); |
384 |
> |
BIO_printf(bio_stdout, "DONE %lu\n", CRYPTO_THREADID_hash(&thread_id)); |
385 |
|
if (reconnect) { |
386 |
|
SSL_free((SSL *)ctx[2]); |
387 |
|
SSL_free((SSL *)ctx[3]); |
466 |
|
|
467 |
|
if (do_server && verbose) { |
468 |
|
if (SSL_in_init(s_ssl)) |
469 |
< |
printf("server waiting in SSL_accept - %s\n", |
470 |
< |
SSL_state_string_long(s_ssl)); |
469 |
> |
BIO_printf(bio_stdout, "server waiting in SSL_accept - %s\n", |
470 |
> |
SSL_state_string_long(s_ssl)); |
471 |
|
else if (s_write) |
472 |
< |
printf("server:SSL_write()\n"); |
472 |
> |
BIO_printf(bio_stdout, "server:SSL_write()\n"); |
473 |
|
else |
474 |
< |
printf("server:SSL_read()\n"); |
474 |
> |
BIO_printf(bio_stdout, "server:SSL_read()\n"); |
475 |
|
} |
476 |
|
|
477 |
|
if (do_client && verbose) { |
478 |
|
if (SSL_in_init(c_ssl)) |
479 |
< |
printf("client waiting in SSL_connect - %s\n", |
480 |
< |
SSL_state_string_long(c_ssl)); |
479 |
> |
BIO_printf(bio_stdout, "client waiting in SSL_connect - %s\n", |
480 |
> |
SSL_state_string_long(c_ssl)); |
481 |
|
else if (c_write) |
482 |
< |
printf("client:SSL_write()\n"); |
482 |
> |
BIO_printf(bio_stdout, "client:SSL_write()\n"); |
483 |
|
else |
484 |
< |
printf("client:SSL_read()\n"); |
484 |
> |
BIO_printf(bio_stdout, "client:SSL_read()\n"); |
485 |
|
} |
486 |
|
|
487 |
|
if (!do_client && !do_server) { |
488 |
< |
fprintf(stdout, "ERROR IN STARTUP\n"); |
488 |
> |
BIO_printf(bio_stdout, "ERROR IN STARTUP\n"); |
489 |
|
break; |
490 |
|
} |
491 |
|
if (do_client && !(done & C_DONE)) { |
500 |
|
if (BIO_should_write(c_bio)) |
501 |
|
c_w = 1; |
502 |
|
} else { |
503 |
< |
fprintf(stderr, "ERROR in CLIENT\n"); |
503 |
> |
BIO_printf(bio_err, "ERROR in CLIENT\n"); |
504 |
|
ERR_print_errors_fp(stderr); |
505 |
|
return (1); |
506 |
|
} |
507 |
|
} else if (i == 0) { |
508 |
< |
fprintf(stderr, "SSL CLIENT STARTUP FAILED\n"); |
508 |
> |
BIO_printf(bio_err, "SSL CLIENT STARTUP FAILED\n"); |
509 |
|
return (1); |
510 |
|
} else { |
511 |
|
/* ok */ |
522 |
|
if (BIO_should_write(c_bio)) |
523 |
|
c_w = 1; |
524 |
|
} else { |
525 |
< |
fprintf(stderr, "ERROR in CLIENT\n"); |
525 |
> |
BIO_printf(bio_err, "ERROR in CLIENT\n"); |
526 |
|
ERR_print_errors_fp(stderr); |
527 |
|
return (1); |
528 |
|
} |
529 |
|
} else if (i == 0) { |
530 |
< |
fprintf(stderr, "SSL CLIENT STARTUP FAILED\n"); |
530 |
> |
BIO_printf(bio_err, "SSL CLIENT STARTUP FAILED\n"); |
531 |
|
return (1); |
532 |
|
} else { |
533 |
|
done |= C_DONE; |
534 |
|
#ifdef undef |
535 |
< |
fprintf(stdout, "CLIENT:from server:"); |
536 |
< |
fwrite(cbuf, 1, i, stdout); |
537 |
< |
fflush(stdout); |
535 |
> |
BIO_printf(bio_stdout, "CLIENT:from server:"); |
536 |
> |
BIO_write(bio_stdout, cbuf, i); |
537 |
> |
BIO_flush(bio_stdout); |
538 |
|
#endif |
539 |
|
} |
540 |
|
} |
552 |
|
if (BIO_should_write(s_bio)) |
553 |
|
s_w = 1; |
554 |
|
} else { |
555 |
< |
fprintf(stderr, "ERROR in SERVER\n"); |
555 |
> |
BIO_printf(bio_err, "ERROR in SERVER\n"); |
556 |
|
ERR_print_errors_fp(stderr); |
557 |
|
return (1); |
558 |
|
} |
559 |
|
} else if (i == 0) { |
560 |
< |
fprintf(stderr, "SSL SERVER STARTUP FAILED\n"); |
560 |
> |
BIO_printf(bio_err, "SSL SERVER STARTUP FAILED\n"); |
561 |
|
return (1); |
562 |
|
} else { |
563 |
|
s_write = 1; |
564 |
|
s_w = 1; |
565 |
|
#ifdef undef |
566 |
< |
fprintf(stdout, "SERVER:from client:"); |
567 |
< |
fwrite(sbuf, 1, i, stdout); |
568 |
< |
fflush(stdout); |
566 |
> |
BIO_printf(bio_stdout, "SERVER:from client:"); |
567 |
> |
BIO_write(bio_stdout, sbuf, i); |
568 |
> |
BIO_flush(bio_stdout); |
569 |
|
#endif |
570 |
|
} |
571 |
|
} else { |
579 |
|
if (BIO_should_write(s_bio)) |
580 |
|
s_w = 1; |
581 |
|
} else { |
582 |
< |
fprintf(stderr, "ERROR in SERVER\n"); |
582 |
> |
BIO_printf(bio_err, "ERROR in SERVER\n"); |
583 |
|
ERR_print_errors_fp(stderr); |
584 |
|
return (1); |
585 |
|
} |
586 |
|
} else if (i == 0) { |
587 |
< |
fprintf(stderr, "SSL SERVER STARTUP FAILED\n"); |
587 |
> |
BIO_printf(bio_err, "SSL SERVER STARTUP FAILED\n"); |
588 |
|
return (1); |
589 |
|
} else { |
590 |
|
s_write = 0; |
605 |
|
SSL_set_shutdown(s_ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); |
606 |
|
|
607 |
|
#ifdef undef |
608 |
< |
fprintf(stdout, "DONE\n"); |
608 |
> |
BIO_printf(bio_stdout, "DONE\n"); |
609 |
|
#endif |
610 |
|
err: |
611 |
|
/* |
639 |
|
return (0); |
640 |
|
} |
641 |
|
|
642 |
< |
int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx) |
642 |
> |
int verify_callback(int ok, X509_STORE_CTX *ctx) |
643 |
|
{ |
644 |
|
char *s, buf[256]; |
645 |
|
|
648 |
|
buf, 256); |
649 |
|
if (s != NULL) { |
650 |
|
if (ok) |
651 |
< |
fprintf(stderr, "depth=%d %s\n", ctx->error_depth, buf); |
651 |
> |
BIO_printf(bio_err, "depth=%d %s\n", ctx->error_depth, buf); |
652 |
|
else |
653 |
< |
fprintf(stderr, "depth=%d error=%d %s\n", |
653 |
> |
BIO_printf(bio_err, "depth=%d error=%d %s\n", |
654 |
|
ctx->error_depth, ctx->error, buf); |
655 |
|
} |
656 |
|
} |
687 |
|
OPENSSL_free(lock_cs); |
688 |
|
} |
689 |
|
|
690 |
< |
void win32_locking_callback(int mode, int type, char *file, int line) |
690 |
> |
void win32_locking_callback(int mode, int type, const char *file, int line) |
691 |
|
{ |
692 |
|
if (mode & CRYPTO_LOCK) { |
693 |
|
WaitForSingleObject(lock_cs[type], INFINITE); |
716 |
|
(void *)ssl_ctx, 0L, &(thread_id[i])); |
717 |
|
} |
718 |
|
|
719 |
< |
printf("reaping\n"); |
719 |
> |
BIO_printf(bio_stdout, "reaping\n"); |
720 |
|
for (i = 0; i < thread_number; i += 50) { |
721 |
|
int j; |
722 |
|
|
726 |
|
(CONST HANDLE *) & (thread_handle[i]), |
727 |
|
TRUE, INFINITE) |
728 |
|
== WAIT_FAILED) { |
729 |
< |
fprintf(stderr, "WaitForMultipleObjects failed:%d\n", |
729 |
> |
BIO_printf(bio_err, "WaitForMultipleObjects failed:%d\n", |
730 |
|
GetLastError()); |
731 |
|
exit(1); |
732 |
|
} |
742 |
|
ret = (ret + end.wSecond - start.wSecond); |
743 |
|
ret += (end.wMilliseconds - start.wMilliseconds) / 1000.0; |
744 |
|
|
745 |
< |
printf("win32 threads done - %.3f seconds\n", ret); |
745 |
> |
BIO_printf(bio_stdout, "win32 threads done - %.3f seconds\n", ret); |
746 |
|
} |
747 |
|
|
748 |
|
#endif /* OPENSSL_SYS_WIN32 */ |
767 |
|
mutex_init(&(lock_cs[i]), USYNC_THREAD, NULL); |
768 |
|
} |
769 |
|
|
770 |
< |
CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id); |
771 |
< |
CRYPTO_set_locking_callback((void (*)())solaris_locking_callback); |
770 |
> |
CRYPTO_set_id_callback(solaris_thread_id); |
771 |
> |
CRYPTO_set_locking_callback(solaris_locking_callback); |
772 |
|
} |
773 |
|
|
774 |
|
void thread_cleanup(void) |
777 |
|
|
778 |
|
CRYPTO_set_locking_callback(NULL); |
779 |
|
|
780 |
< |
fprintf(stderr, "cleanup\n"); |
780 |
> |
BIO_printf(bio_err, "cleanup\n"); |
781 |
|
|
782 |
|
for (i = 0; i < CRYPTO_num_locks(); i++) { |
783 |
|
/* rwlock_destroy(&(lock_cs[i])); */ |
784 |
|
mutex_destroy(&(lock_cs[i])); |
785 |
< |
fprintf(stderr, "%8ld:%s\n", lock_count[i], CRYPTO_get_lock_name(i)); |
785 |
> |
BIO_printf(bio_err, "%8ld:%s\n", lock_count[i], CRYPTO_get_lock_name(i)); |
786 |
|
} |
787 |
|
OPENSSL_free(lock_cs); |
788 |
|
OPENSSL_free(lock_count); |
789 |
|
|
790 |
< |
fprintf(stderr, "done cleanup\n"); |
790 |
> |
BIO_printf(bio_err, "done cleanup\n"); |
791 |
|
|
792 |
|
} |
793 |
|
|
794 |
< |
void solaris_locking_callback(int mode, int type, char *file, int line) |
794 |
> |
void solaris_locking_callback(int mode, int type, const char *file, int line) |
795 |
|
{ |
796 |
|
# ifdef undef |
797 |
< |
fprintf(stderr, "thread=%4d mode=%s lock=%s %s:%d\n", |
798 |
< |
CRYPTO_thread_id(), |
799 |
< |
(mode & CRYPTO_LOCK) ? "l" : "u", |
800 |
< |
(type & CRYPTO_READ) ? "r" : "w", file, line); |
797 |
> |
BIO_printf(bio_err, "thread=%4d mode=%s lock=%s %s:%d\n", |
798 |
> |
CRYPTO_thread_id(), |
799 |
> |
(mode & CRYPTO_LOCK) ? "l" : "u", |
800 |
> |
(type & CRYPTO_READ) ? "r" : "w", file, line); |
801 |
|
# endif |
802 |
|
|
803 |
|
/*- |
804 |
|
if (CRYPTO_LOCK_SSL_CERT == type) |
805 |
< |
fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", |
806 |
< |
CRYPTO_thread_id(), |
807 |
< |
mode,file,line); |
805 |
> |
BIO_printf(bio_err,"(t,m,f,l) %ld %d %s %d\n", |
806 |
> |
CRYPTO_thread_id(), |
807 |
> |
mode,file,line); |
808 |
|
*/ |
809 |
|
if (mode & CRYPTO_LOCK) { |
810 |
|
/*- |
836 |
|
(void *(*)())ndoit, (void *)ssl_ctx, 0L, &(thread_ctx[i])); |
837 |
|
} |
838 |
|
|
839 |
< |
printf("reaping\n"); |
839 |
> |
BIO_printf(bio_stdout, "reaping\n"); |
840 |
|
for (i = 0; i < thread_number; i++) { |
841 |
|
thr_join(thread_ctx[i], NULL, NULL); |
842 |
|
} |
843 |
|
|
844 |
< |
printf("solaris threads done (%d,%d)\n", |
845 |
< |
s_ctx->references, c_ctx->references); |
844 |
> |
#if 0 /* We can't currently find out the reference amount */ |
845 |
> |
BIO_printf(bio_stdout, "solaris threads done (%d,%d)\n", |
846 |
> |
s_ctx->references, c_ctx->references); |
847 |
> |
#else |
848 |
> |
BIO_printf(bio_stdout, "solaris threads done\n"); |
849 |
> |
#endif |
850 |
|
} |
851 |
|
|
852 |
< |
unsigned long solaris_thread_id(void) |
852 |
> |
void solaris_thread_id(CRYPTO_THREADID *tid) |
853 |
|
{ |
854 |
< |
unsigned long ret; |
852 |
< |
|
853 |
< |
ret = (unsigned long)thr_self(); |
854 |
< |
return (ret); |
854 |
> |
CRYPTO_THREADID_set_numeric((unsigned long)thr_self()); |
855 |
|
} |
856 |
|
#endif /* SOLARIS */ |
857 |
|
|
880 |
|
lock_cs[i] = usnewsema(arena, 1); |
881 |
|
} |
882 |
|
|
883 |
< |
CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id); |
884 |
< |
CRYPTO_set_locking_callback((void (*)())irix_locking_callback); |
883 |
> |
CRYPTO_set_id_callback(irix_thread_id); |
884 |
> |
CRYPTO_set_locking_callback(irix_locking_callback); |
885 |
|
} |
886 |
|
|
887 |
|
void thread_cleanup(void) |
899 |
|
OPENSSL_free(lock_cs); |
900 |
|
} |
901 |
|
|
902 |
< |
void irix_locking_callback(int mode, int type, char *file, int line) |
902 |
> |
void irix_locking_callback(int mode, int type, const char *file, int line) |
903 |
|
{ |
904 |
|
if (mode & CRYPTO_LOCK) { |
905 |
< |
printf("lock %d\n", type); |
905 |
> |
BIO_printf(bio_stdout, "lock %d\n", type); |
906 |
|
uspsema(lock_cs[type]); |
907 |
|
} else { |
908 |
< |
printf("unlock %d\n", type); |
908 |
> |
BIO_printf(bio_stdout, "unlock %d\n", type); |
909 |
|
usvsema(lock_cs[type]); |
910 |
|
} |
911 |
|
} |
924 |
|
PR_SADDR | PR_SFDS, (void *)ssl_ctx); |
925 |
|
} |
926 |
|
|
927 |
< |
printf("reaping\n"); |
927 |
> |
BIO_printf(bio_stdout, "reaping\n"); |
928 |
|
for (i = 0; i < thread_number; i++) { |
929 |
|
wait(NULL); |
930 |
|
} |
931 |
|
|
932 |
< |
printf("irix threads done (%d,%d)\n", |
933 |
< |
s_ctx->references, c_ctx->references); |
932 |
> |
#if 0 /* We can't currently find out the reference amount */ |
933 |
> |
BIO_printf(bio_stdout, "irix threads done (%d,%d)\n", |
934 |
> |
s_ctx->references, c_ctx->references); |
935 |
> |
#else |
936 |
> |
BIO_printf(bio_stdout, "irix threads done\n"); |
937 |
> |
#endif |
938 |
|
} |
939 |
|
|
940 |
|
unsigned long irix_thread_id(void) |
941 |
|
{ |
942 |
< |
unsigned long ret; |
939 |
< |
|
940 |
< |
ret = (unsigned long)getpid(); |
941 |
< |
return (ret); |
942 |
> |
CRYPTO_THREADID_set_numeric((unsigned long)getpid()); |
943 |
|
} |
944 |
|
#endif /* IRIX */ |
945 |
|
|
959 |
|
pthread_mutex_init(&(lock_cs[i]), NULL); |
960 |
|
} |
961 |
|
|
962 |
< |
CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id); |
963 |
< |
CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback); |
962 |
> |
CRYPTO_THREADID_set_callback(pthreads_thread_id); |
963 |
> |
CRYPTO_set_locking_callback(pthreads_locking_callback); |
964 |
|
} |
965 |
|
|
966 |
|
void thread_cleanup(void) |
968 |
|
int i; |
969 |
|
|
970 |
|
CRYPTO_set_locking_callback(NULL); |
971 |
< |
fprintf(stderr, "cleanup\n"); |
971 |
> |
BIO_printf(bio_err, "cleanup\n"); |
972 |
|
for (i = 0; i < CRYPTO_num_locks(); i++) { |
973 |
|
pthread_mutex_destroy(&(lock_cs[i])); |
974 |
< |
fprintf(stderr, "%8ld:%s\n", lock_count[i], CRYPTO_get_lock_name(i)); |
974 |
> |
BIO_printf(bio_err, "%8ld:%s\n", lock_count[i], CRYPTO_get_lock_name(i)); |
975 |
|
} |
976 |
|
OPENSSL_free(lock_cs); |
977 |
|
OPENSSL_free(lock_count); |
978 |
|
|
979 |
< |
fprintf(stderr, "done cleanup\n"); |
979 |
> |
BIO_printf(bio_err, "done cleanup\n"); |
980 |
|
} |
981 |
|
|
982 |
< |
void pthreads_locking_callback(int mode, int type, char *file, int line) |
982 |
> |
void pthreads_locking_callback(int mode, int type, const char *file, int line) |
983 |
|
{ |
984 |
|
# ifdef undef |
985 |
< |
fprintf(stderr, "thread=%4d mode=%s lock=%s %s:%d\n", |
986 |
< |
CRYPTO_thread_id(), |
987 |
< |
(mode & CRYPTO_LOCK) ? "l" : "u", |
988 |
< |
(type & CRYPTO_READ) ? "r" : "w", file, line); |
985 |
> |
BIO_printf(bio_err, "thread=%4d mode=%s lock=%s %s:%d\n", |
986 |
> |
CRYPTO_thread_id(), |
987 |
> |
(mode & CRYPTO_LOCK) ? "l" : "u", |
988 |
> |
(type & CRYPTO_READ) ? "r" : "w", file, line); |
989 |
|
# endif |
990 |
|
/*- |
991 |
|
if (CRYPTO_LOCK_SSL_CERT == type) |
992 |
< |
fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n", |
993 |
< |
CRYPTO_thread_id(), |
994 |
< |
mode,file,line); |
992 |
> |
BIO_printf(bio_err,"(t,m,f,l) %ld %d %s %d\n", |
993 |
> |
CRYPTO_thread_id(), |
994 |
> |
mode,file,line); |
995 |
|
*/ |
996 |
|
if (mode & CRYPTO_LOCK) { |
997 |
|
pthread_mutex_lock(&(lock_cs[type])); |
1018 |
|
(void *(*)())ndoit, (void *)ssl_ctx); |
1019 |
|
} |
1020 |
|
|
1021 |
< |
printf("reaping\n"); |
1021 |
> |
BIO_printf(bio_stdout, "reaping\n"); |
1022 |
|
for (i = 0; i < thread_number; i++) { |
1023 |
|
pthread_join(thread_ctx[i], NULL); |
1024 |
|
} |
1025 |
|
|
1026 |
< |
printf("pthreads threads done (%d,%d)\n", |
1027 |
< |
s_ctx->references, c_ctx->references); |
1026 |
> |
#if 0 /* We can't currently find out the reference amount */ |
1027 |
> |
BIO_printf(bio_stdout, "pthreads threads done (%d,%d)\n", |
1028 |
> |
s_ctx->references, c_ctx->references); |
1029 |
> |
#else |
1030 |
> |
BIO_printf(bio_stdout, "pthreads threads done\n"); |
1031 |
> |
#endif |
1032 |
|
} |
1033 |
|
|
1034 |
< |
unsigned long pthreads_thread_id(void) |
1034 |
> |
void pthreads_thread_id(CRYPTO_THREADID *tid) |
1035 |
|
{ |
1036 |
< |
unsigned long ret; |
1032 |
< |
|
1033 |
< |
ret = (unsigned long)pthread_self(); |
1034 |
< |
return (ret); |
1036 |
> |
CRYPTO_THREADID_set_numeric(tid, (unsigned long)pthread_self()); |
1037 |
|
} |
1038 |
|
|
1039 |
|
#endif /* PTHREADS */ |
1053 |
|
|
1054 |
|
ThreadSem = MPKSemaphoreAlloc("OpenSSL mttest semaphore", 0); |
1055 |
|
|
1056 |
< |
CRYPTO_set_id_callback((unsigned long (*)())netware_thread_id); |
1057 |
< |
CRYPTO_set_locking_callback((void (*)())netware_locking_callback); |
1056 |
> |
CRYPTO_set_id_callback(netware_thread_id); |
1057 |
> |
CRYPTO_set_locking_callback(netware_locking_callback); |
1058 |
|
} |
1059 |
|
|
1060 |
|
void thread_cleanup(void) |
1063 |
|
|
1064 |
|
CRYPTO_set_locking_callback(NULL); |
1065 |
|
|
1066 |
< |
fprintf(stdout, "thread_cleanup\n"); |
1066 |
> |
BIO_printf(bio_stdout, "thread_cleanup\n"); |
1067 |
|
|
1068 |
|
for (i = 0; i < CRYPTO_num_locks(); i++) { |
1069 |
|
MPKMutexFree(lock_cs[i]); |
1070 |
< |
fprintf(stdout, "%8ld:%s\n", lock_count[i], CRYPTO_get_lock_name(i)); |
1070 |
> |
BIO_printf(bio_stdout, "%8ld:%s\n", lock_count[i], CRYPTO_get_lock_name(i)); |
1071 |
|
} |
1072 |
|
OPENSSL_free(lock_cs); |
1073 |
|
OPENSSL_free(lock_count); |
1074 |
|
|
1075 |
|
MPKSemaphoreFree(ThreadSem); |
1076 |
|
|
1077 |
< |
fprintf(stdout, "done cleanup\n"); |
1077 |
> |
BIO_printf(bio_stdout, "done cleanup\n"); |
1078 |
|
} |
1079 |
|
|
1080 |
< |
void netware_locking_callback(int mode, int type, char *file, int line) |
1080 |
> |
void netware_locking_callback(int mode, int type, const char *file, int line) |
1081 |
|
{ |
1082 |
|
if (mode & CRYPTO_LOCK) { |
1083 |
|
MPKMutexLock(lock_cs[type]); |
1099 |
|
ThreadSwitchWithDelay(); |
1100 |
|
} |
1101 |
|
|
1102 |
< |
printf("reaping\n"); |
1102 |
> |
BIO_printf(bio_stdout, "reaping\n"); |
1103 |
|
|
1104 |
|
/* loop until all threads have signaled the semaphore */ |
1105 |
|
for (i = 0; i < thread_number; i++) { |
1106 |
|
MPKSemaphoreWait(ThreadSem); |
1107 |
|
} |
1108 |
< |
printf("netware threads done (%d,%d)\n", |
1109 |
< |
s_ctx->references, c_ctx->references); |
1108 |
> |
#if 0 /* We can't currently find out the reference amount */ |
1109 |
> |
BIO_printf(bio_stdout, "netware threads done (%d,%d)\n", |
1110 |
> |
s_ctx->references, c_ctx->references); |
1111 |
> |
#else |
1112 |
> |
BIO_printf(bio_stdout, "netware threads done\n"); |
1113 |
> |
#endif |
1114 |
|
} |
1115 |
|
|
1116 |
|
unsigned long netware_thread_id(void) |
1117 |
|
{ |
1118 |
< |
unsigned long ret; |
1113 |
< |
|
1114 |
< |
ret = (unsigned long)GetThreadID(); |
1115 |
< |
return (ret); |
1118 |
> |
CRYPTO_THREADID_set_numeric((unsigned long)GetThreadID()); |
1119 |
|
} |
1120 |
|
#endif /* NETWARE */ |
1121 |
|
|
1147 |
|
int i; |
1148 |
|
|
1149 |
|
CRYPTO_set_locking_callback(NULL); |
1150 |
< |
fprintf(stderr, "cleanup\n"); |
1150 |
> |
BIO_printf(bio_err, "cleanup\n"); |
1151 |
|
for (i = 0; i < CRYPTO_num_locks(); i++) { |
1152 |
|
delete lock_cs[i]; |
1153 |
< |
fprintf(stderr, "%8ld:%s\n", lock_count[i], CRYPTO_get_lock_name(i)); |
1153 |
> |
BIO_printf(bio_err, "%8ld:%s\n", lock_count[i], CRYPTO_get_lock_name(i)); |
1154 |
|
} |
1155 |
|
OPENSSL_free(lock_cs); |
1156 |
|
OPENSSL_free(lock_count); |
1157 |
|
|
1158 |
< |
fprintf(stderr, "done cleanup\n"); |
1158 |
> |
BIO_printf(bio_err, "done cleanup\n"); |
1159 |
|
} |
1160 |
|
|
1161 |
|
void beos_locking_callback(int mode, int type, const char *file, int line) |
1162 |
|
{ |
1163 |
|
# if 0 |
1164 |
< |
fprintf(stderr, "thread=%4d mode=%s lock=%s %s:%d\n", |
1165 |
< |
CRYPTO_thread_id(), |
1166 |
< |
(mode & CRYPTO_LOCK) ? "l" : "u", |
1167 |
< |
(type & CRYPTO_READ) ? "r" : "w", file, line); |
1164 |
> |
BIO_printf(bio_err, "thread=%4d mode=%s lock=%s %s:%d\n", |
1165 |
> |
CRYPTO_thread_id(), |
1166 |
> |
(mode & CRYPTO_LOCK) ? "l" : "u", |
1167 |
> |
(type & CRYPTO_READ) ? "r" : "w", file, line); |
1168 |
|
# endif |
1169 |
|
if (mode & CRYPTO_LOCK) { |
1170 |
|
lock_cs[type]->Lock(); |
1190 |
|
resume_thread(thread_ctx[i]); |
1191 |
|
} |
1192 |
|
|
1193 |
< |
printf("waiting...\n"); |
1193 |
> |
BIO_printf(bio_stdout, "waiting...\n"); |
1194 |
|
for (i = 0; i < thread_number; i++) { |
1195 |
|
status_t result; |
1196 |
|
wait_for_thread(thread_ctx[i], &result); |
1197 |
|
} |
1198 |
|
|
1199 |
< |
printf("beos threads done (%d,%d)\n", |
1200 |
< |
s_ctx->references, c_ctx->references); |
1199 |
> |
BIO_printf(bio_stdout, "beos threads done (%d,%d)\n", |
1200 |
> |
s_ctx->references, c_ctx->references); |
1201 |
|
} |
1202 |
|
|
1203 |
|
unsigned long beos_thread_id(void) |