title: How to verify server SSL certificate?
body: <p>I am a newbie on SSL concept, I am trying to connect to API which has x509 mutual auth using HTTParty.</p>
  
  <p>I got client cert, client key and server cert (all are pem files). </p>
  
  <p>I got it working with client cert and key and with <code>verify: false</code>. </p>
  
  <p>Now next step is how to verify server cert also?</p>
  
  <p>HTTParty documentation link <a href="https://github.com/jnunemaker/httparty/tree/master/docs#working-with-ssl" rel="nofollow noreferrer">https://github.com/jnunemaker/httparty/tree/master/docs#working-with-ssl</a></p>
  
  <pre><code>class ServiceClient
    include HTTParty
    DEFAULT_HEADERS = {
      'Content-Type' =&gt; 'application/json'
    }.freeze
    base_uri 'https://example.com'
    pem File.read("#{File.expand_path('.')}/path/to/certs/cert.pem")
  
    def self.iframe_url(**payload)
      post(
       '/test/create',
       body: payload.to_json,
       headers: DEFAULT_HEADERS,
       verify: false
      )
    end
  end
  </code></pre>
  
  <p>Call to service client</p>
  
  <pre><code>payload = {user_id: "100", account_id: "1234"} 
  ServiceClient.iframe_url(payload)
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>HTTParty is not a hard requirement so solution with any http client would work for me. </p>
  
  <p>If I remove <code>verify: false</code> I get below error.</p>
  
  <pre><code>OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=error: certificate verify failed
  </code></pre>