当前位置: 首页>>代码示例>>PHP>>正文


PHP Object::decrypt方法代码示例

本文整理汇总了PHP中Object::decrypt方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::decrypt方法的具体用法?PHP Object::decrypt怎么用?PHP Object::decrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Object的用法示例。


在下文中一共展示了Object::decrypt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

 /**
  * Gets Binary Packets
  *
  * See 'The Binary Packet Protocol' of protocol-1.5.txt for more info.
  *
  * Also, this function could be improved upon by adding detection for the following exploit:
  * http://www.securiteam.com/securitynews/5LP042K3FY.html
  *
  * @see Net_SSH1::_send_binary_packet()
  * @return Array
  * @access private
  */
 function _get_binary_packet()
 {
     if (feof($this->fsock)) {
         //user_error('connection closed prematurely');
         return false;
     }
     if ($this->curTimeout) {
         $read = array($this->fsock);
         $write = $except = null;
         $start = strtok(microtime(), ' ') + strtok('');
         // http://php.net/microtime#61838
         $sec = floor($this->curTimeout);
         $usec = 1000000 * ($this->curTimeout - $sec);
         // on windows this returns a "Warning: Invalid CRT parameters detected" error
         if (!@stream_select($read, $write, $except, $sec, $usec) && !count($read)) {
             //$this->_disconnect('Timeout');
             return true;
         }
         $elapsed = strtok(microtime(), ' ') + strtok('') - $start;
         $this->curTimeout -= $elapsed;
     }
     $start = strtok(microtime(), ' ') + strtok('');
     // http://php.net/microtime#61838
     $temp = unpack('Nlength', fread($this->fsock, 4));
     $padding_length = 8 - ($temp['length'] & 7);
     $length = $temp['length'] + $padding_length;
     $raw = '';
     while ($length > 0) {
         $temp = fread($this->fsock, $length);
         $raw .= $temp;
         $length -= strlen($temp);
     }
     $stop = strtok(microtime(), ' ') + strtok('');
     if (strlen($raw) && $this->crypto !== false) {
         $raw = $this->crypto->decrypt($raw);
     }
     $padding = substr($raw, 0, $padding_length);
     $type = $raw[$padding_length];
     $data = substr($raw, $padding_length + 1, -4);
     $temp = unpack('Ncrc', substr($raw, -4));
     //if ( $temp['crc'] != $this->_crc($padding . $type . $data) ) {
     //    user_error('Bad CRC in packet from server');
     //    return false;
     //}
     $type = ord($type);
     if (defined('NET_SSH1_LOGGING')) {
         $temp = isset($this->protocol_flags[$type]) ? $this->protocol_flags[$type] : 'UNKNOWN';
         $temp = '<- ' . $temp . ' (' . round($stop - $start, 4) . 's)';
         $this->_append_log($temp, $data);
     }
     return array(NET_SSH1_RESPONSE_TYPE => $type, NET_SSH1_RESPONSE_DATA => $data);
 }
开发者ID:carlosmirandadiaz,项目名称:LectoGeeks,代码行数:64,代码来源:SSH1.php

