Output prog name within error message
[openssl.git] / apps / s_server.c
index ebf772da07c8cba50ab63ffc6763daa25e21293c..22131bf84fe6d17cc15ba3ed889e428856ebd6b2 100644 (file)
@@ -717,7 +717,8 @@ typedef enum OPTION_choice {
     OPT_CRLF, OPT_QUIET, OPT_BRIEF, OPT_NO_DHE,
     OPT_NO_RESUME_EPHEMERAL, OPT_PSK_HINT, OPT_PSK, OPT_SRPVFILE,
     OPT_SRPUSERSEED, OPT_REV, OPT_WWW, OPT_UPPER_WWW, OPT_HTTP, OPT_ASYNC,
-    OPT_SSL_CONFIG, OPT_SPLIT_SEND_FRAG, OPT_MAX_PIPELINES, OPT_READ_BUF,
+    OPT_SSL_CONFIG, 
+    OPT_MAX_SEND_FRAG, OPT_SPLIT_SEND_FRAG, OPT_MAX_PIPELINES, OPT_READ_BUF,
     OPT_SSL3, OPT_TLS1_3, OPT_TLS1_2, OPT_TLS1_1, OPT_TLS1, OPT_DTLS, OPT_DTLS1,
     OPT_DTLS1_2, OPT_SCTP, OPT_TIMEOUT, OPT_MTU, OPT_LISTEN,
     OPT_ID_PREFIX, OPT_RAND, OPT_SERVERNAME, OPT_SERVERNAME_FATAL,
@@ -856,6 +857,7 @@ const OPTIONS s_server_options[] = {
     {"async", OPT_ASYNC, '-', "Operate in asynchronous mode"},
     {"ssl_config", OPT_SSL_CONFIG, 's',
      "Configure SSL_CTX using the configuration 'val'"},
+    {"max_send_frag", OPT_MAX_SEND_FRAG, 'p', "Maximum Size of send frames "},
     {"split_send_frag", OPT_SPLIT_SEND_FRAG, 'n',
      "Size used to split data for encrypt pipelines"},
     {"max_pipelines", OPT_MAX_PIPELINES, 'n',
@@ -999,6 +1001,7 @@ int s_server_main(int argc, char *argv[])
     int s_tlsextstatus = 0;
 #endif
     int no_resume_ephemeral = 0;
+    unsigned int max_send_fragment = 0;
     unsigned int split_send_fragment = 0, max_pipelines = 0;
     const char *s_serverinfo_file = NULL;
     const char *keylog_file = NULL;
@@ -1497,6 +1500,16 @@ int s_server_main(int argc, char *argv[])
         case OPT_ASYNC:
             async = 1;
             break;
+        case OPT_MAX_SEND_FRAG:
+            max_send_fragment = atoi(opt_arg());
+            if (max_send_fragment == 0) {
+                /*
+                 * Not allowed - set to a deliberately bad value so we get an
+                 * error message below
+                 */
+                max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH + 1;
+            }
+            break;
         case OPT_SPLIT_SEND_FRAG:
             split_send_fragment = atoi(opt_arg());
             if (split_send_fragment == 0) {
@@ -1561,14 +1574,18 @@ int s_server_main(int argc, char *argv[])
         socket_type = SOCK_STREAM;
     }
 #endif
+    if (max_send_fragment > SSL3_RT_MAX_PLAIN_LENGTH) {
+        BIO_printf(bio_err, "%s: Bad max send fragment size\n", prog);
+        goto end;
+    }
 
     if (split_send_fragment > SSL3_RT_MAX_PLAIN_LENGTH) {
-        BIO_printf(bio_err, "Bad split send fragment size\n");
+        BIO_printf(bio_err, "%s:Bad split send fragment size\n", prog);
         goto end;
     }
 
     if (max_pipelines > SSL_MAX_PIPELINES) {
-        BIO_printf(bio_err, "Bad max pipelines value\n");
+        BIO_printf(bio_err, "%s:too large max-pipelines value\n", prog);
         goto end;
     }
 
@@ -1760,6 +1777,10 @@ int s_server_main(int argc, char *argv[])
     if (async) {
         SSL_CTX_set_mode(ctx, SSL_MODE_ASYNC);
     }
+
+    if (max_send_fragment > 0)
+        SSL_CTX_set_max_send_fragment(ctx, max_send_fragment);
+
     if (split_send_fragment > 0) {
         SSL_CTX_set_split_send_fragment(ctx, split_send_fragment);
     }
@@ -2125,11 +2146,11 @@ static int sv_body(int s, int stype, int prot, unsigned char *context)
     struct timeval *timeoutp;
 #endif
 #ifndef OPENSSL_NO_DTLS
- #ifndef OPENSSL_NO_SCTP
+ifndef OPENSSL_NO_SCTP
     int isdtls = (stype == SOCK_DGRAM || prot == IPPROTO_SCTP);
- #else
+else
     int isdtls = (stype == SOCK_DGRAM);
- #endif
+endif
 #endif
 
     buf = app_malloc(bufsize, "server buffer");
@@ -2163,11 +2184,11 @@ static int sv_body(int s, int stype, int prot, unsigned char *context)
     }
 #ifndef OPENSSL_NO_DTLS
     if (isdtls) {
-#ifndef OPENSSL_NO_SCTP
+# ifndef OPENSSL_NO_SCTP
         if (prot == IPPROTO_SCTP)
             sbio = BIO_new_dgram_sctp(s, BIO_NOCLOSE);
         else
-#endif
+# endif
             sbio = BIO_new_dgram(s, BIO_NOCLOSE);
 
         if (enable_timeouts) {
@@ -2728,10 +2749,7 @@ static void print_connection_info(SSL *con)
     if (peer != NULL) {
         BIO_printf(bio_s_out, "Client certificate\n");
         PEM_write_bio_X509(bio_s_out, peer);
-        X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof buf);
-        BIO_printf(bio_s_out, "subject=%s\n", buf);
-        X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof buf);
-        BIO_printf(bio_s_out, "issuer=%s\n", buf);
+        dump_cert_text(bio_s_out, peer);
         X509_free(peer);
         peer = NULL;
     }