summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2014-08-09 10:22:40 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2014-08-09 10:22:40 +0200
commit3623896c39d2e2bf2ad9ff65e8911ba0d17a28f5 (patch)
tree166093ff48ca7324c84488a11193b79f59c94f7e /src
parenteb61deec7ffc9eee7bc999950bb92dce96464e45 (diff)
downloadgnutls-3623896c39d2e2bf2ad9ff65e8911ba0d17a28f5.tar.gz
danetool/gnutls-cli-debug: added support for imap starttls
Diffstat (limited to 'src')
-rw-r--r--src/cli-debug-args.def2
-rw-r--r--src/danetool-args.def2
-rw-r--r--src/socket.c20
3 files changed, 19 insertions, 5 deletions
diff --git a/src/cli-debug-args.def b/src/cli-debug-args.def
index 45b01047d0..93651861b4 100644
--- a/src/cli-debug-args.def
+++ b/src/cli-debug-args.def
@@ -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 = "";
};
diff --git a/src/danetool-args.def b/src/danetool-args.def
index 5185e7190f..27a05bbd30 100644
--- a/src/danetool-args.def
+++ b/src/danetool-args.def
@@ -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.";
};
diff --git a/src/socket.c b/src/socket.c
index 6885efcc0d..3428888f48 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -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);
}