@@ -12,6 +12,7 @@ import (
12
12
13
13
"github.com/google/go-attestation/attest"
14
14
"github.com/gorilla/websocket"
15
+ "github.com/pkg/errors"
15
16
"github.com/sirupsen/logrus"
16
17
)
17
18
@@ -34,6 +35,11 @@ func Get(cacerts []byte, url string, header http.Header) ([]byte, error) {
34
35
return nil , err
35
36
}
36
37
38
+ hash , err := GetPubHash ()
39
+ if err != nil {
40
+ return nil , err
41
+ }
42
+
37
43
token , err := getToken (attestationData )
38
44
if err != nil {
39
45
return nil , err
@@ -44,9 +50,15 @@ func Get(cacerts []byte, url string, header http.Header) ([]byte, error) {
44
50
}
45
51
header .Add ("Authorization" , token )
46
52
wsURL := strings .Replace (url , "http" , "ws" , 1 )
47
- logrus .Infof ("Dialing %s with Authorization: %s" , wsURL , token )
48
- conn , _ , err := dialer .Dial (wsURL , header )
53
+ logrus .Infof ("Using TPMHash %s to dial %s" , hash , wsURL )
54
+ conn , resp , err := dialer .Dial (wsURL , header )
49
55
if err != nil {
56
+ if resp != nil && resp .StatusCode == http .StatusUnauthorized {
57
+ data , err := ioutil .ReadAll (resp .Body )
58
+ if err == nil {
59
+ return nil , errors .New (string (data ))
60
+ }
61
+ }
50
62
return nil , err
51
63
}
52
64
defer conn .Close ()
@@ -61,7 +73,7 @@ func Get(cacerts []byte, url string, header http.Header) ([]byte, error) {
61
73
return nil , fmt .Errorf ("unmarshaling Challenge: %w" , err )
62
74
}
63
75
64
- resp , err := getChallengeResponse (challenge .EC , aikBytes )
76
+ challengeResp , err := getChallengeResponse (challenge .EC , aikBytes )
65
77
if err != nil {
66
78
return nil , err
67
79
}
@@ -72,7 +84,7 @@ func Get(cacerts []byte, url string, header http.Header) ([]byte, error) {
72
84
}
73
85
defer writer .Close ()
74
86
75
- if err := json .NewEncoder (writer ).Encode (resp ); err != nil {
87
+ if err := json .NewEncoder (writer ).Encode (challengeResp ); err != nil {
76
88
return nil , fmt .Errorf ("encoding ChallengeResponse: %w" , err )
77
89
}
78
90
0 commit comments