I have been setting up a shopping cart and checkout by working through the series of RailsCasts(#141-143) and am pretty new to using OpenSSL and pkcs7. Everything has been working perfectly up until implementing security measures in (episode 143: http://railscasts.com/episodes/143-paypal-security). I keep getting a "pkcs7 add signer error"
My paypal_encripted encrypt_for_paypal methods are as follows:
def paypal_encrypted(return_url, notify_url)
values = {
:business => 'merchant@christianorourke.com',
:cmd => '_cart',
:upload => 1,
:return => return_url,
:invoice => id,
:notify_url => notify_url,
:cert_id => "ABKW58VTNJ9LY"
}
order_items.each_with_index do |item, index|
values.merge!({
"amount_#{index+1}" => item.unit_price,
"item_name_#{index+1}" => item.product.name,
"item_number_#{index+1}" => item.id,
"quantity_#{index+1}" => item.quantity
})
end
encrypt_for_paypal(values)
end
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
I am really unsure as to what is going wrong so any help would be greatly appreciated.