Unable to connect to web socket - Unable to verify the server certificate

I’m using the faye-websocket gem in Ruby to try to connect to the paper environment. Here’s the code:

EM.run {
  ws = Faye::WebSocket::Client.new('wss://paper-api.alpaca.markets/stream')

  ws.on :open do |event|
    p [:open]

  ws.on :message do |event|
    p [:message, event.data]

  ws.on :close do |event|
    p [:close, event.code, event.reason]
    ws = nil

  ws.on :error do |event|
    p [:error, event]

First, an error is returned with a message that says: Network error: wss://paper-api.alpaca.markets/stream: Unable to verify the server certificate for ‘paper-api.alpaca.markets’.

Then a close event with status 1006 and an empty reason string is received.

I’m a newbie to integrating with Alpaca. What am I missing here? I’m on Mac OS X.

I found on Google a way to view the certificate. From the command line:

echo | openssl s_client -servername alpaca.markets -connect alpaca.markets:443 2>/dev/null | openssl x509 -text

The first part of the output shows that the certificate should be valid until April 1st:

Signature Algorithm: sha256WithRSAEncryption
    Issuer: C=US, O=Let's Encrypt, CN=R3
        Not Before: Jan  1 04:56:05 2022 GMT
        Not After : Apr  1 04:56:04 2022 GMT
    Subject: CN=alpaca.markets
    Subject Public Key Info:
        Public Key Algorithm: rsaEncryption
            Public-Key: (2048 bit)

Is there something I need to do on my machine relating to the certificate? I could really use a hand here.

Update: I found an article about certificate validation by the faye-websocket gem. I have circumvented the problem for now by disabling certificate verification by doing this:

ws = Faye::WebSocket::Client.new(‘wss://paper-api.alpaca.markets/stream’, [], tls: { verify_peer:false })

I get an :open message now.