source: python/TLSLite/cert/client.py @ 26

Revision 26, 1.1 KB checked in by nakiki, 13 years ago (diff)
  • Property svn:executable set to *
Line 
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4import socket
5import tlslite.api as tls
6import sys
7
8DST = ('localhost', 3746)
9
10# 証明書を使った場合の例
11def connect(sockaddr):
12  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
13  sock.connect(sockaddr)
14  sock.settimeout(10)
15  conn = tls.TLSConnection(sock)
16  conn.closeSocket = True
17  s = open("./clientX509Cert.pem").read()
18  x509 = tls.X509()
19  x509.parse(s)
20  print "fingerprint=", x509.getFingerprint()
21  certChain = tls.X509CertChain([x509])
22  s = open("./clientX509Key.pem").read()
23  privateKey = tls.parsePEMKey(s, private=True)
24  # 提示されるサーバの証明書のfingerprint
25  checker = tls.Checker(x509Fingerprint= '8b8a01e15a2095da731a9b864a30ae272d038180')
26  conn.handshakeClientCert(certChain = certChain, privateKey = privateKey,
27    checker = checker)
28  return conn
29
30conn = connect(DST)
31rfile = conn.makefile('rb')
32while 1:
33  print '> ',
34  line = sys.stdin.readline()
35  if len(line) == 0:
36    conn.close()
37    print
38    break
39  conn.write(line)
40  line = rfile.readline()
41  if len(line) == 0:
42    conn.close()
43    print 'EOF'
44    break
45  sys.stdout.write(line)
Note: See TracBrowser for help on using the repository browser.