Bug 170271 - [GCrypt] Implement AES_GCM support
Summary: [GCrypt] Implement AES_GCM support
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Zan Dobersek
URL:
Keywords:
Depends on: 170269
Blocks: 133122 170274
  Show dependency treegraph
 
Reported: 2017-03-29 23:48 PDT by Zan Dobersek
Modified: 2017-04-03 14:04 PDT (History)
4 users (show)

See Also:


Attachments
Patch (10.89 KB, patch)
2017-03-29 23:51 PDT, Zan Dobersek
no flags Details | Formatted Diff | Diff
Patch (11.13 KB, patch)
2017-03-30 00:21 PDT, Zan Dobersek
no flags Details | Formatted Diff | Diff
Patch (11.20 KB, patch)
2017-03-30 23:39 PDT, Zan Dobersek
no flags Details | Formatted Diff | Diff
Patch for landing (11.46 KB, patch)
2017-04-03 00:38 PDT, Zan Dobersek
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Zan Dobersek 2017-03-29 23:48:09 PDT
[GCrypt] Implement AES_GCM support
Comment 1 Zan Dobersek 2017-03-29 23:51:24 PDT
Created attachment 305840 [details]
Patch
Comment 2 Build Bot 2017-03-29 23:52:25 PDT
Attachment 305840 [details] did not pass style-queue:


ERROR: Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:164:  CryptoAlgorithmAES_GCM::platformEncrypt is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:190:  CryptoAlgorithmAES_GCM::platformDecrypt is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WebCore/PAL/pal/crypto/gcrypt/Handle.h:86:  Missing space before {  [whitespace/braces] [5]
Total errors found: 3 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Zan Dobersek 2017-03-30 00:21:57 PDT
Created attachment 305845 [details]
Patch
Comment 4 Build Bot 2017-03-30 00:24:15 PDT
Attachment 305845 [details] did not pass style-queue:


ERROR: Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:166:  CryptoAlgorithmAES_GCM::platformEncrypt is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:192:  CryptoAlgorithmAES_GCM::platformDecrypt is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 2 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Zan Dobersek 2017-03-30 00:43:45 PDT
Depends on the Utilities.h header that's being added in bug #170269.
Comment 6 Zan Dobersek 2017-03-30 23:39:57 PDT
Created attachment 305949 [details]
Patch
Comment 7 Build Bot 2017-03-30 23:41:44 PDT
Attachment 305949 [details] did not pass style-queue:


ERROR: Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:166:  CryptoAlgorithmAES_GCM::platformEncrypt is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
ERROR: Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:192:  CryptoAlgorithmAES_GCM::platformDecrypt is incorrectly named. Don't use underscores in your identifier names.  [readability/naming/underscores] [4]
Total errors found: 2 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 8 Michael Catanzaro 2017-04-01 17:57:48 PDT
Comment on attachment 305949 [details]
Patch

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

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:39
> +#include <pal/crypto/gcrypt/Handle.h>
> +#include <pal/crypto/gcrypt/Utilities.h>

...

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:46
> +    auto algorithm = PAL::GCrypt::aesAlgorithmForKeySize(key.size() * 8);

Ugh, there's no good way to avoid having to write PAL::GCrypt everywhere, is there? Because a simple "using PAL::GCrypt" is not going to work, right? This is unfortunate.

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:51
> +    gcry_error_t error = gcry_cipher_open(&handle, *algorithm, GCRY_CIPHER_MODE_GCM, 0);

We should probably pass GCRY_CIPHER_SECURE instead of 0 to ensure the key doesn't get paged to disk...?

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:98
> +        output.appendVector(tag);

It feels confusing/fragile, but I guess it's hard to change the cross-platform interface for this? Or is this how the data is expected to be received by the JS API?

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:101
> +    return WTFMove(output);

Remove WTFMove.

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:158
> +        size_t offset = cipherText.size() - tagLength;

I'd declare this up above gcry_cipher_decrypt() so that you can use it on the line following that too.

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:163
> +    return WTFMove(output);

No WTFMove.

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:177
> +                    [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {

Don't capture callback.

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:185
> +                [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) mutable {

Don't capture exceptionCallback.

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:203
> +                    [callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) {

Ditto.

> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:211
> +                [output = WTFMove(*output), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback)](ScriptExecutionContext& context) mutable {

Ditto.
Comment 9 Zan Dobersek 2017-04-02 23:57:34 PDT
Comment on attachment 305949 [details]
Patch

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

>> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:46
>> +    auto algorithm = PAL::GCrypt::aesAlgorithmForKeySize(key.size() * 8);
> 
> Ugh, there's no good way to avoid having to write PAL::GCrypt everywhere, is there? Because a simple "using PAL::GCrypt" is not going to work, right? This is unfortunate.

I think it would work, but I would revisit this later, after the majority of changes lands.

>> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:51
>> +    gcry_error_t error = gcry_cipher_open(&handle, *algorithm, GCRY_CIPHER_MODE_GCM, 0);
> 
> We should probably pass GCRY_CIPHER_SECURE instead of 0 to ensure the key doesn't get paged to disk...?

OK.

>> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:98
>> +        output.appendVector(tag);
> 
> It feels confusing/fragile, but I guess it's hard to change the cross-platform interface for this? Or is this how the data is expected to be received by the JS API?

Confusing/fragile how? Change it how? As it stands, the callback object in the custom JS bindings works with a Vector<uint8_t> object whose contents are then copied into an ArrayBuffer.

>> Source/WebCore/crypto/gcrypt/CryptoAlgorithmAES_GCMGCrypt.cpp:158
>> +        size_t offset = cipherText.size() - tagLength;
> 
> I'd declare this up above gcry_cipher_decrypt() so that you can use it on the line following that too.

OK.
Comment 10 Zan Dobersek 2017-04-03 00:38:52 PDT
Created attachment 306065 [details]
Patch for landing
Comment 11 Zan Dobersek 2017-04-03 11:12:56 PDT
Comment on attachment 306065 [details]
Patch for landing

Clearing flags on attachment: 306065

Committed r214822: <http://trac.webkit.org/changeset/214822>
Comment 12 Zan Dobersek 2017-04-03 11:13:13 PDT
All reviewed patches have been landed.  Closing bug.
Comment 13 Tim Horton 2017-04-03 11:58:21 PDT
I think this broke the GTK EWS build? https://webkit-queues.webkit.org/results/3466261
Comment 14 Michael Catanzaro 2017-04-03 14:04:17 PDT
(In reply to Tim Horton from comment #13)
> I think this broke the GTK EWS build?
> https://webkit-queues.webkit.org/results/3466261

Committed r214837: <http://trac.webkit.org/changeset/214837>