Ok i have been trying to setup a web based message encryption using PGP. To cut to the chase this is waht is happening in the nutshell:
I take the message from the form thru an SSL connection and write it to a temperory file. Then i need to execute the pgpe.exe binary that will actually take the plaintext, encrypt it and output a ascii armored text file. I am having ploblems with this. The pgpe.exe never gets executed.
Heres the code:
<?php
$msg = "Sender's Full Name:\t".$_POST['sender_name']."\n";
$msg .= "Sender's E-Mail:\t".$_POST['sender_email']."\n";
$msg .= "Secret Message?\t".$_POST['secret_msg']."\n\n";
//set the environment variable for PGPPATH
putenv("PGPPATH=d:/pgp");
//generate token for unique filenames
$tmpToken = md5(uniqid(rand()));
//create vars to hold paths and filenames
$plainTxt = $tmpToken.'data';
$crypted = $tmpToken.'pgpdata';
//open file and dump in plaintext contents
$fp = fopen($plainTxt, "w");
fputs($fp, $msg);
fclose($fp);
if (!file_exists($plainTxt)) die("Error - Unable to recieve form data.");
//invoke PGP to encrypt file contents
$line = "pgpe.exe -o $crypted -a $plainTxt -r \"_USER_NAME_\" > log.ssl.txt";
shell_exec($line);
if (!file_exists($crypted)) die("$line<br>Error - Encryption process faced difficulties.");
//open file and read encrypted contents into var
$fd = fopen($crypted, "r");
$mail_cont = fread($fd, filesize($crypted));
fclose($fd);
//delete files!
unlink($plainTxt);
unlink($crypted);
// Build mail message and send it to target recipient.
$recipient = "postmaster@example.com";
$subject = "Secret Message - New Version";
$mailheaders = "From: My Web Site\n";
$mailheaders .= "Reply-To: ".$_POST['sender_email']."\n\n";
mail($recipient, $subject, $mail_cont, $mailheaders);
// Print confirmation to screen.
?>
<H1 align=center>Thank You, <?=$_POST['sender_name']?></h1>
<p align=center>Your secret message has been sent.</p>
?>
I also have an environmental variable in WIndows called PGPPath that points to the path of the binaries in addtion to the putenv in the script.
Ok this is the things that i have done to overcome this problem. I tried putting the executing command in a batch file and then runnin the batch file from PHP, still no luck. I included the full path to the pgpe.exe in the executing line (d:/pgp/pgpe.exe -o $crypted -a $plainTxt -r \"_USER_NAME_\" ) with no luck,
Up on the searching the error logs i found this line added to it each time i run the script:
"The system cannot execute the specified program."
If anybody kno y dis is happenin, please let me kno.
THnx