Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chromeos/dbus/fake_cryptohome_client.cc

Issue 258743005: Enable Enterprise enrollment on desktop builds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added arg to PathService::OverrideAndCreateIfNeeded, added test for FakeCryptohomeClient::InstallAt… Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/chromeos_paths.cc ('k') | chromeos/dbus/fake_session_manager_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chromeos/dbus/fake_cryptohome_client.h" 5 #include "chromeos/dbus/fake_cryptohome_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h"
8 #include "base/location.h" 9 #include "base/location.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/path_service.h"
12 #include "base/threading/worker_pool.h"
13 #include "chromeos/chromeos_paths.h"
10 #include "chromeos/dbus/cryptohome/key.pb.h" 14 #include "chromeos/dbus/cryptohome/key.pb.h"
11 #include "chromeos/dbus/cryptohome/rpc.pb.h" 15 #include "chromeos/dbus/cryptohome/rpc.pb.h"
12 #include "crypto/nss_util.h" 16 #include "crypto/nss_util.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 17 #include "third_party/cros_system_api/dbus/service_constants.h"
18 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h"
19 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h"
20 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite .h"
21
22 namespace {
23
24 // Helper to asynchronously write a file in the WorkerPool.
25 void PersistFile(const base::FilePath& path, const std::string& content) {
26 base::WriteFile(path, content.data(), content.size());
27 }
28
29 } // namespace
14 30
15 namespace chromeos { 31 namespace chromeos {
16 32
17 FakeCryptohomeClient::FakeCryptohomeClient() 33 FakeCryptohomeClient::FakeCryptohomeClient()
18 : service_is_available_(true), 34 : service_is_available_(true),
19 async_call_id_(1), 35 async_call_id_(1),
20 tpm_is_ready_counter_(0), 36 tpm_is_ready_counter_(0),
21 unmount_result_(true), 37 unmount_result_(true),
22 system_salt_(GetStubSystemSalt()), 38 system_salt_(GetStubSystemSalt()),
23 locked_(false), 39 weak_ptr_factory_(this) {
24 weak_ptr_factory_(this) {} 40 base::FilePath cache_path;
41 locked_ = PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &cache_path) &&
42 base::PathExists(cache_path);
43 }
25 44
26 FakeCryptohomeClient::~FakeCryptohomeClient() {} 45 FakeCryptohomeClient::~FakeCryptohomeClient() {}
27 46
28 void FakeCryptohomeClient::Init(dbus::Bus* bus) { 47 void FakeCryptohomeClient::Init(dbus::Bus* bus) {
29 } 48 }
30 49
31 void FakeCryptohomeClient::SetAsyncCallStatusHandlers( 50 void FakeCryptohomeClient::SetAsyncCallStatusHandlers(
32 const AsyncCallStatusHandler& handler, 51 const AsyncCallStatusHandler& handler,
33 const AsyncCallStatusWithDataHandler& data_handler) { 52 const AsyncCallStatusWithDataHandler& data_handler) {
34 async_call_status_handler_ = handler; 53 async_call_status_handler_ = handler;
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 const std::vector<uint8>& value, 258 const std::vector<uint8>& value,
240 bool* successful) { 259 bool* successful) {
241 install_attrs_[name] = value; 260 install_attrs_[name] = value;
242 *successful = true; 261 *successful = true;
243 return true; 262 return true;
244 } 263 }
245 264
246 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) { 265 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) {
247 locked_ = true; 266 locked_ = true;
248 *successful = true; 267 *successful = true;
268
269 // Persist the install attributes so that they can be reloaded if the
270 // browser is restarted. This is used for ease of development when device
271 // enrollment is required.
272 // The cryptohome::SerializedInstallAttributes protobuf lives in
273 // chrome/browser/chromeos, so it can't be used directly here; use the
274 // low-level protobuf API instead to just write the name-value pairs.
Mattias Nissler (ping if slow) 2014/05/02 08:09:29 Are you serious? Why not just place a copy of the
Joao da Silva 2014/05/02 08:22:10 I don't think we want to have a copy that may get
Mattias Nissler (ping if slow) 2014/05/02 08:34:01 Protobufs need to be backward-compatible, so I don
Joao da Silva 2014/05/02 08:43:29 That's fair.
Mattias Nissler (ping if slow) 2014/05/02 09:32:58 That assumes (1) the code is entirely correct in i
275 // The cache file is read by EnterpriseInstallAttributes::ReadCacheFile.
276 base::FilePath cache_path;
277 if (!PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &cache_path))
278 return false;
279
280 std::string result;
281 {
282 // |result| can be used only after the StringOutputStream goes out of
283 // scope.
284 google::protobuf::io::StringOutputStream result_stream(&result);
285 google::protobuf::io::CodedOutputStream result_output(&result_stream);
286
287 // These tags encode a variable-length value on the wire, which can be
288 // used to encode strings, bytes and messages. We only needs constants
289 // for tag numbers 1 and 2 (see install_attributes.proto).
290 const int kVarLengthTag1 = (1 << 3) | 0x2;
291 const int kVarLengthTag2 = (2 << 3) | 0x2;
292
293 typedef std::map<std::string, std::vector<uint8> >::const_iterator Iter;
294 for (Iter it = install_attrs_.begin(); it != install_attrs_.end(); ++it) {
295 std::string attr;
296 {
297 google::protobuf::io::StringOutputStream attr_stream(&attr);
298 google::protobuf::io::CodedOutputStream attr_output(&attr_stream);
299
300 attr_output.WriteVarint32(kVarLengthTag1);
301 attr_output.WriteVarint32(it->first.size());
302 attr_output.WriteString(it->first);
303 attr_output.WriteVarint32(kVarLengthTag2);
304 attr_output.WriteVarint32(it->second.size());
305 attr_output.WriteRaw(it->second.data(), it->second.size());
306 }
307
308 // Two CodedOutputStreams are needed because inner messages must be
309 // prefixed by their total length, which can't be easily computed before
310 // writing their tags and values.
311 result_output.WriteVarint32(kVarLengthTag2);
312 result_output.WriteVarint32(attr.size());
313 result_output.WriteRaw(attr.data(), attr.size());
314 }
315 }
316
317 base::WorkerPool::PostTask(
318 FROM_HERE, base::Bind(&PersistFile, cache_path, result), false);
319
249 return true; 320 return true;
250 } 321 }
251 322
252 void FakeCryptohomeClient::InstallAttributesIsReady( 323 void FakeCryptohomeClient::InstallAttributesIsReady(
253 const BoolDBusMethodCallback& callback) { 324 const BoolDBusMethodCallback& callback) {
254 base::MessageLoop::current()->PostTask( 325 base::MessageLoop::current()->PostTask(
255 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); 326 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true));
256 } 327 }
257 328
258 bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) { 329 bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 FROM_HERE, 567 FROM_HERE,
497 base::Bind(async_call_status_data_handler_, 568 base::Bind(async_call_status_data_handler_,
498 async_call_id_, 569 async_call_id_,
499 true, 570 true,
500 std::string())); 571 std::string()));
501 } 572 }
502 ++async_call_id_; 573 ++async_call_id_;
503 } 574 }
504 575
505 } // namespace chromeos 576 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/chromeos_paths.cc ('k') | chromeos/dbus/fake_session_manager_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698