Sha256: e0a2009aa96fd64dce9a423228aa4748cdddf47f96bec54c36a5a76626e69a5e
Contents?: true
Size: 963 Bytes
Versions: 6
Compression:
Stored size: 963 Bytes
Contents
require 'socket' require 'openssl' require 'forwardable' module Grocer class SSLConnection extend Forwardable def_delegators :@ssl, :write, :read attr_accessor :certificate, :passphrase, :gateway, :port def initialize(options = {}) options.each do |key, val| send("#{key}=", val) end end def connected? !@ssl.nil? end def connect cert_data = File.read(certificate) context = OpenSSL::SSL::SSLContext.new context.key = OpenSSL::PKey::RSA.new(cert_data, passphrase) context.cert = OpenSSL::X509::Certificate.new(cert_data) @sock = TCPSocket.new(gateway, port) @ssl = OpenSSL::SSL::SSLSocket.new(@sock, context) @ssl.sync = true @ssl.connect end def disconnect @ssl.close if @ssl @ssl = nil @sock.close if @sock @sock = nil end def reconnect disconnect connect end end end
Version data entries
6 entries across 6 versions & 1 rubygems