forked from Ferlonas/hpkp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
48 lines (41 loc) · 1019 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package hpkp_test
import (
"fmt"
"log"
"net/http"
"github.com/ferlonas/hpkp"
)
func Example() {
s := hpkp.NewMemStorage()
s.Add("github.com", &hpkp.Header{
Permanent: true,
Sha256Pins: []string{
"WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18=",
"RRM1dGqnDFsCJXBTHky16vi1obOlCgFFn/yOhI/y+ho=",
"k2v657xBsOVe1PQRwOsHsw3bsGT2VzIqz5K+59sNQws=",
"K87oWBWM9UZfyddvDfoxL+8lpNyoUB2ptGtn0fv6G2Q=",
"IQBnNBEiFuhj+8x6X8XLgh01V9Ic5/V3IRQLNFFc7v4=",
"iie1VXtL7HzAMF+/PVPR9xzT80kQxdZeJ+zduCB3uj0=",
"LvRiGEjRqfzurezaWuj8Wie2gyHMrW5Q06LspMnox7A=",
},
})
client := &http.Client{}
dialConf := &hpkp.DialerConfig{
Storage: s,
PinOnly: true,
TLSConfig: nil,
Reporter: func(p *hpkp.PinFailure, reportUri string) {
// TODO: report on PIN failure
fmt.Println(p)
},
}
client.Transport = &http.Transport{
DialTLSContext: dialConf.NewDialer(),
}
resp, err := client.Get("https://github.com")
if err != nil {
log.Fatal(err)
}
fmt.Println(resp.StatusCode)
// Output: 200
}