Skip to contentSkip to conversation

proxy ntlm support

Openvpn-devel William Preston 2 participants 4 messages Sep 15, 2004 – Oct 22, 2004

lore
Share & tools
lore
#0 lore raw

hello list,

here's a patch to add basic ntlm support to openvpn 1.6.0 i've tested it with i386 linux & win32 against MS ISA proxy.

it includes base64 code from heimdal...

- hope it's useful to somebody.

William

base64.c +135 -0
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 1995-2001 Kungliga Tekniska Högskolan
+ * (Royal Institute of Technology, Stockholm, Sweden).
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the Institute nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdlib.h>
+#include <string.h>
+#include "base64.h"
+
+static char base64_chars[] = 
+    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+static int 
+pos(char c)
+{
+    char *p;
+    for (p = base64_chars; *p; p++)
+	if (*p == c)
+	    return p - base64_chars;
+    return -1;
+}
+
+int 
+base64_encode(const void *data, int size, char **str)
+{
+    char *s, *p;
+    int i;
+    int c;
+    const unsigned char *q;
+
+    p = s = (char *) malloc(size * 4 / 3 + 4);
+    if (p == NULL)
+	return -1;
+    q = (const unsigned char *) data;
+    i = 0;
+    for (i = 0; i < size;) {
+	c = q[i++];
+	c *= 256;
+	if (i < size)
+	    c += q[i];
+	i++;
+	c *= 256;
+	if (i < size)
+	    c += q[i];
+	i++;
+	p[0] = base64_chars[(c & 0x00fc0000) >> 18];
+	p[1] = base64_chars[(c & 0x0003f000) >> 12];
+	p[2] = base64_chars[(c & 0x00000fc0) >> 6];
+	p[3] = base64_chars[(c & 0x0000003f) >> 0];
+	if (i > size)
+	    p[3] = '=';
+	if (i > size + 1)
+	    p[2] = '=';
+	p += 4;
+    }
+    *p = 0;
+    *str = s;
+    return strlen(s);
+}
+
+#define DECODE_ERROR 0xffffffff
+
+static unsigned int
+token_decode(const char *token)
+{
+    int i;
+    unsigned int val = 0;
+    int marker = 0;
+    if (strlen(token) < 4)
+	return DECODE_ERROR;
+    for (i = 0; i < 4; i++) {
+	val *= 64;
+	if (token[i] == '=')
+	    marker++;
+	else if (marker > 0)
+	    return DECODE_ERROR;
+	else
+	    val += pos(token[i]);
+    }
+    if (marker > 2)
+	return DECODE_ERROR;
+    return (marker << 24) | val;
+}
+
+int
+base64_decode(const char *str, void *data)
+{
+    const char *p;
+    unsigned char *q;
+
+    q = data;
+    for (p = str; *p && (*p == '=' || strchr(base64_chars, *p)); p += 4) {
+	unsigned int val = token_decode(p);
+	unsigned int marker = (val >> 24) & 0xff;
+	if (val == DECODE_ERROR)
+	    return -1;
+	*q++ = (val >> 16) & 0xff;
+	if (marker < 2)
+	    *q++ = (val >> 8) & 0xff;
+	if (marker < 1)
+	    *q++ = val & 0xff;
+    }
+    return q - (unsigned char *) data;
+}
base64.h +42 -0

42 lines not on this page · raw message

ntlm.c +188 -0

188 lines not on this page · raw message

ntlm.h +7 -0
@@ -0,0 +1,7 @@
+#ifndef NTLM_H
+#define NTLM_H
+
+const char * ntlm_phase_1 (const struct http_proxy_info *p);
+const char * ntlm_phase_3 (const struct http_proxy_info *p, const char *phase_2);
+
+#endif
options.c +9 -2
@@ -86,9 +86,10 @@
   "                  p = udp (default), tcp-server, or tcp-client\n"
   "--connect-retry n : For --proto tcp-client, number of seconds to wait\n"
   "                  between connection retries (default=%d).\n"
-  "--http-proxy s p [up]: Connect to remote host through an HTTP proxy at address\n"
+  "--http-proxy s p [up] [auth]: Connect to remote host through an HTTP proxy at address\n"
   "                  s and port p.  If proxy authentication is required, up is a\n"
-  "                  file containing username/password on 2 lines.\n"
+  "                  file containing username/password on 2 lines.  Add ntlm if\n"
+  "                  the proxy requires NTLM authentication\n"
   "--http-proxy-retry : Retry indefinitely on HTTP proxy errors.\n"
   "--socks-proxy s [p]: Connect to remote host through a Socks5 proxy at address\n"
   "                  s and port p (default port = 1080).\n"
@@ -1481,6 +1482,12 @@
 	  ++i;
 	  options->http_proxy_auth_method = "basic";
 	  options->http_proxy_auth_file = p[3];
+
+	  if (p[4])
+	  {
+	    options->http_proxy_auth_method = p[4];
+	  }
+
 	}
       else
 	{
proxy.c +120 -12

208 lines not on this page · raw message

proxy.h +4 -0
@@ -30,6 +30,7 @@
 #define HTTP_AUTH_NONE  0
 #define HTTP_AUTH_BASIC 1
 #define HTTP_AUTH_N     2
+#define HTTP_AUTH_NTLM  3
 
 struct http_proxy_info {
   bool defined;
@@ -57,4 +58,7 @@
 				    struct buffer *lookahead,
 				    volatile int *signal_received);
 
+uint8_t * make_base64_string2 (const uint8_t *str, int str_len);
+uint8_t * make_base64_string (const uint8_t *str);
+
 #endif
#1 lore raw

William,

Thanks for the patch.

Have you tried it against the 2.0 beta series yet?

That's really the place where I will want to merge it.

Best Regards,
James

Quoted 11 lines · William Preston

hello list,

here's a patch to add basic ntlm support to openvpn 1.6.0 i've tested it with i386 linux & win32 against MS ISA proxy.

it includes base64 code from heimdal...

- hope it's useful to somebody.

William

#2 lore raw
In reply to William Preston

William,

I merged your patch in the just-released OpenVPN-2.0-beta12. Would you mind giving it a test run to make sure I didn't make any mistakes on the merge (there were some conflicts). I don't have an ISA server, so I can't personally test it.

Thanks,

James

Quoted 11 lines · William Preston

hello list,

here's a patch to add basic ntlm support to openvpn 1.6.0 i've tested it with i386 linux & win32 against MS ISA proxy.

it includes base64 code from heimdal...

- hope it's useful to somebody.

William

#3 lore raw

Quoting James Yonan <[email protected]...>:

Quoted 5 lines

I merged your patch in the just-released OpenVPN-2.0-beta12. Would you mind giving it a test run to make sure I didn't make any mistakes on the merge (there were some conflicts). I don't have an ISA server, so I can't personally test it.

Hi,
yes it works without problems.

thanks,

William

Quoted 4 lines · William Preston
Quoted 3 lines

here's a patch to add basic ntlm support to openvpn 1.6.0 i've tested it with i386 linux & win32 against MS ISA proxy.