| 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 "components/policy/core/common/cloud/policy_builder.h" | 5 #include "components/policy/core/common/cloud/policy_builder.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | |
| 10 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 9 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 11 #include "crypto/signature_creator.h" | 10 #include "crypto/signature_creator.h" |
| 12 | 11 |
| 13 namespace em = enterprise_management; | 12 namespace em = enterprise_management; |
| 14 | 13 |
| 15 namespace policy { | 14 namespace policy { |
| 16 | 15 |
| 17 namespace { | 16 namespace { |
| 18 | 17 |
| 19 // Signing key test data in DER-encoded PKCS8 format. | 18 // Signing key test data in DER-encoded PKCS8 format. |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 raw_new_signing_key_signature_.clear(); | 209 raw_new_signing_key_signature_.clear(); |
| 211 } | 210 } |
| 212 | 211 |
| 213 void PolicyBuilder::Build() { | 212 void PolicyBuilder::Build() { |
| 214 // Generate signatures if applicable. | 213 // Generate signatures if applicable. |
| 215 scoped_ptr<crypto::RSAPrivateKey> policy_signing_key = GetNewSigningKey(); | 214 scoped_ptr<crypto::RSAPrivateKey> policy_signing_key = GetNewSigningKey(); |
| 216 if (policy_signing_key) { | 215 if (policy_signing_key) { |
| 217 // Add the new public key. | 216 // Add the new public key. |
| 218 std::vector<uint8> raw_new_public_signing_key; | 217 std::vector<uint8> raw_new_public_signing_key; |
| 219 CHECK(policy_signing_key->ExportPublicKey(&raw_new_public_signing_key)); | 218 CHECK(policy_signing_key->ExportPublicKey(&raw_new_public_signing_key)); |
| 220 policy_.set_new_public_key(vector_as_array(&raw_new_public_signing_key), | 219 policy_.set_new_public_key(raw_new_public_signing_key.data(), |
| 221 raw_new_public_signing_key.size()); | 220 raw_new_public_signing_key.size()); |
| 222 | 221 |
| 223 policy_.set_new_public_key_verification_signature( | 222 policy_.set_new_public_key_verification_signature( |
| 224 raw_new_signing_key_signature_); | 223 raw_new_signing_key_signature_); |
| 225 | 224 |
| 226 // The new public key must be signed by the old key. | 225 // The new public key must be signed by the old key. |
| 227 scoped_ptr<crypto::RSAPrivateKey> old_signing_key = GetSigningKey(); | 226 scoped_ptr<crypto::RSAPrivateKey> old_signing_key = GetSigningKey(); |
| 228 if (old_signing_key) { | 227 if (old_signing_key) { |
| 229 SignData(policy_.new_public_key(), | 228 SignData(policy_.new_public_key(), |
| 230 old_signing_key.get(), | 229 old_signing_key.get(), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 void PolicyBuilder::SignData(const std::string& data, | 293 void PolicyBuilder::SignData(const std::string& data, |
| 295 crypto::RSAPrivateKey* key, | 294 crypto::RSAPrivateKey* key, |
| 296 std::string* signature) { | 295 std::string* signature) { |
| 297 scoped_ptr<crypto::SignatureCreator> signature_creator( | 296 scoped_ptr<crypto::SignatureCreator> signature_creator( |
| 298 crypto::SignatureCreator::Create(key, | 297 crypto::SignatureCreator::Create(key, |
| 299 crypto::SignatureCreator::SHA1)); | 298 crypto::SignatureCreator::SHA1)); |
| 300 signature_creator->Update(reinterpret_cast<const uint8*>(data.c_str()), | 299 signature_creator->Update(reinterpret_cast<const uint8*>(data.c_str()), |
| 301 data.size()); | 300 data.size()); |
| 302 std::vector<uint8> signature_bytes; | 301 std::vector<uint8> signature_bytes; |
| 303 CHECK(signature_creator->Final(&signature_bytes)); | 302 CHECK(signature_creator->Final(&signature_bytes)); |
| 304 signature->assign( | 303 signature->assign(reinterpret_cast<const char*>(signature_bytes.data()), |
| 305 reinterpret_cast<const char*>(vector_as_array(&signature_bytes)), | 304 signature_bytes.size()); |
| 306 signature_bytes.size()); | |
| 307 } | 305 } |
| 308 | 306 |
| 309 template<> | 307 template<> |
| 310 TypedPolicyBuilder<em::CloudPolicySettings>::TypedPolicyBuilder() | 308 TypedPolicyBuilder<em::CloudPolicySettings>::TypedPolicyBuilder() |
| 311 : payload_(new em::CloudPolicySettings()) { | 309 : payload_(new em::CloudPolicySettings()) { |
| 312 policy_data().set_policy_type(dm_protocol::kChromeUserPolicyType); | 310 policy_data().set_policy_type(dm_protocol::kChromeUserPolicyType); |
| 313 } | 311 } |
| 314 | 312 |
| 315 // Have the instantiation compiled into the module. | 313 // Have the instantiation compiled into the module. |
| 316 template class TypedPolicyBuilder<em::CloudPolicySettings>; | 314 template class TypedPolicyBuilder<em::CloudPolicySettings>; |
| 317 | 315 |
| 318 #if !defined(OS_ANDROID) && !defined(OS_IOS) | 316 #if !defined(OS_ANDROID) && !defined(OS_IOS) |
| 319 template<> | 317 template<> |
| 320 TypedPolicyBuilder<em::ExternalPolicyData>::TypedPolicyBuilder() | 318 TypedPolicyBuilder<em::ExternalPolicyData>::TypedPolicyBuilder() |
| 321 : payload_(new em::ExternalPolicyData()) { | 319 : payload_(new em::ExternalPolicyData()) { |
| 322 policy_data().set_policy_type(dm_protocol::kChromeExtensionPolicyType); | 320 policy_data().set_policy_type(dm_protocol::kChromeExtensionPolicyType); |
| 323 } | 321 } |
| 324 | 322 |
| 325 template class TypedPolicyBuilder<em::ExternalPolicyData>; | 323 template class TypedPolicyBuilder<em::ExternalPolicyData>; |
| 326 #endif | 324 #endif |
| 327 | 325 |
| 328 } // namespace policy | 326 } // namespace policy |
| OLD | NEW |