File: echod-threading.py

package info (click to toggle)
m2crypto 0.46.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,964 kB
  • sloc: python: 22,936; makefile: 213; ansic: 94; sh: 17
file content (36 lines) | stat: -rw-r--r-- 977 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python

"""A multi-threading SSL 'echo' server.

Copyright (c) 1999-2003 Ng Pheng Siong. All rights reserved."""

from M2Crypto import DH, Rand, SSL, threading
import echod_lib


class ssl_echo_handler(echod_lib.ssl_echo_handler):

    buffer = "Ye Olde Threading Echo Servre\r\n"

    def finish(self):
        # Threading servers need this.
        self.request.set_shutdown(SSL.SSL_SENT_SHUTDOWN | SSL.SSL_RECEIVED_SHUTDOWN)
        self.request.close()


if __name__ == "__main__":
    try:
        threading.init()
        Rand.load_file("../randpool.dat", -1)
        ctx = echod_lib.init_context(
            "sslv23",
            "server.pem",
            "ca.pem",
            SSL.verify_peer | SSL.verify_fail_if_no_peer_cert,
        )
        ctx.set_tmp_dh("dh1024.pem")
        s = SSL.ThreadingSSLServer(("", 9999), ssl_echo_handler, ctx)
        s.serve_forever()
        Rand.save_file("../randpool.dat")
    except:
        threading.cleanup()