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



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

def ssl_handshake_completed
  return unless should_verify?

  unless @last_cert_verified
    raise SSLError, "Unable to verify the server certificate for '#{ @hostname }'"
  end

  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
# 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)
  unless certificate
    raise SSLError, "Unable to parse SSL certificate for '#{ @hostname }'"
  end

  @last_cert = certificate
  @last_cert_verified = @cert_store.verify(certificate)
  store_cert(certificate) if @last_cert_verified

  true
end