-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fake client for launcher/verifier/client interface (#234)
Fix test with new Fake Client Co-authored-by: Josh Krstic <jkrstic@google.com>
- Loading branch information
1 parent
4292990
commit fb6d253
Showing
6 changed files
with
99 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Package fake is a fake implementation of the Client interface for testing. | ||
package fake | ||
|
||
import ( | ||
"context" | ||
"crypto" | ||
"encoding/binary" | ||
"time" | ||
|
||
"github.com/golang-jwt/jwt/v4" | ||
"github.com/google/go-tpm-tools/launcher/verifier" | ||
) | ||
|
||
type fakeClient struct { | ||
signer crypto.Signer | ||
} | ||
|
||
// NewClient contructs a new fake client given a crypto.Signer. | ||
func NewClient(signer crypto.Signer) verifier.Client { | ||
return &fakeClient{signer} | ||
} | ||
|
||
// CreateChallenge returns a hard coded, basic challenge. | ||
// | ||
// If you have found this method is insufficient for your tests, this class must be updated to | ||
// allow for better testing. | ||
func (fc *fakeClient) CreateChallenge(ctx context.Context) (*verifier.Challenge, error) { | ||
bs := make([]byte, 2) | ||
binary.LittleEndian.PutUint16(bs, 15) | ||
return &verifier.Challenge{ | ||
Name: "projects/fakeProject/locations/fakeRegion/challenges/d882c62f-452f-4709-9335-0cccaf64eee1", | ||
Nonce: bs, | ||
}, nil | ||
} | ||
|
||
// VerifyAttestation does basic checks and returns a hard coded attestation response. | ||
// | ||
// If you have found this method is insufficient for your tests, this class must be updated to | ||
// allow for better testing. | ||
func (fc *fakeClient) VerifyAttestation(ctx context.Context, request verifier.VerifyAttestationRequest) (*verifier.VerifyAttestationResponse, error) { | ||
// Determine signing algorithm. | ||
signingMethod := jwt.SigningMethodRS256 | ||
now := jwt.TimeFunc() | ||
claims := jwt.RegisteredClaims{ | ||
IssuedAt: &jwt.NumericDate{Time: now}, | ||
NotBefore: &jwt.NumericDate{Time: now}, | ||
ExpiresAt: &jwt.NumericDate{Time: now.Add(time.Hour)}, | ||
Audience: []string{"https://sts.googleapis.com/"}, | ||
Issuer: "https://confidentialcomputing.googleapis.com/", | ||
Subject: "https://www.googleapis.com/compute/v1/projects/fakeProject/zones/fakeZone/instances/fakeInstance", | ||
} | ||
|
||
token := jwt.NewWithClaims(signingMethod, claims) | ||
|
||
// Instead of a private key, provide the signer. | ||
signed, err := token.SignedString(fc.signer) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
response := verifier.VerifyAttestationResponse{ | ||
ClaimsToken: []byte(signed), | ||
} | ||
|
||
return &response, nil | ||
} |
81 changes: 0 additions & 81 deletions
81
launcher/verifier/grpcclient/service/fake_attestationverifier.go
This file was deleted.
Oops, something went wrong.
111 changes: 0 additions & 111 deletions
111
launcher/verifier/grpcclient/service/fake_attestationverifier_test.go
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
launcher/verifier/grpcclient/service/fake_tokens/fake_rsa_token.txt
This file was deleted.
Oops, something went wrong.