def server(port=9090): "echo server" server = coro_ssl.ssl_sock() server.create() server.bind(('', port)) server.listen(1024) while True: conn, addr = server.accept() coro.spawn(channel, conn, addr)
def server (port=9090): "echo server" server = coro_ssl.ssl_sock() server.create() server.bind (('', port)) server.listen (1024) while True: conn, addr = server.accept() coro.spawn (channel, conn, addr)
def client(): "test echo client" client = coro_ssl.ssl_sock() client.create() client.connect(('127.0.0.1', 9090)) print client.recv(8192) for i in range(10): client.send('Hello There (%d)\r\n' % i) print client.recv(8192) client.close()
def client(): "test echo client" client = coro_ssl.ssl_sock() client.create() client.connect (('127.0.0.1', 9090)) print client.recv (8192) for i in range (10): client.send ('Hello There (%d)\r\n' % i) print client.recv (8192) client.close()
def http_client(): "fetch a web page from an https server" client = coro_ssl.ssl_sock() client.create() client.connect(('192.168.200.44', 8080)) client.send('GET / HTTP/1.1\r\nConnection: close\r\n\r\n') data = '' while True: block = client.recv(8192) if block: data += block else: break print data client.close()
def http_client(): "fetch a web page from an https server" client = coro_ssl.ssl_sock() client.create() client.connect (('192.168.200.44', 8080)) client.send ('GET / HTTP/1.1\r\nConnection: close\r\n\r\n') data = '' while True: block = client.recv (8192) if block: data += block else: break print data client.close()
def smtp_tls_session(host, port='25', fromaddr='*****@*****.**', to='*****@*****.**'): print "smtp tls test client" sock = coro.make_socket(socket.AF_INET, socket.SOCK_STREAM) print "host=%r port=%r" % (host, port) port = string.atoi(port) sock.connect((host, port)) print sock.recv(8192) sock.send('EHLO fang\r\n') print sock.recv(8192) sock.send('STARTTLS\r\n') print sock.recv(8192) ctx = coro_ssl.ssl_ctx(sslip.SSLV2_CLIENT_METHOD) client = coro_ssl.ssl_sock(ctx) client.create(sock=sock) # client.ssl.set_connect_state() try: coro.print_stderr('calling ssl_connect()\n') client.ssl_connect() coro.print_stderr('ssl_connect done()\n') except sslip.Error: coro.print_stderr("TLS negotiation failed\n") coro.print_stderr("hit <return> to attempt fallback\n") client.shutdown() raw_input() else: sock = client print "ssl_connect() finished" sock.send('HELP\r\n') print sock.recv(8192) sock.send('MAIL FROM:<' + fromaddr + '>\r\n') print sock.recv(8192) sock.send('RCPT TO:<' + to + '>\r\n') print sock.recv(8192) sock.send('DATA\r\n') print sock.recv(8192) sock.send( 'From: ' + fromaddr + '\r\nSubject: testing STARTTLS\r\n\r\nHi there. I was encrypted\r\n.\r\n' ) print sock.recv(8192) sock.send('QUIT\r\n') print sock.recv(8192) sock.close() coro._exit = 1
def smtp_tls_session ( host, port='25', fromaddr='*****@*****.**', to='*****@*****.**' ): print "smtp tls test client" sock = coro.make_socket (socket.AF_INET, socket.SOCK_STREAM) print "host=%r port=%r" % (host, port) port = string.atoi(port) sock.connect ((host, port)) print sock.recv (8192) sock.send ('EHLO fang\r\n') print sock.recv (8192) sock.send ('STARTTLS\r\n') print sock.recv (8192) ctx = coro_ssl.ssl_ctx (sslip.SSLV2_CLIENT_METHOD) client = coro_ssl.ssl_sock (ctx) client.create (sock=sock) # client.ssl.set_connect_state() try: coro.print_stderr ('calling ssl_connect()\n') client.ssl_connect() coro.print_stderr ('ssl_connect done()\n') except sslip.Error: coro.print_stderr ("TLS negotiation failed\n") coro.print_stderr ("hit <return> to attempt fallback\n") client.shutdown() raw_input() else: sock = client print "ssl_connect() finished" sock.send ('HELP\r\n') print sock.recv (8192) sock.send ('MAIL FROM:<' + fromaddr + '>\r\n') print sock.recv (8192) sock.send ('RCPT TO:<' + to + '>\r\n') print sock.recv (8192) sock.send ('DATA\r\n') print sock.recv (8192) sock.send ('From: ' + fromaddr + '\r\nSubject: testing STARTTLS\r\n\r\nHi there. I was encrypted\r\n.\r\n') print sock.recv (8192) sock.send ('QUIT\r\n') print sock.recv (8192) sock.close() coro._exit = 1
def smtp_tls_server_session (conn): oconn = conn conn.send ('200 howdy\r\n') while True: cmd = conn.recv (1024) coro.print_stderr ('got %r\r\n' % (cmd,)) cmd = cmd.lower() if cmd.startswith ('starttls'): conn.send ('220 ready for tls\r\n') ctx = coro_ssl.ssl_ctx (sslip.SSLV23_SERVER_METHOD) try: sconn = coro_ssl.ssl_sock (ctx) sconn.create (sock=conn) sconn.ssl_accept() conn = sconn except sslip.Error: # conn.send ('454 TLS negotiation failed\r\n') pass elif cmd.startswith ('data'): conn.send ('354 go ahead\r\n') while True: block = conn.recv (8192) if block.endswith ('\r\n.\r\n'): break conn.send ('250 Ok.\r\n') elif cmd.startswith ('quit'): conn.send ('221 byte\r\n') conn.close() break elif cmd.startswith ('ehlo'): conn.send ( '250-loki.ironport.com\r\n' '250-PIPELINING\r\n' '250-SIZE 10240000\r\n' '250-STARTTLS\r\n' '250 8BITMIME\r\n' ) else: conn.send ('200 ok\r\n')
def smtp_tls_server_session (conn): oconn = conn conn.send ('200 howdy\r\n') while 1: cmd = conn.recv (1024) coro.print_stderr ('got %r\r\n' % (cmd,)) cmd = cmd.lower() if cmd.startswith ('starttls'): conn.send ('220 ready for tls\r\n') ctx = coro_ssl.ssl_ctx (sslip.SSLV23_SERVER_METHOD) try: sconn = coro_ssl.ssl_sock (ctx) sconn.create (sock=conn) sconn.ssl_accept() conn = sconn except sslip.Error: #conn.send ('454 TLS negotiation failed\r\n') pass elif cmd.startswith ('data'): conn.send ('354 go ahead\r\n') while 1: block = conn.recv (8192) if block.endswith ('\r\n.\r\n'): break conn.send ('250 Ok.\r\n') elif cmd.startswith ('quit'): conn.send ('221 byte\r\n') conn.close() break elif cmd.startswith ('ehlo'): conn.send ( '250-loki.ironport.com\r\n' '250-PIPELINING\r\n' '250-SIZE 10240000\r\n' '250-STARTTLS\r\n' '250 8BITMIME\r\n' ) else: conn.send ('200 ok\r\n')
def _make_socket (self): global ssl_ctx ssl_sock = coro_ssl.ssl_sock(ssl_ctx) ssl_sock.create() return ssl_sock
def _make_socket(self): global ssl_ctx ssl_sock = coro_ssl.ssl_sock(ssl_ctx) ssl_sock.create() return ssl_sock