2018-12-31 20:04:05 +01:00
|
|
|
//
|
2024-01-01 01:07:21 +01:00
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
2018-12-31 20:04:05 +01:00
|
|
|
//
|
|
|
|
// 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)
|
|
|
|
//
|
2024-01-22 00:15:26 +01:00
|
|
|
#include "td/telegram/net/PublicRsaKeySharedMain.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
2019-04-21 01:24:51 +02:00
|
|
|
#include "td/utils/format.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
#include "td/utils/Slice.h"
|
2021-05-17 14:21:11 +02:00
|
|
|
#include "td/utils/SliceBuilder.h"
|
2018-12-31 20:04:05 +01:00
|
|
|
|
|
|
|
namespace td {
|
2018-02-03 13:58:18 +01:00
|
|
|
|
2024-01-22 00:52:58 +01:00
|
|
|
std::shared_ptr<PublicRsaKeySharedMain> PublicRsaKeySharedMain::create(bool is_test) {
|
|
|
|
auto add_pem = [](vector<RsaKey> &keys, CSlice pem) {
|
|
|
|
auto rsa = mtproto::RSA::from_pem_public_key(pem).move_as_ok();
|
|
|
|
auto fingerprint = rsa.get_fingerprint();
|
|
|
|
keys.push_back(RsaKey{std::move(rsa), fingerprint});
|
2018-12-31 20:04:05 +01:00
|
|
|
};
|
2019-01-02 00:43:37 +01:00
|
|
|
|
|
|
|
if (is_test) {
|
2024-01-22 00:52:58 +01:00
|
|
|
static auto test_public_rsa_key = [&] {
|
|
|
|
vector<RsaKey> keys;
|
|
|
|
add_pem(keys,
|
|
|
|
"-----BEGIN RSA PUBLIC KEY-----\n"
|
|
|
|
"MIIBCgKCAQEAyMEdY1aR+sCR3ZSJrtztKTKqigvO/vBfqACJLZtS7QMgCGXJ6XIR\n"
|
|
|
|
"yy7mx66W0/sOFa7/1mAZtEoIokDP3ShoqF4fVNb6XeqgQfaUHd8wJpDWHcR2OFwv\n"
|
|
|
|
"plUUI1PLTktZ9uW2WE23b+ixNwJjJGwBDJPQEQFBE+vfmH0JP503wr5INS1poWg/\n"
|
|
|
|
"j25sIWeYPHYeOrFp/eXaqhISP6G+q2IeTaWTXpwZj4LzXq5YOpk4bYEQ6mvRq7D1\n"
|
|
|
|
"aHWfYmlEGepfaYR8Q0YqvvhYtMte3ITnuSJs171+GDqpdKcSwHnd6FudwGO4pcCO\n"
|
|
|
|
"j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB\n"
|
|
|
|
"-----END RSA PUBLIC KEY-----");
|
|
|
|
return std::make_shared<PublicRsaKeySharedMain>(std::move(keys));
|
|
|
|
}();
|
|
|
|
return test_public_rsa_key;
|
|
|
|
} else {
|
|
|
|
static auto main_public_rsa_key = [&] {
|
|
|
|
vector<RsaKey> keys;
|
|
|
|
add_pem(keys,
|
|
|
|
"-----BEGIN RSA PUBLIC KEY-----\n"
|
|
|
|
"MIIBCgKCAQEA6LszBcC1LGzyr992NzE0ieY+BSaOW622Aa9Bd4ZHLl+TuFQ4lo4g\n"
|
|
|
|
"5nKaMBwK/BIb9xUfg0Q29/2mgIR6Zr9krM7HjuIcCzFvDtr+L0GQjae9H0pRB2OO\n"
|
|
|
|
"62cECs5HKhT5DZ98K33vmWiLowc621dQuwKWSQKjWf50XYFw42h21P2KXUGyp2y/\n"
|
|
|
|
"+aEyZ+uVgLLQbRA1dEjSDZ2iGRy12Mk5gpYc397aYp438fsJoHIgJ2lgMv5h7WY9\n"
|
|
|
|
"t6N/byY9Nw9p21Og3AoXSL2q/2IJ1WRUhebgAdGVMlV1fkuOQoEzR7EdpqtQD9Cs\n"
|
|
|
|
"5+bfo3Nhmcyvk5ftB0WkJ9z6bNZ7yxrP8wIDAQAB\n"
|
|
|
|
"-----END RSA PUBLIC KEY-----");
|
|
|
|
return std::make_shared<PublicRsaKeySharedMain>(std::move(keys));
|
|
|
|
}();
|
|
|
|
return main_public_rsa_key;
|
2019-01-02 00:43:37 +01:00
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2024-01-22 00:15:26 +01:00
|
|
|
Result<mtproto::PublicRsaKeyInterface::RsaKey> PublicRsaKeySharedMain::get_rsa_key(const vector<int64> &fingerprints) {
|
2018-12-31 20:04:05 +01:00
|
|
|
for (auto fingerprint : fingerprints) {
|
2024-01-22 00:52:58 +01:00
|
|
|
for (const auto &key : keys_) {
|
|
|
|
if (key.fingerprint == fingerprint) {
|
|
|
|
return RsaKey{key.rsa.clone(), fingerprint};
|
|
|
|
}
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
}
|
2019-04-21 01:24:51 +02:00
|
|
|
return Status::Error(PSLICE() << "Unknown fingerprints " << format::as_array(fingerprints));
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
2024-01-22 00:15:26 +01:00
|
|
|
void PublicRsaKeySharedMain::drop_keys() {
|
|
|
|
// nothing to do
|
2018-12-31 20:04:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace td
|