summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2016-11-13 17:08:35 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2016-11-13 17:08:37 +0100
commit9725f8b889f36948e2a35ff93f56e5c58107a47f (patch)
tree9f074629b46c10109921f9f217aa4b1eb50d65e8
parent330dcc63b215152837caabda553c475a538fbc78 (diff)
downloadgnutls-tmp-tools-update.tar.gz
tools: added explicit socket flag to skip TLS initializationtmp-tools-update
This allows proper error recovery when SOCKET_FLAG_RAW is specified and initialize_session() fails.
-rw-r--r--src/ocsptool-common.c2
-rw-r--r--src/socket.c14
-rw-r--r--src/socket.h1
3 files changed, 10 insertions, 7 deletions
diff --git a/src/ocsptool-common.c b/src/ocsptool-common.c
index 654cda08ae..2ad91d0838 100644
--- a/src/ocsptool-common.c
+++ b/src/ocsptool-common.c
@@ -205,7 +205,7 @@ int send_ocsp_request(const char *server,
(unsigned int) req.size);
headers_size = strlen(headers);
- socket_open(&hd, hostname, service, NULL, SOCKET_FLAG_RAW, CONNECT_MSG, NULL);
+ socket_open(&hd, hostname, service, NULL, SOCKET_FLAG_RAW|SOCKET_FLAG_SKIP_INIT, CONNECT_MSG, NULL);
socket_send(&hd, headers, headers_size);
socket_send(&hd, req.data, req.size);
diff --git a/src/socket.c b/src/socket.c
index 4de0118b96..f60479f5cc 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -475,10 +475,12 @@ socket_open(socket_st * hd, const char *hostname, const char *service,
hd->app_proto = NULL;
}
- hd->session = init_tls_session(hostname);
- if (hd->session == NULL && !(flags & SOCKET_FLAG_RAW)) {
- fprintf(stderr, "error initializing session\n");
- exit(1);
+ if (!(flags & SOCKET_FLAG_SKIP_INIT)) {
+ hd->session = init_tls_session(hostname);
+ if (hd->session == NULL) {
+ fprintf(stderr, "error initializing session\n");
+ exit(1);
+ }
}
if (hd->session) {
@@ -489,7 +491,7 @@ socket_open(socket_st * hd, const char *hostname, const char *service,
gnutls_transport_set_int(hd->session, sd);
}
- if (!(flags & SOCKET_FLAG_RAW)) {
+ if (!(flags & SOCKET_FLAG_RAW) && !(flags & SOCKET_FLAG_SKIP_INIT)) {
err = do_handshake(hd);
if (err == GNUTLS_E_PUSH_ERROR) { /* failed connecting */
gnutls_deinit(hd->session);
@@ -517,7 +519,7 @@ socket_open(socket_st * hd, const char *hostname, const char *service,
exit(1);
}
- if (flags & SOCKET_FLAG_RAW)
+ if ((flags & SOCKET_FLAG_RAW) || (flags & SOCKET_FLAG_SKIP_INIT))
hd->secure = 0;
else
hd->secure = 1;
diff --git a/src/socket.h b/src/socket.h
index 9be1ee4e16..cb5289a582 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -6,6 +6,7 @@
#define SOCKET_FLAG_STARTTLS (1<<2)
#define SOCKET_FLAG_RAW (1<<3) /* unencrypted */
#define SOCKET_FLAG_VERBOSE (1<<4)
+#define SOCKET_FLAG_SKIP_INIT (1<<5)
typedef struct {