Merge "Unit test script and end-to-end license/decrypt test update" into jb-mr2-dev

This commit is contained in:
Jeff Tinker
2013-04-19 02:19:55 +00:00
committed by Android (Google) Code Review
2 changed files with 71 additions and 34 deletions

View File

@@ -35,7 +35,7 @@ cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine/oemcrypto/test
pwd
mm
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine/test
cd $ANDROID_BUILD_TOP/vendor/widevine/libwvdrmengine/test/unit
pwd
mm
@@ -46,14 +46,13 @@ mm
echo "waiting for device"
adb root && adb wait-for-device remount && adb sync
adb shell /system/bin/request_license_test
adb shell /system/bin/policy_engine_unittest
adb shell /system/bin/libwvdrmmediacrypto_test
adb shell /system/bin/libwvdrmdrmplugin_test
adb shell /system/bin/http_socket_test
adb shell /system/bin/cdm_engine_test
adb shell /system/bin/oemcrypto_test
adb shell LD_LIBRARY_PATH=/system/vendor/lib/mediadrm/ /system/bin/libwvdrmengine_test
adb shell am start com.widevine.test/com.widevine.test.MediaDrmAPITest

View File

@@ -22,6 +22,7 @@ import java.util.UUID;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Random;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;
@@ -258,50 +259,87 @@ public class MediaDrmAPITest extends TabActivity {
}
Log.i(TAG, "Got index " + index);
final int kMaxSubsamplesPerSample = 10;
final int kMaxSampleSize = 128 * 1024;
;
int clearSizes[] = new int[kMaxSubsamplesPerSample];
int encryptedSizes[] = new int[kMaxSubsamplesPerSample];
LinkedList<TestVector> vectors = TestVectors.GetTestVectors();
ListIterator<TestVector> iter = vectors.listIterator(0);
ByteBuffer refBuffer = ByteBuffer.allocate(kMaxSampleSize);
Random rand = new Random();
byte iv[] = null;
byte keyID[] = null;
int numSubSamples = 0;
int sampleSize = 0;
while (iter.hasNext()) {
TestVector tv = iter.next();
if (tv.mByteOffset == 0) {
// start of a new sample
CryptoInfo info = new CryptoInfo();
int clearSizes[] = { tv.mByteOffset };
int encryptedSizes[] = { tv.mEncryptedBuf.length };
if (numSubSamples > 0) {
// send the sample we have
CryptoInfo info = new CryptoInfo();
info.set(numSubSamples, clearSizes, encryptedSizes, keyID, iv,
MediaCodec.CRYPTO_MODE_AES_CTR);
info.set(1, clearSizes, encryptedSizes, tv.mKeyID, tv.mIV,
MediaCodec.CRYPTO_MODE_AES_CTR);
try {
Log.i(TAG,"Sending " + sampleSize + " bytes, numSubSamples=" + numSubSamples);
codec.queueSecureInputBuffer(index, 0 /* offset */, info,
0 /* sampleTime */, 0 /* flags */);
} catch (CryptoException e) {
Log.i(TAG,"Checking " + sampleSize + " bytes");
byte clearBuf[] = new byte[tv.mByteOffset];
// in test mode, the WV CryptoPlugin throws a CryptoException where the
// message string contains a SHA256 hash of the decrypted data, for verification
// purposes.
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte buf[] = Arrays.copyOf(refBuffer.array(), sampleSize);
byte[] sha256 = digest.digest(buf);
if (Arrays.equals(sha256, hex2ba(e.getMessage()))) {
Log.i(TAG, "sha256: " + e.getMessage() + " matches OK");
} else {
Log.i(TAG, "MediaCrypto sha256: " + e.getMessage() +
" does not match test vector sha256: ");
for (int i = 0; i < sha256.length; i++) {
System.out.printf("%02x", sha256[i]);
}
}
}
// clear buffers for next sample
numSubSamples = 0;
sampleSize = 0;
inputBuffers[index].clear();
refBuffer.clear();
}
keyID = tv.mKeyID;
iv = tv.mIV;
}
// add this subsample vector to the list
int clearSize = rand.nextInt(100);
byte clearBuf[] = new byte[clearSize];
for (int i = 0; i < clearBuf.length; i++) {
clearBuf[i] = (byte)i;
}
inputBuffers[index].clear();
clearSizes[numSubSamples] = clearSize;
encryptedSizes[numSubSamples] = tv.mEncryptedBuf.length;
numSubSamples++;
inputBuffers[index].put(clearBuf, 0, clearBuf.length);
inputBuffers[index].put(tv.mEncryptedBuf, 0, tv.mEncryptedBuf.length);
try {
codec.queueSecureInputBuffer(index, 0 /* offset */, info,
0 /* sampleTime */, 0 /* flags */);
} catch (CryptoException e) {
ByteBuffer refBuffer = ByteBuffer.allocate(clearBuf.length + tv.mClearBuf.length);
refBuffer.put(clearBuf, 0, clearBuf.length);
refBuffer.put(tv.mClearBuf, 0, tv.mClearBuf.length);
// in test mode, the WV CryptoPlugin throws a CryptoException where the
// message string contains a SHA256 hash of the decrypted data, for verification
// purposes.
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] sha256 = digest.digest(refBuffer.array());
if (Arrays.equals(sha256, hex2ba(e.getMessage()))) {
Log.i(TAG, "sha256: " + e.getMessage() + " matches OK");
} else {
Log.i(TAG, "MediaCrypto sha256: " + e.getMessage() +
"does not match test vector sha256: ");
for (int i = 0; i < sha256.length; i++) {
System.out.printf("%02x", sha256[i]);
}
}
}
refBuffer.put(clearBuf, 0, clearBuf.length);
refBuffer.put(tv.mClearBuf, 0, tv.mClearBuf.length);
sampleSize += clearSize + tv.mEncryptedBuf.length;
}
codec.stop();
@@ -369,7 +407,7 @@ public class MediaDrmAPITest extends TabActivity {
Log.i(TAG, "sha256: " + e.getMessage() + " matches OK");
} else {
Log.i(TAG, "MediaCrypto sha256: " + e.getMessage() +
"does not match test vector sha256: ");
" does not match test vector sha256: ");
for (int i = 0; i < sha256.length; i++) {
System.out.printf("%02x", sha256[i]);
}