示例2: strtok

 /**
  * Gets Binary Packets
  *
  * See '6. Binary Packet Protocol' of rfc4253 for more info.
  *
  * @see Net_SSH2::_send_binary_packet()
  * @return String
  * @access private
  */
 function _get_binary_packet()
 {
     if (!is_resource($this->fsock) || feof($this->fsock)) {
         user_error('Connection closed prematurely');
         $this->bitmap = 0;
         return false;
     }
     $start = strtok(microtime(), ' ') + strtok('');
     // http://php.net/microtime#61838
     $raw = fread($this->fsock, $this->decrypt_block_size);
     if (!strlen($raw)) {
         return '';
     }
     if ($this->decrypt !== false) {
         $raw = $this->decrypt->decrypt($raw);
     }
     if ($raw === false) {
         user_error('Unable to decrypt content');
         return false;
     }
     extract(unpack('Npacket_length/Cpadding_length', $this->_string_shift($raw, 5)));
     $remaining_length = $packet_length + 4 - $this->decrypt_block_size;
     // quoting <http://tools.ietf.org/html/rfc4253#section-6.1>,
     // "implementations SHOULD check that the packet length is reasonable"
     // PuTTY uses 0x9000 as the actual max packet size and so to shall we
     if ($remaining_length < -$this->decrypt_block_size || $remaining_length > 0x9000 || $remaining_length % $this->decrypt_block_size != 0) {
         user_error('Invalid size');
         return false;
     }
     $buffer = '';
     while ($remaining_length > 0) {
         $temp = fread($this->fsock, $remaining_length);
         if ($temp === false || feof($this->fsock)) {
             user_error('Error reading from socket');
             $this->bitmap = 0;
             return false;
         }
         $buffer .= $temp;
         $remaining_length -= strlen($temp);
     }
     $stop = strtok(microtime(), ' ') + strtok('');
     if (strlen($buffer)) {
         $raw .= $this->decrypt !== false ? $this->decrypt->decrypt($buffer) : $buffer;
     }
     $payload = $this->_string_shift($raw, $packet_length - $padding_length - 1);
     $padding = $this->_string_shift($raw, $padding_length);
     // should leave $raw empty
     if ($this->hmac_check !== false) {
         $hmac = fread($this->fsock, $this->hmac_size);
         if ($hmac === false || strlen($hmac) != $this->hmac_size) {
             user_error('Error reading socket');
             $this->bitmap = 0;
             return false;
         } elseif ($hmac != $this->hmac_check->hash(pack('NNCa*', $this->get_seq_no, $packet_length, $padding_length, $payload . $padding))) {
             user_error('Invalid HMAC');
             return false;
         }
     }
     //if ($this->decompress) {
     //    $payload = gzinflate(substr($payload, 2));
     //}
     $this->get_seq_no++;
     if (defined('NET_SSH2_LOGGING')) {
         $current = strtok(microtime(), ' ') + strtok('');
         $message_number = isset($this->message_numbers[ord($payload[0])]) ? $this->message_numbers[ord($payload[0])] : 'UNKNOWN (' . ord($payload[0]) . ')';
         $message_number = '<- ' . $message_number . ' (since last: ' . round($current - $this->last_packet, 4) . ', network: ' . round($stop - $start, 4) . 's)';
         $this->_append_log($message_number, $payload);
         $this->last_packet = $current;
     }
     return $this->_filter($payload);
 }
开发者ID:pacificcasinohotel,项目名称:pointsystem,代码行数:80,代码来源:SSH2.php

