本文整理汇总了PHP中Zend_OpenId::hashHmac方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_OpenId::hashHmac方法的具体用法?PHP Zend_OpenId::hashHmac怎么用?PHP Zend_OpenId::hashHmac使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_OpenId
的用法示例。
在下文中一共展示了Zend_OpenId::hashHmac方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _makeVerifyParameters
/**
* Подготовить набор параметров для verify
*
* @return array
*/
protected function _makeVerifyParameters(array $extraParams = array())
{
$_SERVER['SCRIPT_URI'] = 'http://localhost/index.php/auth/openid/verify';
$expiresIn = TIME + 600;
$this->storage->addDiscoveryInfo(self::ID, self::REAL_ID, self::SERVER, 1.1, $expiresIn);
$this->storage->addAssociation(self::SERVER, self::HANDLE, "sha1", $secret = pack("H*", "8382aea922560ece833ba55fa53b7a975f597370"), $expiresIn);
$params = array("openid_return_to" => $_SERVER['SCRIPT_URI'], "openid_assoc_handle" => self::HANDLE, "openid_claimed_id" => self::ID, "openid_identity" => self::REAL_ID, "openid_response_nonce" => "2007-08-14T12:52:33Z46c1a59124ffe", "openid_mode" => "id_res", "openid_signed" => "assoc_handle,return_to,claimed_id,identity,response_nonce,mode,signed");
$signed = array($params["openid_signed"]);
if ($extraParams) {
$params = array_merge($params, $extraParams);
// TODO: Фуууууу
$extraParams2 = explode(',', str_replace('_', '.', implode(',', array_keys($extraParams))));
$signed = array_merge($signed, $extraParams2);
}
$params["openid_signed"] = str_replace('openid.', '', implode(',', $signed));
// Подписать данные
$data = '';
foreach (explode(',', $params['openid_signed']) as $key) {
$data .= $key . ':' . $params['openid_' . strtr($key, '.', '_')] . "\n";
}
$params['openid_sig'] = base64_encode(\Zend_OpenId::hashHmac('sha1', $data, $secret));
return $params;
}
示例2: verify
//.........这里部分代码省略.........
$this->_setError("Duplicate openid.response_nonce");
return false;
}
}
}
if (!empty($params['openid_invalidate_handle'])) {
if ($this->_storage->getAssociationByHandle($params['openid_invalidate_handle'], $url, $macFunc, $secret, $expires)) {
$this->_storage->delAssociation($url);
}
}
if ($this->_storage->getAssociationByHandle($params['openid_assoc_handle'], $url, $macFunc, $secret, $expires)) {
// Security fix - check the association bewteen op_endpoint and assoc_handle
if (isset($params['openid_op_endpoint']) && $url !== $params['openid_op_endpoint']) {
$this->_setError("The op_endpoint URI is not the same of URI associated with the assoc_handle");
return false;
}
$signed = explode(',', $params['openid_signed']);
// Check the parameters for the signature
// @see https://openid.net/specs/openid-authentication-2_0.html#positive_assertions
$toCheck = $this->_signParams;
if (isset($params['openid_claimed_id']) && isset($params['openid_identity'])) {
$toCheck = array_merge($toCheck, array('claimed_id', 'identity'));
}
foreach ($toCheck as $param) {
if (!in_array($param, $signed, true)) {
$this->_setError("The required parameter {$param} is missing in the signed");
return false;
}
}
$data = '';
foreach ($signed as $key) {
$data .= $key . ':' . $params['openid_' . strtr($key, '.', '_')] . "\n";
}
if (base64_decode($params['openid_sig']) == Zend_OpenId::hashHmac($macFunc, $data, $secret)) {
if (!Zend_OpenId_Extension::forAll($extensions, 'parseResponse', $params)) {
$this->_setError("Extension::parseResponse failure");
return false;
}
/* OpenID 2.0 (11.2) Verifying Discovered Information */
if (isset($params['openid_claimed_id'])) {
$id = $params['openid_claimed_id'];
if (!Zend_OpenId::normalize($id)) {
$this->_setError("Normalization failed");
return false;
} else {
if (!$this->_discovery($id, $discovered_server, $discovered_version)) {
$this->_setError("Discovery failed: " . $this->getError());
return false;
} else {
if (!empty($params['openid_identity']) && $params["openid_identity"] != $id || !empty($params['openid_op_endpoint']) && $params['openid_op_endpoint'] != $discovered_server || $discovered_version != $version) {
$this->_setError("Discovery information verification failed");
return false;
}
}
}
}
return true;
}
$this->_storage->delAssociation($url);
$this->_setError("Signature check failed");
return false;
} else {
/* Use dumb mode */
if (isset($params['openid_claimed_id'])) {
$id = $params['openid_claimed_id'];
} else {
示例3: _checkAuthentication
/**
* Performs authentication validation for dumb consumers
* Returns array of variables to push back to consumer.
* It MUST contain 'is_valid' variable with value 'true' or 'false'.
*
* @param float $version OpenID version
* @param array $params GET or POST request variables
* @return array
*/
protected function _checkAuthentication($version, $params)
{
$ret = array();
if ($version >= 2.0) {
$ret['ns'] = Zend_OpenId::NS_2_0;
}
$ret['openid.mode'] = 'id_res';
if (empty($params['openid_assoc_handle']) || empty($params['openid_signed']) || empty($params['openid_sig']) || !$this->_storage->getAssociation($params['openid_assoc_handle'], $macFunc, $secret, $expires)) {
$ret['is_valid'] = 'false';
return $ret;
}
$signed = explode(',', $params['openid_signed']);
$data = '';
foreach ($signed as $key) {
$data .= $key . ':';
if ($key == 'mode') {
$data .= "id_res\n";
} else {
$data .= $params['openid_' . strtr($key, '.', '_')] . "\n";
}
}
if ($this->_secureStringCompare(base64_decode($params['openid_sig']), Zend_OpenId::hashHmac($macFunc, $data, $secret))) {
$ret['is_valid'] = 'true';
} else {
$ret['is_valid'] = 'false';
}
return $ret;
}
示例4: verify
/**
* Verifies authentication response from OpenID server.
*
* This is the second step of OpenID authentication process.
* The function returns true on successful authentication and false on
* failure.
*
* @param array $params HTTP query data from OpenID server
* @param string &$identity this argument is set to end-user's claimed
* identifier or OpenID provider local identifier.
* @param mixed $extensions extension object or array of extensions objects
* @return bool
*/
public function verify($params, &$identity = "", $extensions = null)
{
$version = 1.1;
if (isset($params['openid_ns']) && $params['openid_ns'] == Zend_OpenId::NS_2_0) {
$version = 2.0;
}
if (isset($params["openid_claimed_id"])) {
$identity = $params["openid_claimed_id"];
} else {
if (isset($params["openid_identity"])) {
$identity = $params["openid_identity"];
} else {
$identity = "";
}
}
if ($version < 2.0 && !isset($params["openid_claimed_id"])) {
if ($this->_session === null) {
require_once "Zend/Session/Namespace.php";
$this->_session = new Zend_Session_Namespace("zend_openid");
}
$session = $this->_session;
if ($session->identity == $identity) {
$identity = $session->claimed_id;
}
}
if (empty($params['openid_return_to']) || empty($params['openid_signed']) || empty($params['openid_sig']) || empty($params['openid_mode']) || empty($params['openid_assoc_handle']) || $params['openid_mode'] != 'id_res' || $params['openid_return_to'] != Zend_OpenId::selfUrl()) {
return false;
}
if ($version >= 2.0) {
if (empty($params['openid_response_nonce']) || empty($params['openid_op_endpoint'])) {
return false;
/* OpenID 2.0 (11.3) Checking the Nonce */
} else {
if (!$this->_storage->isUniqueNonce($params['openid_op_endpoint'], $params['openid_response_nonce'])) {
return false;
}
}
}
if (!empty($params['openid_invalidate_handle'])) {
if ($this->_storage->getAssociationByHandle($params['openid_invalidate_handle'], $url, $macFunc, $secret, $expires)) {
$this->_storage->delAssociation($url);
}
}
if ($this->_storage->getAssociationByHandle($params['openid_assoc_handle'], $url, $macFunc, $secret, $expires)) {
$signed = explode(',', $params['openid_signed']);
$data = '';
foreach ($signed as $key) {
$data .= $key . ':' . $params['openid_' . strtr($key, '.', '_')] . "\n";
}
if (base64_decode($params['openid_sig']) == Zend_OpenId::hashHmac($macFunc, $data, $secret)) {
if (!Zend_OpenId_Extension::forAll($extensions, 'parseResponse', $params)) {
return false;
}
/* OpenID 2.0 (11.2) Verifying Discovered Information */
if (isset($params['openid_claimed_id'])) {
$id = $params['openid_claimed_id'];
if (!Zend_OpenId::normalize($id) || !$this->_discovery($id, $discovered_server, $discovered_version) || isset($params['openid_identity']) && $params["openid_identity"] != $id || isset($params['openid_op_endpoint']) && $params['openid_op_endpoint'] != $discovered_server || $discovered_version != $version) {
return false;
}
}
return true;
}
$this->_storage->delAssociation($url);
return false;
} else {
/* Use dumb mode */
if (isset($params['openid_claimed_id'])) {
$id = $params['openid_claimed_id'];
} else {
if (isset($params['openid_identity'])) {
$id = $params['openid_identity'];
} else {
return false;
}
}
if (!$this->_discovery($id, $server, $discovered_version)) {
return false;
}
/* OpenID 2.0 (11.2) Verifying Discovered Information */
if (isset($params['openid_identity']) && $params["openid_identity"] != $id || isset($params['openid_op_endpoint']) && $params['openid_op_endpoint'] != $server || $discovered_version != $version) {
return false;
}
$params2 = array();
foreach ($params as $key => $val) {
if (strpos($key, 'openid_ns_') === 0) {
$key = 'openid.ns.' . substr($key, strlen('openid_ns_'));
} else {
//.........这里部分代码省略.........
示例5: testHashHmac
/**
* testing testHashHmac
*
*/
public function testHashHmac()
{
$key = 'password';
$this->assertSame(
'1f48abc79459fa853af681ddb3c73ff7f35c48fb',
bin2hex(Zend_OpenId::hashHmac('sha1', 'hello', $key)) );
$this->assertSame(
'7ae615e698567e5e1512dd8140e740bd4d65dfa4db195d80ca327de6302b4a63',
bin2hex(Zend_OpenId::hashHmac('sha256', 'hello', $key)) );
$key = str_repeat('x',128);
$this->assertSame(
'59c6c30dc9fb96b2cb2d7c41dbc6f96d1fbf67ac',
bin2hex(Zend_OpenId::hashHmac('sha1', 'hello', $key)) );
$this->assertSame(
'f5e0c31f7cdd272710052ac3ebcc40d7e82be2427b7e5e1e8373ef1e327515f4',
bin2hex(Zend_OpenId::hashHmac('sha256', 'hello', $key)) );
}