DRM Pluging uses CDM core's generic crypto API.

[ Merge of http://go/wvgerrit/173170 ]

This CL updates the Widevine's Android DRM plugin to use the generic
crypto operations provided by CDM core rather than its own
implementation.

Bug: 274984456
Test: atest WvtsDeviceTestCases
Change-Id: I94e1c92c7da577aad5ec43bd3bf0bb380b607b80
This commit is contained in:
Alex Dale
2023-05-01 11:08:32 -07:00
parent 37f125a491
commit 628d1ac38c
4 changed files with 199 additions and 356 deletions

View File

@@ -194,36 +194,44 @@ class WVDrmPlugin : public ::aidl::android::hardware::drm::BnDrmPlugin,
// is cleared right before plugin is destructed.
wvutil::LoggingUidSetter mLoggingUidSetter;
struct CryptoSession {
class SessionInfo {
public:
CryptoSession()
: mOecSessionId(-1),
mCipherAlgorithm(kInvalidCryptoAlgorithm),
mMacAlgorithm(kInvalidCryptoAlgorithm) {}
SessionInfo() {}
CryptoSession(OEMCrypto_SESSION sessionId)
: mOecSessionId(sessionId),
mCipherAlgorithm(kInvalidCryptoAlgorithm),
mMacAlgorithm(kInvalidCryptoAlgorithm) {}
SessionInfo(OEMCrypto_SESSION sessionId) : mOecSessionId(sessionId) {}
OEMCrypto_SESSION oecSessionId() const { return mOecSessionId; }
OEMCrypto_Algorithm cipherAlgorithm() const { return mCipherAlgorithm; }
void setCipherAlgorithm(OEMCrypto_Algorithm newAlgorithm) {
mCipherAlgorithm = newAlgorithm;
wvcdm::CdmEncryptionAlgorithm getEncryptionAlgorithm() const {
return mEncryptionAlgorithm;
}
OEMCrypto_Algorithm macAlgorithm() const { return mMacAlgorithm; }
bool hasEncryptionAlgorithm() const {
return mEncryptionAlgorithm != wvcdm::kEncryptionAlgorithmUnknown;
}
void setMacAlgorithm(OEMCrypto_Algorithm newAlgorithm) {
mMacAlgorithm = newAlgorithm;
void setEncryptionAlgorithm(wvcdm::CdmEncryptionAlgorithm newAlgorithm) {
mEncryptionAlgorithm = newAlgorithm;
}
wvcdm::CdmSigningAlgorithm getSigningAlgorithm() const {
return mSigningAlgorithm;
}
bool hasSigningAlgorithm() const {
return mSigningAlgorithm != wvcdm::kSigningAlgorithmUnknown;
}
void setSigningAlgorithm(wvcdm::CdmSigningAlgorithm newAlgorithm) {
mSigningAlgorithm = newAlgorithm;
}
private:
OEMCrypto_SESSION mOecSessionId;
OEMCrypto_Algorithm mCipherAlgorithm;
OEMCrypto_Algorithm mMacAlgorithm;
OEMCrypto_SESSION mOecSessionId = -1;
wvcdm::CdmEncryptionAlgorithm mEncryptionAlgorithm =
wvcdm::kEncryptionAlgorithmUnknown;
wvcdm::CdmSigningAlgorithm mSigningAlgorithm =
wvcdm::kSigningAlgorithmUnknown;
};
class WVClientPropertySet : public wvcdm::CdmClientPropertySet {
@@ -397,24 +405,33 @@ class WVDrmPlugin : public ::aidl::android::hardware::drm::BnDrmPlugin,
android::Mutex mLock;
};
class CryptoSessionMap {
class SessionInfoMap {
public:
std::map<CdmSessionId, std::shared_ptr<CryptoSession>> clear() {
void clear() {
std::unique_lock<std::mutex> auto_lock(mLock);
auto copy = mMap;
mMap.clear();
return copy;
}
std::shared_ptr<CryptoSession> get(const CdmSessionId& sid) {
std::vector<CdmSessionId> getKeysAndClear() {
std::unique_lock<std::mutex> auto_lock(mLock);
if (mMap.count(sid)) {
return mMap[sid];
std::vector<CdmSessionId> keys;
for (const auto pair : mMap) {
keys.push_back(pair.first);
}
mMap.clear();
return keys;
}
std::shared_ptr<SessionInfo> get(const CdmSessionId& sid) const {
std::unique_lock<std::mutex> auto_lock(mLock);
const auto it = mMap.find(sid);
if (it != mMap.end()) {
return it->second;
}
return nullptr;
}
bool empty() {
bool empty() const {
std::unique_lock<std::mutex> auto_lock(mLock);
return mMap.empty();
}
@@ -426,17 +443,17 @@ class WVDrmPlugin : public ::aidl::android::hardware::drm::BnDrmPlugin,
void insert(const CdmSessionId& sid, OEMCrypto_SESSION osid) {
std::unique_lock<std::mutex> auto_lock(mLock);
mMap[sid] = std::make_shared<CryptoSession>(osid);
mMap[sid] = std::make_shared<SessionInfo>(osid);
}
private:
std::mutex mLock;
std::map<CdmSessionId, std::shared_ptr<CryptoSession>> mMap;
mutable std::mutex mLock;
std::map<CdmSessionId, std::shared_ptr<SessionInfo>> mMap;
};
android::sp<wvcdm::WvContentDecryptionModule> const mCDM;
WVGenericCryptoInterface* mCrypto;
CryptoSessionMap mCryptoSessions;
SessionInfoMap mSessionInfoMap;
std::shared_ptr<::aidl::android::hardware::drm::IDrmPluginListener> mListener;
std::string mProvisioningServiceCertificate;