Skip to content

Commit 35f22b4

Browse files
committed
fix: login verify
1 parent aae19ab commit 35f22b4

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

coordinator/internal/types/auth.go

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ type LoginSchema struct {
3030
Token string `json:"token"`
3131
}
3232

33+
type MessageWithoutProverProviderType struct {
34+
Challenge string `json:"challenge"`
35+
ProverVersion string `json:"prover_version"`
36+
ProverName string `json:"prover_name"`
37+
ProverTypes []ProverType `json:"prover_types"`
38+
VKs []string `json:"vks"`
39+
}
40+
3341
// Message the login message struct
3442
type Message struct {
3543
Challenge string `form:"challenge" json:"challenge" binding:"required"`
@@ -56,7 +64,7 @@ type LoginParameter struct {
5664
// SignWithKey auth message with private key and set public key in auth message's Identity
5765
func (a *LoginParameter) SignWithKey(priv *ecdsa.PrivateKey) error {
5866
// Hash identity content
59-
hash, err := a.Message.Hash()
67+
hash, err := Hash(a.Message)
6068
if err != nil {
6169
return err
6270
}
@@ -73,7 +81,14 @@ func (a *LoginParameter) SignWithKey(priv *ecdsa.PrivateKey) error {
7381

7482
// Verify verifies the message of auth.
7583
func (a *LoginParameter) Verify() (bool, error) {
76-
hash, err := a.Message.Hash()
84+
var hash []byte
85+
var err error
86+
if a.Message.ProverProviderType == ProverProviderTypeUndefined {
87+
// for backward compatibility, calculate hash without ProverProviderType
88+
hash, err = Hash(a.Message.ToMessageWithoutProverProviderType())
89+
} else {
90+
hash, err = Hash(a.Message)
91+
}
7792
if err != nil {
7893
return false, err
7994
}
@@ -88,15 +103,14 @@ func (a *LoginParameter) Verify() (bool, error) {
88103
return isValid, nil
89104
}
90105

91-
// Hash returns the hash of the auth message, which should be the message used
92-
// to construct the Signature.
93-
func (i *Message) Hash() ([]byte, error) {
94-
byt, err := rlp.EncodeToBytes(i)
95-
if err != nil {
96-
return nil, err
106+
func (m *Message) ToMessageWithoutProverProviderType() MessageWithoutProverProviderType {
107+
return MessageWithoutProverProviderType{
108+
Challenge: m.Challenge,
109+
ProverVersion: m.ProverVersion,
110+
ProverName: m.ProverName,
111+
ProverTypes: m.ProverTypes,
112+
VKs: m.VKs,
97113
}
98-
hash := crypto.Keccak256Hash(byt)
99-
return hash[:], nil
100114
}
101115

102116
// DecodeAndUnmarshalPubkey decodes a hex-encoded public key and unmarshal it into an ecdsa.PublicKey
@@ -114,3 +128,14 @@ func (i *Message) DecodeAndUnmarshalPubkey(pubKeyHex string) (*ecdsa.PublicKey,
114128
}
115129
return pubKey, nil
116130
}
131+
132+
// Hash returns the hash of the auth message, which should be the message used
133+
// to construct the Signature.
134+
func Hash(i interface{}) ([]byte, error) {
135+
byt, err := rlp.EncodeToBytes(i)
136+
if err != nil {
137+
return nil, err
138+
}
139+
hash := crypto.Keccak256Hash(byt)
140+
return hash[:], nil
141+
}

go.work.sum

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,6 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
448448
github.com/Shopify/goreferrer v0.0.0-20220729165902-8cddb4f5de06/go.mod h1:7erjKLwalezA0k99cWs5L11HWOAPNjdUZ6RxH1BXbbM=
449449
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
450450
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
451-
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=
452-
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
453451
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794/go.mod h1:7e+I0LQFUI9AXWxOfsQROs9xPhoJtbsyWcjJqDd4KPY=
454452
github.com/aead/siphash v1.0.1 h1:FwHfE/T45KPKYuuSAKyyvE+oPWcaQ+CUmFW0bPlM+kg=
455453
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
@@ -862,6 +860,7 @@ github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
862860
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
863861
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
864862
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
863+
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
865864
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
866865
github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI=
867866
github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE=
@@ -1142,8 +1141,6 @@ github.com/scroll-tech/da-codec v0.1.1-0.20241014152913-2703f226fb0b/go.mod h1:4
11421141
github.com/scroll-tech/go-ethereum v1.10.14-0.20240607130425-e2becce6a1a4/go.mod h1:byf/mZ8jLYUCnUePTicjJWn+RvKdxDn7buS6glTnMwQ=
11431142
github.com/scroll-tech/go-ethereum v1.10.14-0.20240821074444-b3fa00861e5e/go.mod h1:swB5NSp8pKNDuYsTxfR08bHS6L56i119PBx8fxvV8Cs=
11441143
github.com/scroll-tech/go-ethereum v1.10.14-0.20241010064814-3d88e870ae22/go.mod h1:r9FwtxCtybMkTbWYCyBuevT9TW3zHmOTHqD082Uh+Oo=
1145-
github.com/scroll-tech/go-ethereum v1.10.14-0.20241023093931-91c2f9c27f4d h1:vuv7fGKEDtoeetI6RkKt8RAByJsYZBWk9Vo6gShv65c=
1146-
github.com/scroll-tech/go-ethereum v1.10.14-0.20241023093931-91c2f9c27f4d/go.mod h1:PWEOTg6LeWlJAlFJauO0msSLXWnpHmE+mVh5txtfeRM=
11471144
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
11481145
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
11491146
github.com/segmentio/kafka-go v0.2.0 h1:HtCSf6B4gN/87yc5qTl7WsxPKQIIGXLPPM1bMCPOsoY=
@@ -1439,7 +1436,6 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14391436
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14401437
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14411438
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1442-
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14431439
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14441440
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
14451441
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 commit comments

Comments
 (0)