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.
This commit is contained in:
John Preston 2018-11-04 14:29:30 +04:00
parent 617d21129f
commit 65b2db2160
12 changed files with 205 additions and 138 deletions

View File

@ -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

View File

@ -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 \

View File

@ -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 = "";

View File

@ -88,6 +88,8 @@
'AL_ALEXT_PROTOTYPES',
'TGVOIP_USE_CXX11_LIB',
'XXH_INLINE_ALL',
'TDESKTOP_API_ID=<(api_id)',
'TDESKTOP_API_HASH=<(api_hash)',
'<!@(python -c "for s in \'<(build_defines)\'.split(\',\'): print(s)")',
],
@ -126,7 +128,7 @@
'conditions': [
[ '"<(official_build_target)" != ""', {
'defines': [
'CUSTOM_API_ID',
'TDESKTOP_OFFICIAL_TARGET=<(official_build_target)',
],
'dependencies': [
'utils.gyp:Packer',

View File

@ -1,44 +0,0 @@
'''
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
'''
import glob
import re
import os
# Generate custom environment.x86 for ninja
# We use msbuild.log to extract some variables
variables = [
'TMP',
'SYSTEMROOT',
'TEMP',
'LIB',
'LIBPATH',
'PATH',
'PATHEXT',
'INCLUDE',
]
var_values = {}
for var_name in variables:
var_values[var_name] = os.environ[var_name]
next_contains_var = 0
with open('msbuild.log') as f:
for line in f:
if (re.match(r'^\s*Task "SetEnv"\s*$', line)):
next_contains_var = 1
elif next_contains_var:
cleanline = re.sub(r'^\s*|\s*$', '', line)
name_value_pair = re.match(r'^([A-Z]+)=(.+)$', cleanline)
if name_value_pair:
var_values[name_value_pair.group(1)] = name_value_pair.group(2)
next_contains_var = 0
out = open('environment.x86', 'wb')
for var_name in variables:
out.write(var_name + '=' + var_values[var_name] + '\0')
out.write('\0')
out.close()

128
Telegram/gyp/generate.py Normal file
View File

@ -0,0 +1,128 @@
'''
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
'''
import sys, os, re, subprocess
def finish(code):
global executePath
os.chdir(executePath)
sys.exit(code)
if sys.platform == 'win32' and not 'COMSPEC' in os.environ:
print('[ERROR] COMSPEC environment variable is not set.')
finish(1)
executePath = os.getcwd()
scriptPath = os.path.dirname(os.path.realpath(__file__))
apiId = ''
apiHash = ''
nextApiId = False
nextApiHash = False
for arg in sys.argv:
if nextApiId:
apiId = re.sub(r'[^\d]', '', arg)
nextApiId = False
elif nextApiHash:
apiHash = re.sub(r'[^a-fA-F\d]', '', arg)
nextApiHash = False
else:
nextApiId = (arg == '--api-id')
nextApiHash = (arg == '--api-hash')
officialTarget = ''
officialTargetFile = scriptPath + '/../build/target'
if os.path.isfile(officialTargetFile):
with open(officialTargetFile, 'r') as f:
for line in f:
officialTarget = line.strip()
if officialTarget != '':
officialApiIdFile = scriptPath + '/../../../TelegramPrivate/custom_api_id.h'
if not os.path.isfile(officialApiIdFile):
print("[ERROR] TelegramPrivate/custom_api_id.h not found.")
finish(1)
with open(officialApiIdFile, 'r') as f:
for line in f:
apiIdMatch = re.search(r'ApiId\s+=\s+(\d+)', line)
apiHashMatch = re.search(r'ApiHash\s+=\s+"([a-fA-F\d]+)"', line)
if apiIdMatch:
apiId = apiIdMatch.group(1)
elif apiHashMatch:
apiHash = apiHashMatch.group(1)
if apiId == '' or apiHash == '':
print("""[USAGE]: refresh --api-id YOUR_API_ID --api-hash YOUR_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)

View File

@ -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

View File

@ -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

13
docs/api_credentials.md Normal file
View File

@ -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**.

View File

@ -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

View File

@ -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

View File

@ -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