From b2ff5bedccc666469d6456509cd6936e32b3b773 Mon Sep 17 00:00:00 2001 From: Jim Shaver Date: Thu, 30 Apr 2015 08:26:29 -0400 Subject: [PATCH] switched to identifying certificate by CN instead of ugly suject. Minor cleanup --- examples/simple/client.py | 8 +++++--- examples/simple/server.py | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/simple/client.py b/examples/simple/client.py index aa591ca7a..a9a0effec 100644 --- a/examples/simple/client.py +++ b/examples/simple/client.py @@ -8,12 +8,14 @@ Simple SSL client, using blocking I/O """ -from OpenSSL import SSL +from OpenSSL import SSL, crypto import sys, os, select, socket def verify_cb(conn, cert, errnum, depth, ok): # This obviously has to be updated - print('Got certificate: %s' % cert.get_subject()) + certsubject = crypto.X509Name(cert.get_subject()) + commonname = certsubject.commonName + print('Got certificate: ' + commonname) return ok if len(sys.argv) < 3: @@ -41,7 +43,7 @@ def verify_cb(conn, cert, errnum, depth, ok): break try: sock.send(line) - sys.stdout.write(sock.recv(1024)) + sys.stdout.write(sock.recv(1024).decode('utf-8')) sys.stdout.flush() except SSL.Error: print('Connection died unexpectedly') diff --git a/examples/simple/server.py b/examples/simple/server.py index 97e18a7a0..f07cfc209 100644 --- a/examples/simple/server.py +++ b/examples/simple/server.py @@ -8,13 +8,15 @@ Simple echo server, using nonblocking I/O """ -from OpenSSL import SSL +from OpenSSL import SSL, crypto import sys, os, select, socket def verify_cb(conn, cert, errnum, depth, ok): # This obviously has to be updated - print('Got certificate: %s' % cert.get_subject()) + certsubject = crypto.X509Name(cert.get_subject()) + commonname = certsubject.commonName + print(('Got certificate: ' + commonname)) return ok if len(sys.argv) < 2: @@ -57,7 +59,7 @@ def dropClient(cli, errors=None): while 1: try: - r, w, _ = select.select([server]+clients.keys(), writers.keys(), []) + r, w, _ = select.select([server] + list(clients.keys()), list(writers.keys()), []) except: break @@ -69,7 +71,7 @@ def dropClient(cli, errors=None): else: try: - ret = cli.recv(1024) + ret = cli.recv(1024).decode('utf-8') except (SSL.WantReadError, SSL.WantWriteError, SSL.WantX509LookupError): pass except SSL.ZeroReturnError: