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

Side by Side Diff: chrome/renderer/resources/extensions/platform_keys/subtle_crypto.js

Issue 1915753002: Sanitize inheritance in callers of utils.expose (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: webview: Set proto on prototype. Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 var utils = require('utils'); 5 var utils = require('utils');
6 var internalAPI = require('platformKeys.internalAPI'); 6 var internalAPI = require('platformKeys.internalAPI');
7 var keyModule = require('platformKeys.Key'); 7 var keyModule = require('platformKeys.Key');
8 var getSpki = keyModule.getSpki; 8 var getSpki = keyModule.getSpki;
9 var KeyUsage = keyModule.KeyUsage; 9 var KeyUsage = keyModule.KeyUsage;
10 10
11 var normalizeAlgorithm = 11 var normalizeAlgorithm =
12 requireNative('platform_keys_natives').NormalizeAlgorithm; 12 requireNative('platform_keys_natives').NormalizeAlgorithm;
13 13
14 // This error is thrown by the internal and public API's token functions and 14 // This error is thrown by the internal and public API's token functions and
15 // must be rethrown by this custom binding. Keep this in sync with the C++ part 15 // must be rethrown by this custom binding. Keep this in sync with the C++ part
16 // of this API. 16 // of this API.
17 var errorInvalidToken = "The token is not valid."; 17 var errorInvalidToken = 'The token is not valid.';
18 18
19 // The following errors are specified in WebCrypto. 19 // The following errors are specified in WebCrypto.
20 // TODO(pneubeck): These should be DOMExceptions. 20 // TODO(pneubeck): These should be DOMExceptions.
21 function CreateNotSupportedError() { 21 function CreateNotSupportedError() {
22 return new Error('The algorithm is not supported'); 22 return new Error('The algorithm is not supported');
23 } 23 }
24 24
25 function CreateInvalidAccessError() { 25 function CreateInvalidAccessError() {
26 return new Error('The requested operation is not valid for the provided key'); 26 return new Error('The requested operation is not valid for the provided key');
27 } 27 }
(...skipping 17 matching lines...) Expand all
45 chrome.runtime.lastError.message == errorInvalidToken) { 45 chrome.runtime.lastError.message == errorInvalidToken) {
46 reject(chrome.runtime.lastError); 46 reject(chrome.runtime.lastError);
47 return true; 47 return true;
48 } 48 }
49 return false; 49 return false;
50 } 50 }
51 51
52 /** 52 /**
53 * Implementation of WebCrypto.SubtleCrypto used in platformKeys and 53 * Implementation of WebCrypto.SubtleCrypto used in platformKeys and
54 * enterprise.platformKeys. 54 * enterprise.platformKeys.
55 *
55 * @param {string} tokenId The id of the backing Token. 56 * @param {string} tokenId The id of the backing Token.
56 * @constructor 57 * @constructor
57 */ 58 */
58 var SubtleCryptoImpl = function(tokenId) { 59 function SubtleCryptoImpl(tokenId) {
59 this.tokenId = tokenId; 60 this.tokenId = tokenId;
60 }; 61 }
62 $Object.setPrototypeOf(SubtleCryptoImpl, null);
63 $Object.setPrototypeOf(SubtleCryptoImpl.prototype, null);
61 64
62 SubtleCryptoImpl.prototype.sign = function(algorithm, key, dataView) { 65 SubtleCryptoImpl.prototype.sign = function(algorithm, key, dataView) {
63 var subtleCrypto = this; 66 var subtleCrypto = this;
64 return new Promise(function(resolve, reject) { 67 return new Promise(function(resolve, reject) {
65 if (key.type != 'private' || key.usages.indexOf(KeyUsage.sign) == -1) 68 if (key.type != 'private' || key.usages.indexOf(KeyUsage.sign) == -1)
66 throw CreateInvalidAccessError(); 69 throw CreateInvalidAccessError();
67 70
68 var normalizedAlgorithmParameters = 71 var normalizedAlgorithmParameters =
69 normalizeAlgorithm(algorithm, 'Sign'); 72 normalizeAlgorithm(algorithm, 'Sign');
70 if (!normalizedAlgorithmParameters) { 73 if (!normalizedAlgorithmParameters) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 utils.expose(SubtleCrypto, SubtleCryptoImpl, { 119 utils.expose(SubtleCrypto, SubtleCryptoImpl, {
117 functions: [ 120 functions: [
118 'sign', 121 'sign',
119 'exportKey', 122 'exportKey',
120 ], 123 ],
121 }); 124 });
122 125
123 // Required for subclassing. 126 // Required for subclassing.
124 exports.$set('SubtleCryptoImpl', SubtleCryptoImpl); 127 exports.$set('SubtleCryptoImpl', SubtleCryptoImpl);
125 exports.$set('SubtleCrypto', SubtleCrypto); 128 exports.$set('SubtleCrypto', SubtleCrypto);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698