Class: Faye::WebSocket::SslVerifier

Inherits:
Object
  • Object
show all
Defined in:
lib/faye/websocket/ssl_verifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(hostname, ssl_opts) ⇒ SslVerifier

Returns a new instance of SslVerifier.


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/faye/websocket/ssl_verifier.rb', line 29

def initialize(hostname, ssl_opts)
  @hostname   = hostname
  @ssl_opts   = ssl_opts
  @cert_store = OpenSSL::X509::Store.new

  if root = @ssl_opts[:root_cert_file]
    [root].flatten.each { |ca_path| @cert_store.add_file(ca_path) }
  else
    @cert_store.set_default_paths
  end
end

Instance Method Details

#ssl_handshake_completedObject


57
58
59
60
61
62
63
# File 'lib/faye/websocket/ssl_verifier.rb', line 57

def ssl_handshake_completed
  return unless should_verify?

  unless identity_verified?
    raise SSLError, "Host '#{ @hostname }' does not match the server certificate"
  end
end

#ssl_verify_peer(cert_text) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/faye/websocket/ssl_verifier.rb', line 41

def ssl_verify_peer(cert_text)
  return true unless should_verify?

  certificate = parse_cert(cert_text)
  return false unless certificate

  unless @cert_store.verify(certificate)
    raise SSLError, "Unable to verify the server certificate for '#{ @hostname }'"
  end

  store_cert(certificate)
  @last_cert = certificate

  true
end