Source release 15.0.0
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
// OEMCrypto unit tests
|
||||
//
|
||||
#include <openssl/rsa.h>
|
||||
#include <time.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -27,6 +28,7 @@ void PrintTo(const vector<uint8_t>& value, ostream* os);
|
||||
|
||||
namespace wvoec {
|
||||
|
||||
// Make sure this is larger than kMaxKeysPerSession, in oemcrypto_test.cpp
|
||||
const size_t kMaxNumKeys = 20;
|
||||
|
||||
namespace {
|
||||
@@ -61,7 +63,6 @@ const int kDefaultKeyIdLength = 16;
|
||||
const size_t kMaxTestRSAKeyLength = 2000; // Rough estimate.
|
||||
const size_t kMaxPSTLength = 255; // In specification.
|
||||
const size_t kMaxMessageSize = 8 * 1024; // In specification.
|
||||
const size_t kMaxDecryptSize = 100 * 1024; // In specification.
|
||||
|
||||
typedef struct {
|
||||
uint8_t key_id[kTestKeyIdMaxLength];
|
||||
@@ -125,6 +126,13 @@ uint32_t htonl_fnc(uint32_t x);
|
||||
// Prints error string from BoringSSL
|
||||
void dump_boringssl_error();
|
||||
|
||||
// Given a message and field, returns an OEMCrypto_Substring with the field's
|
||||
// offset into the message and its length. If |set_zero| is true, both the
|
||||
// offset and length will be zero.
|
||||
OEMCrypto_Substring GetSubstring(const std::string& message = "",
|
||||
const std::string& field = "",
|
||||
bool set_zero = false);
|
||||
|
||||
class Session {
|
||||
public:
|
||||
Session();
|
||||
@@ -165,12 +173,12 @@ class Session {
|
||||
// using OEMCrypto_LoadKeys. This message should have already been created
|
||||
// by FillSimpleEntitlementMessage, modified if needed, and then encrypted
|
||||
// and signed by the server's mac key in EncryptAndSign.
|
||||
void LoadEnitlementTestKeys(const std::string& pst = "",
|
||||
void LoadEntitlementTestKeys(const std::string& pst = "",
|
||||
bool new_mac_keys = true,
|
||||
OEMCryptoResult expected_sts = OEMCrypto_SUCCESS);
|
||||
// Fills an OEMCrypto_EntitledContentKeyObject using the information from
|
||||
// the license_ and randomly generated content keys. This method should be
|
||||
// called after LoadEnitlementTestKeys.
|
||||
// called after LoadEntitlementTestKeys.
|
||||
void FillEntitledKeyArray();
|
||||
// Encrypts and loads the entitled content keys via
|
||||
// OEMCrypto_LoadEntitledContentKeys.
|
||||
@@ -196,7 +204,7 @@ class Session {
|
||||
const std::string& pst = "");
|
||||
// This fills the data structure license_ with entitlement key information.
|
||||
// This data can be modified, and then should be encrypted and signed in
|
||||
// EncryptAndSign before being loaded in LoadEnitlementTestKeys.
|
||||
// EncryptAndSign before being loaded in LoadEntitlementTestKeys.
|
||||
void FillSimpleEntitlementMessage(
|
||||
uint32_t duration, uint32_t control,
|
||||
uint32_t nonce, const std::string& pst = "");
|
||||
@@ -205,6 +213,11 @@ class Session {
|
||||
// is just signed. The signature is computed in RefreshTestKeys, above.
|
||||
void FillRefreshMessage(size_t key_count, uint32_t control_bits,
|
||||
uint32_t nonce);
|
||||
// Sets the OEMCrypto_Substring parameters of the LoadKeys method.
|
||||
// Specifically, it sets the |enc_mac_keys_iv|, |enc_mac_keys|, |pst|, and
|
||||
// |srm_restriction_data| in that order. For testing purposes,
|
||||
// |srm_restriction_data| will always be NULL.
|
||||
void SetLoadKeysSubstringParams();
|
||||
// This copies data from license_ to encrypted_license_, and then encrypts
|
||||
// each field in the key array appropriately. It then signes the buffer with
|
||||
// the server mac keys. It then fills out the key_array_ so that pointers in
|
||||
@@ -364,6 +377,12 @@ class Session {
|
||||
|
||||
// An array of key objects for use in LoadKeys.
|
||||
OEMCrypto_KeyObject* key_array() { return key_array_; }
|
||||
|
||||
// An array of key objects for LoadEntitledContentKeys.
|
||||
OEMCrypto_EntitledContentKeyObject* entitled_key_array() {
|
||||
return entitled_key_array_;
|
||||
}
|
||||
|
||||
// The last signature generated with the server's mac key.
|
||||
std::vector<uint8_t>& signature() { return signature_; }
|
||||
|
||||
@@ -380,6 +399,19 @@ class Session {
|
||||
// The size of the encrypted message.
|
||||
size_t message_size() { return message_size_; }
|
||||
|
||||
// The OEMCrypto_Substrings associated with the encrypted license that are
|
||||
// passed to LoadKeys.
|
||||
vector<OEMCrypto_Substring> load_keys_params() { return load_keys_params_; }
|
||||
OEMCrypto_Substring enc_mac_keys_iv_substr() { return load_keys_params_[0]; }
|
||||
OEMCrypto_Substring enc_mac_keys_substr() { return load_keys_params_[1]; }
|
||||
OEMCrypto_Substring pst_substr() { return load_keys_params_[2]; }
|
||||
OEMCrypto_Substring srm_restriction_data_substr() {
|
||||
return load_keys_params_[3];
|
||||
}
|
||||
|
||||
// Pointer to buffer holding |encrypted_entitled_message_|
|
||||
const uint8_t* encrypted_entitled_message_ptr();
|
||||
|
||||
private:
|
||||
// Generate mac and enc keys give the master key.
|
||||
void DeriveKeys(const uint8_t* master_key,
|
||||
@@ -404,6 +436,7 @@ class Session {
|
||||
} padded_message_;
|
||||
size_t message_size_; // How much of the padded message to use.
|
||||
OEMCrypto_KeyObject key_array_[kMaxNumKeys];
|
||||
vector<OEMCrypto_Substring> load_keys_params_;
|
||||
std::vector<uint8_t> signature_;
|
||||
unsigned int num_keys_;
|
||||
vector<uint8_t> encrypted_usage_entry_;
|
||||
@@ -413,8 +446,11 @@ class Session {
|
||||
// Clear Entitlement key data. This is the backing data for
|
||||
// |entitled_key_array_|.
|
||||
EntitledContentKeyData entitled_key_data_[kMaxNumKeys];
|
||||
// Message containing data from |key_array| and |entitled_key_data_|.
|
||||
std::string entitled_message_;
|
||||
// Entitled key object. Pointers are backed by |entitled_key_data_|.
|
||||
OEMCrypto_EntitledContentKeyObject entitled_key_array_[kMaxNumKeys];
|
||||
std::string encrypted_entitled_message_;
|
||||
};
|
||||
|
||||
} // namespace wvoec
|
||||
|
||||
Reference in New Issue
Block a user