Skip to content

Commit d629cc2

Browse files
committed
Modified Connector to use new attestation end-point for Azure tdvm. (#100)
1 parent 87e6c08 commit d629cc2

File tree

15 files changed

+39
-36
lines changed

15 files changed

+39
-36
lines changed

go-connector/attest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (connector *trustAuthorityConnector) Attest(args AttestArgs) (AttestRespons
2424
return response, errors.Errorf("Failed to collect evidence from adapter: %s", err)
2525
}
2626

27-
tokenResponse, err := connector.GetToken(GetTokenArgs{nil, evidence, args.PolicyIds, args.RequestId})
27+
tokenResponse, err := connector.GetToken(GetTokenArgs{nonceResponse.Nonce, evidence, args.PolicyIds, args.RequestId})
2828
response.Token, response.Headers = tokenResponse.Token, tokenResponse.Headers
2929
if err != nil {
3030
return response, errors.Errorf("Failed to collect token from Trust Authority: %s", err)

go-connector/attest_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestAttest(t *testing.T) {
2626
connector, mux, _, teardown := setup()
2727
defer teardown()
2828

29-
mux.HandleFunc("/appraisal/v1/nonce", func(w http.ResponseWriter, r *http.Request) {
29+
mux.HandleFunc(nonceEndpoint, func(w http.ResponseWriter, r *http.Request) {
3030
w.WriteHeader(http.StatusOK)
3131
w.Write([]byte(`{"val":"` + nonceVal + `","iat":"` + nonceIat + `","signature":"` + nonceSig + `"}`))
3232
})
@@ -35,7 +35,7 @@ func TestAttest(t *testing.T) {
3535
evidence := &Evidence{}
3636
adapter.On("CollectEvidence", mock.Anything).Return(evidence, nil)
3737

38-
mux.HandleFunc("/appraisal/v1/attest", func(w http.ResponseWriter, r *http.Request) {
38+
mux.HandleFunc(attestEndpoint, func(w http.ResponseWriter, r *http.Request) {
3939
w.WriteHeader(http.StatusOK)
4040
w.Write([]byte(`{"token":"` + token + `"}`))
4141
})
@@ -50,15 +50,15 @@ func TestAttest_nonceFailure(t *testing.T) {
5050
connector, mux, _, teardown := setup()
5151
defer teardown()
5252

53-
mux.HandleFunc("/appraisal/v1/nonce", func(w http.ResponseWriter, r *http.Request) {
53+
mux.HandleFunc(nonceEndpoint, func(w http.ResponseWriter, r *http.Request) {
5454
w.WriteHeader(http.StatusOK)
5555
w.Write([]byte(`invalid nonce`))
5656
})
5757

5858
adapter := MockAdapter{}
5959
adapter.On("CollectEvidence", mock.Anything).Return(mock.Anything, nil)
6060

61-
mux.HandleFunc("/appraisal/v1/attest", func(w http.ResponseWriter, r *http.Request) {
61+
mux.HandleFunc(attestEndpoint, func(w http.ResponseWriter, r *http.Request) {
6262
w.WriteHeader(http.StatusOK)
6363
w.Write([]byte(`{"token":"` + token + `"}`))
6464
})
@@ -73,7 +73,7 @@ func TestAttest_evidenceFailure(t *testing.T) {
7373
connector, mux, _, teardown := setup()
7474
defer teardown()
7575

76-
mux.HandleFunc("/appraisal/v1/nonce", func(w http.ResponseWriter, r *http.Request) {
76+
mux.HandleFunc(nonceEndpoint, func(w http.ResponseWriter, r *http.Request) {
7777
w.WriteHeader(http.StatusOK)
7878
w.Write([]byte(`{"val":"` + nonceVal + `","iat":"` + nonceIat + `","signature":"` + nonceSig + `"}`))
7979
})
@@ -82,7 +82,7 @@ func TestAttest_evidenceFailure(t *testing.T) {
8282
evidence := &Evidence{}
8383
adapter.On("CollectEvidence", mock.Anything).Return(evidence, errors.New("failed to collect evidence"))
8484

85-
mux.HandleFunc("/appraisal/v1/attest", func(w http.ResponseWriter, r *http.Request) {
85+
mux.HandleFunc(attestEndpoint, func(w http.ResponseWriter, r *http.Request) {
8686
w.WriteHeader(http.StatusOK)
8787
w.Write([]byte(`{"token":"` + token + `"}`))
8888
})
@@ -97,7 +97,7 @@ func TestAttest_tokenFailure(t *testing.T) {
9797
connector, mux, _, teardown := setup()
9898
defer teardown()
9999

100-
mux.HandleFunc("/appraisal/v1/nonce", func(w http.ResponseWriter, r *http.Request) {
100+
mux.HandleFunc(nonceEndpoint, func(w http.ResponseWriter, r *http.Request) {
101101
w.WriteHeader(http.StatusOK)
102102
w.Write([]byte(`{"val":"` + nonceVal + `","iat":"` + nonceIat + `","signature":"` + nonceSig + `"}`))
103103
})
@@ -106,7 +106,7 @@ func TestAttest_tokenFailure(t *testing.T) {
106106
evidence := &Evidence{}
107107
adapter.On("CollectEvidence", mock.Anything).Return(evidence, nil)
108108

109-
mux.HandleFunc("/appraisal/v1/attest", func(w http.ResponseWriter, r *http.Request) {
109+
mux.HandleFunc(attestEndpoint, func(w http.ResponseWriter, r *http.Request) {
110110
w.WriteHeader(http.StatusOK)
111111
w.Write([]byte(`invalid token`))
112112
})

go-connector/connector.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ type AttestResponse struct {
7373

7474
// Evidence is used to store Quote to be sent for Attestation
7575
type Evidence struct {
76-
Type uint32
77-
Evidence []byte
78-
UserData []byte
79-
EventLog []byte
76+
Type uint32
77+
Quote []byte
78+
UserData []byte
79+
EventLog []byte
80+
RuntimeData []byte
8081
}
8182

8283
// RetryConfig holds the configuration for automatic retries to tolerate minor outages

go-connector/const.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const (
1212
HeaderRequestId = "request-id"
1313
HeaderTraceId = "trace-id"
1414

15+
nonceEndpoint = "/appraisal/v1/nonce"
16+
attestEndpoint = "/appraisal/v1/attest/azure/tdxvm"
17+
1518
mimeApplicationJson = "application/json"
1619
AtsCertChainMaxLen = 10
1720
MaxRetries = 2

go-connector/nonce.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package connector
77

88
import (
99
"encoding/json"
10-
"fmt"
1110
"io"
1211
"net/http"
1312

@@ -16,7 +15,7 @@ import (
1615

1716
// GetNonce is used to get Intel Trust Authority signed nonce
1817
func (connector *trustAuthorityConnector) GetNonce(args GetNonceArgs) (GetNonceResponse, error) {
19-
url := fmt.Sprintf("%s/appraisal/v1/nonce", connector.cfg.ApiUrl)
18+
url := connector.cfg.ApiUrl + nonceEndpoint
2019

2120
newRequest := func() (*http.Request, error) {
2221
return http.NewRequest(http.MethodGet, url, nil)

go-connector/nonce_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestGetNonce(t *testing.T) {
2222
connector, mux, _, teardown := setup()
2323
defer teardown()
2424

25-
mux.HandleFunc("/appraisal/v1/nonce", func(w http.ResponseWriter, r *http.Request) {
25+
mux.HandleFunc(nonceEndpoint, func(w http.ResponseWriter, r *http.Request) {
2626
w.WriteHeader(http.StatusOK)
2727
w.Write([]byte(`{"val":"` + nonceVal + `","iat":"` + nonceIat + `","signature":"` + nonceSig + `"}`))
2828
})
@@ -51,7 +51,7 @@ func TestGetNonce_invalidNonce(t *testing.T) {
5151
connector, mux, _, teardown := setup()
5252
defer teardown()
5353

54-
mux.HandleFunc("/appraisal/v1/nonce", func(w http.ResponseWriter, r *http.Request) {
54+
mux.HandleFunc(nonceEndpoint, func(w http.ResponseWriter, r *http.Request) {
5555
w.WriteHeader(http.StatusOK)
5656
w.Write([]byte(`invalid nonce`))
5757
})

go-connector/token.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"crypto/tls"
1111
"crypto/x509"
1212
"encoding/json"
13-
"fmt"
1413
"io"
1514
"net/http"
1615
"net/url"
@@ -31,7 +30,7 @@ type tokenRequest struct {
3130
VerifierNonce *VerifierNonce `json:"verifier_nonce,omitempty"`
3231
RuntimeData []byte `json:"runtime_data,omitempty"`
3332
PolicyIds []uuid.UUID `json:"policy_ids,omitempty"`
34-
EventLog []byte `json:"event_log,omitempty"`
33+
UserData []byte `json:"user_data,omitempty"`
3534
}
3635

3736
// AttestationTokenResponse holds the token recieved from Intel Trust Authority
@@ -41,15 +40,15 @@ type AttestationTokenResponse struct {
4140

4241
// GetToken is used to get attestation token from Intel Trust Authority
4342
func (connector *trustAuthorityConnector) GetToken(args GetTokenArgs) (GetTokenResponse, error) {
44-
url := fmt.Sprintf("%s/appraisal/v1/attest", connector.cfg.ApiUrl)
43+
url := connector.cfg.ApiUrl + attestEndpoint
4544

4645
newRequest := func() (*http.Request, error) {
4746
tr := tokenRequest{
48-
Quote: args.Evidence.Evidence,
47+
Quote: args.Evidence.Quote,
4948
VerifierNonce: args.Nonce,
50-
RuntimeData: args.Evidence.UserData,
49+
RuntimeData: args.Evidence.RuntimeData,
5150
PolicyIds: args.PolicyIds,
52-
EventLog: args.Evidence.EventLog,
51+
UserData: args.Evidence.UserData,
5352
}
5453

5554
body, err := json.Marshal(tr)

go-connector/token_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestGetToken(t *testing.T) {
3434
connector, mux, _, teardown := setup()
3535
defer teardown()
3636

37-
mux.HandleFunc("/appraisal/v1/attest", func(w http.ResponseWriter, r *http.Request) {
37+
mux.HandleFunc(attestEndpoint, func(w http.ResponseWriter, r *http.Request) {
3838
w.WriteHeader(http.StatusOK)
3939
w.Write([]byte(`{"token":"` + token + `"}`))
4040
})
@@ -51,7 +51,7 @@ func TestGetToken_invalidToken(t *testing.T) {
5151
connector, mux, _, teardown := setup()
5252
defer teardown()
5353

54-
mux.HandleFunc("/appraisal/v1/attest", func(w http.ResponseWriter, r *http.Request) {
54+
mux.HandleFunc(attestEndpoint, func(w http.ResponseWriter, r *http.Request) {
5555
w.WriteHeader(http.StatusOK)
5656
w.Write([]byte(`invalid token`))
5757
})

go-sgx/collect_evidence.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (adapter *sgxAdapter) CollectEvidence(nonce []byte) (*connector.Evidence, e
8484

8585
return &connector.Evidence{
8686
Type: 0,
87-
Evidence: quote_buffer,
87+
Quote: quote_buffer,
8888
UserData: adapter.uData,
8989
}, nil
9090
}

go-tdx/azure_adapter.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,11 @@ func (adapter *azureAdapter) CollectEvidence(nonce []byte) (*connector.Evidence,
118118
}
119119

120120
return &connector.Evidence{
121-
Type: 1,
122-
Evidence: quote,
123-
UserData: runtimeData,
124-
EventLog: eventLog,
121+
Type: 1,
122+
Quote: quote,
123+
UserData: adapter.uData,
124+
EventLog: eventLog,
125+
RuntimeData: runtimeData,
125126
}, nil
126127
}
127128

0 commit comments

Comments
 (0)