OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/child/webcrypto/webcrypto_impl.h" | 5 #include "content/child/webcrypto/webcrypto_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 } | 102 } |
103 | 103 |
104 void CompleteWithError(const Status& status, blink::WebCryptoResult* result) { | 104 void CompleteWithError(const Status& status, blink::WebCryptoResult* result) { |
105 DCHECK(status.IsError()); | 105 DCHECK(status.IsError()); |
106 | 106 |
107 result->completeWithError(status.error_type(), | 107 result->completeWithError(status.error_type(), |
108 blink::WebString::fromUTF8(status.error_details())); | 108 blink::WebString::fromUTF8(status.error_details())); |
109 } | 109 } |
110 | 110 |
111 void CompleteWithBufferOrError(const Status& status, | 111 void CompleteWithBufferOrError(const Status& status, |
112 const std::vector<uint8>& buffer, | 112 const std::vector<uint8_t>& buffer, |
113 blink::WebCryptoResult* result) { | 113 blink::WebCryptoResult* result) { |
114 if (status.IsError()) { | 114 if (status.IsError()) { |
115 CompleteWithError(status, result); | 115 CompleteWithError(status, result); |
116 } else { | 116 } else { |
117 if (buffer.size() > UINT_MAX) { | 117 if (buffer.size() > UINT_MAX) { |
118 // WebArrayBuffers have a smaller range than std::vector<>, so | 118 // WebArrayBuffers have a smaller range than std::vector<>, so |
119 // theoretically this could overflow. | 119 // theoretically this could overflow. |
120 CompleteWithError(Status::ErrorUnexpected(), result); | 120 CompleteWithError(Status::ErrorUnexpected(), result); |
121 } else { | 121 } else { |
122 result->completeWithBuffer(webcrypto::Uint8VectorStart(buffer), | 122 result->completeWithBuffer(webcrypto::Uint8VectorStart(buffer), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 const unsigned char* data, | 192 const unsigned char* data, |
193 unsigned int data_size, | 193 unsigned int data_size, |
194 const blink::WebCryptoResult& result) | 194 const blink::WebCryptoResult& result) |
195 : BaseState(result), | 195 : BaseState(result), |
196 algorithm(algorithm), | 196 algorithm(algorithm), |
197 key(key), | 197 key(key), |
198 data(data, data + data_size) {} | 198 data(data, data + data_size) {} |
199 | 199 |
200 const blink::WebCryptoAlgorithm algorithm; | 200 const blink::WebCryptoAlgorithm algorithm; |
201 const blink::WebCryptoKey key; | 201 const blink::WebCryptoKey key; |
202 const std::vector<uint8> data; | 202 const std::vector<uint8_t> data; |
203 | 203 |
204 std::vector<uint8> buffer; | 204 std::vector<uint8_t> buffer; |
205 }; | 205 }; |
206 | 206 |
207 typedef EncryptState DecryptState; | 207 typedef EncryptState DecryptState; |
208 typedef EncryptState DigestState; | 208 typedef EncryptState DigestState; |
209 | 209 |
210 struct GenerateKeyState : public BaseState { | 210 struct GenerateKeyState : public BaseState { |
211 GenerateKeyState(const blink::WebCryptoAlgorithm& algorithm, | 211 GenerateKeyState(const blink::WebCryptoAlgorithm& algorithm, |
212 bool extractable, | 212 bool extractable, |
213 blink::WebCryptoKeyUsageMask usage_mask, | 213 blink::WebCryptoKeyUsageMask usage_mask, |
214 const blink::WebCryptoResult& result) | 214 const blink::WebCryptoResult& result) |
(...skipping 26 matching lines...) Expand all Loading... |
241 const blink::WebCryptoResult& result) | 241 const blink::WebCryptoResult& result) |
242 : BaseState(result), | 242 : BaseState(result), |
243 format(format), | 243 format(format), |
244 key_data(key_data, key_data + key_data_size), | 244 key_data(key_data, key_data + key_data_size), |
245 algorithm(algorithm), | 245 algorithm(algorithm), |
246 extractable(extractable), | 246 extractable(extractable), |
247 usage_mask(usage_mask), | 247 usage_mask(usage_mask), |
248 key(blink::WebCryptoKey::createNull()) {} | 248 key(blink::WebCryptoKey::createNull()) {} |
249 | 249 |
250 const blink::WebCryptoKeyFormat format; | 250 const blink::WebCryptoKeyFormat format; |
251 const std::vector<uint8> key_data; | 251 const std::vector<uint8_t> key_data; |
252 const blink::WebCryptoAlgorithm algorithm; | 252 const blink::WebCryptoAlgorithm algorithm; |
253 const bool extractable; | 253 const bool extractable; |
254 const blink::WebCryptoKeyUsageMask usage_mask; | 254 const blink::WebCryptoKeyUsageMask usage_mask; |
255 | 255 |
256 blink::WebCryptoKey key; | 256 blink::WebCryptoKey key; |
257 }; | 257 }; |
258 | 258 |
259 struct ExportKeyState : public BaseState { | 259 struct ExportKeyState : public BaseState { |
260 ExportKeyState(blink::WebCryptoKeyFormat format, | 260 ExportKeyState(blink::WebCryptoKeyFormat format, |
261 const blink::WebCryptoKey& key, | 261 const blink::WebCryptoKey& key, |
262 const blink::WebCryptoResult& result) | 262 const blink::WebCryptoResult& result) |
263 : BaseState(result), format(format), key(key) {} | 263 : BaseState(result), format(format), key(key) {} |
264 | 264 |
265 const blink::WebCryptoKeyFormat format; | 265 const blink::WebCryptoKeyFormat format; |
266 const blink::WebCryptoKey key; | 266 const blink::WebCryptoKey key; |
267 | 267 |
268 std::vector<uint8> buffer; | 268 std::vector<uint8_t> buffer; |
269 }; | 269 }; |
270 | 270 |
271 typedef EncryptState SignState; | 271 typedef EncryptState SignState; |
272 | 272 |
273 struct VerifySignatureState : public BaseState { | 273 struct VerifySignatureState : public BaseState { |
274 VerifySignatureState(const blink::WebCryptoAlgorithm& algorithm, | 274 VerifySignatureState(const blink::WebCryptoAlgorithm& algorithm, |
275 const blink::WebCryptoKey& key, | 275 const blink::WebCryptoKey& key, |
276 const unsigned char* signature, | 276 const unsigned char* signature, |
277 unsigned int signature_size, | 277 unsigned int signature_size, |
278 const unsigned char* data, | 278 const unsigned char* data, |
279 unsigned int data_size, | 279 unsigned int data_size, |
280 const blink::WebCryptoResult& result) | 280 const blink::WebCryptoResult& result) |
281 : BaseState(result), | 281 : BaseState(result), |
282 algorithm(algorithm), | 282 algorithm(algorithm), |
283 key(key), | 283 key(key), |
284 signature(signature, signature + signature_size), | 284 signature(signature, signature + signature_size), |
285 data(data, data + data_size), | 285 data(data, data + data_size), |
286 verify_result(false) {} | 286 verify_result(false) {} |
287 | 287 |
288 const blink::WebCryptoAlgorithm algorithm; | 288 const blink::WebCryptoAlgorithm algorithm; |
289 const blink::WebCryptoKey key; | 289 const blink::WebCryptoKey key; |
290 const std::vector<uint8> signature; | 290 const std::vector<uint8_t> signature; |
291 const std::vector<uint8> data; | 291 const std::vector<uint8_t> data; |
292 | 292 |
293 bool verify_result; | 293 bool verify_result; |
294 }; | 294 }; |
295 | 295 |
296 struct WrapKeyState : public BaseState { | 296 struct WrapKeyState : public BaseState { |
297 WrapKeyState(blink::WebCryptoKeyFormat format, | 297 WrapKeyState(blink::WebCryptoKeyFormat format, |
298 const blink::WebCryptoKey& key, | 298 const blink::WebCryptoKey& key, |
299 const blink::WebCryptoKey& wrapping_key, | 299 const blink::WebCryptoKey& wrapping_key, |
300 const blink::WebCryptoAlgorithm& wrap_algorithm, | 300 const blink::WebCryptoAlgorithm& wrap_algorithm, |
301 const blink::WebCryptoResult& result) | 301 const blink::WebCryptoResult& result) |
302 : BaseState(result), | 302 : BaseState(result), |
303 format(format), | 303 format(format), |
304 key(key), | 304 key(key), |
305 wrapping_key(wrapping_key), | 305 wrapping_key(wrapping_key), |
306 wrap_algorithm(wrap_algorithm) {} | 306 wrap_algorithm(wrap_algorithm) {} |
307 | 307 |
308 const blink::WebCryptoKeyFormat format; | 308 const blink::WebCryptoKeyFormat format; |
309 const blink::WebCryptoKey key; | 309 const blink::WebCryptoKey key; |
310 const blink::WebCryptoKey wrapping_key; | 310 const blink::WebCryptoKey wrapping_key; |
311 const blink::WebCryptoAlgorithm wrap_algorithm; | 311 const blink::WebCryptoAlgorithm wrap_algorithm; |
312 | 312 |
313 std::vector<uint8> buffer; | 313 std::vector<uint8_t> buffer; |
314 }; | 314 }; |
315 | 315 |
316 struct UnwrapKeyState : public BaseState { | 316 struct UnwrapKeyState : public BaseState { |
317 UnwrapKeyState(blink::WebCryptoKeyFormat format, | 317 UnwrapKeyState(blink::WebCryptoKeyFormat format, |
318 const unsigned char* wrapped_key, | 318 const unsigned char* wrapped_key, |
319 unsigned wrapped_key_size, | 319 unsigned wrapped_key_size, |
320 const blink::WebCryptoKey& wrapping_key, | 320 const blink::WebCryptoKey& wrapping_key, |
321 const blink::WebCryptoAlgorithm& unwrap_algorithm, | 321 const blink::WebCryptoAlgorithm& unwrap_algorithm, |
322 const blink::WebCryptoAlgorithm& unwrapped_key_algorithm, | 322 const blink::WebCryptoAlgorithm& unwrapped_key_algorithm, |
323 bool extractable, | 323 bool extractable, |
324 blink::WebCryptoKeyUsageMask usages, | 324 blink::WebCryptoKeyUsageMask usages, |
325 const blink::WebCryptoResult& result) | 325 const blink::WebCryptoResult& result) |
326 : BaseState(result), | 326 : BaseState(result), |
327 format(format), | 327 format(format), |
328 wrapped_key(wrapped_key, wrapped_key + wrapped_key_size), | 328 wrapped_key(wrapped_key, wrapped_key + wrapped_key_size), |
329 wrapping_key(wrapping_key), | 329 wrapping_key(wrapping_key), |
330 unwrap_algorithm(unwrap_algorithm), | 330 unwrap_algorithm(unwrap_algorithm), |
331 unwrapped_key_algorithm(unwrapped_key_algorithm), | 331 unwrapped_key_algorithm(unwrapped_key_algorithm), |
332 extractable(extractable), | 332 extractable(extractable), |
333 usages(usages), | 333 usages(usages), |
334 unwrapped_key(blink::WebCryptoKey::createNull()) {} | 334 unwrapped_key(blink::WebCryptoKey::createNull()) {} |
335 | 335 |
336 const blink::WebCryptoKeyFormat format; | 336 const blink::WebCryptoKeyFormat format; |
337 const std::vector<uint8> wrapped_key; | 337 const std::vector<uint8_t> wrapped_key; |
338 const blink::WebCryptoKey wrapping_key; | 338 const blink::WebCryptoKey wrapping_key; |
339 const blink::WebCryptoAlgorithm unwrap_algorithm; | 339 const blink::WebCryptoAlgorithm unwrap_algorithm; |
340 const blink::WebCryptoAlgorithm unwrapped_key_algorithm; | 340 const blink::WebCryptoAlgorithm unwrapped_key_algorithm; |
341 const bool extractable; | 341 const bool extractable; |
342 const blink::WebCryptoKeyUsageMask usages; | 342 const blink::WebCryptoKeyUsageMask usages; |
343 | 343 |
344 blink::WebCryptoKey unwrapped_key; | 344 blink::WebCryptoKey unwrapped_key; |
345 }; | 345 }; |
346 | 346 |
347 // -------------------------------------------------------------------- | 347 // -------------------------------------------------------------------- |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 &key); | 762 &key); |
763 } | 763 } |
764 | 764 |
765 bool WebCryptoImpl::serializeKeyForClone( | 765 bool WebCryptoImpl::serializeKeyForClone( |
766 const blink::WebCryptoKey& key, | 766 const blink::WebCryptoKey& key, |
767 blink::WebVector<unsigned char>& key_data) { | 767 blink::WebVector<unsigned char>& key_data) { |
768 return webcrypto::SerializeKeyForClone(key, &key_data); | 768 return webcrypto::SerializeKeyForClone(key, &key_data); |
769 } | 769 } |
770 | 770 |
771 } // namespace content | 771 } // namespace content |
OLD | NEW |