/usr/share/IlohaMail/include/encryption.inc is in ilohamail 0.8.14-0rc3sid6.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | <?php
/////////////////////////////////////////////////////////
//
// include/encryption.inc
//
// (C)Copyright 2000-2002 Ryo Chijiiwa <Ryo@IlohaMail.org>
//
// This file is part of IlohaMail. IlohaMail is free software released
// under the GPL license. See enclosed file COPYING for details, or
// see http://www.fsf.org/copyleft/gpl.html
//
/////////////////////////////////////////////////////////
/********************************************************
PURPOSE:
Provide basic encryption related functionality.
COMMENTS:
This library commits the worst crime in cryptography:
Never write your own crypto algos.
********************************************************/
function GenerateRandomString($messLen, $seed){
srand ((double) microtime() * 1000000);
if (empty($seed)) $seed="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$seedLen=strlen($seed);
if ($messLen==0) $messLen = rand(10, 20);
for ($i=0;$i<$messLen;$i++){
$point=rand(0, $seedLen-1);
$message.=$seed[$point];
}
return $message;
}
function GenerateMessage($messLen){
$seed="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
return GenerateRandomString($messLen, $seed);
}
function EncryptMessage($key,$message){
$messLen=strlen($message);
$keylen=strlen($key);
$enc_message="";
for ($i=0;$i<$messLen;$i++){
$j=$i % $keylen;
$code=chr((ord($message[$i]) + ord($key[$j])) % 128);
$enc_message.=$code;
}
return base64_encode($enc_message);
}
function DecodeMessage($pass, $message){
$message=base64_decode($message);
$messLen=strlen($message);
$passLen=strlen($pass);
$decMessage="";
for ($i=0;$i<$messLen;$i++){
$j=$i % $passLen;
$num=ord($message[$i]);
$decNum=(($num + 128) - ord($pass[$j])) % 128;
$decMessage.=chr($decNum);
}
return $decMessage;
}
function GenerateKeyFromIP(){
$ip = $_SERVER["REMOTE_ADDR"];
$ipkey="";
$ip_a = explode(".", $ip);
for ($i=3; $i>=0; $i--) $ipkey.=$ip_a[$i];
return $ipkey;
}
function GetSessionEncKey($sid){
global $MAX_SESSION_TIME, $STAY_LOGGED_IN;
$cookie_name = "IMAIL_SESS_KEY_".$sid;
if (empty($_COOKIE[$cookie_name])){
// No cookies, turn IP into encryption key
$ipkey = GenerateKeyFromIP();
}else{
// use cookie
$ipkey = $_COOKIE[$cookie_name];
if ($STAY_LOGGED_IN){
setcookie ($cookie_name, $ipkey, time()+$MAX_SESSION_TIME, "/", $_SERVER[SERVER_NAME]);
}
}
return $ipkey;
}
function InitSessionEncKey($sid){
global $MAX_SESSION_TIME;
if (empty($_COOKIE['IMAIL_TEST_COOKIE'])){
//cookies disabled
$key = GenerateKeyFromIP();
}else{
//cookies enabled
$cookie_name = "IMAIL_SESS_KEY_".$sid;
$key = GenerateRandomString(16, "");
$_COOKIE[$cookie_name] = $key;
setcookie ($cookie_name, $key, time()+$MAX_SESSION_TIME, "/", $_SERVER[SERVER_NAME]);
}
return $key;
}
?>
|