blob: b875f8dfb84f5ecca3c6841b6a7eae9b149a4bb9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#include "td/telegram/NewPasswordState.h"
namespace td {
Result<NewPasswordState> get_new_password_state(tl_object_ptr<telegram_api::PasswordKdfAlgo> new_algo,
tl_object_ptr<telegram_api::SecurePasswordKdfAlgo> new_secure_algo) {
NewPasswordState state;
CHECK(new_algo != nullptr);
switch (new_algo->get_id()) {
case telegram_api::passwordKdfAlgoUnknown::ID:
return Status::Error(400, "Please update client to continue");
case telegram_api::passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow::ID: {
auto algo =
move_tl_object_as<telegram_api::passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow>(new_algo);
state.client_salt = algo->salt1_.as_slice().str();
state.server_salt = algo->salt2_.as_slice().str();
state.srp_g = algo->g_;
state.srp_p = algo->p_.as_slice().str();
break;
}
default:
UNREACHABLE();
}
CHECK(new_secure_algo != nullptr);
switch (new_secure_algo->get_id()) {
case telegram_api::securePasswordKdfAlgoUnknown::ID:
return Status::Error(400, "Please update client to continue");
case telegram_api::securePasswordKdfAlgoSHA512::ID:
return Status::Error(500, "Server has sent outdated secret encryption mode");
case telegram_api::securePasswordKdfAlgoPBKDF2HMACSHA512iter100000::ID: {
auto algo = move_tl_object_as<telegram_api::securePasswordKdfAlgoPBKDF2HMACSHA512iter100000>(new_secure_algo);
state.secure_salt = algo->salt_.as_slice().str();
break;
}
default:
UNREACHABLE();
}
static constexpr size_t MIN_NEW_SECURE_SALT_SIZE = 8;
if (state.secure_salt.size() < MIN_NEW_SECURE_SALT_SIZE) {
return Status::Error(500, "New secure salt length too small");
}
static constexpr size_t MIN_NEW_SALT_SIZE = 8;
if (state.client_salt.size() < MIN_NEW_SALT_SIZE) {
return Status::Error(500, "New salt length too small");
}
return state;
}
} // namespace td
|