Skip to content

Commit ce18931

Browse files
author
root
committed
improve crypto
1 parent 852fbfc commit ce18931

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

inc/oohforms.inc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,10 @@ class form {
513513
}
514514

515515
function encrypt($str) { #must match the decrypt function in tpl_form
516-
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
517-
$key = md5($GLOBALS["sess"]->id.$_ENV["DatabaseClass"],true);
518-
return $iv . mcrypt_encrypt ( MCRYPT_RIJNDAEL_128 , $key , $str , MCRYPT_MODE_CBC, $iv );
516+
global $sess;
517+
if (empty($sess->id)) $key=md5('somecrap'); else $key=$sess->id;
518+
$iv = hex2bin(md5($_ENV["DatabaseClass"]));
519+
return openssl_encrypt($str,"AES-256-CTR",hex2bin($key),OPENSSL_RAW_DATA,$iv);
519520
}
520521

521522
} /* end FORM */

inc/session.inc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,6 @@ class Session {
106106
if ( "" == $id ) {
107107
$newid=false;
108108
switch ($this->mode) {
109-
case "cookieonly":
110-
$id = isset($_COOKIE[$this->name]) ? $_COOKIE[$this->name] : "";
111109
case "cookie":
112110
case "get":
113111
$id = isset($_COOKIE[$this->name]) ?
@@ -128,9 +126,7 @@ class Session {
128126

129127
if ( "" == $id ) {
130128
$newid=true;
131-
do {
132-
$id = $this->that->ac_newid(bin2hex(openssl_random_pseudo_bytes(16)), $this->name); // Generate a new ID
133-
} while ($this->that->ac_get_value($id, $this->name)); // See if it exists already
129+
$id = $this->that->ac_newid(md5(uniqid($this->magic)), $this->name);
134130
}
135131

136132
switch ($this->mode) {
@@ -357,16 +353,20 @@ class Session {
357353
## Reload frozen variables from the database and microwave them.
358354

359355
function thaw() {
360-
$this->get_lock();
356+
$this->get_lock();
361357

362-
$vals = $this->that->ac_get_value($this->id, $this->name);
358+
$vals = $this->that->ac_get_value($this->id, $this->name);
359+
if ((isset($vals)) and (substr($vals,0,1)=="$")) {
360+
eval(sprintf(";%s",$vals)); // support old session data for php3
361+
} else {
363362
$arr = unserialize($vals); // new serialised data req. php => 4.07
364363
if (is_array($arr)) {
365364
foreach($arr as $k=>$v) {
366365
$this->pt[$k]=1;
367366
$GLOBALS[$k]=$v;
368367
}
369368
}
369+
}
370370
}
371371

372372
##

inc/tpl_form.inc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,11 +1134,10 @@ echo "<script type='text/javascript' src='/js/datefunc.js'>
11341134
}
11351135

11361136
function decrypt($str) { # must match encrypt function in oohforms
1137-
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
1138-
$iv = substr($str, 0, $iv_size);
1139-
$str = substr($str, $iv_size);
1140-
$key = md5($GLOBALS["sess"]->id.$_ENV["DatabaseClass"],true);
1141-
return mcrypt_decrypt ( MCRYPT_RIJNDAEL_128 , $key , $str , MCRYPT_MODE_CBC, $iv );
1137+
global $sess;
1138+
if (empty($sess->id)) $key=md5('somecrap'); else $key=$sess->id;
1139+
$iv = hex2bin(md5($_ENV["DatabaseClass"]));
1140+
return openssl_decrypt($str,"AES-256-CTR",hex2bin($key),OPENSSL_RAW_DATA,$iv);
11421141
}
11431142

11441143
}

0 commit comments

Comments
 (0)