RT3548: Remove unsupported platforms
[openssl.git] / apps / s_server.c
index 4b93fdefa2240ab2fe3b5e31a57e913f5be78cc1..412091dd11c11b233497c342ab6840cfab783abf 100644 (file)
  * OTHERWISE.
  */
 
-/* Until the key-gen callbacks are modified to use newer prototypes, we allow
- * deprecated functions for openssl-internal code */
-#ifdef OPENSSL_NO_DEPRECATED
-#undef OPENSSL_NO_DEPRECATED
-#endif
 
 #include <assert.h>
 #include <ctype.h>
 #include <string.h>
 
 #include <openssl/e_os2.h>
-#ifdef OPENSSL_NO_STDIO
-#define APPS_WIN16
-#endif
 
 #if !defined(OPENSSL_SYS_NETWARE)  /* conflicts with winsock2 stuff on netware */
 #include <sys/types.h>
@@ -197,12 +189,8 @@ typedef unsigned int u_int;
 #undef FIONBIO
 #endif
 
-#if defined(OPENSSL_SYS_BEOS_R5)
-#include <fcntl.h>
-#endif
-
 #ifndef OPENSSL_NO_RSA
-static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export, int keylength);
+static RSA *tmp_rsa_cb(SSL *s, int is_export, int keylength);
 #endif
 static int not_resumable_sess_cb(SSL *s, int is_forward_secure);
 static int sv_body(char *hostname, int s, int stype, unsigned char *context);
@@ -376,7 +364,7 @@ typedef struct srpsrvparm_st
    (which would normally occur after a worker has finished) and we
    set the user parameters. 
 */
