예제 #1
0
 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();
 }
예제 #2
0
 function invoke($funcname, &$args, $byRef = false)
 {
     $result = $this->_key_exchange();
     if (is_a($result, 'PHPRPC_Error')) {
         return $result;
     }
     $request = "phprpc_func={$funcname}";
     if (count($args) > 0) {
         $request .= "&phprpc_args=" . base64_encode($this->_encrypt(serialize_fix($args), 1));
     }
     $request .= "&phprpc_encrypt={$this->_encryptMode}";
     if (!$byRef) {
         $request .= "&phprpc_ref=false";
     }
     $request = str_replace('+', '%2B', $request);
     $result = $this->_post($request);
     if (is_a($result, 'PHPRPC_Error')) {
         return $result;
     }
     $phprpc_errno = 0;
     $phprpc_errstr = NULL;
     if (isset($result['phprpc_errno'])) {
         $phprpc_errno = intval($result['phprpc_errno']);
     }
     if (isset($result['phprpc_errstr'])) {
         $phprpc_errstr = base64_decode($result['phprpc_errstr']);
     }
     $this->_warning = new PHPRPC_Error($phprpc_errno, $phprpc_errstr);
     if (array_key_exists('phprpc_output', $result)) {
         $this->_output = base64_decode($result['phprpc_output']);
         if ($this->_server['version'] >= 3) {
             $this->_output = $this->_decrypt($this->_output, 3);
         }
     } else {
         $this->_output = '';
     }
     if (array_key_exists('phprpc_result', $result)) {
         if (array_key_exists('phprpc_args', $result)) {
             $arguments = unserialize($this->_decrypt(base64_decode($result['phprpc_args']), 1));
             for ($i = 0; $i < count($arguments); $i++) {
                 $args[$i] = $arguments[$i];
             }
         }
         $result = unserialize($this->_decrypt(base64_decode($result['phprpc_result']), 2));
     } else {
         $result = $this->_warning;
     }
     return $result;
 }
예제 #3
0
 function sendFunctions()
 {
     $this->buffer .= "phprpc_functions=\"" . $this->encodeString(serialize_fix(array_keys($this->functions))) . "\";\r\n";
     $this->sendCallback();
 }