Skip to content

Commit 3cf685b

Browse files
committed
Fix lint: errors.New, rename FakeAttestor, nolint for CBOR tags
1 parent c7b8c13 commit 3cf685b

4 files changed

Lines changed: 27 additions & 26 deletions

File tree

pkg/teeattestation/nitro/fake/fake.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Package fake provides a FakeAttestor that produces structurally valid
1+
// Package fake provides an Attestor that produces structurally valid
22
// COSE Sign1 attestation documents. These documents pass nitrite.Verify's
33
// full validation chain (CBOR parsing, cert chain, ECDSA signature, UserData,
44
// PCRs) without requiring real Nitro hardware.
@@ -21,9 +21,9 @@ import (
2121
"github.com/fxamacker/cbor/v2"
2222
)
2323

24-
// FakeAttestor produces structurally valid COSE Sign1 attestation documents
24+
// Attestor produces structurally valid COSE Sign1 attestation documents
2525
// that pass nitrite.Verify with a custom CA root.
26-
type FakeAttestor struct {
26+
type Attestor struct {
2727
rootKey *ecdsa.PrivateKey
2828
rootCert *x509.Certificate
2929
rootCertDER []byte
@@ -33,9 +33,9 @@ type FakeAttestor struct {
3333
pcrs map[uint][]byte
3434
}
3535

36-
// NewFakeAttestor generates a self-signed P-384 root CA, a leaf cert signed
36+
// NewAttestor generates a self-signed P-384 root CA, a leaf cert signed
3737
// by that root, and deterministic 48-byte fake PCR values.
38-
func NewFakeAttestor() (*FakeAttestor, error) {
38+
func NewAttestor() (*Attestor, error) {
3939
rootKey, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
4040
if err != nil {
4141
return nil, fmt.Errorf("generate root key: %w", err)
@@ -86,7 +86,7 @@ func NewFakeAttestor() (*FakeAttestor, error) {
8686
2: sha384Sum([]byte("fake-pcr-2")),
8787
}
8888

89-
return &FakeAttestor{
89+
return &Attestor{
9090
rootKey: rootKey,
9191
rootCert: rootCert,
9292
rootCertDER: rootCertDER,
@@ -99,10 +99,10 @@ func NewFakeAttestor() (*FakeAttestor, error) {
9999

100100
// CreateAttestation builds a COSE Sign1 document encoding a Nitro-like
101101
// attestation with the given userData.
102-
func (f *FakeAttestor) CreateAttestation(userData []byte) ([]byte, error) {
102+
func (f *Attestor) CreateAttestation(userData []byte) ([]byte, error) {
103103
doc := attestationDocument{
104104
ModuleID: "fake-enclave-module",
105-
Timestamp: uint64(time.Now().UnixMilli()),
105+
Timestamp: uint64(time.Now().UnixMilli()), //nolint:gosec // timestamp is always positive
106106
Digest: "SHA384",
107107
PCRs: f.pcrs,
108108
Certificate: f.leafCertDER,
@@ -157,14 +157,14 @@ func (f *FakeAttestor) CreateAttestation(userData []byte) ([]byte, error) {
157157
}
158158

159159
// CARoots returns an x509.CertPool containing the fake root CA certificate.
160-
func (f *FakeAttestor) CARoots() *x509.CertPool {
160+
func (f *Attestor) CARoots() *x509.CertPool {
161161
pool := x509.NewCertPool()
162162
pool.AddCert(f.rootCert)
163163
return pool
164164
}
165165

166166
// CARootsPEM returns the root CA certificate in PEM format.
167-
func (f *FakeAttestor) CARootsPEM() string {
167+
func (f *Attestor) CARootsPEM() string {
168168
return string(pem.EncodeToMemory(&pem.Block{
169169
Type: "CERTIFICATE",
170170
Bytes: f.rootCertDER,
@@ -173,7 +173,7 @@ func (f *FakeAttestor) CARootsPEM() string {
173173

174174
// TrustedPCRsJSON returns the PCR values as a JSON object matching the
175175
// format expected by the attestation validator.
176-
func (f *FakeAttestor) TrustedPCRsJSON() []byte {
176+
func (f *Attestor) TrustedPCRsJSON() []byte {
177177
m := map[string]string{
178178
"pcr0": hex.EncodeToString(f.pcrs[0]),
179179
"pcr1": hex.EncodeToString(f.pcrs[1]),
@@ -206,15 +206,15 @@ type coseHeader struct {
206206
}
207207

208208
type cosePayload struct {
209-
_ struct{} `cbor:",toarray"`
209+
_ struct{} `cbor:",toarray"` //nolint:revive // idiomatic CBOR array encoding
210210
Protected []byte
211211
Unprotected cbor.RawMessage
212212
Payload []byte
213213
Signature []byte
214214
}
215215

216216
type coseSignature struct {
217-
_ struct{} `cbor:",toarray"`
217+
_ struct{} `cbor:",toarray"` //nolint:revive // idiomatic CBOR array encoding
218218
Context string
219219
Protected []byte
220220
ExternalAAD []byte

pkg/teeattestation/nitro/fake/fake_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/stretchr/testify/require"
99
)
1010

11-
func TestFakeAttestor_RoundTrip(t *testing.T) {
12-
fa, err := NewFakeAttestor()
11+
func TestAttestor_RoundTrip(t *testing.T) {
12+
fa, err := NewAttestor()
1313
require.NoError(t, err)
1414

1515
userData := []byte("test-user-data-12345")
@@ -32,8 +32,8 @@ func TestFakeAttestor_RoundTrip(t *testing.T) {
3232
require.Len(t, result.Document.PCRs[2], 48)
3333
}
3434

35-
func TestFakeAttestor_TrustedPCRsJSON(t *testing.T) {
36-
fa, err := NewFakeAttestor()
35+
func TestAttestor_TrustedPCRsJSON(t *testing.T) {
36+
fa, err := NewAttestor()
3737
require.NoError(t, err)
3838

3939
pcrsJSON := fa.TrustedPCRsJSON()
@@ -43,8 +43,8 @@ func TestFakeAttestor_TrustedPCRsJSON(t *testing.T) {
4343
require.Contains(t, string(pcrsJSON), `"pcr2"`)
4444
}
4545

46-
func TestFakeAttestor_CARootsPEM(t *testing.T) {
47-
fa, err := NewFakeAttestor()
46+
func TestAttestor_CARootsPEM(t *testing.T) {
47+
fa, err := NewAttestor()
4848
require.NoError(t, err)
4949

5050
pemStr := fa.CARootsPEM()

pkg/teeattestation/nitro/validate.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/x509"
77
"encoding/hex"
88
"encoding/json"
9+
"errors"
910
"fmt"
1011
"time"
1112

@@ -62,13 +63,13 @@ func ValidateAttestation(attestation, expectedUserData, trustedMeasurements []by
6263
// fake enclaves that use self-signed CA roots.
6364
func ValidateAttestationWithRoots(attestation, expectedUserData, trustedMeasurements []byte, caRootsPEM string) error {
6465
if attestation == nil {
65-
return fmt.Errorf("attestation is nil")
66+
return errors.New("attestation is nil")
6667
}
6768

6869
pool := x509.NewCertPool()
6970
ok := pool.AppendCertsFromPEM([]byte(caRootsPEM))
7071
if !ok {
71-
return fmt.Errorf("failed to parse CA roots")
72+
return errors.New("failed to parse CA roots")
7273
}
7374
result, err := nitrite.Verify(attestation, nitrite.VerifyOptions{
7475
CurrentTime: time.Now(),
@@ -78,7 +79,7 @@ func ValidateAttestationWithRoots(attestation, expectedUserData, trustedMeasurem
7879
return fmt.Errorf("failed to verify nitro attestation: %w", err)
7980
}
8081
if !result.SignatureOK {
81-
return fmt.Errorf("signature verification failed")
82+
return errors.New("signature verification failed")
8283
}
8384

8485
if !bytes.Equal(expectedUserData, result.Document.UserData) {

pkg/teeattestation/nitro/validate_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/smartcontractkit/chainlink-common/pkg/teeattestation/nitro/fake"
1010
)
1111

12-
func TestValidateAttestation_FakeAttestor(t *testing.T) {
13-
fa, err := fake.NewFakeAttestor()
12+
func TestValidateAttestation_Attestor(t *testing.T) {
13+
fa, err := fake.NewAttestor()
1414
require.NoError(t, err)
1515

1616
userData := teeattestation.DomainHash("test-tag", []byte(`{"key":"value"}`))
@@ -22,7 +22,7 @@ func TestValidateAttestation_FakeAttestor(t *testing.T) {
2222
}
2323

2424
func TestValidateAttestation_WrongUserData(t *testing.T) {
25-
fa, err := fake.NewFakeAttestor()
25+
fa, err := fake.NewAttestor()
2626
require.NoError(t, err)
2727

2828
userData := teeattestation.DomainHash("test-tag", []byte(`{"key":"value"}`))
@@ -36,7 +36,7 @@ func TestValidateAttestation_WrongUserData(t *testing.T) {
3636
}
3737

3838
func TestValidateAttestation_WrongPCRs(t *testing.T) {
39-
fa, err := fake.NewFakeAttestor()
39+
fa, err := fake.NewAttestor()
4040
require.NoError(t, err)
4141

4242
userData := []byte("test-data")

0 commit comments

Comments
 (0)