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