mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-08-07 07:14:50 +00:00
de50b6d2d4
* feat: Implement EAT (Evidence Attestation Token) generation and verification for attestation responses, replacing raw quotes with EAT tokens in the attestation service and protobuf. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * style: standardize comment formatting and fix a debug log format specifier. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix pkg test Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Introduce named constants for OEM IDs and use them in attestation claim extraction. Signed-off-by: SammyOina <sammyoina@gmail.com> * feat: Implement and test minimum length validation for EAT nonce in `NewEATClaims`. Signed-off-by: SammyOina <sammyoina@gmail.com> * feat: Add EATClaims.Sanitize method and integrate it into the validator to enforce claim dependencies. Signed-off-by: SammyOina <sammyoina@gmail.com> * feat: Add Signature field to SNPExtensions and TDXExtensions for enhanced claim validation Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Update dependencies and improve code structure in attestation package Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Introduce comprehensive test suites for EAT, ATLS, TDX, Azure SNP, and vTPM attestation, and improve EAT decoder robustness. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Add encryption and admin keys, an encrypted algorithm file, and update go.mod to use go-jose/v4. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: add new encryption and KBS admin keys while improving TDX attestation test error handling. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Add new KBS admin and encryption keys, an encrypted linear regression algorithm, and refactor TDX test error message checks. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Implement Azure SNP attestation policy, update certificate verification, and add key management. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: replace hardcoded string literals with variables in Azure SNP attestation tests. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Refactor TDX EAT claims to use individual RTMR fields with `tdx_` prefixes and add an `IntUse` field. Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com> Signed-off-by: SammyOina <sammyoina@gmail.com>
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package tdx
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"crypto/elliptic"
|
|
"crypto/rand"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/ultravioletrs/cocos/pkg/attestation/eat"
|
|
)
|
|
|
|
func TestVerifyEAT_TDX(t *testing.T) {
|
|
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
|
require.NoError(t, err)
|
|
|
|
claims := &eat.EATClaims{
|
|
Nonce: []byte("test-nonce"),
|
|
IssuedAt: time.Now().Unix(),
|
|
RawReport: []byte("dummy-report"),
|
|
PlatformType: "TDX",
|
|
}
|
|
|
|
jwtEncoder := eat.NewJWTEncoder(key, "issuer")
|
|
token, err := jwtEncoder.Encode(claims)
|
|
require.NoError(t, err)
|
|
|
|
vInterface := NewVerifier()
|
|
|
|
v, ok := vInterface.(verifier)
|
|
require.True(t, ok)
|
|
|
|
err = v.VerifyEAT([]byte(token), []byte("tee-nonce"), []byte("vtpm-nonce"))
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "failed")
|
|
}
|
|
|
|
func TestVerifyEAT_TDX_InvalidToken(t *testing.T) {
|
|
vInterface := NewVerifier()
|
|
v, ok := vInterface.(verifier)
|
|
require.True(t, ok)
|
|
|
|
err := v.VerifyEAT([]byte("invalid-token"), nil, nil)
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), "failed to decode EAT token")
|
|
}
|
|
|
|
func TestTeeAttestation_InvalidNonce(t *testing.T) {
|
|
p := NewProvider()
|
|
|
|
nonce := make([]byte, 64)
|
|
_, err := p.TeeAttestation(nonce)
|
|
assert.Error(t, err)
|
|
// Check for likely errors in non-TDX environment
|
|
// Check for likely errors in non-TDX environment
|
|
errMsg := err.Error()
|
|
assert.True(t,
|
|
strings.Contains(errMsg, "no such file or directory") ||
|
|
strings.Contains(errMsg, "permission denied") ||
|
|
strings.Contains(errMsg, "failed to open TDX device"),
|
|
"unexpected error message: %s", errMsg,
|
|
)
|
|
}
|