source: python/TLSLite/shared/server.py @ 29

Revision 29, 1.0 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 SocketServer as ss
6import tlslite.api as tls
7
8sharedKeyDB = tls.SharedKeyDB()
9sharedKeyDB.create()
10sharedKeyDB['nakiki'] = 'nakikinakiki'
11
12# 共有鍵を使った例
13class Handler(ss.StreamRequestHandler):
14  def setup(self):
15    self.connection = tls.TLSConnection(self.request)
16    self.connection.closeSocket = True
17    settings = tls.HandshakeSettings()
18    settings.cipherNames = ["aes128"]
19    self.connection.handshakeServer(sharedKeyDB = sharedKeyDB,
20      settings = settings)
21    self.rfile = self.connection.makefile('rb', self.rbufsize)
22    self.wfile = self.connection.makefile('wb', self.wbufsize)
23
24  def handle(self):
25    print 'handle'
26    while 1:
27      line = self.rfile.readline()
28      if len(line) == 0:
29        return
30      self.wfile.write(line)
31
32class Server(ss.ThreadingTCPServer):
33  allow_reuse_address = 1
34  daemon_threads = 1
35
36server = Server(('localhost', 3747), Handler)
37print 'listening:', server.socket.getsockname()
38server.serve_forever()
Note: See TracBrowser for help on using the repository browser.