diff --git a/Makefile b/Makefile index 871f9a0..ce6a1cc 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) IMAGE_NAME := mtg APP_NAME := $(IMAGE_NAME) -GOMETALINTER := gometalinter.v2 +GOMETALINTER := gometalinter VENDOR_FILES := $(shell find "$(ROOT_DIR)/vendor" 2>/dev/null || echo -n "vendor") CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,windows,darwin,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}") diff --git a/config/config.go b/config/config.go index 793d4d0..39f48c5 100644 --- a/config/config.go +++ b/config/config.go @@ -10,26 +10,28 @@ import ( "github.com/juju/errors" ) +// Config represents common configuration of mtg. type Config struct { - Debug bool - Verbose bool - BindIP net.IP - BindPort uint16 + Debug bool + Verbose bool - PublicIPv4 net.IP + BindPort uint16 PublicIPv4Port uint16 - PublicIPv6 net.IP PublicIPv6Port uint16 - - StatsIP net.IP - StatsPort uint16 + StatsPort uint16 TimeoutRead time.Duration TimeoutWrite time.Duration + BindIP net.IP + PublicIPv4 net.IP + PublicIPv6 net.IP + StatsIP net.IP + Secret []byte } +// URLs contains links to the proxy (tg://, t.me) and their QR codes. type URLs struct { TG string `json:"tg_url"` TMe string `json:"tme_url"` @@ -37,27 +39,33 @@ type URLs struct { TMeQRCode string `json:"tme_qrcode"` } +// IPURLs contains links to both ipv4 and ipv6 of the proxy. type IPURLs struct { IPv4 URLs `json:"ipv4"` IPv6 URLs `json:"ipv6"` } +// BindAddr returns connection for this server to bind to. func (c *Config) BindAddr() string { return getAddr(c.BindIP, c.BindPort) } +// IPv4Addr returns connection string to ipv6 for mtproto proxy. func (c *Config) IPv4Addr() string { return getAddr(c.PublicIPv4, c.PublicIPv4Port) } +// IPv6Addr returns connection string to ipv6 for mtproto proxy. func (c *Config) IPv6Addr() string { return getAddr(c.PublicIPv6, c.PublicIPv6Port) } +// StatAddr returns connection string to the stats API. func (c *Config) StatAddr() string { return getAddr(c.StatsIP, c.StatsPort) } +// GetURLs returns configured IPURLs instance with links to this server. func (c *Config) GetURLs() IPURLs { return IPURLs{ IPv4: getURLs(c.PublicIPv4, c.PublicIPv4Port, c.Secret), @@ -69,7 +77,10 @@ func getAddr(host fmt.Stringer, port uint16) string { return net.JoinHostPort(host.String(), strconv.Itoa(int(port))) } -func NewConfig(debug, verbose bool, +// NewConfig returns new configuration. If required, it manages and +// fetches data from external sources. Parameters passed to this +// function, should come from command line arguments. +func NewConfig(debug, verbose bool, // nolint: gocyclo bindIP net.IP, bindPort uint16, publicIPv4 net.IP, PublicIPv4Port uint16, publicIPv6 net.IP, publicIPv6Port uint16, @@ -120,6 +131,8 @@ func NewConfig(debug, verbose bool, PublicIPv4Port: PublicIPv4Port, PublicIPv6: publicIPv6, PublicIPv6Port: publicIPv6Port, + StatsIP: statsIP, + StatsPort: statsPort, TimeoutRead: timeoutRead, TimeoutWrite: timeoutWrite, Secret: secretBytes, diff --git a/config/global_ips.go b/config/global_ips.go index 965a9cc..5a73747 100644 --- a/config/global_ips.go +++ b/config/global_ips.go @@ -22,7 +22,7 @@ func fetchIP(url string) (net.IP, error) { if err != nil { return nil, err } - defer resp.Body.Close() + defer resp.Body.Close() // nolint: errcheck respData, err := ioutil.ReadAll(resp.Body) if err != nil { diff --git a/config/urls.go b/config/urls.go index fa30ff3..7aada07 100644 --- a/config/urls.go +++ b/config/urls.go @@ -14,7 +14,7 @@ func getURLs(addr net.IP, port uint16, secret []byte) (urls URLs) { values.Set("secret", hex.EncodeToString(secret)) urls.TG = makeTGURL(values) - urls.TMe = makeTGURL(values) + urls.TMe = makeTMeURL(values) urls.TGQRCode = makeQRCodeURL(urls.TG) urls.TMeQRCode = makeQRCodeURL(urls.TG) diff --git a/obfuscated2/obfuscated2_test.go b/obfuscated2/obfuscated2_test.go index 9e660e0..49255df 100644 --- a/obfuscated2/obfuscated2_test.go +++ b/obfuscated2/obfuscated2_test.go @@ -25,7 +25,8 @@ func TestObfs2TelegramDecryptEncryptDecrypt(t *testing.T) { data := []byte{1, 2, 3} encrypted := make([]byte, 3) encryptor.XORKeyStream(encrypted, data) - decrypted := obfs2.Decrypt(encrypted) + decrypted := make([]byte, 3) + obfs2.Decryptor.XORKeyStream(decrypted, encrypted) assert.Equal(t, data, decrypted) } @@ -67,10 +68,12 @@ func TestObfs2Full(t *testing.T) { tgEncryptedMessage := make([]byte, len(message)) tgEncryptor.XORKeyStream(tgEncryptedMessage, message) - tgEncDecryptedMessage := tgObfs.Decrypt(tgEncryptedMessage) + tgEncDecryptedMessage := make([]byte, len(tgEncryptedMessage)) + tgObfs.Decryptor.XORKeyStream(tgEncDecryptedMessage, tgEncryptedMessage) assert.Equal(t, message, tgEncDecryptedMessage) - clientEncryptedMessage := clientObfs.Encrypt(tgEncDecryptedMessage) + clientEncryptedMessage := make([]byte, len(tgEncDecryptedMessage)) + clientObfs.Encryptor.XORKeyStream(clientEncryptedMessage, tgEncDecryptedMessage) finalMessage := make([]byte, len(clientEncryptedMessage)) clientDecryptor.XORKeyStream(finalMessage, clientEncryptedMessage)