-static int MS_CALLBACK ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)
+static int ssl_srp_server_param_cb(SSL *s, int *ad, void *arg)
        {
        srpsrvparm *p = (srpsrvparm *)arg;
        if (p->login == NULL && p->user == NULL )
@@ -508,8 +496,9 @@ static void sv_usage(void)
        BIO_printf(bio_err," -srpvfile file      - The verifier file for SRP\n");
        BIO_printf(bio_err," -srpuserseed string - A seed string for a default user salt.\n");
 #endif
-       BIO_printf(bio_err," -ssl2         - Just talk SSLv2\n");
+#ifndef OPENSSL_NO_SSL3_METHOD
        BIO_printf(bio_err," -ssl3         - Just talk SSLv3\n");
+#endif
        BIO_printf(bio_err," -tls1_2       - Just talk TLSv1.2\n");
        BIO_printf(bio_err," -tls1_1       - Just talk TLSv1.1\n");
        BIO_printf(bio_err," -tls1         - Just talk TLSv1\n");
@@ -518,7 +507,6 @@ static void sv_usage(void)
        BIO_printf(bio_err," -timeout      - Enable timeouts\n");
        BIO_printf(bio_err," -mtu          - Set link layer MTU\n");
        BIO_printf(bio_err," -chain        - Read a certificate chain\n");
-       BIO_printf(bio_err," -no_ssl2      - Just disable SSLv2\n");
        BIO_printf(bio_err," -no_ssl3      - Just disable SSLv3\n");
        BIO_printf(bio_err," -no_tls1      - Just disable TLSv1\n");
        BIO_printf(bio_err," -no_tls1_1    - Just disable TLSv1.1\n");
@@ -554,7 +542,9 @@ static void sv_usage(void)
 # ifndef OPENSSL_NO_NEXTPROTONEG
        BIO_printf(bio_err," -nextprotoneg arg - set the advertised protocols for the NPN extension (comma-separated list)\n");
 # endif
+# ifndef OPENSSL_NO_SRTP
         BIO_printf(bio_err," -use_srtp profiles - Offer SRTP key management with a colon-separated profile list\n");
+# endif
        BIO_printf(bio_err," -alpn arg  - set the advertised protocols for the ALPN extension (comma-separated list)\n");
 #endif
        BIO_printf(bio_err," -keymatexport label   - Export keying material using label\n");
@@ -728,7 +718,7 @@ typedef struct tlsextctx_st {
 } tlsextctx;
 
 
-static int MS_CALLBACK ssl_servername_cb(SSL *s, int *ad, void *arg)
+static int ssl_servername_cb(SSL *s, int *ad, void *arg)
        {
        tlsextctx * p = (tlsextctx *) arg;
        const char * servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name);
@@ -974,7 +964,9 @@ static char *jpake_secret = NULL;
 #ifndef OPENSSL_NO_SRP
        static srpsrvparm srp_callback_parm;
 #endif
+#ifndef OPENSSL_NO_SRTP
 static char *srtp_profiles = NULL;
+#endif
 
 int MAIN(int argc, char *argv[])
        {
@@ -1404,11 +1396,7 @@ int MAIN(int argc, char *argv[])
                        { www=2; }
                else if (strcmp(*argv,"-HTTP") == 0)
                        { www=3; }
-#ifndef OPENSSL_NO_SSL2
-               else if (strcmp(*argv,"-ssl2") == 0)
-                       { meth=SSLv2_server_method(); }
-#endif
-#ifndef OPENSSL_NO_SSL3
+#ifndef OPENSSL_NO_SSL3_METHOD
                else if (strcmp(*argv,"-ssl3") == 0)
                        { meth=SSLv3_server_method(); }
 #endif
@@ -1501,11 +1489,13 @@ int MAIN(int argc, char *argv[])
                        jpake_secret = *(++argv);
                        }
 #endif
+#ifndef OPENSSL_NO_SRTP
                else if (strcmp(*argv,"-use_srtp") == 0)
                        {
                        if (--argc < 1) goto bad;
                        srtp_profiles = *(++argv);
                        }
+#endif
                else if (strcmp(*argv,"-keymatexport") == 0)
                        {
                        if (--argc < 1) goto bad;
@@ -1763,9 +1753,6 @@ bad:
                if(strlen(session_id_prefix) >= 32)
                        BIO_printf(bio_err,
 "warning: id_prefix is too long, only one new session will be possible\n");
-               else if(strlen(session_id_prefix) >= 16)
-                       BIO_printf(bio_err,
-"warning: id_prefix is too long if you use SSLv2\n");
                if(!SSL_CTX_set_generate_session_id(ctx, generate_session_id))
                        {
                        BIO_printf(bio_err,"error setting 'id_prefix'\n");
@@ -1790,8 +1777,10 @@ bad:
        else
                SSL_CTX_sess_set_cache_size(ctx,128);
 
+#ifndef OPENSSL_NO_SRTP
        if (srtp_profiles != NULL)
                SSL_CTX_set_tlsext_use_srtp(ctx, srtp_profiles);
+#endif
 
 #if 0
        if (cipher == NULL) cipher=getenv("SSL_CIPHER");
@@ -1850,9 +1839,6 @@ bad:
                        if(strlen(session_id_prefix) >= 32)
                                BIO_printf(bio_err,
                                        "warning: id_prefix is too long, only one new session will be possible\n");
-                       else if(strlen(session_id_prefix) >= 16)
-                               BIO_printf(bio_err,
-                                       "warning: id_prefix is too long if you use SSLv2\n");
                        if(!SSL_CTX_set_generate_session_id(ctx2, generate_session_id))
                                {
                                BIO_printf(bio_err,"error setting 'id_prefix'\n");
@@ -2224,7 +2210,7 @@ static int sv_body(char *hostname, int s, int stype, unsigned char *context)
        KSSL_CTX *kctx;
 #endif
        struct timeval timeout;
-#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS_R5)
+#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)
        struct timeval tv;
 #else
        struct timeval *timeoutp;
@@ -2297,10 +2283,24 @@ static int sv_body(char *hostname, int s, int stype, unsigned char *context)
                        BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);
                        }
 
-               if (socket_mtu > 28)
+               if (socket_mtu)
                        {
+                       if(socket_mtu < DTLS_get_link_min_mtu(con))
+                               {
+                               BIO_printf(bio_err,"MTU too small. Must be at least %ld\n",
+                                       DTLS_get_link_min_mtu(con));
+                               ret = -1;
+                               BIO_free(sbio);
+                               goto err;
+                               }
                        SSL_set_options(con, SSL_OP_NO_QUERY_MTU);
-                       SSL_set_mtu(con, socket_mtu - 28);
+                       if(!DTLS_set_link_mtu(con, socket_mtu))
+                               {
+                               BIO_printf(bio_err, "Failed to set MTU\n");
+                               ret = -1;
+                               BIO_free(sbio);
+                               goto err;
+                               }
                        }
                else
                        /* want to do MTU discovery */
@@ -2364,7 +2364,7 @@ static int sv_body(char *hostname, int s, int stype, unsigned char *context)
                if (!read_from_sslcon)
                        {
                        FD_ZERO(&readfds);
-#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE) && !defined(OPENSSL_SYS_BEOS_R5)
+#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)
                        openssl_fdset(fileno(stdin),&readfds);
 #endif
                        openssl_fdset(s,&readfds);
@@ -2386,17 +2386,6 @@ static int sv_body(char *hostname, int s, int stype, unsigned char *context)
                        if((i < 0) || (!i && !_kbhit() ) )continue;
                        if(_kbhit())
                                read_from_terminal = 1;
-#elif defined(OPENSSL_SYS_BEOS_R5)
-                       /* Under BeOS-R5 the situation is similar to DOS */
-                       tv.tv_sec = 1;
-                       tv.tv_usec = 0;
-                       (void)fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
-                       i=select(width,(void *)&readfds,NULL,NULL,&tv);
-                       if ((i < 0) || (!i && read(fileno(stdin), buf, 0) < 0))
-                               continue;
-                       if (read(fileno(stdin), buf, 0) >= 0)
-                               read_from_terminal = 1;
-                       (void)fcntl(fileno(stdin), F_SETFL, 0);
 #else
                        if ((SSL_version(con) == DTLS1_VERSION) &&
                                DTLSv1_get_timeout(con, &timeout))
@@ -2743,6 +2732,7 @@ static int init_ssl_connection(SSL *con)
                BIO_printf(bio_s_out, "\n");
                }
 #endif
+#ifndef OPENSSL_NO_SRTP
        {
        SRTP_PROTECTION_PROFILE *srtp_profile
          = SSL_get_selected_srtp_profile(con);
@@ -2751,6 +2741,7 @@ static int init_ssl_connection(SSL *con)
                BIO_printf(bio_s_out,"SRTP Extension negotiated, profile=%s\n",
                           srtp_profile->name);
        }
+#endif
        if (SSL_cache_hit(con)) BIO_printf(bio_s_out,"Reused session-id\n");
        if (SSL_ctrl(con,SSL_CTRL_GET_FLAGS,0,NULL) &
                TLS1_FLAGS_TLS_PADDING_BUG)
@@ -2971,7 +2962,7 @@ static int www_body(char *hostname, int s, int stype, unsigned char *context)
                                BIO_printf(bio_s_out,"read R BLOCK\n");
 #if defined(OPENSSL_SYS_NETWARE)
             delay(1000);
-#elif !defined(OPENSSL_SYS_MSDOS) && !defined(__DJGPP__)
+#elif !defined(OPENSSL_SYS_MSDOS)
                                sleep(1);
 #endif
                                continue;
@@ -3417,7 +3408,7 @@ err:
        }
 
 #ifndef OPENSSL_NO_RSA
-static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export, int keylength)
+static RSA *tmp_rsa_cb(SSL *s, int is_export, int keylength)
        {
        BIGNUM *bn = NULL;
        static RSA *rsa_tmp=NULL;