WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
170350
[GCrypt] Implement CryptoKeyRSA::generatePair()
https://bugs.webkit.org/show_bug.cgi?id=170350
Summary
[GCrypt] Implement CryptoKeyRSA::generatePair()
Zan Dobersek
Reported
2017-03-31 11:30:19 PDT
[GCrypt] Implement CryptoKeyRSA::generatePair()
Attachments
Patch
(11.48 KB, patch)
2017-03-31 11:49 PDT
,
Zan Dobersek
no flags
Details
Formatted Diff
Diff
Patch for landing
(11.58 KB, patch)
2017-04-06 22:47 PDT
,
Zan Dobersek
no flags
Details
Formatted Diff
Diff
Patch for landing
(10.32 KB, patch)
2017-04-07 00:17 PDT
,
Zan Dobersek
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Zan Dobersek
Comment 1
2017-03-31 11:49:26 PDT
Created
attachment 305988
[details]
Patch
Michael Catanzaro
Comment 2
2017-04-01 18:50:16 PDT
Comment on
attachment 305988
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=305988&action=review
> Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:89 > + if (exponent.size() > 4) { > + if (std::any_of(exponent.begin(), exponent.end() - 4, [](uint8_t element) { return !!element; })) > + return std::nullopt; > + }
Can you explain this please?
> Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:95 > + uint32_t result = 0; > + for (size_t size = exponent.size(), i = std::min<size_t>(4, size); i > 0; --i) { > + result <<= 8; > + result += exponent[size - i]; > + }
This too.
> Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:102 > + // libgcrypt doesn't report an error if the exponent is smaller than three or even.
Wow. :(
Zan Dobersek
Comment 3
2017-04-03 11:34:15 PDT
Comment on
attachment 305988
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=305988&action=review
>> Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:95 >> + } > > This too.
The public exponent is passed as a BigInteger, a Uint8Array in big-endian order. This helper function limits it to 32 bits, and checks that any larger value causes a failure.
https://w3c.github.io/webcrypto/Overview.html#dfn-BigInteger
The 32-bit limit was lifted from the Mac implementation, but we're not limited to it with libgcrypt. The only resulting difference would be how the exponent data is loaded into the genkey s-expression. Let me test it out, it might be relatively easy to get this working.
Zan Dobersek
Comment 4
2017-04-03 12:34:49 PDT
(In reply to Zan Dobersek from
comment #3
)
> Comment on
attachment 305988
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=305988&action=review
> > >> Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:95 > >> + } > > > > This too. > > The public exponent is passed as a BigInteger, a Uint8Array in big-endian > order. This helper function limits it to 32 bits, and checks that any larger > value causes a failure. >
https://w3c.github.io/webcrypto/Overview.html#dfn-BigInteger
> > The 32-bit limit was lifted from the Mac implementation, but we're not > limited to it with libgcrypt. The only resulting difference would be how the > exponent data is loaded into the genkey s-expression. > > Let me test it out, it might be relatively easy to get this working.
No, this won't work. Internally, libgcrypt scrapes the data from the s-expression and converts it to an unsigned long (8 bytes in size) via strtoul(). Feeding hex data into the s-expression won't work, since strtoul(), as used in libgcrypt, will default to a base-10 converion. I would recommend sticking to converting the public exponent array into a 32-bit integer for now, adding a FIXME explaining we can stretch it out to 8 bytes. I can add that comment in the next iteration of the patch, or before landing it.
Michael Catanzaro
Comment 5
2017-04-06 08:14:12 PDT
I don't think it requires any FIXME, because normal public exponents are very small (3, 5, 17). Nobody should be using something more than four bytes unless they're doing strange research, and it's not WebKit's job to support that.
Michael Catanzaro
Comment 6
2017-04-06 08:18:00 PDT
Comment on
attachment 305988
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=305988&action=review
OK.
> Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:88 > + if (exponent.size() > 4) { > + if (std::any_of(exponent.begin(), exponent.end() - 4, [](uint8_t element) { return !!element; })) > + return std::nullopt;
I'd add a comment here: "ensure exponent is limited to four bytes"
Zan Dobersek
Comment 7
2017-04-06 22:31:08 PDT
Comment on
attachment 305988
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=305988&action=review
>> Source/WebCore/crypto/gcrypt/CryptoKeyRSAGCrypt.cpp:88 >> + return std::nullopt; > > I'd add a comment here: "ensure exponent is limited to four bytes"
OK.
Zan Dobersek
Comment 8
2017-04-06 22:47:19 PDT
Created
attachment 306469
[details]
Patch for landing
Zan Dobersek
Comment 9
2017-04-07 00:17:06 PDT
Created
attachment 306475
[details]
Patch for landing
Zan Dobersek
Comment 10
2017-04-07 00:35:24 PDT
Comment on
attachment 306475
[details]
Patch for landing Clearing flags on attachment: 306475 Committed
r215085
: <
http://trac.webkit.org/changeset/215085
>
Zan Dobersek
Comment 11
2017-04-07 00:35:28 PDT
All reviewed patches have been landed. Closing bug.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug