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

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: add back something removed accidentally 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..7d4632f5275de725c48183df69594998cc960e1e 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,18 @@ 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.
+ unsigned int enc_flags = EC_KEY_get_enc_flags(ec.get());
+ if (enc_flags & EC_PKEY_NO_PUBKEY) {
davidben 2015/01/06 20:24:41 I maybe wouldn't bother with the check and drop li
eroman 2015/01/06 20:26:46 Good idea, will do!
eroman 2015/01/06 21:14:36 Done.
+ // Remove the flag which prevents the publicKey from being written during
+ // PKCS8 export.
+ 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