Below are a set of CLs being merged from the wv cdm repo to the android repo. * Fix handling of OEM Cert public key. Author: Srujan Gaddam <srujzs@google.com> [ Merge of http://go/wvgerrit/27921 ] This is a potential fix for b/36656190. Set aside public key on first call to get the public key, and use it afterwards. This gets rid of extra calls to OEMCrypto_GetOEMPublicCertificate(), which has side-effect of staging the OEM private key. This also fixes a problem where the public cert string was not being trimmed to match the size returned by OEMCrypto_GetOEMPublicCertificate(). * Complete provisioning request/response for Provisioning 3.0 Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/27780 ] Fix bug on provisioning request path where GenerateDerivedKeys() was being called when preparing to generate the signature. Add message signature verification, and call correct OEMCrypto routine to rewrap the private key (OEMCrypto_RewrapDeviceRSAKey30). * Implement Cdm::deleteAllUsageRecords() Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/27780 ] Delete all usage records for current origin. Removes usage records from file system and retains the PSTs. The deletes any usage entries matching those PSTs held by OEMCrypto. BUG: 35319024 * Remove stringencoders library from third_party. Author: Jacob Trimble <modmaker@google.com> [ Merge of http://go/wvgerrit/27585 ] We have a fork of the stringencoders library that we use for base64 encoding. This reimplements base64 encoding to remove the extra dependency and to reduce the amount of code. * Add Cdm::deleteUsageRecord() based on key_set_id. Author: Gene Morgan <gmorgan@google.com> [ Merge of http://go/wvgerrit/27605 ] Delete specified usage record from file system usage info and from OEMCrypto. BUG: 35319024 * Modifiable OEMCrypto Author: Fred Gylys-Colwell <fredgc@google.com> [ Merge of http://go/wvgerrit/24729 ] This CL adds a new variant of the OEMCrypto mock code that adjusts its behavior based on a configuration file. This is intended for testing. For example, a tester can set current_hdcp to 2 in the options.txt file, push it to the device, and verify that a license is granted for HDCP 2.0. Then the tester can edit the value of current_hdcp to 1 and push the file to the device. Playback should stop because the license is no longer valid. This variant uses a real level 1 liboemcrypto.so to push data to a secure buffer. That means we can test playback for a license that requires secure buffers on an Android device with real secure buffers. BUG: 35141278 BUG: 37353534 BUG: 71650075 Test: Not currently passing. Will be addressed in a subsequent commit in the chain. Change-Id: I58443c510919e992bb455192e70373490a00e2b6
234 lines
8.6 KiB
C++
234 lines
8.6 KiB
C++
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
#ifndef WVCDM_CORE_CDM_SESSION_H_
|
|
#define WVCDM_CORE_CDM_SESSION_H_
|
|
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "crypto_session.h"
|
|
#include "device_files.h"
|
|
#include "file_store.h"
|
|
#include "initialization_data.h"
|
|
#include "license.h"
|
|
#include "metrics_group.h"
|
|
#include "oemcrypto_adapter.h"
|
|
#include "policy_engine.h"
|
|
#include "scoped_ptr.h"
|
|
#include "timer_metric.h"
|
|
#include "wv_cdm_types.h"
|
|
|
|
namespace wvcdm {
|
|
|
|
class CdmClientPropertySet;
|
|
class ServiceCertificate;
|
|
class WvCdmEventListener;
|
|
|
|
class CdmSession {
|
|
public:
|
|
CdmSession(FileSystem* file_system);
|
|
virtual ~CdmSession();
|
|
|
|
void Close() { closed_ = true; }
|
|
bool IsClosed() { return closed_; }
|
|
|
|
virtual CdmResponseType Init(CdmClientPropertySet* cdm_client_property_set);
|
|
virtual CdmResponseType Init(ServiceCertificate* service_certificate,
|
|
CdmClientPropertySet* cdm_client_property_set,
|
|
const CdmSessionId* forced_session_id,
|
|
WvCdmEventListener* event_listener);
|
|
|
|
virtual CdmResponseType RestoreOfflineSession(
|
|
const CdmKeySetId& key_set_id, const CdmLicenseType license_type);
|
|
virtual CdmResponseType RestoreUsageSession(
|
|
const CdmKeyMessage& key_request, const CdmKeyResponse& key_response);
|
|
|
|
virtual const CdmSessionId& session_id() { return session_id_; }
|
|
virtual const CdmKeySetId& key_set_id() { return key_set_id_; }
|
|
|
|
virtual CdmResponseType GenerateKeyRequest(
|
|
const InitializationData& init_data, CdmLicenseType license_type,
|
|
const CdmAppParameterMap& app_parameters, CdmKeyRequest* key_request);
|
|
|
|
// AddKey() - Accept license response and extract key info.
|
|
virtual CdmResponseType AddKey(const CdmKeyResponse& key_response);
|
|
|
|
// Query session status
|
|
virtual CdmResponseType QueryStatus(CdmQueryMap* query_response);
|
|
|
|
// Query license information
|
|
virtual CdmResponseType QueryKeyStatus(CdmQueryMap* query_response);
|
|
|
|
// Query allowed usages for key
|
|
virtual CdmResponseType QueryKeyAllowedUsage(const std::string& key_id,
|
|
CdmKeyAllowedUsage* key_usage);
|
|
|
|
// Query OEMCrypto session ID
|
|
virtual CdmResponseType QueryOemCryptoSessionId(CdmQueryMap* query_response);
|
|
|
|
// Decrypt() - Accept encrypted buffer and return decrypted data.
|
|
virtual CdmResponseType Decrypt(const CdmDecryptionParameters& parameters);
|
|
|
|
// License renewal
|
|
// GenerateRenewalRequest() - Construct valid renewal request for the current
|
|
// session keys.
|
|
virtual CdmResponseType GenerateRenewalRequest(CdmKeyRequest* key_request);
|
|
|
|
// RenewKey() - Accept renewal response and update key info.
|
|
virtual CdmResponseType RenewKey(const CdmKeyResponse& key_response);
|
|
|
|
// License release
|
|
// GenerateReleaseRequest() - Construct valid release request for the current
|
|
// session keys.
|
|
virtual CdmResponseType GenerateReleaseRequest(CdmKeyRequest* key_request);
|
|
|
|
// ReleaseKey() - Accept response and release key.
|
|
virtual CdmResponseType ReleaseKey(const CdmKeyResponse& key_response);
|
|
|
|
virtual bool IsKeyLoaded(const KeyId& key_id);
|
|
virtual int64_t GetDurationRemaining();
|
|
|
|
// Used for notifying the Policy Engine of resolution changes
|
|
virtual void NotifyResolution(uint32_t width, uint32_t height);
|
|
|
|
virtual void OnTimerEvent(bool update_usage);
|
|
virtual void OnKeyReleaseEvent(const CdmKeySetId& key_set_id);
|
|
|
|
virtual void GetApplicationId(std::string* app_id);
|
|
virtual SecurityLevel GetRequestedSecurityLevel() {
|
|
return requested_security_level_;
|
|
}
|
|
virtual CdmSecurityLevel GetSecurityLevel() { return security_level_; }
|
|
|
|
// Delete usage information for the list of tokens, |provider_session_tokens|.
|
|
virtual CdmResponseType DeleteMultipleUsageInformation(
|
|
const std::vector<std::string>& provider_session_tokens);
|
|
virtual CdmResponseType UpdateUsageInformation();
|
|
|
|
virtual bool is_initial_usage_update() { return is_initial_usage_update_; }
|
|
virtual bool is_usage_update_needed() { return is_usage_update_needed_; }
|
|
virtual void reset_usage_flags() {
|
|
is_initial_usage_update_ = false;
|
|
is_usage_update_needed_ = false;
|
|
}
|
|
|
|
virtual bool is_release() { return is_release_; }
|
|
virtual bool is_offline() { return is_offline_; }
|
|
virtual bool is_temporary() { return is_temporary_; }
|
|
virtual bool license_received() { return license_received_; }
|
|
|
|
// ReleaseCrypto() - Closes the underlying crypto session but leaves this
|
|
// object alive. It is invalid to call any method that requires a crypto
|
|
// session after calling this. Since calling this renders this object mostly
|
|
// useless, it is preferable to simply delete this object (which will also
|
|
// release the underlying crypto session) rather than call this method.
|
|
virtual CdmResponseType ReleaseCrypto();
|
|
|
|
// Delete current license and matching usage record
|
|
bool DeleteLicense();
|
|
|
|
// Generate unique ID for each new session.
|
|
CdmSessionId GenerateSessionId();
|
|
|
|
// Generic crypto operations - provides basic crypto operations that an
|
|
// application can use outside of content stream processing
|
|
|
|
// Encrypts a buffer of app-level data.
|
|
virtual CdmResponseType GenericEncrypt(const std::string& in_buffer,
|
|
const std::string& key_id,
|
|
const std::string& iv,
|
|
CdmEncryptionAlgorithm algorithm,
|
|
std::string* out_buffer);
|
|
|
|
// Decrypts a buffer of app-level data.
|
|
virtual CdmResponseType GenericDecrypt(const std::string& in_buffer,
|
|
const std::string& key_id,
|
|
const std::string& iv,
|
|
CdmEncryptionAlgorithm algorithm,
|
|
std::string* out_buffer);
|
|
|
|
// Computes the signature for a message.
|
|
virtual CdmResponseType GenericSign(const std::string& message,
|
|
const std::string& key_id,
|
|
CdmSigningAlgorithm algorithm,
|
|
std::string* signature);
|
|
|
|
// Verifies the signature on a buffer of app-level data.
|
|
virtual CdmResponseType GenericVerify(const std::string& message,
|
|
const std::string& key_id,
|
|
CdmSigningAlgorithm algorithm,
|
|
const std::string& signature);
|
|
|
|
virtual metrics::MetricsGroup* GetMetrics() { return &metrics_; }
|
|
|
|
private:
|
|
friend class CdmSessionTest;
|
|
|
|
bool GenerateKeySetId(CdmKeySetId* key_set_id);
|
|
|
|
CdmResponseType StoreLicense();
|
|
bool StoreLicense(DeviceFiles::LicenseState state);
|
|
|
|
// These setters are for testing only. Takes ownership of the pointers.
|
|
void set_license_parser(CdmLicense* license_parser);
|
|
void set_crypto_session(CryptoSession* crypto_session);
|
|
void set_policy_engine(PolicyEngine* policy_engine);
|
|
void set_file_handle(DeviceFiles* file_handle);
|
|
|
|
// instance variables
|
|
|
|
/*
|
|
* The metrics group must be the first variable declared to ensure
|
|
* that it is the last member destroyed so that no child members
|
|
* try to use a reference to it after it is destroyed. This will
|
|
* ensure that all data has been properly recorded in the group before
|
|
* it is published.
|
|
*/
|
|
metrics::MetricsGroup metrics_;
|
|
metrics::TimerMetric life_span_;
|
|
|
|
bool initialized_;
|
|
bool closed_; // Session closed, but final shared_ptr has not been released.
|
|
CdmSessionId session_id_;
|
|
scoped_ptr<CdmLicense> license_parser_;
|
|
scoped_ptr<CryptoSession> crypto_session_;
|
|
scoped_ptr<PolicyEngine> policy_engine_;
|
|
scoped_ptr<DeviceFiles> file_handle_;
|
|
bool license_received_;
|
|
bool is_offline_;
|
|
bool is_release_;
|
|
bool is_temporary_;
|
|
CdmSecurityLevel security_level_;
|
|
SecurityLevel requested_security_level_;
|
|
CdmAppParameterMap app_parameters_;
|
|
|
|
// decryption and usage flags
|
|
bool is_initial_decryption_;
|
|
bool has_decrypted_since_last_report_; // ... last report to policy engine.
|
|
bool is_initial_usage_update_;
|
|
bool is_usage_update_needed_;
|
|
|
|
// information useful for offline and usage scenarios
|
|
CdmKeyMessage key_request_;
|
|
CdmKeyResponse key_response_;
|
|
|
|
// license type offline related information
|
|
CdmInitData offline_init_data_;
|
|
CdmKeyMessage offline_key_renewal_request_;
|
|
CdmKeyResponse offline_key_renewal_response_;
|
|
std::string offline_release_server_url_;
|
|
|
|
// license type release and offline related information
|
|
CdmKeySetId key_set_id_;
|
|
|
|
bool mock_license_parser_in_use_;
|
|
bool mock_policy_engine_in_use_;
|
|
|
|
CORE_DISALLOW_COPY_AND_ASSIGN(CdmSession);
|
|
};
|
|
|
|
} // namespace wvcdm
|
|
|
|
#endif // WVCDM_CORE_CDM_SESSION_H_
|