2 /* Copyright (C) 1995-1997 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.]
62 #include <sys/types.h>
78 static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int export);
79 static int sv_body(char *hostname, int s);
80 static int www_body(char *hostname, int s);
81 static void close_accept_socket(void );
82 static void sv_usage(void);
83 static int init_ssl_connection(SSL *s);
84 static void print_stats(BIO *bp,SSL_CTX *ctx);
85 static DH *load_dh_param(void );
86 static DH *get_dh512(void);
88 static RSA MS_CALLBACK *tmp_rsa_cb();
90 static int www_body();
91 static void close_accept_socket();
92 static void sv_usage();
93 static int init_ssl_connection();
94 static void print_stats();
95 static DH *load_dh_param();
96 static DH *get_dh512();
101 #define S_ISDIR(a) (((a) & _S_IFMT) == _S_IFDIR)
104 static unsigned char dh512_p[]={
105 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,0xD0,0xE4,0xAF,0x75,
106 0x6F,0x4C,0xCA,0x92,0xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
107 0xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,0x57,0x46,0x50,0xD3,
108 0x69,0x99,0xDB,0x29,0xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
109 0xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,0xD8,0x00,0x3E,0x7C,
112 static unsigned char dh512_g[]={
116 static DH *get_dh512()
121 if ((dh=DH_new()) == NULL) return(NULL);
122 dh->p=BN_bin2bn(dh512_p,sizeof(dh512_p),NULL);
123 dh->g=BN_bin2bn(dh512_g,sizeof(dh512_g),NULL);
124 if ((dh->p == NULL) || (dh->g == NULL))
130 /* static int load_CA(SSL_CTX *ctx, char *file);*/
133 #define BUFSIZZ 8*1024
134 static int accept_socket= -1;
136 #define TEST_CERT "server.pem"
138 #define PROG s_server_main
140 #define DH_PARAM "server.pem"
142 extern int verify_depth;
144 static char *cipher=NULL;
145 int verify=SSL_VERIFY_NONE;
146 char *s_cert_file=TEST_CERT,*s_key_file=NULL;
150 static int s_nbio_test=0;
151 static SSL_CTX *ctx=NULL;
154 static BIO *bio_s_out=NULL;
155 static int s_debug=0;
156 static int s_quiet=0;
158 static void sv_usage()
160 BIO_printf(bio_err,"usage: s_server [args ...]\n");
161 BIO_printf(bio_err,"\n");
162 BIO_printf(bio_err," -accpet arg - port to accept on (default is %d\n",PORT);
163 BIO_printf(bio_err," -verify arg - turn on peer certificate verification\n");
164 BIO_printf(bio_err," -Verify arg - turn on peer certificate verification, must have a cert.\n");
165 BIO_printf(bio_err," -cert arg - certificate file to use, PEM format assumed\n");
166 BIO_printf(bio_err," (default is %s)\n",TEST_CERT);
167 BIO_printf(bio_err," -key arg - RSA file to use, PEM format assumed, in cert file if\n");
168 BIO_printf(bio_err," not specified (default is %s)\n",TEST_CERT);
170 BIO_printf(bio_err," -nbio - Run with non-blocking IO\n");
172 BIO_printf(bio_err," -nbio_test - test with the non-blocking test bio\n");
173 BIO_printf(bio_err," -debug - Print more output\n");
174 BIO_printf(bio_err," -state - Print the SSL states\n");
175 BIO_printf(bio_err," -CApath arg - PEM format directory of CA's\n");
176 BIO_printf(bio_err," -CAfile arg - PEM format file of CA's\n");
177 BIO_printf(bio_err," -nocert - Don't use any certificates (Anon-DH)\n");
178 BIO_printf(bio_err," -cipher arg - play with 'ssleay ciphers' to see what goes here\n");
179 BIO_printf(bio_err," -quiet - No server output\n");
180 BIO_printf(bio_err," -no_tmp_rsa - Do not generate a tmp RSA key\n");
181 BIO_printf(bio_err," -ssl2 - Just talk SSLv2\n");
182 BIO_printf(bio_err," -ssl3 - Just talk SSLv3\n");
183 BIO_printf(bio_err," -bugs - Turn on SSL bug compatability\n");
184 BIO_printf(bio_err," -www - Respond to a 'GET /' with a status page\n");
185 BIO_printf(bio_err," -WWW - Returns requested page from to a 'GET <path> HTTP/1.0'\n");
188 static int local_argc;
189 static char **local_argv;
197 char *CApath=NULL,*CAfile=NULL;
200 int no_tmp_rsa=0,nocert=0;
202 SSL_METHOD *meth=NULL;
205 #if !defined(NO_SSL2) && !defined(NO_SSL3)
206 meth=SSLv23_server_method();
207 #elif !defined(NO_SSL3)
208 meth=SSLv3_server_method();
209 #elif !defined(NO_SSL2)
210 meth=SSLv2_server_method();
221 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
234 if ((strcmp(*argv,"-port") == 0) ||
235 (strcmp(*argv,"-accept") == 0))
237 if (--argc < 1) goto bad;
238 if (!extract_port(*(++argv),&port))
241 else if (strcmp(*argv,"-verify") == 0)
243 verify=SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE;
244 if (--argc < 1) goto bad;
245 verify_depth=atoi(*(++argv));
246 BIO_printf(bio_err,"verify depth is %d\n",verify_depth);
248 else if (strcmp(*argv,"-Verify") == 0)
250 verify=SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT|
251 SSL_VERIFY_CLIENT_ONCE;
252 if (--argc < 1) goto bad;
253 verify_depth=atoi(*(++argv));
254 BIO_printf(bio_err,"verify depth is %d, must return a certificate\n",verify_depth);
256 else if (strcmp(*argv,"-cert") == 0)
258 if (--argc < 1) goto bad;
259 s_cert_file= *(++argv);
261 else if (strcmp(*argv,"-key") == 0)
263 if (--argc < 1) goto bad;
264 s_key_file= *(++argv);
266 else if (strcmp(*argv,"-nocert") == 0)
270 else if (strcmp(*argv,"-CApath") == 0)
272 if (--argc < 1) goto bad;
275 else if (strcmp(*argv,"-cipher") == 0)
277 if (--argc < 1) goto bad;
280 else if (strcmp(*argv,"-CAfile") == 0)
282 if (--argc < 1) goto bad;
286 else if (strcmp(*argv,"-nbio") == 0)
289 else if (strcmp(*argv,"-nbio_test") == 0)
296 else if (strcmp(*argv,"-debug") == 0)
298 else if (strcmp(*argv,"-hack") == 0)
300 else if (strcmp(*argv,"-state") == 0)
302 else if (strcmp(*argv,"-quiet") == 0)
304 else if (strcmp(*argv,"-bugs") == 0)
306 else if (strcmp(*argv,"-no_tmp_rsa") == 0)
308 else if (strcmp(*argv,"-www") == 0)
310 else if (strcmp(*argv,"-WWW") == 0)
313 else if (strcmp(*argv,"-ssl2") == 0)
314 { meth=SSLv2_server_method(); }
317 else if (strcmp(*argv,"-ssl3") == 0)
318 { meth=SSLv3_server_method(); }
322 BIO_printf(bio_err,"unknown option %s\n",*argv);
336 if (bio_s_out == NULL)
338 if (s_quiet && !s_debug)
340 bio_s_out=BIO_new(BIO_s_null());
344 if (bio_s_out == NULL)
345 bio_s_out=BIO_new_fp(stdout,BIO_NOCLOSE);
349 #if !defined(NO_RSA) || !defined(NO_DSA)
357 SSL_load_error_strings();
358 SSLeay_add_ssl_algorithms();
360 ctx=SSL_CTX_new(meth);
363 ERR_print_errors(bio_err);
367 if (bugs) SSL_CTX_set_options(ctx,SSL_OP_ALL);
368 if (hack) SSL_CTX_set_options(ctx,SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG);
369 if (hack) SSL_CTX_set_options(ctx,SSL_OP_NON_EXPORT_FIRST);
371 if (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);
374 if (cipher == NULL) cipher=getenv("SSL_CIPHER");
378 if (s_cert_file == NULL)
380 BIO_printf(bio_err,"You must specify a certificate file for the server to use\n");
385 if ((!SSL_CTX_load_verify_locations(ctx,CAfile,CApath)) ||
386 (!SSL_CTX_set_default_verify_paths(ctx)))
388 BIO_printf(bio_err,"X509_load_verify_locations\n");
389 ERR_print_errors(bio_err);
394 /* EAY EAY EAY evil hack */
398 BIO_printf(bio_s_out,"Setting temp DH parameters\n");
402 BIO_printf(bio_s_out,"Using default temp DH parameters\n");
405 BIO_flush(bio_s_out);
407 SSL_CTX_set_tmp_dh(ctx,dh);
411 if (!set_cert_stuff(ctx,s_cert_file,s_key_file))
415 SSL_CTX_set_tmp_rsa_callback(ctx,tmp_rsa_cb);
417 if (!no_tmp_rsa && SSL_CTX_need_tmp_RSA(ctx))
421 BIO_printf(bio_s_out,"Generating temp (512 bit) RSA key...");
422 BIO_flush(bio_s_out);
424 rsa=RSA_generate_key(512,RSA_F4,NULL);
426 if (!SSL_CTX_set_tmp_rsa(ctx,rsa))
428 ERR_print_errors(bio_err);
432 BIO_printf(bio_s_out,"\n");
437 SSL_CTX_set_cipher_list(ctx,cipher);
438 SSL_CTX_set_verify(ctx,verify,verify_callback);
440 SSL_CTX_set_client_CA_list(ctx,SSL_load_client_CA_file(s_cert_file));
442 BIO_printf(bio_s_out,"ACCEPT\n");
444 do_server(port,&accept_socket,www_body);
446 do_server(port,&accept_socket,sv_body);
447 print_stats(bio_s_out,ctx);
450 if (ctx != NULL) SSL_CTX_free(ctx);
451 if (bio_s_out != NULL)
459 static void print_stats(bio,ssl_ctx)
463 BIO_printf(bio,"%4ld items in the session cache\n",
464 SSL_CTX_sess_number(ssl_ctx));
465 BIO_printf(bio,"%4d client connects (SSL_connect())\n",
466 SSL_CTX_sess_connect(ssl_ctx));
467 BIO_printf(bio,"%4d client connects that finished\n",
468 SSL_CTX_sess_connect_good(ssl_ctx));
469 BIO_printf(bio,"%4d server accepts (SSL_accept())\n",
470 SSL_CTX_sess_accept(ssl_ctx));
471 BIO_printf(bio,"%4d server accepts that finished\n",
472 SSL_CTX_sess_accept_good(ssl_ctx));
473 BIO_printf(bio,"%4d session cache hits\n",SSL_CTX_sess_hits(ssl_ctx));
474 BIO_printf(bio,"%4d session cache misses\n",SSL_CTX_sess_misses(ssl_ctx));
475 BIO_printf(bio,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ssl_ctx));
476 BIO_printf(bio,"%4d callback cache hits\n",SSL_CTX_sess_cb_hits(ssl_ctx));
479 static int sv_body(hostname, s)
491 if ((buf=Malloc(BUFSIZZ)) == NULL)
493 BIO_printf(bio_err,"out of memory\n");
502 BIO_printf(bio_err,"turning on non blocking io\n");
503 socket_ioctl(s,FIONBIO,&sl);
508 con=(SSL *)SSL_new(ctx);
511 sbio=BIO_new_socket(s,BIO_NOCLOSE);
516 test=BIO_new(BIO_f_nbio_test());
517 sbio=BIO_push(test,sbio);
519 SSL_set_bio(con,sbio,sbio);
520 SSL_set_accept_state(con);
521 /* SSL_set_fd(con,s); */
526 BIO_set_callback(SSL_get_rbio(con),bio_dump_cb);
527 BIO_set_callback_arg(SSL_get_rbio(con),bio_s_out);
535 FD_SET(fileno(stdin),&readfds);
538 i=select(width,&readfds,NULL,NULL,NULL);
539 if (i <= 0) continue;
540 if (FD_ISSET(fileno(stdin),&readfds))
542 i=read(fileno(stdin),buf,BUFSIZZ);
545 if ((i <= 0) || (buf[0] == 'Q'))
547 BIO_printf(bio_s_out,"DONE\n");
549 close_accept_socket();
553 if ((i <= 0) || (buf[0] == 'q'))
555 BIO_printf(bio_s_out,"DONE\n");
557 /* close_accept_socket();
563 SSL_renegotiate(con);
566 strcpy(buf,"server side RE-NEGOTIATE\n");
571 SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,NULL);
572 SSL_renegotiate(con);
575 strcpy(buf,"server side RE-NEGOTIATE asking for client cert\n");
579 static char *str="Lets print some clear text\n";
580 BIO_write(SSL_get_wbio(con),str,strlen(str));
584 print_stats(bio_s_out,SSL_get_SSL_CTX(con));
590 /* should do a select for the write */
591 k=SSL_write(con,&(buf[l]),(unsigned int)i);
596 BIO_sock_should_retry(k))
598 BIO_printf(bio_s_out,"Write BLOCK\n");
603 ERR_print_errors(bio_err);
604 BIO_printf(bio_s_out,"DONE\n");
613 if (FD_ISSET(s,&readfds))
615 if (!SSL_is_init_finished(con))
617 i=init_ssl_connection(con);
632 i=SSL_read(con,(char *)buf,BUFSIZZ);
637 BIO_sock_should_retry(i))
639 BIO_printf(bio_s_out,"Read BLOCK\n");
643 ERR_print_errors(bio_err);
644 BIO_printf(bio_s_out,"DONE\n");
649 write(fileno(stdout),buf,
655 BIO_printf(bio_s_out,"shutting down SSL\n");
657 SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
661 if (con != NULL) SSL_free(con);
662 BIO_printf(bio_s_out,"CONNECTION CLOSED\n");
665 memset(buf,0,BUFSIZZ);
669 BIO_printf(bio_s_out,"ACCEPT\n");
673 static void close_accept_socket()
675 BIO_printf(bio_err,"shutdown accept socket\n");
676 if (accept_socket >= 0)
678 SHUTDOWN2(accept_socket);
682 static int init_ssl_connection(con)
689 MS_STATIC char buf[BUFSIZ];
691 if ((i=SSL_accept(con)) <= 0)
693 if (BIO_sock_should_retry(i))
695 BIO_printf(bio_s_out,"DELAY\n");
699 BIO_printf(bio_err,"ERROR\n");
700 verify_error=SSL_get_verify_result(con);
701 if (verify_error != X509_V_OK)
703 BIO_printf(bio_err,"verify error:%s\n",
704 X509_verify_cert_error_string(verify_error));
707 ERR_print_errors(bio_err);
711 PEM_write_bio_SSL_SESSION(bio_s_out,SSL_get_session(con));
713 peer=SSL_get_peer_certificate(con);
716 BIO_printf(bio_s_out,"Client certificate\n");
717 PEM_write_bio_X509(bio_s_out,peer);
718 X509_NAME_oneline(X509_get_subject_name(peer),buf,BUFSIZ);
719 BIO_printf(bio_s_out,"subject=%s\n",buf);
720 X509_NAME_oneline(X509_get_issuer_name(peer),buf,BUFSIZ);
721 BIO_printf(bio_s_out,"issuer=%s\n",buf);
725 if (SSL_get_shared_ciphers(con,buf,BUFSIZ) != NULL)
726 BIO_printf(bio_s_out,"Shared ciphers:%s\n",buf);
727 str=SSL_CIPHER_get_name(SSL_get_current_cipher(con));
728 BIO_printf(bio_s_out,"CIPHER is %s\n",(str != NULL)?str:"(NONE)");
729 if (con->hit) BIO_printf(bio_s_out,"Reused session-id\n");
733 static DH *load_dh_param()
739 if ((bio=BIO_new_file(DH_PARAM,"r")) == NULL)
741 ret=PEM_read_bio_DHparams(bio,NULL,NULL);
743 if (bio != NULL) BIO_free(bio);
749 static int load_CA(ctx,file)
756 if ((in=fopen(file,"r")) == NULL)
761 if (PEM_read_X509(in,&x,NULL) == NULL)
763 SSL_CTX_add_client_CA(ctx,x);
765 if (x != NULL) X509_free(x);
771 static int www_body(hostname, s)
781 BIO *io,*ssl_bio,*sbio;
783 io=BIO_new(BIO_f_buffer());
784 ssl_bio=BIO_new(BIO_f_ssl());
785 if ((io == NULL) || (ssl_bio == NULL)) goto err;
790 unsigned int long sl=1;
793 BIO_printf(bio_err,"turning on non blocking io\n");
794 socket_ioctl(s,FIONBIO,&sl);
798 /* lets make the output buffer a reasonable size */
799 if (!BIO_set_write_buffer_size(io,16*1024)) goto err;
801 if ((con=(SSL *)SSL_new(ctx)) == NULL) goto err;
803 sbio=BIO_new_socket(s,BIO_NOCLOSE);
808 test=BIO_new(BIO_f_nbio_test());
809 sbio=BIO_push(test,sbio);
811 SSL_set_bio(con,sbio,sbio);
812 SSL_set_accept_state(con);
814 /* SSL_set_fd(con,s); */
815 BIO_set_ssl(ssl_bio,con,BIO_CLOSE);
816 BIO_push(io,ssl_bio);
821 BIO_set_callback(SSL_get_rbio(con),bio_dump_cb);
822 BIO_set_callback_arg(SSL_get_rbio(con),bio_s_out);
832 switch (SSL_get_error(con,i))
836 case SSL_ERROR_WANT_WRITE:
837 case SSL_ERROR_WANT_READ:
838 case SSL_ERROR_WANT_X509_LOOKUP:
840 case SSL_ERROR_SYSCALL:
842 case SSL_ERROR_ZERO_RETURN:
848 SSL_renegotiate(con);
849 SSL_write(con,NULL,0);
852 i=BIO_gets(io,buf,sizeof(buf)-1);
853 if (i < 0) /* error */
855 if (!BIO_should_retry(io))
858 ERR_print_errors(bio_err);
863 BIO_printf(bio_s_out,"read R BLOCK\n");
870 else if (i == 0) /* end of input */
876 /* else we have data */
877 if ( ((www == 1) && (strncmp("GET ",buf,4) == 0)) ||
878 ((www == 2) && (strncmp("GET stats ",buf,10) == 0)))
883 static char *space=" ";
885 BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/html\r\n\r\n");
886 BIO_puts(io,"<pre>\n");
887 /* BIO_puts(io,SSLeay_version(SSLEAY_VERSION));*/
889 for (i=0; i<local_argc; i++)
891 BIO_puts(io,local_argv[i]);
896 /* The following is evil and should not really
898 BIO_printf(io,"Ciphers supported in s_server binary\n");
899 sk=SSL_get_ciphers(con);
903 c=(SSL_CIPHER *)sk_value(sk,i);
904 BIO_printf(io,"%s:%-25s",
905 SSL_CIPHER_get_version(c),
906 SSL_CIPHER_get_name(c));
907 if ((((i+1)%3) == 0) && (i+1 != j))
911 p=SSL_get_shared_ciphers(con,buf,sizeof(buf));
914 BIO_printf(io,"---\nCiphers common between both SSL end points:\n");
920 BIO_write(io,space,15-j);
923 BIO_write(io,((i%3)?" ":"\n"),1);
934 BIO_printf(io,((con->hit)
937 c=SSL_get_current_cipher(con);
938 BIO_printf(io,"SSLv%d, Cipher is %s\n",
939 SSL_CIPHER_get_version(c),
940 SSL_CIPHER_get_name(c));
941 SSL_SESSION_print(io,SSL_get_session(con));
942 BIO_printf(io,"---\n");
943 print_stats(io,SSL_get_SSL_CTX(con));
944 BIO_printf(io,"---\n");
945 peer=SSL_get_peer_certificate(con);
948 BIO_printf(io,"Client certificate\n");
950 PEM_write_bio_X509(io,peer);
953 BIO_puts(io,"no client certificate available\n");
956 else if ((www == 2) && (strncmp("GET ",buf,4) == 0))
960 static char *text="HTTP/1.0 200 ok\r\nContent-type: text/plain\r\n\r\n";
965 for (e=p; *e != '\0'; e++)
967 if (e[0] == ' ') break;
968 if ( (e[0] == '.') &&
969 (strncmp(&(e[-1]),"/../",4) == 0))
976 BIO_printf(io,"'%s' is an invalid file name\r\n",p);
984 BIO_printf(io,"'%s' contains '..' reference\r\n",p);
991 BIO_printf(io,"'%s' is an invalid path\r\n",p);
995 /* append if a directory lookup */
997 strcat(p,"index.html");
999 /* if a directory, do the index thang */
1000 if (stat(p,&st_buf) < 0)
1003 BIO_printf(io,"Error accessing '%s'\r\n",p);
1004 ERR_print_errors(io);
1007 if (S_ISDIR(st_buf.st_mode))
1009 strcat(p,"/index.html");
1012 if ((file=BIO_new_file(p,"r")) == NULL)
1015 BIO_printf(io,"Error opening '%s'\r\n",p);
1016 ERR_print_errors(io);
1021 BIO_printf(bio_err,"FILE:%s\n",p);
1024 if ( ((i > 5) && (strcmp(&(p[i-5]),".html") == 0)) ||
1025 ((i > 4) && (strcmp(&(p[i-4]),".php") == 0)) ||
1026 ((i > 4) && (strcmp(&(p[i-4]),".htm") == 0)))
1027 BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/html\r\n\r\n");
1029 BIO_puts(io,"HTTP/1.0 200 ok\r\nContent-type: text/plain\r\n\r\n");
1033 i=BIO_read(file,buf,1024);
1038 k=BIO_write(io,&(buf[j]),i-j);
1041 if (!BIO_should_retry(io))
1045 BIO_printf(bio_s_out,"rwrite W BLOCK\n");
1061 i=(int)BIO_flush(io);
1064 if (!BIO_should_retry(io))
1072 /* make sure we re-use sessions */
1073 SSL_set_shutdown(con,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
1075 /* This kills performace */
1082 BIO_printf(bio_s_out,"ACCEPT\n");
1084 if (io != NULL) BIO_free_all(io);
1085 /* if (ssl_bio != NULL) BIO_free(ssl_bio); */
1089 static RSA MS_CALLBACK *tmp_rsa_cb(s,export)
1093 static RSA *rsa_tmp=NULL;
1095 if (rsa_tmp == NULL)
1099 BIO_printf(bio_err,"Generating temp (512 bit) RSA key...");
1103 rsa_tmp=RSA_generate_key(512,RSA_F4,NULL);
1107 BIO_printf(bio_err,"\n");