2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
66 #include "openssl/e_os.h"
68 #include <openssl/bio.h>
69 #include <openssl/crypto.h>
70 #include <openssl/x509.h>
71 #include <openssl/ssl.h>
72 #include <openssl/err.h>
73 #include <openssl/rand.h>
75 #include "../crypto/bio/bss_file.c"
79 # define TEST_SERVER_CERT "SYS$DISK:[-.APPS]SERVER.PEM"
80 # define TEST_CLIENT_CERT "SYS$DISK:[-.APPS]CLIENT.PEM"
82 # define TEST_SERVER_CERT "../apps/server.pem"
83 # define TEST_CLIENT_CERT "../apps/client.pem"
86 static int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
88 static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export,int keylength);
91 static DH *get_dh512(void);
93 static BIO *bio_err=NULL;
94 static BIO *bio_stdout=NULL;
96 static char *cipher=NULL;
106 static const char rnd_seed[] = "string to make the random number generator think it has entropy";
108 int doit_biopair(SSL *s_ssl,SSL *c_ssl,long bytes);
109 int doit(SSL *s_ssl,SSL *c_ssl,long bytes);
110 static void sv_usage(void)
112 fprintf(stderr,"usage: ssltest [args ...]\n");
113 fprintf(stderr,"\n");
114 fprintf(stderr," -server_auth - check server certificate\n");
115 fprintf(stderr," -client_auth - do client authentication\n");
116 fprintf(stderr," -v - more output\n");
117 fprintf(stderr," -d - debug output\n");
118 fprintf(stderr," -reuse - use session-id reuse\n");
119 fprintf(stderr," -num <val> - number of connections to perform\n");
120 fprintf(stderr," -bytes <val> - number of bytes to swap between client/server\n");
121 #if !defined NO_DH && !defined NO_DSA
122 fprintf(stderr," -dhe1024 - generate 1024 bit key for DHE\n");
125 fprintf(stderr," -no_dhe - disable DHE\n");
128 fprintf(stderr," -ssl2 - use SSLv2\n");
131 fprintf(stderr," -ssl3 - use SSLv3\n");
134 fprintf(stderr," -tls1 - use TLSv1\n");
136 fprintf(stderr," -CApath arg - PEM format directory of CA's\n");
137 fprintf(stderr," -CAfile arg - PEM format file of CA's\n");
138 fprintf(stderr," -cert arg - Certificate file\n");
139 fprintf(stderr," -s_cert arg - Just the server certificate file\n");
140 fprintf(stderr," -c_cert arg - Just the client certificate file\n");
141 fprintf(stderr," -cipher arg - The cipher list\n");
142 fprintf(stderr," -bio_pair - Use BIO pairs\n");
143 fprintf(stderr," -f - Test even cases that can't work\n");
146 int main(int argc, char *argv[])
148 char *CApath=NULL,*CAfile=NULL;
152 int tls1=0,ssl2=0,ssl3=0,ret=1;
155 char *server_cert=TEST_SERVER_CERT;
156 char *client_cert=TEST_CLIENT_CERT;
159 SSL_METHOD *meth=NULL;
161 int number=1,reuse=0;
164 int dhe1024 = 0, no_dhe = 0;
172 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
174 RAND_seed(rnd_seed, sizeof rnd_seed);
176 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
177 bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
184 if (strcmp(*argv,"-server_auth") == 0)
186 else if (strcmp(*argv,"-client_auth") == 0)
188 else if (strcmp(*argv,"-v") == 0)
190 else if (strcmp(*argv,"-d") == 0)
192 else if (strcmp(*argv,"-reuse") == 0)
194 else if (strcmp(*argv,"-dhe1024") == 0)
196 else if (strcmp(*argv,"-no_dhe") == 0)
198 else if (strcmp(*argv,"-ssl2") == 0)
200 else if (strcmp(*argv,"-tls1") == 0)
202 else if (strcmp(*argv,"-ssl3") == 0)
204 else if (strncmp(*argv,"-num",4) == 0)
206 if (--argc < 1) goto bad;
207 number= atoi(*(++argv));
208 if (number == 0) number=1;
210 else if (strcmp(*argv,"-bytes") == 0)
212 if (--argc < 1) goto bad;
213 bytes= atol(*(++argv));
214 if (bytes == 0L) bytes=1L;
216 if (argv[0][i-1] == 'k') bytes*=1024L;
217 if (argv[0][i-1] == 'm') bytes*=1024L*1024L;
219 else if (strcmp(*argv,"-cert") == 0)
221 if (--argc < 1) goto bad;
222 server_cert= *(++argv);
224 else if (strcmp(*argv,"-s_cert") == 0)
226 if (--argc < 1) goto bad;
227 server_cert= *(++argv);
229 else if (strcmp(*argv,"-c_cert") == 0)
231 if (--argc < 1) goto bad;
232 client_cert= *(++argv);
234 else if (strcmp(*argv,"-cipher") == 0)
236 if (--argc < 1) goto bad;
239 else if (strcmp(*argv,"-CApath") == 0)
241 if (--argc < 1) goto bad;
244 else if (strcmp(*argv,"-CAfile") == 0)
246 if (--argc < 1) goto bad;
249 else if (strcmp(*argv,"-bio_pair") == 0)
253 else if (strcmp(*argv,"-f") == 0)
259 fprintf(stderr,"unknown option %s\n",*argv);
273 if (!ssl2 && !ssl3 && !tls1 && number > 1 && !reuse && !force)
275 fprintf(stderr, "This case cannot work. Use -f switch to perform "
277 "(and -d to see what happens, "
278 "and -bio_pair to really make it happen :-)\n"
279 "or add one of -ssl2, -ssl3, -tls1, -reuse to "
280 "avoid protocol mismatch.\n");
284 /* if (cipher == NULL) cipher=getenv("SSL_CIPHER"); */
287 SSL_load_error_strings();
289 #if !defined(NO_SSL2) && !defined(NO_SSL3)
299 meth=SSLv23_method();
308 c_ctx=SSL_CTX_new(meth);
309 s_ctx=SSL_CTX_new(meth);
310 if ((c_ctx == NULL) || (s_ctx == NULL))
312 ERR_print_errors(bio_err);
318 SSL_CTX_set_cipher_list(c_ctx,cipher);
319 SSL_CTX_set_cipher_list(s_ctx,cipher);
329 unsigned char seed[20];
333 fprintf(stdout, "Creating 1024 bit DHE parameters ...");
337 memcpy(seed, "Random String no. 12", 20);
338 dsa = DSA_generate_parameters(1024, seed, 20, NULL, NULL, 0, NULL);
339 dh = DSA_dup_DH(dsa);
341 /* important: SSL_OP_SINGLE_DH_USE to avoid small subgroup attacks */
342 SSL_CTX_set_options(s_ctx, SSL_OP_SINGLE_DH_USE);
345 fprintf(stdout, " done\n");
350 SSL_CTX_set_tmp_dh(s_ctx,dh);
356 SSL_CTX_set_tmp_rsa_callback(s_ctx,tmp_rsa_cb);
359 if (!SSL_CTX_use_certificate_file(s_ctx,server_cert,SSL_FILETYPE_PEM))
361 ERR_print_errors(bio_err);
363 else if (!SSL_CTX_use_PrivateKey_file(s_ctx,server_cert,
366 ERR_print_errors(bio_err);
372 SSL_CTX_use_certificate_file(c_ctx,client_cert,
374 SSL_CTX_use_PrivateKey_file(c_ctx,client_cert,
378 if ( (!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) ||
379 (!SSL_CTX_set_default_verify_paths(s_ctx)) ||
380 (!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) ||
381 (!SSL_CTX_set_default_verify_paths(c_ctx)))
383 /* fprintf(stderr,"SSL_load_verify_locations\n"); */
384 ERR_print_errors(bio_err);
390 fprintf(stderr,"client authentication\n");
391 SSL_CTX_set_verify(s_ctx,
392 SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
397 fprintf(stderr,"server authentication\n");
398 SSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER,
403 int session_id_context = 0;
404 SSL_CTX_set_session_id_context(s_ctx, (void *)&session_id_context, sizeof session_id_context);
407 c_ssl=SSL_new(c_ctx);
408 s_ssl=SSL_new(s_ctx);
410 for (i=0; i<number; i++)
412 if (!reuse) SSL_set_session(c_ssl,NULL);
414 ret=doit_biopair(s_ssl,c_ssl,bytes);
416 ret=doit(s_ssl,c_ssl,bytes);
421 ciph=SSL_get_current_cipher(c_ssl);
422 fprintf(stdout,"Protocol %s, cipher %s, %s\n",
423 SSL_get_version(c_ssl),
424 SSL_CIPHER_get_version(ciph),
425 SSL_CIPHER_get_name(ciph));
427 if ((number > 1) || (bytes > 1L))
428 printf("%d handshakes of %ld bytes done\n",number,bytes);
434 if (s_ctx != NULL) SSL_CTX_free(s_ctx);
435 if (c_ctx != NULL) SSL_CTX_free(c_ctx);
437 if (bio_stdout != NULL) BIO_free(bio_stdout);
442 CRYPTO_mem_leaks(bio_err);
443 if (bio_err != NULL) BIO_free(bio_err);
447 int doit_biopair(SSL *s_ssl, SSL *c_ssl, long count)
449 long cw_num = count, cr_num = count, sw_num = count, sr_num = count;
450 BIO *s_ssl_bio = NULL, *c_ssl_bio = NULL;
451 BIO *server = NULL, *server_io = NULL, *client = NULL, *client_io = NULL;
455 size_t bufsiz = 256; /* small buffer for testing */
457 if (!BIO_new_bio_pair(&server, bufsiz, &server_io, bufsiz))
459 if (!BIO_new_bio_pair(&client, bufsiz, &client_io, bufsiz))
462 s_ssl_bio = BIO_new(BIO_f_ssl());
466 c_ssl_bio = BIO_new(BIO_f_ssl());
470 SSL_set_connect_state(c_ssl);
471 SSL_set_bio(c_ssl, client, client);
472 (void)BIO_set_ssl(c_ssl_bio, c_ssl, BIO_NOCLOSE);
474 SSL_set_accept_state(s_ssl);
475 SSL_set_bio(s_ssl, server, server);
476 (void)BIO_set_ssl(s_ssl_bio, s_ssl, BIO_NOCLOSE);
480 /* c_ssl_bio: SSL filter BIO
482 * client: pseudo-I/O for SSL library
484 * client_io: client's SSL communication; usually to be
485 * relayed over some I/O facility, but in this
486 * test program, we're the server, too:
488 * server_io: server's SSL communication
490 * server: pseudo-I/O for SSL library
492 * s_ssl_bio: SSL filter BIO
494 * The client and the server each employ a "BIO pair":
495 * client + client_io, server + server_io.
496 * BIO pairs are symmetric. A BIO pair behaves similar
497 * to a non-blocking socketpair (but both endpoints must
498 * be handled by the same thread).
499 * [Here we could connect client and server to the ends
500 * of a single BIO pair, but then this code would be less
501 * suitable as an example for BIO pairs in general.]
503 * Useful functions for querying the state of BIO pair endpoints:
505 * BIO_ctrl_pending(bio) number of bytes we can read now
506 * BIO_ctrl_get_read_request(bio) number of bytes needed to fulfil
507 * other side's read attempt
508 * BIO_ctrl_get_write_gurantee(bio) number of bytes we can write now
510 * ..._read_request is never more than ..._write_guarantee;
511 * it depends on the application which one you should use.
514 /* We have non-blocking behaviour throughout this test program, but
515 * can be sure that there is *some* progress in each iteration; so
516 * we don't have to worry about ..._SHOULD_READ or ..._SHOULD_WRITE
517 * -- we just try everything in each iteration
523 MS_STATIC char cbuf[1024*8];
527 if (SSL_in_init(c_ssl))
528 printf("client waiting in SSL_connect - %s\n",
529 SSL_state_string_long(c_ssl));
533 /* Write to server. */
535 if (cw_num > (long)sizeof cbuf)
539 r = BIO_write(c_ssl_bio, cbuf, i);
542 if (!BIO_should_retry(c_ssl_bio))
544 fprintf(stderr,"ERROR in CLIENT\n");
547 /* BIO_should_retry(...) can just be ignored here.
548 * The library expects us to call BIO_write with
549 * the same arguments again, and that's what we will
550 * do in the next iteration. */
554 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
560 printf("client wrote %d\n", r);
567 /* Read from server. */
569 r = BIO_read(c_ssl_bio, cbuf, sizeof(cbuf));
572 if (!BIO_should_retry(c_ssl_bio))
574 fprintf(stderr,"ERROR in CLIENT\n");
577 /* Again, "BIO_should_retry" can be ignored. */
581 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
587 printf("client read %d\n", r);
596 MS_STATIC char sbuf[1024*8];
600 if (SSL_in_init(s_ssl))
601 printf("server waiting in SSL_accept - %s\n",
602 SSL_state_string_long(s_ssl));
606 /* Write to client. */
608 if (sw_num > (long)sizeof sbuf)
612 r = BIO_write(s_ssl_bio, sbuf, i);
615 if (!BIO_should_retry(s_ssl_bio))
617 fprintf(stderr,"ERROR in SERVER\n");
620 /* Ignore "BIO_should_retry". */
624 fprintf(stderr,"SSL SERVER STARTUP FAILED\n");
630 printf("server wrote %d\n", r);
637 /* Read from client. */
639 r = BIO_read(s_ssl_bio, sbuf, sizeof(sbuf));
642 if (!BIO_should_retry(s_ssl_bio))
644 fprintf(stderr,"ERROR in SERVER\n");
651 fprintf(stderr,"SSL SERVER STARTUP FAILED\n");
657 printf("server read %d\n", r);
664 /* "I/O" BETWEEN CLIENT AND SERVER. */
667 BIO *io1 = server_io, *io2 = client_io;
668 /* we use the non-copying interface for io1
669 * and the standard BIO_write/BIO_read interface for io2
672 static int prev_progress = 1;
681 r1 = BIO_ctrl_pending(io1);
682 r2 = BIO_ctrl_get_write_guarantee(io2);
691 if (INT_MAX < num) /* yeah, right */
694 r = BIO_nread(io1, &dataptr, (int)num);
696 assert(r <= (int)num);
697 /* possibly r < num (non-contiguous data) */
699 r = BIO_write(io2, dataptr, (int)num);
700 if (r != (int)num) /* can't happen */
702 fprintf(stderr, "ERROR: BIO_write could not write "
703 "BIO_ctrl_get_write_guarantee() bytes");
709 printf((io1 == client_io) ?
710 "C->S relaying: %d bytes\n" :
711 "S->C relaying: %d bytes\n",
722 r1 = BIO_ctrl_pending(io2);
723 r2 = BIO_ctrl_get_read_request(io1);
724 /* here we could use ..._get_write_guarantee instead of
725 * ..._get_read_request, but by using the latter
726 * we test restartability of the SSL implementation
739 --num; /* test restartability even more thoroughly */
741 r = BIO_nwrite(io1, &dataptr, (int)num);
743 assert(r <= (int)num);
745 r = BIO_read(io2, dataptr, (int)num);
746 if (r != (int)num) /* can't happen */
748 fprintf(stderr, "ERROR: BIO_read could not read "
749 "BIO_ctrl_pending() bytes");
755 printf((io2 == client_io) ?
756 "C->S relaying: %d bytes\n" :
757 "S->C relaying: %d bytes\n",
760 } /* no loop, BIO_ctrl_get_read_request now returns 0 anyway */
762 if (!progress && !prev_progress)
763 if (cw_num > 0 || cr_num > 0 || sw_num > 0 || sr_num > 0)
765 fprintf(stderr, "ERROR: got stuck\n");
766 if (strcmp("SSLv2", SSL_get_version(c_ssl)) == 0)
768 fprintf(stderr, "This can happen for SSL2 because "
769 "CLIENT-FINISHED and SERVER-VERIFY are written \n"
771 if (strncmp("2SCF", SSL_state_string(c_ssl), 4) == 0
772 && strncmp("2SSV", SSL_state_string(s_ssl), 4) == 0)
774 fprintf(stderr, " ok.\n");
778 fprintf(stderr, " ERROR.\n");
781 prev_progress = progress;
784 while (cw_num > 0 || cr_num > 0 || sw_num > 0 || sr_num > 0);
786 ciph = SSL_get_current_cipher(c_ssl);
788 fprintf(stdout,"DONE via BIO pair, protocol %s, cipher %s, %s\n",
789 SSL_get_version(c_ssl),
790 SSL_CIPHER_get_version(ciph),
791 SSL_CIPHER_get_name(ciph));
796 ERR_print_errors(bio_err);
820 int doit(SSL *s_ssl, SSL *c_ssl, long count)
822 MS_STATIC char cbuf[1024*8],sbuf[1024*8];
823 long cw_num=count,cr_num=count;
824 long sw_num=count,sr_num=count;
835 int do_server=0,do_client=0;
838 c_to_s=BIO_new(BIO_s_mem());
839 s_to_c=BIO_new(BIO_s_mem());
840 if ((s_to_c == NULL) || (c_to_s == NULL))
842 ERR_print_errors(bio_err);
846 c_bio=BIO_new(BIO_f_ssl());
847 s_bio=BIO_new(BIO_f_ssl());
848 if ((c_bio == NULL) || (s_bio == NULL))
850 ERR_print_errors(bio_err);
854 SSL_set_connect_state(c_ssl);
855 SSL_set_bio(c_ssl,s_to_c,c_to_s);
856 BIO_set_ssl(c_bio,c_ssl,BIO_NOCLOSE);
858 SSL_set_accept_state(s_ssl);
859 SSL_set_bio(s_ssl,c_to_s,s_to_c);
860 BIO_set_ssl(s_bio,s_ssl,BIO_NOCLOSE);
868 /* We can always do writes */
874 i=(int)BIO_pending(s_bio);
875 if ((i && s_r) || s_w) do_server=1;
877 i=(int)BIO_pending(c_bio);
878 if ((i && c_r) || c_w) do_client=1;
880 if (do_server && debug)
882 if (SSL_in_init(s_ssl))
883 printf("server waiting in SSL_accept - %s\n",
884 SSL_state_string_long(s_ssl));
886 printf("server:SSL_write()\n");
888 printf("server:SSL_read()\n"); */
891 if (do_client && debug)
893 if (SSL_in_init(c_ssl))
894 printf("client waiting in SSL_connect - %s\n",
895 SSL_state_string_long(c_ssl));
897 printf("client:SSL_write()\n");
899 printf("client:SSL_read()\n"); */
902 if (!do_client && !do_server)
904 fprintf(stdout,"ERROR IN STARTUP\n");
905 ERR_print_errors(bio_err);
908 if (do_client && !(done & C_DONE))
912 j=(cw_num > (long)sizeof(cbuf))
913 ?sizeof(cbuf):(int)cw_num;
914 i=BIO_write(c_bio,cbuf,j);
919 if (BIO_should_retry(c_bio))
921 if (BIO_should_read(c_bio))
923 if (BIO_should_write(c_bio))
928 fprintf(stderr,"ERROR in CLIENT\n");
929 ERR_print_errors(bio_err);
935 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
941 printf("client wrote %d\n",i);
950 i=BIO_read(c_bio,cbuf,sizeof(cbuf));
955 if (BIO_should_retry(c_bio))
957 if (BIO_should_read(c_bio))
959 if (BIO_should_write(c_bio))
964 fprintf(stderr,"ERROR in CLIENT\n");
965 ERR_print_errors(bio_err);
971 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
977 printf("client read %d\n",i);
994 if (do_server && !(done & S_DONE))
998 i=BIO_read(s_bio,sbuf,sizeof(cbuf));
1003 if (BIO_should_retry(s_bio))
1005 if (BIO_should_read(s_bio))
1007 if (BIO_should_write(s_bio))
1012 fprintf(stderr,"ERROR in SERVER\n");
1013 ERR_print_errors(bio_err);
1019 ERR_print_errors(bio_err);
1020 fprintf(stderr,"SSL SERVER STARTUP FAILED in SSL_read\n");
1026 printf("server read %d\n",i);
1043 j=(sw_num > (long)sizeof(sbuf))?
1044 sizeof(sbuf):(int)sw_num;
1045 i=BIO_write(s_bio,sbuf,j);
1050 if (BIO_should_retry(s_bio))
1052 if (BIO_should_read(s_bio))
1054 if (BIO_should_write(s_bio))
1059 fprintf(stderr,"ERROR in SERVER\n");
1060 ERR_print_errors(bio_err);
1066 ERR_print_errors(bio_err);
1067 fprintf(stderr,"SSL SERVER STARTUP FAILED in SSL_write\n");
1073 printf("server wrote %d\n",i);
1083 if ((done & S_DONE) && (done & C_DONE)) break;
1086 ciph=SSL_get_current_cipher(c_ssl);
1088 fprintf(stdout,"DONE, protocol %s, cipher %s, %s\n",
1089 SSL_get_version(c_ssl),
1090 SSL_CIPHER_get_version(ciph),
1091 SSL_CIPHER_get_name(ciph));
1094 /* We have to set the BIO's to NULL otherwise they will be
1095 * Free()ed twice. Once when th s_ssl is SSL_free()ed and
1096 * again when c_ssl is SSL_free()ed.
1097 * This is a hack required because s_ssl and c_ssl are sharing the same
1098 * BIO structure and SSL_set_bio() and SSL_free() automatically
1099 * BIO_free non NULL entries.
1100 * You should not normally do this or be required to do this */
1112 if (c_to_s != NULL) BIO_free(c_to_s);
1113 if (s_to_c != NULL) BIO_free(s_to_c);
1114 if (c_bio != NULL) BIO_free_all(c_bio);
1115 if (s_bio != NULL) BIO_free_all(s_bio);
1119 static int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
1123 s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),buf,256);
1127 fprintf(stderr,"depth=%d %s\n",ctx->error_depth,buf);
1129 fprintf(stderr,"depth=%d error=%d %s\n",
1130 ctx->error_depth,ctx->error,buf);
1137 case X509_V_ERR_CERT_NOT_YET_VALID:
1138 case X509_V_ERR_CERT_HAS_EXPIRED:
1139 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
1148 static unsigned char dh512_p[]={
1149 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
1150 0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
1151 0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
1152 0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
1153 0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
1154 0x47,0x74,0xE8,0x33,
1156 static unsigned char dh512_g[]={
1160 static DH *get_dh512(void)
1164 if ((dh=DH_new()) == NULL) return(NULL);
1165 dh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);
1166 dh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);
1167 if ((dh->p == NULL) || (dh->g == NULL))
1174 static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export, int keylength)
1176 static RSA *rsa_tmp=NULL;
1178 if (rsa_tmp == NULL)
1180 BIO_printf(bio_err,"Generating temp (%d bit) RSA key...",keylength);
1181 (void)BIO_flush(bio_err);
1182 rsa_tmp=RSA_generate_key(keylength,RSA_F4,NULL,NULL);
1183 BIO_printf(bio_err,"\n");
1184 (void)BIO_flush(bio_err);