From 711a98164f13981d427ff37518e07b0b6ca006d2 Mon Sep 17 00:00:00 2001 From: Jeff Tinker Date: Thu, 12 Dec 2013 16:23:19 -0800 Subject: [PATCH] Add tests for key sharing mode and decrypting without keys Merge of https://widevine-internal-review.googlesource.com/#/c/8480/ from widevine cdm repo. Change-Id: Idb5ab83bceeb97016075c26c428aba692f017929 related-to-bug: 11967440 --- .../com/widevine/test/MediaDrmAPITest.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/libwvdrmengine/test/java/src/com/widevine/test/MediaDrmAPITest.java b/libwvdrmengine/test/java/src/com/widevine/test/MediaDrmAPITest.java index e0921ae3..6d3a293c 100644 --- a/libwvdrmengine/test/java/src/com/widevine/test/MediaDrmAPITest.java +++ b/libwvdrmengine/test/java/src/com/widevine/test/MediaDrmAPITest.java @@ -121,6 +121,9 @@ public class MediaDrmAPITest extends Activity { testWidevineSchemeSupported(); testProperties(); + + displayText("Running test...screen will blank briefly"); + testQueryKeyStatus(); testGenericEncryptAndDecrypt(); @@ -136,6 +139,8 @@ public class MediaDrmAPITest extends Activity { testClearContentNoKeys(); testEncryptedContent(); + testEncryptedContentSharingKeys(); + testEncryptedContentNoKeys(); runOnUiThread(new Runnable() { public void run() { @@ -305,16 +310,39 @@ public class MediaDrmAPITest extends Activity { return result; } + private final boolean kExpectNoKeyError = true; + private final boolean kRequireKey = false; + private void testEncryptedContent() { MediaDrm drm = startDrm(); byte[] sessionId = openSession(drm); if (getKeys(drm, sessionId)) { - testDecrypt(sessionId); + testDecrypt(sessionId, kRequireKey); } drm.closeSession(sessionId); stopDrm(drm); } + private void testEncryptedContentSharingKeys() { + MediaDrm drm = startDrm(); + drm.setPropertyString("sessionSharing", "enable"); + byte[] sessionId = openSession(drm); + if (getKeys(drm, sessionId)) { + byte[] sessionId2 = openSession(drm); + testDecrypt(sessionId2, kRequireKey); + } + drm.closeSession(sessionId); + stopDrm(drm); + } + + private void testEncryptedContentNoKeys() { + MediaDrm drm = startDrm(); + byte[] sessionId = openSession(drm); + testDecrypt(sessionId, kExpectNoKeyError); + drm.closeSession(sessionId); + stopDrm(drm); + } + private void testGenericEncryptAndDecrypt() { final byte[] kOperatorSessionAESPssh = hex2ba("080112103be2b25db355fc64a0e69a50f4dbb298"); @@ -547,7 +575,7 @@ public class MediaDrmAPITest extends Activity { // do minimal codec setup to pass an encrypted buffer down the stack to see if it gets // decrypted correctly. - public void testDecrypt(byte[] sessionId) { + public void testDecrypt(byte[] sessionId, boolean expectNoKey) { Log.i(TAG, "testDecrypt"); MediaCrypto crypto = null; @@ -618,9 +646,22 @@ public class MediaDrmAPITest extends Activity { // Log.i(TAG,"Sending " + sampleSize + " bytes, numSubSamples=" + numSubSamples); codec.queueSecureInputBuffer(index, 0 /* offset */, info, 0 /* sampleTime */, 0 /* flags */); + if (expectNoKey) { + Log.e(TAG, "MediaCrypto failed to throw ERROR_NO_KEY!"); + mTestFailed = true; + return; + } } catch (CryptoException e) { // Log.i(TAG,"Checking " + sampleSize + " bytes"); + if (e.getErrorCode() == CryptoException.ERROR_NO_KEY) { + if (!expectNoKey) { + Log.e(TAG, "MediaCrypto reports no key loaded!"); + mTestFailed = true; + } + return; + } + // in test mode, the WV CryptoPlugin throws a CryptoException where the // message string contains a SHA256 hash of the decrypted data, for verification // purposes.