Skip to content

Commit

Permalink
issuer: use slog
Browse files Browse the repository at this point in the history
  • Loading branch information
malt3 committed Dec 20, 2023
1 parent 1d68e9d commit 1ea799c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion coordinator/coordapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"log"
"log/slog"
"net"
"sync"
"time"
Expand All @@ -29,7 +30,8 @@ type coordAPIServer struct {
}

func newCoordAPIServer(mSetter manifestSetter, caGetter certChainGetter) (*coordAPIServer, error) {
issuer := snp.NewIssuer()
// TODO(malt3): pass logger down.
issuer := snp.NewIssuer(slog.Default())
credentials := atlscredentials.New(issuer, nil)
grpcServer := grpc.NewServer(
grpc.Creds(credentials),
Expand Down
2 changes: 1 addition & 1 deletion initializer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func run() (retErr error) {
logger.Info("Deriving public key", "pubKeyHash", pubKeyHashStr)

requestCert := func() (*intercom.NewMeshCertResponse, error) {
dial := dialer.NewWithKey(snp.NewIssuer(), atls.NoValidator, &net.Dialer{}, privKey)
dial := dialer.NewWithKey(snp.NewIssuer(logger), atls.NoValidator, &net.Dialer{}, privKey)
conn, err := dial.Dial(ctx, net.JoinHostPort(coordinatorHostname, intercom.Port))
if err != nil {
return nil, fmt.Errorf("dialing: %w", err)
Expand Down
19 changes: 10 additions & 9 deletions internal/attestation/snp/issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
"log"
"log/slog"

"github.com/google/go-sev-guest/client"
)

type Issuer struct {
snpDevicePath string
logger *slog.Logger
}

// NewIssuer returns a new Issuer.
func NewIssuer() *Issuer {
return &Issuer{}
func NewIssuer(log *slog.Logger) *Issuer {
return &Issuer{logger: log.WithGroup("snp-issuer")}
}

func (i *Issuer) OID() asn1.ObjectIdentifier {
Expand All @@ -33,30 +34,30 @@ func (i *Issuer) OID() asn1.ObjectIdentifier {
// userData is hash of issuer public key.
// nonce from validator.
func (i *Issuer) Issue(ctx context.Context, ownPublicKey []byte, nonce []byte) (res []byte, err error) {
log.Println("issuer: issue called")
i.logger.Info("Issue called")
defer func() {
if err != nil {
log.Printf("Failed to issue attestation statement: %s", err)
i.logger.Error("Failed to issue attestation statement", "err", err)
}
}()

snpGuestDevice, err := client.OpenDevice()
if err != nil {
log.Fatalf("issuer: opening device: %v", err)
return nil, fmt.Errorf("issuer: opening device: %w", err)
}
defer snpGuestDevice.Close()

reportData := constructReportData(ownPublicKey, nonce)

reportRaw, err := client.GetRawReport(snpGuestDevice, reportData)
if err != nil {
return nil, fmt.Errorf("getting raw report: %w", err)
return nil, fmt.Errorf("issuer: getting raw report: %w", err)
}
log.Printf("issuer: Report raw: %v", hex.EncodeToString(reportRaw))
i.logger.Info("Retrieved report", "reportRaw", hex.EncodeToString(reportRaw))

reportB64 := make([]byte, base64.StdEncoding.EncodedLen(len(reportRaw)))
base64.StdEncoding.Encode(reportB64, reportRaw)

log.Println("issuer: Successfully issued attestation statement")
i.logger.Info("Successfully issued attestation statement")
return reportB64, nil
}

0 comments on commit 1ea799c

Please sign in to comment.