Skip to content

Commit

Permalink
Refactor DC configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaffeine authored and leha-bot committed Mar 2, 2019
1 parent bbd7709 commit 792a88d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 59 deletions.
1 change: 1 addition & 0 deletions Telegram/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 73 additions & 0 deletions Telegram/SourceFiles/config.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
58 changes: 5 additions & 53 deletions Telegram/SourceFiles/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -174,69 +174,21 @@ 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;
const char *ip;
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\
Expand Down
7 changes: 7 additions & 0 deletions Telegram/SourceFiles/mtproto/auth_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyId *>(sha1.data() + 12);
}

void AuthKey::prepareAES(const MTPint128 &msgKey, MTPint256 &aesKey, MTPint256 &aesIV, bool send) const {
quint32 x = send ? 0 : 8;

Expand Down
7 changes: 1 addition & 6 deletions Telegram/SourceFiles/mtproto/auth_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyId *>(sha1.data() + 12);
}
void countKeyId();

Type _type = Type::Generated;
DcId _dcId = 0;
Expand Down

0 comments on commit 792a88d

Please sign in to comment.