-
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
Fix test with new Fake Client
- Loading branch information
Josh Krstic
committed
Aug 4, 2022
1 parent
51031c1
commit 02aca36
Showing
5 changed files
with
89 additions
and
31 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,59 @@ | ||
// Package fakeverifier is a fake implementation of the AttestationVerifier for testing. | ||
package fake | ||
|
||
import ( | ||
"context" | ||
"crypto" | ||
|
||
"github.com/golang-jwt/jwt/v4" | ||
"github.com/google/go-tpm-tools/launcher/verifier" | ||
) | ||
|
||
type fakeClient struct { | ||
//pbClient servpb.AttestationVerifierClient | ||
signer 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) { | ||
return &verifier.Challenge{ | ||
Name: "FakeName", | ||
Nonce: []byte{0x0}, | ||
}, 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(60 * 60 * 1e9)}, // Add takes nanoseconds | ||
Audience: []string{"TestingAudience"}, | ||
Issuer: "TestingIssuer", | ||
Subject: "TestingSubject", | ||
} | ||
|
||
token := jwt.NewWithClaims(signingMethod, claims) | ||
|
||
// Instead of a private key, provide the signer. | ||
signed, _ := token.SignedString(fc.signer) | ||
|
||
response := verifier.VerifyAttestationResponse{ | ||
ClaimsToken: []byte(signed), | ||
} | ||
|
||
return &response, nil | ||
} |
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
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.