diff --git a/internal/crypto/crypto.go b/client/internal/oicq/ecdh.go similarity index 83% rename from internal/crypto/crypto.go rename to client/internal/oicq/ecdh.go index 4ce94ed0..492400a5 100644 --- a/internal/crypto/crypto.go +++ b/client/internal/oicq/ecdh.go @@ -1,4 +1,4 @@ -package crypto +package oicq import ( "crypto/ecdh" @@ -10,20 +10,17 @@ import ( "strconv" ) -type ECDH struct { +// session is ecdh session in oicq. +type session struct { SvrPublicKeyVer uint16 PublicKey []byte ShareKey []byte } -type EncryptSession struct { - T133 []byte -} - const serverPublicKey = "04EBCA94D733E399B2DB96EACDD3F69A8BB0F74224E2B44E3357812211D2E62EFBC91BB553098E25E33A799ADC7F76FEB208DA7C6522CDB0719A305180CC54A82E" -func NewECDH() *ECDH { - e := &ECDH{ +func newSession() *session { + e := &session{ SvrPublicKeyVer: 1, } key, _ := hex.DecodeString(serverPublicKey) @@ -38,8 +35,8 @@ type pubKeyResp struct { } `json:"PubKeyMeta"` } -// FetchPubKey 从服务器获取PubKey -func (e *ECDH) FetchPubKey(uin int64) { +// fetchPubKey 从服务器获取PubKey +func (e *session) fetchPubKey(uin int64) { resp, err := http.Get("https://keyrotate.qq.com/rotate_key?cipher_suite_ver=305&uin=" + strconv.FormatInt(uin, 10)) if err != nil { return @@ -55,7 +52,7 @@ func (e *ECDH) FetchPubKey(uin int64) { e.init(key) // todo check key sign } -func (e *ECDH) init(svrPubKey []byte) { +func (e *session) init(svrPubKey []byte) { p256 := ecdh.P256() local, _ := p256.GenerateKey(rand.Reader) remote, _ := p256.NewPublicKey(svrPubKey) diff --git a/client/internal/oicq/oicq.go b/client/internal/oicq/oicq.go index a08dde78..c684108a 100644 --- a/client/internal/oicq/oicq.go +++ b/client/internal/oicq/oicq.go @@ -1,17 +1,16 @@ package oicq import ( + "crypto/rand" goBinary "encoding/binary" - "math/rand" "github.com/pkg/errors" "github.com/Mrs4s/MiraiGo/binary" - "github.com/Mrs4s/MiraiGo/internal/crypto" ) type Codec struct { - ecdh *crypto.ECDH + ecdh *session randomKey []byte WtSessionTicketKey []byte @@ -19,11 +18,11 @@ type Codec struct { func NewCodec(uin int64) *Codec { c := &Codec{ - ecdh: crypto.NewECDH(), + ecdh: newSession(), randomKey: make([]byte, 16), } rand.Read(c.randomKey) - c.ecdh.FetchPubKey(uin) + c.ecdh.fetchPubKey(uin) return c }