为什么使用电报护照-没有端到端

嗨%用户名%!



在讨论Passport 新闻时, Telegram的作者对最新技术的安全性进行了激烈的讨论。

让我们看看它是如何加密您的个人数据的,并讨论真正的端到端。

简而言之,Passport是如何工作的。

  • 在本地,使用密码来加密您的个人数据(姓名,电子邮件,护照扫描,其他文件)。
  • 加密的数据+元信息将上传到Telegram云。
  • 当您需要登录服务时,客户端将从云中下载数据,使用密码对其解密,然后将其解密为请求信息的服务的公共密钥,然后将其发送。

我们将考虑第一部分,它涉及个人数据的加密和存储。

根据开发人员的说法,端到端的事实是,Telegram云应该无法解密您的个人数据,而只会看到“随机噪声”。

让我们仔细研究一下位于此处的桌面客户端的个人数据加密算法的代码,看看其工作结果是否符合端到端标准。

一切都以密码开头。 这是它变成中间加密密钥的地方。

bytes::vector CountPasswordHashForSecret(
		bytes::const_span salt,
		bytes::const_span password) {
	return openssl::Sha512(bytes::concatenate(
		salt,
		password,
		salt));
}

, SHA-512. . !

2018 . GPU SHA-512 . 10 GPU 8- 94 ( , , ) 5 .

, GPU, Telegram .

. , :

bytes::vector GenerateSecretBytes() {
	auto result = bytes::vector(kSecretSize);
	memset_rand(result.data(), result.size());
	const auto full = ranges::accumulate(
		result,
		0ULL,
		[](uint64 sum, gsl::byte value) { return sum + uchar(value); });
	const auto mod = (full % 255ULL);
	const auto add = 255ULL + 239 - mod;
	auto first = (static_cast<uchar>(result[0]) + add) % 255ULL;
	result[0] = static_cast<gsl::byte>(first);
	return result;
}

, .

«», HMAC AEAD , , , 239, :

bool CheckBytesMod255(bytes::const_span bytes) {
	const auto full = ranges::accumulate(
		bytes,
		0ULL,
		[](uint64 sum, gsl::byte value) { return sum + uchar(value); });
	const auto mod = (full % 255ULL);
	return (mod == 239);
}

-, . , , HMAC, .

. , . , :

EncryptedData EncryptData(
		bytes::const_span bytes,
		bytes::const_span dataSecret) {
	constexpr auto kFromPadding = kMinPadding + kAlignTo - 1;
	constexpr auto kPaddingDelta = kMaxPadding - kFromPadding;
	const auto randomPadding = kFromPadding
		+ (rand_value<uint32>() % kPaddingDelta);
	const auto padding = randomPadding
		- ((bytes.size() + randomPadding) % kAlignTo);
	Assert(padding >= kMinPadding && padding <= kMaxPadding);

	auto unencrypted = bytes::vector(padding + bytes.size());
	Assert(unencrypted.size() % kAlignTo == 0);

	unencrypted[0] = static_cast<gsl::byte>(padding);
	memset_rand(unencrypted.data() + 1, padding - 1);
	bytes::copy(
		gsl::make_span(unencrypted).subspan(padding),
		bytes);


32 255 .
dataHash. , .

	const auto dataHash = openssl::Sha256(unencrypted);
	const auto bytesForEncryptionKey = bytes::concatenate(
		dataSecret,
		dataHash);

	auto params = PrepareAesParams(bytesForEncryptionKey);
	return {
		{ dataSecret.begin(), dataSecret.end() },
		{ dataHash.begin(), dataHash.end() },
		Encrypt(unencrypted, std::move(params))
	};
}

. SHA-512 , dataHash.


:

  1. ,

« », , , . , AES (2^256).

Telegram , HMAC.

:

  1. , (GPU)
  2. (AES-NI)
  3. .
  4. - SHA-512 (GPU)
  5. (AES-NI)
  6. SHA-256, , :

if (padding < kMinPadding
		|| padding > kMaxPadding
		|| padding > decrypted.size()) {

, , . . GPU, AES-NI. , , . , ?

, , Don't roll your own crypto , End-to-End, .

, , , .

End-to-End


E2E , . , .

, , , , . Signal, (WhatsApp, etc). , , , .

, . .

Telegram , . , , .

P.S. E2E, VirgilSecurity , .

Source: https://habr.com/ru/post/zh-CN418535/


All Articles