This updates the partner repo to match the internal version, including the following changes: - Adds a WB_RESULT_NOT_IMPLEMENTED error code - Add a flag to control new features (e.g. entitlement support). - Updates tests to match new expectations
80 lines
2.5 KiB
C++
80 lines
2.5 KiB
C++
// Copyright 2021 Google LLC. All Rights Reserved.
|
|
|
|
#include "api/license_whitebox.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "api/golden_data.h"
|
|
#include "api/license_whitebox_test_base.h"
|
|
#include "api/test_license_builder.h"
|
|
#include "testing/gmock/include/gmock/gmock-matchers.h"
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
namespace widevine {
|
|
|
|
class LicenseWhiteboxEntitlementContentKeyTest
|
|
: public LicenseWhiteboxTestBase {
|
|
protected:
|
|
void SetUp() {
|
|
LicenseWhiteboxTestBase::SetUp();
|
|
server_ = TestServer::CreateDualKey();
|
|
|
|
TestLicenseBuilder builder;
|
|
builder.AddSigningKey(TestLicenseBuilder::DefaultSigningKey());
|
|
builder.AddEntitlementKey(
|
|
golden_data_.EntitlementContent().entitlement_key);
|
|
builder.Build(*server_, &license_);
|
|
}
|
|
|
|
std::unique_ptr<TestServer> server_;
|
|
License license_;
|
|
};
|
|
|
|
TEST_F(LicenseWhiteboxEntitlementContentKeyTest, Decrypt) {
|
|
auto result = WB_License_ProcessLicenseResponse(
|
|
whitebox_, WB_LICENSE_KEY_MODE_DUAL_KEY, 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());
|
|
#ifndef HAS_ENTITLEMENT
|
|
if (result == WB_RESULT_NOT_IMPLEMENTED)
|
|
GTEST_SKIP();
|
|
#endif
|
|
ASSERT_EQ(result, WB_RESULT_OK);
|
|
|
|
const KeyId key_id = golden_data_.GetFreeId();
|
|
auto& content = golden_data_.EntitlementContent();
|
|
result = WB_License_LoadEntitledContentKey(
|
|
whitebox_, content.entitlement_key.id.data(),
|
|
content.entitlement_key.id.size(), key_id.data(), key_id.size(),
|
|
content.key_data_iv.data(), content.key_data_iv.size(),
|
|
content.key_data.data(), content.key_data.size());
|
|
#ifndef HAS_ENTITLEMENT
|
|
if (result == WB_RESULT_NOT_IMPLEMENTED)
|
|
GTEST_SKIP();
|
|
#endif
|
|
ASSERT_EQ(result, WB_RESULT_OK);
|
|
|
|
std::vector<uint8_t> decrypted(content.plaintext.size());
|
|
size_t decrypted_size = decrypted.size();
|
|
ASSERT_EQ(WB_License_Decrypt(
|
|
whitebox_,
|
|
WB_CIPHER_MODE_CTR,
|
|
key_id.data(),
|
|
key_id.size(),
|
|
content.ciphertext.data(),
|
|
content.ciphertext.size(),
|
|
content.iv.data(),
|
|
content.iv.size(),
|
|
&decrypted[0],
|
|
&decrypted_size),
|
|
WB_RESULT_OK);
|
|
decrypted.resize(decrypted_size);
|
|
EXPECT_EQ(decrypted, content.plaintext);
|
|
}
|
|
|
|
} // namespace widevine
|