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

Unified Diff: chrome/renderer/resources/extensions/enterprise_platform_keys/key.js

Issue 332233002: enterprise.platformKeys: Copy-on-read the 'algorithm' member of Key objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
Index: chrome/renderer/resources/extensions/enterprise_platform_keys/key.js
diff --git a/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js b/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js
index 7d146cc69acc1193153a4b3355984d5eca741bf8..406ba25d9a1cca2ad778783b1bc93a1e530f3b09 100644
--- a/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js
+++ b/chrome/renderer/resources/extensions/enterprise_platform_keys/key.js
@@ -22,6 +22,23 @@ var KeyUsage = {
verify: 'verify'
};
+// Freezes |object| recursively. |object| must not contain cyclic references.
+// TODO(pneubeck): Freeze Uint8Arrays (currently used for the publicExponent
+// only) also, once V8 supports it.
+function deepFreeze(object) {
+ if (Object.isFrozen(object))
+ return;
+ Object.freeze(object);
+ for (var key in object) {
+ var prop = object[key];
+ if (!object.hasOwnProperty(key) || (typeof prop) !== 'object' ||
+ prop.__proto__.constructor.name === 'Uint8Array') {
+ continue;
+ }
+ deepFreeze(prop);
+ }
+}
+
/**
* Implementation of WebCrypto.Key used in enterprise.platformKeys.
* @param {KeyType} type The type of the new key.
@@ -36,6 +53,7 @@ var KeyImpl = function(type, publicKeySpki, algorithm, usages, extractable) {
this.type = type;
this.spki = publicKeySpki;
this.algorithm = algorithm;
+ deepFreeze(this.algorithm);
not at google - send to devlin 2014/06/16 17:58:32 why do you need this? the way that you're exposing
pneubeck (no reviews) 2014/06/16 18:01:18 algorithm is an Object and defineProperty doesn't
not at google - send to devlin 2014/06/16 18:08:31 ah right. "deepFreeze" is a great name. I find it
this.usages = usages;
this.extractable = extractable;
};

Powered by Google App Engine
This is Rietveld 408576698