| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/renderer/webcrypto/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 176 |
| 177 void WebCryptoImpl::encrypt( | 177 void WebCryptoImpl::encrypt( |
| 178 const blink::WebCryptoAlgorithm& algorithm, | 178 const blink::WebCryptoAlgorithm& algorithm, |
| 179 const blink::WebCryptoKey& key, | 179 const blink::WebCryptoKey& key, |
| 180 const unsigned char* data, | 180 const unsigned char* data, |
| 181 unsigned data_size, | 181 unsigned data_size, |
| 182 blink::WebCryptoResult result) { | 182 blink::WebCryptoResult result) { |
| 183 DCHECK(!algorithm.isNull()); | 183 DCHECK(!algorithm.isNull()); |
| 184 blink::WebArrayBuffer buffer; | 184 blink::WebArrayBuffer buffer; |
| 185 Status status = EncryptInternal(algorithm, key, data, data_size, &buffer); | 185 Status status = EncryptInternal(algorithm, key, data, data_size, &buffer); |
| 186 if (status.IsError()) { | 186 if (status.IsError()) |
| 187 CompleteWithError(status, &result); | 187 CompleteWithError(status, &result); |
| 188 } else { | 188 else |
| 189 result.completeWithBuffer(buffer); | 189 result.completeWithBuffer(buffer); |
| 190 } | |
| 191 } | 190 } |
| 192 | 191 |
| 193 void WebCryptoImpl::decrypt( | 192 void WebCryptoImpl::decrypt( |
| 194 const blink::WebCryptoAlgorithm& algorithm, | 193 const blink::WebCryptoAlgorithm& algorithm, |
| 195 const blink::WebCryptoKey& key, | 194 const blink::WebCryptoKey& key, |
| 196 const unsigned char* data, | 195 const unsigned char* data, |
| 197 unsigned data_size, | 196 unsigned data_size, |
| 198 blink::WebCryptoResult result) { | 197 blink::WebCryptoResult result) { |
| 199 DCHECK(!algorithm.isNull()); | 198 DCHECK(!algorithm.isNull()); |
| 200 blink::WebArrayBuffer buffer; | 199 blink::WebArrayBuffer buffer; |
| 201 Status status = DecryptInternal(algorithm, key, data, data_size, &buffer); | 200 Status status = DecryptInternal(algorithm, key, data, data_size, &buffer); |
| 202 if (status.IsError()) { | 201 if (status.IsError()) |
| 203 CompleteWithError(status, &result); | 202 CompleteWithError(status, &result); |
| 204 } else { | 203 else |
| 205 result.completeWithBuffer(buffer); | 204 result.completeWithBuffer(buffer); |
| 206 } | |
| 207 } | 205 } |
| 208 | 206 |
| 209 void WebCryptoImpl::digest( | 207 void WebCryptoImpl::digest( |
| 210 const blink::WebCryptoAlgorithm& algorithm, | 208 const blink::WebCryptoAlgorithm& algorithm, |
| 211 const unsigned char* data, | 209 const unsigned char* data, |
| 212 unsigned data_size, | 210 unsigned data_size, |
| 213 blink::WebCryptoResult result) { | 211 blink::WebCryptoResult result) { |
| 214 DCHECK(!algorithm.isNull()); | 212 DCHECK(!algorithm.isNull()); |
| 215 blink::WebArrayBuffer buffer; | 213 blink::WebArrayBuffer buffer; |
| 216 Status status = DigestInternal(algorithm, data, data_size, &buffer); | 214 Status status = DigestInternal(algorithm, data, data_size, &buffer); |
| 217 if (status.IsError()) { | 215 if (status.IsError()) |
| 218 CompleteWithError(status, &result); | 216 CompleteWithError(status, &result); |
| 219 } else { | 217 else |
| 220 result.completeWithBuffer(buffer); | 218 result.completeWithBuffer(buffer); |
| 221 } | |
| 222 } | 219 } |
| 223 | 220 |
| 224 void WebCryptoImpl::generateKey( | 221 void WebCryptoImpl::generateKey( |
| 225 const blink::WebCryptoAlgorithm& algorithm, | 222 const blink::WebCryptoAlgorithm& algorithm, |
| 226 bool extractable, | 223 bool extractable, |
| 227 blink::WebCryptoKeyUsageMask usage_mask, | 224 blink::WebCryptoKeyUsageMask usage_mask, |
| 228 blink::WebCryptoResult result) { | 225 blink::WebCryptoResult result) { |
| 229 DCHECK(!algorithm.isNull()); | 226 DCHECK(!algorithm.isNull()); |
| 230 if (IsAlgorithmAsymmetric(algorithm)) { | 227 if (IsAlgorithmAsymmetric(algorithm)) { |
| 231 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 228 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 result.completeWithKey(key); | 293 result.completeWithKey(key); |
| 297 } | 294 } |
| 298 } | 295 } |
| 299 | 296 |
| 300 void WebCryptoImpl::exportKey( | 297 void WebCryptoImpl::exportKey( |
| 301 blink::WebCryptoKeyFormat format, | 298 blink::WebCryptoKeyFormat format, |
| 302 const blink::WebCryptoKey& key, | 299 const blink::WebCryptoKey& key, |
| 303 blink::WebCryptoResult result) { | 300 blink::WebCryptoResult result) { |
| 304 blink::WebArrayBuffer buffer; | 301 blink::WebArrayBuffer buffer; |
| 305 Status status = ExportKeyInternal(format, key, &buffer); | 302 Status status = ExportKeyInternal(format, key, &buffer); |
| 306 if (status.IsError()) { | 303 if (status.IsError()) |
| 307 CompleteWithError(status, &result); | 304 CompleteWithError(status, &result); |
| 308 } else { | 305 else |
| 309 result.completeWithBuffer(buffer); | 306 result.completeWithBuffer(buffer); |
| 310 } | |
| 311 } | 307 } |
| 312 | 308 |
| 313 void WebCryptoImpl::sign( | 309 void WebCryptoImpl::sign( |
| 314 const blink::WebCryptoAlgorithm& algorithm, | 310 const blink::WebCryptoAlgorithm& algorithm, |
| 315 const blink::WebCryptoKey& key, | 311 const blink::WebCryptoKey& key, |
| 316 const unsigned char* data, | 312 const unsigned char* data, |
| 317 unsigned data_size, | 313 unsigned data_size, |
| 318 blink::WebCryptoResult result) { | 314 blink::WebCryptoResult result) { |
| 319 DCHECK(!algorithm.isNull()); | 315 DCHECK(!algorithm.isNull()); |
| 320 blink::WebArrayBuffer buffer; | 316 blink::WebArrayBuffer buffer; |
| 321 Status status = SignInternal(algorithm, key, data, data_size, &buffer); | 317 Status status = SignInternal(algorithm, key, data, data_size, &buffer); |
| 322 if (status.IsError()) { | 318 if (status.IsError()) |
| 323 CompleteWithError(status, &result); | 319 CompleteWithError(status, &result); |
| 324 } else { | 320 else |
| 325 result.completeWithBuffer(buffer); | 321 result.completeWithBuffer(buffer); |
| 326 } | |
| 327 } | 322 } |
| 328 | 323 |
| 329 void WebCryptoImpl::verifySignature( | 324 void WebCryptoImpl::verifySignature( |
| 330 const blink::WebCryptoAlgorithm& algorithm, | 325 const blink::WebCryptoAlgorithm& algorithm, |
| 331 const blink::WebCryptoKey& key, | 326 const blink::WebCryptoKey& key, |
| 332 const unsigned char* signature, | 327 const unsigned char* signature, |
| 333 unsigned signature_size, | 328 unsigned signature_size, |
| 334 const unsigned char* data, | 329 const unsigned char* data, |
| 335 unsigned data_size, | 330 unsigned data_size, |
| 336 blink::WebCryptoResult result) { | 331 blink::WebCryptoResult result) { |
| 337 DCHECK(!algorithm.isNull()); | 332 DCHECK(!algorithm.isNull()); |
| 338 bool signature_match = false; | 333 bool signature_match = false; |
| 339 Status status = VerifySignatureInternal(algorithm, | 334 Status status = VerifySignatureInternal(algorithm, |
| 340 key, | 335 key, |
| 341 signature, | 336 signature, |
| 342 signature_size, | 337 signature_size, |
| 343 data, | 338 data, |
| 344 data_size, | 339 data_size, |
| 345 &signature_match); | 340 &signature_match); |
| 346 if (status.IsError()) { | 341 if (status.IsError()) |
| 347 CompleteWithError(status, &result); | 342 CompleteWithError(status, &result); |
| 348 } else { | 343 else |
| 349 result.completeWithBoolean(signature_match); | 344 result.completeWithBoolean(signature_match); |
| 350 } | |
| 351 } | 345 } |
| 352 | 346 |
| 353 Status WebCryptoImpl::ImportKeyJwk( | 347 Status WebCryptoImpl::ImportKeyJwk( |
| 354 const unsigned char* key_data, | 348 const unsigned char* key_data, |
| 355 unsigned key_data_size, | 349 unsigned key_data_size, |
| 356 const blink::WebCryptoAlgorithm& algorithm_or_null, | 350 const blink::WebCryptoAlgorithm& algorithm_or_null, |
| 357 bool extractable, | 351 bool extractable, |
| 358 blink::WebCryptoKeyUsageMask usage_mask, | 352 blink::WebCryptoKeyUsageMask usage_mask, |
| 359 blink::WebCryptoKey* key) { | 353 blink::WebCryptoKey* key) { |
| 360 | 354 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 key); | 631 key); |
| 638 | 632 |
| 639 } else { | 633 } else { |
| 640 return Status::ErrorJwkUnrecognizedKty(); | 634 return Status::ErrorJwkUnrecognizedKty(); |
| 641 } | 635 } |
| 642 | 636 |
| 643 return Status::Success(); | 637 return Status::Success(); |
| 644 } | 638 } |
| 645 | 639 |
| 646 } // namespace content | 640 } // namespace content |
| OLD | NEW |