Certificate provisioning verification

bug: 8620943

This is a merge of changes made to the Widevine CDM
repository during certificate provisioning verification.

The following changes are included:

Fixes for certificate based licensing
https://widevine-internal-review.googlesource.com/#/c/5162/

Base64 encode and decode now handles non-multiple of 24-bits input
https://widevine-internal-review.googlesource.com/#/c/4981/

Fixed issues with device provisioning response handling
https://widevine-internal-review.googlesource.com/#/c/5153/

Persistent storage to support device certificates
https://widevine-internal-review.googlesource.com/#/c/5161/

Enable loading of certificates
https://widevine-internal-review.googlesource.com/#/c/5172/

Provide license server url
https://widevine-internal-review.googlesource.com/#/c/5173/

Change-Id: I0c032c1ae0055dcc1a7a77ad4b0ea0898030dc7d
This commit is contained in:
Jeff Tinker
2013-04-22 20:05:55 -07:00
parent 3a28eeeb68
commit 958bbe6d05
30 changed files with 1497 additions and 290 deletions

View File

@@ -3,13 +3,13 @@
#ifndef CDM_BASE_CDM_ENGINE_H_
#define CDM_BASE_CDM_ENGINE_H_
#include "crypto_engine.h"
#include "timer.h"
#include "wv_cdm_types.h"
namespace wvcdm {
class CdmSession;
class CryptoEngine;
class WvCdmEventListener;
typedef std::map<CdmSessionId, CdmSession*> CdmSessionMap;
@@ -32,13 +32,11 @@ class CdmEngine : public TimerHandler {
const CdmInitData& init_data,
const CdmLicenseType license_type,
CdmAppParameterMap& app_parameters,
CdmKeyMessage* key_request);
CdmKeyMessage* key_request,
std::string* server_url);
// Accept license response and extract key info.
CdmResponseType AddKey(const CdmSessionId& session_id,
bool is_key_system_init_data_present,
const CdmKeySystem& key_system,
const CdmInitData& init_data,
const CdmKeyResponse& key_data);
// Cancel session and unload keys.
@@ -48,16 +46,11 @@ class CdmEngine : public TimerHandler {
// Construct valid renewal request for the current session keys.
CdmResponseType GenerateRenewalRequest(const CdmSessionId& session_id,
bool is_key_system_init_data_present,
const CdmKeySystem& key_system,
const CdmInitData& init_data,
CdmKeyMessage* key_request);
CdmKeyMessage* key_request,
std::string* server_url);
// Accept renewal response and update key info.
CdmResponseType RenewKey(const CdmSessionId& session_id,
bool is_key_system_init_data_present,
const CdmKeySystem& key_system,
const CdmInitData& init_data,
const CdmKeyResponse& key_data);
// Query system information
@@ -107,9 +100,7 @@ class CdmEngine : public TimerHandler {
// private methods
// Cancel all sessions
bool CancelSessions();
void CleanupProvisioingSessions(CdmSession* cdm_session,
CryptoEngine* crypto_engine,
const CdmSessionId& cdm_session_id);
void CleanupProvisioningSession(const CdmSessionId& cdm_session_id);
void ComposeJsonRequest(const std::string& message,
const std::string& signature,
CdmProvisioningRequest* request);
@@ -131,6 +122,7 @@ class CdmEngine : public TimerHandler {
virtual void OnTimerEvent();
// instance variables
CdmSession* provisioning_session_;
CdmSessionMap sessions_;
// policy timer

View File

@@ -36,7 +36,8 @@ class CdmSession {
CdmResponseType GenerateKeyRequest(const CdmInitData& pssh_data,
const CdmLicenseType license_type,
CdmAppParameterMap& app_parameters,
CdmKeyMessage* key_request);
CdmKeyMessage* key_request,
std::string* server_url);
// AddKey() - Accept license response and extract key info.
CdmResponseType AddKey(const CdmKeyResponse& key_response);
@@ -65,7 +66,8 @@ class CdmSession {
// License renewal
// GenerateRenewalRequest() - Construct valid renewal request for the current
// session keys.
CdmResponseType GenerateRenewalRequest(CdmKeyMessage* key_request);
CdmResponseType GenerateRenewalRequest(CdmKeyMessage* key_request,
std::string* server_url);
// RenewKey() - Accept renewal response and update key info.
CdmResponseType RenewKey(const CdmKeyResponse& key_response);

View File

@@ -56,10 +56,11 @@ class CryptoSession {
bool GenerateSignature(const std::string& message,
std::string* signature);
bool RewrapDeviceRSAKey(const std::string& message,
const uint32_t* nonce,
const uint8_t* enc_rsa_key,
const std::string& signature,
const std::string& nonce,
const std::string& enc_rsa_key,
size_t enc_rsa_key_length,
const uint8_t* enc_rsa_key_iv,
const std::string& rsa_key_iv,
uint8_t* wrapped_rsa_key,
size_t* wrapped_rsa_key_length);

View File

@@ -0,0 +1,33 @@
// Copyright 2013 Google Inc. All Rights Reserved.
//
#ifndef CDM_BASE_DEVICE_FILES_H_
#define CDM_BASE_DEVICE_FILES_H_
#include "wv_cdm_types.h"
namespace wvcdm {
class DeviceFiles {
public:
static bool StoreCertificate(const std::string& certificate,
const std::string& wrapped_private_key);
static bool RetrieveCertificate(std::string* certificate,
std::string* wrapped_private_key);
static std::string GetPath(const char* dir, const char * filename);
static const char* kBasePath;
static const char* kIdmPath;
static const char* kCencPath;
static const char* kDeviceCertificateFileName;
private:
static bool Hash(const std::string& data, std::string* hash);
static bool StoreFile(const char* name, const std::string& data);
static bool RetrieveFile(const char* name, std::string* data);
CORE_DISALLOW_COPY_AND_ASSIGN(DeviceFiles);
}; // namespace wvcdm
}
#endif // CDM_BASE_DEVICE_FILES_H_

View File

@@ -0,0 +1,52 @@
// Copyright 2013 Google Inc. All Rights Reserved.
//
// File - Platform independent interface for a File class
//
#ifndef CDM_BASE_FILE_STORE_H_
#define CDM_BASE_FILE_STORE_H_
#include "wv_cdm_types.h"
namespace wvcdm {
// File class. The implementation is platform dependent.
class File {
public:
// defines as bit flag
enum OpenFlags {
kNoFlags = 0,
kBinary = 1,
kCreate = 2,
kReadOnly = 4, // defauts to read and write access
kTruncate = 8
};
File();
File(const std::string& file_path, int flags);
virtual ~File();
bool Open(const std::string& file_path, int flags);
void Close();
bool IsOpen();
bool IsBad();
ssize_t Read(void *buf, size_t bytes);
ssize_t Write(const void* buf, size_t bytes);
static bool Exists(const std::string& file_path);
static bool Remove(const std::string& file_path);
static bool CreateDirectory(const std::string dir_path);
static bool IsDirectory(const std::string& dir_path);
static bool IsRegularFile(const std::string& file_path);
static ssize_t FileSize(const std::string& file_path);
private:
class Impl;
Impl *impl_;
CORE_DISALLOW_COPY_AND_ASSIGN(File);
};
} // namespace wvcdm
#endif // CDM_BASE_FILE_STORE_H_

View File

@@ -27,8 +27,10 @@ class CdmLicense {
bool PrepareKeyRequest(const CdmInitData& pssh_data,
const CdmLicenseType license_type,
CdmAppParameterMap& app_parameters,
CdmKeyMessage* signed_request);
bool PrepareKeyRenewalRequest(CdmKeyMessage* signed_request);
CdmKeyMessage* signed_request,
std::string* server_url);
bool PrepareKeyRenewalRequest(CdmKeyMessage* signed_request,
std::string* server_url);
CdmResponseType HandleKeyResponse(const CdmKeyResponse& license_response);
CdmResponseType HandleKeyRenewalResponse(
const CdmKeyResponse& license_response);
@@ -39,6 +41,7 @@ private:
LicenseIdentification license_id_;
CryptoSession* session_;
PolicyEngine* policy_engine_;
std::string server_url_;
std::string token_;
// Used for certificate based licensing