Rewrite SRI checks to use raw data rather than strings
Our original Subresource Integrity implementation took the resources as
normalized text strings and verified their integrity. However, this lead
to reports of incorrect integrity failures in the presence of resources
with various Unicode characters. It turned out that these characters,
when normalized, gave a different byte output than the raw data had,
thus leading to incorrect failures.
To address this, the SRI checks are rewritten here to use raw bytes
rather than strings. While this might sound straightforward, it's a bit
more complicated because ScriptResource objects do not keep the raw data
around after the source is accessed once, so if the resource is accessed
from the MemoryCache for a second time, there is no way to redo the SRI
check.
Thus, this implements a scheme where we cache the integrity information
for a ScriptResource after the first time it is checked, and if there is
another request for that resource, with the same integrity metadata, we
skip the integrity calculation. However, if the integrity metadata is a
mismatch, we skip the MemoryCache and rerequest the resource. We expect
this to be an uncommon case, however, as it implies two same-origin
requests to the same resource, but with different integrity metadata.
The changes to StyleSheets and the Fetch module are straightforward
rewrites of the SRI API calls.
BUG=527286
R=mkwst@chromium.org
Review URL: https://codereview.chromium.org/1387523002
Cr-Commit-Position: refs/heads/master@{#353464}