Skip to content

Commit

Permalink
Take into account nil fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
NullHypothesis committed Oct 27, 2024
1 parent cfcf46b commit 54c9591
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions internal/enclave/attester_nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/Amnesic-Systems/veil/internal/errs"
"github.com/Amnesic-Systems/veil/internal/nonce"
"github.com/Amnesic-Systems/veil/internal/util"

"github.com/hf/nitrite"
"github.com/hf/nsm"
Expand All @@ -28,6 +27,26 @@ func (*NitroAttester) Type() string {
return typeNitro
}

// convertTo converts our representation of an auxiliary field to the nsm
// package's representation.
func convertTo(auxField *[AuxFieldLen]byte) []byte {
if auxField == nil {
return nil
}
return auxField[:]
}

// convertFrom converts the nsm package's representation of an auxiliary field
// to our representation.
func convertFrom(auxField []byte) *[AuxFieldLen]byte {
if auxField == nil {
return nil
}
var res [AuxFieldLen]byte
copy(res[:], auxField)
return &res
}

func (a *NitroAttester) Attest(aux *AuxInfo) (_ *AttestationDoc, err error) {
defer errs.Wrap(&err, "failed to create attestation document")

Expand All @@ -43,9 +62,9 @@ func (a *NitroAttester) Attest(aux *AuxInfo) (_ *AttestationDoc, err error) {
}

req := &request.Attestation{
Nonce: aux.Nonce[:],
UserData: aux.UserData[:],
PublicKey: aux.PublicKey[:],
Nonce: convertTo(aux.Nonce),
UserData: convertTo(aux.UserData),
PublicKey: convertTo(aux.PublicKey),
}
resp, err := a.session.Send(req)
if err != nil {
Expand Down Expand Up @@ -89,8 +108,8 @@ func (a *NitroAttester) Verify(doc *AttestationDoc, ourNonce *nonce.Nonce) (_ *A
}

return &AuxInfo{
Nonce: util.AddrOf([AuxFieldLen]byte(res.Document.Nonce)),
UserData: util.AddrOf([AuxFieldLen]byte(res.Document.UserData)),
PublicKey: util.AddrOf([AuxFieldLen]byte(res.Document.PublicKey)),
Nonce: convertFrom(res.Document.Nonce),
UserData: convertFrom(res.Document.UserData),
PublicKey: convertFrom(res.Document.PublicKey),
}, nil
}

0 comments on commit 54c9591

Please sign in to comment.