-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixtures_test.go
More file actions
122 lines (111 loc) · 4.51 KB
/
Copy pathfixtures_test.go
File metadata and controls
122 lines (111 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package awsnitroverifier
import (
"encoding/base64"
"encoding/hex"
"strings"
"testing"
)
// Note: Attestation fixtures are embedded and managed in the root package test_helpers.go
// using //go:embed. This allows the root package tests and the internal package tests
// to share the same test data files.
// Capturing fresh AWS Nitro attestation documents for use as test fixtures:
//
// 1. Run an enclave with your application.
// 2. From within the enclave, call the Nitro Secure Module to get an attestation
// document (it will contain your PCR values and optional user data).
// 3. Base64-encode the document and drop it into testdata/.
//
// References:
// - https://docs.aws.amazon.com/enclaves/latest/user/nitro-enclave-concepts.html
// - https://docs.aws.amazon.com/enclaves/latest/user/verify-root.html
//
// Note: bundled fixtures contain expired certificates and must be validated
// with SkipTimestampCheck: true.
//
// Expected values for the bundled fixtures (Turnkey-derived, real-world Nitro
// attestations — the verifier itself is generic):
//
// turnkey-prod.base64:
// PCR[3]: b798abfdbd591d5e1b7db6485a6de9e65100f5796d9e3a2bd7c179989cd663338b567162974974fbcc45d03847e70d8b
// UserData: 8a5510ca253818acec5fb27b3ca114b4a260fb84f881838eb124aae9c968ad74 (32 bytes)
// PublicKey: 130 bytes (ECDSA)
//
// turnkey-preprod.base64 (if added):
// PCR[3]: 864e9095a9947ab14698122370c13baf23183f4e9911953cf5b909a49db00f43f446707314674d9309974f3cc4b24728
// UserData: 37ef96370730962341148a03754955137884516def11439b5d841809f6f9caac (32 bytes)
// PublicKey: 130 bytes (ECDSA)
//
// Example: capturing a Turnkey signer attestation via the Turnkey CLI:
// turnkey request \
// --host api.turnkey.com \
// --path /public/v1/query/get_attestation \
// --body '{"organizationId": "<yourOrgId>","enclaveType": "signer"}' \
// --organization=<yourOrgId> | jq -r '.attestationDocument' > turnkey-attestation.base64
// TestAWSRootCertificateVerification - this test has been moved to internal package
// since it tests internal implementation details
// TestAWSNitroFixtures tests AWS Nitro attestation documents from Veracruz project
// These documents are sourced from: https://github.com/veracruz-project/go-nitro-enclave-attestation-document/blob/main/test/aws_nitro_document.cbor
func TestAWSNitroFixtures(t *testing.T) {
testCases := []struct {
name string
attestationData []byte
description string
}{
{
name: "AWS Nitro Document (Base64)",
attestationData: func() []byte {
data, err := base64.StdEncoding.DecodeString(strings.TrimSpace(awsNitroDocumentBase64))
if err != nil {
panic("Failed to decode embedded base64 data: " + err.Error())
}
return data
}(),
description: "Base64 encoded version",
},
{
name: "AWS Nitro Document (CBOR)",
attestationData: awsNitroDocumentCbor,
description: "Raw CBOR bytes",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Test with chain validation enabled but timestamp check disabled
// (These are older certificates that may have expired)
validator := NewVerifier(AWSNitroVerifierOptions{
SkipTimestampCheck: true,
})
result, err := validator.Validate(tc.attestationData)
if err != nil {
t.Fatalf("Fatal error validating %s: %v", tc.description, err)
}
// Check chain validation was performed
if !result.ChainTrusted {
t.Errorf("Certificate chain was not validated for %s, errors: %v", tc.description, result.Errors)
}
// Verify root fingerprint matches AWS Nitro root using built-in constant
if result.RootFingerprint != awsNitroRootFingerprint {
t.Errorf("Root fingerprint mismatch for %s: expected %s, got %s",
tc.description, awsNitroRootFingerprint, result.RootFingerprint)
} else {
t.Logf("✓ Root fingerprint verified for %s: %s", tc.description, result.RootFingerprint)
}
// Test that validation is successful overall
if !result.Valid {
t.Errorf("Validation was not successful for %s, errors: %v", tc.description, result.Errors)
} else {
t.Logf("✓ AWS Nitro attestation (%s) validated successfully", tc.description)
}
// Log some details about the attestation
if len(result.UserData) > 0 {
t.Logf(" UserData: %d bytes (%s)", len(result.UserData), hex.EncodeToString(result.UserData))
}
if len(result.PublicKey) > 0 {
t.Logf(" PublicKey: %d bytes", len(result.PublicKey))
}
if len(result.Nonce) > 0 {
t.Logf(" Nonce: %d bytes", len(result.Nonce))
}
})
}
}