| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/ownership/owner_settings_service.h" | 5 #include "components/ownership/owner_settings_service.h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <keyhi.h> | 8 #include <keyhi.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace ownership { | 25 namespace ownership { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 using ScopedSGNContext = std::unique_ptr< | 29 using ScopedSGNContext = std::unique_ptr< |
| 30 SGNContext, | 30 SGNContext, |
| 31 crypto::NSSDestroyer1<SGNContext, SGN_DestroyContext, PR_TRUE>>; | 31 crypto::NSSDestroyer1<SGNContext, SGN_DestroyContext, PR_TRUE>>; |
| 32 | 32 |
| 33 std::unique_ptr<em::PolicyFetchResponse> AssembleAndSignPolicy( | 33 std::unique_ptr<em::PolicyFetchResponse> AssembleAndSignPolicy( |
| 34 std::unique_ptr<em::PolicyData> policy, | 34 std::unique_ptr<em::PolicyData> policy, |
| 35 SECKEYPrivateKey* private_key) { | 35 scoped_refptr<ownership::PrivateKey> private_key) { |
| 36 DCHECK(private_key->key()); |
| 37 |
| 36 // Assemble the policy. | 38 // Assemble the policy. |
| 37 std::unique_ptr<em::PolicyFetchResponse> policy_response( | 39 std::unique_ptr<em::PolicyFetchResponse> policy_response( |
| 38 new em::PolicyFetchResponse()); | 40 new em::PolicyFetchResponse()); |
| 39 if (!policy->SerializeToString(policy_response->mutable_policy_data())) { | 41 if (!policy->SerializeToString(policy_response->mutable_policy_data())) { |
| 40 LOG(ERROR) << "Failed to encode policy payload."; | 42 LOG(ERROR) << "Failed to encode policy payload."; |
| 41 return nullptr; | 43 return nullptr; |
| 42 } | 44 } |
| 43 | 45 |
| 44 ScopedSGNContext sign_context( | 46 ScopedSGNContext sign_context(SGN_NewContext( |
| 45 SGN_NewContext(SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION, private_key)); | 47 SEC_OID_PKCS1_SHA1_WITH_RSA_ENCRYPTION, private_key->key())); |
| 46 if (!sign_context) { | 48 if (!sign_context) { |
| 47 NOTREACHED(); | 49 NOTREACHED(); |
| 48 return nullptr; | 50 return nullptr; |
| 49 } | 51 } |
| 50 | 52 |
| 51 SECItem signature_item; | 53 SECItem signature_item; |
| 52 if (SGN_Begin(sign_context.get()) != SECSuccess || | 54 if (SGN_Begin(sign_context.get()) != SECSuccess || |
| 53 SGN_Update(sign_context.get(), | 55 SGN_Update(sign_context.get(), |
| 54 reinterpret_cast<const uint8_t*>( | 56 reinterpret_cast<const uint8_t*>( |
| 55 policy_response->policy_data().c_str()), | 57 policy_response->policy_data().c_str()), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 } | 104 } |
| 103 | 105 |
| 104 bool OwnerSettingsService::AssembleAndSignPolicyAsync( | 106 bool OwnerSettingsService::AssembleAndSignPolicyAsync( |
| 105 base::TaskRunner* task_runner, | 107 base::TaskRunner* task_runner, |
| 106 std::unique_ptr<em::PolicyData> policy, | 108 std::unique_ptr<em::PolicyData> policy, |
| 107 const AssembleAndSignPolicyAsyncCallback& callback) { | 109 const AssembleAndSignPolicyAsyncCallback& callback) { |
| 108 DCHECK(thread_checker_.CalledOnValidThread()); | 110 DCHECK(thread_checker_.CalledOnValidThread()); |
| 109 if (!task_runner || !IsOwner()) | 111 if (!task_runner || !IsOwner()) |
| 110 return false; | 112 return false; |
| 111 return base::PostTaskAndReplyWithResult( | 113 return base::PostTaskAndReplyWithResult( |
| 112 task_runner, | 114 task_runner, FROM_HERE, |
| 113 FROM_HERE, | 115 base::Bind(&AssembleAndSignPolicy, base::Passed(&policy), private_key_), |
| 114 base::Bind( | |
| 115 &AssembleAndSignPolicy, base::Passed(&policy), private_key_->key()), | |
| 116 callback); | 116 callback); |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool OwnerSettingsService::SetBoolean(const std::string& setting, bool value) { | 119 bool OwnerSettingsService::SetBoolean(const std::string& setting, bool value) { |
| 120 DCHECK(thread_checker_.CalledOnValidThread()); | 120 DCHECK(thread_checker_.CalledOnValidThread()); |
| 121 base::Value in_value(value); | 121 base::Value in_value(value); |
| 122 return Set(setting, in_value); | 122 return Set(setting, in_value); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool OwnerSettingsService::SetInteger(const std::string& setting, int value) { | 125 bool OwnerSettingsService::SetInteger(const std::string& setting, int value) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 for (std::vector<IsOwnerCallback>::iterator it(is_owner_callbacks.begin()); | 160 for (std::vector<IsOwnerCallback>::iterator it(is_owner_callbacks.begin()); |
| 161 it != is_owner_callbacks.end(); | 161 it != is_owner_callbacks.end(); |
| 162 ++it) { | 162 ++it) { |
| 163 it->Run(is_owner); | 163 it->Run(is_owner); |
| 164 } | 164 } |
| 165 | 165 |
| 166 OnPostKeypairLoadedActions(); | 166 OnPostKeypairLoadedActions(); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace ownership | 169 } // namespace ownership |
| OLD | NEW |