Skip to contentSkip to conversation

Implement custom HTTP header for http-proxy

PATCH Superseded Arne Schwabe 2 participants 8 messages Sep 8, 2013 – Nov 15, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Implement custom HTTP header for http-proxy

There are some patched OpenVPN versions out there without source code (e.g. NDMVPN) that support adding custom http header.

This patch adds custom header to OpenVPN and supports the syntax that the "in the wild" variants use.

---
 doc/openvpn.8         |    7 +++++++
 src/openvpn/options.c |   29 +++++++++++++++++++++++++++++
 src/openvpn/proxy.c   |   16 ++++++++++++++++
 src/openvpn/proxy.h   |    7 +++++++
 4 files changed, 59 insertions(+)
doc/openvpn.8 +7 -0
index 573d6a8..72a85a9 100644
@@ -551,6 +551,13 @@ Set HTTP version number to
 .B AGENT user-agent \-\-
 Set HTTP "User-Agent" string to
 .B user-agent.
+
+.B CUSTOM\-HEADER name content \-\-
+Adds the custom Header with 
+.B name
+as name and 
+.B content
+as the content of the custom HTTP header.
 .\"*********************************************************
 .TP
 .B \-\-socks-proxy server [port]
src/openvpn/options.c +29 -0
index e551c30..01960f2 100644
@@ -4979,6 +4979,35 @@ add_option (struct options *options,
 	{
 	  ho->user_agent = p[2];
 	}
+      else if ((streq (p[1], "EXT1") || streq(p[1], "EXT2") || streq(p[1], "CUSTOM-HEADER"))
+	       && p[2])
+	{
+	  /* In the wild patched versions use both EXT1/2 and CUSTOM-HEADER with either two
+	   * argument or one */
+	  struct http_custom_header *custom_header =NULL;
+	  int i;
+	  
+	  
+	  /* Find the first free header */
+	  for (i=0; i < MAX_CUSTOM_HTTP_HEADER; i++) {
+	    if (!ho->custom_headers[i].name) {
+	      custom_header = &ho->custom_headers[i];
+	      break;
+	    }
+	  }
+	  if (!custom_header)
+	    {
+	      msg (msglevel, "Cannot use more than %d http-proxy-option CUSTOM-HEAER : '%s'", MAX_CUSTOM_HTTP_HEADER, p[1]);
+	    }
+	  else
+	    {
+	      /* We will save p[2] and p[3], the proxy code will detect if 
+	       * p[3] is NULL */
+	      custom_header->name = p[2];
+	      custom_header->content = p[3];
+	    }
+	  
+	}
       else
 	{
 	  msg (msglevel, "Bad http-proxy-option or missing parameter: '%s'", p[1]);
src/openvpn/proxy.c +16 -0
index 533e747..a2721cd 100644
@@ -519,6 +519,7 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
     }
   else
     {
+      int i=0;
       /* format HTTP CONNECT message */
       openvpn_snprintf (buf, sizeof(buf), "CONNECT %s:%s HTTP/%s",
 			host,
@@ -543,6 +544,21 @@ establish_http_proxy_passthru (struct http_proxy_info *p,
 	  if (!send_line_crlf (sd, buf))
 	    goto error;
 	}
+      /* Send custom headers if provided */
+      while (p->options.custom_headers[i].name)
+	{
+	  if (p->options.custom_headers[i].content)
+	    openvpn_snprintf (buf, sizeof(buf), "%s: %s",
+			      p->options.custom_headers[i].name,
+			      p->options.custom_headers[i].content);
+	  else
+	    openvpn_snprintf (buf, sizeof(buf), "%s",
+			      p->options.custom_headers[i].name);
+	 
+	  if (!send_line_crlf (sd, buf))
+	    goto error;
+	  i++;
+	}
 
       /* auth specified? */
       switch (p->auth_method)
src/openvpn/proxy.h +7 -0
index 9d75e06..0e7a6df 100644
@@ -38,6 +38,12 @@
 #define HTTP_AUTH_NTLM2  4
 #define HTTP_AUTH_N      5 /* number of HTTP_AUTH methods */
 
+struct http_custom_header {
+  const char *name;
+  const char *content;
+};
+
+#define MAX_CUSTOM_HTTP_HEADER 10
 struct http_proxy_options {
   const char *server;
   const char *port;
@@ -53,6 +59,7 @@ struct http_proxy_options {
   const char *auth_file;
   const char *http_version;
   const char *user_agent;
+  struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER];
 };
 
 struct http_proxy_options_simple {
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/1 Implement custom HTTP header for http-proxy, always send user-agent

There are some patched OpenVPN versions out there without source code (e.g. NDMVPN) that support adding custom http header.

This patch adds custom header to OpenVPN and supports the syntax that the "in the wild" variants use.

---
 doc/openvpn.8         |    7 ++++
 src/openvpn/options.c |   29 +++++++++++++++
 src/openvpn/proxy.c   |   97 ++++++++++++++++++++++++++++++++++++++-----------
 src/openvpn/proxy.h   |    7 ++++
 4 files changed, 119 insertions(+), 21 deletions(-)
doc/openvpn.8 +7 -0
index c0b209c..25576ed 100644
@@ -552,6 +552,13 @@ Set HTTP version number to
 .B AGENT user-agent \-\-
 Set HTTP "User-Agent" string to
 .B user-agent.
+
+.B CUSTOM\-HEADER name content \-\-
+Adds the custom Header with 
+.B name
+as name and 
+.B content
+as the content of the custom HTTP header.
 .\"*********************************************************
 .TP
 .B \-\-socks-proxy server [port]
src/openvpn/options.c +29 -0
index 4d0271f..1ad06f3 100644
@@ -5061,6 +5061,35 @@ add_option (struct options *options,
 	{
 	  ho->user_agent = p[2];
 	}
+      else if ((streq (p[1], "EXT1") || streq(p[1], "EXT2") || streq(p[1], "CUSTOM-HEADER"))
+	       && p[2])
+	{
+	  /* In the wild patched versions use both EXT1/2 and CUSTOM-HEADER with either two
+	   * argument or one */
+	  struct http_custom_header *custom_header =NULL;
+	  int i;
+	  
+	  
+	  /* Find the first free header */
+	  for (i=0; i < MAX_CUSTOM_HTTP_HEADER; i++) {
+	    if (!ho->custom_headers[i].name) {
+	      custom_header = &ho->custom_headers[i];
+	      break;
+	    }
+	  }
+	  if (!custom_header)
+	    {
+	      msg (msglevel, "Cannot use more than %d http-proxy-option CUSTOM-HEAER : '%s'", MAX_CUSTOM_HTTP_HEADER, p[1]);
+	    }
+	  else
+	    {
+	      /* We will save p[2] and p[3], the proxy code will detect if 
+	       * p[3] is NULL */
+	      custom_header->name = p[2];
+	      custom_header->content = p[3];
+	    }
+	  
+	}
       else
 	{
 	  msg (msglevel, "Bad http-proxy-option or missing parameter: '%s'", p[1]);
src/openvpn/proxy.c +76 -21

124 lines not on this page · raw message

src/openvpn/proxy.h +7 -0
index 5e476f1..b72748f 100644
@@ -38,6 +38,12 @@
 #define HTTP_AUTH_NTLM2  4
 #define HTTP_AUTH_N      5 /* number of HTTP_AUTH methods */
 
+struct http_custom_header {
+  const char *name;
+  const char *content;
+};
+
+#define MAX_CUSTOM_HTTP_HEADER 10
 struct http_proxy_options {
   const char *server;
   int port;
@@ -53,6 +59,7 @@ struct http_proxy_options {
   const char *auth_file;
   const char *http_version;
   const char *user_agent;
+  struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER];
 };
 
 struct http_proxy_options_simple {
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v3 1/1 Implement custom HTTP header for http-proxy, always send user-agent

There are some patched OpenVPN versions out there without source code (e.g. NDMVPN) that support adding custom http header.

This patch adds custom header to OpenVPN and supports the syntax that the "in the wild" variants use.

Patch v3 also prints all custom headers with other http options in --verb 5

---
 doc/openvpn.8         |    7 ++++
 src/openvpn/options.c |   37 +++++++++++++++++++
 src/openvpn/proxy.c   |   96 ++++++++++++++++++++++++++++++++++++++-----------
 src/openvpn/proxy.h   |    7 ++++
 4 files changed, 126 insertions(+), 21 deletions(-)
doc/openvpn.8 +7 -0
index c0b209c..25576ed 100644
@@ -552,6 +552,13 @@ Set HTTP version number to
 .B AGENT user-agent \-\-
 Set HTTP "User-Agent" string to
 .B user-agent.
+
+.B CUSTOM\-HEADER name content \-\-
+Adds the custom Header with 
+.B name
+as name and 
+.B content
+as the content of the custom HTTP header.
 .\"*********************************************************
 .TP
 .B \-\-socks-proxy server [port]
src/openvpn/options.c +37 -0
index 4d0271f..7eb3da2 100644
@@ -1295,6 +1295,7 @@ option_iroute_ipv6 (struct options *o,
 static void
 show_http_proxy_options (const struct http_proxy_options *o)
 {
+  int i;
   msg (D_SHOW_PARMS, "BEGIN http_proxy");
   SHOW_STR (server);
   SHOW_INT (port);
@@ -1304,6 +1305,15 @@ show_http_proxy_options (const struct http_proxy_options *o)
   SHOW_INT (timeout);
   SHOW_STR (http_version);
   SHOW_STR (user_agent);
+  for  (i=0; i < MAX_CUSTOM_HTTP_HEADER && o->custom_headers[i].name;i++)
+    {
+      if (o->custom_headers[i].content)
+	msg (D_SHOW_PARMS, "  custom_header[%d] = %s: %s", i,
+	       o->custom_headers[i].name, o->custom_headers[i].content);
+      else
+	msg (D_SHOW_PARMS, "  custom_header[%d] = %s", i,
+	     o->custom_headers[i].name);
+    }
   msg (D_SHOW_PARMS, "END http_proxy");
 }
 #endif
@@ -5061,6 +5071,33 @@ add_option (struct options *options,
 	{
 	  ho->user_agent = p[2];
 	}
+      else if ((streq (p[1], "EXT1") || streq(p[1], "EXT2") || streq(p[1], "CUSTOM-HEADER"))
+	       && p[2])
+	{
+	  /* In the wild patched versions use both EXT1/2 and CUSTOM-HEADER with either two
+	   * argument or one */
+
+	  struct http_custom_header *custom_header =NULL;
+	  int i;
+	  /* Find the first free header */
+	  for (i=0; i < MAX_CUSTOM_HTTP_HEADER; i++) {
+	    if (!ho->custom_headers[i].name) {
+	      custom_header = &ho->custom_headers[i];
+	      break;
+	    }
+	  }
+	  if (!custom_header)
+	    {
+	      msg (msglevel, "Cannot use more than %d http-proxy-option CUSTOM-HEAER : '%s'", MAX_CUSTOM_HTTP_HEADER, p[1]);
+	    }
+	  else
+	    {
+	      /* We will save p[2] and p[3], the proxy code will detect if 
+	       * p[3] is NULL */
+	      custom_header->name = p[2];
+	      custom_header->content = p[3];
+	    }
+	}
       else
 	{
 	  msg (msglevel, "Bad http-proxy-option or missing parameter: '%s'", p[1]);
src/openvpn/proxy.c +75 -21

123 lines not on this page · raw message

src/openvpn/proxy.h +7 -0
index 5e476f1..b72748f 100644
@@ -38,6 +38,12 @@
 #define HTTP_AUTH_NTLM2  4
 #define HTTP_AUTH_N      5 /* number of HTTP_AUTH methods */
 
+struct http_custom_header {
+  const char *name;
+  const char *content;
+};
+
+#define MAX_CUSTOM_HTTP_HEADER 10
 struct http_proxy_options {
   const char *server;
   int port;
@@ -53,6 +59,7 @@ struct http_proxy_options {
   const char *auth_file;
   const char *http_version;
   const char *user_agent;
+  struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER];
 };
 
 struct http_proxy_options_simple {
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v4 1/1 Implement custom HTTP header for http-proxy, always send user-agent

There are some patched OpenVPN versions out there without source code (e.g. NDMVPN) that support adding custom http header.

This patch adds custom header to OpenVPN and supports the syntax that the "in the wild" variants use.

Patch v3 also prints all custom headers with other http options in --verb 5 Patch v4 does clean up the add_proxy_header function

---
 doc/openvpn.8         |    7 ++++
 src/openvpn/options.c |   37 ++++++++++++++++++++
 src/openvpn/proxy.c   |   90 +++++++++++++++++++++++++++++++++++++------------
 src/openvpn/proxy.h   |    7 ++++
 4 files changed, 120 insertions(+), 21 deletions(-)
doc/openvpn.8 +7 -0
index c0b209c..25576ed 100644
@@ -552,6 +552,13 @@ Set HTTP version number to
 .B AGENT user-agent \-\-
 Set HTTP "User-Agent" string to
 .B user-agent.
+
+.B CUSTOM\-HEADER name content \-\-
+Adds the custom Header with 
+.B name
+as name and 
+.B content
+as the content of the custom HTTP header.
 .\"*********************************************************
 .TP
 .B \-\-socks-proxy server [port]
src/openvpn/options.c +37 -0
index 4d0271f..7eb3da2 100644
@@ -1295,6 +1295,7 @@ option_iroute_ipv6 (struct options *o,
 static void
 show_http_proxy_options (const struct http_proxy_options *o)
 {
+  int i;
   msg (D_SHOW_PARMS, "BEGIN http_proxy");
   SHOW_STR (server);
   SHOW_INT (port);
@@ -1304,6 +1305,15 @@ show_http_proxy_options (const struct http_proxy_options *o)
   SHOW_INT (timeout);
   SHOW_STR (http_version);
   SHOW_STR (user_agent);
+  for  (i=0; i < MAX_CUSTOM_HTTP_HEADER && o->custom_headers[i].name;i++)
+    {
+      if (o->custom_headers[i].content)
+	msg (D_SHOW_PARMS, "  custom_header[%d] = %s: %s", i,
+	       o->custom_headers[i].name, o->custom_headers[i].content);
+      else
+	msg (D_SHOW_PARMS, "  custom_header[%d] = %s", i,
+	     o->custom_headers[i].name);
+    }
   msg (D_SHOW_PARMS, "END http_proxy");
 }
 #endif
@@ -5061,6 +5071,33 @@ add_option (struct options *options,
 	{
 	  ho->user_agent = p[2];
 	}
+      else if ((streq (p[1], "EXT1") || streq(p[1], "EXT2") || streq(p[1], "CUSTOM-HEADER"))
+	       && p[2])
+	{
+	  /* In the wild patched versions use both EXT1/2 and CUSTOM-HEADER with either two
+	   * argument or one */
+
+	  struct http_custom_header *custom_header =NULL;
+	  int i;
+	  /* Find the first free header */
+	  for (i=0; i < MAX_CUSTOM_HTTP_HEADER; i++) {
+	    if (!ho->custom_headers[i].name) {
+	      custom_header = &ho->custom_headers[i];
+	      break;
+	    }
+	  }
+	  if (!custom_header)
+	    {
+	      msg (msglevel, "Cannot use more than %d http-proxy-option CUSTOM-HEAER : '%s'", MAX_CUSTOM_HTTP_HEADER, p[1]);
+	    }
+	  else
+	    {
+	      /* We will save p[2] and p[3], the proxy code will detect if 
+	       * p[3] is NULL */
+	      custom_header->name = p[2];
+	      custom_header->content = p[3];
+	    }
+	}
       else
 	{
 	  msg (msglevel, "Bad http-proxy-option or missing parameter: '%s'", p[1]);
src/openvpn/proxy.c +69 -21

115 lines not on this page · raw message

src/openvpn/proxy.h +7 -0
index 5e476f1..b72748f 100644
@@ -38,6 +38,12 @@
 #define HTTP_AUTH_NTLM2  4
 #define HTTP_AUTH_N      5 /* number of HTTP_AUTH methods */
 
+struct http_custom_header {
+  const char *name;
+  const char *content;
+};
+
+#define MAX_CUSTOM_HTTP_HEADER 10
 struct http_proxy_options {
   const char *server;
   int port;
@@ -53,6 +59,7 @@ struct http_proxy_options {
   const char *auth_file;
   const char *http_version;
   const char *user_agent;
+  struct http_custom_header custom_headers[MAX_CUSTOM_HTTP_HEADER];
 };
 
 struct http_proxy_options_simple {
Signature · 1 line
1.7.9.5
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: Implement custom HTTP header for http-proxy, always send user-agent

ACK.

Your patch has been applied to the master branch, with some whitespace fixes, and one typo fix in a string in show_http_proxy_options().

commit d0cb816cf8be68359617b61a55799f6330901f6a (master)

Author: Arne Schwabe
Date:   Fri Oct 25 10:02:23 2013 +0200
     Implement custom HTTP header for http-proxy, always send user-agent

     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: http://article.gmane.org/gmane.network.openvpn.devel/7946
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw

PATCH 1/1 Fix argument type warning introduced by http extra proxy header patch.

In reply to Arne Schwabe

d0cb816cf8be68359617b61a55799f6330901f6a introduced add_proxy_headers(), passing "port" as "const char *" - but it should be an "int". As port is not yet actually used inside add_proxy_headers(), it's just a warning.

---
 src/openvpn/proxy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/proxy.c +1 -1
index ed4aedd..c3496e2 100644
@@ -492,7 +492,7 @@ bool
 add_proxy_headers (struct http_proxy_info *p,
 		  socket_descriptor_t sd, /* already open to proxy */
 		  const char *host,	  /* openvpn server remote */
-		  const char *port	  /* openvpn server port */
+		  const int port	  /* openvpn server port */
 		  )
 {
   char buf[512];
Signature · 1 line
1.8.1.5
#6 lore raw

Re: [Openvpn-devel] [PATCH] Fix argument type warning introduced by http extra proxy header patch.

Am 15.11.13 15:41, schrieb Gert Doering:

Quoted 14 lines

d0cb816cf8be68359617b61a55799f6330901f6a introduced add_proxy_headers(), passing "port" as "const char *" - but it should be an "int". As port is not yet actually used inside add_proxy_headers(), it's just a warning.

---
 src/openvpn/proxy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/proxy.c +0 -0
index ed4aedd..c3496e2 100644

src/openvpn/proxy.c bool · line 498

Quoted 8 lines
src/openvpn/proxy.c +1 -1
@@ -492,7 +492,7 @@ bool
 add_proxy_headers (struct http_proxy_info *p,
 		  socket_descriptor_t sd, /* already open to proxy */
 		  const char *host,	  /* openvpn server remote */
-		  const char *port	  /* openvpn server port */
+		  const int port	  /* openvpn server port */
 		  )
 {
   char buf[512];

ACK.

Arne

#7 lore raw

Re: [Openvpn-devel] [PATCH] Fix argument type warning introduced by http extra proxy header patch.

Hi,

Quoted 6 lines · Arne Schwabe

Am 15.11.13 15:41, schrieb Gert Doering:

Quoted 5 lines

d0cb816cf8be68359617b61a55799f6330901f6a introduced add_proxy_headers(), passing "port" as "const char *" - but it should be an "int". As port is not yet actually used inside add_proxy_headers(), it's just a warning.

[..]

Quoted 1 line

ACK.

committed and pushed, as 16e24daaba4432e0a905478bab23b65f904be135

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...