Merge changes Iea5df62b,I346c04a5
* changes: Do Not Add Parallel Unit Tests Split CryptoSession Lock into Three
This commit is contained in:
@@ -343,6 +343,7 @@ class CdmEngine {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class CdmEngineFactory;
|
friend class CdmEngineFactory;
|
||||||
|
friend class ParallelCdmTest;
|
||||||
friend class WvCdmEnginePreProvTest;
|
friend class WvCdmEnginePreProvTest;
|
||||||
friend class WvCdmTestBase;
|
friend class WvCdmTestBase;
|
||||||
friend class WvGenericOperationsTest;
|
friend class WvGenericOperationsTest;
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ class CryptoSession {
|
|||||||
HdcpCapability* max);
|
HdcpCapability* max);
|
||||||
virtual CdmResponseType GetHdcpCapabilities(SecurityLevel security_level,
|
virtual CdmResponseType GetHdcpCapabilities(SecurityLevel security_level,
|
||||||
HdcpCapability* current,
|
HdcpCapability* current,
|
||||||
HdcpCapability* max);
|
HdcpCapability* max);
|
||||||
virtual bool GetResourceRatingTier(uint32_t* tier);
|
virtual bool GetResourceRatingTier(uint32_t* tier);
|
||||||
virtual bool GetResourceRatingTier(SecurityLevel security_level,
|
virtual bool GetResourceRatingTier(SecurityLevel security_level,
|
||||||
uint32_t* tier);
|
uint32_t* tier);
|
||||||
@@ -180,11 +180,10 @@ class CryptoSession {
|
|||||||
virtual uint32_t IsDecryptHashSupported(SecurityLevel security_level);
|
virtual uint32_t IsDecryptHashSupported(SecurityLevel security_level);
|
||||||
|
|
||||||
virtual CdmResponseType SetDecryptHash(uint32_t frame_number,
|
virtual CdmResponseType SetDecryptHash(uint32_t frame_number,
|
||||||
const std::string& hash);
|
const std::string& hash);
|
||||||
|
|
||||||
virtual CdmResponseType GetDecryptHashError(std::string* error_string);
|
virtual CdmResponseType GetDecryptHashError(std::string* error_string);
|
||||||
|
|
||||||
|
|
||||||
virtual CdmResponseType GenericEncrypt(const std::string& in_buffer,
|
virtual CdmResponseType GenericEncrypt(const std::string& in_buffer,
|
||||||
const std::string& key_id,
|
const std::string& key_id,
|
||||||
const std::string& iv,
|
const std::string& iv,
|
||||||
@@ -257,6 +256,7 @@ class CryptoSession {
|
|||||||
// OEMCrypto to use a test keybox.
|
// OEMCrypto to use a test keybox.
|
||||||
// Ownership of the object is transfered to CryptoSession.
|
// Ownership of the object is transfered to CryptoSession.
|
||||||
static void SetCryptoSessionFactory(CryptoSessionFactory* factory) {
|
static void SetCryptoSessionFactory(CryptoSessionFactory* factory) {
|
||||||
|
std::unique_lock<std::mutex> auto_lock(factory_lock_);
|
||||||
factory_.reset(factory);
|
factory_.reset(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,9 +311,38 @@ class CryptoSession {
|
|||||||
size_t max_chunk_size);
|
size_t max_chunk_size);
|
||||||
static void IncrementIV(uint64_t increase_by, std::vector<uint8_t>* iv_out);
|
static void IncrementIV(uint64_t increase_by, std::vector<uint8_t>* iv_out);
|
||||||
|
|
||||||
|
// These methods should be used to take the various CryptoSession locks in
|
||||||
|
// preference to taking the locks directly.
|
||||||
|
//
|
||||||
|
// The Static Field Lock should be taken before accessing any of
|
||||||
|
// CryptoSession's non-atomic static fields. The OEMCrypto Lock should be
|
||||||
|
// taken before calling into OEMCrypto. Note that accessing |key_session_|
|
||||||
|
// often accesses OEMCrypto, so this lock should be held before calling into
|
||||||
|
// |key_session_| as well. If a function needs to take both locks
|
||||||
|
// simultaneously, it must *always* take the Static Field Lock first. In
|
||||||
|
// general, locks should only be held for the minimum time necessary.
|
||||||
|
// (e.g. |oem_crypto_lock_| should only be held for the duration of a single
|
||||||
|
// call into OEMCrypto, unless there is a compelling argument otherwise such
|
||||||
|
// as making two calls into OEMCrypto immediately after each other.)
|
||||||
|
template <class Func>
|
||||||
|
static auto WithStaticFieldLock(const char* tag, Func body)
|
||||||
|
-> decltype(body());
|
||||||
|
|
||||||
|
template <class Func>
|
||||||
|
static auto WithOecLock(const char* tag, Func body) -> decltype(body());
|
||||||
|
|
||||||
|
static bool IsInitialized();
|
||||||
|
|
||||||
|
// Constants
|
||||||
static const size_t kAes128BlockSize = 16; // Block size for AES_CBC_128
|
static const size_t kAes128BlockSize = 16; // Block size for AES_CBC_128
|
||||||
static const size_t kSignatureSize = 32; // size for HMAC-SHA256 signature
|
static const size_t kSignatureSize = 32; // size for HMAC-SHA256 signature
|
||||||
static std::mutex crypto_lock_;
|
|
||||||
|
// The |WithStaticFieldLock| and |WithOecLock| methods should be used in
|
||||||
|
// preference to taking these locks directly. When taken, the rules of
|
||||||
|
// ordering documented with those functions must still be upheld.
|
||||||
|
static std::mutex static_field_lock_;
|
||||||
|
static std::mutex oem_crypto_lock_;
|
||||||
|
|
||||||
static bool initialized_;
|
static bool initialized_;
|
||||||
static int session_count_;
|
static int session_count_;
|
||||||
|
|
||||||
@@ -344,6 +373,10 @@ class CryptoSession {
|
|||||||
CdmCipherMode cipher_mode_;
|
CdmCipherMode cipher_mode_;
|
||||||
uint32_t api_version_;
|
uint32_t api_version_;
|
||||||
|
|
||||||
|
// In order to avoid creating a deadlock if instantiation needs to take any
|
||||||
|
// of the CryptoSession static locks, |factory_| is protected by its own lock
|
||||||
|
// that is only used in the two funtions that interact with it.
|
||||||
|
static std::mutex factory_lock_;
|
||||||
static std::unique_ptr<CryptoSessionFactory> factory_;
|
static std::unique_ptr<CryptoSessionFactory> factory_;
|
||||||
|
|
||||||
CORE_DISALLOW_COPY_AND_ASSIGN(CryptoSession);
|
CORE_DISALLOW_COPY_AND_ASSIGN(CryptoSession);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user