Skip to content

Commit

Permalink
format certificate as pem
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead committed Oct 16, 2023
1 parent 9d3b821 commit f515924
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
31 changes: 23 additions & 8 deletions cli/internal/cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,18 +738,33 @@ func newCertificates(certTypeName string, cert []byte, log debugLog) (certs []ve
if err != nil {
return certs, fmt.Errorf("parsing VCEK certificate extensions: %w", err)
}
block := &pem.Block{
Type: "CERTIFICATE",
Bytes: cert.Raw,
}

var buf bytes.Buffer
err = pem.Encode(&buf, block)
if err != nil {
return certs, fmt.Errorf("encoding PEM block: %w", err)
}
certs = append(certs, verify.Certificate{
Certificate: cert,
CertTypeName: certTypeName,
StructVersion: vcekExts.StructVersion,
ProductName: vcekExts.ProductName,
TCBVersion: newTCBVersion(vcekExts.TCBVersion),
HardwareID: vcekExts.HWID,
CertificatePEM: buf.String(),
CertTypeName: certTypeName,
StructVersion: vcekExts.StructVersion,
ProductName: vcekExts.ProductName,
TCBVersion: newTCBVersion(vcekExts.TCBVersion),
HardwareID: vcekExts.HWID,
})
} else {
var buf bytes.Buffer
err = pem.Encode(&buf, block)
if err != nil {
return certs, fmt.Errorf("encoding PEM block: %w", err)
}
certs = append(certs, verify.Certificate{
Certificate: cert,
CertTypeName: certTypeName,
CertificatePEM: buf.String(),
CertTypeName: certTypeName,
})
}
i++
Expand Down
14 changes: 6 additions & 8 deletions internal/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ the attestationconfigapi upload tool through JSON serialization.
package verify

import (
"crypto/x509"

"github.com/golang-jwt/jwt/v5"
)

Expand All @@ -28,12 +26,12 @@ type Report struct {

// Certificate contains the certificate data and additional information.
type Certificate struct {
*x509.Certificate `json:"certificate"`
CertTypeName string `json:"cert_type_name"`
StructVersion uint8 `json:"struct_version"`
ProductName string `json:"product_name"`
HardwareID []byte `json:"hardware_id"`
TCBVersion TCBVersion `json:"tcb_version"`
CertificatePEM string `json:"certificate"`
CertTypeName string `json:"cert_type_name"`
StructVersion uint8 `json:"struct_version"`
ProductName string `json:"product_name"`
HardwareID []byte `json:"hardware_id"`
TCBVersion TCBVersion `json:"tcb_version"`
}

// TCBVersion contains the TCB version data.
Expand Down

0 comments on commit f515924

Please sign in to comment.