mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 18:34:02 +03:00
Correct encryptor/decryptor
This commit is contained in:
@@ -25,14 +25,14 @@ var emptyIP = [4]byte{0x00, 0x00, 0x00, 0x00}
|
|||||||
func NewMiddleProxyCipherRWC(conn wrappers.ReadWriteCloserWithAddr, req *rpc.RPCNonceRequest,
|
func NewMiddleProxyCipherRWC(conn wrappers.ReadWriteCloserWithAddr, req *rpc.RPCNonceRequest,
|
||||||
resp *rpc.RPCNonceResponse, client *net.TCPAddr, secret []byte) wrappers.ReadWriteCloserWithAddr {
|
resp *rpc.RPCNonceResponse, client *net.TCPAddr, secret []byte) wrappers.ReadWriteCloserWithAddr {
|
||||||
remote := conn.Addr()
|
remote := conn.Addr()
|
||||||
encryptor := newCBCCipher(CipherPurposeClient, req, resp, client, remote, secret)
|
encryptor, _ := newCBCCipher(CipherPurposeClient, req, resp, client, remote, secret)
|
||||||
decryptor := newCBCCipher(CipherPurposeServer, req, resp, client, remote, secret)
|
_, decryptor := newCBCCipher(CipherPurposeServer, req, resp, client, remote, secret)
|
||||||
|
|
||||||
return wrappers.NewBlockCipherRWC(conn, encryptor, decryptor)
|
return wrappers.NewBlockCipherRWC(conn, encryptor, decryptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCBCCipher(purpose CipherPurpose, req *rpc.RPCNonceRequest, resp *rpc.RPCNonceResponse,
|
func newCBCCipher(purpose CipherPurpose, req *rpc.RPCNonceRequest, resp *rpc.RPCNonceResponse,
|
||||||
client *net.TCPAddr, remote *net.TCPAddr, secret []byte) cipher.BlockMode {
|
client *net.TCPAddr, remote *net.TCPAddr, secret []byte) (cipher.BlockMode, cipher.BlockMode) {
|
||||||
message := bytes.Buffer{}
|
message := bytes.Buffer{}
|
||||||
message.Write(resp.Nonce[:])
|
message.Write(resp.Nonce[:])
|
||||||
message.Write(req.Nonce[:])
|
message.Write(req.Nonce[:])
|
||||||
@@ -74,7 +74,7 @@ func newCBCCipher(purpose CipherPurpose, req *rpc.RPCNonceRequest, resp *rpc.RPC
|
|||||||
return makeCipher(message.Bytes())
|
return makeCipher(message.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCipher(message []byte) cipher.BlockMode {
|
func makeCipher(message []byte) (cipher.BlockMode, cipher.BlockMode) {
|
||||||
md5sum := md5.Sum(message[1:])
|
md5sum := md5.Sum(message[1:])
|
||||||
sha1sum := sha1.Sum(message)
|
sha1sum := sha1.Sum(message)
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ func makeCipher(message []byte) cipher.BlockMode {
|
|||||||
panic("Cannot create cipher from the given key")
|
panic("Cannot create cipher from the given key")
|
||||||
}
|
}
|
||||||
|
|
||||||
return cipher.NewCBCEncrypter(block, iv[:])
|
return cipher.NewCBCEncrypter(block, iv[:]), cipher.NewCBCDecrypter(block, iv[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func reverseBytes(data []byte) []byte {
|
func reverseBytes(data []byte) []byte {
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ func (t *middleTelegram) Init(connOpts *mtproto.ConnectionOpts, conn wrappers.Re
|
|||||||
}
|
}
|
||||||
|
|
||||||
secureConn := mtwrappers.NewFrameRWC(conn, rpc.RPCHandshakeSeqNo)
|
secureConn := mtwrappers.NewFrameRWC(conn, rpc.RPCHandshakeSeqNo)
|
||||||
secureConn = mtwrappers.NewMiddleProxyCipherRWC(conn, rpcNonceReq,
|
secureConn = mtwrappers.NewMiddleProxyCipherRWC(secureConn, rpcNonceReq,
|
||||||
rpcNonceResp, connOpts.ClientAddr, t.proxySecret)
|
rpcNonceResp, connOpts.ClientAddr, t.proxySecret)
|
||||||
|
|
||||||
rpcHandshakeReq, err := t.sendRPCHandshakeRequest(secureConn)
|
rpcHandshakeReq, err := t.sendRPCHandshakeRequest(secureConn)
|
||||||
|
|||||||
Reference in New Issue
Block a user