HowTo Encrypt form submissions - Ensim 3.0

Article By : admin | User Rating : Average Rating : 1.00 From 5 Voter(s)

HowTo Encrypt form submissions - Ensim 3.0


If you are not using a merchant account and gateway to processor your online orders in real time you may need to receive an email with sensitive credit card information for manual processing. There are a couple of steps in order to make sure that the data you are passing is secure:


1. The website that form is being submitted from is using an SSL Cert...such as the GeoTrust Certs RS offers

2. The data needs to be encrypted before being sent...then un encrypted by the recipient using a private key


This How-To describes the process for installing and using GnuPG encryption to secure transmissions sent from your web server. I will describe how to set it up for both the main server site as well as any virtual sites. There are several prerequisites and assumptions that are made:


- Ensim 3.0 server (although I'm sure this will work for 3.1 as well)

- PHP compiled in CGI mode

- Madsere's ensimpkg


- admin for the site has SSH turned on

- You or your customer has downloaded and installed pgp on your home/office PC from https://store.pgp.com/display.php?pageID=2. There is a freeware version as well as commercial versions. You decide how you will be using the product in order to abide by the terms of download.


So let's get started...


Step 1 - Installing GnuPG for use by the virtual site


GnuPG-1.0.6 is installed on Ensim by default. To verify type the following as root:


rpm -q gnupg


You should also have a site with a secure certificate installed. You can install a self-signed Cert or you can purchase one and have it installed. For the purposes of this How-To, We are going to assume that it is installed in virtual site1 which is named domain.com.


We need to install the appropriate rpms necessary for GnuPG (gpg) to be accessible from our site1. So we are going to use Madsere's ensimpkg to install several rpms (again we are assuming that you have already installed ensimpkg using Madsere's How To):


First lets install gpg to site1:


addpkg domain.com gnupg


We will also need zlib installed in the virtual, so:


addpkg domain.com zlib


gpg uses the urandom node in the encryption algorithms, so you will need to create the node for the virtual site:


mknod -m 0644 /home/virtual/site1/fst/dev/urandom c 1 9


Now we can su to admin@domain.com(site1/admin1):


su admin@domain.com


Now let's generate the keyring for admin by typing:


gpg


You should see the following:




Quote:

gpg: Warning: using insecure memory!

gpg: /home/admin/.gnupg: directory created

gpg: /home/admin/.gnupg/options: new options file created

gpg: you have to start GnuPG again, so it can read the new options file

 


 


This indicates that the keyring has been setup. Step 1 is complete


Step 2 - Generating the Public Key and importing into the server


So now we need to generate a public key to be imported into our keyring on the server so we can use it to encrypt messages.


Open the PGP program on your PC and create a key pair. When prompted, enter your Full Name and email address. Click Next.

Create a Diffie-Hellman/DSS key. Click Next

Make the key size at least 1024 bits. Click Next

Set the key to never expire. Click Next

Enter a passphrase you will remember. You will have to type it each time they want to decrypt a message. Click Next

No need to send the key to the root server. Click Next Click Finish

Make a backup of the key when prompted

While still in PGP Keys, right click on the key you generated (should have a person icon next to it) and click "export..."

The file to export will be an ASCII file (i.e. full name.asc). This will only export the PUBLIC key, not the PRIVATE one. There is NO security risk in sharing the public key. In fact you want others to have it so they can send you encrypted emails.

Close PGP.


Now let's ftp the public key to the server and import it into the keyring:

FTP the ASCII file (full name.asc) to /home/virtual/site1/fst/home/admin

SSH into the server and su to admin@domain.com. (Skip this if you still have the SSH terminal open from earlier)

Now to import the key type:


gpg --import /home/virtual/site1/fst/home/admin/Full Name.asc (Note: if your ASCII filename has a space in it make sure you escape it by preceding it with a character)


If all goes well then you should get something like:


Quote:

gpg: Warning: using insecure memory!

gpg: key D252E851: public key imported

gpg: /home/admin/.gnupg/trustdb.gpg: trustdb created

gpg: Total number processed: 1

gpg: imported: 1

 


 


You can see the key by typing:


gpg --list-key


You should see something like the following:


Quote:

gpg: Warning: using insecure memory!

/home/admin/.gnupg/pubring.gpg

------------------------------

pub 1024D/D252E851 2002-05-19 Full Name <username@yourdomain.com>

sub 2048g/61FDDF37 2002-05-19

 




There are a couple of quick things you should know about the above key listing. When we get ready to start sending the encrypted messages, we will need to specify the key. We can use the key ID "D252E851" the key name "Full Name" or the key email address "username@yourdomain.com". I use the email address as it doesn't have spaces or any weird characters...but you can use which ever one makes the most sense for your application.

Test the key and gpg by typing:


echo 'hello client' | gpg --always-trust -ear username@yourdomain.com (make sure you replace "username@yourdomain.com" with the email address of the public key)


If you get a bunch of encrypted garbage back...all is well and you are now ready to start using a form to encrypted the data.


Step 3 - Encrypting and Sending the Data


You can use either perl or php cgi scripts to encrypted and send the form resultsWe use PHP in this case.


PHP Code:

#!/usr/local/php/bin/php

<?

    // Fake information to simulate a user form submission

    $sender_name="John Doe";

    $sender_email="john@doe.com";

    $secret_msg="This is the top secret message...dont tell anyone";


    // The message we are going to encrypt

    $msg = "Sender's Full Name:t$sender_namen";

    $msg .= "Sender's E-Mail:t$sender_emailn";

    $msg .= "Secret Message?t$secret_msgnn";


    // This is the meat of the script see below the example for a description of what is happening

    // The following three lines should all be one continuous line.

    $mail_cont = `echo "$msg" | /home/virtual/site1/fst/usr/bin/gpg

       --always-trust -at -e -r username@domain.com --homedir

       /home/virtual/site1/fst/home/admin/.gnupg`;

    

    // This should be the email address of the public key you are using to encrypt

    $recipient = "username@domain.com";

    $subject = "Secret Message";


    // Mail headers for the email

    $mailheaders = "From: My Web Site <"">n";

    $mailheaders .= "Reply-To: $sender_emailnn";


    // Sending the email

    mail("$recipient", "$subject", $mail_cont, $mailheaders);


    // Display a verification

    echo "<H1 align=center>Thank You, $sender_name</h1>";

    echo "<p align=center>Your secret message has been sent.</p>";


?>




Now I will try to explain what the encryption command is doing:

$mail_cont = `echo "$msg" | /home/virtual/site1/fst/usr/bin/gpg --always-trust -at -e -r username@domain.com --homedir /home/virtual/site1/fst/home/admin/.gnupg`;


We are echoing the contents of the $msg variable through a pipe "|" to the gpg encryption. See 'man gpg' for the option flags.


-r username@domain.com tells gpg to use the public key to encrypt the contents of $msg.


--homedir /home/virtual/site1/fst/home/admin/.gnupg tells gpg where to find the public keyring that our key is in.


 


About the Author


Article submitted via email. No author information available at this time.



Webhostingresourcekit.com - The home of free server tutorials, web hosting tutorials, cpanel tutorials, and hosting articles. 300+ articles and tutorials of web hosting help speak a clear language.







Send to a friend Send to a friend
Rate this Article :

1

2

3

4

5

6

7

8

9

10
Poor Excellent

SEARCH:
Advanced Search
CATEGORIES:
EXTERNAL RESOURCES:
FREE RESOURCES:
VISITOR GUIDES:
 
Copyright 2004 - 2008 | Webhostingresourcekit.com |