. * *************************************************************/ // check that data has arrived here via HTTPS if ($_SERVER['HTTPS'] != "on") { die ("Use a secure HTTPS connection to the server. Aborting ..."); } // use GET without data only if (strtoupper($_SERVER['REQUEST_METHOD']) != "POST") { //check if there is a query string, then abort. if (count($_GET) != 0){ die ("Always use POST to prevent recording of query strings. Aborting ..."); } } if (! is_file("gpgconfig.php")){ die ("Config file does not exist."); } require_once('gpgconfig.php'); if (! is_dir($GPGDIR)){ die ("GPG directory $GPGDIR does not exist."); } else { $ERRORFILE = $GPGDIR."/gpgerrors"; } $TEXT = ""; if (isset($_REQUEST[$ENCRYPTIONTEXTAREA])) { $TEXT = $_REQUEST[$ENCRYPTIONTEXTAREA]; // quote newlines and " and ' to preserve them $TEXT = addslashes($TEXT); } if (! isset($KEYSELECTION)){ $KEYSELECTION = "no"; } if (! isset($IFRAMENUMBER)){ $IFRAMENUMBER = 0; } if (! isset($SHOWTEXTAREA)){ $SHOWTEXTAREA = "no"; } if (isset($_REQUEST['encryptionkey'])){ $ENCRYPTIONKEY = $_REQUEST['encryptionkey']; } echo "\n"; echo "
\n"; if (isset($ENCRYPTIONKEY) && isset($TEXT)) { if (strlen($ENCRYPTIONKEY) > 0) { // perform encryption echo "

Encryption with key:
\"".htmlentities($ENCRYPTIONKEY)."\"

\n"; $ENC = "echo \"".$TEXT."\" | /usr/bin/gpg -a --homedir ".$GPGDIR." --cipher-algo AES --yes --logger-file ".$ERRORFILE." --recipient \"".$ENCRYPTIONKEY."\" --always-trust -e "; $RESULT = unix($ENC); // check if encryption is successful $ERR = strpos($RESULT,'BEGIN PGP MESSAGE'); if (! $ERR === false){ if ($SHOWTEXTAREA == "yes"){ $RESULT = "\n\n"; } echo "
\n"; echo "

\n"; echo "    \n\n"; } else { echo "

Encryption failed.

"; echo "

\n

\n"; } } else { echo "

Encryption failed.

"; echo "

\n

\n"; } } else { // select a public key from the keyring if (! isset($ENCRYPTIONKEY)) { if ($KEYSELECTION == "yes") { echo "

Please choose one of the following public keys

\n"; $Keys = unix("/usr/bin/gpg --homedir $GPGDIR --list-keys"); $List = explode ("\n", $Keys); if (count($List) < 2 ) { die ("

No keys available. Aborting ...

"); } echo "
\n"; foreach ($List as $Line){ $KEYID = htmlentities(trim(substr($Line,4))); if ( substr_count($Line, "pub ") == 1){ echo ""; } if ( substr_count($Line, "uid ") == 1){ echo "\n"; } } echo "
".$KEYID."".$KEYID."

\n"; echo "

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
Key
\n
"; echo "    \n"; echo "
\n"; echo "
\n"; } else { echo "

No encryption key selected. Encryption impossible.

"; echo "

\n"; } } else { echo "

\n"; } } echo "
\n"; ?>