blob: 3be81f1cf53b501cd4cf7f197c395fe82f993177 [file] [log] [blame]
mukesh agrawal4d0401c2012-01-06 16:05:31 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
mukesh agrawal6e277772011-09-29 15:04:23 -07002// 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/wpa_supplicant.h"
6
Paul Stewart0654ece2013-03-26 15:21:26 -07007#include <map>
8#include <string>
9#include <vector>
10
11#include <base/file_path.h>
12
13#include "shill/certificate_file.h"
14#include "shill/eap_credentials.h"
15#include "shill/nss.h"
16
17using base::FilePath;
18using std::map;
19using std::string;
20using std::vector;
21
mukesh agrawal6e277772011-09-29 15:04:23 -070022namespace shill {
23
Paul Stewart0654ece2013-03-26 15:21:26 -070024// static
25const char WPASupplicant::kBSSPropertyBSSID[] = "BSSID";
26const char WPASupplicant::kBSSPropertyFrequency[] = "Frequency";
27const char WPASupplicant::kBSSPropertyIEs[] = "IEs";
28const char WPASupplicant::kBSSPropertyMode[] = "Mode";
29const char WPASupplicant::kBSSPropertyRates[] = "Rates";
30const char WPASupplicant::kBSSPropertySSID[] = "SSID";
31const char WPASupplicant::kBSSPropertySignal[] = "Signal";
Gaurav Shah10109f22011-11-11 20:16:22 -080032// TODO(gauravsh): Make this path be a configurable option. crosbug.com/25661
33// Location of the system root CA certificates.
Paul Stewart0654ece2013-03-26 15:21:26 -070034const char WPASupplicant::kCaPath[] = "/etc/ssl/certs";
35const char WPASupplicant::kCurrentBSSNull[] = "/";
36const char WPASupplicant::kDBusAddr[] = "fi.w1.wpa_supplicant1";
37const char WPASupplicant::kDBusPath[] = "/fi/w1/wpa_supplicant1";
38const char WPASupplicant::kDebugLevelDebug[] = "debug";
39const char WPASupplicant::kDebugLevelError[] = "error";
40const char WPASupplicant::kDebugLevelExcessive[] = "excessive";
41const char WPASupplicant::kDebugLevelInfo[] = "info";
42const char WPASupplicant::kDebugLevelMsgDump[] = "msgdump";
43const char WPASupplicant::kDebugLevelWarning[] = "warning";
44const char WPASupplicant::kDriverNL80211[] = "nl80211";
Paul Stewart196f50f2013-03-27 18:02:11 -070045const char WPASupplicant::kDriverWired[] = "wired";
Paul Stewart0654ece2013-03-26 15:21:26 -070046const char WPASupplicant::kEAPParameterAlertUnknownCA[] = "unknown CA";
47const char WPASupplicant::kEAPParameterFailure[] = "failure";
48const char WPASupplicant::kEAPParameterSuccess[] = "success";
49const char WPASupplicant::kEAPStatusAcceptProposedMethod[] =
50 "accept proposed method";
51const char WPASupplicant::kEAPStatusCompletion[] = "completion";
52const char WPASupplicant::kEAPStatusLocalTLSAlert[] = "local TLS alert";
53const char WPASupplicant::kEAPStatusParameterNeeded[] = "eap parameter needed";
54const char WPASupplicant::kEAPStatusRemoteCertificateVerification[] =
Paul Stewartdb0f9172012-11-30 16:48:09 -080055 "remote certificate verification";
Paul Stewart0654ece2013-03-26 15:21:26 -070056const char WPASupplicant::kEAPStatusRemoteTLSAlert[] = "remote TLS alert";
57const char WPASupplicant::kEAPStatusStarted[] = "started";
58const char WPASupplicant::kEnginePKCS11[] = "pkcs11";
59const char WPASupplicant::kErrorNetworkUnknown[]
60 = "fi.w1.wpa_supplicant1.NetworkUnknown";
61const char WPASupplicant::kErrorInterfaceExists[]
62 = "fi.w1.wpa_supplicant1.InterfaceExists";
63const char WPASupplicant::kInterfacePropertyConfigFile[] = "ConfigFile";
64const char WPASupplicant::kInterfacePropertyCurrentBSS[] = "CurrentBSS";
65const char WPASupplicant::kInterfacePropertyDepth[] = "depth";
66const char WPASupplicant::kInterfacePropertyDriver[] = "Driver";
67const char WPASupplicant::kInterfacePropertyName[] = "Ifname";
68const char WPASupplicant::kInterfacePropertyState[] = "State";
69const char WPASupplicant::kInterfacePropertySubject[] = "subject";
70const char WPASupplicant::kInterfaceState4WayHandshake[] = "4way_handshake";
71const char WPASupplicant::kInterfaceStateAssociated[] = "associated";
72const char WPASupplicant::kInterfaceStateAssociating[] = "associating";
73const char WPASupplicant::kInterfaceStateAuthenticating[] = "authenticating";
74const char WPASupplicant::kInterfaceStateCompleted[] = "completed";
75const char WPASupplicant::kInterfaceStateDisconnected[] = "disconnected";
76const char WPASupplicant::kInterfaceStateGroupHandshake[] = "group_handshake";
77const char WPASupplicant::kInterfaceStateInactive[] = "inactive";
78const char WPASupplicant::kInterfaceStateScanning[] = "scanning";
Paul Stewart9413bcc2013-04-04 16:12:43 -070079const char WPASupplicant::kKeyManagementIeee8021X[] = "IEEE8021X";
Paul Stewart0654ece2013-03-26 15:21:26 -070080const char WPASupplicant::kKeyManagementMethodSuffixEAP[] = "-eap";
81const char WPASupplicant::kKeyManagementMethodSuffixPSK[] = "-psk";
82const char WPASupplicant::kKeyModeNone[] = "NONE";
83const char WPASupplicant::kNetworkBgscanMethodLearn[] = "learn";
Christopher Wileya998df22012-07-11 15:14:55 -070084// None is not a real method name, but we interpret 'none' as a request that
85// no background scan parameter should be supplied to wpa_supplicant.
Paul Stewart0654ece2013-03-26 15:21:26 -070086const char WPASupplicant::kNetworkBgscanMethodNone[] = "none";
87const char WPASupplicant::kNetworkBgscanMethodSimple[] = "simple";
88const char WPASupplicant::kNetworkModeInfrastructure[] = "infrastructure";
89const char WPASupplicant::kNetworkModeAdHoc[] = "ad-hoc";
90const char WPASupplicant::kNetworkModeAccessPoint[] = "ap";
91const char WPASupplicant::kNetworkPropertyBgscan[] = "bgscan";
92const char WPASupplicant::kNetworkPropertyCaPath[] = "ca_path";
93const char WPASupplicant::kNetworkPropertyEapIdentity[] = "identity";
94const char WPASupplicant::kNetworkPropertyEapKeyManagement[] = "key_mgmt";
95const char WPASupplicant::kNetworkPropertyEapEap[] = "eap";
96const char WPASupplicant::kNetworkPropertyEapInnerEap[] = "phase2";
97const char WPASupplicant::kNetworkPropertyEapAnonymousIdentity[]
98 = "anonymous_identity";
99const char WPASupplicant::kNetworkPropertyEapClientCert[] = "client_cert";
100const char WPASupplicant::kNetworkPropertyEapPrivateKey[] = "private_key";
101const char WPASupplicant::kNetworkPropertyEapPrivateKeyPassword[] =
102 "private_key_passwd";
103const char WPASupplicant::kNetworkPropertyEapCaCert[] = "ca_cert";
104const char WPASupplicant::kNetworkPropertyEapCaPassword[] = "password";
105const char WPASupplicant::kNetworkPropertyEapCertId[] = "cert_id";
106const char WPASupplicant::kNetworkPropertyEapKeyId[] = "key_id";
107const char WPASupplicant::kNetworkPropertyEapCaCertId[] = "ca_cert_id";
108const char WPASupplicant::kNetworkPropertyEapPin[] = "pin";
109const char WPASupplicant::kNetworkPropertyEapSubjectMatch[] = "subject_match";
Paul Stewart9413bcc2013-04-04 16:12:43 -0700110const char WPASupplicant::kNetworkPropertyEapolFlags[] = "eapol_flags";
Paul Stewart0654ece2013-03-26 15:21:26 -0700111const char WPASupplicant::kNetworkPropertyEngine[] = "engine";
112const char WPASupplicant::kNetworkPropertyEngineId[] = "engine_id";
113const char WPASupplicant::kNetworkPropertyFrequency[] = "frequency";
114const char WPASupplicant::kNetworkPropertyIeee80211w[] = "ieee80211w";
115const char WPASupplicant::kNetworkPropertyMode[] = "mode";
116const char WPASupplicant::kNetworkPropertyScanSSID[] = "scan_ssid";
117const char WPASupplicant::kNetworkPropertySSID[] = "ssid";
118const char WPASupplicant::kPropertyAuthAlg[] = "auth_alg";
119const char WPASupplicant::kPropertyPreSharedKey[] = "psk";
120const char WPASupplicant::kPropertyPrivacy[] = "Privacy";
121const char WPASupplicant::kPropertyRSN[] = "RSN";
122const char WPASupplicant::kPropertyScanSSIDs[] = "SSIDs";
123const char WPASupplicant::kPropertyScanType[] = "Type";
124const char WPASupplicant::kPropertySecurityProtocol[] = "proto";
125const char WPASupplicant::kPropertyWEPKey[] = "wep_key";
126const char WPASupplicant::kPropertyWEPTxKeyIndex[] = "wep_tx_keyidx";
127const char WPASupplicant::kPropertyWPA[] = "WPA";
128const char WPASupplicant::kScanTypeActive[] = "active";
129const char WPASupplicant::kSecurityAuthAlg[] = "OPEN SHARED";
130const char WPASupplicant::kSecurityMethodPropertyKeyManagement[] = "KeyMgmt";
131const char WPASupplicant::kSecurityModeRSN[] = "RSN";
132const char WPASupplicant::kSecurityModeWPA[] = "WPA";
mukesh agrawal6e277772011-09-29 15:04:23 -0700133
Paul Stewart0654ece2013-03-26 15:21:26 -0700134const uint32_t WPASupplicant::kDefaultEngine = 1;
135const uint32_t WPASupplicant::kNetworkIeee80211wDisabled = 0;
136const uint32_t WPASupplicant::kNetworkIeee80211wEnabled = 1;
137const uint32_t WPASupplicant::kNetworkIeee80211wRequired = 2;
138const uint32_t WPASupplicant::kNetworkModeInfrastructureInt = 0;
139const uint32_t WPASupplicant::kNetworkModeAdHocInt = 1;
140const uint32_t WPASupplicant::kNetworkModeAccessPointInt = 2;
141const uint32_t WPASupplicant::kScanMaxSSIDsPerScan = 4;
142
Paul Stewart196f50f2013-03-27 18:02:11 -0700143const char WPASupplicant::kSupplicantConfPath[] =
144 SHIMDIR "/wpa_supplicant.conf";
145
Paul Stewart0654ece2013-03-26 15:21:26 -0700146// static
Paul Stewart735eab52013-03-29 09:19:23 -0700147bool WPASupplicant::ExtractRemoteCertification(
148 const std::map<std::string, DBus::Variant> &properties,
149 std::string *subject, uint32 *depth) {
150 map<string, ::DBus::Variant>::const_iterator depth_it =
151 properties.find(WPASupplicant::kInterfacePropertyDepth);
152 if (depth_it == properties.end()) {
153 LOG(ERROR) << __func__ << " no depth parameter.";
154 return false;
155 }
156 map<string, ::DBus::Variant>::const_iterator subject_it =
157 properties.find(WPASupplicant::kInterfacePropertySubject);
158 if (subject_it == properties.end()) {
159 LOG(ERROR) << __func__ << " no subject parameter.";
160 return false;
161 }
162 *depth = depth_it->second.reader().get_uint32();
163 *subject = subject_it->second.reader().get_string();
164 return true;
165}
166
mukesh agrawal6e277772011-09-29 15:04:23 -0700167} // namespace shill