Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Unified Diff: content/child/webcrypto/openssl/ec_algorithm_openssl.cc

Issue 835633002: Change the WebCrypto behavior when importing EC private keys without a public key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@add_private_tests
Patch Set: properly rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/child/webcrypto/test/ecdsa_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/openssl/ec_algorithm_openssl.cc
diff --git a/content/child/webcrypto/openssl/ec_algorithm_openssl.cc b/content/child/webcrypto/openssl/ec_algorithm_openssl.cc
index 5c41148b630fede25c62faacf9af698f12063a59..d36c0252999137bf261a8b4c64b3de29ca58280a 100644
--- a/content/child/webcrypto/openssl/ec_algorithm_openssl.cc
+++ b/content/child/webcrypto/openssl/ec_algorithm_openssl.cc
@@ -105,6 +105,7 @@ Status WebCryptoCurveToJwkCrv(blink::WebCryptoNamedCurve named_curve,
// Verifies that an EC key imported from PKCS8 or SPKI format is correct.
// This involves verifying the key validity, and the NID for the named curve.
+// Also removes the EC_PKEY_NO_PUBKEY flag if present.
Status VerifyEcKeyAfterSpkiOrPkcs8Import(
EVP_PKEY* pkey,
blink::WebCryptoNamedCurve expected_named_curve) {
@@ -114,6 +115,14 @@ Status VerifyEcKeyAfterSpkiOrPkcs8Import(
if (!ec.get())
return Status::ErrorUnexpected();
+ // When importing an ECPrivateKey, the public key is optional. If it was
+ // omitted then the public key will be calculated by BoringSSL and added into
+ // the EC_KEY. However an encoding flag is set such that when exporting to
+ // PKCS8 format the public key is once again omitted. Remove this flag.
+ unsigned int enc_flags = EC_KEY_get_enc_flags(ec.get());
+ enc_flags &= ~EC_PKEY_NO_PUBKEY;
+ EC_KEY_set_enc_flags(ec.get(), enc_flags);
+
// TODO(eroman): Is this necessary? From my tests it seems that BoringSSL
// already does these checks when setting the public key's affine coordinates.
if (!EC_KEY_check_key(ec.get()))
« no previous file with comments | « no previous file | content/child/webcrypto/test/ecdsa_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698