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
Implement STARTTLS event; Fix #113 #214
Conversation
sock.setblocking(False) | ||
self._poller.addReader(self, sock) | ||
self._clients.append(sock) | ||
self.fire(connect(sock, *sock.getpeername())) |
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.
Add check for already started starttls and don't fire connect again.
def starttls(self, sock): | ||
if not HAS_SSL: | ||
return | ||
if self.__starttls: |
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.
Oh, this seems wrong. Should be a dict of sock -> bool.
7853628
to
f8edea5
Compare
Nice! |
@handler('starttls') | ||
def starttls(self, sock): | ||
if not HAS_SSL: | ||
return # TODO: emit a warning? |
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.
Just raise an appropriate exception maybe?
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.
@prologic Done that.
Rebase? |
Current coverage is 77.10% (diff: 60.97%)
|
0c8e9dd
to
27c689e
Compare
from circuits import Component, Debugger from circuits.net.sockets import TCPServer, write from circuits.net.events import starttls class TLSEchoServer(Component): def init(self, bind): self.transport = TCPServer(bind, certfile="/circuits/tests/net/cert.pem", ).register(self) def connect(self, sock, foo, bar): self.fire(write(sock, b'* OK [CAPABILITY STARTTLS] Dovecot ready.\r\n')) def read(self, sock, data): if data.strip().upper() == b". STARTTLS": yield self.fire(write(sock, b'. OK Begin TLS negotiation now.')) self.fire(starttls(sock)) return if data.strip() == b'. CAPABILITY': self.fire(write(sock, b'* CAPABILITY STARTTLS \r\n. OK Pre-login capabilities listed, post-login capabilities have more.\r\n')) else: self.fire(write(sock, b'Thanks for TLS encrypting! You wrote: %r' % (data,))) (TLSEchoServer(("0.0.0.0", 8000)) + Debugger()).run() $ openssl s_client -connect localhost:8000 -starttls imap
$ openssl s_client -connect localhost:8000 -starttls imap