[EME] InitDataRegistry should use base64url encoding and decoding for keyids
authorzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jan 2017 11:41:07 +0000 (11:41 +0000)
committerzandobersek@gmail.com <zandobersek@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Jan 2017 11:41:07 +0000 (11:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=167592

Reviewed by Jer Noble.

Source/WebCore:

In InitDataRegistry, WTF::base64URLEncode() and WTF::base64URLDecode() should
be used to encode and decode the 'keyids' initialization data format, as
required by the relevant specification.
https://w3c.github.io/encrypted-media/format-registry/initdata/keyids.html#format

Relevant test case was added to media/encrypted-media/mock-MediaKeySession-generateRequest.html.

* Modules/encryptedmedia/InitDataRegistry.cpp:
(WebCore::extractKeyIDsKeyids):
(WebCore::sanitizeKeyids):

LayoutTests:

* media/encrypted-media/mock-MediaKeySession-generateRequest-expected.txt:
* media/encrypted-media/mock-MediaKeySession-generateRequest.html: Include a test case
that passes an init data JSON to generateRequest() that fails to decode when using the
plain base64 decoding algorithm. The test passes when base64url encoding and decoding
are used in InitDataRegistry.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211429 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/media/encrypted-media/mock-MediaKeySession-generateRequest-expected.txt
LayoutTests/media/encrypted-media/mock-MediaKeySession-generateRequest.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp

index 7fb8d52..7d12fbc 100644 (file)
@@ -1,3 +1,16 @@
+2017-01-31  Zan Dobersek  <zdobersek@igalia.com>
+
+        [EME] InitDataRegistry should use base64url encoding and decoding for keyids
+        https://bugs.webkit.org/show_bug.cgi?id=167592
+
+        Reviewed by Jer Noble.
+
+        * media/encrypted-media/mock-MediaKeySession-generateRequest-expected.txt:
+        * media/encrypted-media/mock-MediaKeySession-generateRequest.html: Include a test case
+        that passes an init data JSON to generateRequest() that fails to decode when using the
+        plain base64 decoding algorithm. The test passes when base64url encoding and decoding
+        are used in InitDataRegistry.
+
 2017-01-31  Antoine Quint  <graouts@apple.com>
 
         [Sierra WK1] LayoutTest media/modern-media-controls/placard-support/placard-support-pip.html is a flaky crash
index e3560ca..357ce3b 100644 (file)
@@ -37,5 +37,11 @@ RUN(kids = JSON.stringify({ kids: [ "MTIzNDU="], invalid: "invalid" }))
 RUN(mediaKeySession = mediaKeys.createSession("temporary"))
 RUN(promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids)))
 Promise resolved OK
+
+initData is encoded in base64url.
+RUN(kids = JSON.stringify({ kids: [ "ig2FRSEF1BU1j-qPaObBkQ"] }))
+RUN(mediaKeySession = mediaKeys.createSession("temporary"))
+RUN(promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids)))
+Promise resolved OK
 END OF TEST
 
index c77fca4..0d10798 100644 (file)
             run('promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids))');
             shouldResolve(promise).then(next, next);
         },
+
+        function() {
+            consoleWrite('initData is encoded in base64url.')
+            run('kids = JSON.stringify({ kids: [ "ig2FRSEF1BU1j-qPaObBkQ"] })');
+            run('mediaKeySession = mediaKeys.createSession("temporary")');
+            run('promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids))');
+            shouldResolve(promise).then(next, next);
+        },
     ];
     </script>
 </head>
index 2c8c04c..457e45b 100644 (file)
@@ -1,3 +1,21 @@
+2017-01-31  Zan Dobersek  <zdobersek@igalia.com>
+
+        [EME] InitDataRegistry should use base64url encoding and decoding for keyids
+        https://bugs.webkit.org/show_bug.cgi?id=167592
+
+        Reviewed by Jer Noble.
+
+        In InitDataRegistry, WTF::base64URLEncode() and WTF::base64URLDecode() should
+        be used to encode and decode the 'keyids' initialization data format, as
+        required by the relevant specification.
+        https://w3c.github.io/encrypted-media/format-registry/initdata/keyids.html#format
+
+        Relevant test case was added to media/encrypted-media/mock-MediaKeySession-generateRequest.html.
+
+        * Modules/encryptedmedia/InitDataRegistry.cpp:
+        (WebCore::extractKeyIDsKeyids):
+        (WebCore::sanitizeKeyids):
+
 2017-01-31  Joseph Pecoraro  <pecoraro@apple.com>
 
         Performance Timeline: Add serializer to PerformanceEntry
index 0e81b4f..f5b4758 100644 (file)
@@ -63,7 +63,7 @@ static Vector<Ref<SharedBuffer>> extractKeyIDsKeyids(const SharedBuffer& buffer)
             continue;
 
         Vector<char> keyIDData;
-        if (!WTF::base64Decode(keyID, { keyIDData }))
+        if (!WTF::base64URLDecode(keyID, { keyIDData }))
             continue;
 
         Ref<SharedBuffer> keyIDBuffer = SharedBuffer::adoptVector(keyIDData);
@@ -84,7 +84,7 @@ static RefPtr<SharedBuffer> sanitizeKeyids(const SharedBuffer& buffer)
     auto object = InspectorObject::create();
     auto kidsArray = InspectorArray::create();
     for (auto& buffer : keyIDBuffer)
-        kidsArray->pushString(base64Encode(buffer->data(), buffer->size()));
+        kidsArray->pushString(WTF::base64URLEncode(buffer->data(), buffer->size()));
     object->setArray("kids", WTFMove(kidsArray));
 
     CString jsonData = object->toJSONString().utf8();