mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 08:44:01 +03:00
Proxy is working in a simple mode now
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"io"
|
||||
)
|
||||
|
||||
type serverHandshakeFrame struct {
|
||||
@@ -13,17 +13,16 @@ type serverHandshakeFrame struct {
|
||||
}
|
||||
|
||||
func (s *serverHandshakeFrame) decryptor() cipher.Stream {
|
||||
return makeAesCtr(s.key(), s.iv())
|
||||
invertedHandshake := s.invert()
|
||||
|
||||
return makeAesCtr(invertedHandshake.key(), invertedHandshake.iv())
|
||||
}
|
||||
|
||||
func (s *serverHandshakeFrame) encryptor() cipher.Stream {
|
||||
arr := serverHandshakeFrame{}
|
||||
invertByteSlices(arr.data[:], s.data[:])
|
||||
|
||||
return makeAesCtr(arr.key(), arr.iv())
|
||||
return makeAesCtr(s.key(), s.iv())
|
||||
}
|
||||
|
||||
func ServerHandshake(conn net.Conn) (cipher.Stream, cipher.Stream, error) {
|
||||
func ServerHandshake(writer io.Writer) (cipher.Stream, cipher.Stream, error) {
|
||||
handshake := generateServerHanshakeFrame()
|
||||
copyHandshake := handshake
|
||||
encryptor := handshake.encryptor()
|
||||
@@ -33,7 +32,7 @@ func ServerHandshake(conn net.Conn) (cipher.Stream, cipher.Stream, error) {
|
||||
copy(handshake.key(), copyHandshake.key())
|
||||
copy(handshake.iv(), copyHandshake.iv())
|
||||
|
||||
if _, err := conn.Write(handshake.data[:]); err != nil {
|
||||
if _, err := writer.Write(handshake.data[:]); err != nil {
|
||||
return nil, nil, fmt.Errorf("cannot send a handshake frame to telegram: %w", err)
|
||||
}
|
||||
|
||||
@@ -48,16 +47,16 @@ func generateServerHanshakeFrame() serverHandshakeFrame {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if frame.data[0] == 0xef {
|
||||
if frame.data[0] == 0xef { // nolint: gomnd // taken from tg sources
|
||||
continue
|
||||
}
|
||||
|
||||
switch binary.LittleEndian.Uint32(frame.data[:4]) {
|
||||
case 0x44414548, 0x54534f50, 0x20544547, 0x4954504f, 0xeeeeeeee:
|
||||
case 0x44414548, 0x54534f50, 0x20544547, 0x4954504f, 0xeeeeeeee: // nolint: gomnd // taken from tg sources
|
||||
continue
|
||||
}
|
||||
|
||||
if (frame.data[4] | frame.data[5] | frame.data[6] | frame.data[7]) == 0 {
|
||||
if frame.data[4]|frame.data[5]|frame.data[6]|frame.data[7] == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user