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

Side by Side Diff: third_party/WebKit/Source/modules/crypto/SubtleCrypto.cpp

Issue 2160943003: Transfer WebCrypto databuffers across the Blink API using blink::WebVector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: checkpoint Created 4 years, 5 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 26 matching lines...) Expand all
37 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
38 #include "modules/crypto/CryptoHistograms.h" 38 #include "modules/crypto/CryptoHistograms.h"
39 #include "modules/crypto/CryptoKey.h" 39 #include "modules/crypto/CryptoKey.h"
40 #include "modules/crypto/CryptoResultImpl.h" 40 #include "modules/crypto/CryptoResultImpl.h"
41 #include "modules/crypto/NormalizeAlgorithm.h" 41 #include "modules/crypto/NormalizeAlgorithm.h"
42 #include "platform/JSONValues.h" 42 #include "platform/JSONValues.h"
43 #include "public/platform/Platform.h" 43 #include "public/platform/Platform.h"
44 #include "public/platform/WebCrypto.h" 44 #include "public/platform/WebCrypto.h"
45 #include "public/platform/WebCryptoAlgorithm.h" 45 #include "public/platform/WebCryptoAlgorithm.h"
46 46
47 // TODO(eroman): Change the public blink::WebCrypto interface to allow
48 // transferring ownership of data buffers instead of just taking
49 // a raw pointer+length. This will avoid an extra copy.
50
51 namespace blink { 47 namespace blink {
52 48
53 static bool parseAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op , WebCryptoAlgorithm& algorithm, CryptoResult* result) 49 static bool parseAlgorithm(const AlgorithmIdentifier& raw, WebCryptoOperation op , WebCryptoAlgorithm& algorithm, CryptoResult* result)
54 { 50 {
55 AlgorithmError error; 51 AlgorithmError error;
56 bool success = normalizeAlgorithm(raw, op, algorithm, &error); 52 bool success = normalizeAlgorithm(raw, op, algorithm, &error);
57 if (!success) 53 if (!success)
58 result->completeWithError(error.errorType, error.errorDetails); 54 result->completeWithError(error.errorType, error.errorDetails);
59 return success; 55 return success;
60 } 56 }
(...skipping 27 matching lines...) Expand all
88 for (unsigned i = 0; i < value.size(); ++i) 84 for (unsigned i = 0; i < value.size(); ++i)
89 jsonArray->pushString(value[i]); 85 jsonArray->pushString(value[i]);
90 destination->setArray(property, jsonArray.release()); 86 destination->setArray(property, jsonArray.release());
91 return true; 87 return true;
92 } 88 }
93 89
94 // FIXME: At the time of writing this is not a part of the spec. It is based an 90 // FIXME: At the time of writing this is not a part of the spec. It is based an
95 // an unpublished editor's draft for: 91 // an unpublished editor's draft for:
96 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24963 92 // https://www.w3.org/Bugs/Public/show_bug.cgi?id=24963
97 // See http://crbug.com/373917. 93 // See http://crbug.com/373917.
98 static bool copyJwkDictionaryToJson(const Dictionary& dict, Vector<uint8_t>& jso nUtf8, CryptoResult* result) 94 static bool copyJwkDictionaryToJson(const Dictionary& dict, WebVector<uint8_t>& jsonUtf8, CryptoResult* result)
99 { 95 {
100 RefPtr<JSONObject> jsonObject = JSONObject::create(); 96 RefPtr<JSONObject> jsonObject = JSONObject::create();
101 97
102 if (!copyStringProperty("kty", dict, jsonObject.get())) { 98 if (!copyStringProperty("kty", dict, jsonObject.get())) {
103 result->completeWithError(WebCryptoErrorTypeData, "The required JWK memb er \"kty\" was missing"); 99 result->completeWithError(WebCryptoErrorTypeData, "The required JWK memb er \"kty\" was missing");
104 return false; 100 return false;
105 } 101 }
106 102
107 copyStringProperty("use", dict, jsonObject.get()); 103 copyStringProperty("use", dict, jsonObject.get());
108 copySequenceOfStringProperty("key_ops", dict, jsonObject.get()); 104 copySequenceOfStringProperty("key_ops", dict, jsonObject.get());
109 copyStringProperty("alg", dict, jsonObject.get()); 105 copyStringProperty("alg", dict, jsonObject.get());
110 106
111 bool ext; 107 bool ext;
112 if (DictionaryHelper::get(dict, "ext", ext)) 108 if (DictionaryHelper::get(dict, "ext", ext))
113 jsonObject->setBoolean("ext", ext); 109 jsonObject->setBoolean("ext", ext);
114 110
115 const char* const propertyNames[] = { "d", "n", "e", "p", "q", "dp", "dq", " qi", "k", "crv", "x", "y" }; 111 const char* const propertyNames[] = { "d", "n", "e", "p", "q", "dp", "dq", " qi", "k", "crv", "x", "y" };
116 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(propertyNames); ++i) 112 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(propertyNames); ++i)
117 copyStringProperty(propertyNames[i], dict, jsonObject.get()); 113 copyStringProperty(propertyNames[i], dict, jsonObject.get());
118 114
119 String json = jsonObject->toJSONString(); 115 String json = jsonObject->toJSONString();
120 jsonUtf8.clear(); 116 jsonUtf8 = WebVector<uint8_t>(json.utf8().data(), json.utf8().length());
121 jsonUtf8.append(json.utf8().data(), json.utf8().length());
122 return true; 117 return true;
123 } 118 }
124 119
125 static Vector<uint8_t> copyBytes(const DOMArrayPiece& source) 120 static WebVector<uint8_t> copyBytes(const DOMArrayPiece& source)
126 { 121 {
127 Vector<uint8_t> result; 122 return WebVector<uint8_t>(static_cast<uint8_t*>(source.data()), source.byteL ength());
128 result.append(reinterpret_cast<const uint8_t*>(source.data()), source.byteLe ngth());
129 return result;
130 } 123 }
131 124
132 SubtleCrypto::SubtleCrypto() 125 SubtleCrypto::SubtleCrypto()
133 { 126 {
134 } 127 }
135 128
136 ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const BufferSource& rawData) 129 ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const BufferSource& rawData)
137 { 130 {
138 // Method described by: https://w3c.github.io/webcrypto/Overview.html#dfn-Su btleCrypto-method-encrypt 131 // Method described by: https://w3c.github.io/webcrypto/Overview.html#dfn-Su btleCrypto-method-encrypt
139 132
140 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); 133 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
141 ScriptPromise promise = result->promise(); 134 ScriptPromise promise = result->promise();
142 135
143 if (!canAccessWebCrypto(scriptState, result)) 136 if (!canAccessWebCrypto(scriptState, result))
144 return promise; 137 return promise;
145 138
146 // 14.3.1.2: Let data be the result of getting a copy of the bytes held by 139 // 14.3.1.2: Let data be the result of getting a copy of the bytes held by
147 // the data parameter passed to the encrypt method. 140 // the data parameter passed to the encrypt method.
148 Vector<uint8_t> data = copyBytes(rawData); 141 WebVector<uint8_t> data = copyBytes(rawData);
149 142
150 WebCryptoAlgorithm algorithm; 143 WebCryptoAlgorithm algorithm;
151 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu lt)) 144 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu lt))
152 return promise; 145 return promise;
153 146
154 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result) ) 147 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result) )
155 return promise; 148 return promise;
156 149
157 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); 150 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key());
158 Platform::current()->crypto()->encrypt(algorithm, key->key(), data.data(), d ata.size(), result->result()); 151 Platform::current()->crypto()->encrypt(algorithm, key->key(), std::move(data ), result->result());
159 return promise; 152 return promise;
160 } 153 }
161 154
162 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const BufferSource& rawData) 155 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const BufferSource& rawData)
163 { 156 {
164 // Method described by: https://w3c.github.io/webcrypto/Overview.html#dfn-Su btleCrypto-method-decrypt 157 // Method described by: https://w3c.github.io/webcrypto/Overview.html#dfn-Su btleCrypto-method-decrypt
165 158
166 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); 159 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
167 ScriptPromise promise = result->promise(); 160 ScriptPromise promise = result->promise();
168 161
169 if (!canAccessWebCrypto(scriptState, result)) 162 if (!canAccessWebCrypto(scriptState, result))
170 return promise; 163 return promise;
171 164
172 // 14.3.2.2: Let data be the result of getting a copy of the bytes held by 165 // 14.3.2.2: Let data be the result of getting a copy of the bytes held by
173 // the data parameter passed to the decrypt method. 166 // the data parameter passed to the decrypt method.
174 Vector<uint8_t> data = copyBytes(rawData); 167 WebVector<uint8_t> data = copyBytes(rawData);
175 168
176 WebCryptoAlgorithm algorithm; 169 WebCryptoAlgorithm algorithm;
177 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu lt)) 170 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu lt))
178 return promise; 171 return promise;
179 172
180 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result) ) 173 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result) )
181 return promise; 174 return promise;
182 175
183 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); 176 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key());
184 Platform::current()->crypto()->decrypt(algorithm, key->key(), data.data(), d ata.size(), result->result()); 177 Platform::current()->crypto()->decrypt(algorithm, key->key(), std::move(data ), result->result());
185 return promise; 178 return promise;
186 } 179 }
187 180
188 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti fier& rawAlgorithm, CryptoKey* key, const BufferSource& rawData) 181 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti fier& rawAlgorithm, CryptoKey* key, const BufferSource& rawData)
189 { 182 {
190 // Method described by: https://w3c.github.io/webcrypto/Overview.html#dfn-Su btleCrypto-method-sign 183 // Method described by: https://w3c.github.io/webcrypto/Overview.html#dfn-Su btleCrypto-method-sign
191 184
192 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); 185 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
193 ScriptPromise promise = result->promise(); 186 ScriptPromise promise = result->promise();
194 187
195 if (!canAccessWebCrypto(scriptState, result)) 188 if (!canAccessWebCrypto(scriptState, result))
196 return promise; 189 return promise;
197 190
198 // 14.3.3.2: Let data be the result of getting a copy of the bytes held by 191 // 14.3.3.2: Let data be the result of getting a copy of the bytes held by
199 // the data parameter passed to the sign method. 192 // the data parameter passed to the sign method.
200 Vector<uint8_t> data = copyBytes(rawData); 193 WebVector<uint8_t> data = copyBytes(rawData);
201 194
202 WebCryptoAlgorithm algorithm; 195 WebCryptoAlgorithm algorithm;
203 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result) ) 196 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result) )
204 return promise; 197 return promise;
205 198
206 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result)) 199 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result))
207 return promise; 200 return promise;
208 201
209 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); 202 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key());
210 Platform::current()->crypto()->sign(algorithm, key->key(), data.data(), data .size(), result->result()); 203 Platform::current()->crypto()->sign(algorithm, key->key(), std::move(data), result->result());
211 return promise; 204 return promise;
212 } 205 }
213 206
214 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo rithmIdentifier& rawAlgorithm, CryptoKey* key, const BufferSource& rawSignature, const BufferSource& rawData) 207 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo rithmIdentifier& rawAlgorithm, CryptoKey* key, const BufferSource& rawSignature, const BufferSource& rawData)
215 { 208 {
216 // Method described by: https://w3c.github.io/webcrypto/Overview.html#Subtle Crypto-method-verify 209 // Method described by: https://w3c.github.io/webcrypto/Overview.html#Subtle Crypto-method-verify
217 210
218 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); 211 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
219 ScriptPromise promise = result->promise(); 212 ScriptPromise promise = result->promise();
220 213
221 if (!canAccessWebCrypto(scriptState, result)) 214 if (!canAccessWebCrypto(scriptState, result))
222 return promise; 215 return promise;
223 216
224 // 14.3.4.2: Let signature be the result of getting a copy of the bytes 217 // 14.3.4.2: Let signature be the result of getting a copy of the bytes
225 // held by the signature parameter passed to the verify method. 218 // held by the signature parameter passed to the verify method.
226 Vector<uint8_t> signature = copyBytes(rawSignature); 219 WebVector<uint8_t> signature = copyBytes(rawSignature);
227 220
228 WebCryptoAlgorithm algorithm; 221 WebCryptoAlgorithm algorithm;
229 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul t)) 222 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul t))
230 return promise; 223 return promise;
231 224
232 // 14.3.4.5: Let data be the result of getting a copy of the bytes held by 225 // 14.3.4.5: Let data be the result of getting a copy of the bytes held by
233 // the data parameter passed to the verify method. 226 // the data parameter passed to the verify method.
234 Vector<uint8_t> data = copyBytes(rawData); 227 WebVector<uint8_t> data = copyBytes(rawData);
235 228
236 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result)) 229 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result))
237 return promise; 230 return promise;
238 231
239 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); 232 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key());
240 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat ure.data(), signature.size(), data.data(), data.size(), result->result()); 233 Platform::current()->crypto()->verifySignature(algorithm, key->key(), std::m ove(signature), std::move(data), result->result());
241 return promise; 234 return promise;
242 } 235 }
243 236
244 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden tifier& rawAlgorithm, const BufferSource& rawData) 237 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden tifier& rawAlgorithm, const BufferSource& rawData)
245 { 238 {
246 // Method described by: https://w3c.github.io/webcrypto/Overview.html#Subtle Crypto-method-digest 239 // Method described by: https://w3c.github.io/webcrypto/Overview.html#Subtle Crypto-method-digest
247 240
248 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); 241 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
249 ScriptPromise promise = result->promise(); 242 ScriptPromise promise = result->promise();
250 243
251 if (!canAccessWebCrypto(scriptState, result)) 244 if (!canAccessWebCrypto(scriptState, result))
252 return promise; 245 return promise;
253 246
254 // 14.3.5.2: Let data be the result of getting a copy of the bytes held 247 // 14.3.5.2: Let data be the result of getting a copy of the bytes held
255 // by the data parameter passed to the digest method. 248 // by the data parameter passed to the digest method.
256 Vector<uint8_t> data = copyBytes(rawData); 249 WebVector<uint8_t> data = copyBytes(rawData);
257 250
258 WebCryptoAlgorithm algorithm; 251 WebCryptoAlgorithm algorithm;
259 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul t)) 252 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul t))
260 return promise; 253 return promise;
261 254
262 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); 255 histogramAlgorithm(scriptState->getExecutionContext(), algorithm);
263 Platform::current()->crypto()->digest(algorithm, data.data(), data.size(), r esult->result()); 256 Platform::current()->crypto()->digest(algorithm, std::move(data), result->re sult());
264 return promise; 257 return promise;
265 } 258 }
266 259
267 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) 260 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages)
268 { 261 {
269 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); 262 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
270 ScriptPromise promise = result->promise(); 263 ScriptPromise promise = result->promise();
271 264
272 if (!canAccessWebCrypto(scriptState, result)) 265 if (!canAccessWebCrypto(scriptState, result))
273 return promise; 266 return promise;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 303 }
311 304
312 WebCryptoKeyUsageMask keyUsages; 305 WebCryptoKeyUsageMask keyUsages;
313 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result)) 306 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result))
314 return promise; 307 return promise;
315 308
316 WebCryptoAlgorithm algorithm; 309 WebCryptoAlgorithm algorithm;
317 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationImportKey, algorithm, re sult)) 310 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationImportKey, algorithm, re sult))
318 return promise; 311 return promise;
319 312
320 Vector<uint8_t> keyData; 313 WebVector<uint8_t> keyData;
321 if (rawKeyData.isArrayBuffer()) { 314 if (rawKeyData.isArrayBuffer()) {
322 keyData = copyBytes(rawKeyData.getAsArrayBuffer()); 315 keyData = copyBytes(rawKeyData.getAsArrayBuffer());
323 } else if (rawKeyData.isArrayBufferView()) { 316 } else if (rawKeyData.isArrayBufferView()) {
324 keyData = copyBytes(rawKeyData.getAsArrayBufferView()); 317 keyData = copyBytes(rawKeyData.getAsArrayBufferView());
325 } else if (rawKeyData.isDictionary()) { 318 } else if (rawKeyData.isDictionary()) {
326 if (!copyJwkDictionaryToJson(rawKeyData.getAsDictionary(), keyData, resu lt)) 319 if (!copyJwkDictionaryToJson(rawKeyData.getAsDictionary(), keyData, resu lt))
327 return promise; 320 return promise;
328 } 321 }
329 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); 322 histogramAlgorithm(scriptState->getExecutionContext(), algorithm);
330 Platform::current()->crypto()->importKey(format, keyData.data(), keyData.siz e(), algorithm, extractable, keyUsages, result->result()); 323 Platform::current()->crypto()->importKey(format, std::move(keyData), algorit hm, extractable, keyUsages, result->result());
331 return promise; 324 return promise;
332 } 325 }
333 326
334 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra wFormat, CryptoKey* key) 327 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra wFormat, CryptoKey* key)
335 { 328 {
336 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); 329 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
337 ScriptPromise promise = result->promise(); 330 ScriptPromise promise = result->promise();
338 331
339 if (!canAccessWebCrypto(scriptState, result)) 332 if (!canAccessWebCrypto(scriptState, result))
340 return promise; 333 return promise;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 if (!CryptoKey::parseFormat(rawFormat, format, result)) 390 if (!CryptoKey::parseFormat(rawFormat, format, result))
398 return promise; 391 return promise;
399 392
400 WebCryptoKeyUsageMask keyUsages; 393 WebCryptoKeyUsageMask keyUsages;
401 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result)) 394 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result))
402 return promise; 395 return promise;
403 396
404 // 14.3.12.2: Let wrappedKey be the result of getting a copy of the bytes 397 // 14.3.12.2: Let wrappedKey be the result of getting a copy of the bytes
405 // held by the wrappedKey parameter passed to the unwrapKey 398 // held by the wrappedKey parameter passed to the unwrapKey
406 // method. 399 // method.
407 Vector<uint8_t> wrappedKey = copyBytes(rawWrappedKey); 400 WebVector<uint8_t> wrappedKey = copyBytes(rawWrappedKey);
408 401
409 WebCryptoAlgorithm unwrapAlgorithm; 402 WebCryptoAlgorithm unwrapAlgorithm;
410 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA lgorithm, result)) 403 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA lgorithm, result))
411 return promise; 404 return promise;
412 405
413 WebCryptoAlgorithm unwrappedKeyAlgorithm; 406 WebCryptoAlgorithm unwrappedKeyAlgorithm;
414 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, WebCryptoOperationImportKey, u nwrappedKeyAlgorithm, result)) 407 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, WebCryptoOperationImportKey, u nwrappedKeyAlgorithm, result))
415 return promise; 408 return promise;
416 409
417 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, WebCryptoKeyUsage UnwrapKey, result)) 410 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, WebCryptoKeyUsage UnwrapKey, result))
418 return promise; 411 return promise;
419 412
420 histogramAlgorithmAndKey(scriptState->getExecutionContext(), unwrapAlgorithm , unwrappingKey->key()); 413 histogramAlgorithmAndKey(scriptState->getExecutionContext(), unwrapAlgorithm , unwrappingKey->key());
421 histogramAlgorithm(scriptState->getExecutionContext(), unwrappedKeyAlgorithm ); 414 histogramAlgorithm(scriptState->getExecutionContext(), unwrappedKeyAlgorithm );
422 Platform::current()->crypto()->unwrapKey(format, wrappedKey.data(), wrappedK ey.size(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extract able, keyUsages, result->result()); 415 Platform::current()->crypto()->unwrapKey(format, std::move(wrappedKey), unwr appingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages , result->result());
423 return promise; 416 return promise;
424 } 417 }
425 418
426 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits) 419 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits)
427 { 420 {
428 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); 421 CryptoResultImpl* result = CryptoResultImpl::create(scriptState);
429 ScriptPromise promise = result->promise(); 422 ScriptPromise promise = result->promise();
430 423
431 if (!canAccessWebCrypto(scriptState, result)) 424 if (!canAccessWebCrypto(scriptState, result))
432 return promise; 425 return promise;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe ngthAlgorithm, result)) 463 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe ngthAlgorithm, result))
471 return promise; 464 return promise;
472 465
473 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, base Key->key()); 466 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, base Key->key());
474 histogramAlgorithm(scriptState->getExecutionContext(), importAlgorithm); 467 histogramAlgorithm(scriptState->getExecutionContext(), importAlgorithm);
475 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result()); 468 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result());
476 return promise; 469 return promise;
477 } 470 }
478 471
479 } // namespace blink 472 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698