mukesh agrawal | 4d0401c | 2012-01-06 16:05:31 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 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/wpa_supplicant.h" |
| 6 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 7 | #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 | |
| 17 | using base::FilePath; |
| 18 | using std::map; |
| 19 | using std::string; |
| 20 | using std::vector; |
| 21 | |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 22 | namespace shill { |
| 23 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 24 | // static |
| 25 | const char WPASupplicant::kBSSPropertyBSSID[] = "BSSID"; |
| 26 | const char WPASupplicant::kBSSPropertyFrequency[] = "Frequency"; |
| 27 | const char WPASupplicant::kBSSPropertyIEs[] = "IEs"; |
| 28 | const char WPASupplicant::kBSSPropertyMode[] = "Mode"; |
| 29 | const char WPASupplicant::kBSSPropertyRates[] = "Rates"; |
| 30 | const char WPASupplicant::kBSSPropertySSID[] = "SSID"; |
| 31 | const char WPASupplicant::kBSSPropertySignal[] = "Signal"; |
Gaurav Shah | 10109f2 | 2011-11-11 20:16:22 -0800 | [diff] [blame] | 32 | // TODO(gauravsh): Make this path be a configurable option. crosbug.com/25661 |
| 33 | // Location of the system root CA certificates. |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 34 | const char WPASupplicant::kCaPath[] = "/etc/ssl/certs"; |
| 35 | const char WPASupplicant::kCurrentBSSNull[] = "/"; |
| 36 | const char WPASupplicant::kDBusAddr[] = "fi.w1.wpa_supplicant1"; |
| 37 | const char WPASupplicant::kDBusPath[] = "/fi/w1/wpa_supplicant1"; |
| 38 | const char WPASupplicant::kDebugLevelDebug[] = "debug"; |
| 39 | const char WPASupplicant::kDebugLevelError[] = "error"; |
| 40 | const char WPASupplicant::kDebugLevelExcessive[] = "excessive"; |
| 41 | const char WPASupplicant::kDebugLevelInfo[] = "info"; |
| 42 | const char WPASupplicant::kDebugLevelMsgDump[] = "msgdump"; |
| 43 | const char WPASupplicant::kDebugLevelWarning[] = "warning"; |
| 44 | const char WPASupplicant::kDriverNL80211[] = "nl80211"; |
Paul Stewart | 196f50f | 2013-03-27 18:02:11 -0700 | [diff] [blame] | 45 | const char WPASupplicant::kDriverWired[] = "wired"; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 46 | const char WPASupplicant::kEAPParameterAlertUnknownCA[] = "unknown CA"; |
| 47 | const char WPASupplicant::kEAPParameterFailure[] = "failure"; |
| 48 | const char WPASupplicant::kEAPParameterSuccess[] = "success"; |
| 49 | const char WPASupplicant::kEAPStatusAcceptProposedMethod[] = |
| 50 | "accept proposed method"; |
| 51 | const char WPASupplicant::kEAPStatusCompletion[] = "completion"; |
| 52 | const char WPASupplicant::kEAPStatusLocalTLSAlert[] = "local TLS alert"; |
| 53 | const char WPASupplicant::kEAPStatusParameterNeeded[] = "eap parameter needed"; |
| 54 | const char WPASupplicant::kEAPStatusRemoteCertificateVerification[] = |
Paul Stewart | db0f917 | 2012-11-30 16:48:09 -0800 | [diff] [blame] | 55 | "remote certificate verification"; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 56 | const char WPASupplicant::kEAPStatusRemoteTLSAlert[] = "remote TLS alert"; |
| 57 | const char WPASupplicant::kEAPStatusStarted[] = "started"; |
| 58 | const char WPASupplicant::kEnginePKCS11[] = "pkcs11"; |
| 59 | const char WPASupplicant::kErrorNetworkUnknown[] |
| 60 | = "fi.w1.wpa_supplicant1.NetworkUnknown"; |
| 61 | const char WPASupplicant::kErrorInterfaceExists[] |
| 62 | = "fi.w1.wpa_supplicant1.InterfaceExists"; |
| 63 | const char WPASupplicant::kInterfacePropertyConfigFile[] = "ConfigFile"; |
| 64 | const char WPASupplicant::kInterfacePropertyCurrentBSS[] = "CurrentBSS"; |
| 65 | const char WPASupplicant::kInterfacePropertyDepth[] = "depth"; |
| 66 | const char WPASupplicant::kInterfacePropertyDriver[] = "Driver"; |
| 67 | const char WPASupplicant::kInterfacePropertyName[] = "Ifname"; |
| 68 | const char WPASupplicant::kInterfacePropertyState[] = "State"; |
| 69 | const char WPASupplicant::kInterfacePropertySubject[] = "subject"; |
| 70 | const char WPASupplicant::kInterfaceState4WayHandshake[] = "4way_handshake"; |
| 71 | const char WPASupplicant::kInterfaceStateAssociated[] = "associated"; |
| 72 | const char WPASupplicant::kInterfaceStateAssociating[] = "associating"; |
| 73 | const char WPASupplicant::kInterfaceStateAuthenticating[] = "authenticating"; |
| 74 | const char WPASupplicant::kInterfaceStateCompleted[] = "completed"; |
| 75 | const char WPASupplicant::kInterfaceStateDisconnected[] = "disconnected"; |
| 76 | const char WPASupplicant::kInterfaceStateGroupHandshake[] = "group_handshake"; |
| 77 | const char WPASupplicant::kInterfaceStateInactive[] = "inactive"; |
| 78 | const char WPASupplicant::kInterfaceStateScanning[] = "scanning"; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 79 | const char WPASupplicant::kKeyManagementIeee8021X[] = "IEEE8021X"; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 80 | const char WPASupplicant::kKeyManagementMethodSuffixEAP[] = "-eap"; |
| 81 | const char WPASupplicant::kKeyManagementMethodSuffixPSK[] = "-psk"; |
| 82 | const char WPASupplicant::kKeyModeNone[] = "NONE"; |
| 83 | const char WPASupplicant::kNetworkBgscanMethodLearn[] = "learn"; |
Christopher Wiley | a998df2 | 2012-07-11 15:14:55 -0700 | [diff] [blame] | 84 | // 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 Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 86 | const char WPASupplicant::kNetworkBgscanMethodNone[] = "none"; |
| 87 | const char WPASupplicant::kNetworkBgscanMethodSimple[] = "simple"; |
| 88 | const char WPASupplicant::kNetworkModeInfrastructure[] = "infrastructure"; |
| 89 | const char WPASupplicant::kNetworkModeAdHoc[] = "ad-hoc"; |
| 90 | const char WPASupplicant::kNetworkModeAccessPoint[] = "ap"; |
| 91 | const char WPASupplicant::kNetworkPropertyBgscan[] = "bgscan"; |
| 92 | const char WPASupplicant::kNetworkPropertyCaPath[] = "ca_path"; |
| 93 | const char WPASupplicant::kNetworkPropertyEapIdentity[] = "identity"; |
| 94 | const char WPASupplicant::kNetworkPropertyEapKeyManagement[] = "key_mgmt"; |
| 95 | const char WPASupplicant::kNetworkPropertyEapEap[] = "eap"; |
| 96 | const char WPASupplicant::kNetworkPropertyEapInnerEap[] = "phase2"; |
| 97 | const char WPASupplicant::kNetworkPropertyEapAnonymousIdentity[] |
| 98 | = "anonymous_identity"; |
| 99 | const char WPASupplicant::kNetworkPropertyEapClientCert[] = "client_cert"; |
| 100 | const char WPASupplicant::kNetworkPropertyEapPrivateKey[] = "private_key"; |
| 101 | const char WPASupplicant::kNetworkPropertyEapPrivateKeyPassword[] = |
| 102 | "private_key_passwd"; |
| 103 | const char WPASupplicant::kNetworkPropertyEapCaCert[] = "ca_cert"; |
| 104 | const char WPASupplicant::kNetworkPropertyEapCaPassword[] = "password"; |
| 105 | const char WPASupplicant::kNetworkPropertyEapCertId[] = "cert_id"; |
| 106 | const char WPASupplicant::kNetworkPropertyEapKeyId[] = "key_id"; |
| 107 | const char WPASupplicant::kNetworkPropertyEapCaCertId[] = "ca_cert_id"; |
| 108 | const char WPASupplicant::kNetworkPropertyEapPin[] = "pin"; |
| 109 | const char WPASupplicant::kNetworkPropertyEapSubjectMatch[] = "subject_match"; |
Paul Stewart | 9413bcc | 2013-04-04 16:12:43 -0700 | [diff] [blame] | 110 | const char WPASupplicant::kNetworkPropertyEapolFlags[] = "eapol_flags"; |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 111 | const char WPASupplicant::kNetworkPropertyEngine[] = "engine"; |
| 112 | const char WPASupplicant::kNetworkPropertyEngineId[] = "engine_id"; |
| 113 | const char WPASupplicant::kNetworkPropertyFrequency[] = "frequency"; |
| 114 | const char WPASupplicant::kNetworkPropertyIeee80211w[] = "ieee80211w"; |
| 115 | const char WPASupplicant::kNetworkPropertyMode[] = "mode"; |
| 116 | const char WPASupplicant::kNetworkPropertyScanSSID[] = "scan_ssid"; |
| 117 | const char WPASupplicant::kNetworkPropertySSID[] = "ssid"; |
| 118 | const char WPASupplicant::kPropertyAuthAlg[] = "auth_alg"; |
| 119 | const char WPASupplicant::kPropertyPreSharedKey[] = "psk"; |
| 120 | const char WPASupplicant::kPropertyPrivacy[] = "Privacy"; |
| 121 | const char WPASupplicant::kPropertyRSN[] = "RSN"; |
| 122 | const char WPASupplicant::kPropertyScanSSIDs[] = "SSIDs"; |
| 123 | const char WPASupplicant::kPropertyScanType[] = "Type"; |
| 124 | const char WPASupplicant::kPropertySecurityProtocol[] = "proto"; |
| 125 | const char WPASupplicant::kPropertyWEPKey[] = "wep_key"; |
| 126 | const char WPASupplicant::kPropertyWEPTxKeyIndex[] = "wep_tx_keyidx"; |
| 127 | const char WPASupplicant::kPropertyWPA[] = "WPA"; |
| 128 | const char WPASupplicant::kScanTypeActive[] = "active"; |
| 129 | const char WPASupplicant::kSecurityAuthAlg[] = "OPEN SHARED"; |
| 130 | const char WPASupplicant::kSecurityMethodPropertyKeyManagement[] = "KeyMgmt"; |
| 131 | const char WPASupplicant::kSecurityModeRSN[] = "RSN"; |
| 132 | const char WPASupplicant::kSecurityModeWPA[] = "WPA"; |
mukesh agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 133 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 134 | const uint32_t WPASupplicant::kDefaultEngine = 1; |
| 135 | const uint32_t WPASupplicant::kNetworkIeee80211wDisabled = 0; |
| 136 | const uint32_t WPASupplicant::kNetworkIeee80211wEnabled = 1; |
| 137 | const uint32_t WPASupplicant::kNetworkIeee80211wRequired = 2; |
| 138 | const uint32_t WPASupplicant::kNetworkModeInfrastructureInt = 0; |
| 139 | const uint32_t WPASupplicant::kNetworkModeAdHocInt = 1; |
| 140 | const uint32_t WPASupplicant::kNetworkModeAccessPointInt = 2; |
| 141 | const uint32_t WPASupplicant::kScanMaxSSIDsPerScan = 4; |
| 142 | |
Paul Stewart | 196f50f | 2013-03-27 18:02:11 -0700 | [diff] [blame] | 143 | const char WPASupplicant::kSupplicantConfPath[] = |
| 144 | SHIMDIR "/wpa_supplicant.conf"; |
| 145 | |
Paul Stewart | 0654ece | 2013-03-26 15:21:26 -0700 | [diff] [blame] | 146 | // static |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 147 | bool 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 agrawal | 6e27777 | 2011-09-29 15:04:23 -0700 | [diff] [blame] | 167 | } // namespace shill |