Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added debug method to internal logger #24

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/attestation/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ const (

// Logger is a logger used to print warnings and infos during attestation validation.
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
}

// NOPLogger is a no-op implementation of [Logger].
type NOPLogger struct{}

// Debug is a no-op.
func (NOPLogger) Debug(string, ...interface{}) {}

// Info is a no-op.
func (NOPLogger) Info(string, ...interface{}) {}

Expand Down
9 changes: 0 additions & 9 deletions internal/attestation/azure/snp/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,6 @@ func (v *Validator) checkIDKeyDigest(ctx context.Context, report *spb.Attestatio
return nil
}

// nopAttestationLogger is a no-op implementation of AttestationLogger.
type nopAttestationLogger struct{}

// Infof is a no-op.
func (nopAttestationLogger) Info(string, ...interface{}) {}

// Warnf is a no-op.
func (nopAttestationLogger) Warn(string, ...interface{}) {}

MoeMahhouk marked this conversation as resolved.
Show resolved Hide resolved
type maaValidator interface {
validateToken(ctx context.Context, maaURL string, token string, extraData []byte) error
}
Expand Down
2 changes: 1 addition & 1 deletion internal/attestation/vtpm/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (v *Validator) Validate(ctx context.Context, attDocRaw []byte, nonce []byte
if err := json.Unmarshal(attDocRaw, &attDoc); err != nil {
return nil, fmt.Errorf("unmarshaling TPM attestation document: %w", err)
}
v.log.Warn(fmt.Sprintf("Attestation document: %s", string(attDocRaw)))
v.log.Debug(fmt.Sprintf("Attestation document: %s", string(attDocRaw)))

extraData := attestation.MakeExtraData(attDoc.UserData, nonce)

Expand Down
5 changes: 5 additions & 0 deletions internal/attestation/vtpm/attestation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,18 @@ func TestGetSelectedMeasurements(t *testing.T) {

type testAttestationLogger struct {
infos []string
debugs []string
warnings []string
}

func (w *testAttestationLogger) Info(format string, args ...any) {
w.infos = append(w.infos, fmt.Sprintf(format, args...))
}

func (w *testAttestationLogger) Debug(format string, args ...any) {
w.debugs = append(w.debugs, fmt.Sprintf(format, args...))
}

func (w *testAttestationLogger) Warn(format string, args ...any) {
w.warnings = append(w.warnings, fmt.Sprintf(format, args...))
}
6 changes: 5 additions & 1 deletion proxy/atls_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

"github.com/flashbots/cvm-reverse-proxy/internal/atls"
azure_tdx "github.com/flashbots/cvm-reverse-proxy/internal/attestation/azure/tdx"
dcap_tdx "github.com/flashbots/cvm-reverse-proxy/tdx"
"github.com/flashbots/cvm-reverse-proxy/internal/attestation/measurements"
"github.com/flashbots/cvm-reverse-proxy/internal/attestation/variant"
"github.com/flashbots/cvm-reverse-proxy/internal/cloud/cloudprovider"
"github.com/flashbots/cvm-reverse-proxy/internal/config"
dcap_tdx "github.com/flashbots/cvm-reverse-proxy/tdx"
)

type AttestationType string
Expand Down Expand Up @@ -120,6 +120,10 @@ func (w AttestationLogger) Info(format string, args ...any) {
w.Log.Log(context.TODO(), slog.LevelInfo, fmt.Sprintf(format, args...))
}

func (w AttestationLogger) Debug(format string, args ...any) {
w.Log.Log(context.TODO(), slog.LevelDebug, fmt.Sprintf(format, args...))
}

func (w AttestationLogger) Warn(format string, args ...any) {
w.Log.Log(context.TODO(), slog.LevelWarn, fmt.Sprintf(format, args...))
}
10 changes: 6 additions & 4 deletions proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proxy

import (
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
"encoding/hex"
Expand Down Expand Up @@ -108,12 +109,12 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
p.log.With("duration", duration).Info("[proxy-request] proxying complete")
}

func (p *Proxy) getMeasurementsFromTLS(conn *tls.ConnectionState) (atlsVariant variant.Variant, measurements map[uint32][]byte, err error) {
func GetMeasurementsFromTLS(certs []*x509.Certificate, validatorOIDs []asn1.ObjectIdentifier) (atlsVariant variant.Variant, measurements map[uint32][]byte, err error) {
// In verifyEmbeddedReport which is used to validate the extensions, only the first matching extension is validated! Refuse to accept multiple
var ATLSExtension *pkix.Extension = nil
for _, cert := range conn.PeerCertificates {
for _, cert := range certs {
for _, ext := range cert.Extensions {
for _, validatorOID := range p.validatorOIDs {
for _, validatorOID := range validatorOIDs {
if ext.Id.Equal(validatorOID) {
if ATLSExtension != nil {
return nil, nil, errors.New("more than one ATLS extension provided, refusing to continue")
Expand Down Expand Up @@ -142,7 +143,8 @@ func (p *Proxy) getMeasurementsFromTLS(conn *tls.ConnectionState) (atlsVariant v
}

func (p *Proxy) copyMeasurementsToHeader(conn *tls.ConnectionState, header *http.Header) (int, error) {
atlsVariant, extractedMeasurements, err := p.getMeasurementsFromTLS(conn)
certs := conn.PeerCertificates
atlsVariant, extractedMeasurements, err := GetMeasurementsFromTLS(certs, p.validatorOIDs)
if err != nil {
return http.StatusTeapot, err
} else if extractedMeasurements == nil {
Expand Down
Loading