Skip to content

Commit

Permalink
fix(coordinator): add compatible logic to jwt when curie prover not a…
Browse files Browse the repository at this point in the history
…dding public_key in login request (#1472)

Co-authored-by: amoylan2 <[email protected]>
  • Loading branch information
amoylan2 and amoylan2 authored Aug 6, 2024
1 parent cce5c6c commit 073e9e8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.4.39"
var tag = "v4.4.40"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
14 changes: 13 additions & 1 deletion coordinator/internal/controller/api/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"github.com/scroll-tech/go-ethereum/log"
"gorm.io/gorm"

"scroll-tech/coordinator/internal/config"
Expand Down Expand Up @@ -58,8 +59,19 @@ func (a *AuthController) PayloadFunc(data interface{}) jwt.MapClaims {
return jwt.MapClaims{}
}

publicKey := v.PublicKey
if publicKey == "" {
var err error
publicKey, err = v.RecoverPublicKeyFromSignature()
if err != nil {
// do not handle error here since already called v.Verify() beforehands so there should be no error
// add log just in case some error happens
log.Error("impossible path: failed to recover public key from signature", "error", err.Error())
}
}

return jwt.MapClaims{
types.PublicKey: v.PublicKey,
types.PublicKey: publicKey,
types.ProverName: v.Message.ProverName,
types.ProverVersion: v.Message.ProverVersion,
}
Expand Down
16 changes: 16 additions & 0 deletions coordinator/internal/types/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ func (a *LoginParameter) Verify() (bool, error) {
return isValid, nil
}

// RecoverPublicKeyFromSignature get public key from signature.
// This method is for pre-darwin's compatible.
func (a *LoginParameter) RecoverPublicKeyFromSignature() (string, error) {
hash, err := a.Message.Hash()
if err != nil {
return "", err
}
sig := common.FromHex(a.Signature)
// recover public key
pk, err := crypto.SigToPub(hash, sig)
if err != nil {
return "", err
}
return common.Bytes2Hex(crypto.CompressPubkey(pk)), nil
}

// Hash returns the hash of the auth message, which should be the message used
// to construct the Signature.
func (i *Message) Hash() ([]byte, error) {
Expand Down

0 comments on commit 073e9e8

Please sign in to comment.