-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
crypto: pass all WebCryptoAPI WPTs #43656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9952d1f
491ea8d
d9cd385
f0c0a9c
3720974
4fcfa50
e305875
7745cb0
41d849d
07a8676
fb5eb54
03275d0
8c05855
2561171
09a6e50
d51c30c
c8d7b2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,20 +103,58 @@ bool HKDFTraits::DeriveBits( | |
EVPKeyCtxPointer ctx = | ||
EVPKeyCtxPointer(EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, nullptr)); | ||
if (!ctx || !EVP_PKEY_derive_init(ctx.get()) || | ||
!EVP_PKEY_CTX_hkdf_mode(ctx.get(), | ||
EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND) || | ||
!EVP_PKEY_CTX_set_hkdf_md(ctx.get(), params.digest) || | ||
!EVP_PKEY_CTX_set1_hkdf_salt( | ||
ctx.get(), params.salt.data<unsigned char>(), params.salt.size()) || | ||
!EVP_PKEY_CTX_set1_hkdf_key( | ||
ctx.get(), | ||
reinterpret_cast<const unsigned char*>(params.key->GetSymmetricKey()), | ||
params.key->GetSymmetricKeySize()) || | ||
!EVP_PKEY_CTX_add1_hkdf_info( | ||
ctx.get(), params.info.data<unsigned char>(), params.info.size())) { | ||
return false; | ||
} | ||
|
||
// TODO(panva): Once support for OpenSSL 1.1.1 is dropped the whole | ||
// of HKDFTraits::DeriveBits can be refactored to use | ||
// EVP_KDF which does handle zero length key. | ||
if (params.key->GetSymmetricKeySize() != 0) { | ||
if (!EVP_PKEY_CTX_hkdf_mode(ctx.get(), | ||
EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND) || | ||
!EVP_PKEY_CTX_set1_hkdf_salt( | ||
ctx.get(), params.salt.data<unsigned char>(), params.salt.size()) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does a non-zero-length key work with a 0-length salt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's allowed, I am just wondering if OpenSSL implements it that way. The RFC's statement Now I am confused as to whether an empty salt is the same as passing no salt in our current implementation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Our implementation does not allow to omit passing salt, we require the argument, albeit we allow it to be zero-length. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
that's also covered by a passing wpt btw |
||
!EVP_PKEY_CTX_set1_hkdf_key(ctx.get(), | ||
reinterpret_cast<const unsigned char*>( | ||
params.key->GetSymmetricKey()), | ||
params.key->GetSymmetricKeySize())) { | ||
return false; | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a brief comment to the beginning of the If we accept that this branch must exist (until we fully drop OpenSSL 1.1.1), then we should probably either
The first option would give us improved coverage because all HMAC operations would go through it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure.
I think that can be done as a follow-up, I am not up for such challenge myself.
You mean to change the implementation to use |
||
// Workaround for EVP_PKEY_derive HKDF not handling zero length keys. | ||
unsigned char temp_key[EVP_MAX_MD_SIZE]; | ||
unsigned int len = sizeof(temp_key); | ||
if (params.salt.size() != 0) { | ||
if (HMAC(params.digest, | ||
params.salt.data(), | ||
params.salt.size(), | ||
nullptr, | ||
0, | ||
temp_key, | ||
&len) == nullptr) { | ||
return false; | ||
} | ||
} else { | ||
char salt[EVP_MAX_MD_SIZE] = {0}; | ||
if (HMAC(params.digest, | ||
salt, | ||
EVP_MD_size(params.digest), | ||
nullptr, | ||
0, | ||
temp_key, | ||
&len) == nullptr) { | ||
return false; | ||
} | ||
} | ||
if (!EVP_PKEY_CTX_hkdf_mode(ctx.get(), EVP_PKEY_HKDEF_MODE_EXPAND_ONLY) || | ||
!EVP_PKEY_CTX_set1_hkdf_key(ctx.get(), temp_key, len)) { | ||
return false; | ||
} | ||
} | ||
|
||
size_t length = params.length; | ||
ByteSource::Builder buf(length); | ||
if (EVP_PKEY_derive(ctx.get(), buf.data<unsigned char>(), &length) <= 0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -871,7 +871,6 @@ void KeyObjectData::MemoryInfo(MemoryTracker* tracker) const { | |
} | ||
|
||
std::shared_ptr<KeyObjectData> KeyObjectData::CreateSecret(ByteSource key) { | ||
CHECK(key); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might need to verify that no other uses of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is a zero length buffer key data treated as a nullptr? I would like to keep the check here but I don't understand the C++ keyobject implementation enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a suggestion that would allow us to keep this check? |
||
return std::shared_ptr<KeyObjectData>(new KeyObjectData(std::move(key))); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,7 +368,7 @@ class WPTRunner { | |
|
||
// TODO(joyeecheung): work with the upstream to port more tests in .html | ||
// to .js. | ||
runJsTests() { | ||
async runJsTests() { | ||
let queue = []; | ||
|
||
// If the tests are run as `node test/wpt/test-something.js subset.any.js`, | ||
|
@@ -459,6 +459,12 @@ class WPTRunner { | |
); | ||
this.inProgress.delete(testFileName); | ||
}); | ||
|
||
await new Promise((resolve) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to That being said, it looks like the caller never awaits the returned There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The point is to process the queue one by one. This has helped stabilize CI, especially the keygen tests that easily bogged the hosts down minutes at a time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Rejecting would skip running the rest of the queue. So maybe this? await Promise.allSettled([events.once(worker, 'exit')]) or await events.once(worker, 'exit').catch(() => {}) |
||
worker.on('exit', () => { | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
|
||
process.on('exit', () => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.