Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to set the SSLServer's start_immediately field to false in order to start the SSL server in plain text mode. At any point (ie. when you receive the STARTTLS command from the client), you can call the SSLSocket's accept method to initiate SSL/TLS handshake. The client will of course have to agree to the protocol :)</p> <p>Here is a sample server I wrote to test this:</p> <pre><code>#!/usr/bin/ruby require 'socket'; require 'openssl'; certfile = 'mycert.pem'; port = 9002; server = TCPServer.new( port ); # Establish an SSL context sslContext = OpenSSL::SSL::SSLContext.new sslContext.cert = OpenSSL::X509::Certificate.new( File.open( certfile ) ); sslContext.key = OpenSSL::PKey::RSA.new( File.open( certfile ) ); # Create SSL server sslServer = OpenSSL::SSL::SSLServer.new( server, sslContext ); # Don't expect an immidate SSL handshake upon connection. sslServer.start_immediately = false; sslSocket = sslServer.accept; sslSocket.puts( "Toast.." ); # Server loop while line = sslSocket.gets line.chomp!; if "STARTTLS" == line # Starting TLS sslSocket.accept; end sslSocket.puts( "Got '#{line}'" ); end sslSocket.close; </code></pre> <p>I'm sure the original poster knows how to test STARTTLS, but the rest of us might need this reminder. Actaually I'm normally using the utils from the GNUTLS package (gnutls-bin in debian/ubuntu) to test starttls, because it allows me to start the handshake whenever I want to:</p> <pre class="lang-bash prettyprint-override"><code>$ gnutls-cli --starttls --port 9002 --insecure localhost </code></pre> <p>This connects in plain text TCP socket mode. Type some lines and get them echoed. This traffic is unencrypted. If you send <code>STARTTLS</code>, the <code>sslSocket.accept</code> is called, and the server waits for SSL handshake. Press ctrl-d (EOF) to start handshake from the gnutls client, and watch it establish an encrypted SSL connection. Subsequent lines will be echoed as well, but the traffic is now encrypted.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload