OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/chromeos/login/signed_settings.h" | 5 #include "chrome/browser/chromeos/login/signed_settings.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/chromeos/cros/cros_library.h" | 15 #include "chrome/browser/chromeos/cros/cros_library.h" |
16 #include "chrome/browser/chromeos/cros/login_library.h" | |
17 #include "chrome/browser/chromeos/cros_settings_names.h" | 16 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 17 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
| 18 #include "chrome/browser/chromeos/dbus/session_manager_client.h" |
18 #include "chrome/browser/chromeos/login/authenticator.h" | 19 #include "chrome/browser/chromeos/login/authenticator.h" |
19 #include "chrome/browser/chromeos/login/ownership_service.h" | 20 #include "chrome/browser/chromeos/login/ownership_service.h" |
20 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" | 21 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" |
21 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 22 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
22 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 23 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
23 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
24 | 25 |
25 namespace chromeos { | 26 namespace chromeos { |
26 using google::protobuf::RepeatedPtrField; | 27 using google::protobuf::RepeatedPtrField; |
27 using std::string; | 28 using std::string; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 SignedSettings::Delegate<bool>* d); | 225 SignedSettings::Delegate<bool>* d); |
225 virtual ~StorePolicyOp(); | 226 virtual ~StorePolicyOp(); |
226 void Execute(); | 227 void Execute(); |
227 void Fail(SignedSettings::ReturnCode code); | 228 void Fail(SignedSettings::ReturnCode code); |
228 void Succeed(bool value); | 229 void Succeed(bool value); |
229 // Implementation of OwnerManager::Delegate | 230 // Implementation of OwnerManager::Delegate |
230 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 231 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
231 const std::vector<uint8>& payload); | 232 const std::vector<uint8>& payload); |
232 | 233 |
233 private: | 234 private: |
234 static void OnBoolComplete(void* delegate, bool success); | 235 void OnBoolComplete(bool success); |
235 // Always call d_->OnSettingOpCompleted() via this call. | 236 // Always call d_->OnSettingOpCompleted() via this call. |
236 // It guarantees that the callback will not be triggered until _after_ | 237 // It guarantees that the callback will not be triggered until _after_ |
237 // Execute() returns, which is implicitly assumed by SignedSettingsHelper | 238 // Execute() returns, which is implicitly assumed by SignedSettingsHelper |
238 // in some cases. | 239 // in some cases. |
239 void PerformCallback(SignedSettings::ReturnCode code, bool value); | 240 void PerformCallback(SignedSettings::ReturnCode code, bool value); |
240 | 241 |
241 em::PolicyFetchResponse* policy_; | 242 em::PolicyFetchResponse* policy_; |
242 SignedSettings::Delegate<bool>* d_; | 243 SignedSettings::Delegate<bool>* d_; |
243 | 244 |
244 void RequestStorePolicy(); | 245 void RequestStorePolicy(); |
245 }; | 246 }; |
246 | 247 |
247 class RetrievePolicyOp : public SignedSettings { | 248 class RetrievePolicyOp : public SignedSettings { |
248 public: | 249 public: |
249 explicit RetrievePolicyOp( | 250 explicit RetrievePolicyOp( |
250 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d); | 251 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d); |
251 virtual ~RetrievePolicyOp(); | 252 virtual ~RetrievePolicyOp(); |
252 void Execute(); | 253 void Execute(); |
253 void Fail(SignedSettings::ReturnCode code); | 254 void Fail(SignedSettings::ReturnCode code); |
254 void Succeed(const em::PolicyFetchResponse& value); | 255 void Succeed(const em::PolicyFetchResponse& value); |
255 // Implementation of OwnerManager::Delegate | 256 // Implementation of OwnerManager::Delegate |
256 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 257 void OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
257 const std::vector<uint8>& payload); | 258 const std::vector<uint8>& payload); |
258 | 259 |
259 private: | 260 private: |
260 static void OnStringComplete(void* delegate, | 261 void OnStringComplete(const std::string& serialized_proto); |
261 const char* policy, | |
262 const unsigned int len); | |
263 // Always call d_->OnSettingOpCompleted() via this call. | 262 // Always call d_->OnSettingOpCompleted() via this call. |
264 // It guarantees that the callback will not be triggered until _after_ | 263 // It guarantees that the callback will not be triggered until _after_ |
265 // Execute() returns, which is implicitly assumed by SignedSettingsHelper | 264 // Execute() returns, which is implicitly assumed by SignedSettingsHelper |
266 // in some cases. | 265 // in some cases. |
267 void PerformCallback(SignedSettings::ReturnCode code, | 266 void PerformCallback(SignedSettings::ReturnCode code, |
268 const em::PolicyFetchResponse& value); | 267 const em::PolicyFetchResponse& value); |
269 | 268 |
270 void ProcessPolicy(const char* out, const unsigned int len); | 269 void ProcessPolicy(const std::string& serialized_proto); |
271 | 270 |
272 em::PolicyFetchResponse policy_; | 271 em::PolicyFetchResponse policy_; |
273 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d_; | 272 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d_; |
274 }; | 273 }; |
275 | 274 |
276 // static | 275 // static |
277 SignedSettings* SignedSettings::CreateCheckWhitelistOp( | 276 SignedSettings* SignedSettings::CreateCheckWhitelistOp( |
278 const std::string& email, | 277 const std::string& email, |
279 SignedSettings::Delegate<bool>* d) { | 278 SignedSettings::Delegate<bool>* d) { |
280 DCHECK(d != NULL); | 279 DCHECK(d != NULL); |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 } | 776 } |
778 | 777 |
779 StorePolicyOp::StorePolicyOp(em::PolicyFetchResponse* policy, | 778 StorePolicyOp::StorePolicyOp(em::PolicyFetchResponse* policy, |
780 SignedSettings::Delegate<bool>* d) | 779 SignedSettings::Delegate<bool>* d) |
781 : policy_(policy), | 780 : policy_(policy), |
782 d_(d) { | 781 d_(d) { |
783 } | 782 } |
784 | 783 |
785 StorePolicyOp::~StorePolicyOp() {} | 784 StorePolicyOp::~StorePolicyOp() {} |
786 | 785 |
787 // static | 786 void StorePolicyOp::OnBoolComplete(bool success) { |
788 void StorePolicyOp::OnBoolComplete(void* delegate, bool success) { | |
789 StorePolicyOp* op = static_cast<StorePolicyOp*>(delegate); | |
790 if (success) | 787 if (success) |
791 op->Succeed(true); | 788 Succeed(true); |
792 else | 789 else |
793 op->Fail(NOT_FOUND); | 790 Fail(NOT_FOUND); |
794 } | 791 } |
795 | 792 |
796 void StorePolicyOp::Execute() { | 793 void StorePolicyOp::Execute() { |
797 // get protobuf contents to sign | 794 // get protobuf contents to sign |
798 if (!policy_->has_policy_data()) | 795 if (!policy_->has_policy_data()) |
799 Fail(OPERATION_FAILED); | 796 Fail(OPERATION_FAILED); |
800 else if (!policy_->has_policy_data_signature()) | 797 else if (!policy_->has_policy_data_signature()) |
801 service_->StartSigningAttempt(policy_->policy_data(), this); | 798 service_->StartSigningAttempt(policy_->policy_data(), this); |
802 else | 799 else |
803 RequestStorePolicy(); | 800 RequestStorePolicy(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 policy_->set_policy_data_signature(std::string(payload.begin(), | 837 policy_->set_policy_data_signature(std::string(payload.begin(), |
841 payload.end())); | 838 payload.end())); |
842 RequestStorePolicy(); | 839 RequestStorePolicy(); |
843 return; | 840 return; |
844 } | 841 } |
845 Fail(SignedSettings::MapKeyOpCode(return_code)); | 842 Fail(SignedSettings::MapKeyOpCode(return_code)); |
846 } | 843 } |
847 | 844 |
848 void StorePolicyOp::RequestStorePolicy() { | 845 void StorePolicyOp::RequestStorePolicy() { |
849 std::string serialized; | 846 std::string serialized; |
850 if (policy_->SerializeToString(&serialized) && | 847 if (policy_->SerializeToString(&serialized)) { |
851 CrosLibrary::Get()->EnsureLoaded()) { | 848 DBusThreadManager::Get()->session_manager_client()->StorePolicy( |
852 CrosLibrary::Get()->GetLoginLibrary()->RequestStorePolicy( | |
853 serialized, | 849 serialized, |
854 &StorePolicyOp::OnBoolComplete, | 850 base::Bind(&StorePolicyOp::OnBoolComplete, this)); |
855 this); | |
856 } else { | 851 } else { |
857 Fail(OPERATION_FAILED); | 852 Fail(OPERATION_FAILED); |
858 } | 853 } |
859 } | 854 } |
860 | 855 |
861 void StorePolicyOp::PerformCallback(SignedSettings::ReturnCode code, | 856 void StorePolicyOp::PerformCallback(SignedSettings::ReturnCode code, |
862 bool value) { | 857 bool value) { |
863 d_->OnSettingsOpCompleted(code, value); | 858 d_->OnSettingsOpCompleted(code, value); |
864 } | 859 } |
865 | 860 |
866 RetrievePolicyOp::RetrievePolicyOp( | 861 RetrievePolicyOp::RetrievePolicyOp( |
867 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d) | 862 SignedSettings::Delegate<const em::PolicyFetchResponse&>* d) |
868 : d_(d) { | 863 : d_(d) { |
869 } | 864 } |
870 | 865 |
871 RetrievePolicyOp::~RetrievePolicyOp() {} | 866 RetrievePolicyOp::~RetrievePolicyOp() {} |
872 | 867 |
873 void RetrievePolicyOp::Execute() { | 868 void RetrievePolicyOp::Execute() { |
874 if (CrosLibrary::Get()->EnsureLoaded()) { | 869 DBusThreadManager::Get()->session_manager_client()->RetrievePolicy( |
875 CrosLibrary::Get()->GetLoginLibrary()->RequestRetrievePolicy( | 870 base::Bind(&RetrievePolicyOp::OnStringComplete, this)); |
876 &RetrievePolicyOp::OnStringComplete, this); | |
877 } else { | |
878 Fail(OPERATION_FAILED); | |
879 } | |
880 } | 871 } |
881 | 872 |
882 void RetrievePolicyOp::Fail(SignedSettings::ReturnCode code) { | 873 void RetrievePolicyOp::Fail(SignedSettings::ReturnCode code) { |
883 VLOG(2) << "RetrievePolicyOp::Execute() failed with " << code; | 874 VLOG(2) << "RetrievePolicyOp::Execute() failed with " << code; |
884 BrowserThread::PostTask( | 875 BrowserThread::PostTask( |
885 BrowserThread::UI, FROM_HERE, | 876 BrowserThread::UI, FROM_HERE, |
886 base::Bind(&RetrievePolicyOp::PerformCallback, this, code, | 877 base::Bind(&RetrievePolicyOp::PerformCallback, this, code, |
887 em::PolicyFetchResponse())); | 878 em::PolicyFetchResponse())); |
888 } | 879 } |
889 | 880 |
(...skipping 19 matching lines...) Expand all Loading... |
909 payload)); | 900 payload)); |
910 return; | 901 return; |
911 } | 902 } |
912 // Now, sure we're on the UI thread. | 903 // Now, sure we're on the UI thread. |
913 if (return_code == OwnerManager::SUCCESS) | 904 if (return_code == OwnerManager::SUCCESS) |
914 Succeed(policy_); | 905 Succeed(policy_); |
915 else | 906 else |
916 Fail(SignedSettings::MapKeyOpCode(return_code)); | 907 Fail(SignedSettings::MapKeyOpCode(return_code)); |
917 } | 908 } |
918 | 909 |
919 // static | 910 void RetrievePolicyOp::OnStringComplete(const std::string& serialized_proto) { |
920 void RetrievePolicyOp::OnStringComplete(void* delegate, | 911 ProcessPolicy(serialized_proto); |
921 const char* out, | |
922 const unsigned int len) { | |
923 RetrievePolicyOp* op = static_cast<RetrievePolicyOp*>(delegate); | |
924 op->ProcessPolicy(out, len); | |
925 } | 912 } |
926 | 913 |
927 void RetrievePolicyOp::ProcessPolicy(const char* out, const unsigned int len) { | 914 void RetrievePolicyOp::ProcessPolicy(const std::string& serialized_proto) { |
928 if (!out || !policy_.ParseFromString(std::string(out, len)) || | 915 if (!policy_.ParseFromString(serialized_proto) || |
929 (!policy_.has_policy_data() && !policy_.has_policy_data_signature())) { | 916 (!policy_.has_policy_data() && !policy_.has_policy_data_signature())) { |
930 Fail(NOT_FOUND); | 917 Fail(NOT_FOUND); |
931 return; | 918 return; |
932 } | 919 } |
933 if (!policy_.has_policy_data()) { | 920 if (!policy_.has_policy_data()) { |
934 Fail(OPERATION_FAILED); | 921 Fail(OPERATION_FAILED); |
935 return; | 922 return; |
936 } | 923 } |
937 if (!policy_.has_policy_data_signature()) { | 924 if (!policy_.has_policy_data_signature()) { |
938 Fail(BAD_SIGNATURE); | 925 Fail(BAD_SIGNATURE); |
939 return; | 926 return; |
940 } | 927 } |
941 std::vector<uint8> sig; | 928 std::vector<uint8> sig; |
942 const char* sig_ptr = policy_.policy_data_signature().c_str(); | 929 const char* sig_ptr = policy_.policy_data_signature().c_str(); |
943 sig.assign(sig_ptr, sig_ptr + policy_.policy_data_signature().length()); | 930 sig.assign(sig_ptr, sig_ptr + policy_.policy_data_signature().length()); |
944 service_->StartVerifyAttempt(policy_.policy_data(), sig, this); | 931 service_->StartVerifyAttempt(policy_.policy_data(), sig, this); |
945 } | 932 } |
946 | 933 |
947 void RetrievePolicyOp::PerformCallback(SignedSettings::ReturnCode code, | 934 void RetrievePolicyOp::PerformCallback(SignedSettings::ReturnCode code, |
948 const em::PolicyFetchResponse& value) { | 935 const em::PolicyFetchResponse& value) { |
949 d_->OnSettingsOpCompleted(code, value); | 936 d_->OnSettingsOpCompleted(code, value); |
950 } | 937 } |
951 | 938 |
952 } // namespace chromeos | 939 } // namespace chromeos |
OLD | NEW |