realex icon indicating copy to clipboard operation
realex copied to clipboard

Add certificate verification

Open edzhelyov opened this issue 12 years ago • 0 comments

Hi,

In the project that I currently maintain the Realex code has been changed to support verification of the target certificated when using SSL.

Do you think this a good addition to Realex. I want to replace my local plugin with an official Realex gem, but need to address these local changes that were made.

Here is the change in client.rb:

      def call(url,xml)
        h = Net::HTTP.new('epage.payandshop.com', 443)
        h.use_ssl = true

        root_ca = File.join(File.dirname(__FILE__), 'cacert.pem')
        if File.exist?(root_ca)
          h.ca_file = root_ca
          h.verify_mode = OpenSSL::SSL::VERIFY_PEER
          h.verify_depth = 5
        else
          h.verify_mode = OpenSSL::SSL::VERIFY_NONE
          puts "Warning: no cacert.pem file found. Target host will be not checked."
        end
        response = h.request_post(url, xml)
        result = Nokogiri.XML(response.body)
        result
      end

The cacert.pem file is stated to be taken from:

cacert.pem taken from http://curl.haxx.se/docs/caextract.html
this source have been used by active_mechant https://github.com/Shopify/active_merchant/blob/master/lib/certs/cacert.pem

As I said, I'm migrating a Rails 3.1 project to 3.2 and want to replace the local plugins with gem versions, but because of these local changes and that this is related to the payment I'm more cautious.

Thank you for your time.

edzhelyov avatar Oct 24 '13 14:10 edzhelyov