Bug 188978 - [WinCairo] Add CryptoDigestOpenSSL
Summary: [WinCairo] Add CryptoDigestOpenSSL
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-08-26 23:28 PDT by Yoshiaki Jitsukawa
Modified: 2018-09-01 22:34 PDT (History)
8 users (show)

See Also:


Attachments
patch (17.67 KB, patch)
2018-08-27 02:29 PDT, Yoshiaki Jitsukawa
no flags Details | Formatted Diff | Diff
Patch take2 (17.19 KB, patch)
2018-08-27 16:37 PDT, Yoshiaki Jitsukawa
achristensen: review-
Details | Formatted Diff | Diff
Patch take3 (15.79 KB, patch)
2018-08-29 05:38 PDT, Yoshiaki Jitsukawa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yoshiaki Jitsukawa 2018-08-26 23:28:39 PDT
It's nice to have a CryptoDigest implementation with OpenSSL/LibreSSL, which could potentially be shared with other ports.
Comment 1 Yoshiaki Jitsukawa 2018-08-27 02:29:37 PDT
Created attachment 348128 [details]
patch
Comment 2 Don Olmstead 2018-08-27 10:29:42 PDT
Comment on attachment 348128 [details]
patch

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

LGTM and adding tests is awesome.

I'm just not sure we need all the #ifndef's hanging out.

> Source/WebCore/PAL/pal/crypto/openssl/CryptoDigestOpenSSL.cpp:38
> +#ifndef OPENSSL_NO_SHA1

What are the cases where this and the other macros would be defined?

> Tools/TestWebKitAPI/PlatformWin.cmake:129
> +if (PAL_LIBRARY_TYPE MATCHES STATIC)

Could this go into the root CMakelists.txt?
Comment 3 Alex Christensen 2018-08-27 11:23:08 PDT
Comment on attachment 348128 [details]
patch

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

>> Source/WebCore/PAL/pal/crypto/openssl/CryptoDigestOpenSSL.cpp:38
>> +#ifndef OPENSSL_NO_SHA1
> 
> What are the cases where this and the other macros would be defined?

Do we want to support those cases?  I think probably not, especially not without a fallback.

> Source/WebCore/PAL/pal/crypto/openssl/CryptoDigestOpenSSL.cpp:71
> +    : m_context(new CryptoDigestContext)

This is what std::make_unique is for.
Comment 4 Don Olmstead 2018-08-27 16:02:10 PDT
Myles and Alex after this would we like to create a TestPAL project? There's a legit test now in the repository.
Comment 5 Yoshiaki Jitsukawa 2018-08-27 16:25:38 PDT
Thanks for the reviews. I'm revising my patch.
Comment 6 Yoshiaki Jitsukawa 2018-08-27 16:31:00 PDT
(In reply to Don Olmstead from comment #2)
> > Tools/TestWebKitAPI/PlatformWin.cmake:129
> > +if (PAL_LIBRARY_TYPE MATCHES STATIC)
> 
> Could this go into the root CMakelists.txt?

I don't think so since somehow TestWebCoreLib is defined in each Platform*.cmake, perhaps due to JSCOnly.
Comment 7 Don Olmstead 2018-08-27 16:34:59 PDT
(In reply to Yoshiaki Jitsukawa from comment #6)
> (In reply to Don Olmstead from comment #2)
> > > Tools/TestWebKitAPI/PlatformWin.cmake:129
> > > +if (PAL_LIBRARY_TYPE MATCHES STATIC)
> > 
> > Could this go into the root CMakelists.txt?
> 
> I don't think so since somehow TestWebCoreLib is defined in each
> Platform*.cmake, perhaps due to JSCOnly.

K I'll maybe take a look at the CMake stuff for the tests in the future.
Comment 8 Yoshiaki Jitsukawa 2018-08-27 16:37:41 PDT
Created attachment 348235 [details]
Patch take2

Removing #ifndefs and switching to make_unique().
Comment 9 Alex Christensen 2018-08-28 09:27:40 PDT
Comment on attachment 348235 [details]
Patch take2

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

> Source/WebCore/PAL/pal/crypto/openssl/CryptoDigestOpenSSL.cpp:81
> +    case CryptoDigest::Algorithm::SHA_1:
> +        delete toSHA1Context(m_context.get());
> +        return;
> +    case CryptoDigest::Algorithm::SHA_224:
> +        delete toSHA224Context(m_context.get());
> +        return;

This is what a virtual destructor is for.

> Source/WebCore/PAL/pal/crypto/openssl/CryptoDigestOpenSSL.cpp:96
> +    std::unique_ptr<CryptoDigest> digest(new CryptoDigest);

This is also what make_unique is for.
Comment 10 Yoshiaki Jitsukawa 2018-08-29 05:38:26 PDT
Created attachment 348399 [details]
Patch take3

Using template to generate CryptoDigestContextImpl variants of SHA family.
Comment 11 Yoshiaki Jitsukawa 2018-08-29 05:41:52 PDT
(In reply to Alex Christensen from comment #9)
> > Source/WebCore/PAL/pal/crypto/openssl/CryptoDigestOpenSSL.cpp:96
> > +    std::unique_ptr<CryptoDigest> digest(new CryptoDigest);
> 
> This is also what make_unique is for.

Since the constructor of CryptoDigest is private, unfortunately make_unique cannot invoke it.
Comment 12 Alex Christensen 2018-08-29 18:58:43 PDT
Why don't we make the constructor public instead of having a static create method that returns a unique_ptr?  And why doesn't this replace wtf/SHA1.h?
Comment 13 Yoshiaki Jitsukawa 2018-08-29 20:35:42 PDT
(In reply to Alex Christensen from comment #12)
> And why doesn't this replace wtf/SHA1.h?

I think that's because WTF::Persistence::Encoder and JSC::CodeBlockHash use it.
Comment 14 Yoshiaki Jitsukawa 2018-08-29 20:47:20 PDT
(In reply to Alex Christensen from comment #12)
> Why don't we make the constructor public instead of having a static create
> method that returns a unique_ptr?

I suppose we don't want to return a CryptoDigest instance with unsupported algorithm. As far as I see CryptoDigestWin lacks SHA_224.
Comment 15 WebKit Commit Bot 2018-09-01 22:33:59 PDT
Comment on attachment 348399 [details]
Patch take3

Clearing flags on attachment: 348399

Committed r235587: <https://trac.webkit.org/changeset/235587>
Comment 16 WebKit Commit Bot 2018-09-01 22:34:01 PDT
All reviewed patches have been landed.  Closing bug.
Comment 17 Radar WebKit Bug Importer 2018-09-01 22:34:15 PDT
<rdar://problem/44041807>