From 792a88d064d74ff481782957ec67e65dd9bc163e Mon Sep 17 00:00:00 2001 From: Alexander Akulich Date: Fri, 25 Jan 2019 21:48:44 +0300 Subject: [PATCH] Refactor DC configuration --- Telegram/CMakeLists.txt | 1 + Telegram/SourceFiles/config.cpp | 73 +++++++++++++++++++++++ Telegram/SourceFiles/config.h.in | 58 ++---------------- Telegram/SourceFiles/mtproto/auth_key.cpp | 7 +++ Telegram/SourceFiles/mtproto/auth_key.h | 7 +-- 5 files changed, 87 insertions(+), 59 deletions(-) create mode 100644 Telegram/SourceFiles/config.cpp diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 767f0df52..1ea959a22 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -447,6 +447,7 @@ add_executable(Kepka WIN32 MACOSX_BUNDLE SourceFiles/app.cpp SourceFiles/application.cpp SourceFiles/auth_session.cpp + SourceFiles/config.cpp SourceFiles/facades.cpp SourceFiles/layerwidget.cpp SourceFiles/layout.cpp diff --git a/Telegram/SourceFiles/config.cpp b/Telegram/SourceFiles/config.cpp new file mode 100644 index 000000000..2f091707b --- /dev/null +++ b/Telegram/SourceFiles/config.cpp @@ -0,0 +1,73 @@ +// +// This file is part of Kepka, +// an unofficial desktop version of Telegram messaging app, +// see https://github.com/procxx/kepka +// +// Kepka is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// It is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// In addition, as a special exception, the copyright holders give permission +// to link the code of portions of this program with the OpenSSL library. +// +// Full license: https://github.com/procxx/kepka/blob/master/LICENSE +// Copyright (c) 2018- Kepka Contributors, https://github.com/procxx +// + +#include "config.h" +#include "core/utils.h" + +const char **cPublicRSAKeys(size_t &keysCount) { + static const char *(keys[]) = { + "\ +-----BEGIN RSA PUBLIC KEY-----\n\ +MIIBCgKCAQEAwVACPi9w23mF3tBkdZz+zwrzKOaaQdr01vAbU4E1pvkfj4sqDsm6\n\ +lyDONS789sVoD/xCS9Y0hkkC3gtL1tSfTlgCMOOul9lcixlEKzwKENj1Yz/s7daS\n\ +an9tqw3bfUV/nqgbhGX81v/+7RFAEd+RwFnK7a+XYl9sluzHRyVVaTTveB2GazTw\n\ +Efzk2DWgkBluml8OREmvfraX3bkHZJTKX4EQSjBbbdJ2ZXIsRrYOXfaA+xayEGB+\n\ +8hdlLmAjbCVfaigxX0CDqWeR1yFL9kwd9P0NsZRPsmoqVwMbMu7mStFai6aIhc3n\n\ +Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB\n\ +-----END RSA PUBLIC KEY-----"}; + keysCount = base::array_size(keys); + return keys; +} + +static const BuiltInDc _builtInDcs[] = {{1, "149.154.175.50", 443}, + {2, "149.154.167.51", 443}, + {3, "149.154.175.100", 443}, + {4, "149.154.167.91", 443}, + {5, "149.154.171.5", 443}}; + +static const BuiltInDc _builtInDcsIPv6[] = {{1, "2001:b28:f23d:f001::a", 443}, + {2, "2001:67c:4e8:f002::a", 443}, + {3, "2001:b28:f23d:f003::a", 443}, + {4, "2001:67c:4e8:f004::a", 443}, + {5, "2001:b28:f23f:f005::a", 443}}; + +static const BuiltInDc _builtInTestDcs[] = { + {1, "149.154.175.10", 443}, {2, "149.154.167.40", 443}, {3, "149.154.175.117", 443}}; + +static const BuiltInDc _builtInTestDcsIPv6[] = { + {1, "2001:b28:f23d:f001::e", 443}, {2, "2001:67c:4e8:f002::e", 443}, {3, "2001:b28:f23d:f003::e", 443}}; + +const BuiltInDc *builtInDcs() { + return cTestMode() ? _builtInTestDcs : _builtInDcs; +} + +int builtInDcsCount() { + return (cTestMode() ? sizeof(_builtInTestDcs) : sizeof(_builtInDcs)) / sizeof(BuiltInDc); +} + +const BuiltInDc *builtInDcsIPv6() { + return cTestMode() ? _builtInTestDcsIPv6 : _builtInDcsIPv6; +} + +int builtInDcsCountIPv6() { + return (cTestMode() ? sizeof(_builtInTestDcsIPv6) : sizeof(_builtInDcsIPv6)) / sizeof(BuiltInDc); +} diff --git a/Telegram/SourceFiles/config.h.in b/Telegram/SourceFiles/config.h.in index 2973996b1..d46fadc11 100644 --- a/Telegram/SourceFiles/config.h.in +++ b/Telegram/SourceFiles/config.h.in @@ -174,19 +174,7 @@ inline const char *cGUIDStr() { return gGuidStr; } -inline const char **cPublicRSAKeys(size_t &keysCount) { - static const char *(keys[]) = {"\ ------BEGIN RSA PUBLIC KEY-----\n\ -MIIBCgKCAQEAwVACPi9w23mF3tBkdZz+zwrzKOaaQdr01vAbU4E1pvkfj4sqDsm6\n\ -lyDONS789sVoD/xCS9Y0hkkC3gtL1tSfTlgCMOOul9lcixlEKzwKENj1Yz/s7daS\n\ -an9tqw3bfUV/nqgbhGX81v/+7RFAEd+RwFnK7a+XYl9sluzHRyVVaTTveB2GazTw\n\ -Efzk2DWgkBluml8OREmvfraX3bkHZJTKX4EQSjBbbdJ2ZXIsRrYOXfaA+xayEGB+\n\ -8hdlLmAjbCVfaigxX0CDqWeR1yFL9kwd9P0NsZRPsmoqVwMbMu7mStFai6aIhc3n\n\ -Slv8kg9qv1m6XHVQY3PnEw+QQtqSIXklHwIDAQAB\n\ ------END RSA PUBLIC KEY-----"}; - keysCount = base::array_size(keys); - return keys; -} +const char **cPublicRSAKeys(size_t &keysCount); struct BuiltInDc { int id; @@ -194,49 +182,13 @@ struct BuiltInDc { int port; }; -static const BuiltInDc _builtInDcs[] = { - { 1, "149.154.175.50", 443 }, - { 2, "149.154.167.51", 443 }, - { 3, "149.154.175.100", 443 }, - { 4, "149.154.167.91", 443 }, - { 5, "149.154.171.5", 443 } -}; - -static const BuiltInDc _builtInDcsIPv6[] = { - { 1, "2001:b28:f23d:f001::a", 443 }, - { 2, "2001:67c:4e8:f002::a", 443 }, - { 3, "2001:b28:f23d:f003::a", 443 }, - { 4, "2001:67c:4e8:f004::a", 443 }, - { 5, "2001:b28:f23f:f005::a", 443 } -}; - -static const BuiltInDc _builtInTestDcs[] = { - { 1, "149.154.175.10", 443 }, - { 2, "149.154.167.40", 443 }, - { 3, "149.154.175.117", 443 } -}; - -static const BuiltInDc _builtInTestDcsIPv6[] = { - { 1, "2001:b28:f23d:f001::e", 443 }, - { 2, "2001:67c:4e8:f002::e", 443 }, - { 3, "2001:b28:f23d:f003::e", 443 } -}; +const BuiltInDc *builtInDcs(); -inline const BuiltInDc *builtInDcs() { - return cTestMode() ? _builtInTestDcs : _builtInDcs; -} +int builtInDcsCount(); -inline int builtInDcsCount() { - return (cTestMode() ? sizeof(_builtInTestDcs) : sizeof(_builtInDcs)) / sizeof(BuiltInDc); -} +const BuiltInDc *builtInDcsIPv6(); -inline const BuiltInDc *builtInDcsIPv6() { - return cTestMode() ? _builtInTestDcsIPv6 : _builtInDcsIPv6; -} - -inline int builtInDcsCountIPv6() { - return (cTestMode() ? sizeof(_builtInTestDcsIPv6) : sizeof(_builtInDcsIPv6)) / sizeof(BuiltInDc); -} +int builtInDcsCountIPv6(); static const char *UpdatesPublicKey = "\ -----BEGIN RSA PUBLIC KEY-----\n\ diff --git a/Telegram/SourceFiles/mtproto/auth_key.cpp b/Telegram/SourceFiles/mtproto/auth_key.cpp index 30fa5aff2..115ff86fc 100644 --- a/Telegram/SourceFiles/mtproto/auth_key.cpp +++ b/Telegram/SourceFiles/mtproto/auth_key.cpp @@ -64,6 +64,13 @@ void AuthKey::prepareAES_oldmtp(const MTPint128 &msgKey, MTPint256 &aesKey, MTPi memcpy(iv + 12 + 8 + 4, sha1_d, 8); } +void AuthKey::countKeyId() { + auto sha1 = hashSha1(_key.data(), _key.size()); + + // Lower 64 bits = 8 bytes of 20 byte SHA1 hash. + _keyId = *reinterpret_cast(sha1.data() + 12); +} + void AuthKey::prepareAES(const MTPint128 &msgKey, MTPint256 &aesKey, MTPint256 &aesIV, bool send) const { quint32 x = send ? 0 : 8; diff --git a/Telegram/SourceFiles/mtproto/auth_key.h b/Telegram/SourceFiles/mtproto/auth_key.h index de1d70d12..7e38f572b 100644 --- a/Telegram/SourceFiles/mtproto/auth_key.h +++ b/Telegram/SourceFiles/mtproto/auth_key.h @@ -98,12 +98,7 @@ class AuthKey { } private: - void countKeyId() { - auto sha1 = hashSha1(_key.data(), _key.size()); - - // Lower 64 bits = 8 bytes of 20 byte SHA1 hash. - _keyId = *reinterpret_cast(sha1.data() + 12); - } + void countKeyId(); Type _type = Type::Generated; DcId _dcId = 0;