Skip to content

Commit da9d29a

Browse files
authored
Added debug method to internal logger (#24)
* export GetMeasurementsFromTLS and make independent of proxy * Added debug method to internal logger
1 parent 04abe8c commit da9d29a

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

internal/attestation/attestation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ const (
4545

4646
// Logger is a logger used to print warnings and infos during attestation validation.
4747
type Logger interface {
48+
Debug(msg string, args ...any)
4849
Info(msg string, args ...any)
4950
Warn(msg string, args ...any)
5051
}
5152

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

56+
// Debug is a no-op.
57+
func (NOPLogger) Debug(string, ...interface{}) {}
58+
5559
// Info is a no-op.
5660
func (NOPLogger) Info(string, ...interface{}) {}
5761

internal/attestation/azure/snp/validator.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,6 @@ func (v *Validator) checkIDKeyDigest(ctx context.Context, report *spb.Attestatio
223223
return nil
224224
}
225225

226-
// nopAttestationLogger is a no-op implementation of AttestationLogger.
227-
type nopAttestationLogger struct{}
228-
229-
// Infof is a no-op.
230-
func (nopAttestationLogger) Info(string, ...interface{}) {}
231-
232-
// Warnf is a no-op.
233-
func (nopAttestationLogger) Warn(string, ...interface{}) {}
234-
235226
type maaValidator interface {
236227
validateToken(ctx context.Context, maaURL string, token string, extraData []byte) error
237228
}

internal/attestation/vtpm/attestation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func (v *Validator) Validate(ctx context.Context, attDocRaw []byte, nonce []byte
224224
if err := json.Unmarshal(attDocRaw, &attDoc); err != nil {
225225
return nil, fmt.Errorf("unmarshaling TPM attestation document: %w", err)
226226
}
227-
v.log.Warn(fmt.Sprintf("Attestation document: %s", string(attDocRaw)))
227+
v.log.Debug(fmt.Sprintf("Attestation document: %s", string(attDocRaw)))
228228

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

internal/attestation/vtpm/attestation_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,18 @@ func TestGetSelectedMeasurements(t *testing.T) {
478478

479479
type testAttestationLogger struct {
480480
infos []string
481+
debugs []string
481482
warnings []string
482483
}
483484

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

489+
func (w *testAttestationLogger) Debug(format string, args ...any) {
490+
w.debugs = append(w.debugs, fmt.Sprintf(format, args...))
491+
}
492+
488493
func (w *testAttestationLogger) Warn(format string, args ...any) {
489494
w.warnings = append(w.warnings, fmt.Sprintf(format, args...))
490495
}

proxy/atls_config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ func (w AttestationLogger) Info(format string, args ...any) {
120120
w.Log.Log(context.TODO(), slog.LevelInfo, fmt.Sprintf(format, args...))
121121
}
122122

123+
func (w AttestationLogger) Debug(format string, args ...any) {
124+
w.Log.Log(context.TODO(), slog.LevelDebug, fmt.Sprintf(format, args...))
125+
}
126+
123127
func (w AttestationLogger) Warn(format string, args ...any) {
124128
w.Log.Log(context.TODO(), slog.LevelWarn, fmt.Sprintf(format, args...))
125129
}

0 commit comments

Comments
 (0)