Skip to content

Commit

Permalink
Merge branch 'keystatus'
Browse files Browse the repository at this point in the history
  • Loading branch information
peak3d committed Aug 22, 2019
2 parents 80e4dbf + 84829d7 commit 7775b53
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 6 deletions.
6 changes: 6 additions & 0 deletions wvdecrypter/jni/src/HashMap.cpp
Expand Up @@ -36,3 +36,9 @@ jhstring CJNIHashMap::put(const jhstring key, const jhstring value)
"put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
key, value);
}

jhobject CJNIHashMap::entrySet()
{
return call_method<jhobject>(m_object,
"entrySet", "()Ljava/util/Set;");
}
3 changes: 2 additions & 1 deletion wvdecrypter/jni/src/HashMap.h
Expand Up @@ -31,7 +31,8 @@ class CJNIHashMap : public CJNIBase
CJNIHashMap();
virtual ~CJNIHashMap() {}

virtual jhstring put(const jhstring key, const jhstring value);
jhstring put(const jhstring key, const jhstring value);
jhobject entrySet();
};

}
Expand Down
2 changes: 1 addition & 1 deletion wvdecrypter/jni/src/JNIBase.h
Expand Up @@ -46,7 +46,7 @@ class CJNIBase
CJNIBase(std::string classname);
virtual ~CJNIBase();

const std::string & GetClassName() {return m_className;}
const std::string & GetClassName() const {return m_className;}
static const std::string GetDotClassName(const std::string & classname);

jni::jhobject m_object;
Expand Down
47 changes: 45 additions & 2 deletions wvdecrypter/jni/src/MediaDrm.cpp
Expand Up @@ -147,14 +147,12 @@ CJNIMediaDrmProvisionRequest CJNIMediaDrm::getProvisionRequest() const

void CJNIMediaDrm::provideProvisionResponse(const std::vector<char> &response) const
{
JNIEnv *env = xbmc_jnienv();
call_method<void>(m_object,
"provideProvisionResponse", "([B)V", jcast<jhbyteArray, std::vector<char> >(response));
}

void CJNIMediaDrm::removeKeys(const std::vector<char> &sessionId) const
{
JNIEnv *env = xbmc_jnienv();
call_method<void>(m_object,
"removeKeys", "([B)V", jcast<jhbyteArray, std::vector<char> >(sessionId));
}
Expand All @@ -165,3 +163,48 @@ void CJNIMediaDrm::setOnEventListener(const CJNIMediaDrmOnEventListener &listene
"(Landroid/media/MediaDrm$OnEventListener;)V",
listener.get_raw());
}

std::map<std::string, std::string> CJNIMediaDrm::queryKeyStatus(const std::vector<char> &sessionId) const
{
if (CJNIBase::GetSDKVersion() >= 23)
{
std::map<std::string, std::string> result;

CJNIHashMap hashMap = call_method<jhobject>(m_object,
"queryKeyStatus", "([B)Ljava/util/HashMap;", jcast<jhbyteArray, std::vector<char> >(sessionId));
// Get a set with Map.entry from hashmap
jhobject entrySet = hashMap.entrySet();
// Get the Iterator
jhobject iterator = call_method<jhobject>(entrySet, "iterator", "()Ljava/util/Iterator;");
while (call_method<jboolean>(iterator, "hasNext", "()Z"))
{
jhobject next = call_method<jhobject>(iterator, "next", "()Ljava/util/Map$Entry;");
std::string key = jcast<std::string>(call_method<jhstring>(next, "getKey", "()Ljava/lang/Object;"));
std::string value = jcast<std::string>(call_method<jhstring>(next, "getValue", "()Ljava/lang/Object;"));
result[key] = value;
}
return result;
}
return std::map<std::string, std::string>();
}

int CJNIMediaDrm::getSecurityLevel(const std::vector<char> &sessionId) const
{
if (CJNIBase::GetSDKVersion() >= 28)
{
return call_method<int>(m_object,
"getSecurityLevel", "([B)I", jcast<jhbyteArray, std::vector<char> >(sessionId));
}
return -1;
}


