]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
danetool/gnutls-cli-debug: added support for imap starttls
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 9 Aug 2014 08:22:40 +0000 (10:22 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Sat, 9 Aug 2014 08:22:40 +0000 (10:22 +0200)
src/cli-debug-args.def
src/danetool-args.def
src/socket.c

index 45b01047d01036614590caa3a8e69b2ae8ce68fc..93651861b4bc18e2b9c18c4d6558d08450779b7c 100644 (file)
@@ -29,7 +29,7 @@ flag = {
 flag = {
     name      = app-proto;
     arg-type  = string;
-    descrip   = "The application protocol to be used to obtain the server's certificate (https, smtp)";
+    descrip   = "The application protocol to be used to obtain the server's certificate (https, smtp, imap)";
     doc      = "";
 };
 
index 5185e7190f3aac566a9bcb31b116706a20c2c008..27a05bbd30df99e16272ce50f1910138f4e39b27 100644 (file)
@@ -92,7 +92,7 @@ flag = {
 
 flag = {
     name      = app-proto;
-    descrip   = "The application protocol to be used to obtain the server's certificate (https, smtp)";
+    descrip   = "The application protocol to be used to obtain the server's certificate (https, smtp, imap)";
     arg-type  = string;
     doc = "When the server's certificate isn't provided danetool will connect to the server to obtain the certificate. In that case it is required to known the protocol to talk with the server prior to initiating the TLS handshake.";
 };
index 6885efcc0d18d97ea5817a2af3d5c8ced6f8ccc1..3428888f48a552afab30572a5b13f970354ae319 100644 (file)
@@ -131,16 +131,25 @@ ssize_t send_line(int fd, const char *txt)
 static
 ssize_t wait_for_text(int fd, const char *txt, unsigned txt_size)
 {
-       char buf[256];
+       char buf[512];
+       char *p;
        int ret;
 
        alarm(10);
        do {
-               ret = recv(fd, buf, sizeof(buf), 0);
+               ret = recv(fd, buf, sizeof(buf)-1, 0);
                if (ret == -1) {
                        fprintf(stderr, "error receiving %s\n", txt);
                        exit(1);
                }
+               buf[ret] = 0;
+
+               p = memmem(buf, ret, txt, txt_size);
+               if (p != NULL && p != buf) {
+                       p--;
+                       if (*p == '\n')
+                               break;
+               }
        } while(ret < (int)txt_size || strncmp(buf, txt, txt_size) != 0);
 
        alarm(0);
@@ -157,11 +166,16 @@ socket_starttls(socket_st * socket, const char *app_proto)
        if (app_proto == NULL || strcasecmp(app_proto, "https") == 0)
                return;
 
-       if (strcasecmp(app_proto, "smtp") == 0) {
+       if (strcasecmp(app_proto, "smtp") == 0 || strcasecmp(app_proto, "submission") == 0) {
                send_line(socket->fd, "EHLO mail.example.com\n");
                wait_for_text(socket->fd, "220 ", 4);
                send_line(socket->fd, "STARTTLS\n");
                wait_for_text(socket->fd, "220 ", 4);
+       } else if (strcasecmp(app_proto, "imap") == 0 || strcasecmp(app_proto, "imap2") == 0) {
+               send_line(socket->fd, "a CAPABILITY\r\n");
+               wait_for_text(socket->fd, "a OK", 4);
+               send_line(socket->fd, "a STARTTLS\r\n");
+               wait_for_text(socket->fd, "a OK", 4);
        } else {
                fprintf(stderr, "unknown protocol %s\n", app_proto);
        }