summaryrefslogtreecommitdiff
path: root/https_wrapper.py
diff options
context:
space:
mode:
authorBen Murray <ben@duosecurity.com>2013-11-21 12:05:44 -0500
committerBen Murray <ben@duosecurity.com>2013-11-22 16:21:38 -0500
commit438f391a1a2fac8a0aec3f6f25bbf4305232aac6 (patch)
treee272fdda1a9c39fb7956e00d64b61a92c680e421 /https_wrapper.py
parente7fd788d6a11a9d8a13d7e249bac6c8bb610a16c (diff)
downloadopenvpn-duo-plugin-438f391a1a2fac8a0aec3f6f25bbf4305232aac6.tar.gz
openvpn-duo-plugin-438f391a1a2fac8a0aec3f6f25bbf4305232aac6.zip
Fixes #3 Add HTTPS proxy support (if using the Python helper script)
Diffstat (limited to 'https_wrapper.py')
-rw-r--r--https_wrapper.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/https_wrapper.py b/https_wrapper.py
index c3a9ce3..94c0c8a 100644
--- a/https_wrapper.py
+++ b/https_wrapper.py
@@ -1,8 +1,6 @@
-#!/usr/bin/env python
-#
-# Adapted from:
-# https://googleappengine.googlecode.com/svn-history/r136/trunk/python/google/appengine/tools/https_wrapper.py
-#
+### The following code was adapted from:
+### https://googleappengine.googlecode.com/svn-history/r136/trunk/python/google/appengine/tools/https_wrapper.py
+
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -49,6 +47,7 @@ class InvalidCertificateException(httplib.HTTPException):
'http://code.google.com/appengine/kb/general.html#rpcssl' %
(self.host, self.reason, self.cert))
+
class CertValidatingHTTPSConnection(httplib.HTTPConnection):
"""An HTTPConnection that connects over SSL and validates certificates."""
@@ -109,9 +108,11 @@ class CertValidatingHTTPSConnection(httplib.HTTPConnection):
def connect(self):
"Connect to a host on a given (SSL) port."
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect((self.host, self.port))
- self.sock = ssl.wrap_socket(sock, keyfile=self.key_file,
+ self.sock = socket.create_connection((self.host, self.port),
+ self.timeout)
+ if self._tunnel_host:
+ self._tunnel()
+ self.sock = ssl.wrap_socket(self.sock, keyfile=self.key_file,
certfile=self.cert_file,
cert_reqs=self.cert_reqs,
ca_certs=self.ca_certs)