-
Notifications
You must be signed in to change notification settings - Fork 421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Begin making examples Python 3 compatible #245
Changes from all commits
f2e2a0d
0d4ec3e
71ad368
0529886
8a4a7ae
a6d16be
473fe6a
aab9ddd
4852ef4
b2ff5be
90a3117
677402f
e461dad
75feb89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ __pycache__ | |
doc/_build/ | ||
.coverage | ||
.eggs | ||
examples/simple/*.cert | ||
examples/simple/*.pkey |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,17 +8,18 @@ | |
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are these changes needed, particularly the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I should have made a comment to clarify :). This is what you get on master: This is what you get with that: I think that is the direction the orig author was going in when he said: "# This obviously has to be updated". I can remove the comment if you agree. I suppose there are less spoofable things that we could use to identify the certs in addition to the CN, like the fingerprint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah please get rid of the comment. there’s nothing obvious about it. |
||
return ok | ||
|
||
if len(sys.argv) < 2: | ||
print 'Usage: python[2] server.py PORT' | ||
print('Usage: python server.py PORT') | ||
sys.exit(1) | ||
|
||
dir = os.path.dirname(sys.argv[0]) | ||
|
@@ -44,40 +45,40 @@ def verify_cb(conn, cert, errnum, depth, ok): | |
|
||
def dropClient(cli, errors=None): | ||
if errors: | ||
print 'Client %s left unexpectedly:' % (clients[cli],) | ||
print ' ', errors | ||
print('Client %s left unexpectedly:' % (clients[cli],)) | ||
print(' ', errors) | ||
else: | ||
print 'Client %s left politely' % (clients[cli],) | ||
print('Client %s left politely' % (clients[cli],)) | ||
del clients[cli] | ||
if writers.has_key(cli): | ||
if cli in writers: | ||
del writers[cli] | ||
if not errors: | ||
cli.shutdown() | ||
cli.close() | ||
|
||
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 | ||
|
||
for cli in r: | ||
if cli == server: | ||
cli,addr = server.accept() | ||
print 'Connection from %s' % (addr,) | ||
print('Connection from %s' % (addr,)) | ||
clients[cli] = addr | ||
|
||
else: | ||
try: | ||
ret = cli.recv(1024) | ||
ret = cli.recv(1024).decode('utf-8') | ||
except (SSL.WantReadError, SSL.WantWriteError, SSL.WantX509LookupError): | ||
pass | ||
except SSL.ZeroReturnError: | ||
dropClient(cli) | ||
except SSL.Error, errors: | ||
except SSL.Error as errors: | ||
dropClient(cli, errors) | ||
else: | ||
if not writers.has_key(cli): | ||
if cli not in writers: | ||
writers[cli] = '' | ||
writers[cli] = writers[cli] + ret | ||
|
||
|
@@ -88,7 +89,7 @@ def dropClient(cli, errors=None): | |
pass | ||
except SSL.ZeroReturnError: | ||
dropClient(cli) | ||
except SSL.Error, errors: | ||
except SSL.Error as errors: | ||
dropClient(cli, errors) | ||
else: | ||
writers[cli] = writers[cli][ret:] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to PEP 3113 tuple unpacking is deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it’s actually even removed in Python 3 (which kind of sucks when doing Twisted)