mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
internal/crypto: move to client/internal/oicq
This commit is contained in:
parent
94b761717e
commit
1a7fcd76cf
@ -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)
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user