This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pdp
Recipients pdp
Date 2009-04-01.06:38:18
SpamBayes Score 1.6850188e-09
Marked as misclassified No
Message-id <1238567905.09.0.139467917453.issue5639@psf.upfronthosting.co.za>
In-reply-to
Content
With TLS it is possible to have the client use an extension (defined in
RFC 4366, and RFC 3546 before that) to indicate to the server which
hostname it believes it is talking to.  The server can then choose TLS
certificates accordingly.  This makes virtual-hosting possible.  Most
modern GUI web-browsers support making use of this extension, Server
Name Indication (SNI).

OpenSSL 0.9.8f onwards have optional support for this; OpenSSL needs to
have been built with "enable-tlsext" in EXTRACONFIGURE.  If that is not
present, then there's a guard macro defined to say it's absent.

This patch, against Python 2.6.1, adds to the standard ssl module the
ability to set the extension, using server_hostname as a arg in relevant
places.  This is only set for client connections and will silently be
ignored if the OpenSSL library does not support it.

I have tested this on FreeBSD 7.0/amd64 with OpenSSL 0.9.8k when talking
to Apache 2.2.x with the SNI patches from https://sni.velox.ch/.  Below
is my simple test program, to dump raw HTTP results back.  With this, I
can connect to various local https vhosts and get the correct content back.

I am not a Python core dev and not too enthusiastic at the thought of
grabbing latest svn to port this across; I hope that it's still of use.

=============
import socket
import ssl
import sys

def dump_https_page(hostname, uri='/'):

  sock = socket.socket(socket.AF_INET)
  s = ssl.SSLSocket(sock=sock,
                    ca_certs='/etc/ssl/certs',
                    server_hostname=hostname)
  print 'have socket'
  s.connect((hostname, 443))
  print 'connected'

  print >>s, 'GET %s HTTP/1.0\r\nHost: %s\r\nConnection: close\r\n\r\n' % (
      uri, hostname),

  t = s.read()
  while t:
    print t,
    t = s.read()

if __name__ == '__main__':
  for x in sys.argv[1:]:
    dump_https_page(hostname=x)
History
Date User Action Args
2009-04-01 06:38:25pdpsetrecipients: + pdp
2009-04-01 06:38:25pdpsetmessageid: <1238567905.09.0.139467917453.issue5639@psf.upfronthosting.co.za>
2009-04-01 06:38:23pdplinkissue5639 messages
2009-04-01 06:38:21pdpcreate