[email protected] | cf5d32e5 | 2014-03-07 18:00:08 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 5 | #include "components/webcrypto/webcrypto_impl.h" |
[email protected] | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 6 | |
avi | 51ba3e69 | 2015-12-26 17:30:50 | [diff] [blame] | 7 | #include <limits.h> |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 12 | #include "base/bind.h" |
| 13 | #include "base/lazy_instance.h" |
| 14 | #include "base/location.h" |
[email protected] | c1b944a | 2013-10-23 06:33:21 | [diff] [blame] | 15 | #include "base/logging.h" |
gab | 2c979bb | 2016-09-14 02:36:47 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 17 | #include "base/single_thread_task_runner.h" |
| 18 | #include "base/task_runner.h" |
gab | 2c979bb | 2016-09-14 02:36:47 | [diff] [blame] | 19 | #include "base/threading/thread.h" |
gab | 7966d31 | 2016-05-11 20:35:01 | [diff] [blame] | 20 | #include "base/threading/thread_task_runner_handle.h" |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 21 | #include "base/trace_event/trace_event.h" |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 22 | #include "components/webcrypto/algorithm_dispatch.h" |
| 23 | #include "components/webcrypto/crypto_data.h" |
| 24 | #include "components/webcrypto/generate_key_result.h" |
| 25 | #include "components/webcrypto/status.h" |
[email protected] | 8238bb1c | 2014-02-26 15:16:25 | [diff] [blame] | 26 | #include "third_party/WebKit/public/platform/WebCryptoKeyAlgorithm.h" |
[email protected] | cf5d32e5 | 2014-03-07 18:00:08 | [diff] [blame] | 27 | #include "third_party/WebKit/public/platform/WebString.h" |
[email protected] | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 28 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 29 | namespace webcrypto { |
[email protected] | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 30 | |
[email protected] | cca89748 | 2014-01-30 22:40:19 | [diff] [blame] | 31 | using webcrypto::Status; |
| 32 | |
[email protected] | 043cf1d3 | 2013-11-02 13:27:30 | [diff] [blame] | 33 | namespace { |
| 34 | |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 35 | // --------------------- |
| 36 | // Threading |
| 37 | // --------------------- |
| 38 | // |
| 39 | // WebCrypto operations can be slow. For instance generating an RSA key can |
eroman | 984ead6c | 2016-06-23 00:25:25 | [diff] [blame] | 40 | // take seconds. |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 41 | // |
gab | 2c979bb | 2016-09-14 02:36:47 | [diff] [blame] | 42 | // The strategy used here is to run a worker pool for all WebCrypto operations |
| 43 | // (except structured cloning). This same pool is also used by requests started |
| 44 | // from Blink Web Workers. |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 45 | // |
| 46 | // A few notes to keep in mind: |
| 47 | // |
eroman | 984ead6c | 2016-06-23 00:25:25 | [diff] [blame] | 48 | // * PostTaskAndReply() is not used because of how it handles failures -- it |
| 49 | // leaks the callback when failing to post back to the origin thread. |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 50 | // |
eroman | 984ead6c | 2016-06-23 00:25:25 | [diff] [blame] | 51 | // This is a problem since WebCrypto may be called from WebWorker threads, |
| 52 | // which may be aborted at any time. Leaking would be undesirable, and |
| 53 | // reachable in practice. |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 54 | // |
| 55 | // * blink::WebArrayBuffer is NOT threadsafe, and should therefore be allocated |
eroman | 984ead6c | 2016-06-23 00:25:25 | [diff] [blame] | 56 | // only on the target Blink thread. |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 57 | // |
| 58 | // TODO(eroman): Is there any way around this? Copying the result between |
| 59 | // threads is silly. |
| 60 | // |
eroman | 984ead6c | 2016-06-23 00:25:25 | [diff] [blame] | 61 | // * WebCryptoAlgorithm and WebCryptoKey are threadsafe, by virtue of being |
| 62 | // immutable. Internally asymmetric WebCryptoKeys wrap BoringSSL's EVP_PKEY. |
| 63 | // These are safe to use for BoringSSL operations across threads, provided |
| 64 | // the internals of the EVP_PKEY are not mutated (they never should be |
| 65 | // following ImportKey()). |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 66 | // |
| 67 | // * blink::WebCryptoResult is not threadsafe and should only be operated on |
| 68 | // the target Blink thread. HOWEVER, it is safe to delete it from any thread. |
| 69 | // This can happen if by the time the operation has completed in the crypto |
| 70 | // worker pool, the Blink worker thread that initiated the request is gone. |
| 71 | // Posting back to the origin thread will fail, and the WebCryptoResult will |
| 72 | // be deleted while running in the crypto worker pool. |
| 73 | class CryptoThreadPool { |
| 74 | public: |
gab | 2c979bb | 2016-09-14 02:36:47 | [diff] [blame] | 75 | CryptoThreadPool() : worker_thread_("WebCrypto") { |
| 76 | base::Thread::Options options; |
| 77 | options.joinable = false; |
| 78 | worker_thread_.StartWithOptions(options); |
| 79 | } |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 80 | |
Brett Wilson | 1c99002 | 2017-09-12 20:11:15 | [diff] [blame] | 81 | static bool PostTask(const base::Location& from_here, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 82 | const base::Closure& task); |
| 83 | |
| 84 | private: |
gab | 2c979bb | 2016-09-14 02:36:47 | [diff] [blame] | 85 | // TODO(gab): the pool is currently using a single non-joinable thread to |
| 86 | // mimic the old behavior of using a CONTINUE_ON_SHUTDOWN SequencedTaskRunner |
| 87 | // on a single-threaded SequencedWorkerPool, but we'd like to consider using |
| 88 | // the TaskScheduler here and allowing multiple threads (SEQUENCED or even |
| 89 | // PARALLEL ExecutionMode: http://crbug.com/623700). |
| 90 | base::Thread worker_thread_; |
| 91 | |
| 92 | DISALLOW_COPY_AND_ASSIGN(CryptoThreadPool); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | base::LazyInstance<CryptoThreadPool>::Leaky crypto_thread_pool = |
| 96 | LAZY_INSTANCE_INITIALIZER; |
| 97 | |
Brett Wilson | 1c99002 | 2017-09-12 20:11:15 | [diff] [blame] | 98 | bool CryptoThreadPool::PostTask(const base::Location& from_here, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 99 | const base::Closure& task) { |
gab | 2c979bb | 2016-09-14 02:36:47 | [diff] [blame] | 100 | return crypto_thread_pool.Get().worker_thread_.task_runner()->PostTask( |
| 101 | from_here, task); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void CompleteWithThreadPoolError(blink::WebCryptoResult* result) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 105 | result->CompleteWithError(blink::kWebCryptoErrorTypeOperation, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 106 | "Failed posting to crypto worker pool"); |
| 107 | } |
| 108 | |
[email protected] | cca89748 | 2014-01-30 22:40:19 | [diff] [blame] | 109 | void CompleteWithError(const Status& status, blink::WebCryptoResult* result) { |
| 110 | DCHECK(status.IsError()); |
[email protected] | c503936 | 2014-04-28 19:10:34 | [diff] [blame] | 111 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 112 | result->CompleteWithError(status.error_type(), |
| 113 | blink::WebString::FromUTF8(status.error_details())); |
[email protected] | cca89748 | 2014-01-30 22:40:19 | [diff] [blame] | 114 | } |
| 115 | |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 116 | void CompleteWithBufferOrError(const Status& status, |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 117 | const std::vector<uint8_t>& buffer, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 118 | blink::WebCryptoResult* result) { |
| 119 | if (status.IsError()) { |
| 120 | CompleteWithError(status, result); |
| 121 | } else { |
| 122 | if (buffer.size() > UINT_MAX) { |
| 123 | // WebArrayBuffers have a smaller range than std::vector<>, so |
| 124 | // theoretically this could overflow. |
| 125 | CompleteWithError(Status::ErrorUnexpected(), result); |
| 126 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 127 | result->CompleteWithBuffer(buffer.data(), |
brettw | 690c9667 | 2015-04-21 16:19:54 | [diff] [blame] | 128 | static_cast<unsigned int>(buffer.size())); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void CompleteWithKeyOrError(const Status& status, |
| 134 | const blink::WebCryptoKey& key, |
| 135 | blink::WebCryptoResult* result) { |
| 136 | if (status.IsError()) { |
| 137 | CompleteWithError(status, result); |
| 138 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 139 | result->CompleteWithKey(key); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
Sadrul Habib Chowdhury | 3a4b2d1 | 2015-02-04 01:10:42 | [diff] [blame] | 143 | // Gets a task runner for the current thread. |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 144 | scoped_refptr<base::TaskRunner> GetCurrentBlinkThread() { |
Sadrul Habib Chowdhury | 3a4b2d1 | 2015-02-04 01:10:42 | [diff] [blame] | 145 | DCHECK(base::ThreadTaskRunnerHandle::IsSet()); |
| 146 | return base::ThreadTaskRunnerHandle::Get(); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | // -------------------------------------------------------------------- |
| 150 | // State |
| 151 | // -------------------------------------------------------------------- |
| 152 | // |
| 153 | // Explicit state classes are used rather than base::Bind(). This is done |
| 154 | // both for clarity, but also to avoid extraneous allocations for things |
| 155 | // like passing buffers and result objects between threads. |
| 156 | // |
| 157 | // BaseState is the base class common to all of the async operations, and |
| 158 | // keeps track of the thread to complete on, the error state, and the |
| 159 | // callback into Blink. |
| 160 | // |
| 161 | // Ownership of the State object is passed between the crypto thread and the |
| 162 | // Blink thread. Under normal completion it is destroyed on the Blink thread. |
| 163 | // However it may also be destroyed on the crypto thread if the Blink thread |
| 164 | // has vanished (which can happen for Blink web worker threads). |
| 165 | |
| 166 | struct BaseState { |
| 167 | explicit BaseState(const blink::WebCryptoResult& result) |
| 168 | : origin_thread(GetCurrentBlinkThread()), result(result) {} |
| 169 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 170 | bool cancelled() { return result.Cancelled(); } |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 171 | |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 172 | scoped_refptr<base::TaskRunner> origin_thread; |
| 173 | |
| 174 | webcrypto::Status status; |
| 175 | blink::WebCryptoResult result; |
| 176 | |
| 177 | protected: |
| 178 | // Since there is no virtual destructor, must not delete directly as a |
| 179 | // BaseState. |
| 180 | ~BaseState() {} |
| 181 | }; |
| 182 | |
| 183 | struct EncryptState : public BaseState { |
| 184 | EncryptState(const blink::WebCryptoAlgorithm& algorithm, |
| 185 | const blink::WebCryptoKey& key, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 186 | blink::WebVector<unsigned char> data, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 187 | const blink::WebCryptoResult& result) |
| 188 | : BaseState(result), |
| 189 | algorithm(algorithm), |
| 190 | key(key), |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 191 | data(std::move(data)) {} |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 192 | |
| 193 | const blink::WebCryptoAlgorithm algorithm; |
| 194 | const blink::WebCryptoKey key; |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 195 | const blink::WebVector<unsigned char> data; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 196 | |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 197 | std::vector<uint8_t> buffer; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | typedef EncryptState DecryptState; |
| 201 | typedef EncryptState DigestState; |
| 202 | |
| 203 | struct GenerateKeyState : public BaseState { |
| 204 | GenerateKeyState(const blink::WebCryptoAlgorithm& algorithm, |
| 205 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 206 | blink::WebCryptoKeyUsageMask usages, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 207 | const blink::WebCryptoResult& result) |
| 208 | : BaseState(result), |
| 209 | algorithm(algorithm), |
| 210 | extractable(extractable), |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 211 | usages(usages) {} |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 212 | |
| 213 | const blink::WebCryptoAlgorithm algorithm; |
| 214 | const bool extractable; |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 215 | const blink::WebCryptoKeyUsageMask usages; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 216 | |
eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 217 | webcrypto::GenerateKeyResult generate_key_result; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | struct ImportKeyState : public BaseState { |
| 221 | ImportKeyState(blink::WebCryptoKeyFormat format, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 222 | blink::WebVector<unsigned char> key_data, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 223 | const blink::WebCryptoAlgorithm& algorithm, |
| 224 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 225 | blink::WebCryptoKeyUsageMask usages, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 226 | const blink::WebCryptoResult& result) |
| 227 | : BaseState(result), |
| 228 | format(format), |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 229 | key_data(std::move(key_data)), |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 230 | algorithm(algorithm), |
| 231 | extractable(extractable), |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 232 | usages(usages) {} |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 233 | |
| 234 | const blink::WebCryptoKeyFormat format; |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 235 | const blink::WebVector<unsigned char> key_data; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 236 | const blink::WebCryptoAlgorithm algorithm; |
| 237 | const bool extractable; |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 238 | const blink::WebCryptoKeyUsageMask usages; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 239 | |
| 240 | blink::WebCryptoKey key; |
| 241 | }; |
| 242 | |
| 243 | struct ExportKeyState : public BaseState { |
| 244 | ExportKeyState(blink::WebCryptoKeyFormat format, |
| 245 | const blink::WebCryptoKey& key, |
| 246 | const blink::WebCryptoResult& result) |
| 247 | : BaseState(result), format(format), key(key) {} |
| 248 | |
| 249 | const blink::WebCryptoKeyFormat format; |
| 250 | const blink::WebCryptoKey key; |
| 251 | |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 252 | std::vector<uint8_t> buffer; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | typedef EncryptState SignState; |
| 256 | |
| 257 | struct VerifySignatureState : public BaseState { |
| 258 | VerifySignatureState(const blink::WebCryptoAlgorithm& algorithm, |
| 259 | const blink::WebCryptoKey& key, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 260 | blink::WebVector<unsigned char> signature, |
| 261 | blink::WebVector<unsigned char> data, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 262 | const blink::WebCryptoResult& result) |
| 263 | : BaseState(result), |
| 264 | algorithm(algorithm), |
| 265 | key(key), |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 266 | signature(std::move(signature)), |
| 267 | data(std::move(data)), |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 268 | verify_result(false) {} |
| 269 | |
| 270 | const blink::WebCryptoAlgorithm algorithm; |
| 271 | const blink::WebCryptoKey key; |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 272 | blink::WebVector<unsigned char> signature; |
| 273 | blink::WebVector<unsigned char> data; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 274 | |
| 275 | bool verify_result; |
| 276 | }; |
| 277 | |
| 278 | struct WrapKeyState : public BaseState { |
| 279 | WrapKeyState(blink::WebCryptoKeyFormat format, |
| 280 | const blink::WebCryptoKey& key, |
| 281 | const blink::WebCryptoKey& wrapping_key, |
| 282 | const blink::WebCryptoAlgorithm& wrap_algorithm, |
| 283 | const blink::WebCryptoResult& result) |
| 284 | : BaseState(result), |
| 285 | format(format), |
| 286 | key(key), |
| 287 | wrapping_key(wrapping_key), |
| 288 | wrap_algorithm(wrap_algorithm) {} |
| 289 | |
| 290 | const blink::WebCryptoKeyFormat format; |
| 291 | const blink::WebCryptoKey key; |
| 292 | const blink::WebCryptoKey wrapping_key; |
| 293 | const blink::WebCryptoAlgorithm wrap_algorithm; |
| 294 | |
[email protected] | 53b6c9d2 | 2014-07-19 05:08:38 | [diff] [blame] | 295 | std::vector<uint8_t> buffer; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | struct UnwrapKeyState : public BaseState { |
| 299 | UnwrapKeyState(blink::WebCryptoKeyFormat format, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 300 | blink::WebVector<unsigned char> wrapped_key, |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 301 | const blink::WebCryptoKey& wrapping_key, |
| 302 | const blink::WebCryptoAlgorithm& unwrap_algorithm, |
| 303 | const blink::WebCryptoAlgorithm& unwrapped_key_algorithm, |
| 304 | bool extractable, |
| 305 | blink::WebCryptoKeyUsageMask usages, |
| 306 | const blink::WebCryptoResult& result) |
| 307 | : BaseState(result), |
| 308 | format(format), |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 309 | wrapped_key(std::move(wrapped_key)), |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 310 | wrapping_key(wrapping_key), |
| 311 | unwrap_algorithm(unwrap_algorithm), |
| 312 | unwrapped_key_algorithm(unwrapped_key_algorithm), |
| 313 | extractable(extractable), |
eroman | 7b9591ab | 2014-10-21 17:13:01 | [diff] [blame] | 314 | usages(usages) {} |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 315 | |
| 316 | const blink::WebCryptoKeyFormat format; |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 317 | blink::WebVector<unsigned char> wrapped_key; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 318 | const blink::WebCryptoKey wrapping_key; |
| 319 | const blink::WebCryptoAlgorithm unwrap_algorithm; |
| 320 | const blink::WebCryptoAlgorithm unwrapped_key_algorithm; |
| 321 | const bool extractable; |
| 322 | const blink::WebCryptoKeyUsageMask usages; |
| 323 | |
| 324 | blink::WebCryptoKey unwrapped_key; |
| 325 | }; |
| 326 | |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 327 | struct DeriveBitsState : public BaseState { |
| 328 | DeriveBitsState(const blink::WebCryptoAlgorithm& algorithm, |
| 329 | const blink::WebCryptoKey& base_key, |
| 330 | unsigned int length_bits, |
| 331 | const blink::WebCryptoResult& result) |
| 332 | : BaseState(result), |
| 333 | algorithm(algorithm), |
| 334 | base_key(base_key), |
| 335 | length_bits(length_bits) {} |
| 336 | |
| 337 | const blink::WebCryptoAlgorithm algorithm; |
| 338 | const blink::WebCryptoKey base_key; |
| 339 | const unsigned int length_bits; |
| 340 | |
| 341 | std::vector<uint8_t> derived_bytes; |
| 342 | }; |
| 343 | |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 344 | struct DeriveKeyState : public BaseState { |
| 345 | DeriveKeyState(const blink::WebCryptoAlgorithm& algorithm, |
| 346 | const blink::WebCryptoKey& base_key, |
| 347 | const blink::WebCryptoAlgorithm& import_algorithm, |
| 348 | const blink::WebCryptoAlgorithm& key_length_algorithm, |
| 349 | bool extractable, |
| 350 | blink::WebCryptoKeyUsageMask usages, |
| 351 | const blink::WebCryptoResult& result) |
| 352 | : BaseState(result), |
| 353 | algorithm(algorithm), |
| 354 | base_key(base_key), |
| 355 | import_algorithm(import_algorithm), |
| 356 | key_length_algorithm(key_length_algorithm), |
| 357 | extractable(extractable), |
| 358 | usages(usages) {} |
| 359 | |
| 360 | const blink::WebCryptoAlgorithm algorithm; |
| 361 | const blink::WebCryptoKey base_key; |
| 362 | const blink::WebCryptoAlgorithm import_algorithm; |
| 363 | const blink::WebCryptoAlgorithm key_length_algorithm; |
| 364 | bool extractable; |
| 365 | blink::WebCryptoKeyUsageMask usages; |
| 366 | |
| 367 | blink::WebCryptoKey derived_key; |
| 368 | }; |
| 369 | |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 370 | // -------------------------------------------------------------------- |
| 371 | // Wrapper functions |
| 372 | // -------------------------------------------------------------------- |
| 373 | // |
| 374 | // * The methods named Do*() run on the crypto thread. |
| 375 | // * The methods named Do*Reply() run on the target Blink thread |
| 376 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 377 | void DoEncryptReply(std::unique_ptr<EncryptState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 378 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 379 | "DoEncryptReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 380 | CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
| 381 | } |
| 382 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 383 | void DoEncrypt(std::unique_ptr<EncryptState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 384 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoEncrypt"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 385 | EncryptState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 386 | if (state->cancelled()) |
| 387 | return; |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 388 | state->status = |
| 389 | webcrypto::Encrypt(state->algorithm, state->key, |
| 390 | webcrypto::CryptoData(state->data), &state->buffer); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 391 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 392 | FROM_HERE, base::Bind(DoEncryptReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 393 | } |
| 394 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 395 | void DoDecryptReply(std::unique_ptr<DecryptState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 396 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 397 | "DoDecryptReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 398 | CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
| 399 | } |
| 400 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 401 | void DoDecrypt(std::unique_ptr<DecryptState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 402 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoDecrypt"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 403 | DecryptState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 404 | if (state->cancelled()) |
| 405 | return; |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 406 | state->status = |
| 407 | webcrypto::Decrypt(state->algorithm, state->key, |
| 408 | webcrypto::CryptoData(state->data), &state->buffer); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 409 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 410 | FROM_HERE, base::Bind(DoDecryptReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 411 | } |
| 412 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 413 | void DoDigestReply(std::unique_ptr<DigestState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 414 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoDigestReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 415 | CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
| 416 | } |
| 417 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 418 | void DoDigest(std::unique_ptr<DigestState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 419 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoDigest"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 420 | DigestState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 421 | if (state->cancelled()) |
| 422 | return; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 423 | state->status = webcrypto::Digest( |
| 424 | state->algorithm, webcrypto::CryptoData(state->data), &state->buffer); |
| 425 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 426 | FROM_HERE, base::Bind(DoDigestReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 427 | } |
| 428 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 429 | void DoGenerateKeyReply(std::unique_ptr<GenerateKeyState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 430 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 431 | "DoGenerateKeyReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 432 | if (state->status.IsError()) { |
| 433 | CompleteWithError(state->status, &state->result); |
| 434 | } else { |
eroman | 9b747eaf | 2014-10-18 22:03:28 | [diff] [blame] | 435 | state->generate_key_result.Complete(&state->result); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 439 | void DoGenerateKey(std::unique_ptr<GenerateKeyState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 440 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoGenerateKey"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 441 | GenerateKeyState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 442 | if (state->cancelled()) |
| 443 | return; |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 444 | state->status = |
| 445 | webcrypto::GenerateKey(state->algorithm, state->extractable, |
| 446 | state->usages, &state->generate_key_result); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 447 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 448 | FROM_HERE, base::Bind(DoGenerateKeyReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 449 | } |
| 450 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 451 | void DoImportKeyReply(std::unique_ptr<ImportKeyState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 452 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 453 | "DoImportKeyReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 454 | CompleteWithKeyOrError(state->status, state->key, &state->result); |
| 455 | } |
| 456 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 457 | void DoImportKey(std::unique_ptr<ImportKeyState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 458 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoImportKey"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 459 | ImportKeyState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 460 | if (state->cancelled()) |
| 461 | return; |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 462 | state->status = webcrypto::ImportKey( |
| 463 | state->format, webcrypto::CryptoData(state->key_data), state->algorithm, |
| 464 | state->extractable, state->usages, &state->key); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 465 | if (state->status.IsSuccess()) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 466 | DCHECK(state->key.Handle()); |
| 467 | DCHECK(!state->key.Algorithm().IsNull()); |
| 468 | DCHECK_EQ(state->extractable, state->key.Extractable()); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 472 | FROM_HERE, base::Bind(DoImportKeyReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 473 | } |
| 474 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 475 | void DoExportKeyReply(std::unique_ptr<ExportKeyState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 476 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 477 | "DoExportKeyReply"); |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 478 | if (state->format != blink::kWebCryptoKeyFormatJwk) { |
[email protected] | b7deaa08 | 2014-06-17 22:24:37 | [diff] [blame] | 479 | CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
| 480 | return; |
| 481 | } |
| 482 | |
| 483 | if (state->status.IsError()) { |
| 484 | CompleteWithError(state->status, &state->result); |
| 485 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 486 | state->result.CompleteWithJson( |
davidben | aa62f38 | 2015-11-20 22:10:01 | [diff] [blame] | 487 | reinterpret_cast<const char*>(state->buffer.data()), |
brettw | 690c9667 | 2015-04-21 16:19:54 | [diff] [blame] | 488 | static_cast<unsigned int>(state->buffer.size())); |
[email protected] | b7deaa08 | 2014-06-17 22:24:37 | [diff] [blame] | 489 | } |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 490 | } |
| 491 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 492 | void DoExportKey(std::unique_ptr<ExportKeyState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 493 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoExportKey"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 494 | ExportKeyState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 495 | if (state->cancelled()) |
| 496 | return; |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 497 | state->status = |
| 498 | webcrypto::ExportKey(state->format, state->key, &state->buffer); |
| 499 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 500 | FROM_HERE, base::Bind(DoExportKeyReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 501 | } |
| 502 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 503 | void DoSignReply(std::unique_ptr<SignState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 504 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoSignReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 505 | CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
| 506 | } |
| 507 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 508 | void DoSign(std::unique_ptr<SignState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 509 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoSign"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 510 | SignState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 511 | if (state->cancelled()) |
| 512 | return; |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 513 | state->status = |
| 514 | webcrypto::Sign(state->algorithm, state->key, |
| 515 | webcrypto::CryptoData(state->data), &state->buffer); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 516 | |
| 517 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 518 | FROM_HERE, base::Bind(DoSignReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 519 | } |
| 520 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 521 | void DoVerifyReply(std::unique_ptr<VerifySignatureState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 522 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoVerifyReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 523 | if (state->status.IsError()) { |
| 524 | CompleteWithError(state->status, &state->result); |
| 525 | } else { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 526 | state->result.CompleteWithBoolean(state->verify_result); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 527 | } |
| 528 | } |
| 529 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 530 | void DoVerify(std::unique_ptr<VerifySignatureState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 531 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoVerify"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 532 | VerifySignatureState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 533 | if (state->cancelled()) |
| 534 | return; |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 535 | state->status = webcrypto::Verify( |
| 536 | state->algorithm, state->key, webcrypto::CryptoData(state->signature), |
| 537 | webcrypto::CryptoData(state->data), &state->verify_result); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 538 | |
| 539 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 540 | FROM_HERE, base::Bind(DoVerifyReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 541 | } |
| 542 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 543 | void DoWrapKeyReply(std::unique_ptr<WrapKeyState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 544 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 545 | "DoWrapKeyReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 546 | CompleteWithBufferOrError(state->status, state->buffer, &state->result); |
| 547 | } |
| 548 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 549 | void DoWrapKey(std::unique_ptr<WrapKeyState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 550 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoWrapKey"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 551 | WrapKeyState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 552 | if (state->cancelled()) |
| 553 | return; |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 554 | state->status = |
| 555 | webcrypto::WrapKey(state->format, state->key, state->wrapping_key, |
| 556 | state->wrap_algorithm, &state->buffer); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 557 | |
| 558 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 559 | FROM_HERE, base::Bind(DoWrapKeyReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 560 | } |
| 561 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 562 | void DoUnwrapKeyReply(std::unique_ptr<UnwrapKeyState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 563 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 564 | "DoUnwrapKeyReply"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 565 | CompleteWithKeyOrError(state->status, state->unwrapped_key, &state->result); |
| 566 | } |
| 567 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 568 | void DoUnwrapKey(std::unique_ptr<UnwrapKeyState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 569 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoUnwrapKey"); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 570 | UnwrapKeyState* state = passed_state.get(); |
[email protected] | 345bd20 | 2014-06-19 04:51:16 | [diff] [blame] | 571 | if (state->cancelled()) |
| 572 | return; |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 573 | state->status = webcrypto::UnwrapKey( |
| 574 | state->format, webcrypto::CryptoData(state->wrapped_key), |
| 575 | state->wrapping_key, state->unwrap_algorithm, |
| 576 | state->unwrapped_key_algorithm, state->extractable, state->usages, |
| 577 | &state->unwrapped_key); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 578 | |
| 579 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 580 | FROM_HERE, base::Bind(DoUnwrapKeyReply, base::Passed(&passed_state))); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 581 | } |
| 582 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 583 | void DoDeriveBitsReply(std::unique_ptr<DeriveBitsState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 584 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 585 | "DoDeriveBitsReply"); |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 586 | CompleteWithBufferOrError(state->status, state->derived_bytes, |
| 587 | &state->result); |
| 588 | } |
| 589 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 590 | void DoDeriveBits(std::unique_ptr<DeriveBitsState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 591 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoDeriveBits"); |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 592 | DeriveBitsState* state = passed_state.get(); |
| 593 | if (state->cancelled()) |
| 594 | return; |
| 595 | state->status = |
| 596 | webcrypto::DeriveBits(state->algorithm, state->base_key, |
| 597 | state->length_bits, &state->derived_bytes); |
| 598 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 599 | FROM_HERE, base::Bind(DoDeriveBitsReply, base::Passed(&passed_state))); |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 600 | } |
| 601 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 602 | void DoDeriveKeyReply(std::unique_ptr<DeriveKeyState> state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 603 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 604 | "DoDeriveKeyReply"); |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 605 | CompleteWithKeyOrError(state->status, state->derived_key, &state->result); |
| 606 | } |
| 607 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 608 | void DoDeriveKey(std::unique_ptr<DeriveKeyState> passed_state) { |
Alexei Filippov | b4e75fa | 2017-11-23 04:44:21 | [diff] [blame^] | 609 | TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "DoDeriveKey"); |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 610 | DeriveKeyState* state = passed_state.get(); |
| 611 | if (state->cancelled()) |
| 612 | return; |
| 613 | state->status = webcrypto::DeriveKey( |
| 614 | state->algorithm, state->base_key, state->import_algorithm, |
| 615 | state->key_length_algorithm, state->extractable, state->usages, |
| 616 | &state->derived_key); |
| 617 | state->origin_thread->PostTask( |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 618 | FROM_HERE, base::Bind(DoDeriveKeyReply, base::Passed(&passed_state))); |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 619 | } |
| 620 | |
[email protected] | 043cf1d3 | 2013-11-02 13:27:30 | [diff] [blame] | 621 | } // namespace |
| 622 | |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 623 | WebCryptoImpl::WebCryptoImpl() { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 624 | } |
[email protected] | 7e4c36f | 2013-09-12 06:10:19 | [diff] [blame] | 625 | |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 626 | WebCryptoImpl::~WebCryptoImpl() { |
| 627 | } |
[email protected] | 04166f8 | 2014-02-19 06:11:04 | [diff] [blame] | 628 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 629 | void WebCryptoImpl::Encrypt(const blink::WebCryptoAlgorithm& algorithm, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 630 | const blink::WebCryptoKey& key, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 631 | blink::WebVector<unsigned char> data, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 632 | blink::WebCryptoResult result) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 633 | DCHECK(!algorithm.IsNull()); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 634 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 635 | std::unique_ptr<EncryptState> state( |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 636 | new EncryptState(algorithm, key, std::move(data), result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 637 | if (!CryptoThreadPool::PostTask( |
| 638 | FROM_HERE, base::Bind(DoEncrypt, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 639 | CompleteWithThreadPoolError(&result); |
| 640 | } |
[email protected] | a2a06c73 | 2013-09-27 10:50:54 | [diff] [blame] | 641 | } |
| 642 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 643 | void WebCryptoImpl::Decrypt(const blink::WebCryptoAlgorithm& algorithm, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 644 | const blink::WebCryptoKey& key, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 645 | blink::WebVector<unsigned char> data, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 646 | blink::WebCryptoResult result) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 647 | DCHECK(!algorithm.IsNull()); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 648 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 649 | std::unique_ptr<DecryptState> state( |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 650 | new DecryptState(algorithm, key, std::move(data), result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 651 | if (!CryptoThreadPool::PostTask( |
| 652 | FROM_HERE, base::Bind(DoDecrypt, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 653 | CompleteWithThreadPoolError(&result); |
| 654 | } |
[email protected] | 868085a9 | 2013-10-01 00:42:30 | [diff] [blame] | 655 | } |
| 656 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 657 | void WebCryptoImpl::Digest(const blink::WebCryptoAlgorithm& algorithm, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 658 | blink::WebVector<unsigned char> data, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 659 | blink::WebCryptoResult result) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 660 | DCHECK(!algorithm.IsNull()); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 661 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 662 | std::unique_ptr<DigestState> state(new DigestState( |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 663 | algorithm, blink::WebCryptoKey::CreateNull(), std::move(data), result)); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 664 | if (!CryptoThreadPool::PostTask(FROM_HERE, |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 665 | base::Bind(DoDigest, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 666 | CompleteWithThreadPoolError(&result); |
| 667 | } |
[email protected] | 408699c | 2013-07-17 21:23:16 | [diff] [blame] | 668 | } |
| 669 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 670 | void WebCryptoImpl::GenerateKey(const blink::WebCryptoAlgorithm& algorithm, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 671 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 672 | blink::WebCryptoKeyUsageMask usages, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 673 | blink::WebCryptoResult result) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 674 | DCHECK(!algorithm.IsNull()); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 675 | |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 676 | std::unique_ptr<GenerateKeyState> state( |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 677 | new GenerateKeyState(algorithm, extractable, usages, result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 678 | if (!CryptoThreadPool::PostTask( |
| 679 | FROM_HERE, base::Bind(DoGenerateKey, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 680 | CompleteWithThreadPoolError(&result); |
[email protected] | dfae8ab | 2013-10-10 19:45:06 | [diff] [blame] | 681 | } |
| 682 | } |
| 683 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 684 | void WebCryptoImpl::ImportKey(blink::WebCryptoKeyFormat format, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 685 | blink::WebVector<unsigned char> key_data, |
[email protected] | c7a9468 | 2014-03-20 22:58:40 | [diff] [blame] | 686 | const blink::WebCryptoAlgorithm& algorithm, |
| 687 | bool extractable, |
eroman | 0e1d34e | 2014-10-21 19:13:31 | [diff] [blame] | 688 | blink::WebCryptoKeyUsageMask usages, |
[email protected] | c7a9468 | 2014-03-20 22:58:40 | [diff] [blame] | 689 | blink::WebCryptoResult result) { |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 690 | std::unique_ptr<ImportKeyState> state(new ImportKeyState( |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 691 | format, std::move(key_data), algorithm, extractable, usages, result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 692 | if (!CryptoThreadPool::PostTask( |
| 693 | FROM_HERE, base::Bind(DoImportKey, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 694 | CompleteWithThreadPoolError(&result); |
[email protected] | cca89748 | 2014-01-30 22:40:19 | [diff] [blame] | 695 | } |
[email protected] | 1c879bc9 | 2013-09-18 07:45:32 | [diff] [blame] | 696 | } |
| 697 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 698 | void WebCryptoImpl::ExportKey(blink::WebCryptoKeyFormat format, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 699 | const blink::WebCryptoKey& key, |
| 700 | blink::WebCryptoResult result) { |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 701 | std::unique_ptr<ExportKeyState> state( |
| 702 | new ExportKeyState(format, key, result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 703 | if (!CryptoThreadPool::PostTask( |
| 704 | FROM_HERE, base::Bind(DoExportKey, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 705 | CompleteWithThreadPoolError(&result); |
| 706 | } |
[email protected] | e9b2c10 | 2013-11-26 04:26:33 | [diff] [blame] | 707 | } |
| 708 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 709 | void WebCryptoImpl::Sign(const blink::WebCryptoAlgorithm& algorithm, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 710 | const blink::WebCryptoKey& key, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 711 | blink::WebVector<unsigned char> data, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 712 | blink::WebCryptoResult result) { |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 713 | std::unique_ptr<SignState> state( |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 714 | new SignState(algorithm, key, std::move(data), result)); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 715 | if (!CryptoThreadPool::PostTask(FROM_HERE, |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 716 | base::Bind(DoSign, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 717 | CompleteWithThreadPoolError(&result); |
| 718 | } |
[email protected] | 1c879bc9 | 2013-09-18 07:45:32 | [diff] [blame] | 719 | } |
| 720 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 721 | void WebCryptoImpl::VerifySignature(const blink::WebCryptoAlgorithm& algorithm, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 722 | const blink::WebCryptoKey& key, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 723 | blink::WebVector<unsigned char> signature, |
| 724 | blink::WebVector<unsigned char> data, |
[email protected] | a6032655 | 2014-02-19 22:58:24 | [diff] [blame] | 725 | blink::WebCryptoResult result) { |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 726 | std::unique_ptr<VerifySignatureState> state(new VerifySignatureState( |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 727 | algorithm, key, std::move(signature), std::move(data), result)); |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 728 | if (!CryptoThreadPool::PostTask(FROM_HERE, |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 729 | base::Bind(DoVerify, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 730 | CompleteWithThreadPoolError(&result); |
| 731 | } |
[email protected] | 3ed0026 | 2013-09-26 22:28:10 | [diff] [blame] | 732 | } |
| 733 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 734 | void WebCryptoImpl::WrapKey(blink::WebCryptoKeyFormat format, |
[email protected] | baa9284 | 2014-03-25 01:07:38 | [diff] [blame] | 735 | const blink::WebCryptoKey& key, |
| 736 | const blink::WebCryptoKey& wrapping_key, |
| 737 | const blink::WebCryptoAlgorithm& wrap_algorithm, |
| 738 | blink::WebCryptoResult result) { |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 739 | std::unique_ptr<WrapKeyState> state( |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 740 | new WrapKeyState(format, key, wrapping_key, wrap_algorithm, result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 741 | if (!CryptoThreadPool::PostTask( |
| 742 | FROM_HERE, base::Bind(DoWrapKey, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 743 | CompleteWithThreadPoolError(&result); |
| 744 | } |
[email protected] | baa9284 | 2014-03-25 01:07:38 | [diff] [blame] | 745 | } |
| 746 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 747 | void WebCryptoImpl::UnwrapKey( |
[email protected] | baa9284 | 2014-03-25 01:07:38 | [diff] [blame] | 748 | blink::WebCryptoKeyFormat format, |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 749 | blink::WebVector<unsigned char> wrapped_key, |
[email protected] | baa9284 | 2014-03-25 01:07:38 | [diff] [blame] | 750 | const blink::WebCryptoKey& wrapping_key, |
| 751 | const blink::WebCryptoAlgorithm& unwrap_algorithm, |
| 752 | const blink::WebCryptoAlgorithm& unwrapped_key_algorithm, |
| 753 | bool extractable, |
| 754 | blink::WebCryptoKeyUsageMask usages, |
| 755 | blink::WebCryptoResult result) { |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 756 | std::unique_ptr<UnwrapKeyState> state(new UnwrapKeyState( |
eroman | eeb3a0e | 2016-07-20 20:55:58 | [diff] [blame] | 757 | format, std::move(wrapped_key), wrapping_key, unwrap_algorithm, |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 758 | unwrapped_key_algorithm, extractable, usages, result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 759 | if (!CryptoThreadPool::PostTask( |
| 760 | FROM_HERE, base::Bind(DoUnwrapKey, base::Passed(&state)))) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 761 | CompleteWithThreadPoolError(&result); |
| 762 | } |
[email protected] | bd48e641 | 2014-02-22 08:32:53 | [diff] [blame] | 763 | } |
| 764 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 765 | void WebCryptoImpl::DeriveBits(const blink::WebCryptoAlgorithm& algorithm, |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 766 | const blink::WebCryptoKey& base_key, |
| 767 | unsigned int length_bits, |
| 768 | blink::WebCryptoResult result) { |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 769 | std::unique_ptr<DeriveBitsState> state( |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 770 | new DeriveBitsState(algorithm, base_key, length_bits, result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 771 | if (!CryptoThreadPool::PostTask( |
| 772 | FROM_HERE, base::Bind(DoDeriveBits, base::Passed(&state)))) { |
eroman | 1499b494 | 2014-11-26 19:59:53 | [diff] [blame] | 773 | CompleteWithThreadPoolError(&result); |
| 774 | } |
| 775 | } |
| 776 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 777 | void WebCryptoImpl::DeriveKey( |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 778 | const blink::WebCryptoAlgorithm& algorithm, |
| 779 | const blink::WebCryptoKey& base_key, |
| 780 | const blink::WebCryptoAlgorithm& import_algorithm, |
| 781 | const blink::WebCryptoAlgorithm& key_length_algorithm, |
| 782 | bool extractable, |
| 783 | blink::WebCryptoKeyUsageMask usages, |
| 784 | blink::WebCryptoResult result) { |
dcheng | 7036d1e5 | 2016-04-21 23:13:03 | [diff] [blame] | 785 | std::unique_ptr<DeriveKeyState> state( |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 786 | new DeriveKeyState(algorithm, base_key, import_algorithm, |
| 787 | key_length_algorithm, extractable, usages, result)); |
dcheng | 0917ec4 | 2015-11-19 07:00:20 | [diff] [blame] | 788 | if (!CryptoThreadPool::PostTask( |
| 789 | FROM_HERE, base::Bind(DoDeriveKey, base::Passed(&state)))) { |
eroman | 20bf4c3c | 2014-12-12 17:22:37 | [diff] [blame] | 790 | CompleteWithThreadPoolError(&result); |
| 791 | } |
| 792 | } |
| 793 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 794 | std::unique_ptr<blink::WebCryptoDigestor> WebCryptoImpl::CreateDigestor( |
[email protected] | 6f778f0 | 2014-04-01 02:31:33 | [diff] [blame] | 795 | blink::WebCryptoAlgorithmId algorithm_id) { |
dcheng | 7578e8ee | 2016-07-13 03:52:45 | [diff] [blame] | 796 | return webcrypto::CreateDigestor(algorithm_id); |
[email protected] | 6f778f0 | 2014-04-01 02:31:33 | [diff] [blame] | 797 | } |
| 798 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 799 | bool WebCryptoImpl::DeserializeKeyForClone( |
[email protected] | 5daca047 | 2014-03-18 20:27:08 | [diff] [blame] | 800 | const blink::WebCryptoKeyAlgorithm& algorithm, |
| 801 | blink::WebCryptoKeyType type, |
| 802 | bool extractable, |
| 803 | blink::WebCryptoKeyUsageMask usages, |
| 804 | const unsigned char* key_data, |
| 805 | unsigned key_data_size, |
| 806 | blink::WebCryptoKey& key) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 807 | return webcrypto::DeserializeKeyForClone( |
eroman | 38bb4bd | 2014-11-24 23:47:06 | [diff] [blame] | 808 | algorithm, type, extractable, usages, |
| 809 | webcrypto::CryptoData(key_data, key_data_size), &key); |
[email protected] | 5daca047 | 2014-03-18 20:27:08 | [diff] [blame] | 810 | } |
| 811 | |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 812 | bool WebCryptoImpl::SerializeKeyForClone( |
[email protected] | 5daca047 | 2014-03-18 20:27:08 | [diff] [blame] | 813 | const blink::WebCryptoKey& key, |
| 814 | blink::WebVector<unsigned char>& key_data) { |
[email protected] | 88be9856 | 2014-04-30 11:18:59 | [diff] [blame] | 815 | return webcrypto::SerializeKeyForClone(key, &key_data); |
[email protected] | 5daca047 | 2014-03-18 20:27:08 | [diff] [blame] | 816 | } |
| 817 | |
erg | 56f1232 | 2015-04-17 00:51:48 | [diff] [blame] | 818 | } // namespace webcrypto |