You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ruby-TLS decouples the management of encrypted communications, putting you in charge of the transport layer. It can be used as an alternative to Ruby's SSLSocket.
Windows users will require an installation of OpenSSL (32bit or 64bit matching the Ruby installation)
Usage
require'rubygems'require'ruby-tls'classtransportdefinitializeis_server=truecallback_obj=selfoptions={verify_peer: true,private_key: '/file/path.pem',cert_chain: '/file/path.crt',ciphers: 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES128-SHA:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH:!CAMELLIA:@STRENGTH'# (default)# protocols: ["h2", "http/1.1"], # Can be used where OpenSSL >= 1.0.2 (Application Level Protocol negotiation)# fallback: "http/1.1", # Optional fallback to a default protocol when either client or server doesn't support ALPN# client_ca: '/file/path.pem'}@ssl_layer=RubyTls::SSL::Box.new(is_server,callback_obj,options)enddefclose_cbputs "Thetransportlayershouldbeshutdown"
enddefdispatch_cb(data)puts"Clear text data that has been decrypted"enddeftransmit_cb(data)puts"Encrypted data for transmission to remote"# @tcp.send dataenddefhandshake_cb(protocol)puts"initial handshake has completed"enddefverify_cb(cert)# Return true or falseis_cert_valid?certenddefstart_tls# Start SSL negotiation when you are ready@ssl_layer.startenddefsend(data)@ssl_layer.encrypt(data)endend## Create a new TLS connection#connection=transport.new## Init the handshake#connection.start_tls## Start sending data to the remote, this will trigger the# transmit_cb with encrypted data to send.#connection.send('client request')## Similarly when data is received from the remote it should be# passed to connection.decrypt where the dispatch_cb will be# called with clear text#