OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <openssl/evp.h> | 5 #include <openssl/evp.h> |
6 #include <openssl/rsa.h> | 6 #include <openssl/rsa.h> |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
20 #include "base/stl_util.h" | |
21 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
23 #include "base/values.h" | 22 #include "base/values.h" |
24 #include "chrome/browser/extensions/extension_apitest.h" | 23 #include "chrome/browser/extensions/extension_apitest.h" |
25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
26 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
27 #include "components/policy/core/browser/browser_policy_connector.h" | 26 #include "components/policy/core/browser/browser_policy_connector.h" |
28 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 27 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
29 #include "components/policy/core/common/policy_map.h" | 28 #include "components/policy/core/common/policy_map.h" |
30 #include "components/policy/core/common/policy_types.h" | 29 #include "components/policy/core/common/policy_types.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 crypto::RSAPrivateKey* key, | 80 crypto::RSAPrivateKey* key, |
82 std::vector<uint8_t>* signature) { | 81 std::vector<uint8_t>* signature) { |
83 crypto::ScopedRSA rsa_key(EVP_PKEY_get1_RSA(key->key())); | 82 crypto::ScopedRSA rsa_key(EVP_PKEY_get1_RSA(key->key())); |
84 if (!rsa_key) | 83 if (!rsa_key) |
85 return false; | 84 return false; |
86 | 85 |
87 uint8_t* prefixed_digest = nullptr; | 86 uint8_t* prefixed_digest = nullptr; |
88 size_t prefixed_digest_len = 0; | 87 size_t prefixed_digest_len = 0; |
89 int is_alloced = 0; | 88 int is_alloced = 0; |
90 if (!RSA_add_pkcs1_prefix(&prefixed_digest, &prefixed_digest_len, &is_alloced, | 89 if (!RSA_add_pkcs1_prefix(&prefixed_digest, &prefixed_digest_len, &is_alloced, |
91 NID_sha1, vector_as_array(&digest), | 90 NID_sha1, digest.data(), digest.size())) { |
92 digest.size())) { | |
93 return false; | 91 return false; |
94 } | 92 } |
95 size_t len = 0; | 93 size_t len = 0; |
96 signature->resize(RSA_size(rsa_key.get())); | 94 signature->resize(RSA_size(rsa_key.get())); |
97 const int rv = RSA_sign_raw(rsa_key.get(), &len, vector_as_array(signature), | 95 const int rv = |
98 signature->size(), prefixed_digest, | 96 RSA_sign_raw(rsa_key.get(), &len, signature->data(), signature->size(), |
99 prefixed_digest_len, RSA_PKCS1_PADDING); | 97 prefixed_digest, prefixed_digest_len, RSA_PKCS1_PADDING); |
100 if (is_alloced) | 98 if (is_alloced) |
101 free(prefixed_digest); | 99 free(prefixed_digest); |
102 | 100 |
103 if (rv) { | 101 if (rv) { |
104 signature->resize(len); | 102 signature->resize(len); |
105 return true; | 103 return true; |
106 } else { | 104 } else { |
107 signature->clear(); | 105 signature->clear(); |
108 return false; | 106 return false; |
109 } | 107 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 base::RunLoop run_loop; | 254 base::RunLoop run_loop; |
257 const std::string code = "replyWithSignatureSecondTime();"; | 255 const std::string code = "replyWithSignatureSecondTime();"; |
258 bool result = false; | 256 bool result = false; |
259 extension_contents->GetMainFrame()->ExecuteJavaScriptForTests( | 257 extension_contents->GetMainFrame()->ExecuteJavaScriptForTests( |
260 base::ASCIIToUTF16(code), | 258 base::ASCIIToUTF16(code), |
261 base::Bind(&StoreBool, &result, run_loop.QuitClosure())); | 259 base::Bind(&StoreBool, &result, run_loop.QuitClosure())); |
262 run_loop.Run(); | 260 run_loop.Run(); |
263 EXPECT_TRUE(result); | 261 EXPECT_TRUE(result); |
264 } | 262 } |
265 } | 263 } |
OLD | NEW |