Index: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc |
diff --git a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc |
index cdf779cbf963192e5d3f4c13d40b7edd52a1a48a..c9278151ee50b9ebde572583f68c742f23283a16 100644 |
--- a/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc |
+++ b/chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc |
@@ -22,9 +22,11 @@ namespace api_epki = api::enterprise_platform_keys_internal; |
// This error will occur if a token is removed and will be exposed to the |
// extension. Keep this in sync with the custom binding in Javascript. |
const char kErrorInvalidToken[] = "The token is not valid."; |
- |
+const char kErrorPublicExponent[] = |
+ "The public exponent is empty or too large."; |
const char kErrorInvalidX509Cert[] = |
"Certificate is not a valid X.509 certificate."; |
+ |
const char kTokenIdUser[] = "user"; |
// Returns whether |token_id| references a known Token. |
@@ -33,6 +35,28 @@ bool ValidateToken(const std::string& token_id) { |
return token_id == kTokenIdUser; |
} |
+// Converts a (big-endian) WebCrypto BigInteger, with or without leading zeros, |
+// to unsigned long. |
+// Note: This must be identical to the conversion used by WebCrypto (see |
+// /content/child/webcrypto/platform_crypto_nss.cc). |
+bool BigIntegerToLong(const std::string& data, unsigned long* result) { |
+ // TODO(padolph): Is it correct to say that empty data is an error, or does it |
+ // mean value 0? See https://www.w3.org/Bugs/Public/show_bug.cgi?id=23655 |
+ if (data.size() == 0) |
+ return false; |
Ryan Sleevi
2014/06/03 19:35:29
https://code.google.com/p/chromium/issues/detail?i
|
+ |
+ *result = 0; |
+ for (size_t i = 0; i < data.size(); ++i) { |
+ size_t reverse_i = data.size() - i - 1; |
+ |
+ if (reverse_i >= sizeof(unsigned long) && data[i]) |
+ return false; // Too large for a long. |
+ |
+ *result |= reinterpret_cast<const unsigned char&>(data[i]) << 8 * reverse_i; |
+ } |
+ return true; |
+} |
+ |
} // namespace |
EnterprisePlatformKeysInternalGenerateKeyFunction:: |
@@ -48,9 +72,14 @@ EnterprisePlatformKeysInternalGenerateKeyFunction::Run() { |
if (!ValidateToken(params->token_id)) |
return RespondNow(Error(kErrorInvalidToken)); |
+ unsigned long public_exponent = 0; |
+ if (!BigIntegerToLong(params->public_exponent, &public_exponent)) |
+ return RespondNow(Error(kErrorPublicExponent)); |
+ |
chromeos::platform_keys::GenerateRSAKey( |
params->token_id, |
params->modulus_length, |
+ public_exponent, |
base::Bind( |
&EnterprisePlatformKeysInternalGenerateKeyFunction::OnGeneratedKey, |
this), |