Files
whitebox/api/license_whitebox_sign_renewal_request_test.cc
Aaron Vaage 77f7ef98c0 Initial Code Drop
This is the initial code drop of the reference implementation and
test cases for the Widevine Whitebox API.

In this drop, the full reference implementation for the AEAD
white-box is provided and all test cases verifying the top-level
behave have are enabled. Since the implementations can vary so much
the testing is mostly left to verifying the return codes for specific
parameter conditions.

A full reference implementation for the license white-box is provided,
however not all tests are implemented or enabled. A number of tests
have been disabled as they required a loaded license and test licenses
are still being worked on.

The two license white-box API functions that are the further from
competition are ProcessLicenseResponse() and MaskedDecryt().
ProcessLicenseResponse() is still being worked on and MaskedDecrypt()
is waiting on Decrypt() to be fully functional.

Most tests focus on verifying return code for specific parameter
conditions, but as test licenses are created, tests looking to test
the internal behaviour of license management will be added to
ProcessLicenseResponse(), Decrypt(), and MaskedDecrypt().
2020-05-18 19:45:53 -07:00

150 lines
5.0 KiB
C++

// Copyright 2020 Google LLC. All Rights Reserved.
#include "api/license_whitebox.h"
#include <memory>
#include <string>
#include <vector>
#include "api/test_data.h"
#include "testing/include/gtest/gtest.h"
namespace {
const uint8_t kDummyMessage[] = {
0x1e, 0x70, 0xbd, 0xeb, 0x24, 0xf2, 0x9d, 0x05, 0xc5, 0xb5,
0xf4, 0xca, 0xe6, 0x1d, 0x01, 0x97, 0x29, 0xf4, 0xe0, 0x7c,
0xfd, 0xcc, 0x97, 0x8d, 0xc2, 0xbb, 0x2d, 0x9b, 0x6b, 0x45,
0x06, 0xbd, 0x2c, 0x66, 0x10, 0x42, 0x73, 0x8d, 0x88, 0x9b,
0x18, 0xcc, 0xcb, 0x7e, 0x43, 0x23, 0x06, 0xe9, 0x8f, 0x8f,
};
const size_t kDummyMessageSize = sizeof(kDummyMessage);
// Size of a license signature. This must be big enough to hold the signature
// returned by WB_License_SignRenewalRequest().
constexpr size_t kSignatureSize = 256;
// These tests assume that WB_License_Create() and
// WB_License_ProcessLicenseResponse() work as all tests will require a valid
// white-box instance with a valid license already loaded.
class LicenseWhiteboxSignRenewalRequestTest : public ::testing::Test {
protected:
void SetUp() override {
const std::vector<uint8_t> init_data_ = GetLicenseInitData();
ASSERT_EQ(
WB_License_Create(init_data_.data(), init_data_.size(), &whitebox_),
WB_RESULT_OK);
}
void TearDown() override { WB_License_Delete(whitebox_); }
void LoadLicense() {
// TODO: Load the license here. It would be nice if we could do it in
// SetUp(), but since we need to support the WB_RESULT_INVALID_STATE test
// case, we need a way to not load a license.
}
WB_License_Whitebox* whitebox_ = nullptr;
};
// TODO: Implement the success test case (ideally with a real renewal request).
TEST_F(LicenseWhiteboxSignRenewalRequestTest, InvalidParameterForNullWhitebox) {
LoadLicense();
size_t signature_size = kSignatureSize;
std::vector<uint8_t> signature(signature_size);
ASSERT_EQ(
WB_License_SignRenewalRequest(nullptr, kDummyMessage, kDummyMessageSize,
signature.data(), &signature_size),
WB_RESULT_INVALID_PARAMETER);
}
TEST_F(LicenseWhiteboxSignRenewalRequestTest, InvalidParameterForNullMessage) {
LoadLicense();
size_t signature_size = kSignatureSize;
std::vector<uint8_t> signature(signature_size);
ASSERT_EQ(WB_License_SignRenewalRequest(whitebox_, nullptr, kDummyMessageSize,
signature.data(), &signature_size),
WB_RESULT_INVALID_PARAMETER);
}
TEST_F(LicenseWhiteboxSignRenewalRequestTest,
InvalidParameterForZeroMessageSize) {
LoadLicense();
size_t signature_size = kSignatureSize;
std::vector<uint8_t> signature(signature_size);
ASSERT_EQ(WB_License_SignRenewalRequest(whitebox_, kDummyMessage, 0,
signature.data(), &signature_size),
WB_RESULT_INVALID_PARAMETER);
}
TEST_F(LicenseWhiteboxSignRenewalRequestTest,
InvalidParameterForNullSignature) {
LoadLicense();
size_t signature_size = kSignatureSize;
ASSERT_EQ(
WB_License_SignRenewalRequest(whitebox_, kDummyMessage, kDummyMessageSize,
nullptr, &signature_size),
WB_RESULT_INVALID_PARAMETER);
}
TEST_F(LicenseWhiteboxSignRenewalRequestTest,
InvalidParameterForNullSignatureSize) {
LoadLicense();
size_t signature_size = kSignatureSize;
std::vector<uint8_t> signature(signature_size);
ASSERT_EQ(
WB_License_SignRenewalRequest(whitebox_, kDummyMessage, kDummyMessageSize,
signature.data(), nullptr),
WB_RESULT_INVALID_PARAMETER);
}
TEST_F(LicenseWhiteboxSignRenewalRequestTest, BufferTooSmall) {
// TODO: This test must be skipped as the "too small" check takes place after
// we check for a key.
GTEST_SKIP();
LoadLicense();
// We need the signature to be too small. While it would be possible to use
// zero, using a non-zero value ensures that we are not combining "empty" and
// "too small".
size_t signature_size = 1;
std::vector<uint8_t> signature(signature_size);
ASSERT_EQ(
WB_License_SignRenewalRequest(whitebox_, kDummyMessage, kDummyMessageSize,
signature.data(), &signature_size),
WB_RESULT_BUFFER_TOO_SMALL);
// Since the API does not limit the signature size, we can't specify the
// actual expected size, however, it should at least be greater than our "too
// small" size.
ASSERT_GT(signature_size, 1);
}
TEST_F(LicenseWhiteboxSignRenewalRequestTest, InvalidState) {
// Unlike the other tests, we do not call LoadLicense() because we need to
// have no license loaded in order to have no renewal key, which is the
// criteria WB_RESULT_INVALID_STATE.
size_t signature_size = kSignatureSize;
std::vector<uint8_t> signature(signature_size);
ASSERT_EQ(
WB_License_SignRenewalRequest(whitebox_, kDummyMessage, kDummyMessageSize,
signature.data(), &signature_size),
WB_RESULT_INVALID_STATE);
}
} // namespace