Bug 155247 - [Win] Implement CryptoDigest
Summary: [Win] Implement CryptoDigest
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Local Build
Hardware: PC Windows 8
: P2 Normal
Assignee: Daniel Bates
URL:
Keywords: InRadar, PlatformOnly
Depends on:
Blocks: 155007
  Show dependency treegraph
 
Reported: 2016-03-09 12:03 PST by Daniel Bates
Modified: 2016-03-09 17:47 PST (History)
4 users (show)

See Also:


Attachments
Patch (6.51 KB, patch)
2016-03-09 12:06 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch (6.84 KB, patch)
2016-03-09 14:29 PST, Daniel Bates
no flags Details | Formatted Diff | Diff
Patch (6.85 KB, patch)
2016-03-09 14:35 PST, Daniel Bates
bfulgham: review+
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews114 for mac-yosemite (937.75 KB, application/zip)
2016-03-09 15:49 PST, Build Bot
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2016-03-09 12:03:03 PST
We should implement CryptoDigest for Windows to have access to cryptographically secure hash algorithms. This will allow us to support Content Security Policy inline script and inline stylesheet hashes on Windows among other benefits.
Comment 1 Radar WebKit Bug Importer 2016-03-09 12:03:49 PST
<rdar://problem/25065843>
Comment 2 Daniel Bates 2016-03-09 12:06:45 PST
Created attachment 273453 [details]
Patch
Comment 3 Alexey Proskuryakov 2016-03-09 12:25:49 PST
Comment on attachment 273453 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=273453&action=review

> Source/WebCore/ChangeLog:9
> +        Implement the CryptoDigest abstraction for Windows so that we can compute cryptographically

Is this covered by any regression tests that can be unskipped?

> Source/WebCore/platform/crypto/win/CryptoDigestWin.cpp:83
> +    CryptHashData(m_context->hHash, input, length, 0);

Please add a RELEASE_ASSERT for return value.

Also, what does the function do for null input and zero length? I don't remember if we ever pass such arguments, or what CommonCrypto does.

> Source/WebCore/platform/crypto/win/CryptoDigestWin.cpp:91
> +    CryptGetHashParam(m_context->hHash, HP_HASHSIZE, nullptr, &digestLength, 0);

This function also returns a result that we should check.

> Source/WebCore/platform/crypto/win/CryptoDigestWin.cpp:94
> +    CryptGetHashParam(m_context->hHash, HP_HASHVAL, result.data(), result.size());

I don't think that this is going to compile, as this call has fewer arguments. We should probably assert that the newly provided size matches digestLength.
Comment 4 Daniel Bates 2016-03-09 12:50:05 PST
(In reply to comment #3)
> > Source/WebCore/ChangeLog:9
> > +        Implement the CryptoDigest abstraction for Windows so that we can compute cryptographically
> 
> Is this covered by any regression tests that can be unskipped?
> 

Yes, this code is covered by the Content Security Policy tests for inline script and inline stylesheet hashes that I will unskip in the patch for bug #155007.

> > Source/WebCore/platform/crypto/win/CryptoDigestWin.cpp:83
> > +    CryptHashData(m_context->hHash, input, length, 0);
> 
> Please add a RELEASE_ASSERT for return value.
> 

Will do.

> Also, what does the function do for null input and zero length? [...]
> 

Will bail out early if either input is null or length is 0.

From reading <https://msdn.microsoft.com/en-us/library/windows/desktop/aa380202(v=vs.85).aspx> I suspect that this function is likely unhappy when passed a null pointer or zero length based on the presence of the possible error value ERROR_INVALID_PARAMETER.

> > Source/WebCore/platform/crypto/win/CryptoDigestWin.cpp:91
> > +    CryptGetHashParam(m_context->hHash, HP_HASHSIZE, nullptr, &digestLength, 0);
> 
> This function also returns a result that we should check.
> 

Will do.

> > Source/WebCore/platform/crypto/win/CryptoDigestWin.cpp:94
> > +    CryptGetHashParam(m_context->hHash, HP_HASHVAL, result.data(), result.size());
> 
> I don't think that this is going to compile, as this call has fewer
> arguments. We should probably assert that the newly provided size matches
> digestLength.

Oops! Will fix.
Comment 5 Daniel Bates 2016-03-09 14:29:46 PST
Created attachment 273479 [details]
Patch
Comment 6 Daniel Bates 2016-03-09 14:35:47 PST
Created attachment 273483 [details]
Patch
Comment 7 Brent Fulgham 2016-03-09 14:50:07 PST
Comment on attachment 273483 [details]
Patch

r=me. Please land if the tests are green.
Comment 8 Build Bot 2016-03-09 15:49:24 PST
Comment on attachment 273483 [details]
Patch

Attachment 273483 [details] did not pass mac-debug-ews (mac):
Output: http://webkit-queues.webkit.org/results/950532

New failing tests:
js/function-apply.html
Comment 9 Build Bot 2016-03-09 15:49:26 PST
Created attachment 273495 [details]
Archive of layout-test-results from ews114 for mac-yosemite

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews114  Port: mac-yosemite  Platform: Mac OS X 10.10.5
Comment 10 Daniel Bates 2016-03-09 17:08:54 PST
Committed r197905: <http://trac.webkit.org/changeset/197905>
Comment 11 Daniel Bates 2016-03-09 17:47:25 PST
Committed Windows build fix in <https://trac.webkit.org/changeset/197911>.