Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "chromeos/network/client_cert_resolver.h" | 4 #include "chromeos/network/client_cert_resolver.h" |
| 5 | 5 |
| 6 #include <cert.h> | 6 #include <cert.h> |
| 7 #include <pk11pub.h> | 7 #include <pk11pub.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 const char* kUserProfilePath = "user_profile"; | 48 const char* kUserProfilePath = "user_profile"; |
| 49 const char* kUserHash = "user_hash"; | 49 const char* kUserHash = "user_hash"; |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 class ClientCertResolverTest : public testing::Test, | 53 class ClientCertResolverTest : public testing::Test, |
| 54 public ClientCertResolver::Observer { | 54 public ClientCertResolver::Observer { |
| 55 public: | 55 public: |
| 56 ClientCertResolverTest() | 56 ClientCertResolverTest() |
| 57 : network_properties_changed_count_(0), | 57 : network_properties_changed_count_(0), |
| 58 cert_loader_(nullptr), | |
|
emaxx
2017/04/20 20:10:39
nit: It's generally advisable to move onto C++11 i
pmarko
2017/04/24 14:49:56
Done. I've left scoped_task_scheduler(&message_loo
| |
| 58 service_test_(nullptr), | 59 service_test_(nullptr), |
| 59 profile_test_(nullptr), | 60 profile_test_(nullptr), |
| 60 cert_loader_(nullptr), | |
| 61 scoped_task_scheduler_(&message_loop_) {} | 61 scoped_task_scheduler_(&message_loop_) {} |
| 62 ~ClientCertResolverTest() override {} | 62 ~ClientCertResolverTest() override {} |
| 63 | 63 |
| 64 void SetUp() override { | 64 void SetUp() override { |
| 65 ASSERT_TRUE(test_nssdb_.is_open()); | 65 ASSERT_TRUE(test_nssdb_.is_open()); |
| 66 ASSERT_TRUE(test_system_nssdb_.is_open()); | |
| 66 | 67 |
| 67 // Use the same DB for public and private slot. | 68 // Use the same DB for public and private slot. |
| 68 test_nsscertdb_.reset(new net::NSSCertDatabaseChromeOS( | 69 test_nsscertdb_.reset(new net::NSSCertDatabaseChromeOS( |
| 69 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_nssdb_.slot())), | 70 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_nssdb_.slot())), |
| 70 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_nssdb_.slot())))); | 71 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_nssdb_.slot())))); |
| 71 test_nsscertdb_->SetSlowTaskRunnerForTest(message_loop_.task_runner()); | 72 test_nsscertdb_->SetSlowTaskRunnerForTest(message_loop_.task_runner()); |
| 72 | 73 |
| 73 DBusThreadManager::Initialize(); | 74 DBusThreadManager::Initialize(); |
| 74 service_test_ = | 75 service_test_ = |
| 75 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 76 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 << net::ErrorToString(failures[0].net_error); | 131 << net::ErrorToString(failures[0].net_error); |
| 131 } | 132 } |
| 132 | 133 |
| 133 // Import a client cert signed by that CA. | 134 // Import a client cert signed by that CA. |
| 134 test_client_cert_ = net::ImportClientCertAndKeyFromFile( | 135 test_client_cert_ = net::ImportClientCertAndKeyFromFile( |
| 135 net::GetTestCertsDirectory(), prefix + ".pem", prefix + ".pk8", | 136 net::GetTestCertsDirectory(), prefix + ".pem", prefix + ".pk8", |
| 136 test_nssdb_.slot()); | 137 test_nssdb_.slot()); |
| 137 ASSERT_TRUE(test_client_cert_.get()); | 138 ASSERT_TRUE(test_client_cert_.get()); |
| 138 } | 139 } |
| 139 | 140 |
| 141 void SetupTestCertInSystemToken(const std::string& prefix) { | |
| 142 test_nsscertdb_->SetSystemSlot( | |
| 143 crypto::ScopedPK11Slot(PK11_ReferenceSlot(test_system_nssdb_.slot()))); | |
| 144 | |
| 145 test_client_cert_ = net::ImportClientCertAndKeyFromFile( | |
| 146 net::GetTestCertsDirectory(), prefix + ".pem", prefix + ".pk8", | |
| 147 test_system_nssdb_.slot()); | |
| 148 ASSERT_TRUE(test_client_cert_.get()); | |
| 149 } | |
| 150 | |
| 140 void SetupNetworkHandlers() { | 151 void SetupNetworkHandlers() { |
| 141 network_state_handler_ = NetworkStateHandler::InitializeForTest(); | 152 network_state_handler_ = NetworkStateHandler::InitializeForTest(); |
| 142 network_profile_handler_.reset(new NetworkProfileHandler()); | 153 network_profile_handler_.reset(new NetworkProfileHandler()); |
| 143 network_config_handler_.reset(new NetworkConfigurationHandler()); | 154 network_config_handler_.reset(new NetworkConfigurationHandler()); |
| 144 managed_config_handler_.reset(new ManagedNetworkConfigurationHandlerImpl()); | 155 managed_config_handler_.reset(new ManagedNetworkConfigurationHandlerImpl()); |
| 145 client_cert_resolver_.reset(new ClientCertResolver()); | 156 client_cert_resolver_.reset(new ClientCertResolver()); |
| 146 | 157 |
| 147 test_clock_.reset(new base::SimpleTestClock); | 158 test_clock_.reset(new base::SimpleTestClock); |
| 148 test_clock_->SetNow(base::Time::Now()); | 159 test_clock_->SetNow(base::Time::Now()); |
| 149 client_cert_resolver_->SetClockForTesting(test_clock_.get()); | 160 client_cert_resolver_->SetClockForTesting(test_clock_.get()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 ASSERT_TRUE(policy_value->GetAsList(&policy)); | 225 ASSERT_TRUE(policy_value->GetAsList(&policy)); |
| 215 | 226 |
| 216 managed_config_handler_->SetPolicy( | 227 managed_config_handler_->SetPolicy( |
| 217 onc::ONC_SOURCE_USER_POLICY, kUserHash, *policy, | 228 onc::ONC_SOURCE_USER_POLICY, kUserHash, *policy, |
| 218 base::DictionaryValue() /* no global network config */); | 229 base::DictionaryValue() /* no global network config */); |
| 219 } | 230 } |
| 220 | 231 |
| 221 // Sets up a policy with a certificate pattern that matches any client cert | 232 // Sets up a policy with a certificate pattern that matches any client cert |
| 222 // that is signed by the test CA cert (stored in |test_ca_cert_pem_|). In | 233 // that is signed by the test CA cert (stored in |test_ca_cert_pem_|). In |
| 223 // particular it will match the test client cert. | 234 // particular it will match the test client cert. |
| 224 void SetupPolicyMatchingIssuerPEM(const std::string& identity) { | 235 void SetupPolicyMatchingIssuerPEM(onc::ONCSource onc_source, |
| 236 const std::string& identity) { | |
| 225 const char* kTestPolicyTemplate = | 237 const char* kTestPolicyTemplate = |
| 226 "[ { \"GUID\": \"wifi_stub\"," | 238 "[ { \"GUID\": \"wifi_stub\"," |
| 227 " \"Name\": \"wifi_stub\"," | 239 " \"Name\": \"wifi_stub\"," |
| 228 " \"Type\": \"WiFi\"," | 240 " \"Type\": \"WiFi\"," |
| 229 " \"WiFi\": {" | 241 " \"WiFi\": {" |
| 230 " \"Security\": \"WPA-EAP\"," | 242 " \"Security\": \"WPA-EAP\"," |
| 231 " \"SSID\": \"wifi_ssid\"," | 243 " \"SSID\": \"wifi_ssid\"," |
| 232 " \"EAP\": {" | 244 " \"EAP\": {" |
| 233 " \"Identity\": \"%s\"," | 245 " \"Identity\": \"%s\"," |
| 234 " \"Outer\": \"EAP-TLS\"," | 246 " \"Outer\": \"EAP-TLS\"," |
| 235 " \"ClientCertType\": \"Pattern\"," | 247 " \"ClientCertType\": \"Pattern\"," |
| 236 " \"ClientCertPattern\": {" | 248 " \"ClientCertPattern\": {" |
| 237 " \"IssuerCAPEMs\": [ \"%s\" ]" | 249 " \"IssuerCAPEMs\": [ \"%s\" ]" |
| 238 " }" | 250 " }" |
| 239 " }" | 251 " }" |
| 240 " }" | 252 " }" |
| 241 "} ]"; | 253 "} ]"; |
| 242 std::string policy_json = base::StringPrintf( | 254 std::string policy_json = base::StringPrintf( |
| 243 kTestPolicyTemplate, identity.c_str(), test_ca_cert_pem_.c_str()); | 255 kTestPolicyTemplate, identity.c_str(), test_ca_cert_pem_.c_str()); |
| 244 | 256 |
| 245 std::string error; | 257 std::string error; |
| 246 std::unique_ptr<base::Value> policy_value = | 258 std::unique_ptr<base::Value> policy_value = |
| 247 base::JSONReader::ReadAndReturnError( | 259 base::JSONReader::ReadAndReturnError( |
| 248 policy_json, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error); | 260 policy_json, base::JSON_ALLOW_TRAILING_COMMAS, nullptr, &error); |
| 249 ASSERT_TRUE(policy_value) << error; | 261 ASSERT_TRUE(policy_value) << error; |
| 250 | 262 |
| 251 base::ListValue* policy = nullptr; | 263 base::ListValue* policy = nullptr; |
| 252 ASSERT_TRUE(policy_value->GetAsList(&policy)); | 264 ASSERT_TRUE(policy_value->GetAsList(&policy)); |
| 253 | 265 |
| 266 std::string user_hash = | |
| 267 onc_source == onc::ONC_SOURCE_USER_POLICY ? kUserHash : ""; | |
| 254 managed_config_handler_->SetPolicy( | 268 managed_config_handler_->SetPolicy( |
| 255 onc::ONC_SOURCE_USER_POLICY, | 269 onc_source, user_hash, *policy, |
| 256 kUserHash, | |
| 257 *policy, | |
| 258 base::DictionaryValue() /* no global network config */); | 270 base::DictionaryValue() /* no global network config */); |
| 259 } | 271 } |
| 260 | 272 |
| 261 void SetWifiState(const std::string& state) { | 273 void SetWifiState(const std::string& state) { |
| 262 ASSERT_TRUE(service_test_->SetServiceProperty( | 274 ASSERT_TRUE(service_test_->SetServiceProperty( |
| 263 kWifiStub, shill::kStateProperty, base::Value(state))); | 275 kWifiStub, shill::kStateProperty, base::Value(state))); |
| 264 } | 276 } |
| 265 | 277 |
| 266 void GetServiceProperty(const std::string& prop_name, | 278 void GetServiceProperty(const std::string& prop_name, |
| 267 std::string* prop_value) { | 279 std::string* prop_value) { |
| 268 prop_value->clear(); | 280 prop_value->clear(); |
| 269 const base::DictionaryValue* properties = | 281 const base::DictionaryValue* properties = |
| 270 service_test_->GetServiceProperties(kWifiStub); | 282 service_test_->GetServiceProperties(kWifiStub); |
| 271 if (!properties) | 283 if (!properties) |
| 272 return; | 284 return; |
| 273 properties->GetStringWithoutPathExpansion(prop_name, prop_value); | 285 properties->GetStringWithoutPathExpansion(prop_name, prop_value); |
| 274 } | 286 } |
| 275 | 287 |
| 276 int network_properties_changed_count_; | 288 int network_properties_changed_count_; |
| 277 std::string test_cert_id_; | 289 std::string test_cert_id_; |
| 278 std::unique_ptr<base::SimpleTestClock> test_clock_; | 290 std::unique_ptr<base::SimpleTestClock> test_clock_; |
| 279 std::unique_ptr<ClientCertResolver> client_cert_resolver_; | 291 std::unique_ptr<ClientCertResolver> client_cert_resolver_; |
| 292 CertLoader* cert_loader_; | |
| 280 | 293 |
| 281 private: | 294 private: |
| 282 // ClientCertResolver::Observer: | 295 // ClientCertResolver::Observer: |
| 283 void ResolveRequestCompleted(bool network_properties_changed) override { | 296 void ResolveRequestCompleted(bool network_properties_changed) override { |
| 284 if (network_properties_changed) | 297 if (network_properties_changed) |
| 285 ++network_properties_changed_count_; | 298 ++network_properties_changed_count_; |
| 286 } | 299 } |
| 287 | 300 |
| 288 ShillServiceClient::TestInterface* service_test_; | 301 ShillServiceClient::TestInterface* service_test_; |
| 289 ShillProfileClient::TestInterface* profile_test_; | 302 ShillProfileClient::TestInterface* profile_test_; |
| 290 CertLoader* cert_loader_; | |
| 291 std::unique_ptr<NetworkStateHandler> network_state_handler_; | 303 std::unique_ptr<NetworkStateHandler> network_state_handler_; |
| 292 std::unique_ptr<NetworkProfileHandler> network_profile_handler_; | 304 std::unique_ptr<NetworkProfileHandler> network_profile_handler_; |
| 293 std::unique_ptr<NetworkConfigurationHandler> network_config_handler_; | 305 std::unique_ptr<NetworkConfigurationHandler> network_config_handler_; |
| 294 std::unique_ptr<ManagedNetworkConfigurationHandlerImpl> | 306 std::unique_ptr<ManagedNetworkConfigurationHandlerImpl> |
| 295 managed_config_handler_; | 307 managed_config_handler_; |
| 296 base::MessageLoop message_loop_; | 308 base::MessageLoop message_loop_; |
| 297 base::test::ScopedTaskScheduler scoped_task_scheduler_; | 309 base::test::ScopedTaskScheduler scoped_task_scheduler_; |
| 298 scoped_refptr<net::X509Certificate> test_client_cert_; | 310 scoped_refptr<net::X509Certificate> test_client_cert_; |
| 299 std::string test_ca_cert_pem_; | 311 std::string test_ca_cert_pem_; |
| 300 crypto::ScopedTestNSSDB test_nssdb_; | 312 crypto::ScopedTestNSSDB test_nssdb_; |
| 313 crypto::ScopedTestNSSDB test_system_nssdb_; | |
| 301 std::unique_ptr<net::NSSCertDatabaseChromeOS> test_nsscertdb_; | 314 std::unique_ptr<net::NSSCertDatabaseChromeOS> test_nsscertdb_; |
| 302 | 315 |
| 303 DISALLOW_COPY_AND_ASSIGN(ClientCertResolverTest); | 316 DISALLOW_COPY_AND_ASSIGN(ClientCertResolverTest); |
| 304 }; | 317 }; |
| 305 | 318 |
| 306 TEST_F(ClientCertResolverTest, NoMatchingCertificates) { | 319 TEST_F(ClientCertResolverTest, NoMatchingCertificates) { |
| 307 SetupTestCerts("client_1", false /* do not import the issuer */); | 320 SetupTestCerts("client_1", false /* do not import the issuer */); |
| 308 StartCertLoader(); | 321 StartCertLoader(); |
| 309 SetupWifi(); | 322 SetupWifi(); |
| 310 base::RunLoop().RunUntilIdle(); | 323 base::RunLoop().RunUntilIdle(); |
| 311 network_properties_changed_count_ = 0; | 324 network_properties_changed_count_ = 0; |
| 312 SetupNetworkHandlers(); | 325 SetupNetworkHandlers(); |
| 313 SetupPolicyMatchingIssuerPEM(""); | 326 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_USER_POLICY, ""); |
| 314 base::RunLoop().RunUntilIdle(); | 327 base::RunLoop().RunUntilIdle(); |
| 315 | 328 |
| 316 // Verify that no client certificate was configured. | 329 // Verify that no client certificate was configured. |
| 317 std::string pkcs11_id; | 330 std::string pkcs11_id; |
| 318 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); | 331 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); |
| 319 EXPECT_EQ(std::string(), pkcs11_id); | 332 EXPECT_EQ(std::string(), pkcs11_id); |
| 320 EXPECT_EQ(1, network_properties_changed_count_); | 333 EXPECT_EQ(1, network_properties_changed_count_); |
| 321 EXPECT_FALSE(client_cert_resolver_->IsAnyResolveTaskRunning()); | 334 EXPECT_FALSE(client_cert_resolver_->IsAnyResolveTaskRunning()); |
| 322 } | 335 } |
| 323 | 336 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 341 EXPECT_EQ(test_cert_id_, pkcs11_id); | 354 EXPECT_EQ(test_cert_id_, pkcs11_id); |
| 342 EXPECT_EQ(1, network_properties_changed_count_); | 355 EXPECT_EQ(1, network_properties_changed_count_); |
| 343 } | 356 } |
| 344 | 357 |
| 345 TEST_F(ClientCertResolverTest, ResolveOnCertificatesLoaded) { | 358 TEST_F(ClientCertResolverTest, ResolveOnCertificatesLoaded) { |
| 346 SetupTestCerts("client_1", true /* import issuer */); | 359 SetupTestCerts("client_1", true /* import issuer */); |
| 347 SetupWifi(); | 360 SetupWifi(); |
| 348 base::RunLoop().RunUntilIdle(); | 361 base::RunLoop().RunUntilIdle(); |
| 349 | 362 |
| 350 SetupNetworkHandlers(); | 363 SetupNetworkHandlers(); |
| 351 SetupPolicyMatchingIssuerPEM(""); | 364 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_USER_POLICY, ""); |
| 352 base::RunLoop().RunUntilIdle(); | 365 base::RunLoop().RunUntilIdle(); |
| 353 | 366 |
| 354 network_properties_changed_count_ = 0; | 367 network_properties_changed_count_ = 0; |
| 355 StartCertLoader(); | 368 StartCertLoader(); |
| 356 base::RunLoop().RunUntilIdle(); | 369 base::RunLoop().RunUntilIdle(); |
| 357 | 370 |
| 358 // Verify that the resolver positively matched the pattern in the policy with | 371 // Verify that the resolver positively matched the pattern in the policy with |
| 359 // the test client cert and configured the network. | 372 // the test client cert and configured the network. |
| 360 std::string pkcs11_id; | 373 std::string pkcs11_id; |
| 361 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); | 374 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); |
| 362 EXPECT_EQ(test_cert_id_, pkcs11_id); | 375 EXPECT_EQ(test_cert_id_, pkcs11_id); |
| 363 EXPECT_EQ(1, network_properties_changed_count_); | 376 EXPECT_EQ(1, network_properties_changed_count_); |
| 364 } | 377 } |
| 365 | 378 |
| 366 TEST_F(ClientCertResolverTest, ResolveAfterPolicyApplication) { | 379 TEST_F(ClientCertResolverTest, ResolveAfterPolicyApplication) { |
| 367 SetupTestCerts("client_1", true /* import issuer */); | 380 SetupTestCerts("client_1", true /* import issuer */); |
| 368 SetupWifi(); | 381 SetupWifi(); |
| 369 base::RunLoop().RunUntilIdle(); | 382 base::RunLoop().RunUntilIdle(); |
| 370 StartCertLoader(); | 383 StartCertLoader(); |
| 371 SetupNetworkHandlers(); | 384 SetupNetworkHandlers(); |
| 372 base::RunLoop().RunUntilIdle(); | 385 base::RunLoop().RunUntilIdle(); |
| 373 | 386 |
| 374 // Policy application will trigger the ClientCertResolver. | 387 // Policy application will trigger the ClientCertResolver. |
| 375 network_properties_changed_count_ = 0; | 388 network_properties_changed_count_ = 0; |
| 376 SetupPolicyMatchingIssuerPEM(""); | 389 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_USER_POLICY, ""); |
| 377 base::RunLoop().RunUntilIdle(); | 390 base::RunLoop().RunUntilIdle(); |
| 378 | 391 |
| 379 // Verify that the resolver positively matched the pattern in the policy with | 392 // Verify that the resolver positively matched the pattern in the policy with |
| 380 // the test client cert and configured the network. | 393 // the test client cert and configured the network. |
| 381 std::string pkcs11_id; | 394 std::string pkcs11_id; |
| 382 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); | 395 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); |
| 383 EXPECT_EQ(test_cert_id_, pkcs11_id); | 396 EXPECT_EQ(test_cert_id_, pkcs11_id); |
| 384 EXPECT_EQ(1, network_properties_changed_count_); | 397 EXPECT_EQ(1, network_properties_changed_count_); |
| 385 } | 398 } |
| 386 | 399 |
| 387 TEST_F(ClientCertResolverTest, ExpiringCertificate) { | 400 TEST_F(ClientCertResolverTest, ExpiringCertificate) { |
| 388 SetupTestCerts("client_1", true /* import issuer */); | 401 SetupTestCerts("client_1", true /* import issuer */); |
| 389 SetupWifi(); | 402 SetupWifi(); |
| 390 base::RunLoop().RunUntilIdle(); | 403 base::RunLoop().RunUntilIdle(); |
| 391 | 404 |
| 392 SetupNetworkHandlers(); | 405 SetupNetworkHandlers(); |
| 393 SetupPolicyMatchingIssuerPEM(""); | 406 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_USER_POLICY, ""); |
| 394 base::RunLoop().RunUntilIdle(); | 407 base::RunLoop().RunUntilIdle(); |
| 395 | 408 |
| 396 StartCertLoader(); | 409 StartCertLoader(); |
| 397 base::RunLoop().RunUntilIdle(); | 410 base::RunLoop().RunUntilIdle(); |
| 398 | 411 |
| 399 SetWifiState(shill::kStateOnline); | 412 SetWifiState(shill::kStateOnline); |
| 400 base::RunLoop().RunUntilIdle(); | 413 base::RunLoop().RunUntilIdle(); |
| 401 | 414 |
| 402 // Verify that the resolver positively matched the pattern in the policy with | 415 // Verify that the resolver positively matched the pattern in the policy with |
| 403 // the test client cert and configured the network. | 416 // the test client cert and configured the network. |
| 404 std::string pkcs11_id; | 417 std::string pkcs11_id; |
| 405 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); | 418 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); |
| 406 EXPECT_EQ(test_cert_id_, pkcs11_id); | 419 EXPECT_EQ(test_cert_id_, pkcs11_id); |
| 407 | 420 |
| 408 // Verify that, after the certificate expired and the network disconnection | 421 // Verify that, after the certificate expired and the network disconnection |
| 409 // happens, no client certificate was configured. | 422 // happens, no client certificate was configured. |
| 410 test_clock_->SetNow(base::Time::Max()); | 423 test_clock_->SetNow(base::Time::Max()); |
| 411 SetWifiState(shill::kStateOffline); | 424 SetWifiState(shill::kStateOffline); |
| 412 base::RunLoop().RunUntilIdle(); | 425 base::RunLoop().RunUntilIdle(); |
| 413 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); | 426 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); |
| 414 EXPECT_EQ(std::string(), pkcs11_id); | 427 EXPECT_EQ(std::string(), pkcs11_id); |
| 415 } | 428 } |
| 416 | 429 |
| 430 TEST_F(ClientCertResolverTest, UserPolicyUsesSystemToken) { | |
| 431 SetupTestCertInSystemToken("client_1"); | |
| 432 SetupWifi(); | |
| 433 base::RunLoop().RunUntilIdle(); | |
| 434 | |
| 435 SetupNetworkHandlers(); | |
| 436 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_USER_POLICY, ""); | |
| 437 base::RunLoop().RunUntilIdle(); | |
| 438 | |
| 439 StartCertLoader(); | |
| 440 base::RunLoop().RunUntilIdle(); | |
| 441 EXPECT_EQ(1U, cert_loader_->system_cert_list().size()); | |
| 442 | |
| 443 // Verify that the resolver positively matched the pattern in the policy with | |
| 444 // the test client cert and configured the network. | |
| 445 std::string pkcs11_id; | |
| 446 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); | |
| 447 EXPECT_EQ(test_cert_id_, pkcs11_id); | |
| 448 } | |
| 449 | |
| 450 TEST_F(ClientCertResolverTest, DevicePolicyUsesSystemToken) { | |
| 451 SetupTestCertInSystemToken("client_1"); | |
| 452 SetupWifi(); | |
| 453 base::RunLoop().RunUntilIdle(); | |
| 454 | |
| 455 SetupNetworkHandlers(); | |
| 456 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_DEVICE_POLICY, ""); | |
| 457 base::RunLoop().RunUntilIdle(); | |
| 458 | |
| 459 StartCertLoader(); | |
| 460 base::RunLoop().RunUntilIdle(); | |
| 461 EXPECT_EQ(1U, cert_loader_->system_cert_list().size()); | |
| 462 | |
| 463 // Verify that the resolver positively matched the pattern in the policy with | |
| 464 // the test client cert and configured the network. | |
| 465 std::string pkcs11_id; | |
| 466 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); | |
| 467 EXPECT_EQ(test_cert_id_, pkcs11_id); | |
| 468 } | |
| 469 | |
| 470 TEST_F(ClientCertResolverTest, DevicePolicyDoesNotUseUserToken) { | |
| 471 SetupTestCerts("client_1", false /* import issuer */); | |
| 472 SetupWifi(); | |
| 473 base::RunLoop().RunUntilIdle(); | |
| 474 | |
| 475 SetupNetworkHandlers(); | |
| 476 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_DEVICE_POLICY, ""); | |
| 477 base::RunLoop().RunUntilIdle(); | |
| 478 | |
| 479 network_properties_changed_count_ = 0; | |
| 480 StartCertLoader(); | |
| 481 base::RunLoop().RunUntilIdle(); | |
| 482 EXPECT_EQ(0U, cert_loader_->system_cert_list().size()); | |
| 483 | |
| 484 // Verify that no client certificate was configured. | |
| 485 std::string pkcs11_id; | |
| 486 GetServiceProperty(shill::kEapCertIdProperty, &pkcs11_id); | |
| 487 EXPECT_EQ(std::string(), pkcs11_id); | |
| 488 EXPECT_EQ(1, network_properties_changed_count_); | |
| 489 EXPECT_FALSE(client_cert_resolver_->IsAnyResolveTaskRunning()); | |
| 490 } | |
| 491 | |
| 417 TEST_F(ClientCertResolverTest, PopulateIdentityFromCert) { | 492 TEST_F(ClientCertResolverTest, PopulateIdentityFromCert) { |
| 418 SetupTestCerts("client_3", true /* import issuer */); | 493 SetupTestCerts("client_3", true /* import issuer */); |
| 419 SetupWifi(); | 494 SetupWifi(); |
| 420 base::RunLoop().RunUntilIdle(); | 495 base::RunLoop().RunUntilIdle(); |
| 421 | 496 |
| 422 SetupNetworkHandlers(); | 497 SetupNetworkHandlers(); |
| 423 SetupPolicyMatchingIssuerPEM("${CERT_SAN_EMAIL}"); | 498 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_USER_POLICY, |
| 499 "${CERT_SAN_EMAIL}"); | |
| 424 base::RunLoop().RunUntilIdle(); | 500 base::RunLoop().RunUntilIdle(); |
| 425 | 501 |
| 426 network_properties_changed_count_ = 0; | 502 network_properties_changed_count_ = 0; |
| 427 StartCertLoader(); | 503 StartCertLoader(); |
| 428 base::RunLoop().RunUntilIdle(); | 504 base::RunLoop().RunUntilIdle(); |
| 429 | 505 |
| 430 // Verify that the resolver read the subjectAltName email field from the | 506 // Verify that the resolver read the subjectAltName email field from the |
| 431 // cert, and wrote it into the shill service entry. | 507 // cert, and wrote it into the shill service entry. |
| 432 std::string identity; | 508 std::string identity; |
| 433 GetServiceProperty(shill::kEapIdentityProperty, &identity); | 509 GetServiceProperty(shill::kEapIdentityProperty, &identity); |
| 434 EXPECT_EQ("santest@example.com", identity); | 510 EXPECT_EQ("santest@example.com", identity); |
| 435 EXPECT_EQ(1, network_properties_changed_count_); | 511 EXPECT_EQ(1, network_properties_changed_count_); |
| 436 | 512 |
| 437 // Verify that after changing the ONC policy to request a variant of the | 513 // Verify that after changing the ONC policy to request a variant of the |
| 438 // Microsoft Universal Principal Name field instead, the correct value is | 514 // Microsoft Universal Principal Name field instead, the correct value is |
| 439 // substituted into the shill service entry. | 515 // substituted into the shill service entry. |
| 440 SetupPolicyMatchingIssuerPEM("upn-${CERT_SAN_UPN}-suffix"); | 516 SetupPolicyMatchingIssuerPEM(onc::ONC_SOURCE_USER_POLICY, |
| 517 "upn-${CERT_SAN_UPN}-suffix"); | |
| 441 base::RunLoop().RunUntilIdle(); | 518 base::RunLoop().RunUntilIdle(); |
| 442 | 519 |
| 443 GetServiceProperty(shill::kEapIdentityProperty, &identity); | 520 GetServiceProperty(shill::kEapIdentityProperty, &identity); |
| 444 EXPECT_EQ("upn-santest@ad.corp.example.com-suffix", identity); | 521 EXPECT_EQ("upn-santest@ad.corp.example.com-suffix", identity); |
| 445 EXPECT_EQ(2, network_properties_changed_count_); | 522 EXPECT_EQ(2, network_properties_changed_count_); |
| 446 } | 523 } |
| 447 | 524 |
| 448 } // namespace chromeos | 525 } // namespace chromeos |
| OLD | NEW |