OLD | NEW |
---|---|
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 13 matching lines...) Expand all Loading... | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "modules/crypto/SubtleCrypto.h" | 31 #include "modules/crypto/SubtleCrypto.h" |
32 | 32 |
33 #include "bindings/core/v8/Dictionary.h" | 33 #include "bindings/core/v8/Dictionary.h" |
34 #include "core/dom/DOMArrayBuffer.h" | |
35 #include "core/dom/DOMArrayBufferView.h" | |
34 #include "core/dom/ExecutionContext.h" | 36 #include "core/dom/ExecutionContext.h" |
35 #include "modules/crypto/CryptoHistograms.h" | 37 #include "modules/crypto/CryptoHistograms.h" |
36 #include "modules/crypto/CryptoKey.h" | 38 #include "modules/crypto/CryptoKey.h" |
37 #include "modules/crypto/CryptoResultImpl.h" | 39 #include "modules/crypto/CryptoResultImpl.h" |
38 #include "modules/crypto/NormalizeAlgorithm.h" | 40 #include "modules/crypto/NormalizeAlgorithm.h" |
39 #include "platform/JSONValues.h" | 41 #include "platform/JSONValues.h" |
40 #include "public/platform/Platform.h" | 42 #include "public/platform/Platform.h" |
41 #include "public/platform/WebCrypto.h" | 43 #include "public/platform/WebCrypto.h" |
42 #include "public/platform/WebCryptoAlgorithm.h" | 44 #include "public/platform/WebCryptoAlgorithm.h" |
45 #include "wtf/typed_arrays/ArrayPiece.h" | |
43 | 46 |
44 namespace blink { | 47 namespace blink { |
45 | 48 |
46 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) |
47 { | 50 { |
48 AlgorithmError error; | 51 AlgorithmError error; |
49 bool success = normalizeAlgorithm(raw, op, algorithm, &error); | 52 bool success = normalizeAlgorithm(raw, op, algorithm, &error); |
50 if (!success) | 53 if (!success) |
51 result->completeWithError(error.errorType, error.errorDetails); | 54 result->completeWithError(error.errorType, error.errorDetails); |
52 return success; | 55 return success; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
107 | 110 |
108 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" }; |
109 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(propertyNames); ++i) | 112 for (unsigned i = 0; i < WTF_ARRAY_LENGTH(propertyNames); ++i) |
110 copyStringProperty(propertyNames[i], dict, jsonObject.get()); | 113 copyStringProperty(propertyNames[i], dict, jsonObject.get()); |
111 | 114 |
112 String json = jsonObject->toJSONString(); | 115 String json = jsonObject->toJSONString(); |
113 jsonUtf8 = json.utf8(); | 116 jsonUtf8 = json.utf8(); |
114 return true; | 117 return true; |
115 } | 118 } |
116 | 119 |
120 // Gets the bytes underlying an ArrayBuffer, or throws an error if it has been | |
121 // neutered. | |
122 static bool getArrayBufferBytes(const DOMArrayBuffer* source, WTF::ArrayPiece& d ataBytes, CryptoResult* result) | |
123 { | |
124 if (source->isNeutered()) { | |
125 dataBytes = WTF::ArrayPiece(); | |
126 result->completeWithError(WebCryptoErrorTypeType, "ArrayBuffer is neuter ed"); | |
127 return false; | |
128 } | |
129 | |
130 dataBytes = WTF::ArrayPiece(const_cast<void*>(source->data()), source->byteL ength()); | |
131 return true; | |
132 } | |
133 | |
134 // Gets the bytes underlying an ArrayBufferView, or throws an error if it has | |
135 // been neutered. | |
136 static bool getArrayBufferViewBytes(const DOMArrayBufferView* source, WTF::Array Piece& dataBytes, CryptoResult* result) | |
137 { | |
138 if (source->buffer()->isNeutered()) { | |
139 dataBytes = WTF::ArrayPiece(); | |
140 result->completeWithError(WebCryptoErrorTypeType, "ArrayBufferView is ne utered"); | |
141 return false; | |
142 } | |
143 | |
144 dataBytes = WTF::ArrayPiece(const_cast<void*>(source->baseAddress()), source ->byteLength()); | |
145 return true; | |
146 } | |
147 | |
148 // Gets a pointer to the (read-only) bytes of a BufferSource. On | |
149 // success writes the pointer+length into |dataBytes| and returns true. | |
150 // On failure sets an error in |result| and returns false. | |
151 // | |
152 // This process is described by the WebIDL spec under: | |
153 // http://heycam.github.io/webidl/#dfn-get-buffer-source-reference | |
154 // | |
155 // The spec doesn't specifically say what error to return when the | |
foolip
2016/07/13 14:27:39
Looks like spec always uses https://dvcs.w3.org/hg
foolip
2016/07/13 14:28:18
s/behavior/behaving/
| |
156 // buffer has been neutered, so TypeError is used by this | |
157 // implementation: | |
158 // | |
159 // Attempting to get a reference to or get a copy of the bytes | |
160 // held by a buffer source when the ArrayBuffer has been detached | |
161 // will fail in a language binding-specific manner. | |
162 static bool getBufferSourceBytes(const BufferSource& source, WTF::ArrayPiece& da taBytes, CryptoResult* result) | |
163 { | |
164 if (source.isNull()) { | |
165 // Shouldn't be reachable based on callers, but check anyway. | |
166 result->completeWithError(WebCryptoErrorTypeType, "BufferSource is null" ); | |
167 return false; | |
168 } | |
169 | |
170 if (source.isArrayBufferView()) | |
171 return getArrayBufferViewBytes(source.getAsArrayBufferView(), dataBytes, result); | |
172 | |
173 if (source.isArrayBuffer()) | |
174 return getArrayBufferBytes(source.getAsArrayBuffer(), dataBytes, result) ; | |
175 | |
176 result->completeWithError(WebCryptoErrorTypeType, "Unexpected BufferSource t ype"); | |
177 return false; | |
178 } | |
179 | |
117 SubtleCrypto::SubtleCrypto() | 180 SubtleCrypto::SubtleCrypto() |
118 { | 181 { |
119 } | 182 } |
120 | 183 |
121 ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) | 184 ScriptPromise SubtleCrypto::encrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const BufferSource& data) |
122 { | 185 { |
123 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 186 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
124 ScriptPromise promise = result->promise(); | 187 ScriptPromise promise = result->promise(); |
125 | 188 |
126 if (!canAccessWebCrypto(scriptState, result)) | 189 if (!canAccessWebCrypto(scriptState, result)) |
127 return promise; | 190 return promise; |
128 | 191 |
129 WebCryptoAlgorithm algorithm; | 192 WebCryptoAlgorithm algorithm; |
130 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu lt)) | 193 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationEncrypt, algorithm, resu lt)) |
131 return promise; | 194 return promise; |
132 | 195 |
133 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result) ) | 196 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageEncrypt, result) ) |
134 return promise; | 197 return promise; |
135 | 198 |
136 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); | 199 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); |
137 Platform::current()->crypto()->encrypt(algorithm, key->key(), data.bytes(), data.byteLength(), result->result()); | 200 |
201 WTF::ArrayPiece dataBytes; | |
202 if (!getBufferSourceBytes(data, dataBytes, result)) | |
203 return promise; | |
204 | |
205 Platform::current()->crypto()->encrypt(algorithm, key->key(), dataBytes.byte s(), dataBytes.byteLength(), result->result()); | |
138 return promise; | 206 return promise; |
139 } | 207 } |
140 | 208 |
141 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) | 209 ScriptPromise SubtleCrypto::decrypt(ScriptState* scriptState, const AlgorithmIde ntifier& rawAlgorithm, CryptoKey* key, const BufferSource& data) |
142 { | 210 { |
143 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 211 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
144 ScriptPromise promise = result->promise(); | 212 ScriptPromise promise = result->promise(); |
145 | 213 |
146 if (!canAccessWebCrypto(scriptState, result)) | 214 if (!canAccessWebCrypto(scriptState, result)) |
147 return promise; | 215 return promise; |
148 | 216 |
149 WebCryptoAlgorithm algorithm; | 217 WebCryptoAlgorithm algorithm; |
150 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu lt)) | 218 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDecrypt, algorithm, resu lt)) |
151 return promise; | 219 return promise; |
152 | 220 |
153 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result) ) | 221 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageDecrypt, result) ) |
154 return promise; | 222 return promise; |
155 | 223 |
224 WTF::ArrayPiece dataBytes; | |
225 if (!getBufferSourceBytes(data, dataBytes, result)) | |
226 return promise; | |
227 | |
156 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); | 228 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); |
157 Platform::current()->crypto()->decrypt(algorithm, key->key(), data.bytes(), data.byteLength(), result->result()); | 229 Platform::current()->crypto()->decrypt(algorithm, key->key(), dataBytes.byte s(), dataBytes.byteLength(), result->result()); |
158 return promise; | 230 return promise; |
159 } | 231 } |
160 | 232 |
161 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti fier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& data) | 233 ScriptPromise SubtleCrypto::sign(ScriptState* scriptState, const AlgorithmIdenti fier& rawAlgorithm, CryptoKey* key, const BufferSource& data) |
162 { | 234 { |
163 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 235 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
164 ScriptPromise promise = result->promise(); | 236 ScriptPromise promise = result->promise(); |
165 | 237 |
166 if (!canAccessWebCrypto(scriptState, result)) | 238 if (!canAccessWebCrypto(scriptState, result)) |
167 return promise; | 239 return promise; |
168 | 240 |
169 WebCryptoAlgorithm algorithm; | 241 WebCryptoAlgorithm algorithm; |
170 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result) ) | 242 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationSign, algorithm, result) ) |
171 return promise; | 243 return promise; |
172 | 244 |
173 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result)) | 245 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageSign, result)) |
174 return promise; | 246 return promise; |
175 | 247 |
248 WTF::ArrayPiece dataBytes; | |
249 if (!getBufferSourceBytes(data, dataBytes, result)) | |
250 return promise; | |
251 | |
176 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); | 252 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); |
177 Platform::current()->crypto()->sign(algorithm, key->key(), data.bytes(), dat a.byteLength(), result->result()); | 253 Platform::current()->crypto()->sign(algorithm, key->key(), dataBytes.bytes() , dataBytes.byteLength(), result->result()); |
178 return promise; | 254 return promise; |
179 } | 255 } |
180 | 256 |
181 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo rithmIdentifier& rawAlgorithm, CryptoKey* key, const DOMArrayPiece& signature, c onst DOMArrayPiece& data) | 257 ScriptPromise SubtleCrypto::verifySignature(ScriptState* scriptState, const Algo rithmIdentifier& rawAlgorithm, CryptoKey* key, const BufferSource& signature, co nst BufferSource& data) |
182 { | 258 { |
183 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 259 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
184 ScriptPromise promise = result->promise(); | 260 ScriptPromise promise = result->promise(); |
185 | 261 |
186 if (!canAccessWebCrypto(scriptState, result)) | 262 if (!canAccessWebCrypto(scriptState, result)) |
187 return promise; | 263 return promise; |
188 | 264 |
189 WebCryptoAlgorithm algorithm; | 265 WebCryptoAlgorithm algorithm; |
190 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul t)) | 266 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationVerify, algorithm, resul t)) |
191 return promise; | 267 return promise; |
192 | 268 |
193 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result)) | 269 if (!key->canBeUsedForAlgorithm(algorithm, WebCryptoKeyUsageVerify, result)) |
194 return promise; | 270 return promise; |
195 | 271 |
272 WTF::ArrayPiece signatureBytes; | |
273 if (!getBufferSourceBytes(signature, signatureBytes, result)) | |
274 return promise; | |
275 | |
276 WTF::ArrayPiece dataBytes; | |
277 if (!getBufferSourceBytes(data, dataBytes, result)) | |
278 return promise; | |
279 | |
196 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); | 280 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, key- >key()); |
197 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat ure.bytes(), signature.byteLength(), data.bytes(), data.byteLength(), result->re sult()); | 281 Platform::current()->crypto()->verifySignature(algorithm, key->key(), signat ureBytes.bytes(), signatureBytes.byteLength(), dataBytes.bytes(), dataBytes.byte Length(), result->result()); |
198 return promise; | 282 return promise; |
199 } | 283 } |
200 | 284 |
201 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden tifier& rawAlgorithm, const DOMArrayPiece& data) | 285 ScriptPromise SubtleCrypto::digest(ScriptState* scriptState, const AlgorithmIden tifier& rawAlgorithm, const BufferSource& data) |
202 { | 286 { |
203 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 287 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
204 ScriptPromise promise = result->promise(); | 288 ScriptPromise promise = result->promise(); |
205 | 289 |
206 if (!canAccessWebCrypto(scriptState, result)) | 290 if (!canAccessWebCrypto(scriptState, result)) |
207 return promise; | 291 return promise; |
208 | 292 |
209 WebCryptoAlgorithm algorithm; | 293 WebCryptoAlgorithm algorithm; |
210 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul t)) | 294 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationDigest, algorithm, resul t)) |
211 return promise; | 295 return promise; |
212 | 296 |
297 WTF::ArrayPiece dataBytes; | |
298 if (!getBufferSourceBytes(data, dataBytes, result)) | |
299 return promise; | |
300 | |
213 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); | 301 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); |
214 Platform::current()->crypto()->digest(algorithm, data.bytes(), data.byteLeng th(), result->result()); | 302 Platform::current()->crypto()->digest(algorithm, dataBytes.bytes(), dataByte s.byteLength(), result->result()); |
215 return promise; | 303 return promise; |
216 } | 304 } |
217 | 305 |
218 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) | 306 ScriptPromise SubtleCrypto::generateKey(ScriptState* scriptState, const Algorith mIdentifier& rawAlgorithm, bool extractable, const Vector<String>& rawKeyUsages) |
219 { | 307 { |
220 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 308 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
221 ScriptPromise promise = result->promise(); | 309 ScriptPromise promise = result->promise(); |
222 | 310 |
223 if (!canAccessWebCrypto(scriptState, result)) | 311 if (!canAccessWebCrypto(scriptState, result)) |
224 return promise; | 312 return promise; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 } | 347 } |
260 | 348 |
261 WebCryptoKeyUsageMask keyUsages; | 349 WebCryptoKeyUsageMask keyUsages; |
262 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result)) | 350 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result)) |
263 return promise; | 351 return promise; |
264 | 352 |
265 WebCryptoAlgorithm algorithm; | 353 WebCryptoAlgorithm algorithm; |
266 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationImportKey, algorithm, re sult)) | 354 if (!parseAlgorithm(rawAlgorithm, WebCryptoOperationImportKey, algorithm, re sult)) |
267 return promise; | 355 return promise; |
268 | 356 |
269 const unsigned char* ptr = nullptr; | |
270 unsigned len = 0; | |
271 | |
272 CString jsonUtf8; | 357 CString jsonUtf8; |
358 WTF::ArrayPiece keyDataBytes; | |
273 if (keyData.isArrayBuffer()) { | 359 if (keyData.isArrayBuffer()) { |
274 ptr = static_cast<const unsigned char*>(keyData.getAsArrayBuffer()->data ()); | 360 if (!getArrayBufferBytes(keyData.getAsArrayBuffer(), keyDataBytes, resul t)) |
275 len = keyData.getAsArrayBuffer()->byteLength(); | 361 return promise; |
276 } else if (keyData.isArrayBufferView()) { | 362 } else if (keyData.isArrayBufferView()) { |
277 ptr = static_cast<const unsigned char*>(keyData.getAsArrayBufferView()-> baseAddress()); | 363 if (!getArrayBufferViewBytes(keyData.getAsArrayBufferView(), keyDataByte s, result)) |
278 len = keyData.getAsArrayBufferView()->byteLength(); | 364 return promise; |
279 } else if (keyData.isDictionary()) { | 365 } else if (keyData.isDictionary()) { |
280 if (!copyJwkDictionaryToJson(keyData.getAsDictionary(), jsonUtf8, result )) | 366 if (!copyJwkDictionaryToJson(keyData.getAsDictionary(), jsonUtf8, result )) |
281 return promise; | 367 return promise; |
282 ptr = reinterpret_cast<const unsigned char*>(jsonUtf8.data()); | 368 keyDataBytes = WTF::ArrayPiece(const_cast<char*>(jsonUtf8.data()), jsonU tf8.length()); |
283 len = jsonUtf8.length(); | |
284 } | 369 } |
285 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); | 370 histogramAlgorithm(scriptState->getExecutionContext(), algorithm); |
286 Platform::current()->crypto()->importKey(format, ptr, len, algorithm, extrac table, keyUsages, result->result()); | 371 Platform::current()->crypto()->importKey(format, keyDataBytes.bytes(), keyDa taBytes.byteLength(), algorithm, extractable, keyUsages, result->result()); |
287 return promise; | 372 return promise; |
288 } | 373 } |
289 | 374 |
290 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra wFormat, CryptoKey* key) | 375 ScriptPromise SubtleCrypto::exportKey(ScriptState* scriptState, const String& ra wFormat, CryptoKey* key) |
291 { | 376 { |
292 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 377 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
293 ScriptPromise promise = result->promise(); | 378 ScriptPromise promise = result->promise(); |
294 | 379 |
295 if (!canAccessWebCrypto(scriptState, result)) | 380 if (!canAccessWebCrypto(scriptState, result)) |
296 return promise; | 381 return promise; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 | 417 |
333 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WebCryptoKeyUsageWrap Key, result)) | 418 if (!wrappingKey->canBeUsedForAlgorithm(wrapAlgorithm, WebCryptoKeyUsageWrap Key, result)) |
334 return promise; | 419 return promise; |
335 | 420 |
336 histogramAlgorithmAndKey(scriptState->getExecutionContext(), wrapAlgorithm, wrappingKey->key()); | 421 histogramAlgorithmAndKey(scriptState->getExecutionContext(), wrapAlgorithm, wrappingKey->key()); |
337 histogramKey(scriptState->getExecutionContext(), key->key()); | 422 histogramKey(scriptState->getExecutionContext(), key->key()); |
338 Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key( ), wrapAlgorithm, result->result()); | 423 Platform::current()->crypto()->wrapKey(format, key->key(), wrappingKey->key( ), wrapAlgorithm, result->result()); |
339 return promise; | 424 return promise; |
340 } | 425 } |
341 | 426 |
342 ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra wFormat, const DOMArrayPiece& wrappedKey, CryptoKey* unwrappingKey, const Algori thmIdentifier& rawUnwrapAlgorithm, const AlgorithmIdentifier& rawUnwrappedKeyAlg orithm, bool extractable, const Vector<String>& rawKeyUsages) | 427 ScriptPromise SubtleCrypto::unwrapKey(ScriptState* scriptState, const String& ra wFormat, const BufferSource& wrappedKey, CryptoKey* unwrappingKey, const Algorit hmIdentifier& rawUnwrapAlgorithm, const AlgorithmIdentifier& rawUnwrappedKeyAlgo rithm, bool extractable, const Vector<String>& rawKeyUsages) |
343 { | 428 { |
344 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 429 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
345 ScriptPromise promise = result->promise(); | 430 ScriptPromise promise = result->promise(); |
346 | 431 |
347 if (!canAccessWebCrypto(scriptState, result)) | 432 if (!canAccessWebCrypto(scriptState, result)) |
348 return promise; | 433 return promise; |
349 | 434 |
350 WebCryptoKeyFormat format; | 435 WebCryptoKeyFormat format; |
351 if (!CryptoKey::parseFormat(rawFormat, format, result)) | 436 if (!CryptoKey::parseFormat(rawFormat, format, result)) |
352 return promise; | 437 return promise; |
353 | 438 |
354 WebCryptoKeyUsageMask keyUsages; | 439 WebCryptoKeyUsageMask keyUsages; |
355 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result)) | 440 if (!CryptoKey::parseUsageMask(rawKeyUsages, keyUsages, result)) |
356 return promise; | 441 return promise; |
357 | 442 |
358 WebCryptoAlgorithm unwrapAlgorithm; | 443 WebCryptoAlgorithm unwrapAlgorithm; |
359 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA lgorithm, result)) | 444 if (!parseAlgorithm(rawUnwrapAlgorithm, WebCryptoOperationUnwrapKey, unwrapA lgorithm, result)) |
360 return promise; | 445 return promise; |
361 | 446 |
362 WebCryptoAlgorithm unwrappedKeyAlgorithm; | 447 WebCryptoAlgorithm unwrappedKeyAlgorithm; |
363 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, WebCryptoOperationImportKey, u nwrappedKeyAlgorithm, result)) | 448 if (!parseAlgorithm(rawUnwrappedKeyAlgorithm, WebCryptoOperationImportKey, u nwrappedKeyAlgorithm, result)) |
364 return promise; | 449 return promise; |
365 | 450 |
366 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, WebCryptoKeyUsage UnwrapKey, result)) | 451 if (!unwrappingKey->canBeUsedForAlgorithm(unwrapAlgorithm, WebCryptoKeyUsage UnwrapKey, result)) |
367 return promise; | 452 return promise; |
368 | 453 |
454 WTF::ArrayPiece wrappedKeyBytes; | |
455 if (!getBufferSourceBytes(wrappedKey, wrappedKeyBytes, result)) | |
456 return promise; | |
457 | |
369 histogramAlgorithmAndKey(scriptState->getExecutionContext(), unwrapAlgorithm , unwrappingKey->key()); | 458 histogramAlgorithmAndKey(scriptState->getExecutionContext(), unwrapAlgorithm , unwrappingKey->key()); |
370 histogramAlgorithm(scriptState->getExecutionContext(), unwrappedKeyAlgorithm ); | 459 histogramAlgorithm(scriptState->getExecutionContext(), unwrappedKeyAlgorithm ); |
371 Platform::current()->crypto()->unwrapKey(format, wrappedKey.bytes(), wrapped Key.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyAlgorithm, extractable, keyUsages, result->result()); | 460 Platform::current()->crypto()->unwrapKey(format, wrappedKeyBytes.bytes(), wr appedKeyBytes.byteLength(), unwrappingKey->key(), unwrapAlgorithm, unwrappedKeyA lgorithm, extractable, keyUsages, result->result()); |
372 return promise; | 461 return promise; |
373 } | 462 } |
374 | 463 |
375 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits) | 464 ScriptPromise SubtleCrypto::deriveBits(ScriptState* scriptState, const Algorithm Identifier& rawAlgorithm, CryptoKey* baseKey, unsigned lengthBits) |
376 { | 465 { |
377 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); | 466 CryptoResultImpl* result = CryptoResultImpl::create(scriptState); |
378 ScriptPromise promise = result->promise(); | 467 ScriptPromise promise = result->promise(); |
379 | 468 |
380 if (!canAccessWebCrypto(scriptState, result)) | 469 if (!canAccessWebCrypto(scriptState, result)) |
381 return promise; | 470 return promise; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe ngthAlgorithm, result)) | 508 if (!parseAlgorithm(rawDerivedKeyType, WebCryptoOperationGetKeyLength, keyLe ngthAlgorithm, result)) |
420 return promise; | 509 return promise; |
421 | 510 |
422 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, base Key->key()); | 511 histogramAlgorithmAndKey(scriptState->getExecutionContext(), algorithm, base Key->key()); |
423 histogramAlgorithm(scriptState->getExecutionContext(), importAlgorithm); | 512 histogramAlgorithm(scriptState->getExecutionContext(), importAlgorithm); |
424 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result()); | 513 Platform::current()->crypto()->deriveKey(algorithm, baseKey->key(), importAl gorithm, keyLengthAlgorithm, extractable, keyUsages, result->result()); |
425 return promise; | 514 return promise; |
426 } | 515 } |
427 | 516 |
428 } // namespace blink | 517 } // namespace blink |
OLD | NEW |