]> git.ipfire.org Git - thirdparty/openssl.git/blob - ssl/ssltest.c
New Configure option no-<cipher> (rsa, idea, rc5, ...).
[thirdparty/openssl.git] / ssl / ssltest.c
1 /* ssl/ssltest.c */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
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.
8 *
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).
15 *
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.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
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)"
40 *
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
51 * SUCH DAMAGE.
52 *
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.]
57 */
58
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <errno.h>
63 #include <openssl/e_os.h>
64 #include <openssl/bio.h>
65 #include <openssl/crypto.h>
66 #include <openssl/x509.h>
67 #include <openssl/ssl.h>
68 #include <openssl/err.h>
69 #ifdef WINDOWS
70 #include "../crypto/bio/bss_file.c"
71 #endif
72
73 #if defined(NO_RSA) && !defined(NO_SSL2)
74 #define NO_SSL2
75 #endif
76
77 #define TEST_SERVER_CERT "../apps/server.pem"
78 #define TEST_CLIENT_CERT "../apps/client.pem"
79
80 int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx);
81 #ifndef NO_RSA
82 static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int export,int keylength);
83 #endif
84 #ifndef NO_DH
85 static DH *get_dh512(void);
86 #endif
87 BIO *bio_err=NULL;
88 BIO *bio_stdout=NULL;
89
90 static char *cipher=NULL;
91 int verbose=0;
92 int debug=0;
93 #ifdef FIONBIO
94 static int s_nbio=0;
95 #endif
96
97
98 int doit(SSL *s_ssl,SSL *c_ssl,long bytes);
99 static void sv_usage(void)
100 {
101 fprintf(stderr,"usage: ssltest [args ...]\n");
102 fprintf(stderr,"\n");
103 fprintf(stderr," -server_auth - check server certificate\n");
104 fprintf(stderr," -client_auth - do client authentication\n");
105 fprintf(stderr," -v - more output\n");
106 fprintf(stderr," -d - debug output\n");
107 fprintf(stderr," -reuse - use session-id reuse\n");
108 fprintf(stderr," -num <val> - number of connections to perform\n");
109 fprintf(stderr," -bytes <val> - number of bytes to swap between client/server\n");
110 #ifndef NO_SSL2
111 fprintf(stderr," -ssl2 - use SSLv2\n");
112 #endif
113 #ifndef NO_SSL3
114 fprintf(stderr," -ssl3 - use SSLv3\n");
115 #endif
116 #ifndef NO_TLS1
117 fprintf(stderr," -tls1 - use TLSv1\n");
118 #endif
119 fprintf(stderr," -CApath arg - PEM format directory of CA's\n");
120 fprintf(stderr," -CAfile arg - PEM format file of CA's\n");
121 fprintf(stderr," -cert arg - Certificate file\n");
122 fprintf(stderr," -s_cert arg - Just the server certificate file\n");
123 fprintf(stderr," -c_cert arg - Just the client certificate file\n");
124 fprintf(stderr," -cipher arg - The cipher list\n");
125 }
126
127 int main(int argc, char *argv[])
128 {
129 char *CApath=NULL,*CAfile=NULL;
130 int badop=0;
131 int tls1=0,ssl2=0,ssl3=0,ret=1;
132 int client_auth=0;
133 int server_auth=0,i;
134 char *server_cert=TEST_SERVER_CERT;
135 char *client_cert=TEST_CLIENT_CERT;
136 SSL_CTX *s_ctx=NULL;
137 SSL_CTX *c_ctx=NULL;
138 SSL_METHOD *meth=NULL;
139 SSL *c_ssl,*s_ssl;
140 int number=1,reuse=0;
141 long bytes=1L;
142 SSL_CIPHER *ciph;
143 #ifndef NO_DH
144 DH *dh;
145 #endif
146
147 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
148 bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
149
150 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
151
152 argc--;
153 argv++;
154
155 while (argc >= 1)
156 {
157 if (strcmp(*argv,"-server_auth") == 0)
158 server_auth=1;
159 else if (strcmp(*argv,"-client_auth") == 0)
160 client_auth=1;
161 else if (strcmp(*argv,"-v") == 0)
162 verbose=1;
163 else if (strcmp(*argv,"-d") == 0)
164 debug=1;
165 else if (strcmp(*argv,"-reuse") == 0)
166 reuse=1;
167 else if (strcmp(*argv,"-ssl2") == 0)
168 ssl2=1;
169 else if (strcmp(*argv,"-tls1") == 0)
170 tls1=1;
171 else if (strcmp(*argv,"-ssl3") == 0)
172 ssl3=1;
173 else if (strncmp(*argv,"-num",4) == 0)
174 {
175 if (--argc < 1) goto bad;
176 number= atoi(*(++argv));
177 if (number == 0) number=1;
178 }
179 else if (strcmp(*argv,"-bytes") == 0)
180 {
181 if (--argc < 1) goto bad;
182 bytes= atol(*(++argv));
183 if (bytes == 0L) bytes=1L;
184 i=strlen(argv[0]);
185 if (argv[0][i-1] == 'k') bytes*=1024L;
186 if (argv[0][i-1] == 'm') bytes*=1024L*1024L;
187 }
188 else if (strcmp(*argv,"-cert") == 0)
189 {
190 if (--argc < 1) goto bad;
191 server_cert= *(++argv);
192 }
193 else if (strcmp(*argv,"-s_cert") == 0)
194 {
195 if (--argc < 1) goto bad;
196 server_cert= *(++argv);
197 }
198 else if (strcmp(*argv,"-c_cert") == 0)
199 {
200 if (--argc < 1) goto bad;
201 client_cert= *(++argv);
202 }
203 else if (strcmp(*argv,"-cipher") == 0)
204 {
205 if (--argc < 1) goto bad;
206 cipher= *(++argv);
207 }
208 else if (strcmp(*argv,"-CApath") == 0)
209 {
210 if (--argc < 1) goto bad;
211 CApath= *(++argv);
212 }
213 else if (strcmp(*argv,"-CAfile") == 0)
214 {
215 if (--argc < 1) goto bad;
216 CAfile= *(++argv);
217 }
218 else
219 {
220 fprintf(stderr,"unknown option %s\n",*argv);
221 badop=1;
222 break;
223 }
224 argc--;
225 argv++;
226 }
227 if (badop)
228 {
229 bad:
230 sv_usage();
231 goto end;
232 }
233
234 /* if (cipher == NULL) cipher=getenv("SSL_CIPHER"); */
235
236 SSL_library_init();
237 SSL_load_error_strings();
238
239 #if !defined(NO_SSL2) && !defined(NO_SSL3)
240 if (ssl2)
241 meth=SSLv2_method();
242 else
243 if (tls1)
244 meth=TLSv1_method();
245 else
246 if (ssl3)
247 meth=SSLv3_method();
248 else
249 meth=SSLv23_method();
250 #else
251 #ifdef NO_SSL2
252 meth=SSLv3_method();
253 #else
254 meth=SSLv2_method();
255 #endif
256 #endif
257
258 c_ctx=SSL_CTX_new(meth);
259 s_ctx=SSL_CTX_new(meth);
260 if ((c_ctx == NULL) || (s_ctx == NULL))
261 {
262 ERR_print_errors(bio_err);
263 goto end;
264 }
265
266 if (cipher != NULL)
267 {
268 SSL_CTX_set_cipher_list(c_ctx,cipher);
269 SSL_CTX_set_cipher_list(s_ctx,cipher);
270 }
271
272 #ifndef NO_DH
273 dh=get_dh512();
274 SSL_CTX_set_tmp_dh(s_ctx,dh);
275 DH_free(dh);
276 #endif
277
278 #ifndef NO_RSA
279 SSL_CTX_set_tmp_rsa_callback(s_ctx,tmp_rsa_cb);
280 #endif
281
282 if (!SSL_CTX_use_certificate_file(s_ctx,server_cert,SSL_FILETYPE_PEM))
283 {
284 ERR_print_errors(bio_err);
285 }
286 else if (!SSL_CTX_use_PrivateKey_file(s_ctx,server_cert,
287 SSL_FILETYPE_PEM))
288 {
289 ERR_print_errors(bio_err);
290 goto end;
291 }
292
293 if (client_auth)
294 {
295 SSL_CTX_use_certificate_file(c_ctx,client_cert,
296 SSL_FILETYPE_PEM);
297 SSL_CTX_use_PrivateKey_file(c_ctx,client_cert,
298 SSL_FILETYPE_PEM);
299 }
300
301 if ( (!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) ||
302 (!SSL_CTX_set_default_verify_paths(s_ctx)) ||
303 (!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) ||
304 (!SSL_CTX_set_default_verify_paths(c_ctx)))
305 {
306 /* fprintf(stderr,"SSL_load_verify_locations\n"); */
307 ERR_print_errors(bio_err);
308 /* goto end; */
309 }
310
311 if (client_auth)
312 {
313 fprintf(stderr,"client authentication\n");
314 SSL_CTX_set_verify(s_ctx,
315 SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
316 verify_callback);
317 }
318 if (server_auth)
319 {
320 fprintf(stderr,"server authentication\n");
321 SSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER,
322 verify_callback);
323 }
324
325 c_ssl=SSL_new(c_ctx);
326 s_ssl=SSL_new(s_ctx);
327
328 for (i=0; i<number; i++)
329 {
330 if (!reuse) SSL_set_session(c_ssl,NULL);
331 ret=doit(s_ssl,c_ssl,bytes);
332 }
333
334 if (!verbose)
335 {
336 ciph=SSL_get_current_cipher(c_ssl);
337 fprintf(stdout,"Protocol %s, cipher %s, %s\n",
338 SSL_get_version(c_ssl),
339 SSL_CIPHER_get_version(ciph),
340 SSL_CIPHER_get_name(ciph));
341 }
342 if ((number > 1) || (bytes > 1L))
343 printf("%d handshakes of %ld bytes done\n",number,bytes);
344
345 SSL_free(s_ssl);
346 SSL_free(c_ssl);
347
348 end:
349 if (s_ctx != NULL) SSL_CTX_free(s_ctx);
350 if (c_ctx != NULL) SSL_CTX_free(c_ctx);
351
352 if (bio_stdout != NULL) BIO_free(bio_stdout);
353
354 ERR_free_strings();
355 ERR_remove_state(0);
356 EVP_cleanup();
357 CRYPTO_mem_leaks(bio_err);
358 EXIT(ret);
359 }
360
361 #define W_READ 1
362 #define W_WRITE 2
363 #define C_DONE 1
364 #define S_DONE 2
365
366 int doit(SSL *s_ssl, SSL *c_ssl, long count)
367 {
368 MS_STATIC char cbuf[1024*8],sbuf[1024*8];
369 long cw_num=count,cr_num=count;
370 long sw_num=count,sr_num=count;
371 int ret=1;
372 BIO *c_to_s=NULL;
373 BIO *s_to_c=NULL;
374 BIO *c_bio=NULL;
375 BIO *s_bio=NULL;
376 int c_r,c_w,s_r,s_w;
377 int c_want,s_want;
378 int i,j;
379 int done=0;
380 int c_write,s_write;
381 int do_server=0,do_client=0;
382 SSL_CIPHER *ciph;
383
384 c_to_s=BIO_new(BIO_s_mem());
385 s_to_c=BIO_new(BIO_s_mem());
386 if ((s_to_c == NULL) || (c_to_s == NULL))
387 {
388 ERR_print_errors(bio_err);
389 goto err;
390 }
391
392 c_bio=BIO_new(BIO_f_ssl());
393 s_bio=BIO_new(BIO_f_ssl());
394 if ((c_bio == NULL) || (s_bio == NULL))
395 {
396 ERR_print_errors(bio_err);
397 goto err;
398 }
399
400 SSL_set_connect_state(c_ssl);
401 SSL_set_bio(c_ssl,s_to_c,c_to_s);
402 BIO_set_ssl(c_bio,c_ssl,BIO_NOCLOSE);
403
404 SSL_set_accept_state(s_ssl);
405 SSL_set_bio(s_ssl,c_to_s,s_to_c);
406 BIO_set_ssl(s_bio,s_ssl,BIO_NOCLOSE);
407
408 c_r=0; s_r=1;
409 c_w=1; s_w=0;
410 c_want=W_WRITE;
411 s_want=0;
412 c_write=1,s_write=0;
413
414 /* We can always do writes */
415 for (;;)
416 {
417 do_server=0;
418 do_client=0;
419
420 i=(int)BIO_pending(s_bio);
421 if ((i && s_r) || s_w) do_server=1;
422
423 i=(int)BIO_pending(c_bio);
424 if ((i && c_r) || c_w) do_client=1;
425
426 if (do_server && debug)
427 {
428 if (SSL_in_init(s_ssl))
429 printf("server waiting in SSL_accept - %s\n",
430 SSL_state_string_long(s_ssl));
431 /* else if (s_write)
432 printf("server:SSL_write()\n");
433 else
434 printf("server:SSL_read()\n"); */
435 }
436
437 if (do_client && debug)
438 {
439 if (SSL_in_init(c_ssl))
440 printf("client waiting in SSL_connect - %s\n",
441 SSL_state_string_long(c_ssl));
442 /* else if (c_write)
443 printf("client:SSL_write()\n");
444 else
445 printf("client:SSL_read()\n"); */
446 }
447
448 if (!do_client && !do_server)
449 {
450 fprintf(stdout,"ERROR IN STARTUP\n");
451 ERR_print_errors(bio_err);
452 break;
453 }
454 if (do_client && !(done & C_DONE))
455 {
456 if (c_write)
457 {
458 j=(cw_num > (long)sizeof(cbuf))
459 ?sizeof(cbuf):(int)cw_num;
460 i=BIO_write(c_bio,cbuf,j);
461 if (i < 0)
462 {
463 c_r=0;
464 c_w=0;
465 if (BIO_should_retry(c_bio))
466 {
467 if (BIO_should_read(c_bio))
468 c_r=1;
469 if (BIO_should_write(c_bio))
470 c_w=1;
471 }
472 else
473 {
474 fprintf(stderr,"ERROR in CLIENT\n");
475 ERR_print_errors(bio_err);
476 goto err;
477 }
478 }
479 else if (i == 0)
480 {
481 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
482 goto err;
483 }
484 else
485 {
486 if (debug)
487 printf("client wrote %d\n",i);
488 /* ok */
489 s_r=1;
490 c_write=0;
491 cw_num-=i;
492 }
493 }
494 else
495 {
496 i=BIO_read(c_bio,cbuf,sizeof(cbuf));
497 if (i < 0)
498 {
499 c_r=0;
500 c_w=0;
501 if (BIO_should_retry(c_bio))
502 {
503 if (BIO_should_read(c_bio))
504 c_r=1;
505 if (BIO_should_write(c_bio))
506 c_w=1;
507 }
508 else
509 {
510 fprintf(stderr,"ERROR in CLIENT\n");
511 ERR_print_errors(bio_err);
512 goto err;
513 }
514 }
515 else if (i == 0)
516 {
517 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
518 goto err;
519 }
520 else
521 {
522 if (debug)
523 printf("client read %d\n",i);
524 cr_num-=i;
525 if (sw_num > 0)
526 {
527 s_write=1;
528 s_w=1;
529 }
530 if (cr_num <= 0)
531 {
532 s_write=1;
533 s_w=1;
534 done=S_DONE|C_DONE;
535 }
536 }
537 }
538 }
539
540 if (do_server && !(done & S_DONE))
541 {
542 if (!s_write)
543 {
544 i=BIO_read(s_bio,sbuf,sizeof(cbuf));
545 if (i < 0)
546 {
547 s_r=0;
548 s_w=0;
549 if (BIO_should_retry(s_bio))
550 {
551 if (BIO_should_read(s_bio))
552 s_r=1;
553 if (BIO_should_write(s_bio))
554 s_w=1;
555 }
556 else
557 {
558 fprintf(stderr,"ERROR in SERVER\n");
559 ERR_print_errors(bio_err);
560 goto err;
561 }
562 }
563 else if (i == 0)
564 {
565 ERR_print_errors(bio_err);
566 fprintf(stderr,"SSL SERVER STARTUP FAILED in SSL_read\n");
567 goto err;
568 }
569 else
570 {
571 if (debug)
572 printf("server read %d\n",i);
573 sr_num-=i;
574 if (cw_num > 0)
575 {
576 c_write=1;
577 c_w=1;
578 }
579 if (sr_num <= 0)
580 {
581 s_write=1;
582 s_w=1;
583 c_write=0;
584 }
585 }
586 }
587 else
588 {
589 j=(sw_num > (long)sizeof(sbuf))?
590 sizeof(sbuf):(int)sw_num;
591 i=BIO_write(s_bio,sbuf,j);
592 if (i < 0)
593 {
594 s_r=0;
595 s_w=0;
596 if (BIO_should_retry(s_bio))
597 {
598 if (BIO_should_read(s_bio))
599 s_r=1;
600 if (BIO_should_write(s_bio))
601 s_w=1;
602 }
603 else
604 {
605 fprintf(stderr,"ERROR in SERVER\n");
606 ERR_print_errors(bio_err);
607 goto err;
608 }
609 }
610 else if (i == 0)
611 {
612 ERR_print_errors(bio_err);
613 fprintf(stderr,"SSL SERVER STARTUP FAILED in SSL_write\n");
614 goto err;
615 }
616 else
617 {
618 if (debug)
619 printf("server wrote %d\n",i);
620 sw_num-=i;
621 s_write=0;
622 c_r=1;
623 if (sw_num <= 0)
624 done|=S_DONE;
625 }
626 }
627 }
628
629 if ((done & S_DONE) && (done & C_DONE)) break;
630 }
631
632 ciph=SSL_get_current_cipher(c_ssl);
633 if (verbose)
634 fprintf(stdout,"DONE, protocol %s, cipher %s, %s\n",
635 SSL_get_version(c_ssl),
636 SSL_CIPHER_get_version(ciph),
637 SSL_CIPHER_get_name(ciph));
638 ret=0;
639 err:
640 /* We have to set the BIO's to NULL otherwise they will be
641 * Free()ed twice. Once when th s_ssl is SSL_free()ed and
642 * again when c_ssl is SSL_free()ed.
643 * This is a hack required because s_ssl and c_ssl are sharing the same
644 * BIO structure and SSL_set_bio() and SSL_free() automatically
645 * BIO_free non NULL entries.
646 * You should not normally do this or be required to do this */
647 if (s_ssl != NULL)
648 {
649 s_ssl->rbio=NULL;
650 s_ssl->wbio=NULL;
651 }
652 if (c_ssl != NULL)
653 {
654 c_ssl->rbio=NULL;
655 c_ssl->wbio=NULL;
656 }
657
658 if (c_to_s != NULL) BIO_free(c_to_s);
659 if (s_to_c != NULL) BIO_free(s_to_c);
660 if (c_bio != NULL) BIO_free_all(c_bio);
661 if (s_bio != NULL) BIO_free_all(s_bio);
662 return(ret);
663 }
664
665 int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
666 {
667 char *s,buf[256];
668
669 s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),buf,256);
670 if (s != NULL)
671 {
672 if (ok)
673 fprintf(stderr,"depth=%d %s\n",ctx->error_depth,buf);
674 else
675 fprintf(stderr,"depth=%d error=%d %s\n",
676 ctx->error_depth,ctx->error,buf);
677 }
678
679 if (ok == 0)
680 {
681 switch (ctx->error)
682 {
683 case X509_V_ERR_CERT_NOT_YET_VALID:
684 case X509_V_ERR_CERT_HAS_EXPIRED:
685 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
686 ok=1;
687 }
688 }
689
690 return(ok);
691 }
692
693 #ifndef NO_DH
694 static unsigned char dh512_p[]={
695 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
696 0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
697 0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
698 0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
699 0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
700 0x47,0x74,0xE8,0x33,
701 };
702 static unsigned char dh512_g[]={
703 0x02,
704 };
705
706 static DH *get_dh512(void)
707 {
708 DH *dh=NULL;
709
710 if ((dh=DH_new()) == NULL) return(NULL);
711 dh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);
712 dh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);
713 if ((dh->p == NULL) || (dh->g == NULL))
714 return(NULL);
715 return(dh);
716 }
717 #endif
718
719 #ifndef NO_RSA
720 static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int export, int keylength)
721 {
722 static RSA *rsa_tmp=NULL;
723
724 if (rsa_tmp == NULL)
725 {
726 BIO_printf(bio_err,"Generating temp (%d bit) RSA key...",keylength);
727 BIO_flush(bio_err);
728 rsa_tmp=RSA_generate_key(keylength,RSA_F4,NULL,NULL);
729 BIO_printf(bio_err,"\n");
730 BIO_flush(bio_err);
731 }
732 return(rsa_tmp);
733 }
734 #endif