Exemple #1
0
 /**
  * Handle process challenge message
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Message\ChallengeMessage $msg
  */
 public function processChallenge(ClientSession $session, ChallengeMessage $msg)
 {
     $authMethod = $msg->getAuthMethod();
     // look for authenticator
     /** @var ClientAuthenticationInterface $ca */
     foreach ($this->clientAuthenticators as $ca) {
         if (in_array($authMethod, $ca->getAuthMethods())) {
             $authenticateMsg = $ca->getAuthenticateFromChallenge($msg);
             $session->sendMessage($authenticateMsg);
             return;
         }
     }
     $this->emit('challenge', [$session, $msg]);
 }
 public function getAuthenticateFromChallenge(ChallengeMessage $msg)
 {
     echo "Got challenge:\n";
     echo $msg->getSerializedMessage();
     echo "\n";
     if (!in_array($msg->getAuthMethod(), $this->getAuthMethods())) {
         //throw new \Exception("method isn't in methods");
         return false;
     }
     if (!is_array($msg->getDetails())) {
         echo "No details sent with challenge.\n";
         return false;
     }
     $challenge = '';
     if (isset($msg->getDetails()['challenge'])) {
         $challenge = $msg->getDetails()['challenge'];
     } else {
         echo "No challenge for wampcra?\n";
         return false;
     }
     $keyToUse = $this->key;
     if (isset($msg->getDetails()['salt'])) {
         // we need a salted key
         $salt = $msg->getDetails()['salt'];
         $keyLen = 32;
         if (isset($msg->getDetails()['keylen'])) {
             if (is_numeric($msg->getDetails()['keylen'])) {
                 $keyLen = $msg->getDetails()['keylen'];
             } else {
                 echo "keylen is not numeric.\n";
             }
         }
         $iterations = 1000;
         if (isset($msg->getDetails()['iterations'])) {
             if (is_numeric($msg->getDetails()['iterations'])) {
                 $iterations = $msg->getDetails()['iterations'];
             } else {
                 echo "iterations is not numeric.\n";
             }
         }
         $keyToUse = $this->getDerivedKey($this->key, $salt, $iterations, $keyLen);
     }
     $token = base64_encode(hash_hmac('sha256', $challenge, $keyToUse, true));
     $authMessage = new AuthenticateMessage($token);
     echo "returning: " . $authMessage->getSerializedMessage() . "\n";
     return $authMessage;
 }