function printPacket($packet)
{
    $str = "";
    $str .= "Packet: ";
    for ($i = 0; $i < strlen($packet); $i++) {
        $str .= byte2hex(ord($packet[$i]));
        if ($i % 2) {
            $str .= "_";
        }
    }
    $str .= "<br>\n";
    return $str;
}
Exemple #2
0
 public function verifyM1computeM2($clientM1)
 {
     //M1 = H( H(N) xor H(g) , H (I) , s, A, B, K)
     $hi = byte2hex($this->_srp->NgXorHash());
     $hi .= $this->_srp->hash($this->_username);
     $hi .= $this->_shex;
     $hi .= str_pad($this->_Ahex, strlen($this->_srp->Nhex()), "0", STR_PAD_LEFT);
     $hi .= str_pad($this->_Bhex, strlen($this->_srp->Nhex()), "0", STR_PAD_LEFT);
     $hi .= $this->_Khex;
     if (strlen($hi) % 2 == 1) {
         $hi = $hi . '0';
     }
     $hi = pack("H*", $hi);
     $hash_input = $this->_srp->NgXorHash();
     $hash_input .= pack("H*", $this->_srp->hash($this->_username));
     $hash_input .= pack("H*", $this->_shex);
     $hash_input .= pack("H*", $this->_Ahex);
     $hash_input .= pack("H*", $this->_Bhex);
     $hash_input .= pack("H*", $this->_Khex);
     $M1 = $this->_srp->hash($hi);
     $this->_M1 = $M1;
     if (strcmp($this->_M1, $clientM1) != 0) {
         throw new Exception('AUTHENTICATION_FAILED');
     }
     // Login the user
     $this->login($this->_username, $this->_userid);
     //M2 = H(A, M, K)
     $M2 = $this->_srp->hash(pack("H*", $this->_Ahex) . pack("H*", $M1) . pack("H*", $this->_Khex));
     return $M2;
 }