example_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package hpkp_test
  2. import (
  3. "fmt"
  4. "log"
  5. "net/http"
  6. "git.schwanenlied.me/yawning/hpkp.git"
  7. )
  8. func Example() {
  9. s := hpkp.NewMemStorage()
  10. s.Add("github.com", &hpkp.Header{
  11. Permanent: true,
  12. Sha256Pins: []string{
  13. "WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=",
  14. "RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=",
  15. "k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws=",
  16. "K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q=",
  17. "IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4=",
  18. "iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0=",
  19. "LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A=",
  20. },
  21. })
  22. client := &http.Client{}
  23. dialConf := &hpkp.DialerConfig{
  24. Storage: s,
  25. PinOnly: true,
  26. TLSConfig: nil,
  27. Reporter: func(p *hpkp.PinFailure, reportUri string) {
  28. // TODO: report on PIN failure
  29. fmt.Println(p)
  30. },
  31. }
  32. client.Transport = &http.Transport{
  33. DialTLS: dialConf.NewDialer(),
  34. }
  35. resp, err := client.Get("https://github.com")
  36. if err != nil {
  37. log.Fatal(err)
  38. }
  39. fmt.Println(resp.StatusCode)
  40. // Output: 200
  41. }