ruby-tls
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.
Install the gem
Install it with RubyGems
gem install ruby-tls
or add this to your Gemfile if you use Bundler:
gem "ruby-tls"
Windows users will require an installation of OpenSSL (32bit or 64bit matching the Ruby installation)
Usage
require 'rubygems'
require 'ruby-tls'
class transport
def initialize
is_server = true
callback_obj = self
options = {
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'
}
@ssl_layer = RubyTls::SSL::Box.new(is_server, callback_obj, options)
end
def close_cb
puts "The transport layer should be shutdown"
end
def dispatch_cb(data)
puts "Clear text data that has been decrypted"
end
def transmit_cb(data)
puts "Encrypted data for transmission to remote"
end
def handshake_cb(protocol)
puts "initial handshake has completed"
end
def verify_cb(cert)
is_cert_valid? cert
end
def start_tls
@ssl_layer.start
end
def send(data)
@ssl_layer.encrypt(data)
end
end
connection = transport.new
connection.start_tls
connection.send('client request')
License and copyright
MIT