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/trusted/validator/validation_cache.h" | 10 #include "native_client/src/trusted/validator/validation_cache.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 CHECK(nacl_version.length() >= 4); | 22 CHECK(nacl_version.length() >= 4); |
23 } | 23 } |
24 | 24 |
25 NaClValidationQuery* NaClValidationQueryContext::CreateQuery() { | 25 NaClValidationQuery* NaClValidationQueryContext::CreateQuery() { |
26 NaClValidationQuery* query = new NaClValidationQuery(db_, profile_key_); | 26 NaClValidationQuery* query = new NaClValidationQuery(db_, profile_key_); |
27 // Changing the version effectively invalidates existing hashes. | 27 // Changing the version effectively invalidates existing hashes. |
28 query->AddData(nacl_version_); | 28 query->AddData(nacl_version_); |
29 return query; | 29 return query; |
30 } | 30 } |
31 | 31 |
32 bool NaClValidationQueryContext::ResolveFileNonce(uint64 nonce, int32* fd, | |
33 std::string* path) { | |
34 return db_->ResolveFileNonce(nonce, fd, path); | |
35 } | |
36 | |
32 NaClValidationQuery::NaClValidationQuery(NaClValidationDB* db, | 37 NaClValidationQuery::NaClValidationQuery(NaClValidationDB* db, |
33 const std::string& profile_key) | 38 const std::string& profile_key) |
34 : state_(READY), | 39 : state_(READY), |
35 hasher_(crypto::HMAC::SHA256), | 40 hasher_(crypto::HMAC::SHA256), |
36 db_(db), | 41 db_(db), |
37 buffer_length_(0) { | 42 buffer_length_(0) { |
38 // Without this line on Linux, HMAC::Init will instantiate a singleton that | 43 // 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 | 44 // in turn attempts to open a file. Disabling this behavior avoids a ~70 ms |
40 // stall the first time HMAC is used. | 45 // stall the first time HMAC is used. |
41 // This function is also called in nacl_helper_linux.cc, but nacl_helper may | 46 // 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 } | 125 } |
121 | 126 |
122 static void SetKnownToValidate(void* query) { | 127 static void SetKnownToValidate(void* query) { |
123 static_cast<NaClValidationQuery*>(query)->SetKnownToValidate(); | 128 static_cast<NaClValidationQuery*>(query)->SetKnownToValidate(); |
124 } | 129 } |
125 | 130 |
126 static void DestroyQuery(void* query) { | 131 static void DestroyQuery(void* query) { |
127 delete static_cast<NaClValidationQuery*>(query); | 132 delete static_cast<NaClValidationQuery*>(query); |
128 } | 133 } |
129 | 134 |
135 static int ResolveFileNonce(void* handle, uint64 nonce, int32* fd, | |
Mark Seaborn
2013/05/16 23:01:47
So you're returning absolute filenames to the NaCl
Nick Bray (chromium)
2013/05/21 20:09:06
Security team is not worried, and I have too much
| |
136 char** file_path, uint32 *file_path_length) { | |
137 std::string path; | |
138 *file_path = NULL; | |
139 *file_path_length = 0; | |
140 bool ok = static_cast<NaClValidationQueryContext*>(handle)-> | |
141 ResolveFileNonce(nonce, fd, &path); | |
142 if (ok) { | |
143 *file_path = (char *) malloc(path.length() + 1); | |
Mark Seaborn
2013/05/16 23:01:47
Use C++-style casts?
Nick Bray (chromium)
2013/05/21 20:09:06
Done.
| |
144 CHECK(*file_path); | |
145 memcpy(*file_path, path.data(), path.length()); | |
146 (*file_path)[path.length()] = 0; | |
147 *file_path_length = (uint32) path.length(); | |
Mark Seaborn
2013/05/16 23:01:47
Ditto
Nick Bray (chromium)
2013/05/21 20:09:06
Done.
| |
148 } | |
149 return ok; | |
150 } | |
151 | |
130 struct NaClValidationCache* CreateValidationCache( | 152 struct NaClValidationCache* CreateValidationCache( |
131 NaClValidationDB* db, const std::string& profile_key, | 153 NaClValidationDB* db, const std::string& profile_key, |
132 const std::string& nacl_version) { | 154 const std::string& nacl_version) { |
133 NaClValidationCache* cache = | 155 NaClValidationCache* cache = |
134 static_cast<NaClValidationCache*>(malloc(sizeof(NaClValidationCache))); | 156 static_cast<NaClValidationCache*>(malloc(sizeof(NaClValidationCache))); |
135 // Make sure any fields introduced in a cross-repo change are zeroed. | 157 // Make sure any fields introduced in a cross-repo change are zeroed. |
136 memset(cache, 0, sizeof(*cache)); | 158 memset(cache, 0, sizeof(*cache)); |
137 cache->handle = new NaClValidationQueryContext(db, profile_key, nacl_version); | 159 cache->handle = new NaClValidationQueryContext(db, profile_key, nacl_version); |
138 cache->CreateQuery = CreateQuery; | 160 cache->CreateQuery = CreateQuery; |
139 cache->AddData = AddData; | 161 cache->AddData = AddData; |
140 cache->QueryKnownToValidate = QueryKnownToValidate; | 162 cache->QueryKnownToValidate = QueryKnownToValidate; |
141 cache->SetKnownToValidate = SetKnownToValidate; | 163 cache->SetKnownToValidate = SetKnownToValidate; |
142 cache->DestroyQuery = DestroyQuery; | 164 cache->DestroyQuery = DestroyQuery; |
165 cache->ResolveFileNonce = ResolveFileNonce; | |
143 return cache; | 166 return cache; |
144 } | 167 } |
OLD | NEW |