-
-
Notifications
You must be signed in to change notification settings - Fork 28
Add an example for a SSL server #67
Comments
Not sure if this helps, but there are examples of how to configure SSL certificates here: https://github.com/socketry/sus-fixtures-openssl/tree/main/test/sus/fixtures/openssl They can be used like this: https://github.com/socketry/async-http/blob/main/test/async/http/ssl.rb Does that help? |
As an aside, I'd prefer if we had less OpenSSL specific methods of constructing SSL connections - as there are multiple implementations of SSL and they basically just need the right certificates. Because we depend specifically on the OpenSSL context interface, we depend on OpenSSL itself. |
I would also be interested in such an example - especially if it is also possible to apply StartSSL. (without creating an OpenSSL instance myself). If there is no support for StartSSL yet, I would make a feature request. |
For Ruby 3.1+ using Async 2, By the time Ruby 3.0 is EOL, this gem will also be EOL. I don't think we should continue to extend this gem for new features, as it was originally designed as a shim for Ruby's IO classes. In that case, my suggestion is we fix any deficiencies in Ruby's core IO classes. |
That means the recommendation now for Ruby 3.1 and higher is not to use async-io anymore, but the native Ruby library? Will other async gems also be EOL then? |
You can continue to use it. We may make a final "Ruby 3.1" shim update which basically replaces all the wrappers with native IO. Other Async gems will become compatible with raw Extracting the endpoint functionality is going on here: https://github.com/socketry/io-endpoint |
Wow I was unaware of this. Since I have some WIP gems that use |
I managed to create a simple SSL server example: #!/usr/bin/env ruby
require 'async'
require 'async/io'
require 'async/io/stream'
key_file = File.join(__dir__,'key.pem')
cert_file = File.join(__dir__,'cert.crt')
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_context.key = OpenSSL::PKey::RSA.new(File.read(key_file))
ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(cert_file))
endpoint = Async::IO::Endpoint.ssl('localhost',5678, ssl_context: ssl_context)
Async do |async|
endpoint.accept do |peer|
stream = Async::IO::Stream.new(peer)
stream.puts "Hello!"
while line = stream.read_partial
puts "Received: #{line}"
end
end
end @ioquatix should I submit a PR or post it Discussions? |
Please feel free to contribute it into the examples directory with a working client and server. |
I think it would be beneficial to add an example of how to start a SSL/TLS server using custom SSL certificate and private key files. It appears that Async::IO::Endpoint.ssl accepts a
ssl_context
keyword argument. Is that how you create a custom SSL/TLS server? Or is there another way to pass in the SSL certificate and key information?The text was updated successfully, but these errors were encountered: