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 (
|
import (
|
||||||
"crypto/ecdh"
|
"crypto/ecdh"
|
||||||
@ -10,20 +10,17 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ECDH struct {
|
// session is ecdh session in oicq.
|
||||||
|
type session struct {
|
||||||
SvrPublicKeyVer uint16
|
SvrPublicKeyVer uint16
|
||||||
PublicKey []byte
|
PublicKey []byte
|
||||||
ShareKey []byte
|
ShareKey []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
type EncryptSession struct {
|
|
||||||
T133 []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
const serverPublicKey = "04EBCA94D733E399B2DB96EACDD3F69A8BB0F74224E2B44E3357812211D2E62EFBC91BB553098E25E33A799ADC7F76FEB208DA7C6522CDB0719A305180CC54A82E"
|
const serverPublicKey = "04EBCA94D733E399B2DB96EACDD3F69A8BB0F74224E2B44E3357812211D2E62EFBC91BB553098E25E33A799ADC7F76FEB208DA7C6522CDB0719A305180CC54A82E"
|
||||||
|
|
||||||
func NewECDH() *ECDH {
|
func newSession() *session {
|
||||||
e := &ECDH{
|
e := &session{
|
||||||
SvrPublicKeyVer: 1,
|
SvrPublicKeyVer: 1,
|
||||||
}
|
}
|
||||||
key, _ := hex.DecodeString(serverPublicKey)
|
key, _ := hex.DecodeString(serverPublicKey)
|
||||||
@ -38,8 +35,8 @@ type pubKeyResp struct {
|
|||||||
} `json:"PubKeyMeta"`
|
} `json:"PubKeyMeta"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchPubKey 从服务器获取PubKey
|
// fetchPubKey 从服务器获取PubKey
|
||||||
func (e *ECDH) FetchPubKey(uin int64) {
|
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))
|
resp, err := http.Get("https://keyrotate.qq.com/rotate_key?cipher_suite_ver=305&uin=" + strconv.FormatInt(uin, 10))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -55,7 +52,7 @@ func (e *ECDH) FetchPubKey(uin int64) {
|
|||||||
e.init(key) // todo check key sign
|
e.init(key) // todo check key sign
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ECDH) init(svrPubKey []byte) {
|
func (e *session) init(svrPubKey []byte) {
|
||||||
p256 := ecdh.P256()
|
p256 := ecdh.P256()
|
||||||
local, _ := p256.GenerateKey(rand.Reader)
|
local, _ := p256.GenerateKey(rand.Reader)
|
||||||
remote, _ := p256.NewPublicKey(svrPubKey)
|
remote, _ := p256.NewPublicKey(svrPubKey)
|
@ -1,17 +1,16 @@
|
|||||||
package oicq
|
package oicq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
goBinary "encoding/binary"
|
goBinary "encoding/binary"
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/Mrs4s/MiraiGo/binary"
|
"github.com/Mrs4s/MiraiGo/binary"
|
||||||
"github.com/Mrs4s/MiraiGo/internal/crypto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Codec struct {
|
type Codec struct {
|
||||||
ecdh *crypto.ECDH
|
ecdh *session
|
||||||
randomKey []byte
|
randomKey []byte
|
||||||
|
|
||||||
WtSessionTicketKey []byte
|
WtSessionTicketKey []byte
|
||||||
@ -19,11 +18,11 @@ type Codec struct {
|
|||||||
|
|
||||||
func NewCodec(uin int64) *Codec {
|
func NewCodec(uin int64) *Codec {
|
||||||
c := &Codec{
|
c := &Codec{
|
||||||
ecdh: crypto.NewECDH(),
|
ecdh: newSession(),
|
||||||
randomKey: make([]byte, 16),
|
randomKey: make([]byte, 16),
|
||||||
}
|
}
|
||||||
rand.Read(c.randomKey)
|
rand.Read(c.randomKey)
|
||||||
c.ecdh.FetchPubKey(uin)
|
c.ecdh.fetchPubKey(uin)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user