コード例 #1
0
ファイル: phprpc_client.php プロジェクト: edmundwong/V604
 function _key_exchange()
 {
     if (!is_null($this->_key) || $this->_encryptMode == 0) {
         return true;
     }
     $request = "phprpc_encrypt=true&phprpc_keylen={$this->_keylen}";
     $result = $this->_post($request);
     if (is_a($result, 'PHPRPC_Error')) {
         return $result;
     }
     if (array_key_exists('phprpc_keylen', $result)) {
         $this->_keylen = (int) $result['phprpc_keylen'];
     } else {
         $this->_keylen = 128;
     }
     if (array_key_exists('phprpc_encrypt', $result)) {
         $encrypt = unserialize(base64_decode($result['phprpc_encrypt']));
         require_once 'bigint.php';
         require_once 'xxtea.php';
         $x = bigint_random($this->_keylen - 1, true);
         $key = bigint_powmod(bigint_dec2num($encrypt['y']), $x, bigint_dec2num($encrypt['p']));
         if ($this->_keylen == 128) {
             $key = bigint_num2str($key);
         } else {
             $key = pack('H*', md5(bigint_num2dec($key)));
         }
         $this->_key = str_pad($key, 16, "", STR_PAD_LEFT);
         $encrypt = bigint_num2dec(bigint_powmod(bigint_dec2num($encrypt['g']), $x, bigint_dec2num($encrypt['p'])));
         $request = "phprpc_encrypt={$encrypt}";
         $result = $this->_post($request);
         if (is_a($result, 'PHPRPC_Error')) {
             return $result;
         }
     } else {
         $this->_key = NULL;
         $this->_encryptMode = 0;
     }
     return true;
 }
コード例 #2
0
ファイル: phprpc_server.php プロジェクト: GurgleSSH/Laundry
 function keyExchange()
 {
     require_once '../../ThirdParty/ThinkPHP/Extend/Vendor/phpRPC/bigint.php';
     $this->initKeylen();
     if (isset($_SESSION[$this->cid])) {
         $session = unserialize(base64_decode($_SESSION[$this->cid]));
     } else {
         $session = array();
     }
     if ($this->encrypt === true) {
         require_once '../../ThirdParty/ThinkPHP/Extend/Vendor/phpRPC/dhparams.php';
         $DHParams = new DHParams($this->keylen);
         $this->keylen = $DHParams->getL();
         $encrypt = $DHParams->getDHParams();
         $x = bigint_random($this->keylen - 1, true);
         $session['x'] = bigint_num2dec($x);
         $session['p'] = $encrypt['p'];
         $session['keylen'] = $this->keylen;
         $encrypt['y'] = bigint_num2dec(bigint_powmod(bigint_dec2num($encrypt['g']), $x, bigint_dec2num($encrypt['p'])));
         $this->buffer .= "phprpc_encrypt=\"" . $this->encodeString(serialize_fix($encrypt)) . "\";\r\n";
         if ($this->keylen != 128) {
             $this->buffer .= "phprpc_keylen=\"{$this->keylen}\";\r\n";
         }
         $this->sendURL();
     } else {
         $y = bigint_dec2num($this->encrypt);
         $x = bigint_dec2num($session['x']);
         $p = bigint_dec2num($session['p']);
         $key = bigint_powmod($y, $x, $p);
         if ($this->keylen == 128) {
             $key = bigint_num2str($key);
         } else {
             $key = pack('H*', md5(bigint_num2dec($key)));
         }
         $session['key'] = str_pad($key, 16, "", STR_PAD_LEFT);
     }
     $_SESSION[$this->cid] = base64_encode(serialize($session));
     $this->sendCallback();
 }