Skip to content

Instantly share code, notes, and snippets.

@titanous
Last active December 17, 2015 14:59
Show Gist options
  • Save titanous/5628913 to your computer and use it in GitHub Desktop.
Save titanous/5628913 to your computer and use it in GitHub Desktop.
Hawk test vector generator
package main
import (
"crypto/sha256"
"fmt"
"strconv"
"time"
"github.com/tent/hawk-go"
)
func main() {
hawk.Now = func() time.Time { return time.Unix(1368996800, 0) }
req := hawk.Auth{
Credentials: hawk.Credentials{
ID: "exqbZWtykFZIh2D7cXi9dA",
Key: "HX9QcbD-r3ItFEnRcAuOSg",
App: "wn6yzHGe5TLaT-fvOPbAyQ",
Hash: sha256.New,
},
Method: "POST",
RequestURI: "/posts",
Host: "example.com",
Port: "443",
Nonce: "3yuYCD4Z",
Timestamp: hawk.Now(),
}
typ := "application/vnd.tent.post.v0+json"
hash := req.PayloadHash(typ)
data := `{"type":"https://tent.io/types/status/v0#"}`
hash.Write([]byte(data))
req.SetHash(hash)
req.ReqHash = true
oldHash := req.Hash
fmt.Printf("\n```text\nAuthorization: %s\n\n%s\n```\n", req.RequestHeader(), strconv.Quote(req.NormalizedString(hawk.AuthHeader)))
fmt.Printf("\n```text\nServer-Authorization: %s\n\n%s\n```\n", req.ResponseHeader(""), strconv.Quote(req.NormalizedString(hawk.AuthResponse)))
req.Credentials.App = ""
fmt.Printf("\n```text\nAuthorization: %s\n\n%s\n```\n", req.RequestHeader(), strconv.Quote(req.NormalizedString(hawk.AuthHeader)))
req.ReqHash = false
req.Hash = oldHash
fmt.Printf("\n```text\nServer-Authorization: %s\n\n%s\n```\n", req.ResponseHeader(""), strconv.Quote(req.NormalizedString(hawk.AuthResponse)))
fmt.Printf("\n```text\nWWW-Authenticate: %s\n```\n", req.StaleTimestampHeader())
req.Hash = nil
fmt.Printf("\n```text\n/posts?bewit=%s\n\n%s\n```\n", req.Bewit(), strconv.Quote(req.NormalizedString(hawk.AuthBewit)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment