Module: SyslogShipper::TlsWrapper

Defined in:
lib/syslog_shipper/tls_wrapper.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.verifiedObject

Returns the value of attribute verified.



6
7
8
# File 'lib/syslog_shipper/tls_wrapper.rb', line 6

def verified
  @verified
end

Instance Method Details

#connection_completedObject



22
23
24
# File 'lib/syslog_shipper/tls_wrapper.rb', line 22

def connection_completed
  puts 'connection completed' if @verbose
end

#initialize(ca_cert = nil, with_tls = false, bypass_peer_check = false, verbose = false) ⇒ Object



9
10
11
12
13
14
# File 'lib/syslog_shipper/tls_wrapper.rb', line 9

def initialize(ca_cert = nil, with_tls = false, bypass_peer_check = false, verbose = false)
  @ca_cert = ca_cert
  @with_tls = true
  @bypass_peer_check = bypass_peer_check
  @verbose = verbose
end

#post_initObject



16
17
18
19
20
# File 'lib/syslog_shipper/tls_wrapper.rb', line 16

def post_init
  puts 'post init' if @verbose
  
  start_tls :verify_peer => @with_tls
end

#ssl_handshake_completedObject



56
57
58
# File 'lib/syslog_shipper/tls_wrapper.rb', line 56

def ssl_handshake_completed
  puts 'ssl handshake completed' if @verbose
end

#ssl_verify_peer(cert) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/syslog_shipper/tls_wrapper.rb', line 26

def ssl_verify_peer cert
  puts 'verifying peer' if @verbose
  unless defined?(@@verified)
    return true if @bypass_peer_check

    server_cert = OpenSSL::X509::Certificate.new cert
    verified = false

    if @ca_cert
      ca_cert = read_ca_cert
      verified = server_cert.verify(ca_cert.public_key)
    end

    unless verified
      puts server_cert.inspect
      print "The server certificate is not recognized, would you still like to connect? (Y/N) "
      answer = STDIN.gets.chomp
      unless ['y', 'yes'].include?(answer.downcase)
        raise OpenSSL::X509::CertificateError.new("Couldn't verify peer")
      end
    end
    
    @@verified = verified

    puts 'verified peer' if @verbose
  end

  true
end

#unbindObject



60
61
62
# File 'lib/syslog_shipper/tls_wrapper.rb', line 60

def unbind
  puts 'connection unbound!' if @verbose
end