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
Support ssl_verify_peer with wss. #101
Conversation
* add :trust_ca option * implement ssl_verify_peer on Connection
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.
I suspect that correctly implementing SSL cert validation via this EM ssl_verify_peer
interface is kinda impossible, without EM changes to properly support cert chain validation, but the PR for that has been open since 2012 😱 eventmachine/eventmachine#378
|
||
def ssl_verify_peer(cert) | ||
crt = OpenSSL::X509::Certificate.new(cert) | ||
return @cert_store.verify(crt) || @trust_ca.any?{|ca| ca.verify(crt.public_key) } |
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.
I didn't test this code yet, but immediate problems that I see with this:
- The EM OpenSSL verify callback ignores the OpenSSL cert preverify errors, i.e. it doesn't care if the server-supplied cert and private key do not match? ssl_verify_peer() not called on CA mismatch of cert and key eventmachine/eventmachine#275 https://github.com/eventmachine/eventmachine/blob/v1.2.3/ext/ssl.cpp#L589
- This callback gets called with each individual cert in the chain that the server sends? How will it work if the server sends an intermediate CA cert that's not in the cert store?
- This doesn't actually validate the depth=0 cert's CN against the URI host, so it will accept any valid cert for any domain?
- No cert validity (NotBefore/NotAfter) checks etc.
@authorNari Apologies it's taken me so long to respond to this; it's been a bit of a rough year so far. My initial gut reaction to this, which was confirmed by @SpComb's comments, is that I don't have the domain expertise to maintain SSL-related implementation and I'd rather not have it be baked into my libraries. I'm fine with passing options off to an underlying I/O system we're relying on (e.g. if EventMachine handled this) or, I could provide some hooks in the API for you to inject these checks yourself. Is there an API design that we could add to this library that would let you add this SSL code into the connection process? |
AFAIK: no I came to the conclusion that EM's SSL support is just fundamentally flawed, and there's no reasonable way to support SSL cert verification (client or server). It just doesn't expose the necessary information from libssl, so while you can make some crude attempts at trying to whitelist some specific certificates, it's never going work correctly without changes to EM (eventmachine/eventmachine#378). We ended up getting rid of EM on the client side, and writing our own websocket client library with faye/websocket-driver-ruby and ruby stdlib We still use EM on the server side, but that's with haproxy handling the SSL termination and proxying the websocket connections. (EDIT: use more considerate terminology) |
I suspect @SpComb's comments are how we should resolve this. If you have issues at the transport layer, then either:
|
To clarify: given it looks like EventMachine does not support the functionality you want, then I consider it out of scope for this library and you would be better served integration a good TLS implementation with websocket-driver. |
@SpComb I'd also be very grateful if you could avoid using the word 'sane' to refer to software designs you find agreeable. There are usually better terms you could use to refer more specifically to the problem at hand. |
Hi! Maintainer of EventMachine here. I'd love to improve our TLS support, and whatever else I can do to support this project. Note that while I don't have a ton of time, I am always happy to review PRs and shepherd out EM releases. |
Hi @sodabrew, I'm not entirely sure if this is the right PR/issue to discuss this on, but I can briefly summarize what EM support I think would be required for implementing SSL clients with server certificate verification, Listed in terms of the exposed libssl APIs:
I think the Additional bonus points for:
|
If this is going to turn into discussing changes to EventMachine, I'd appreciate it if a thread could be opened on that project rather than being continued here. At such time as an acceptable API exists in EM I'm happy to take another look. |
Thanks to @sodabrew for chiming in and offering help :) |
However it is open to MITM attack so it is no secure at all. |
fbb94f0
to
9d4f1bb
Compare
@authorNari @sodabrew @SpComb we may now be able to move this issue forward. Last month, I have opened #129 as an attempt to adapt the
That last point means it performs additional verification to what's done here, but I don't know what other functionality it still lacks that we might be able to add. I would add that I would still much rather that EventMachine integrated SSL verification into |
This has now been superseded by the merging of #129. |
EM::Connection should implements a
.ssl_verify_peer
method when you use averify_peer: true
option.http://www.rubydoc.info/github/eventmachine/eventmachine/EventMachine/Connection#ssl_verify_peer-instance_method
So I implement these code.
.ssl_verify_peer
on Connection