blob: 9aff759c7a78d6a70cf33fffdbdf416fd87d76d0 [file] [log] [blame]
Paul Stewartc43cbbe2013-04-11 06:29:30 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/eap_credentials.h"
6
7#include <map>
8#include <string>
9#include <utility>
10#include <vector>
11
12#include <chromeos/dbus/service_constants.h>
13
14#include "shill/certificate_file.h"
Paul Stewartc43cbbe2013-04-11 06:29:30 -070015#include "shill/key_value_store.h"
Alex Vakulenkoa41ab512014-07-23 14:24:23 -070016#include "shill/logging.h"
Paul Stewartc43cbbe2013-04-11 06:29:30 -070017#include "shill/metrics.h"
Paul Stewartc43cbbe2013-04-11 06:29:30 -070018#include "shill/property_accessor.h"
19#include "shill/property_store.h"
20#include "shill/service.h"
21#include "shill/store_interface.h"
Ben Chanda69ecf2014-11-19 07:44:42 -080022#include "shill/supplicant/wpa_supplicant.h"
Paul Stewartc43cbbe2013-04-11 06:29:30 -070023
24using base::FilePath;
25using std::map;
26using std::string;
27using std::vector;
28
29using std::string;
30
31namespace shill {
32
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070033namespace Logging {
34static auto kModuleLogScope = ScopeLogger::kService;
Paul Stewarta794cd62015-06-16 13:13:10 -070035static string ObjectID(const EapCredentials* e) { return "(eap_credentials)"; }
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070036}
37
Paul Stewartc43cbbe2013-04-11 06:29:30 -070038const char EapCredentials::kStorageEapAnonymousIdentity[] =
39 "EAP.AnonymousIdentity";
40const char EapCredentials::kStorageEapCACert[] = "EAP.CACert";
41const char EapCredentials::kStorageEapCACertID[] = "EAP.CACertID";
42const char EapCredentials::kStorageEapCACertNSS[] = "EAP.CACertNSS";
43const char EapCredentials::kStorageEapCACertPEM[] = "EAP.CACertPEM";
44const char EapCredentials::kStorageEapCertID[] = "EAP.CertID";
45const char EapCredentials::kStorageEapClientCert[] = "EAP.ClientCert";
46const char EapCredentials::kStorageEapEap[] = "EAP.EAP";
47const char EapCredentials::kStorageEapIdentity[] = "EAP.Identity";
48const char EapCredentials::kStorageEapInnerEap[] = "EAP.InnerEAP";
49const char EapCredentials::kStorageEapKeyID[] = "EAP.KeyID";
50const char EapCredentials::kStorageEapKeyManagement[] = "EAP.KeyMgmt";
51const char EapCredentials::kStorageEapPIN[] = "EAP.PIN";
52const char EapCredentials::kStorageEapPassword[] = "EAP.Password";
53const char EapCredentials::kStorageEapPrivateKey[] = "EAP.PrivateKey";
54const char EapCredentials::kStorageEapPrivateKeyPassword[] =
55 "EAP.PrivateKeyPassword";
56const char EapCredentials::kStorageEapSubjectMatch[] =
57 "EAP.SubjectMatch";
Matthew Weinfa6f8ce2015-04-08 16:19:25 -070058const char EapCredentials::kStorageEapUseProactiveKeyCaching[] =
59 "EAP.UseProactiveKeyCaching";
Paul Stewartc43cbbe2013-04-11 06:29:30 -070060const char EapCredentials::kStorageEapUseSystemCAs[] = "EAP.UseSystemCAs";
61
Matthew Weinfa6f8ce2015-04-08 16:19:25 -070062EapCredentials::EapCredentials() : use_system_cas_(true),
63 use_proactive_key_caching_(false) {}
Paul Stewartc43cbbe2013-04-11 06:29:30 -070064
65EapCredentials::~EapCredentials() {}
66
67// static
68void EapCredentials::PopulateSupplicantProperties(
Paul Stewarta794cd62015-06-16 13:13:10 -070069 CertificateFile* certificate_file,
70 map<string, DBus::Variant>* params) const {
Paul Stewartc43cbbe2013-04-11 06:29:30 -070071 string ca_cert = ca_cert_;
72 if (!ca_cert_pem_.empty()) {
73 FilePath certfile =
Paul Stewartb3008ea2013-06-28 14:51:54 -070074 certificate_file->CreatePEMFromStrings(ca_cert_pem_);
Paul Stewartc43cbbe2013-04-11 06:29:30 -070075 if (certfile.empty()) {
76 LOG(ERROR) << "Unable to extract PEM certificate.";
77 } else {
78 ca_cert = certfile.value();
79 }
Paul Stewartc43cbbe2013-04-11 06:29:30 -070080 }
81
82
Paul Stewarta794cd62015-06-16 13:13:10 -070083 typedef std::pair<const char*, const char*> KeyVal;
Paul Stewartc43cbbe2013-04-11 06:29:30 -070084 KeyVal init_propertyvals[] = {
85 // Authentication properties.
86 KeyVal(WPASupplicant::kNetworkPropertyEapAnonymousIdentity,
87 anonymous_identity_.c_str()),
Paul Stewartc43cbbe2013-04-11 06:29:30 -070088 KeyVal(WPASupplicant::kNetworkPropertyEapClientCert,
89 client_cert_.c_str()),
90 KeyVal(WPASupplicant::kNetworkPropertyEapIdentity, identity_.c_str()),
Paul Stewartc43cbbe2013-04-11 06:29:30 -070091 KeyVal(WPASupplicant::kNetworkPropertyEapCaPassword,
92 password_.c_str()),
93 KeyVal(WPASupplicant::kNetworkPropertyEapPrivateKey,
94 private_key_.c_str()),
95 KeyVal(WPASupplicant::kNetworkPropertyEapPrivateKeyPassword,
96 private_key_password_.c_str()),
97
98 // Non-authentication properties.
99 KeyVal(WPASupplicant::kNetworkPropertyEapCaCert, ca_cert.c_str()),
100 KeyVal(WPASupplicant::kNetworkPropertyEapCaCertId,
101 ca_cert_id_.c_str()),
102 KeyVal(WPASupplicant::kNetworkPropertyEapEap, eap_.c_str()),
103 KeyVal(WPASupplicant::kNetworkPropertyEapInnerEap,
104 inner_eap_.c_str()),
105 KeyVal(WPASupplicant::kNetworkPropertyEapSubjectMatch,
106 subject_match_.c_str())
107 };
108
109 vector<KeyVal> propertyvals(init_propertyvals,
110 init_propertyvals + arraysize(init_propertyvals));
111 if (use_system_cas_) {
112 propertyvals.push_back(KeyVal(
113 WPASupplicant::kNetworkPropertyCaPath, WPASupplicant::kCaPath));
114 } else if (ca_cert.empty()) {
115 LOG(WARNING) << __func__
116 << ": No certificate authorities are configured."
117 << " Server certificates will be accepted"
118 << " unconditionally.";
119 }
120
Paul Stewart416a9812013-08-27 09:38:54 -0700121 if (ClientAuthenticationUsesCryptoToken()) {
122 propertyvals.push_back(KeyVal(
123 WPASupplicant::kNetworkPropertyEapCertId, cert_id_.c_str()));
124 propertyvals.push_back(KeyVal(
125 WPASupplicant::kNetworkPropertyEapKeyId, key_id_.c_str()));
126 }
127
128 if (ClientAuthenticationUsesCryptoToken() || !ca_cert_id_.empty()) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700129 propertyvals.push_back(KeyVal(
130 WPASupplicant::kNetworkPropertyEapPin, pin_.c_str()));
131 propertyvals.push_back(KeyVal(
132 WPASupplicant::kNetworkPropertyEngineId,
133 WPASupplicant::kEnginePKCS11));
134 // We can't use the propertyvals vector for this since this argument
Ben Chan7fab8972014-08-10 17:14:46 -0700135 // is a uint32_t, not a string.
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700136 (*params)[WPASupplicant::kNetworkPropertyEngine].writer().
137 append_uint32(WPASupplicant::kDefaultEngine);
138 }
139
Matthew Weinfa6f8ce2015-04-08 16:19:25 -0700140 if (use_proactive_key_caching_) {
141 (*params)[WPASupplicant::kNetworkPropertyEapProactiveKeyCaching].writer().
142 append_uint32(WPASupplicant::kProactiveKeyCachingEnabled);
143 } else {
144 (*params)[WPASupplicant::kNetworkPropertyEapProactiveKeyCaching].writer().
145 append_uint32(WPASupplicant::kProactiveKeyCachingDisabled);
146 }
147
Paul Stewarta794cd62015-06-16 13:13:10 -0700148 for (const auto& keyval : propertyvals) {
Paul Stewart6db7b242014-05-02 15:34:21 -0700149 if (strlen(keyval.second) > 0) {
150 (*params)[keyval.first].writer().append_string(keyval.second);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700151 }
152 }
153}
154
155// static
Paul Stewarta794cd62015-06-16 13:13:10 -0700156void EapCredentials::PopulateWiMaxProperties(KeyValueStore* params) const {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700157 if (!anonymous_identity_.empty()) {
158 params->SetString(wimax_manager::kEAPAnonymousIdentity,
159 anonymous_identity_);
160 }
161 if (!identity_.empty()) {
162 params->SetString(wimax_manager::kEAPUserIdentity, identity_);
163 }
164 if (!password_.empty()) {
165 params->SetString(wimax_manager::kEAPUserPassword, password_);
166 }
167}
168
Paul Stewarta794cd62015-06-16 13:13:10 -0700169void EapCredentials::InitPropertyStore(PropertyStore* store) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700170 // Authentication properties.
Ben Chan783f00b2013-09-20 13:50:34 -0700171 store->RegisterString(kEapAnonymousIdentityProperty, &anonymous_identity_);
Ben Chan011e6662014-05-07 11:03:25 -0700172 store->RegisterString(kEapCertIdProperty, &cert_id_);
173 store->RegisterString(kEapClientCertProperty, &client_cert_);
Ben Chan783f00b2013-09-20 13:50:34 -0700174 store->RegisterString(kEapIdentityProperty, &identity_);
Ben Chan011e6662014-05-07 11:03:25 -0700175 store->RegisterString(kEapKeyIdProperty, &key_id_);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700176 HelpRegisterDerivedString(store,
Ben Chan783f00b2013-09-20 13:50:34 -0700177 kEapKeyMgmtProperty,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700178 &EapCredentials::GetKeyManagement,
179 &EapCredentials::SetKeyManagement);
180 HelpRegisterWriteOnlyDerivedString(store,
Ben Chan783f00b2013-09-20 13:50:34 -0700181 kEapPasswordProperty,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700182 &EapCredentials::SetEapPassword,
Ben Chancc225ef2014-09-30 13:26:51 -0700183 nullptr,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700184 &password_);
Ben Chan011e6662014-05-07 11:03:25 -0700185 store->RegisterString(kEapPinProperty, &pin_);
Ben Chan783f00b2013-09-20 13:50:34 -0700186 store->RegisterString(kEapPrivateKeyProperty, &private_key_);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700187 HelpRegisterWriteOnlyDerivedString(store,
Ben Chan783f00b2013-09-20 13:50:34 -0700188 kEapPrivateKeyPasswordProperty,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700189 &EapCredentials::SetEapPrivateKeyPassword,
Ben Chancc225ef2014-09-30 13:26:51 -0700190 nullptr,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700191 &private_key_password_);
192
193 // Non-authentication properties.
Paul Stewartb3008ea2013-06-28 14:51:54 -0700194 store->RegisterStrings(kEapCaCertPemProperty, &ca_cert_pem_);
Ben Chan011e6662014-05-07 11:03:25 -0700195 store->RegisterString(kEapCaCertIdProperty, &ca_cert_id_);
Ben Chan783f00b2013-09-20 13:50:34 -0700196 store->RegisterString(kEapCaCertNssProperty, &ca_cert_nss_);
197 store->RegisterString(kEapCaCertProperty, &ca_cert_);
Ben Chan011e6662014-05-07 11:03:25 -0700198 store->RegisterString(kEapMethodProperty, &eap_);
Ben Chan783f00b2013-09-20 13:50:34 -0700199 store->RegisterString(kEapPhase2AuthProperty, &inner_eap_);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700200 store->RegisterString(kEapSubjectMatchProperty, &subject_match_);
Matthew Weinfa6f8ce2015-04-08 16:19:25 -0700201 store->RegisterBool(kEapUseProactiveKeyCachingProperty,
202 &use_proactive_key_caching_);
Ben Chan011e6662014-05-07 11:03:25 -0700203 store->RegisterBool(kEapUseSystemCasProperty, &use_system_cas_);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700204}
205
206// static
207bool EapCredentials::IsEapAuthenticationProperty(const string property) {
208 return
Ben Chan783f00b2013-09-20 13:50:34 -0700209 property == kEapAnonymousIdentityProperty ||
Ben Chan011e6662014-05-07 11:03:25 -0700210 property == kEapCertIdProperty ||
211 property == kEapClientCertProperty ||
Ben Chan783f00b2013-09-20 13:50:34 -0700212 property == kEapIdentityProperty ||
Ben Chan011e6662014-05-07 11:03:25 -0700213 property == kEapKeyIdProperty ||
Ben Chan783f00b2013-09-20 13:50:34 -0700214 property == kEapKeyMgmtProperty ||
215 property == kEapPasswordProperty ||
Ben Chan011e6662014-05-07 11:03:25 -0700216 property == kEapPinProperty ||
Ben Chan783f00b2013-09-20 13:50:34 -0700217 property == kEapPrivateKeyProperty ||
218 property == kEapPrivateKeyPasswordProperty;
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700219}
220
221bool EapCredentials::IsConnectable() const {
222 // Identity is required.
223 if (identity_.empty()) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700224 SLOG(this, 2) << "Not connectable: Identity is empty.";
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700225 return false;
226 }
227
228 if (!client_cert_.empty() || !cert_id_.empty()) {
229 // If a client certificate is being used, we must have a private key.
230 if (private_key_.empty() && key_id_.empty()) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700231 SLOG(this, 2)
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700232 << "Not connectable: Client certificate but no private key.";
233 return false;
234 }
235 }
236 if (!cert_id_.empty() || !key_id_.empty() ||
237 !ca_cert_id_.empty()) {
238 // If PKCS#11 data is needed, a PIN is required.
239 if (pin_.empty()) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700240 SLOG(this, 2) << "Not connectable: PKCS#11 data but no PIN.";
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700241 return false;
242 }
243 }
244
245 // For EAP-TLS, a client certificate is required.
Ben Chan783f00b2013-09-20 13:50:34 -0700246 if (eap_.empty() || eap_ == kEapMethodTLS) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700247 if ((!client_cert_.empty() || !cert_id_.empty()) &&
248 (!private_key_.empty() || !key_id_.empty())) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700249 SLOG(this, 2) << "Connectable: EAP-TLS with a client cert and key.";
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700250 return true;
251 }
252 }
253
254 // For EAP types other than TLS (e.g. EAP-TTLS or EAP-PEAP, password is the
255 // minimum requirement), at least an identity + password is required.
Ben Chan783f00b2013-09-20 13:50:34 -0700256 if (eap_.empty() || eap_ != kEapMethodTLS) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700257 if (!password_.empty()) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700258 SLOG(this, 2) << "Connectable. !EAP-TLS and has a password.";
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700259 return true;
260 }
261 }
262
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -0700263 SLOG(this, 2) << "Not connectable: No suitable EAP configuration was found.";
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700264 return false;
265}
266
267bool EapCredentials::IsConnectableUsingPassphrase() const {
268 return !identity_.empty() && !password_.empty();
269}
270
Paul Stewarta794cd62015-06-16 13:13:10 -0700271void EapCredentials::Load(StoreInterface* storage, const string& id) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700272 // Authentication properties.
273 storage->GetCryptedString(id,
274 kStorageEapAnonymousIdentity,
275 &anonymous_identity_);
276 storage->GetString(id, kStorageEapCertID, &cert_id_);
277 storage->GetString(id, kStorageEapClientCert, &client_cert_);
278 storage->GetCryptedString(id, kStorageEapIdentity, &identity_);
279 storage->GetString(id, kStorageEapKeyID, &key_id_);
280 string key_management;
281 storage->GetString(id, kStorageEapKeyManagement, &key_management);
Ben Chancc225ef2014-09-30 13:26:51 -0700282 SetKeyManagement(key_management, nullptr);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700283 storage->GetCryptedString(id, kStorageEapPassword, &password_);
284 storage->GetString(id, kStorageEapPIN, &pin_);
285 storage->GetString(id, kStorageEapPrivateKey, &private_key_);
286 storage->GetCryptedString(id,
287 kStorageEapPrivateKeyPassword,
288 &private_key_password_);
289
290 // Non-authentication properties.
291 storage->GetString(id, kStorageEapCACert, &ca_cert_);
292 storage->GetString(id, kStorageEapCACertID, &ca_cert_id_);
293 storage->GetString(id, kStorageEapCACertNSS, &ca_cert_nss_);
Paul Stewartb3008ea2013-06-28 14:51:54 -0700294 storage->GetStringList(id, kStorageEapCACertPEM, &ca_cert_pem_);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700295 storage->GetString(id, kStorageEapEap, &eap_);
296 storage->GetString(id, kStorageEapInnerEap, &inner_eap_);
297 storage->GetString(id, kStorageEapSubjectMatch, &subject_match_);
Matthew Weinfa6f8ce2015-04-08 16:19:25 -0700298 storage->GetBool(id, kStorageEapUseProactiveKeyCaching,
299 &use_proactive_key_caching_);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700300 storage->GetBool(id, kStorageEapUseSystemCAs, &use_system_cas_);
301}
302
303void EapCredentials::OutputConnectionMetrics(
Paul Stewarta794cd62015-06-16 13:13:10 -0700304 Metrics* metrics, Technology::Identifier technology) const {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700305 Metrics::EapOuterProtocol outer_protocol =
306 Metrics::EapOuterProtocolStringToEnum(eap_);
307 metrics->SendEnumToUMA(
mukesh agrawal132e96f2014-04-24 11:49:42 -0700308 metrics->GetFullMetricName(Metrics::kMetricNetworkEapOuterProtocolSuffix,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700309 technology),
310 outer_protocol,
311 Metrics::kMetricNetworkEapOuterProtocolMax);
312
313 Metrics::EapInnerProtocol inner_protocol =
314 Metrics::EapInnerProtocolStringToEnum(inner_eap_);
315 metrics->SendEnumToUMA(
mukesh agrawal132e96f2014-04-24 11:49:42 -0700316 metrics->GetFullMetricName(Metrics::kMetricNetworkEapInnerProtocolSuffix,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700317 technology),
318 inner_protocol,
319 Metrics::kMetricNetworkEapInnerProtocolMax);
320}
321
Paul Stewarta794cd62015-06-16 13:13:10 -0700322void EapCredentials::Save(StoreInterface* storage, const string& id,
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700323 bool save_credentials) const {
324 // Authentication properties.
325 Service::SaveString(storage,
326 id,
327 kStorageEapAnonymousIdentity,
328 anonymous_identity_,
329 true,
330 save_credentials);
331 Service::SaveString(storage,
332 id,
333 kStorageEapCertID,
334 cert_id_,
335 false,
336 save_credentials);
337 Service::SaveString(storage,
338 id,
339 kStorageEapClientCert,
340 client_cert_,
341 false,
342 save_credentials);
343 Service::SaveString(storage,
344 id,
345 kStorageEapIdentity,
346 identity_,
347 true,
348 save_credentials);
349 Service::SaveString(storage,
350 id,
351 kStorageEapKeyID,
352 key_id_,
353 false,
354 save_credentials);
355 Service::SaveString(storage,
356 id,
357 kStorageEapKeyManagement,
358 key_management_,
359 false,
360 true);
361 Service::SaveString(storage,
362 id,
363 kStorageEapPassword,
364 password_,
365 true,
366 save_credentials);
367 Service::SaveString(storage,
368 id,
369 kStorageEapPIN,
370 pin_,
371 false,
372 save_credentials);
373 Service::SaveString(storage,
374 id,
375 kStorageEapPrivateKey,
376 private_key_,
377 false,
378 save_credentials);
379 Service::SaveString(storage,
380 id,
381 kStorageEapPrivateKeyPassword,
382 private_key_password_,
383 true,
384 save_credentials);
385
386 // Non-authentication properties.
387 Service::SaveString(storage, id, kStorageEapCACert, ca_cert_, false, true);
388 Service::SaveString(storage,
389 id,
390 kStorageEapCACertID,
391 ca_cert_id_,
392 false,
393 true);
394 Service::SaveString(storage,
395 id,
396 kStorageEapCACertNSS,
397 ca_cert_nss_,
398 false,
399 true);
Paul Stewartb3008ea2013-06-28 14:51:54 -0700400 if (ca_cert_pem_.empty()) {
401 storage->DeleteKey(id, kStorageEapCACertPEM);
402 } else {
403 storage->SetStringList(id, kStorageEapCACertPEM, ca_cert_pem_);
404 }
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700405 Service::SaveString(storage, id, kStorageEapEap, eap_, false, true);
406 Service::SaveString(storage,
407 id,
408 kStorageEapInnerEap,
409 inner_eap_,
410 false,
411 true);
412 Service::SaveString(storage,
413 id,
414 kStorageEapSubjectMatch,
415 subject_match_,
416 false,
417 true);
Matthew Weinfa6f8ce2015-04-08 16:19:25 -0700418 storage->SetBool(id, kStorageEapUseProactiveKeyCaching,
419 use_proactive_key_caching_);
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700420 storage->SetBool(id, kStorageEapUseSystemCAs, use_system_cas_);
421}
422
423void EapCredentials::Reset() {
424 // Authentication properties.
425 anonymous_identity_ = "";
426 cert_id_ = "";
427 client_cert_ = "";
428 identity_ = "";
429 key_id_ = "";
Paul Stewart9956dc72013-04-23 14:06:17 -0700430 // Do not reset key_management_, since it should never be emptied.
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700431 password_ = "";
432 pin_ = "";
433 private_key_ = "";
434 private_key_password_ = "";
435
436 // Non-authentication properties.
437 ca_cert_ = "";
438 ca_cert_id_ = "";
439 ca_cert_nss_ = "";
Paul Stewartb3008ea2013-06-28 14:51:54 -0700440 ca_cert_pem_.clear();
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700441 eap_ = "";
442 inner_eap_ = "";
443 subject_match_ = "";
444 use_system_cas_ = true;
Matthew Weinfa6f8ce2015-04-08 16:19:25 -0700445 use_proactive_key_caching_ = false;
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700446}
447
Paul Stewarta794cd62015-06-16 13:13:10 -0700448bool EapCredentials::SetEapPassword(const string& password, Error* /*error*/) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700449 if (password_ == password) {
450 return false;
451 }
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700452 password_ = password;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700453 return true;
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700454}
455
Paul Stewarta794cd62015-06-16 13:13:10 -0700456bool EapCredentials::SetEapPrivateKeyPassword(const string& password,
457 Error* /*error*/) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700458 if (private_key_password_ == password) {
459 return false;
460 }
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700461 private_key_password_ = password;
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700462 return true;
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700463}
464
Paul Stewarta794cd62015-06-16 13:13:10 -0700465string EapCredentials::GetKeyManagement(Error* /*error*/) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700466 return key_management_;
467}
468
Paul Stewarta794cd62015-06-16 13:13:10 -0700469bool EapCredentials::SetKeyManagement(const std::string& key_management,
470 Error* /*error*/) {
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700471 if (key_management.empty()) {
472 return false;
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700473 }
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700474 if (key_management_ == key_management) {
475 return false;
476 }
477 key_management_ = key_management;
478 return true;
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700479}
480
Paul Stewart416a9812013-08-27 09:38:54 -0700481bool EapCredentials::ClientAuthenticationUsesCryptoToken() const {
Ben Chan783f00b2013-09-20 13:50:34 -0700482 return (eap_.empty() || eap_ == kEapMethodTLS ||
483 inner_eap_ == kEapMethodTLS) &&
Paul Stewart416a9812013-08-27 09:38:54 -0700484 (!cert_id_.empty() || !key_id_.empty());
485}
486
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700487void EapCredentials::HelpRegisterDerivedString(
Paul Stewarta794cd62015-06-16 13:13:10 -0700488 PropertyStore* store,
489 const string& name,
490 string(EapCredentials::*get)(Error* error),
491 bool(EapCredentials::*set)(const string&, Error*)) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700492 store->RegisterDerivedString(
493 name,
494 StringAccessor(new CustomAccessor<EapCredentials, string>(
495 this, get, set)));
496}
497
498void EapCredentials::HelpRegisterWriteOnlyDerivedString(
Paul Stewarta794cd62015-06-16 13:13:10 -0700499 PropertyStore* store,
500 const string& name,
501 bool(EapCredentials::*set)(const string&, Error*),
502 void(EapCredentials::*clear)(Error* error),
503 const string* default_value) {
Paul Stewartc43cbbe2013-04-11 06:29:30 -0700504 store->RegisterDerivedString(
505 name,
506 StringAccessor(
507 new CustomWriteOnlyAccessor<EapCredentials, string>(
508 this, set, clear, default_value)));
509}
510
Alex Vakulenko8a532292014-06-16 17:18:44 -0700511} // namespace shill