From 65b2db216033aa08b7bc846df27843e566f08981 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 4 Nov 2018 14:29:30 +0400 Subject: [PATCH] Don't provide 'api_id' and 'api_hash' by default. We ask the developer to obtain his own api credentials, because the bundled 'api_id' / 'api_hash' are strictly limited by the server. The old credentials still could be used for test purposes, but the developer will need to explicitly opt-in to use them. --- .appveyor/install.bat | 2 +- .travis/build.sh | 2 + Telegram/SourceFiles/config.h | 42 +++++++++-- Telegram/gyp/Telegram.gyp | 4 +- Telegram/gyp/create_env.py | 44 ------------ Telegram/gyp/generate.py | 128 ++++++++++++++++++++++++++++++++++ Telegram/gyp/refresh.bat | 55 +-------------- Telegram/gyp/refresh.sh | 32 +-------- docs/api_credentials.md | 13 ++++ docs/building-cmake.md | 9 ++- docs/building-msvc.md | 6 ++ docs/building-xcode.md | 6 ++ 12 files changed, 205 insertions(+), 138 deletions(-) delete mode 100644 Telegram/gyp/create_env.py create mode 100644 Telegram/gyp/generate.py create mode 100644 docs/api_credentials.md diff --git a/.appveyor/install.bat b/.appveyor/install.bat index e04e29ea8..fa5ba7589 100644 --- a/.appveyor/install.bat +++ b/.appveyor/install.bat @@ -48,7 +48,7 @@ GOTO:EOF git submodule init git submodule update cd %SRC_DIR%\Telegram - call gyp\refresh.bat + call gyp\refresh.bat --api-id 17349 --api-hash 344583e45741c457fe1862106095a5eb GOTO:EOF :configureBuild diff --git a/.travis/build.sh b/.travis/build.sh index cacd2bd81..a377031fc 100755 --- a/.travis/build.sh +++ b/.travis/build.sh @@ -673,6 +673,8 @@ buildTelegram() { cd "$UPSTREAM/Telegram/gyp" "$GYP_PATH/gyp" \ + -Dapi_id=17349 \ + -Dapi_hash=344583e45741c457fe1862106095a5eb \ -Dbuild_defines=${GYP_DEFINES:1} \ -Dlinux_path_xkbcommon=$XKB_PATH \ -Dlinux_path_va=$VA_PATH \ diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index ed3407ba2..182a6398b 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -192,12 +192,40 @@ w/CVnbwQOw0g5GBwwFV3r0uTTvy44xx8XXxk+Qknu4eBCsmrAFNnAgMBAAE=\n\ -----END RSA PUBLIC KEY-----\ "; -#ifdef CUSTOM_API_ID -#include "../../../TelegramPrivate/custom_api_id.h" // Custom API id and API hash -#else -static const int32 ApiId = 17349; -static const char *ApiHash = "344583e45741c457fe1862106095a5eb"; -#endif +#if defined TDESKTOP_API_ID && defined TDESKTOP_API_HASH + +#define TDESKTOP_API_HASH_TO_STRING_HELPER(V) #V +#define TDESKTOP_API_HASH_TO_STRING(V) TDESKTOP_API_HASH_TO_STRING_HELPER(V) + +constexpr auto ApiId = TDESKTOP_API_ID; +constexpr auto ApiHash = TDESKTOP_API_HASH_TO_STRING(TDESKTOP_API_HASH); + +#undef TDESKTOP_API_HASH_TO_STRING +#undef TDESKTOP_API_HASH_TO_STRING_HELPER + +#else // TDESKTOP_API_ID && TDESKTOP_API_HASH + +// To build your version of Telegram Desktop you're required to provide +// your own 'api_id' and 'api_hash' for the Telegram API access. +// +// How to obtain your 'api_id' and 'api_hash' is described here: +// https://core.telegram.org/api/obtaining_api_id +// +// If you're building the application not for deployment, +// but only for test purposes you can comment out the error below. +// +// This will allow you to use TEST ONLY 'api_id' and 'api_hash' which are +// very limited by the Telegram API server. +// +// Your users will start getting internal server errors on login +// if you deploy an app using those 'api_id' and 'api_hash'. + +#error You are required to provide API_ID and API_HASH. + +constexpr auto ApiId = 17349; +constexpr auto ApiHash = "344583e45741c457fe1862106095a5eb"; + +#endif // TDESKTOP_API_ID && TDESKTOP_API_HASH #if Q_BYTE_ORDER == Q_BIG_ENDIAN #error "Only little endian is supported!" @@ -207,7 +235,7 @@ static const char *ApiHash = "344583e45741c457fe1862106095a5eb"; #error "Alpha version macro is not defined." #endif -#if (defined CUSTOM_API_ID) && (ALPHA_VERSION_MACRO > 0ULL) +#if (defined TDESKTOP_OFFICIAL_TARGET) && (ALPHA_VERSION_MACRO > 0ULL) #include "../../../TelegramPrivate/alpha_private.h" // private key for downloading closed alphas #else static const char *AlphaPrivateKey = ""; diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index dd7779c7e..ac7696e1d 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -88,6 +88,8 @@ 'AL_ALEXT_PROTOTYPES', 'TGVOIP_USE_CXX11_LIB', 'XXH_INLINE_ALL', + 'TDESKTOP_API_ID=<(api_id)', + 'TDESKTOP_API_HASH=<(api_hash)', ' To build your version of Telegram Desktop you're required to provide +> your own 'api_id' and 'api_hash' for the Telegram API access. +> +> How to obtain your 'api_id' and 'api_hash' is described here: +> https://core.telegram.org/api/obtaining_api_id +> +> If you're building the application not for deployment, +> but only for test purposes you can use TEST ONLY credentials, +> which are very limited by the Telegram API server: +> +> api_id: 17349 +> api_hash: 344583e45741c457fe1862106095a5eb +> +> Your users will start getting internal server errors on login +> if you deploy an app using those 'api_id' and 'api_hash'.""") + finish(0) + +gypScript = 'gyp' +gypFormats = [] +gypArguments = [] +cmakeConfigurations = [] +gypArguments.append('--depth=.') +gypArguments.append('--generator-output=..') +gypArguments.append('-Goutput_dir=../out') +gypArguments.append('-Dapi_id=' + apiId) +gypArguments.append('-Dapi_hash=' + apiHash) +gypArguments.append('-Dofficial_build_target=' + officialTarget) +if 'TDESKTOP_BUILD_DEFINES' in os.environ: + buildDefines = os.environ['TDESKTOP_BUILD_DEFINES'] + gypArguments.append('-Dbuild_defines=' + buildDefines) + print('[INFO] Set build defines to ' + buildDefines) + +if sys.platform == 'win32': + os.environ['GYP_MSVS_VERSION'] = '2017' + gypFormats.append('ninja') + gypFormats.append('msvs-ninja') +elif sys.platform == 'darwin': + # use patched gyp with Xcode project generator + gypScript = '../../../Libraries/gyp/gyp' + gypArguments.append('-Gxcode_upgrade_check_project_version=1010') + gypFormats.append('xcode') +else: + gypScript = '../../../Libraries/gyp/gyp' + gypFormats.append('cmake') + cmakeConfigurations.append('Debug') + cmakeConfigurations.append('Release') + +os.chdir(scriptPath) +for format in gypFormats: + command = gypArguments[:] + command.insert(0, gypScript) + command.append('--format=' + format) + command.append('Telegram.gyp') + result = subprocess.call(' '.join(command), shell=True) + if result != 0: + print('[ERROR] Failed generating for format: ' + format) + finish(result) + +os.chdir(scriptPath + '/../../out') +for configuration in cmakeConfigurations: + os.chdir(configuration) + result = subprocess.call('cmake .', shell=True) + if result != 0: + print('[ERROR] Failed calling cmake for ' + configuration) + finish(result) + os.chdir('..') + +finish(0) diff --git a/Telegram/gyp/refresh.bat b/Telegram/gyp/refresh.bat index 3622ced93..be6a96944 100644 --- a/Telegram/gyp/refresh.bat +++ b/Telegram/gyp/refresh.bat @@ -1,63 +1,12 @@ @echo OFF -setlocal EnableDelayedExpansion + set "FullScriptPath=%~dp0" -set "FullExecPath=%cd%" -set "Silence=>nul" -if "%1" == "-v" set "Silence=" - -if exist "%FullScriptPath%..\build\target" ( - FOR /F "tokens=1* delims= " %%i in (%FullScriptPath%..\build\target) do set "BuildTarget=%%i" -) else ( - set "BuildTarget=" -) - -rem strangely linking of Release Telegram build complains about the absence of lib.pdb -if exist "%FullScriptPath%..\..\..\Libraries\openssl\tmp32\lib.pdb" ( - if not exist "%FullScriptPath%..\..\..\Libraries\openssl\Release\lib\lib.pdb" ( - xcopy "%FullScriptPath%..\..\..\Libraries\openssl\tmp32\lib.pdb" "%FullScriptPath%..\..\..\Libraries\openssl\Release\lib\" %Silence% - ) -) - -set BUILD_DEFINES= -if not "%TDESKTOP_BUILD_DEFINES%" == "" ( - set "BUILD_DEFINES=-Dbuild_defines=%TDESKTOP_BUILD_DEFINES%" - echo [INFO] Set build defines to !BUILD_DEFINES! -) - -set GYP_MSVS_VERSION=2017 - -cd "%FullScriptPath%" -call gyp --depth=. --generator-output=.. -Goutput_dir=../out !BUILD_DEFINES! -Dofficial_build_target=%BuildTarget% Telegram.gyp --format=ninja +python %FullScriptPath%generate.py %1 %2 %3 %4 %5 %6 if %errorlevel% neq 0 goto error -call gyp --depth=. --generator-output=.. -Goutput_dir=../out !BUILD_DEFINES! -Dofficial_build_target=%BuildTarget% Telegram.gyp --format=msvs-ninja -if %errorlevel% neq 0 goto error -cd ../.. -rem looks like ninja build works without sdk 7.1 which was used by generating custom environment.arch files - -rem cd "%FullScriptPath%" -rem call gyp --depth=. --generator-output=../.. -Goutput_dir=out -Gninja_use_custom_environment_files=1 Telegram.gyp --format=ninja -rem if %errorlevel% neq 0 goto error -rem call gyp --depth=. --generator-output=../.. -Goutput_dir=out -Gninja_use_custom_environment_files=1 Telegram.gyp --format=msvs-ninja -rem if %errorlevel% neq 0 goto error -rem cd ../.. - -rem call msbuild /target:SetBuildDefaultEnvironmentVariables Telegram.vcxproj /fileLogger %Silence% -rem if %errorlevel% neq 0 goto error - -rem call python "%FullScriptPath%create_env.py" -rem if %errorlevel% neq 0 goto error - -rem call move environment.x86 out\Debug\ %Silence% -rem if %errorlevel% neq 0 goto error - -cd "%FullExecPath%" exit /b :error echo FAILED -if exist "%FullScriptPath%..\..\msbuild.log" del "%FullScriptPath%..\..\msbuild.log" -if exist "%FullScriptPath%..\..\environment.x86" del "%FullScriptPath%..\..\environment.x86" -cd "%FullExecPath%" exit /b 1 diff --git a/Telegram/gyp/refresh.sh b/Telegram/gyp/refresh.sh index c42c10f74..5fb8f9320 100755 --- a/Telegram/gyp/refresh.sh +++ b/Telegram/gyp/refresh.sh @@ -1,38 +1,10 @@ #!/usr/bin/env bash set -e -FullExecPath=$PWD + pushd `dirname $0` > /dev/null FullScriptPath=`pwd` popd > /dev/null -if [ -f "$FullScriptPath/../build/target" ]; then - while IFS='' read -r line || [[ -n "$line" ]]; do - BuildTarget="$line" - done < "$FullScriptPath/../build/target" -else - BuildTarget="" -fi +python $FullScriptPath/generate.py $1 $2 $3 $4 $5 $6 -MySystem=`uname -s` -cd $FullScriptPath - -if [ "$MySystem" == "Linux" ]; then - ../../../Libraries/gyp/gyp --depth=. --generator-output=.. -Goutput_dir=../out -Dofficial_build_target=$BuildTarget Telegram.gyp --format=cmake - cd ../../out/Debug - cmake . - cd ../Release - cmake . - cd ../../Telegram/gyp -else - #gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=ninja - #gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode-ninja - #gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode - # use patched gyp with Xcode project generator - ../../../Libraries/gyp/gyp --depth=. --generator-output=.. -Goutput_dir=../out -Gxcode_upgrade_check_project_version=1000 -Dofficial_build_target=$BuildTarget Telegram.gyp --format=xcode -fi - -cd ../.. - -cd $FullExecPath exit - diff --git a/docs/api_credentials.md b/docs/api_credentials.md new file mode 100644 index 000000000..0d2819bd3 --- /dev/null +++ b/docs/api_credentials.md @@ -0,0 +1,13 @@ +## Obtaining your API credentials + +To build your version of Telegram Desktop you're required to provide your own **api_id** and **api_hash** for the Telegram API access. + +How to obtain your **api_id** and **api_hash** is described here: [https://core.telegram.org/api/obtaining_api_id](https://core.telegram.org/api/obtaining_api_id) + +If you're building the application not for deployment, but only for test purposes you can use TEST ONLY credentials, which are very limited by the Telegram API server: + +**api_id**: 17349 +**api_hash**: 344583e45741c457fe1862106095a5eb + +Your users will start getting internal server errors on login if you deploy an app using those **api_id** and **api_hash**. + diff --git a/docs/building-cmake.md b/docs/building-cmake.md index 181bdfc29..92b8e3f75 100644 --- a/docs/building-cmake.md +++ b/docs/building-cmake.md @@ -4,6 +4,10 @@ Choose an empty folder for the future build, for example **/home/user/TBuild**. It will be named ***BuildPath*** in the rest of this document. +### Obtain your API credentials + +You will require **api_id** and **api_hash** to access the Telegram API servers. To learn how to obtain them [click here][api_credentials]. + ### Install software and required packages You will need GCC 7.2 and CMake 3.2 installed. To install them and all the required dependencies run @@ -150,9 +154,9 @@ Go to ***BuildPath*** and run ### Building the project -Go to ***BuildPath*/tdesktop/Telegram** and run +Go to ***BuildPath*/tdesktop/Telegram** and run (using [your **api_id** and **api_hash**](#obtain-your-api-credentials)) - gyp/refresh.sh + gyp/refresh.sh --api-id YOUR_API_ID --api-hash YOUR_API_HASH To make Debug version go to ***BuildPath*/tdesktop/out/Debug** and run @@ -164,3 +168,4 @@ To make Release version go to ***BuildPath*/tdesktop/out/Release** and run You can debug your builds from Qt Creator, just open **CMakeLists.txt** from ***BuildPath*/tdesktop/out/Debug** and launch with debug. +[api_credentials]: api_credentials.md diff --git a/docs/building-msvc.md b/docs/building-msvc.md index aee50ff70..1758bcbf0 100644 --- a/docs/building-msvc.md +++ b/docs/building-msvc.md @@ -12,6 +12,10 @@ Choose an empty folder for the future build, for example **D:\\TBuild**. It will All commands (if not stated otherwise) will be launched from **x86 Native Tools Command Prompt for VS 2017.bat** (should be in **Start Menu > Visual Studio 2017** menu folder). Pay attention not to use any other Command Prompt. +### Obtain your API credentials + +You will require **api_id** and **api_hash** to access the Telegram API servers. To learn how to obtain them [click here][api_credentials]. + ## Install third party software * Download **ActivePerl** installer from [https://www.activestate.com/activeperl/downloads](https://www.activestate.com/activeperl/downloads) and install to ***BuildPath*\\ThirdParty\\Perl** @@ -170,3 +174,5 @@ For better debugging you may want to install Qt Visual Studio Tools: * Go to **Online** tab * Search for **Qt** * Install **Qt Visual Studio Tools** extension + +[api_credentials]: api_credentials.md diff --git a/docs/building-xcode.md b/docs/building-xcode.md index aef94506d..71d6c0172 100644 --- a/docs/building-xcode.md +++ b/docs/building-xcode.md @@ -4,6 +4,10 @@ Choose a folder for the future build, for example **/Users/user/TBuild**. It will be named ***BuildPath*** in the rest of this document. All commands will be launched from Terminal. +### Obtain your API credentials + +You will require **api_id** and **api_hash** to access the Telegram API servers. To learn how to obtain them [click here][api_credentials]. + ### Download libraries Download [**xz-5.0.5**](http://tukaani.org/xz/xz-5.0.5.tar.gz) and unpack to ***BuildPath*/Libraries/xz-5.0.5** @@ -138,3 +142,5 @@ Go to ***BuildPath*/tdesktop/Telegram** and run gyp/refresh.sh Then launch Xcode, open ***BuildPath*/tdesktop/Telegram/Telegram.xcodeproj** and build for Debug / Release. + +[api_credentials]: api_credentials.md