tgcrypt

package
v0.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Generate init packet

Index

Constants

View Source
const (
	FlagNotEncrypted uint32 = 0x02
	FlagHasAdTag     uint32 = 0x8
	FlagMagic        uint32 = 0x1000
	FlagExtNode2     uint32 = 0x20000
	FlagPad          uint32 = 0x8000000
	FlagIntermediate uint32 = 0x20000000
	FlagAbbridged    uint32 = 0x40000000
	FlagQuickAck     uint32 = 0x80000000
)
View Source
const (
	Abridged     = 0xef
	Intermediate = 0xee //0xeeeeeeee
	Padded       = 0xdd //0xdddddddd
	Full         = 0
)
View Source
const AddTagLength = 16
View Source
const FakeTlsHandshakeLen = 1 + 2 + 2 + 512 // handshake version payload_length payload
View Source
const MaxPayloadSize = 1024 * 1024 // 131200 // supposed to be 1<<17-1 but i've 131176 in abridged and more in padded
View Source
const NonceSize = 64
View Source
const RpcNonceLen = 16

Variables

View Source
var (
	RpcNonceTag     = [4]byte{0xaa, 0x87, 0xcb, 0x7a}
	RpcCryptoAesTag = [4]byte{0x01, 0, 0, 0}
	RpcHandShakeTag = [4]byte{0xf5, 0xee, 0x82, 0x76}
	RpcProxyAnsTag  = [4]byte{0x0d, 0xda, 0x03, 0x44}
	RpcCloseExtTag  = [4]byte{0xa2, 0x34, 0xb6, 0x5e}
	RpcSimpleAckTag = [4]byte{0x9b, 0x40, 0xac, 0x3b}
	RpcUnknown      = [4]byte{0xdf, 0xa2, 0x30, 0x57}
	RpcProxyReqTag  = [4]byte{0xee, 0xf1, 0xce, 0x36}
	ProxyTag        = [4]byte{0xae, 0x26, 0x1e, 0xdb}
	ExtraSize       = [4]byte{0x18, 0x00, 0x00, 0x00}
	PaddingFiller   = [4]byte{0x4, 0, 0, 0}
)
View Source
var FakeTlsHeader = [...]byte{
	0x16,
	0x03,
	0x01,
	0x02,
	0x00,
	0x01,
	0x00,
	0x01,
	0xfc,
	0x03,
	0x03}
View Source
var WrongNonceStarters = [...][]byte{
	{0xef},
	{0x48, 0x45, 0x41, 0x44},
	{0x50, 0x4f, 0x53, 0x54},
	{0x47, 0x45, 0x54, 0x20},
	{0x4f, 0x50, 0x54, 0x49},
	{0x16, 0x03, 0x01, 0x02},
	{0xdd, 0xdd, 0xdd, 0xdd},
	{0xee, 0xee, 0xee, 0xee},
}

Functions

func IsWrongNonce

func IsWrongNonce(nonce Nonce) bool

Check if nonce is correct. Usefull for clients validation

Types

type DcCtx

type DcCtx struct {
	Nonce    Nonce
	Protocol uint8
	// contains filtered or unexported fields
}

Context for obfuscation proxy-DC connection

func DcCtxNew

func DcCtxNew(dc int16, protocol byte) (c *DcCtx)

func (*DcCtx) DecryptNext

func (c *DcCtx) DecryptNext(buf []byte)

func (*DcCtx) EncryptNext

func (c *DcCtx) EncryptNext(buf []byte)

type FakeTlsCtx

type FakeTlsCtx struct {
	Header    FakeTlsHandshake
	Digest    [32]byte
	Timestamp uint32
	Secret    *Secret
}

func FakeTlsCtxFromTlsHeader

func FakeTlsCtxFromTlsHeader(header FakeTlsHandshake, secret *Secret) (c *FakeTlsCtx, err error)

Checks handshake bytes against user secret (does not check timestamp) Returb faketls context in case os success.

type FakeTlsHandshake added in v0.7.1

type FakeTlsHandshake = [FakeTlsHandshakeLen]byte

FakeTlsHandshake is a set of bytes client supposed to send for initiate faketls connection.

type MiddleCtx added in v0.8.0

type MiddleCtx struct {
	CliNonce RpcNonce
	AdTag    []byte
	Out      netip.AddrPort
	MP       netip.AddrPort
	Obf      *MpCtx
}

func NewMiddleCtx added in v0.8.0

func NewMiddleCtx(
	ipOut netip.AddrPort,
	ipMP netip.AddrPort,
	adTag []byte,
) (m *MiddleCtx)

func (*MiddleCtx) BlockSize added in v0.8.0

func (m *MiddleCtx) BlockSize() int

func (*MiddleCtx) DecryptBlock added in v0.8.0

func (m *MiddleCtx) DecryptBlock(buf []byte)

func (*MiddleCtx) EncryptBlock added in v0.8.0

func (m *MiddleCtx) EncryptBlock(buf []byte)

func (*MiddleCtx) SetObf added in v0.8.0

func (m *MiddleCtx) SetObf(
	nonceSrv, tsCli, secret []byte,
)

initialize obfuscator for MiddleCtx

type MpCtx added in v0.8.0

type MpCtx struct {
	// contains filtered or unexported fields
}

func (*MpCtx) BlockSize added in v0.8.0

func (m *MpCtx) BlockSize() int

func (*MpCtx) DecryptBlocks added in v0.8.0

func (m *MpCtx) DecryptBlocks(buf []byte)

func (*MpCtx) EncryptBlocks added in v0.8.0

func (m *MpCtx) EncryptBlocks(buf []byte)

type Nonce added in v0.7.1

type Nonce [NonceSize]byte

nonce is a set of bytes, received when initiating encrypted connection

type ObfCtx added in v0.7.1

type ObfCtx struct {
	Nonce    Nonce
	Secret   *Secret
	Protocol uint8
	Dc       int16
	Random   [2]byte
	// contains filtered or unexported fields
}

Context for client-proxy obfuscation

func ObfCtxFromNonce added in v0.7.1

func ObfCtxFromNonce(header Nonce, secret *Secret) (c *ObfCtx, err error)

Generate client encryption context

func (*ObfCtx) DecryptNext added in v0.7.1

func (c *ObfCtx) DecryptNext(buf []byte)

func (*ObfCtx) EncryptNext added in v0.7.1

func (c *ObfCtx) EncryptNext(buf []byte)

type Obfuscator added in v0.7.1

type Obfuscator interface {
	DecryptNext(buf []byte)
	EncryptNext(buf []byte)
}

Common interface that supports encryption and decryption of obfuscated messages.

type RpcNonce added in v0.8.0

type RpcNonce [RpcNonceLen]byte

type Secret

type Secret struct {
	RawSecret []byte
	Type      SecretType
	Tag       byte
	Fakehost  string
}

func NewSecret

func NewSecret(secret []byte) (*Secret, error)

Generate secret from byte array

func NewSecretHex

func NewSecretHex(secret string) (*Secret, error)

Generate secret from hex string

type SecretType

type SecretType int
const (
	Simple  SecretType = 1
	Secured SecretType = 2
	FakeTLS SecretType = 3
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL