Files
whitebox/whitebox/api/license_whitebox_sign_benchmark.cc
KongQun Yang d6ef4e1133 Update the test to support license protocol 2.2
- Add a flag ENABLE_LICENSE_PROTOCOL_2_2, when the flag is enabled
  - Hash the license request in WB_License_ProcessLicenseResponse, i.e.
    the request used for the key derivation, which ensures the key
    derivation message to be a string of constant size 64 bytes.
  - Hash the license request in WB_License_SignLicenseRequest. Note that
    the function takes license request (or hashed) + odk message as
    parameter for odk v17 or above.
- Enable the flag just for Chrome and ChromeOS for now.

We may change the implementation to hash inside the white-box in the
future.

Also included a few other misc changes, e.g. updating the DEPS of
boringssl and googletest which are already in the white-box directory,
adding a test main etc.
2023-03-29 19:20:23 +00:00

111 lines
3.4 KiB
C++

// Copyright 2020 Google LLC. All Rights Reserved.
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <vector>
#include "api/license_whitebox.h"
#include "api/license_whitebox_benchmark.h"
#include "api/license_whitebox_provider_keys_test_data.h"
#include "api/result.h"
#include "api/test_license_builder.h"
#include "benchmarking/data_source.h"
#include "benchmarking/measurements.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace widevine {
namespace {
constexpr size_t kMessageSize = 1024;
constexpr size_t kSignatureSize = 256;
constexpr size_t kIterations = 10;
} // namespace
class LicenseWhiteboxSignBenchmark
: public LicenseWhiteboxBenchmark,
public testing::WithParamInterface<WB_LicenseKeyMode> {
protected:
void SetUp() override {
LicenseWhiteboxBenchmark::SetUp();
message_ = Data().Get(kMessageSize);
signature_.resize(kSignatureSize);
key_mode_ = GetParam();
auto init_data = GetLicenseWhiteboxProviderKeysInitData();
ASSERT_EQ(WB_License_Create(init_data.data(), init_data.size(), &whitebox_),
WB_RESULT_OK);
const auto license = CreateLicense(
key_mode_, 1, SecurityLevel::kSoftwareSecureCrypto, kNoProviderKeyId);
ASSERT_EQ(WB_License_ProcessLicenseResponse(
whitebox_, key_mode_, license.core_message.data(),
license.core_message.size(), license.message.data(),
license.message.size(), license.signature.data(),
license.signature.size(), license.session_key.data(),
license.session_key.size(), kNoProviderKeyId,
license.request.data(), license.request.size()),
WB_RESULT_OK);
}
void TearDown() override { WB_License_Delete(whitebox_); }
// Tells which key mode to use for process license response. We need to test
// with both single-key and dual-key.
WB_LicenseKeyMode key_mode_;
WB_License_Whitebox* whitebox_;
std::vector<uint8_t> message_;
std::vector<uint8_t> signature_;
};
TEST_P(LicenseWhiteboxSignBenchmark, SignLicenseRequest) {
Timer timer;
Sampler sampler;
for (size_t i = 0; i < kIterations; i++) {
size_t signature_size = signature_.size();
timer.Reset();
ASSERT_EQ(WB_RESULT_OK, WB_License_SignLicenseRequest(
whitebox_, message_.data(), message_.size(),
signature_.data(), &signature_size));
sampler.Push(timer.Get());
}
PrettyPrint("License White-box Sign License Request Duration", sampler,
message_.size());
}
TEST_P(LicenseWhiteboxSignBenchmark, SignRenewalRequest) {
Timer timer;
Sampler sampler;
for (size_t i = 0; i < kIterations; i++) {
size_t signature_size = signature_.size();
timer.Reset();
ASSERT_EQ(WB_RESULT_OK, WB_License_SignRenewalRequest(
whitebox_, message_.data(), message_.size(),
signature_.data(), &signature_size));
sampler.Push(timer.Get());
}
PrettyPrint("License White-box Sign Renewal Request Duration", sampler,
message_.size());
}
INSTANTIATE_TEST_SUITE_P(SingleKey,
LicenseWhiteboxSignBenchmark,
::testing::Values(WB_LICENSE_KEY_MODE_SINGLE_KEY));
INSTANTIATE_TEST_SUITE_P(DualKey,
LicenseWhiteboxSignBenchmark,
::testing::Values(WB_LICENSE_KEY_MODE_DUAL_KEY));
} // namespace widevine