int CJNIMediaDrm::getMaxSecurityLevel() const
{
if (CJNIBase::GetSDKVersion() >= 28)
{
return call_static_method<int>(GetClassName().c_str(),
"getMaxSecurityLevel", "()I");
}
return -1;
}
5 changes: 5 additions & 0 deletions wvdecrypter/jni/src/MediaDrm.h
Expand Up @@ -68,6 +68,11 @@ class CJNIMediaDrm : public CJNIBase
void removeKeys(const std::vector<char> &sessionId) const;

void setOnEventListener(const CJNIMediaDrmOnEventListener &listener) const;

std::map<std::string, std::string> queryKeyStatus(const std::vector<char> &sessionId) const;

int getSecurityLevel(const std::vector<char> &sessionId) const;
int getMaxSecurityLevel() const;
};

}
Expand Down
19 changes: 17 additions & 2 deletions wvdecrypter/wvdecrypter_android_jni.cpp
Expand Up @@ -146,7 +146,7 @@ WV_DRM::WV_DRM(WV_KEYSYSTEM ks, const char* licenseURL, const AP4_DataBuffer &se
return;
}

std::string strDeviceId = media_drm_->getPropertyString("deviceUniqueId");
std::vector<char> strDeviceId = media_drm_->getPropertyByteArray("deviceUniqueId");
xbmc_jnienv()->ExceptionClear();
std::string strSecurityLevel = media_drm_->getPropertyString("securityLevel");
xbmc_jnienv()->ExceptionClear();
Expand All @@ -172,7 +172,7 @@ WV_DRM::WV_DRM(WV_KEYSYSTEM ks, const char* licenseURL, const AP4_DataBuffer &se
}
}

Log(SSD_HOST::LL_DEBUG, "Successful instanciated media_drm: %p, deviceid: %s, systemId: %s security-level: %s", media_drm_, strDeviceId.c_str(), strSystemId.c_str(), strSecurityLevel.c_str());
Log(SSD_HOST::LL_DEBUG, "Successful instanciated deviceUniqueIdSize: %ld,systemId: %s security-level: %s", strDeviceId.size(), strSystemId.c_str(), strSecurityLevel.c_str());

if (license_url_.find('|') == std::string::npos)
{
Expand Down Expand Up @@ -385,6 +385,15 @@ WV_CencSingleSampleDecrypter::WV_CencSingleSampleDecrypter(WV_DRM &drm, AP4_Data
if (optionalKeyParameter)
optParams_["PRCustomData"] = optionalKeyParameter;

/*
std::vector<char> pui = media_drm_.GetMediaDrm()->getPropertyByteArray("provisioningUniqueId");
if (pui.size() > 0)
{
std::string encoded = b64_encode(reinterpret_cast<const uint8_t*>(pui.data()), pui.size(), false);
optParams_["CDMID"] = encoded;;
}
*/

RETRY_OPEN:
session_id_ = media_drm_.GetMediaDrm()->openSession();
if (xbmc_jnienv()->ExceptionCheck())
Expand Down Expand Up @@ -413,6 +422,8 @@ WV_CencSingleSampleDecrypter::WV_CencSingleSampleDecrypter(WV_DRM &drm, AP4_Data

memcpy(session_id_char_, session_id_.data(), session_id_.size());
session_id_char_[session_id_.size()] = 0;

Log(SSD_HOST::LL_DEBUG, "SessionId: %s, SecurityLevel: %d, MaxSecurityLevel: %d", session_id_char_, media_drm_.GetMediaDrm()->getSecurityLevel(session_id_), media_drm_.GetMediaDrm()->getMaxSecurityLevel());
}

WV_CencSingleSampleDecrypter::~WV_CencSingleSampleDecrypter()
Expand Down Expand Up @@ -556,6 +567,10 @@ bool WV_CencSingleSampleDecrypter::KeyUpdateRequest(bool waitKeys)
}
}
Log(SSD_HOST::LL_DEBUG, "License update successful");
std::map<std::string, std::string> keyStatus = media_drm_.GetMediaDrm()->queryKeyStatus(session_id_);
Log(SSD_HOST::LL_DEBUG, "Key Status (%ld):", keyStatus.size());
for (auto const& ks : keyStatus)
Log(SSD_HOST::LL_DEBUG, "-> %s -> %s", ks.first.c_str(), ks.second.c_str());
return true;
}

Expand Down

0 comments on commit 7775b53

Please sign in to comment.