Example #1
0
 /**
  * Generate response data.
  *
  * @param array $values
  */
 protected function response($values)
 {
     $values['cnonce'] = uniqid(mt_rand(), false);
     $values['nc'] = '00000001';
     $values['qop'] = 'auth';
     if (!isset($values['realm'])) {
         $values['realm'] = $this->getOptions()->getTo();
     }
     if (!isset($values['digest-uri'])) {
         $values['digest-uri'] = 'xmpp/' . $this->getOptions()->getTo();
     }
     $a1 = sprintf('%s:%s:%s', $this->getUsername(), $values['realm'], $this->getPassword());
     if ('md5-sess' === $values['algorithm']) {
         $a1 = pack('H32', md5($a1)) . ':' . $values['nonce'] . ':' . $values['cnonce'];
     }
     $a2 = "AUTHENTICATE:" . $values['digest-uri'];
     $password = md5($a1) . ':' . $values['nonce'] . ':' . $values['nc'] . ':' . $values['cnonce'] . ':' . $values['qop'] . ':' . md5($a2);
     $password = md5($password);
     $response = sprintf('username="******",realm="%s",nonce="%s",cnonce="%s",nc=%s,qop=%s,digest-uri="%s",response=%s,charset=utf-8', $this->getUsername(), $values['realm'], $values['nonce'], $values['cnonce'], $values['nc'], $values['qop'], $values['digest-uri'], $password);
     return XML::base64Encode($response);
 }