| 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/algorithm_dispatch.h" | 5 #include "content/child/webcrypto/algorithm_dispatch.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/child/webcrypto/algorithm_implementation.h" | 8 #include "content/child/webcrypto/algorithm_implementation.h" |
| 9 #include "content/child/webcrypto/algorithm_registry.h" | 9 #include "content/child/webcrypto/algorithm_registry.h" |
| 10 #include "content/child/webcrypto/crypto_data.h" | 10 #include "content/child/webcrypto/crypto_data.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 Status Verify(const blink::WebCryptoAlgorithm& algorithm, | 205 Status Verify(const blink::WebCryptoAlgorithm& algorithm, |
| 206 const blink::WebCryptoKey& key, | 206 const blink::WebCryptoKey& key, |
| 207 const CryptoData& signature, | 207 const CryptoData& signature, |
| 208 const CryptoData& data, | 208 const CryptoData& data, |
| 209 bool* signature_match) { | 209 bool* signature_match) { |
| 210 if (!KeyUsageAllows(key, blink::WebCryptoKeyUsageVerify)) | 210 if (!KeyUsageAllows(key, blink::WebCryptoKeyUsageVerify)) |
| 211 return Status::ErrorUnexpected(); | 211 return Status::ErrorUnexpected(); |
| 212 if (algorithm.id() != key.algorithm().id()) | 212 if (algorithm.id() != key.algorithm().id()) |
| 213 return Status::ErrorUnexpected(); | 213 return Status::ErrorUnexpected(); |
| 214 | 214 |
| 215 // TODO(eroman): Move this into implementation which need it instead. | |
| 216 if (!signature.byte_length()) { | |
| 217 // None of the algorithms generate valid zero-length signatures so this | |
| 218 // will necessarily fail verification. Early return to protect | |
| 219 // implementations from dealing with a NULL signature pointer. | |
| 220 *signature_match = false; | |
| 221 return Status::Success(); | |
| 222 } | |
| 223 | |
| 224 const AlgorithmImplementation* impl = NULL; | 215 const AlgorithmImplementation* impl = NULL; |
| 225 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); | 216 Status status = GetAlgorithmImplementation(algorithm.id(), &impl); |
| 226 if (status.IsError()) | 217 if (status.IsError()) |
| 227 return status; | 218 return status; |
| 228 | 219 |
| 229 return impl->Verify(algorithm, key, signature, data, signature_match); | 220 return impl->Verify(algorithm, key, signature, data, signature_match); |
| 230 } | 221 } |
| 231 | 222 |
| 232 Status WrapKey(blink::WebCryptoKeyFormat format, | 223 Status WrapKey(blink::WebCryptoKeyFormat format, |
| 233 const blink::WebCryptoKey& key_to_wrap, | 224 const blink::WebCryptoKey& key_to_wrap, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 276 |
| 286 scoped_ptr<blink::WebCryptoDigestor> CreateDigestor( | 277 scoped_ptr<blink::WebCryptoDigestor> CreateDigestor( |
| 287 blink::WebCryptoAlgorithmId algorithm) { | 278 blink::WebCryptoAlgorithmId algorithm) { |
| 288 PlatformInit(); | 279 PlatformInit(); |
| 289 return CreatePlatformDigestor(algorithm); | 280 return CreatePlatformDigestor(algorithm); |
| 290 } | 281 } |
| 291 | 282 |
| 292 } // namespace webcrypto | 283 } // namespace webcrypto |
| 293 | 284 |
| 294 } // namespace content | 285 } // namespace content |
| OLD | NEW |