* dss * first pass at a client and tests * constructors work * working request, need to fix the response parsing * basic tests working for service client * refactored the constructors * testproxy and tests * format file * got client and one API working * list working * all apis recorded * new assets.json * assets.json regen * format json * adding word to cspell * fix build issues * fix one more break * typo * clangs * one more issue * more fixezez * regen recordings * try again * clangs * clangs again * new assets * new test proxy * regen tests based on new merge * hmmm * restore * add debug env for test proxy * resync cmake presets from main * gor get and set working * get stats * table client and create * delete * get/set acls * list tables * some cleanup * Create /update/merge/delete * upsert * query entities * generated tests * clangs * some fixes * some more errors * cspells * got transaction API working * transactions working , need to parse response * get data out of the response * clangs * batch1 * regen tests * part 2 * batch3 * batch4 * clangs * regen tests * regen tests * try again * live only * added some more tests for the transaction body * small refactor for tests * oops * some oter update * darn includes * sddfsd * erorr fix * key clients * sas * small cleanup * All tests passing * test recordings * clangs * missing ENV for test * attempt1 * retry * couple recordings * regen some tests * clangs * again * again * comments * comments * headers and footers * some cleanjup * Move folders step1 * revert assets and test resources in storage * revert to main * cspell * readme * comments * revert ci.yml * liveonly test * clangs * camke * ci2 * try again * fdssfs * fdsfsd * some cleanup * dasda * dsdsds * asda * assets * comments * a few more bits and pieces * some other updates for cspell * typo * more docs * spell * another doc error * clangs docs * docs * test cov * dasdas * hg * stress test * cspell * Update sdk/storage/azure-storage-common/test/ut/CMakeLists.txt Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/storage/azure-storage-common/test/ut/shared_key_policy_lite_test.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/CHANGELOG.md Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/CMakeLists.txt Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/test/stress/scenarios-matrix.yaml Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/test/stress/Dockerfile Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * PR comments * respurces cleanup * cleanup 2 * respurce fix * revddrt * weqq * oops * try again * Update sdk/tables/azure-data-tables/vcpkg/vcpkg.json Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * try * test fix * samples * readmes * readmes * readmes * api view settings * qualify friends * try * moving usings * refactor for API View tool * some more * clangs * Update sdk/tables/README.md Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/core/azure-core/inc/azure/core/http/http.hpp Co-authored-by: Ahson Khan <ahkha@microsoft.com> * Update sdk/core/azure-core/src/http/transport_policy.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/inc/azure/data/tables/rest_client.hpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/CHANGELOG.md Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/test/ut/CMakeLists.txt Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/tables/azure-data-tables/src/rest_client.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * some comments * comments * comments part N * clang * try now * clang * comments * update file names * update test to check for the final signature * ccc * rename shared key policy lite * cleanup some includes * add a couple more tests * small update * clang * increase test limits * xml transition * service_version_policy * shared creds and key policy lite * switch to secondary policy * code done * remove last storage vestiges * put back some code * readme/changelog * Update sdk/tables/azure-data-tables/src/serializers.cpp Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Add the shared key policy for Larry * Larry comments * curlybracify the initializers * Update sdk/core/azure-core-xml/inc/azure/core/xml/dll_import_export.hpp Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Update sdk/core/azure-core-xml/vcpkg.json Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Update sdk/tables/azure-data-tables/inc/azure/data/tables.hpp Co-authored-by: Rick Winter <rick.winter@microsoft.com> * Rick's comments one more namespace change for serializers * whiteline * typo * oops * includes and clangs * cleanup * jhfjdhjfd * hjkjdhf * daas * Anton's comments * clang * revert some changes * fdss * Update sdk/core/azure-core-xml/CHANGELOG.md Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * everything works * clangs and vcpkg test * test remove azure-core-xml * vcpkg json * remove the code * merge main * saa * wqw * last comments * clang --------- Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> Co-authored-by: Ahson Khan <ahkha@microsoft.com> Co-authored-by: Rick Winter <rick.winter@microsoft.com>
91 lines
2.9 KiB
C++
91 lines
2.9 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "azure/data/tables/internal/policies/shared_key_policy.hpp"
|
|
|
|
#include "azure/data/tables/internal/cryptography/hmacsha256.hpp"
|
|
|
|
#include <azure/core/base64.hpp>
|
|
#include <azure/core/cryptography/hash.hpp>
|
|
#include <azure/core/http/http.hpp>
|
|
#include <azure/core/internal/strings.hpp>
|
|
|
|
#include <algorithm>
|
|
|
|
namespace Azure { namespace Data { namespace Tables { namespace _detail { namespace Policies {
|
|
|
|
std::string SharedKeyPolicy::GetSignature(const Core::Http::Request& request) const
|
|
{
|
|
std::string string_to_sign;
|
|
string_to_sign += request.GetMethod().ToString() + "\n";
|
|
|
|
const auto& headers = request.GetHeaders();
|
|
for (std::string headerName :
|
|
{"Content-Encoding",
|
|
"Content-Language",
|
|
"Content-Length",
|
|
"Content-MD5",
|
|
"Content-Type",
|
|
"Date",
|
|
"If-Modified-Since",
|
|
"If-Match",
|
|
"If-None-Match",
|
|
"If-Unmodified-Since",
|
|
"Range"})
|
|
{
|
|
auto ite = headers.find(headerName);
|
|
if (ite != headers.end())
|
|
{
|
|
if (headerName == "Content-Length" && ite->second == "0")
|
|
{
|
|
// do nothing
|
|
}
|
|
else
|
|
{
|
|
string_to_sign += ite->second;
|
|
}
|
|
}
|
|
string_to_sign += "\n";
|
|
}
|
|
|
|
// canonicalized headers
|
|
const std::string prefix = "x-ms-";
|
|
std::vector<std::pair<std::string, std::string>> ordered_kv;
|
|
for (auto ite = headers.lower_bound(prefix);
|
|
ite != headers.end() && ite->first.substr(0, prefix.length()) == prefix;
|
|
++ite)
|
|
{
|
|
std::string key = Azure::Core::_internal::StringExtensions::ToLower(ite->first);
|
|
ordered_kv.emplace_back(std::make_pair(std::move(key), ite->second));
|
|
}
|
|
std::sort(ordered_kv.begin(), ordered_kv.end());
|
|
for (const auto& p : ordered_kv)
|
|
{
|
|
string_to_sign += p.first + ":" + p.second + "\n";
|
|
}
|
|
ordered_kv.clear();
|
|
|
|
// canonicalized resource
|
|
string_to_sign += "/" + m_credential->AccountName + "/" + request.GetUrl().GetPath() + "\n";
|
|
for (const auto& query : request.GetUrl().GetQueryParameters())
|
|
{
|
|
std::string key = Azure::Core::_internal::StringExtensions::ToLower(query.first);
|
|
ordered_kv.emplace_back(
|
|
std::make_pair(Azure::Core::Url::Decode(key), Azure::Core::Url::Decode(query.second)));
|
|
}
|
|
std::sort(ordered_kv.begin(), ordered_kv.end());
|
|
for (const auto& p : ordered_kv)
|
|
{
|
|
string_to_sign += p.first + ":" + p.second + "\n";
|
|
}
|
|
|
|
// remove last linebreak
|
|
string_to_sign.pop_back();
|
|
|
|
return Azure::Core::Convert::Base64Encode(
|
|
Azure::Data::Tables::_detail::Cryptography::HmacSha256::Compute(
|
|
std::vector<uint8_t>(string_to_sign.begin(), string_to_sign.end()),
|
|
Azure::Core::Convert::Base64Decode(m_credential->GetAccountKey())));
|
|
}
|
|
}}}}} // namespace Azure::Data::Tables::_detail::Policies
|