示例3: array

 /**
  * Key Exchange
  *
  * @param String $kexinit_payload_server
  *
  * @access private
  */
 function _key_exchange($kexinit_payload_server)
 {
     static $kex_algorithms = array('diffie-hellman-group1-sha1', 'diffie-hellman-group14-sha1');
     static $server_host_key_algorithms = array('ssh-rsa', 'ssh-dss');
     static $encryption_algorithms = false;
     if ($encryption_algorithms === false) {
         $encryption_algorithms = array('arcfour256', 'arcfour128', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'twofish128-ctr', 'twofish192-ctr', 'twofish256-ctr', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc', 'twofish128-cbc', 'twofish192-cbc', 'twofish256-cbc', 'twofish-cbc', 'blowfish-ctr', 'blowfish-cbc', '3des-ctr', '3des-cbc');
         if (phpseclib_resolve_include_path('Crypt/RC4.php') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('arcfour256', 'arcfour128', 'arcfour'));
         }
         if (phpseclib_resolve_include_path('Crypt/Rijndael.php') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc'));
         }
         if (phpseclib_resolve_include_path('Crypt/Twofish.php') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('twofish128-ctr', 'twofish192-ctr', 'twofish256-ctr', 'twofish128-cbc', 'twofish192-cbc', 'twofish256-cbc', 'twofish-cbc'));
         }
         if (phpseclib_resolve_include_path('Crypt/Blowfish.php') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('blowfish-ctr', 'blowfish-cbc'));
         }
         if (phpseclib_resolve_include_path('Crypt/TripleDES.php') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('3des-ctr', '3des-cbc'));
         }
         $encryption_algorithms = array_values($encryption_algorithms);
     }
     $mac_algorithms = array('hmac-sha2-256', 'hmac-sha1-96', 'hmac-sha1', 'hmac-md5-96', 'hmac-md5');
     static $compression_algorithms = array('none');
     // some SSH servers have buggy implementations of some of the above algorithms
     switch ($this->server_identifier) {
         case 'SSH-2.0-SSHD':
             $mac_algorithms = array_values(array_diff($mac_algorithms, array('hmac-sha1-96', 'hmac-md5-96')));
     }
     static $str_kex_algorithms, $str_server_host_key_algorithms, $encryption_algorithms_server_to_client, $mac_algorithms_server_to_client, $compression_algorithms_server_to_client, $encryption_algorithms_client_to_server, $mac_algorithms_client_to_server, $compression_algorithms_client_to_server;
     if (empty($str_kex_algorithms)) {
         $str_kex_algorithms = implode(',', $kex_algorithms);
         $str_server_host_key_algorithms = implode(',', $server_host_key_algorithms);
         $encryption_algorithms_server_to_client = $encryption_algorithms_client_to_server = implode(',', $encryption_algorithms);
         $mac_algorithms_server_to_client = $mac_algorithms_client_to_server = implode(',', $mac_algorithms);
         $compression_algorithms_server_to_client = $compression_algorithms_client_to_server = implode(',', $compression_algorithms);
     }
     $client_cookie = crypt_random_string(16);
     $response = $kexinit_payload_server;
     $this->_string_shift($response, 1);
     // skip past the message number (it should be SSH_MSG_KEXINIT)
     $server_cookie = $this->_string_shift($response, 16);
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->kex_algorithms = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->server_host_key_algorithms = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->encryption_algorithms_client_to_server = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->encryption_algorithms_server_to_client = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->mac_algorithms_client_to_server = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->mac_algorithms_server_to_client = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->compression_algorithms_client_to_server = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->compression_algorithms_server_to_client = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->languages_client_to_server = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->languages_server_to_client = explode(',', $this->_string_shift($response, $temp['length']));
     extract(unpack('Cfirst_kex_packet_follows', $this->_string_shift($response, 1)));
     $first_kex_packet_follows = $first_kex_packet_follows != 0;
     // the sending of SSH2_MSG_KEXINIT could go in one of two places.  this is the second place.
     $kexinit_payload_client = pack('Ca*Na*Na*Na*Na*Na*Na*Na*Na*Na*Na*CN', NET_SSH2_MSG_KEXINIT, $client_cookie, strlen($str_kex_algorithms), $str_kex_algorithms, strlen($str_server_host_key_algorithms), $str_server_host_key_algorithms, strlen($encryption_algorithms_client_to_server), $encryption_algorithms_client_to_server, strlen($encryption_algorithms_server_to_client), $encryption_algorithms_server_to_client, strlen($mac_algorithms_client_to_server), $mac_algorithms_client_to_server, strlen($mac_algorithms_server_to_client), $mac_algorithms_server_to_client, strlen($compression_algorithms_client_to_server), $compression_algorithms_client_to_server, strlen($compression_algorithms_server_to_client), $compression_algorithms_server_to_client, 0, '', 0, '', 0, 0);
     if (!$this->_send_binary_packet($kexinit_payload_client)) {
         return false;
     }
     // here ends the second place.
     // we need to decide upon the symmetric encryption algorithms before we do the diffie-hellman key exchange
     for ($i = 0; $i < count($encryption_algorithms) && !in_array($encryption_algorithms[$i], $this->encryption_algorithms_server_to_client); $i++) {
     }
     if ($i == count($encryption_algorithms)) {
         user_error('No compatible server to client encryption algorithms found');
         return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
     }
     // we don't initialize any crypto-objects, yet - we do that, later. for now, we need the lengths to make the
     // diffie-hellman key exchange as fast as possible
     $decrypt = $encryption_algorithms[$i];
     switch ($decrypt) {
         case '3des-cbc':
         case '3des-ctr':
             $decryptKeyLength = 24;
             // eg. 192 / 8
             break;
         case 'aes256-cbc':
         case 'aes256-ctr':
         case 'twofish-cbc':
         case 'twofish256-cbc':
         case 'twofish256-ctr':
//.........这里部分代码省略.........
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:101,代码来源:SSH2.php

示例4: strtok

 /**
  * Gets Binary Packets
  *
  * See '6. Binary Packet Protocol' of rfc4253 for more info.
  *
  * @see Net_SSH2::_send_binary_packet()
  * @return String
  * @access private
  */
 function _get_binary_packet()
 {
     if (feof($this->fsock)) {
         user_error('Connection closed prematurely', E_USER_NOTICE);
         return false;
     }
     $start = strtok(microtime(), ' ') + strtok('');
     // http://php.net/microtime#61838
     $raw = fread($this->fsock, $this->decrypt_block_size);
     $stop = strtok(microtime(), ' ') + strtok('');
     if (empty($raw)) {
         return '';
     }
     if ($this->decrypt !== false) {
         $raw = $this->decrypt->decrypt($raw);
     }
     extract(unpack('Npacket_length/Cpadding_length', $this->_string_shift($raw, 5)));
     $remaining_length = $packet_length + 4 - $this->decrypt_block_size;
     $buffer = '';
     while ($remaining_length > 0) {
         $temp = fread($this->fsock, $remaining_length);
         $buffer .= $temp;
         $remaining_length -= strlen($temp);
     }
     if (!empty($buffer)) {
         $raw .= $this->decrypt !== false ? $this->decrypt->decrypt($buffer) : $buffer;
         $buffer = $temp = '';
     }
     $payload = $this->_string_shift($raw, $packet_length - $padding_length - 1);
     $padding = $this->_string_shift($raw, $padding_length);
     // should leave $raw empty
     if ($this->hmac_check !== false) {
         $hmac = fread($this->fsock, $this->hmac_size);
         if ($hmac != $this->hmac_check->hash(pack('NNCa*', $this->get_seq_no, $packet_length, $padding_length, $payload . $padding))) {
             user_error('Invalid HMAC', E_USER_NOTICE);
             return false;
         }
     }
     //if ($this->decompress) {
     //    $payload = gzinflate(substr($payload, 2));
     //}
     $this->get_seq_no++;
     if (defined('NET_SSH2_LOGGING')) {
         $temp = isset($this->message_numbers[ord($payload[0])]) ? $this->message_numbers[ord($payload[0])] : 'UNKNOWN (' . ord($payload[0]) . ')';
         $this->message_number_log[] = '<- ' . $temp . ' (' . round($stop - $start, 4) . 's)';
         if (NET_SSH2_LOGGING == NET_SSH2_LOG_COMPLEX) {
             $this->message_log[] = substr($payload, 1);
         }
     }
     return $this->_filter($payload);
 }
开发者ID:grimsmath,项目名称:lavillafdn,代码行数:60,代码来源:SSH2.php

示例5: unpack

 /**
  * Gets Binary Packets
  *
  * See 'The Binary Packet Protocol' of protocol-1.5.txt for more info.
  *
  * Also, this function could be improved upon by adding detection for the following exploit:
  * http://www.securiteam.com/securitynews/5LP042K3FY.html
  *
  * @see Net_SSH1::_send_binary_packet()
  * @return Array
  * @access private
  */
 function _get_binary_packet()
 {
     if (feof($this->fsock)) {
         //user_error('connection closed prematurely', E_USER_NOTICE);
         return false;
     }
     $temp = unpack('Nlength', fread($this->fsock, 4));
     $padding_length = 8 - ($temp['length'] & 7);
     $length = $temp['length'] + $padding_length;
     $raw = fread($this->fsock, $length);
     if ($this->crypto !== false) {
         $raw = $this->crypto->decrypt($raw);
     }
     $padding = substr($raw, 0, $padding_length);
     $type = $raw[$padding_length];
     $data = substr($raw, $padding_length + 1, -4);
     $temp = unpack('Ncrc', substr($raw, -4));
     //if ( $temp['crc'] != $this->_crc($padding . $type . $data) ) {
     //    user_error('Bad CRC in packet from server', E_USER_NOTICE);
     //    return false;
     //}
     return array(NET_SSH1_RESPONSE_TYPE => ord($type), NET_SSH1_RESPONSE_DATA => $data);
 }
开发者ID:lahirwisada,项目名称:orangehrm,代码行数:35,代码来源:SSH1.php

示例6: unpack

 /**
  * Gets Binary Packets
  *
  * See 'The Binary Packet Protocol' of protocol-1.5.txt for more info.
  *
  * Also, this function could be improved upon by adding detection for the following exploit:
  * http://www.securiteam.com/securitynews/5LP042K3FY.html
  *
  * @see Net_SSH1::_send_binary_packet()
  * @return Array
  * @access private
  */
 function _get_binary_packet()
 {
     if (feof($this->fsock)) {
         //user_error('connection closed prematurely', E_USER_NOTICE);
         return false;
     }
     $temp = unpack('Nlength', fread($this->fsock, 4));
     $padding_length = 8 - ($temp['length'] & 7);
     $length = $temp['length'] + $padding_length;
     $start = strtok(microtime(), ' ') + strtok('');
     // http://php.net/microtime#61838
     $raw = fread($this->fsock, $length);
     $stop = strtok(microtime(), ' ') + strtok('');
     if ($this->crypto !== false) {
         $raw = $this->crypto->decrypt($raw);
     }
     $padding = substr($raw, 0, $padding_length);
     $type = $raw[$padding_length];
     $data = substr($raw, $padding_length + 1, -4);
     $temp = unpack('Ncrc', substr($raw, -4));
     //if ( $temp['crc'] != $this->_crc($padding . $type . $data) ) {
     //    user_error('Bad CRC in packet from server', E_USER_NOTICE);
     //    return false;
     //}
     $type = ord($type);
     if (defined('NET_SSH1_LOGGING')) {
         $temp = isset($this->protocol_flags[$type]) ? $this->protocol_flags[$type] : 'UNKNOWN';
         $this->protocol_flags_log[] = '<- ' . $temp . ' (' . round($stop - $start, 4) . 's)';
         if (NET_SSH1_LOGGING == NET_SSH1_LOG_COMPLEX) {
             $this->message_log[] = $data;
         }
     }
     return array(NET_SSH1_RESPONSE_TYPE => $type, NET_SSH1_RESPONSE_DATA => $data);
 }
开发者ID:macconsultinggroup,项目名称:WordPress,代码行数:46,代码来源:SSH1.php

示例7: strtok

 /**
  * Gets Binary Packets
  *
  * See '6. Binary Packet Protocol' of rfc4253 for more info.
  *
  * @see Net_SSH2::_send_binary_packet()
  * @return String
  * @access private
  */
 function _get_binary_packet()
 {
     if (!is_resource($this->fsock) || feof($this->fsock)) {
         user_error('Connection closed prematurely');
         $this->bitmask = 0;
         return false;
     }
     $start = strtok(microtime(), ' ') + strtok('');
     // http://php.net/microtime#61838
     $raw = fread($this->fsock, $this->decrypt_block_size);
     $stop = strtok(microtime(), ' ') + strtok('');
     if (empty($raw)) {
         return '';
     }
     if ($this->decrypt !== false) {
         $raw = $this->decrypt->decrypt($raw);
     }
     if ($raw === false) {
         user_error('Unable to decrypt content');
         return false;
     }
     extract(unpack('Npacket_length/Cpadding_length', $this->_string_shift($raw, 5)));
     $remaining_length = $packet_length + 4 - $this->decrypt_block_size;
     $buffer = '';
     while ($remaining_length > 0) {
         $temp = fread($this->fsock, $remaining_length);
         $buffer .= $temp;
         $remaining_length -= strlen($temp);
     }
     if (!empty($buffer)) {
         $raw .= $this->decrypt !== false ? $this->decrypt->decrypt($buffer) : $buffer;
         $buffer = $temp = '';
     }
     $payload = $this->_string_shift($raw, $packet_length - $padding_length - 1);
     $padding = $this->_string_shift($raw, $padding_length);
     // should leave $raw empty
     if ($this->hmac_check !== false) {
         $hmac = fread($this->fsock, $this->hmac_size);
         if ($hmac != $this->hmac_check->hash(pack('NNCa*', $this->get_seq_no, $packet_length, $padding_length, $payload . $padding))) {
             user_error('Invalid HMAC');
             return false;
         }
     }
     //if ($this->decompress) {
     //    $payload = gzinflate(substr($payload, 2));
     //}
     $this->get_seq_no++;
     if (defined('NET_SSH2_LOGGING')) {
         $current = strtok(microtime(), ' ') + strtok('');
         $message_number = isset($this->message_numbers[ord($payload[0])]) ? $this->message_numbers[ord($payload[0])] : 'UNKNOWN (' . ord($payload[0]) . ')';
         $message_number = '<- ' . $message_number . ' (since last: ' . round($current - $this->last_packet, 4) . ', network: ' . round($stop - $start, 4) . 's)';
         $this->_append_log($message_number, $payload);
         $this->last_packet = $current;
     }
     return $this->_filter($payload);
 }
开发者ID:HeliWang,项目名称:EngSoc-Website,代码行数:65,代码来源:SSH2.php

示例8: fread

 /**
  * Gets Binary Packets
  *
  * See '6. Binary Packet Protocol' of rfc4253 for more info.
  *
  * @see Net_SSH2::_send_binary_packet()
  * @return String
  * @access private
  */
 function _get_binary_packet()
 {
     if (feof($this->fsock)) {
         user_error('Connection closed prematurely', E_USER_NOTICE);
         return false;
     }
     $raw = fread($this->fsock, $this->decrypt_block_size);
     if ($this->decrypt !== false) {
         $raw = $this->decrypt->decrypt($raw);
     }
     $temp = unpack('Npacket_length/Cpadding_length', $this->_string_shift($raw, 5));
     $packet_length = $temp['packet_length'];
     $padding_length = $temp['padding_length'];
     $remaining_length = $packet_length + 4 - $this->decrypt_block_size;
     $buffer = '';
     while ($remaining_length > 0) {
         $temp = fread($this->fsock, $remaining_length);
         $buffer .= $temp;
         $remaining_length -= strlen($temp);
     }
     if (!empty($buffer)) {
         $raw .= $this->decrypt !== false ? $this->decrypt->decrypt($buffer) : $buffer;
         $buffer = $temp = '';
     }
     $payload = $this->_string_shift($raw, $packet_length - $padding_length - 1);
     $padding = $this->_string_shift($raw, $padding_length);
     // should leave $raw empty
     if ($this->hmac_check !== false) {
         $hmac = fread($this->fsock, $this->hmac_size);
         if ($hmac != $this->hmac_check->hash(pack('NNCa*', $this->get_seq_no, $packet_length, $padding_length, $payload . $padding))) {
             user_error('Invalid HMAC', E_USER_NOTICE);
             return false;
         }
     }
     //if ($this->decompress) {
     //    $payload = gzinflate(substr($payload, 2));
     //}
     $this->get_seq_no++;
     if (defined('NET_SSH2_LOGGING')) {
         $this->message_number_log[] = '<- ' . $this->message_numbers[ord($payload[0])];
         $this->message_log[] = $payload;
     }
     return $this->_filter($payload);
 }
开发者ID:qickrooms,项目名称:flextermshell,代码行数:53,代码来源:SSH2.php

示例9: array

 /**
  * Key Exchange
  *
  * @param String $kexinit_payload_server
  *
  * @access private
  */
 function _key_exchange($kexinit_payload_server)
 {
     static $kex_algorithms = array('curve25519-sha256@libssh.org', 'diffie-hellman-group1-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group-exchange-sha256');
     if (!class_exists('\\Sodium')) {
         $kex_algorithms = array_diff($kex_algorithms, array('curve25519-sha256@libssh.org'));
     }
     static $server_host_key_algorithms = array('ssh-rsa', 'ssh-dss');
     static $encryption_algorithms = false;
     if ($encryption_algorithms === false) {
         $encryption_algorithms = array('arcfour256', 'arcfour128', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'twofish128-ctr', 'twofish192-ctr', 'twofish256-ctr', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc', 'twofish128-cbc', 'twofish192-cbc', 'twofish256-cbc', 'twofish-cbc', 'blowfish-ctr', 'blowfish-cbc', '3des-ctr', '3des-cbc');
         if (extension_loaded('openssl') && !extension_loaded('mcrypt')) {
             // OpenSSL does not support arcfour256 in any capacity and arcfour128 / arcfour support is limited to
             // instances that do not use continuous buffers
             $encryption_algorithms = array_diff($encryption_algorithms, array('arcfour256', 'arcfour128', 'arcfour'));
         }
         if (class_exists('\\phpseclib\\Crypt\\RC4') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('arcfour256', 'arcfour128', 'arcfour'));
         }
         if (class_exists('\\phpseclib\\Crypt\\Rijndael') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-cbc', 'aes192-cbc', 'aes256-cbc'));
         }
         if (class_exists('\\phpseclib\\Crypt\\Twofish') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('twofish128-ctr', 'twofish192-ctr', 'twofish256-ctr', 'twofish128-cbc', 'twofish192-cbc', 'twofish256-cbc', 'twofish-cbc'));
         }
         if (class_exists('\\phpseclib\\Crypt\\Blowfish') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('blowfish-ctr', 'blowfish-cbc'));
         }
         if (class_exists('\\phpseclib\\Crypt\\TripleDES') === false) {
             $encryption_algorithms = array_diff($encryption_algorithms, array('3des-ctr', '3des-cbc'));
         }
         $encryption_algorithms = array_values($encryption_algorithms);
     }
     $mac_algorithms = array('hmac-sha2-256', 'hmac-sha1-96', 'hmac-sha1', 'hmac-md5-96', 'hmac-md5');
     static $compression_algorithms = array('none');
     // some SSH servers have buggy implementations of some of the above algorithms
     switch ($this->server_identifier) {
         case 'SSH-2.0-SSHD':
             $mac_algorithms = array_values(array_diff($mac_algorithms, array('hmac-sha1-96', 'hmac-md5-96')));
     }
     static $str_kex_algorithms, $str_server_host_key_algorithms, $encryption_algorithms_server_to_client, $mac_algorithms_server_to_client, $compression_algorithms_server_to_client, $encryption_algorithms_client_to_server, $mac_algorithms_client_to_server, $compression_algorithms_client_to_server;
     if (empty($str_kex_algorithms)) {
         $str_kex_algorithms = implode(',', $kex_algorithms);
         $str_server_host_key_algorithms = implode(',', $server_host_key_algorithms);
         $encryption_algorithms_server_to_client = $encryption_algorithms_client_to_server = implode(',', $encryption_algorithms);
         $mac_algorithms_server_to_client = $mac_algorithms_client_to_server = implode(',', $mac_algorithms);
         $compression_algorithms_server_to_client = $compression_algorithms_client_to_server = implode(',', $compression_algorithms);
     }
     $client_cookie = Random::string(16);
     $response = $kexinit_payload_server;
     $this->_string_shift($response, 1);
     // skip past the message number (it should be SSH_MSG_KEXINIT)
     $server_cookie = $this->_string_shift($response, 16);
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->kex_algorithms = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->server_host_key_algorithms = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->encryption_algorithms_client_to_server = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->encryption_algorithms_server_to_client = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->mac_algorithms_client_to_server = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->mac_algorithms_server_to_client = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->compression_algorithms_client_to_server = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->compression_algorithms_server_to_client = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->languages_client_to_server = explode(',', $this->_string_shift($response, $temp['length']));
     $temp = unpack('Nlength', $this->_string_shift($response, 4));
     $this->languages_server_to_client = explode(',', $this->_string_shift($response, $temp['length']));
     extract(unpack('Cfirst_kex_packet_follows', $this->_string_shift($response, 1)));
     $first_kex_packet_follows = $first_kex_packet_follows != 0;
     // the sending of SSH2_MSG_KEXINIT could go in one of two places.  this is the second place.
     $kexinit_payload_client = pack('Ca*Na*Na*Na*Na*Na*Na*Na*Na*Na*Na*CN', NET_SSH2_MSG_KEXINIT, $client_cookie, strlen($str_kex_algorithms), $str_kex_algorithms, strlen($str_server_host_key_algorithms), $str_server_host_key_algorithms, strlen($encryption_algorithms_client_to_server), $encryption_algorithms_client_to_server, strlen($encryption_algorithms_server_to_client), $encryption_algorithms_server_to_client, strlen($mac_algorithms_client_to_server), $mac_algorithms_client_to_server, strlen($mac_algorithms_server_to_client), $mac_algorithms_server_to_client, strlen($compression_algorithms_client_to_server), $compression_algorithms_client_to_server, strlen($compression_algorithms_server_to_client), $compression_algorithms_server_to_client, 0, '', 0, '', 0, 0);
     if (!$this->_send_binary_packet($kexinit_payload_client)) {
         return false;
     }
     // here ends the second place.
     // we need to decide upon the symmetric encryption algorithms before we do the diffie-hellman key exchange
     // we don't initialize any crypto-objects, yet - we do that, later. for now, we need the lengths to make the
     // diffie-hellman key exchange as fast as possible
     $decrypt = $this->_array_intersect_first($encryption_algorithms, $this->encryption_algorithms_server_to_client);
     $decryptKeyLength = $this->_encryption_algorithm_to_key_size($decrypt);
     if ($decryptKeyLength === null) {
         user_error('No compatible server to client encryption algorithms found');
         return $this->_disconnect(NET_SSH2_DISCONNECT_KEY_EXCHANGE_FAILED);
     }
     $encrypt = $this->_array_intersect_first($encryption_algorithms, $this->encryption_algorithms_client_to_server);
     $encryptKeyLength = $this->_encryption_algorithm_to_key_size($encrypt);
     if ($encryptKeyLength === null) {
         user_error('No compatible client to server encryption algorithms found');
//.........这里部分代码省略.........
开发者ID:BozzaCoon,项目名称:SPHERE-Framework,代码行数:101,代码来源:SSH2.php


注:本文中的Object::decrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。