def new_ctx (cert=None, chain=(), key=None, proto=None, ciphers=None, dhparam=None, next_protos=None): ctx = openssl.ssl_ctx() if cert: ctx.use_cert (cert, chain) if key: ctx.use_key (key) if proto: ctx.set_options (ctx.get_options() | ssl_op_map[proto]) if ciphers: ctx.set_ciphers (ciphers) if dhparam: ctx.set_tmp_dh (dhparam) if next_protos: ctx.set_next_protos (next_protos) return ctx
def new_ctx(cert=None, chain=(), key=None, proto=None, ciphers=None, dhparam=None, next_protos=None): ctx = openssl.ssl_ctx() if cert: ctx.use_cert(cert, chain) if key: ctx.use_key(key) if proto: ctx.set_options(ctx.get_options() | ssl_op_map[proto]) if ciphers: ctx.set_ciphers(ciphers) if dhparam: ctx.set_tmp_dh(dhparam) if next_protos: ctx.set_next_protos(next_protos) return ctx
# -*- Mode: Python -*- import coro from coro.ssl import openssl import coro.ssl import coro.backdoor W = coro.write_stderr ctx = openssl.ssl_ctx() ctx.use_cert (openssl.x509 (open ('../../http/cert/server.crt').read())) ctx.use_key (openssl.pkey (open ('../../http/cert/server.key').read(), '', True)) ctx.set_ciphers ('RC4-SHA:RC4-MD5:ALL') # ctx.set_tmp_dh (openssl.dh_param (open ('../../http/cert/dh_param_1024.pem').read())) # ctx.set_next_protos (['spdy/2', 'http/1.1']) def session (conn, addr): conn.ssl.set_fd (conn.fd) try: print 'conn=', conn, conn.__class__ while 1: block = conn.recv (1000) if not block: break else: conn.send (block) finally: coro.sleep_relative (1000) W ('why for I exit?\n') all_conns = []