diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2015-10-16 22:58:54 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2015-10-16 22:58:54 +0200 |
commit | c0b286b28992dc10bc4a9cf343b54af0526e4de0 (patch) | |
tree | 57e4a3171474419e6a101298eaecffbb328bc3f6 /src | |
parent | 333d98ed59babd8b3a3834cc92686b905ad0dd4b (diff) | |
download | gnutls-c0b286b28992dc10bc4a9cf343b54af0526e4de0.tar.gz |
tools: when the starttls-proto is specified automatically detect the port if not given
Diffstat (limited to 'src')
-rw-r--r-- | src/cli-debug-args.def | 5 | ||||
-rw-r--r-- | src/cli-debug.c | 8 | ||||
-rw-r--r-- | src/cli.c | 5 | ||||
-rw-r--r-- | src/danetool-args.def | 5 | ||||
-rw-r--r-- | src/danetool.c | 6 | ||||
-rw-r--r-- | src/socket.c | 35 | ||||
-rw-r--r-- | src/socket.h | 2 |
7 files changed, 62 insertions, 4 deletions
diff --git a/src/cli-debug-args.def b/src/cli-debug-args.def index 11dc3cb12d..728f204139 100644 --- a/src/cli-debug-args.def +++ b/src/cli-debug-args.def @@ -28,6 +28,11 @@ flag = { flag = { name = app-proto; + aliases = starttls-proto; +}; + +flag = { + name = starttls-proto; arg-type = string; descrip = "The application protocol to be used to obtain the server's certificate (https, ftp, smtp, imap, ldap, xmpp)"; doc = ""; diff --git a/src/cli-debug.c b/src/cli-debug.c index 35e4d0634a..8cc98fae94 100644 --- a/src/cli-debug.c +++ b/src/cli-debug.c @@ -339,8 +339,12 @@ static void cmd_parser(int argc, char **argv) if (HAVE_OPT(PORT)) port = OPT_VALUE_PORT; - else - port = 443; + else { + if (HAVE_OPT(APP_PROTO)) + port = starttls_proto_to_port(OPT_ARG(STARTTLS_PROTO)); + else + port = 443; + } if (rest == NULL) hostname = "localhost"; @@ -1528,7 +1528,10 @@ static void cmd_parser(int argc, char **argv) if (HAVE_OPT(PORT)) { service = OPT_ARG(PORT); } else { - service = "443"; + if (HAVE_OPT(STARTTLS_PROTO)) + service = starttls_proto_to_service(OPT_ARG(STARTTLS_PROTO)); + else + service = "443"; } record_max_size = OPT_VALUE_RECORDSIZE; diff --git a/src/danetool-args.def b/src/danetool-args.def index 44ceaac3d1..7e4c229e5f 100644 --- a/src/danetool-args.def +++ b/src/danetool-args.def @@ -92,6 +92,11 @@ flag = { flag = { name = app-proto; + aliases = starttls-proto; +}; + +flag = { + name = starttls-proto; descrip = "The application protocol to be used to obtain the server's certificate (https, ftp, smtp, imap, ldap, xmpp)"; 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/danetool.c b/src/danetool.c index 2d301760c3..49f0b2029e 100644 --- a/src/danetool.c +++ b/src/danetool.c @@ -158,8 +158,12 @@ static void cmd_parser(int argc, char **argv) if (HAVE_OPT(LOAD_CERTIFICATE)) cinfo.cert = OPT_ARG(LOAD_CERTIFICATE); - if (HAVE_OPT(PORT)) + if (HAVE_OPT(PORT)) { port = OPT_VALUE_PORT; + } else { + if (HAVE_OPT(STARTTLS_PROTO)) + port = starttls_proto_to_port(OPT_ARG(STARTTLS_PROTO)); + } if (HAVE_OPT(PROTO)) proto = OPT_ARG(PROTO); diff --git a/src/socket.c b/src/socket.c index cac9634466..fadfff16bf 100644 --- a/src/socket.c +++ b/src/socket.c @@ -239,6 +239,41 @@ socket_starttls(socket_st * socket, const char *app_proto) return; } +#define CANON_SERVICE(app_proto) \ + if (strcasecmp(app_proto, "xmpp") == 0) \ + app_proto = "xmpp-server"; \ + +int +starttls_proto_to_port(const char *app_proto) +{ + struct servent *s; + + CANON_SERVICE(app_proto); + + s = getservbyname(app_proto, NULL); + if (s != NULL) { + return s->s_port; + } + endservent(); + + return 443; +} + +const char *starttls_proto_to_service(const char *app_proto) +{ + struct servent *s; + + CANON_SERVICE(app_proto); + + s = getservbyname(app_proto, NULL); + if (s != NULL) { + return s->s_name; + } + endservent(); + + return "443"; +} + void socket_bye(socket_st * socket) { int ret; diff --git a/src/socket.h b/src/socket.h index e47138cf9e..ae27418f13 100644 --- a/src/socket.h +++ b/src/socket.h @@ -28,5 +28,7 @@ void sockets_init(void); int service_to_port(const char *service, const char *proto); const char *port_to_service(const char *sport, const char *proto); +int starttls_proto_to_port(const char *app_proto); +const char *starttls_proto_to_service(const char *app_proto); #define CONNECT_MSG "Connecting to" |