README.md in localhost-1.1.4 vs README.md in localhost-1.1.5

- old
+ new

@@ -24,45 +24,57 @@ $ gem install localhost ## Usage -This example shows how to generate a certificate for an SSL secured web server: +This example shows how to generate a certificate for an SSL secured server: ```ruby -require 'localhost/authority' require 'socket' +require 'thread' +require 'localhost/authority' + +# Get the self-signed authority for localhost: authority = Localhost::Authority.fetch +ready = Thread::Queue.new + +# Start a server thread: server_thread = Thread.new do server = OpenSSL::SSL::SSLServer.new(TCPServer.new("localhost", 4050), authority.server_context) server.listen + ready << true + peer = server.accept - puts "Writing..." + peer.puts "Hello World!" peer.flush peer.close end +ready.pop + client = OpenSSL::SSL::SSLSocket.new(TCPSocket.new("localhost", 4050), authority.client_context) -# Initialize SSL connection +# Initialize SSL connection: client.connect -puts client.read +# Read the encrypted message: +puts client.read(12) client.close - server_thread.join ``` If you use Safari to access such a server, it will allow you to add the certificate to your keychain without much work. Once you've done this, you won't need to do it again for any other site when running such a development environment from the same user account. +For an example of how to make your own HTTPS web server, see [examples/https.rb](examples/https.rb). + ### Safari If you use this with a web server, when you open the site in Safari: ![Safari](media/safari.png) @@ -70,10 +82,10 @@ - Click "View the certificate" to check that it is the correct certificate. - Click "visit this website" which will prompt you to add the certificate to your keychain. Once you've done this, it should work for a long time. ### Chrome -If you use this with a web server, when you open the site in Safari: +If you use this with a web server, when you open the site in Chrome: ![Chrome](media/chrome.png) - Click "ADVANCED" to see additional details, including... - Click "Proceed to localhost (unsafe)" which will allow you to use the site for the current browser session.