Skip to content

Commit cb37f17

Browse files
authored
Use proto request messages for the teeserver (google#723)
1 parent 22911ef commit cb37f17

File tree

6 files changed

+264
-13
lines changed

6 files changed

+264
-13
lines changed

launcher/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
cloud.google.com/go/compute/metadata v0.9.0
99
cloud.google.com/go/logging v1.13.1
1010
cos.googlesource.com/cos/tools.git v0.0.0-20250414225215-0cf736c0714c
11-
github.com/GoogleCloudPlatform/confidential-space/server v0.0.0-20260307011055-895ec9019dd7
11+
github.com/GoogleCloudPlatform/confidential-space/server v0.0.0-20260313232128-53cb34b09004
1212
github.com/NVIDIA/go-nvml v0.13.0-1
1313
github.com/cenkalti/backoff/v4 v4.3.0
1414
github.com/confidentsecurity/go-nvtrust v0.2.2

launcher/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ github.com/Azure/go-autorest v12.0.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSW
9494
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
9595
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
9696
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20191009163259-e802c2cb94ae/go.mod h1:mjwGPas4yKduTyubHvD1Atl9r1rUq8DfVy+gkVvZ+oo=
97-
github.com/GoogleCloudPlatform/confidential-space/server v0.0.0-20260307011055-895ec9019dd7 h1:Iz7wjnn93xcmPlUS/9ue7CeyH7yvcxHAXKu+2lE2/is=
98-
github.com/GoogleCloudPlatform/confidential-space/server v0.0.0-20260307011055-895ec9019dd7/go.mod h1:sNFt/HcARjGxR3/2s7hwlqvHlUzXdaCiS62u7A4rnHg=
97+
github.com/GoogleCloudPlatform/confidential-space/server v0.0.0-20260313232128-53cb34b09004 h1:KBneM0Z9zFepj+SkNat7z+4+DvB78edk/LIBjlU3xYM=
98+
github.com/GoogleCloudPlatform/confidential-space/server v0.0.0-20260313232128-53cb34b09004/go.mod h1:sNFt/HcARjGxR3/2s7hwlqvHlUzXdaCiS62u7A4rnHg=
9999
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
100100
github.com/Masterminds/goutils v1.1.0/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
101101
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=

launcher/teeserver/proto/gen/teeserver/teeserver.pb.go

Lines changed: 228 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
protoc -I. -I../../../ -I../../../proto --go_out=. --go_opt=module=github.com/google/go-tpm-tools/launcher/teeserver/proto --experimental_allow_proto3_optional teeserver.proto
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
3+
package teeserver;
4+
5+
import "keymanager/km_common/proto/crypto_types.proto";
6+
7+
option go_package = "github.com/google/go-tpm-tools/launcher/teeserver/proto/gen/teeserver";
8+
9+
message GetKeyEndorsementRequest {
10+
bytes challenge = 1;
11+
keymanager.KeyHandle key_handle = 2;
12+
}
13+
14+
message GetAttestationEvidenceRequest {
15+
bytes challenge = 1;
16+
}

launcher/teeserver/tee_server.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"encoding/json"
88
"fmt"
9+
"io"
910
"net"
1011
"net/http"
1112
"strings"
@@ -16,6 +17,7 @@ import (
1617
"github.com/google/go-tpm-tools/launcher/agent"
1718
"github.com/google/go-tpm-tools/launcher/internal/logging"
1819
"github.com/google/go-tpm-tools/launcher/spec"
20+
tspb "github.com/google/go-tpm-tools/launcher/teeserver/proto/gen/teeserver"
1921
"github.com/google/go-tpm-tools/verifier"
2022
"github.com/google/go-tpm-tools/verifier/models"
2123
"google.golang.org/grpc/codes"
@@ -162,11 +164,13 @@ func (a *attestHandler) getAttestationEvidence(w http.ResponseWriter, r *http.Re
162164
return
163165
}
164166

165-
var req struct {
166-
Challenge []byte `json:"challenge"`
167+
var req tspb.GetAttestationEvidenceRequest
168+
body, err := io.ReadAll(r.Body)
169+
if err != nil {
170+
a.logAndWriteHTTPError(w, http.StatusBadRequest, fmt.Errorf("failed to read request body: %v", err))
171+
return
167172
}
168-
169-
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
173+
if err := protojson.Unmarshal(body, &req); err != nil {
170174
a.logAndWriteHTTPError(w, http.StatusBadRequest, fmt.Errorf("failed to decode request: %v", err))
171175
return
172176
}
@@ -245,14 +249,14 @@ func (a *attestHandler) getKeyEndorsement(w http.ResponseWriter, r *http.Request
245249
return
246250
}
247251

248-
var req struct {
249-
Challenge []byte `json:"challenge"`
250-
KeyHandle struct {
251-
Handle string `json:"handle"`
252-
} `json:"key_handle"`
252+
var req tspb.GetKeyEndorsementRequest
253+
body, err := io.ReadAll(r.Body)
254+
if err != nil {
255+
a.logAndWriteHTTPError(w, http.StatusBadRequest, fmt.Errorf("failed to read request body: %v", err))
256+
return
253257
}
254258

255-
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
259+
if err := protojson.Unmarshal(body, &req); err != nil {
256260
a.logAndWriteHTTPError(w, http.StatusBadRequest, fmt.Errorf("failed to decode request: %v", err))
257261
return
258262
}

0 commit comments

Comments
 (0)