Jean-Paul Calderone | 7fb6b21 | 2011-06-06 08:31:28 -0400 | [diff] [blame] | 1 | # Copyright (C) Jean-Paul Calderone |
| 2 | # See LICENSE for details. |
| 3 | |
| 4 | if __name__ == '__main__': |
| 5 | import client |
| 6 | raise SystemExit(client.main()) |
| 7 | |
| 8 | from sys import argv, stdout |
| 9 | from socket import socket |
| 10 | |
| 11 | from OpenSSL.SSL import TLSv1_METHOD, Context, Connection |
| 12 | |
| 13 | def main(): |
| 14 | """ |
| 15 | Connect to an SNI-enabled server and request a specific hostname, specified |
| 16 | by argv[1], of it. |
| 17 | """ |
| 18 | if len(argv) < 2: |
| 19 | print 'Usage: %s <hostname>' % (argv[0],) |
| 20 | return 1 |
| 21 | |
| 22 | client = socket() |
| 23 | |
| 24 | print 'Connecting...', |
| 25 | stdout.flush() |
| 26 | client.connect(('127.0.0.1', 8443)) |
| 27 | print 'connected', client.getpeername() |
| 28 | |
| 29 | client_ssl = Connection(Context(TLSv1_METHOD), client) |
| 30 | client_ssl.set_connect_state() |
| 31 | client_ssl.set_tlsext_host_name(argv[1]) |
| 32 | client_ssl.do_handshake() |
| 33 | print 'Server subject is', client_ssl.get_peer_certificate().get_subject() |
| 34 | client_ssl.close() |
| 35 | |