From 7624268b9304337494405c89efda50036e221086 Mon Sep 17 00:00:00 2001 From: xmdhs Date: Wed, 13 Sep 2023 23:37:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E9=AB=98=E5=AF=B9=E7=AC=AC=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E5=90=AF=E5=8A=A8=E5=99=A8=E7=9A=84=E5=85=BC=E5=AE=B9?= =?UTF-8?q?=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/yggdrasil/model.go | 7 ++--- model/yggdrasil/textures.go | 2 +- server/route/route.go | 1 + service/yggdrasil/user.go | 51 +++++++++++++++++++++---------------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/model/yggdrasil/model.go b/model/yggdrasil/model.go index a2fcf39..5f86486 100644 --- a/model/yggdrasil/model.go +++ b/model/yggdrasil/model.go @@ -7,10 +7,6 @@ type Pass struct { } type Authenticate struct { - Agent struct { - Name string `json:"name" validate:"required,eq=Minecraft"` - Version int `json:"version" validate:"required,eq=1"` - } `json:"agent"` ClientToken string `json:"clientToken"` RequestUser bool `json:"requestUser"` Pass @@ -23,7 +19,8 @@ type Error struct { } type TokenUserID struct { - ID string `json:"id"` + ID string `json:"id"` + Properties []any `json:"properties,omitempty"` } type Token struct { diff --git a/model/yggdrasil/textures.go b/model/yggdrasil/textures.go index d37c548..fe04f1d 100644 --- a/model/yggdrasil/textures.go +++ b/model/yggdrasil/textures.go @@ -11,7 +11,7 @@ type UserTextures struct { ProfileName string `json:"profileName"` Textures map[string]Textures `json:"textures"` // 时间戳 毫秒 - Timestamp string `json:"timestamp"` + Timestamp int64 `json:"timestamp"` } type Textures struct { diff --git a/server/route/route.go b/server/route/route.go index 66744d5..69b4de1 100644 --- a/server/route/route.go +++ b/server/route/route.go @@ -40,6 +40,7 @@ func newYggdrasil(r *httprouter.Router, handelY yggdrasil.Yggdrasil) error { r.POST("/api/yggdrasil/minecraftservices/player/certificates", warpHJSON(handelY.PlayerCertificates())) r.GET("/api/yggdrasil", warpHJSON(handelY.YggdrasilRoot())) + r.GET("/api/yggdrasil/", warpHJSON(handelY.YggdrasilRoot())) r.GET("/texture/*filepath", handelY.TextureAssets()) return nil diff --git a/service/yggdrasil/user.go b/service/yggdrasil/user.go index 34af0a4..dc0dd00 100644 --- a/service/yggdrasil/user.go +++ b/service/yggdrasil/user.go @@ -104,7 +104,8 @@ func (y *Yggdrasil) Authenticate(cxt context.Context, auth yggdrasil.Authenticat ClientToken: clientToken, SelectedProfile: p, User: yggdrasil.TokenUserID{ - ID: utils.UUIDGen(strconv.Itoa(u.ID)), + ID: utils.UUIDGen(strconv.Itoa(u.ID)), + Properties: []any{}, }, }, nil } @@ -171,16 +172,16 @@ func (y *Yggdrasil) Refresh(ctx context.Context, token yggdrasil.RefreshToken) ( if err != nil { return yggdrasil.Token{}, fmt.Errorf("Authenticate: %w", err) } + u := yggdrasil.UserInfo{ID: up.UUID, Name: up.Name} return yggdrasil.Token{ - AccessToken: jwts, - ClientToken: t.CID, - SelectedProfile: yggdrasil.UserInfo{ - ID: up.UUID, - Name: up.Name, - }, + AccessToken: jwts, + AvailableProfiles: []yggdrasil.UserInfo{u}, + ClientToken: t.CID, + SelectedProfile: u, User: yggdrasil.TokenUserID{ - ID: utils.UUIDGen(strconv.Itoa(t.UID)), + ID: utils.UUIDGen(strconv.Itoa(t.UID)), + Properties: []any{}, }, }, nil } @@ -209,7 +210,7 @@ func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool, ProfileID: up.UUID, ProfileName: up.Name, Textures: map[string]yggdrasil.Textures{}, - Timestamp: strconv.FormatInt(time.Now().UnixMilli(), 10), + Timestamp: time.Now().UnixMilli(), } for _, v := range up.Edges.Usertexture { @@ -230,25 +231,31 @@ func (y *Yggdrasil) GetProfile(ctx context.Context, uuid string, unsigned bool, texturesBase64 := ut.Base64() - var signStr string + pl := []yggdrasil.UserProperties{} + pl = append(pl, yggdrasil.UserProperties{ + Name: "textures", + Value: texturesBase64, + }) + pl = append(pl, yggdrasil.UserProperties{ + Name: "uploadableTextures", + Value: "skin,cape", + }) + if !unsigned { s := sign.NewAuthlibSignWithKey(y.prikey) - signStr, err = s.Sign([]byte(texturesBase64)) - if err != nil { - return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", err) + for i, v := range pl { + sign, err := s.Sign([]byte(v.Signature)) + if err != nil { + return yggdrasil.UserInfo{}, fmt.Errorf("GetProfile: %w", ErrNotUser) + } + pl[i].Signature = sign } } uinfo := yggdrasil.UserInfo{ - ID: up.UUID, - Name: up.Name, - Properties: []yggdrasil.UserProperties{ - { - Name: "textures", - Value: texturesBase64, - Signature: signStr, - }, - }, + ID: up.UUID, + Name: up.Name, + Properties: pl, } return uinfo, nil