Skip to content

Commit

Permalink
switched to identifying certificate by CN instead of ugly suject. Min…
Browse files Browse the repository at this point in the history
…or cleanup
  • Loading branch information
ihamburglar committed Apr 30, 2015
1 parent 4852ef4 commit b2ff5be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions examples/simple/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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')
Expand Down
10 changes: 6 additions & 4 deletions examples/simple/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down

0 comments on commit b2ff5be

Please sign in to comment.