]> diplodocus.org Git - nmh/commitdiff
Report on the TLS negotation time
authorKen Hornstein <kenh@pobox.com>
Wed, 1 Nov 2017 18:00:18 +0000 (14:00 -0400)
committerKen Hornstein <kenh@pobox.com>
Thu, 2 Nov 2017 03:46:51 +0000 (23:46 -0400)
uip/imaptest.c

index 01d3ee5..befedab 100644 (file)
@@ -81,6 +81,7 @@ static int get_imap_response(netsec_context *, const char *token,
 
 static void ts_report(struct timeval *tv, const char *fmt, ...)
                      CHECK_PRINTF(2, 3);
 
 static void ts_report(struct timeval *tv, const char *fmt, ...)
                      CHECK_PRINTF(2, 3);
+static void imap_negotiate_tls(netsec_context *);
 
 static void add_msg(bool queue, const char *fmt, ...) CHECK_PRINTF(2, 3);
 
 
 static void add_msg(bool queue, const char *fmt, ...) CHECK_PRINTF(2, 3);
 
@@ -220,8 +221,8 @@ main (int argc, char **argv)
        if (netsec_set_tls(nsc, 1, 0, &errstr) != OK)
            die("%s", errstr);
 
        if (netsec_set_tls(nsc, 1, 0, &errstr) != OK)
            die("%s", errstr);
 
-       if (initialtls && netsec_negotiate_tls(nsc, &errstr) != OK)
-           die("%s", errstr);
+       if (initialtls)
+           imap_negotiate_tls(nsc);
     }
 
     if (sasl) {
     }
 
     if (sasl) {
@@ -296,9 +297,8 @@ main (int argc, char **argv)
            fprintf(stderr, "STARTTLS failed: %s\n", errstr);
            goto finish;
        }
            fprintf(stderr, "STARTTLS failed: %s\n", errstr);
            goto finish;
        }
-       if (netsec_negotiate_tls(nsc, &errstr) != OK) {
-           die("%s", errstr);
-       }
+
+       imap_negotiate_tls(nsc);
     }
 
     if (sasl) {
     }
 
     if (sasl) {
@@ -790,6 +790,26 @@ add_msg(bool queue, const char *fmt, ...)
     }
 }
 
     }
 }
 
+/*
+ * Negotiate TLS connection, with optional timestamp
+ */
+
+static void
+imap_negotiate_tls(netsec_context *nsc)
+{
+    char *errstr;
+    struct timeval tv;
+
+    if (timestamp)
+       gettimeofday(&tv, NULL);
+
+    if (netsec_negotiate_tls(nsc, &errstr) != OK)
+           die("%s", errstr);
+
+    if (timestamp)
+       ts_report(&tv, "TLS negotation time");
+}
+
 /*
  * Give a timestamp report.
  */
 /*
  * Give a timestamp report.
  */