I'm trying to convert a bit of PHP code to Ruby. The code snippet is located here: https://developer.2c2p.com/docs/read-payment-response-1 (located at the bottom of the page) and I'm trying to understand how I'd go about implementing this in Ruby. I've got as far as:
payment_response = params.dig(:paymentResponse)
cert_store = OpenSSL::X509::Store.new
my_cert = OpenSSL::X509::Certificate.new(File.read('config/twoctwop_keys/demo2.crt'))
signature = OpenSSL::PKCS7.new(File.read('config/twoctwop_keys/demo2.pem'))
signature.verify([my_cert], cert_store, payment_response, OpenSSL::PKCS7::NOVERIFY)
signature.data
However with the above I seem to be getting the following error:
ArgumentError: Could not parse the PKCS7: nested asn1 error
from the following line:
OpenSSL::PKCS7.new(File.read('config/twoctwop_keys/demo2.pem'))
Without pasting the contents of the demo2.pem file it seems to contain multiple certificates since I can see:
Bag Attributes
Microsoft Local Key set: <No Values>
localKeyID: 01 00 00 00
friendlyName: omitted
Microsoft CSP Name: Microsoft RSA SChannel Cryptographic Provider
Key Attributes
X509v3 Key Usage: 10
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,3A2DD8162BC67378
..... key......
-----END RSA PRIVATE KEY-----
Bag Attributes
localKeyID: 01 00 00 00
friendlyName: demo2.2c2p.com
subject=/C=SG/ST=Singapore/L=Singapore/O=xx Pte Ltd./OU=xxx IT/CN=xxx
issuer=xxxx
-----BEGIN CERTIFICATE-----
....key....
-----END CERTIFICATE-----
Bag Attributes: <Empty Attributes>
subject=/CN=SinaptIQ CA
issuer=/CN=SinaptIQ CA
-----BEGIN CERTIFICATE-----
....key....
-----END CERTIFICATE-----
Is there something that I'm not understanding here.