This page documents my work in using encryption to increase the security of Paypal transactions (buy buttons, shopping carts, etc.) using Perl or shell scripts.
Paypal uses a series of HTML fields to transfer data about what the user is paying for. You might have something like the following on your webpage:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick" /> <input type="hidden" name="business" value="bad@foo.com" /> <input type="hidden" name="return" value="http://foo.com/thanks.html" /> <input type="hidden" name="item_name" value="Donation" /> <input type="hidden" name="amount" value="10.00" /> <input type="submit" value="Donate $10" /> </form>
The problem is that the HTML is out there for all to see. Spiders can see and visit where paypal will return you when the transaction is done (return field). Phishers and spammers can (and do) harvest the email address which receives the paypal mail. Hackers can change the value or quantities meaning that your system has to verify the amounts before delivering the product. There are best-practices and hacks that work around some of these problems but they don't go far enough.
Paypal has a solution called Encrypted Website Payments (paypal login required). Here's the EWP manual which doesn't seem to require a login. With EWP, the fields and values are signed with a local certificate which is uploaded to the Paypal servers and encrypted with a public certificate which Paypal distributes. All of this stuff is wrapped up using S/MIME and is used instead of the hidden HTML fields.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_s-xclick"> <input type="hidden" name="encrypted" value=" -----BEGIN PKCS7----- MIIG5QYJKoZIhvcNAQcDoIIG1jCCBtICAQAxggE6MIIBNgIBADCBnjCBmDELMAkG A1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExETAPBgNVBAcTCFNhbiBKb3Nl ... wkTGxwAxwWownnk9yzWnyPpK7InDhQIGFrobpf/kpfw9tkORgYR+Ufa9gcOa3Xg/ KpWp9N88uBHP/W225LYHH3AMgHi0HqQJum+8JdfWvvt5NSdJJMfTz9Y= -----END PKCS7----- " /> <input type="hidden" name="amount" value="10.00" /> <input type="submit" value="Donate $10" /> </form>
Now you can encrypt your button arguments if you use Paypal's button creation pages but that does not allow you to make changes to the arguments dynamically. What I wanted was the ability to encrypt the buttons via cgi scripts on my site. Paypal supports this but on the default pages, their only sample code is for Windows C and Java. I finally found out about the API sourcebook pages which have details about using PHP and shell encryption scripts. Thanks much to Dave and the rest of the authors of these documents for the help.
I added a Perl version of the encryption script which calls openssl directly and not the shell script. I've modified their shell script a bit to make some improvements. I've added some documentation, improved the variables, and removed the need for a temporary file. The variables for the transaction are in the params.txt file but could be coded into the shell or perl script if you were doing the buttons on the fly.
To get the encryption to work for your system you need to following the following steps. Feedback welcome.
openssl genrsa -out my_key.pem 1024
cat > openssl.cnf <<EOF [ req ] prompt = no distinguished_name = req_distinguished_name [ req_distinguished_name ] C = US ST = Your state L = Your city O = YourDomain.com OU = YourDomain.com EOF
openssl req -new -config openssl.cnf -key my_key.pem -x509 -days 365 -out my_cert.pem
Enjoy. Feedback welcome.
Free Spam Protection Android ORM Simple Java Zip JMX using HTTP Great Eggnog Recipe