2
/////////////////////////////////////////////////////////
6
// (C)Copyright 2003 Ryo Chijiiwa <Ryo@IlohaMail.org>
8
// This file is part of IlohaMail, and released under GPL.
9
// See COPYING, or http://www.fsf.org/copyleft/gpl.html
11
/////////////////////////////////////////////////////////
12
/********************************************************
13
PURPOSE: GPG interface
14
COMMENTS: Based on code contributed by Paul A. Martin
16
********************************************************/
18
function gpg_list_keys(){
19
global $GPG_HOME_STR, $GPG_PATH;
20
global $loginID, $host;
22
$gpg_home = str_replace("%h", $host, str_replace("%u", $loginID, $GPG_HOME_STR));
23
$gpgkeys=`"$GPG_PATH" --home="$gpg_home" --list-public-keys`;
24
preg_match_all("/pub\s+[\w\/]+\s+[\w-]+\s+([\w ]+).*<([\w@.]+)>/", $gpgkeys, $works);
27
for($i=0; $works[1][$i] != ""; $i++){
29
$str = $works[1][$i]." <".$works[2][$i].">";
36
function gpg_export($person){
37
global $loginID, $host;
38
global $GPG_HOME_STR, $GPG_PATH;
40
$person = escapeshellcmd(stripslashes($person));
41
$gpg_home = str_replace("%h", $host, str_replace("%u", $loginID, $GPG_HOME_STR));
42
$command = $GPG_PATH." --home=".$gpg_home." --export -a \"$person\"";
43
$temp = exec($command, $result, $errorno);
44
return implode("\n", $result);
47
function gpg_encrypt($loginID, $host, $gpgrecp, &$gpgmessage){
48
global $GPG_HOME_STR, $GPG_PATH;
50
$original_message = $gpgmessage;
52
if($gpgrecp!="noencode")
54
//disable command injection
55
$gpgmessage = str_replace("`", "\\`", $gpgmessage);
57
//format home directory path
58
$gpg_home = str_replace("%h", $host, str_replace("%u", $loginID, $GPG_HOME_STR));
59
$gpg_home = realpath($gpg_home);
62
$tempcom = 'echo "'.$gpgmessage.'" | '.$GPG_PATH.' --home='.$gpg_home.' -a --always-trust --batch -e -r "'.$gpgrecp.'"';
63
echo $tempcom."<br>\n";
64
$oldhome = getEnv("HOME");
65
$msg = exec($tempcom, $encrypted, $errorcode);
66
echo "msg: $msg <br>\n";
67
echo "errorcode: $errorcode <br>\n";
68
$gpgmessage = implode("\n", $encrypted);
69
echo "New message: <pre>$gpgmessage</pre> <br>\n";
70
$gpg_encrypted = true;
72
$gpgmessage = $original_message;
81
function gpg_decrypt($gpg_passphrase, &$body){
82
global $GPG_HOME_STR, $GPG_PATH;
83
global $loginID, $host, $user;
85
//$oldhome = getEnv("HOME");
86
//$blah = nl2br($body);
88
$gpg_home = str_replace("%h", $host, str_replace("%u", $loginID, $GPG_HOME_STR));
89
$temp_file = $gpg_home."/$user-gpg.tmp";
90
$fp = fopen($temp_file,'w');
91
//$fp = fopen("/home/$loginID/.gnupg/blah",'w');
93
fwrite($fp, $body, strlen($body));
96
$temp = 'echo "'.escapeshellcmd($gpg_passphrase).'" | '.$GPG_PATH.' --home='.$gpg_home.' -v --batch --passphrase-fd 0 --decrypt '.escapeshellcmd($temp_file);
97
$blah = exec($temp, $body, $errorcode);
100
$body = implode("\n", $body);
101
$body = stripslashes($body);
103
$body = "gpg_decrypt: Decryption failed... (errorno: $errorcode)\n\n".$original;
106
//unlink("/home/$loginID/.gnupg/$fp");
108
$body = "gpg_decrypt: Couldn't open temp file: $temp_file\n\n".$original;
b'\\ No newline at end of file'