OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/nacl/nacl_validation_query.h" | 5 #include "chrome/nacl/nacl_validation_query.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "crypto/nss_util.h" | 8 #include "crypto/nss_util.h" |
9 #include "chrome/nacl/nacl_validation_db.h" | 9 #include "chrome/nacl/nacl_validation_db.h" |
10 #include "native_client/src/include/portability.h" | |
Mark Seaborn
2013/05/24 22:48:11
Why? You shouldn't be using native_client/src/inc
| |
11 #include "native_client/src/trusted/validator/nacl_file_info.h" | |
10 #include "native_client/src/trusted/validator/validation_cache.h" | 12 #include "native_client/src/trusted/validator/validation_cache.h" |
11 | 13 |
12 NaClValidationQueryContext::NaClValidationQueryContext( | 14 NaClValidationQueryContext::NaClValidationQueryContext( |
13 NaClValidationDB* db, | 15 NaClValidationDB* db, |
14 const std::string& profile_key, | 16 const std::string& profile_key, |
15 const std::string& nacl_version) | 17 const std::string& nacl_version) |
16 : db_(db), | 18 : db_(db), |
17 profile_key_(profile_key), | 19 profile_key_(profile_key), |
18 nacl_version_(nacl_version) { | 20 nacl_version_(nacl_version) { |
19 | 21 |
20 // Sanity checks. | 22 // Sanity checks. |
21 CHECK(profile_key.length() >= 8); | 23 CHECK(profile_key.length() >= 8); |
22 CHECK(nacl_version.length() >= 4); | 24 CHECK(nacl_version.length() >= 4); |
23 } | 25 } |
24 | 26 |
25 NaClValidationQuery* NaClValidationQueryContext::CreateQuery() { | 27 NaClValidationQuery* NaClValidationQueryContext::CreateQuery() { |
26 NaClValidationQuery* query = new NaClValidationQuery(db_, profile_key_); | 28 NaClValidationQuery* query = new NaClValidationQuery(db_, profile_key_); |
27 // Changing the version effectively invalidates existing hashes. | 29 // Changing the version effectively invalidates existing hashes. |
28 query->AddData(nacl_version_); | 30 query->AddData(nacl_version_); |
29 return query; | 31 return query; |
30 } | 32 } |
31 | 33 |
34 bool NaClValidationQueryContext::ResolveFileToken( | |
35 struct NaClFileToken* file_token, | |
36 int32* fd, | |
37 std::string* path) { | |
38 return db_->ResolveFileToken(file_token, fd, path); | |
39 } | |
40 | |
32 NaClValidationQuery::NaClValidationQuery(NaClValidationDB* db, | 41 NaClValidationQuery::NaClValidationQuery(NaClValidationDB* db, |
33 const std::string& profile_key) | 42 const std::string& profile_key) |
34 : state_(READY), | 43 : state_(READY), |
35 hasher_(crypto::HMAC::SHA256), | 44 hasher_(crypto::HMAC::SHA256), |
36 db_(db), | 45 db_(db), |
37 buffer_length_(0) { | 46 buffer_length_(0) { |
38 // Without this line on Linux, HMAC::Init will instantiate a singleton that | 47 // Without this line on Linux, HMAC::Init will instantiate a singleton that |
39 // in turn attempts to open a file. Disabling this behavior avoids a ~70 ms | 48 // in turn attempts to open a file. Disabling this behavior avoids a ~70 ms |
40 // stall the first time HMAC is used. | 49 // stall the first time HMAC is used. |
41 // This function is also called in nacl_helper_linux.cc, but nacl_helper may | 50 // This function is also called in nacl_helper_linux.cc, but nacl_helper may |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 129 } |
121 | 130 |
122 static void SetKnownToValidate(void* query) { | 131 static void SetKnownToValidate(void* query) { |
123 static_cast<NaClValidationQuery*>(query)->SetKnownToValidate(); | 132 static_cast<NaClValidationQuery*>(query)->SetKnownToValidate(); |
124 } | 133 } |
125 | 134 |
126 static void DestroyQuery(void* query) { | 135 static void DestroyQuery(void* query) { |
127 delete static_cast<NaClValidationQuery*>(query); | 136 delete static_cast<NaClValidationQuery*>(query); |
128 } | 137 } |
129 | 138 |
139 static int ResolveFileToken(void* handle, struct NaClFileToken* file_token, | |
140 int32* fd, char** file_path, | |
141 uint32* file_path_length) { | |
142 std::string path; | |
143 *file_path = NULL; | |
144 *file_path_length = 0; | |
145 bool ok = static_cast<NaClValidationQueryContext*>(handle)-> | |
146 ResolveFileToken(file_token, fd, &path); | |
147 if (ok) { | |
148 *file_path = static_cast<char*>(malloc(path.length() + 1)); | |
149 CHECK(*file_path); | |
150 memcpy(*file_path, path.data(), path.length()); | |
151 (*file_path)[path.length()] = 0; | |
152 *file_path_length = static_cast<uint32>(path.length()); | |
153 } | |
154 return ok; | |
155 } | |
156 | |
130 struct NaClValidationCache* CreateValidationCache( | 157 struct NaClValidationCache* CreateValidationCache( |
131 NaClValidationDB* db, const std::string& profile_key, | 158 NaClValidationDB* db, const std::string& profile_key, |
132 const std::string& nacl_version) { | 159 const std::string& nacl_version) { |
133 NaClValidationCache* cache = | 160 NaClValidationCache* cache = |
134 static_cast<NaClValidationCache*>(malloc(sizeof(NaClValidationCache))); | 161 static_cast<NaClValidationCache*>(malloc(sizeof(NaClValidationCache))); |
135 // Make sure any fields introduced in a cross-repo change are zeroed. | 162 // Make sure any fields introduced in a cross-repo change are zeroed. |
136 memset(cache, 0, sizeof(*cache)); | 163 memset(cache, 0, sizeof(*cache)); |
137 cache->handle = new NaClValidationQueryContext(db, profile_key, nacl_version); | 164 cache->handle = new NaClValidationQueryContext(db, profile_key, nacl_version); |
138 cache->CreateQuery = CreateQuery; | 165 cache->CreateQuery = CreateQuery; |
139 cache->AddData = AddData; | 166 cache->AddData = AddData; |
140 cache->QueryKnownToValidate = QueryKnownToValidate; | 167 cache->QueryKnownToValidate = QueryKnownToValidate; |
141 cache->SetKnownToValidate = SetKnownToValidate; | 168 cache->SetKnownToValidate = SetKnownToValidate; |
142 cache->DestroyQuery = DestroyQuery; | 169 cache->DestroyQuery = DestroyQuery; |
170 cache->ResolveFileToken = ResolveFileToken; | |
143 return cache; | 171 return cache; |
144 } | 172 } |
OLD | NEW |