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

    hmm.... i find dis really wierd cuz i used the same code b4 and it worked without ne problems. Now its having problems. I just do not get y PHP cant execute a binary in a Win32 environment cuz der r no access rights for files.

    nebody have ne clues?

      If the .exe is not in the current directory, and is also not in any of the directories in the environment's PATH variable, then Windows won't be able to find it. Windows doesn't recognize PGPPATH coz it's not a standard environment variable for it. Maybe it's only used by PGP, but Windows won't use it. Therefore, you have to add the full path to pgp.exe

      Diego

        @ Diego,
        Ya i thought of that too, so i tried adding the path to the PGP binaries to the PATH environment of windows and I can access the pgpe.exe from any directory just by typing it in the DOS shell. But its still not working.

        funny thing is, PHP will execute any other command. for example i can get the contents by executing this:

        dir . > dirlist.txt

        I can also put that line inside a batch file and I can run the batch file thru PHP and has no problem. Its jus when it comes to this binary.

          Write a Reply...