Exemplo n.º 1
0
 private function generateNormalizedString($type, Artifacts $attributes)
 {
     $normalized = 'hawk.' . self::HEADER_VERSION . '.' . $type . "\n" . $attributes->timestamp() . "\n" . $attributes->nonce() . "\n" . strtoupper($attributes->method()) . "\n" . $attributes->resource() . "\n" . strtolower($attributes->host()) . "\n" . $attributes->port() . "\n" . $attributes->hash() . "\n";
     if ($attributes->ext()) {
         // TODO: escape ext
         $normalized .= $attributes->ext();
     }
     $normalized .= "\n";
     if ($attributes->app()) {
         $normalized .= $attributes->app() . "\n" . $attributes->dlg() . "\n";
     }
     return $normalized;
 }
Exemplo n.º 2
0
 public function createHeader(CredentialsInterface $credentials, Artifacts $artifacts, array $options = array())
 {
     if (isset($options['payload']) || isset($options['content_type'])) {
         if (isset($options['payload']) && isset($options['content_type'])) {
             $payload = $options['payload'];
             $contentType = $options['content_type'];
             $hash = $this->crypto->calculatePayloadHash($payload, $credentials->algorithm(), $contentType);
         } else {
             throw new \InvalidArgumentException("If one of 'payload' and 'content_type' are specified, both must be specified.");
         }
     } else {
         $payload = null;
         $contentType = null;
         $hash = null;
     }
     $ext = isset($options['ext']) ? $options['ext'] : null;
     $responseArtifacts = new Artifacts($artifacts->method(), $artifacts->host(), $artifacts->port(), $artifacts->resource(), $artifacts->timestamp(), $artifacts->nonce(), $ext, $payload, $contentType, $hash, $artifacts->app(), $artifacts->dlg());
     $attributes = array('mac' => $this->crypto->calculateMac('response', $credentials, $responseArtifacts));
     if ($hash) {
         $attributes['hash'] = $hash;
     }
     if ($ext) {
         $attributes['ext'] = $ext;
     }
     return HeaderFactory::create('Server-Authorization', $attributes);
 }