From ca4fe0ecb30fe01c5e047d88b428e50a53292352 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 13 Jan 2019 22:56:38 +0300 Subject: [PATCH] Support unencrypted pushes in getPushReceiverId. GitOrigin-RevId: f8404aec776934ae804f7b76dd8cbbe352ace50b --- td/telegram/NotificationManager.cpp | 16 +++++++++++++++- td/telegram/Td.cpp | 4 +++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/td/telegram/NotificationManager.cpp b/td/telegram/NotificationManager.cpp index 60784510..3521bb9c 100644 --- a/td/telegram/NotificationManager.cpp +++ b/td/telegram/NotificationManager.cpp @@ -2074,7 +2074,6 @@ void NotificationManager::process_push_notification(string payload, Promise NotificationManager::get_push_receiver_id(string payload) { - VLOG(notifications) << "Get push notification receiver ID of \"" << format::escaped(payload) << '"'; auto r_json_value = json_decode(payload); if (r_json_value.is_error()) { return Status::Error(400, "Failed to parse payload as JSON object"); @@ -2097,6 +2096,21 @@ Result NotificationManager::get_push_receiver_id(string payload) { } return as(data.data()); } + if (field_value.first == "user_id") { + auto user_id = std::move(field_value.second); + if (user_id.type() != JsonValue::Type::String && user_id.type() != JsonValue::Type::Number) { + return Status::Error(400, "Expected user_id as a String or a Number"); + } + Slice user_id_str = user_id.type() == JsonValue::Type::String ? user_id.get_string() : user_id.get_number(); + auto r_user_id = to_integer_safe(user_id_str); + if (r_user_id.is_error()) { + return Status::Error(400, PSLICE() << "Failed to get user_id from " << user_id_str); + } + if (r_user_id.ok() <= 0) { + return Status::Error(400, PSLICE() << "Receive wrong user_id " << user_id_str); + } + return static_cast(r_user_id.ok()); + } } return Status::Error(200, "Unsupported push notification"); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 4170dda6..6aca278e 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -7007,8 +7007,10 @@ td_api::object_ptr Td::do_static_request(const td_api::getLangua td_api::object_ptr Td::do_static_request(const td_api::getPushReceiverId &request) { // don't check push payload UTF-8 correctness - auto r_push_receiver_id = NotificationManager::get_push_receiver_id(std::move(request.payload_)); + auto r_push_receiver_id = NotificationManager::get_push_receiver_id(request.payload_); if (r_push_receiver_id.is_error()) { + VLOG(notifications) << "Failed to get push notification receiver from \"" << format::escaped(request.payload_) + << '"'; return make_error(r_push_receiver_id.error().code(), r_push_receiver_id.error().message()); } return td_api::make_object(r_push_receiver_id.ok());