Commit 9436d074 authored by Josh Nohle's avatar Josh Nohle Committed by Commit Bot

[Nearby] Base64 encode certificate IDs in query parameters

The ListPublicCertificates HTTP GET request has the option of including
the IDs of certificates that the user already has. These certificates
will not be returned by the server.

The certificate ID is a byte field in the proto, and One Platform
requires that byte fields be base64 encoded before being added to the
URL's query parameters
(https://developers.google.com/protocol-buffers/docs/proto3#json).
Otherwise we get "Bad Request" errors in the HTTP response body like
"Invalid value at 'secret_ids' (TYPE_BYTES), Base64 decoding failed
for...".

Fixed: 1128021
Change-Id: Icef3d04456de40a7207aba0ed64eda8f1438c675
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410578
Auto-Submit: Josh Nohle <nohle@chromium.org>
Commit-Queue: James Vecore <vecore@google.com>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#806919}
parent a1e2ad67
......@@ -6,6 +6,7 @@
#include <memory>
#include "base/base64url.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/memory/ptr_util.h"
......@@ -83,8 +84,12 @@ ListPublicCertificatesRequestToQueryParameters(
if (!request.page_token().empty()) {
query_parameters.emplace_back(kPageToken, request.page_token());
}
for (int i = 0; i < request.secret_ids_size(); ++i) {
query_parameters.emplace_back(kSecretIds, request.secret_ids(i));
for (const std::string& id : request.secret_ids()) {
// NOTE: One Platform requires that byte fields be URL-safe base64 encoded.
std::string encoded_id;
base::Base64UrlEncode(id, base::Base64UrlEncodePolicy::INCLUDE_PADDING,
&encoded_id);
query_parameters.emplace_back(kSecretIds, encoded_id);
}
return query_parameters;
}
......
......@@ -52,6 +52,8 @@ const char kPhoneNumber1[] = "1231231234";
const char kPublicKey1[] = "publickey1";
const char kSecretId1[] = "secretid1";
const char kSecretId2[] = "secretid2";
const char kSecretId1Encoded[] = "c2VjcmV0aWQx";
const char kSecretId2Encoded[] = "c2VjcmV0aWQy";
const char kSecretKey1[] = "secretkey1";
const char kTestGoogleApisUrl[] = "https://nearbysharing-pa.testgoogleapis.com";
const int32_t kNanos1 = 123123123;
......@@ -688,7 +690,7 @@ TEST_F(NearbyShareClientImplTest, ListPublicCertificatesSuccess) {
std::vector<std::string>{kPageToken1},
ExpectQueryStringValues(request_as_query_parameters(), "page_token"));
EXPECT_EQ(
(std::vector<std::string>{kSecretId1, kSecretId2}),
(std::vector<std::string>{kSecretId1Encoded, kSecretId2Encoded}),
ExpectQueryStringValues(request_as_query_parameters(), "secret_ids"));
nearbyshare::proto::ListPublicCertificatesResponse response_proto;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment