设备\密码\验证器-AWS Cognito-PHP SDK

设备\密码\验证器-AWS Cognito-PHP SDK,php,amazon-web-services,amazon-cognito,aws-php-sdk,Php,Amazon Web Services,Amazon Cognito,Aws Php Sdk,我已经试着让它工作了一段时间了。我可以使用一些代码作为参考,但不幸的是,我仍然面临一些问题,现在还不清楚为什么会发生这种情况 在我开始讨论这个问题之前,我想指出我前面提到的参考文献。以下是帮助我的关键链接: (极好的起点) 这是一篇我用来提供帮助的博客文章,与上面提供的链接保持一致: 让我参考那篇文章,以便更好地解释我的问题 所以,我能够通过所有的步骤,除了最后一个不断失败的步骤。让我们假设一些基本变量: $device_group_key = "-hdk698"; $

我已经试着让它工作了一段时间了。我可以使用一些代码作为参考,但不幸的是,我仍然面临一些问题,现在还不清楚为什么会发生这种情况

在我开始讨论这个问题之前,我想指出我前面提到的参考文献。以下是帮助我的关键链接:

  • (极好的起点)
  • 这是一篇我用来提供帮助的博客文章,与上面提供的链接保持一致:

    让我参考那篇文章,以便更好地解释我的问题

    所以,我能够通过所有的步骤,除了最后一个不断失败的步骤。让我们假设一些基本变量:

    $device_group_key = "-hdk698";
    $device_key = "us-east-1-dsdsdsds-sdsds-sdsd";
    $username = $poolId.$userId;
    
    我首先需要获取
    设备[“PasswordVerifier”]
    。为此,我将调用此函数:

    $device = $this->getDeviceSecretVerifierConfig($device_group_key, $username);
    
    // reference to the function
    public function getDeviceSecretVerifierConfig(string $deviceGroupKey, string $username): array
    {
      $salt = $this->bytes(16);
      $randomPassword = $this->bytes(40);
      $fullPassword = $this->hash(sprintf('%s%s:%s', $deviceGroupKey, $username, $randomPassword));
    
      $passwordVerifier = $this->g->modPow(
        new BigInteger($this->hexHash($salt->toHex() . $fullPassword), 16),
        $this->N
      );
    
      return [
        'Salt' => base64_encode($salt->toString()),
        'PasswordVerifier' => base64_encode($passwordVerifier->toString())
      ];
    }
    
    现在,我需要获取
    设备密码身份验证密钥

    $hkdf = $this->getDevicePasswordAuthenticationKey(
      $username, 
      $device["PasswordVerifier"], 
      $device_group_key, 
      $challengeParameters['SRP_B'],
      $challengeParameters['SALT']
    );
    
    $msg = $device_group_key.$device_key.$secretBlock.$time;
    $signature = hash_hmac('sha256', $msg, $hkdf, true);
    
    // reference to the function
    protected function getDevicePasswordAuthenticationKey(string $username, string $devicePassword, string $deviceGroup, string $server, string $salt): string
    {
      $u = $this->calculateU($this->largeA(), $serverB = new BigInteger($server, 16));
    
      if ($u->equals(new BigInteger(0))) {
        throw new \RuntimeException('U cannot be zero.');
      }
    
      $fullPassword = $this->hash(sprintf('%s%s:%s', $deviceGroupKey, $username, $devicePassword));
    
      $x = new BigInteger($this->hexHash($this->padHex($salt).$fullPassword), 16);
      $gModPowXN = $this->g->modPow($x, $this->N);
      $intValue2 = $serverB->subtract($this->k->multiply($gModPowXN));
      $s = $intValue2->modPow($this->smallA()->add($u->multiply($x)), $this->N);
    
      return $this->computeHkdf(
        hex2bin($this->padHex($s)),
        hex2bin($this->padHex($u))
      );
    }
    
    有了所有这些信息,我终于可以返回通过最后一个挑战所需的信息

    return [
      "TIMESTAMP" => $time,
      "USERNAME" => $userId,
      "PASSWORD_CLAIM_SECRET_BLOCK" => $secret_block,
      "PASSWORD_CLAIM_SIGNATURE" => base64_encode($signature),
      "DEVICE_KEY" => $device_key
    ];
    
    请注意,这不是全部代码,我只是试图显示基本的位,但我可能是错的,所以让我知道

    由于某些原因,它并没有像预期的那样工作,我尝试了无数种选择,但都没有成功。如果有人能帮忙,那就太好了

    非常感谢! 标记