Skip to content

Commit

Permalink
upgrade lcp version
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jun 16, 2024
1 parent c7e5755 commit 6e5dfcc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 63 deletions.
103 changes: 52 additions & 51 deletions light-clients/lcp/types/lcp.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions light-clients/lcp/types/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (cs ClientState) verifyRegisterEnclaveKey(ctx sdk.Context, store storetypes
}
var operator common.Address
if len(message.OperatorSignature) > 0 {
commitment, err := ComputeEIP712RegisterEnclaveKeyHash(ctx.ChainID(), []byte(exported.StoreKey), message.Report)
commitment, err := ComputeEIP712RegisterEnclaveKeyHash(ctx.ChainID(), []byte(exported.StoreKey), string(message.Report))
if err != nil {
return errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "failed to compute commitment: %v", err)
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (cs ClientState) registerEnclaveKey(ctx sdk.Context, clientStore storetypes
}
var operator common.Address
if len(message.OperatorSignature) > 0 {
commitment, err := ComputeEIP712RegisterEnclaveKeyHash(ctx.ChainID(), []byte(exported.StoreKey), message.Report)
commitment, err := ComputeEIP712RegisterEnclaveKeyHash(ctx.ChainID(), []byte(exported.StoreKey), string(message.Report))
if err != nil {
panic(errorsmod.Wrapf(clienttypes.ErrInvalidHeader, "failed to compute commitment: %v", err))
}
Expand Down
10 changes: 5 additions & 5 deletions relay/lcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ func (pr *Prover) selectNewEnclaveKey(ctx context.Context) (*enclave.EnclaveKeyI
}

for _, eki := range res.Keys {
if err := ias.VerifyReport(eki.Report, eki.Signature, eki.SigningCert, time.Now()); err != nil {
if err := ias.VerifyReport([]byte(eki.Report), eki.Signature, eki.SigningCert, time.Now()); err != nil {
return nil, err
}
avr, err := ias.ParseAndValidateAVR(eki.Report)
avr, err := ias.ParseAndValidateAVR([]byte(eki.Report))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -320,14 +320,14 @@ func (pr *Prover) updateELC(elcClientID string, includeState bool) ([]*elc.MsgUp

func (pr *Prover) registerEnclaveKey(verifier core.Chain, eki *enclave.EnclaveKeyInfo) (core.MsgID, error) {
clientLogger := pr.getClientLogger(pr.originChain.Path().ClientID)
if err := ias.VerifyReport(eki.Report, eki.Signature, eki.SigningCert, time.Now()); err != nil {
if err := ias.VerifyReport([]byte(eki.Report), eki.Signature, eki.SigningCert, time.Now()); err != nil {
return nil, err
}
if _, err := ias.ParseAndValidateAVR(eki.Report); err != nil {
if _, err := ias.ParseAndValidateAVR([]byte(eki.Report)); err != nil {
return nil, err
}
message := &lcptypes.RegisterEnclaveKeyMessage{
Report: eki.Report,
Report: []byte(eki.Report),
Signature: eki.Signature,
SigningCert: eki.SigningCert,
OperatorSignature: nil,
Expand Down
8 changes: 4 additions & 4 deletions sgx/ias/sgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (avr AttestationVerificationReport) GetTimestamp() time.Time {
return tm.Truncate(time.Second)
}

func VerifyReport(report string, signature []byte, signingCertDer []byte, currentTime time.Time) error {
func VerifyReport(report []byte, signature []byte, signingCertDer []byte, currentTime time.Time) error {
rootCert := GetRARootCert()
signingCert, err := x509.ParseCertificate(signingCertDer)
if err != nil {
Expand All @@ -50,15 +50,15 @@ func VerifyReport(report string, signature []byte, signingCertDer []byte, curren
return fmt.Errorf("unexpected root cert: %v", chains[0][1])
}

if err = signingCert.CheckSignature(x509.SHA256WithRSA, []byte(report), signature); err != nil {
if err = signingCert.CheckSignature(x509.SHA256WithRSA, report, signature); err != nil {
return fmt.Errorf("failed to verify AVR signature: %w", err)
}

return nil
}

func ParseAndValidateAVR(report string) (*AttestationVerificationReport, error) {
avr, err := ias.UnsafeDecodeAVR([]byte(report))
func ParseAndValidateAVR(report []byte) (*AttestationVerificationReport, error) {
avr, err := ias.UnsafeDecodeAVR(report)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 6e5dfcc

Please sign in to comment.