Module: Ronin::Network::SSL
Overview
Provides helper methods for communicating with SSL-enabled services.
Constant Summary collapse
- VERIFY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps SSL verify modes to
OpenSSL::SSL::VERIFY_*
constants. Hash.new do |hash,key| verify_const = if key then "VERIFY_#{key.to_s.upcase}" else 'VERIFY_NONE' end unless OpenSSL::SSL.const_defined?(verify_const) raise(RuntimeError,"unknown verify mode #{key}") end hash[key] = OpenSSL::SSL.const_get(verify_const) end
Instance Method Summary collapse
-
#ssl_connect(host, port, options = {}) {|ssl_socket| ... } ⇒ OpenSSL::SSL::SSLSocket
Establishes a SSL connection.
-
#ssl_session(host, port, options = {}) {|ssl_socket| ... } ⇒ nil
Creates a new temporary SSL connection.
Methods included from TCP
#tcp_accept, #tcp_banner, #tcp_connect, #tcp_connect_and_send, #tcp_open?, #tcp_send, #tcp_server, #tcp_server_loop, #tcp_server_session, #tcp_session, #tcp_single_server
Instance Method Details
#ssl_connect(host, port, options = {}) {|ssl_socket| ... } ⇒ OpenSSL::SSL::SSLSocket
Establishes a SSL connection.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/ronin/network/ssl.rb', line 105 def ssl_connect(host,port,={}) local_host = [:local_host] local_port = [:local_port] cert = [:cert] key = [:key] socket = tcp_connect(host,port,local_host,local_port) ssl_context = OpenSSL::SSL::SSLContext.new() ssl_context.verify_mode = SSL::VERIFY[[:verify]] if cert ssl_context.cert = OpenSSL::X509::Certificate.new(File.new(cert)) end if key ssl_context.key = OpenSSL::PKey::RSA.new(File.new(key)) end ssl_socket = OpenSSL::SSL::SSLSocket.new(socket,ssl_context) ssl_socket.sync_close = true ssl_socket.connect yield ssl_socket if block_given? return ssl_socket end |
#ssl_session(host, port, options = {}) {|ssl_socket| ... } ⇒ nil
Creates a new temporary SSL connection.
179 180 181 182 183 |
# File 'lib/ronin/network/ssl.rb', line 179 def ssl_session(host,port,={},&block) ssl_socket = ssl_connect(host,port,,&block) ssl_socket.close return nil end |