Bug 1308821 - Ensure ClearKey doesn't parse a keyids initdata format session type parameter. r=kikuo
authorChris Pearce <cpearce@mozilla.com>
Sun, 09 Oct 2016 20:42:01 -0700
changeset 319853 50482ffb2969a1013d3daa2af2924fa3cd86aa75
parent 319852 61061d39b87022c493fae5bc6757633a18f716e0
child 319854 9de67ae226941715a65130b6c54589e136842203
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskikuo
bugs1308821
milestone52.0a1
Bug 1308821 - Ensure ClearKey doesn't parse a keyids initdata format session type parameter. r=kikuo The specification doesn't require there to be a 'type' member of the keyids init data format. MozReview-Commit-ID: 7mOm7KwyyuC
dom/html/HTMLMediaElement.cpp
dom/media/test/test_eme_initDataTypes.html
media/gmp-clearkey/0.1/ClearKeySession.cpp
media/gmp-clearkey/0.1/ClearKeyUtils.cpp
media/gmp-clearkey/0.1/ClearKeyUtils.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -6200,16 +6200,20 @@ HTMLMediaElement::SetOnwaitingforkey(Eve
 {
   EventTarget::SetEventHandler(nsGkAtoms::onwaitingforkey, EmptyString(), aCallback);
 }
 
 void
 HTMLMediaElement::DispatchEncrypted(const nsTArray<uint8_t>& aInitData,
                                     const nsAString& aInitDataType)
 {
+  LOG(LogLevel::Debug,
+      ("%p DispatchEncrypted initDataType='%s'",
+      this, NS_ConvertUTF16toUTF8(aInitDataType).get()));
+
   if (mReadyState == nsIDOMHTMLMediaElement::HAVE_NOTHING) {
     // Ready state not HAVE_METADATA (yet), don't dispatch encrypted now.
     // Queueing for later dispatch in MetadataLoaded.
     mPendingEncryptedInitData.AddInitData(aInitDataType, aInitData);
     return;
   }
 
   RefPtr<MediaEncryptedEvent> event;
--- a/dom/media/test/test_eme_initDataTypes.html
+++ b/dom/media/test/test_eme_initDataTypes.html
@@ -54,23 +54,16 @@ var tests = [
   {
     name: "Empty keyId",
     initDataType: 'keyids',
     initData: '{"kids":[""]}',
     sessionType: 'temporary',
     expectPass: false,
   },
   {
-    name: "SessionType in license doesn't match MediaKeySession's sessionType",
-    initDataType: 'keyids',
-    initData: '{"kids":["LwVHf8JLtPrv2GUXFW2v_A"]}',
-    sessionType: 'persistent-license',
-    expectPass: false,
-  },
-  {
     name: "Invalid initData",
     initDataType: 'keyids',
     initData: 'invalid initData',
     sessionType: 'temporary',
     expectPass: false,
   },
   {
     name: "'webm' initDataType",
--- a/media/gmp-clearkey/0.1/ClearKeySession.cpp
+++ b/media/gmp-clearkey/0.1/ClearKeySession.cpp
@@ -57,23 +57,17 @@ ClearKeySession::Init(uint32_t aCreateSe
                       const std::string& aInitDataType,
                       const uint8_t* aInitData, uint32_t aInitDataSize)
 {
   CK_LOGD("ClearKeySession::Init");
 
   if (aInitDataType == "cenc") {
     ParseCENCInitData(aInitData, aInitDataSize, mKeyIds);
   } else if (aInitDataType == "keyids") {
-    std::string sessionType;
-    ClearKeyUtils::ParseKeyIdsInitData(aInitData, aInitDataSize, mKeyIds, sessionType);
-    if (sessionType != ClearKeyUtils::SessionTypeToString(mSessionType)) {
-      const char message[] = "Session type specified in keyids init data doesn't match session type.";
-      mCallback->RejectPromise(aPromiseId, kGMPInvalidAccessError, message, strlen(message));
-      return;
-    }
+    ClearKeyUtils::ParseKeyIdsInitData(aInitData, aInitDataSize, mKeyIds);
   } else if (aInitDataType == "webm" && aInitDataSize <= kMaxWebmInitDataSize) {
     // "webm" initData format is simply the raw bytes of the keyId.
     vector<uint8_t> keyId;
     keyId.assign(aInitData, aInitData+aInitDataSize);
     mKeyIds.push_back(keyId);
   }
 
   if (!mKeyIds.size()) {
--- a/media/gmp-clearkey/0.1/ClearKeyUtils.cpp
+++ b/media/gmp-clearkey/0.1/ClearKeyUtils.cpp
@@ -459,21 +459,18 @@ ParseKeyIds(ParserContext& aCtx, vector<
 
   return GetNextSymbol(aCtx) == ']';
 }
 
 
 /* static */ bool
 ClearKeyUtils::ParseKeyIdsInitData(const uint8_t* aInitData,
                                    uint32_t aInitDataSize,
-                                   vector<KeyId>& aOutKeyIds,
-                                   string& aOutSessionType)
+                                   vector<KeyId>& aOutKeyIds)
 {
-  aOutSessionType = "temporary";
-
   ParserContext ctx;
   ctx.mIter = aInitData;
   ctx.mEnd = aInitData + aInitDataSize;
 
   // Consume '{' from start of object.
   EXPECT_SYMBOL(ctx, '{');
 
   while (true) {
@@ -483,19 +480,16 @@ ClearKeyUtils::ParseKeyIdsInitData(const
     EXPECT_SYMBOL(ctx, ':');
 
     if (label == "kids") {
       // Parse "kids" array.
       if (!ParseKeyIds(ctx, aOutKeyIds) ||
           aOutKeyIds.empty()) {
         return false;
       }
-    } else if (label == "type") {
-      // Consume type string.
-      if (!GetNextLabel(ctx, aOutSessionType)) return false;
     } else {
       SkipToken(ctx);
     }
 
     // Check for end of object.
     if (PeekSymbol(ctx) == '}') {
       break;
     }
--- a/media/gmp-clearkey/0.1/ClearKeyUtils.h
+++ b/media/gmp-clearkey/0.1/ClearKeyUtils.h
@@ -57,18 +57,17 @@ struct KeyIdPair
 class ClearKeyUtils
 {
 public:
   static void DecryptAES(const std::vector<uint8_t>& aKey,
                          std::vector<uint8_t>& aData, std::vector<uint8_t>& aIV);
 
   static bool ParseKeyIdsInitData(const uint8_t* aInitData,
                                   uint32_t aInitDataSize,
-                                  std::vector<KeyId>& aOutKeyIds,
-                                  std::string& aOutSessionType);
+                                  std::vector<KeyId>& aOutKeyIds);
 
   static void MakeKeyRequest(const std::vector<KeyId>& aKeyIds,
                              std::string& aOutRequest,
                              GMPSessionType aSessionType);
 
   static bool ParseJWK(const uint8_t* aKeyData, uint32_t aKeyDataSize,
                        std::vector<KeyIdPair>& aOutKeys,
                        GMPSessionType aSessionType);