Bug 1308076 - Validate keyids json format. r=smaug
Use a WebIDL dict to define the "keyids" EME init data format, and
then use that to parse and validate incomint "keyids" EME init data
and ensure it's in the expected JSON format, i.e.:
https://w3c.github.io/encrypted-media/format-registry/initdata/keyids.html
This means we now pass the "generateRequest() with too short key ID."
case of encrypted-media-generate-request-disallowed-input.html
(upstream that is, our local copy of that WPT is out of sync).
MozReview-Commit-ID: 6W7j2a9Bg7E
--- a/dom/media/eme/MediaKeySession.cpp
+++ b/dom/media/eme/MediaKeySession.cpp
@@ -6,16 +6,17 @@
#include "mozilla/dom/HTMLMediaElement.h"
#include "mozilla/dom/MediaKeySession.h"
#include "mozilla/dom/MediaKeyError.h"
#include "mozilla/dom/MediaKeyMessageEvent.h"
#include "mozilla/dom/MediaEncryptedEvent.h"
#include "mozilla/dom/MediaKeyStatusMap.h"
#include "mozilla/dom/MediaKeySystemAccess.h"
+#include "mozilla/dom/KeyIdsInitDataBinding.h"
#include "nsCycleCollectionParticipant.h"
#include "mozilla/CDMProxy.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Move.h"
#include "nsContentUtils.h"
#include "mozilla/EMEUtils.h"
#include "GMPUtils.h"
#include "nsPrintfCString.h"
@@ -191,17 +192,34 @@ ValidateInitData(const nsTArray<uint8_t>
if (aInitData.Length() > MAX_CENC_INIT_DATA_LENGTH) {
return false;
}
// TODO: Validate PSSH in future patch...
} else if (aInitDataType.LowerCaseEqualsLiteral("keyids")) {
if (aInitData.Length() > MAX_KEY_ID_LENGTH) {
return false;
}
- // TODO: Validate keyIds in future patch...
+ // Ensure that init data matches the expected JSON format.
+ mozilla::dom::KeyIdsInitData keyIds;
+ nsString json;
+ nsDependentCSubstring raw(reinterpret_cast<const char*>(aInitData.Elements()), aInitData.Length());
+ if (NS_FAILED(nsContentUtils::ConvertStringFromEncoding(NS_LITERAL_CSTRING("UTF-8"), raw, json))) {
+ return false;
+ }
+ if (!keyIds.Init(json)) {
+ return false;
+ }
+ if (keyIds.mKids.Length() == 0) {
+ return false;
+ }
+ for (const auto& kid : keyIds.mKids) {
+ if (kid.IsEmpty()) {
+ return false;
+ }
+ }
}
return true;
}
// Generates a license request based on the initData. A message of type
// "license-request" or "individualization-request" will always be queued
// if the algorithm succeeds and the promise is resolved.
already_AddRefed<Promise>
new file mode 100644
--- /dev/null
+++ b/dom/webidl/KeyIdsInitData.webidl
@@ -0,0 +1,11 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+// "KeyIds" EME init data format definition/parser, as defined by
+// https://w3c.github.io/encrypted-media/format-registry/initdata/keyids.html
+dictionary KeyIdsInitData {
+ required sequence<DOMString> kids;
+};
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -288,16 +288,17 @@ WEBIDL_FILES = [
'InputPortManager.webidl',
'InspectorUtils.webidl',
'IterableIterator.webidl',
'KeyAlgorithm.webidl',
'KeyboardEvent.webidl',
'KeyEvent.webidl',
'KeyframeAnimationOptions.webidl',
'KeyframeEffect.webidl',
+ 'KeyIdsInitData.webidl',
'LegacyQueryInterface.webidl',
'LinkStyle.webidl',
'ListBoxObject.webidl',
'LocalMediaStream.webidl',
'Location.webidl',
'MediaDeviceInfo.webidl',
'MediaDevices.webidl',
'MediaElementAudioSourceNode.webidl',