Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 1 | // 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/supplicant_eap_state_handler.h" |
| 6 | |
| 7 | #include "shill/logging.h" |
| 8 | #include "shill/wpa_supplicant.h" |
| 9 | |
| 10 | namespace shill { |
| 11 | |
| 12 | using std::string; |
| 13 | |
| 14 | SupplicantEAPStateHandler::SupplicantEAPStateHandler() |
| 15 | : is_eap_in_progress_(false) {} |
| 16 | |
| 17 | SupplicantEAPStateHandler::~SupplicantEAPStateHandler() {} |
| 18 | |
| 19 | bool SupplicantEAPStateHandler::ParseStatus(const string &status, |
| 20 | const string ¶meter, |
| 21 | Service::ConnectFailure *failure) { |
| 22 | if (status == WPASupplicant::kEAPStatusAcceptProposedMethod) { |
| 23 | LOG(INFO) << "EAP: accepted method " << parameter; |
| 24 | } else if (status == WPASupplicant::kEAPStatusCompletion) { |
| 25 | if (parameter == WPASupplicant::kEAPParameterSuccess) { |
| 26 | LOG(INFO) << "EAP: Completed authentication successfully."; |
| 27 | is_eap_in_progress_ = false; |
| 28 | return true; |
| 29 | } else if (parameter == WPASupplicant::kEAPParameterFailure) { |
| 30 | // If there was a TLS error, use this instead of the generic failure. |
| 31 | if (tls_error_ == WPASupplicant::kEAPStatusLocalTLSAlert) { |
| 32 | *failure = Service::kFailureEAPLocalTLS; |
| 33 | } else if (tls_error_ == |
| 34 | WPASupplicant::kEAPStatusRemoteTLSAlert) { |
| 35 | *failure = Service::kFailureEAPRemoteTLS; |
| 36 | } else { |
| 37 | *failure = Service::kFailureEAPAuthentication; |
| 38 | } |
| 39 | } else { |
| 40 | LOG(ERROR) << "EAP: Unexpected " << status << " parameter: " << parameter; |
| 41 | } |
| 42 | } else if (status == WPASupplicant::kEAPStatusLocalTLSAlert || |
| 43 | status == WPASupplicant::kEAPStatusRemoteTLSAlert) { |
| 44 | tls_error_ = status; |
| 45 | } else if (status == |
| 46 | WPASupplicant::kEAPStatusRemoteCertificateVerification) { |
| 47 | if (parameter == WPASupplicant::kEAPParameterSuccess) { |
| 48 | LOG(INFO) << "EAP: Completed remote certificate verification."; |
| 49 | } else { |
| 50 | // wpa_supplicant doesn't currently have a verification failure |
| 51 | // message. We will instead get a RemoteTLSAlert above. |
| 52 | LOG(ERROR) << "EAP: Unexpected " << status << " parameter: " << parameter; |
| 53 | } |
| 54 | } else if (status == WPASupplicant::kEAPStatusParameterNeeded) { |
Paul Stewart | 11c224b | 2013-10-22 19:04:40 -0700 | [diff] [blame] | 55 | if (parameter == WPASupplicant::kEAPRequestedParameterPIN) { |
| 56 | // wpa_supplicant could have erased the PIN. Signal to WiFi that |
| 57 | // it should supply one if possible. |
| 58 | *failure = Service::kFailurePinMissing; |
| 59 | } else { |
| 60 | LOG(ERROR) << "EAP: Authentication aborted due to missing authentication " |
| 61 | << "parameter: " << parameter; |
| 62 | *failure = Service::kFailureEAPAuthentication; |
| 63 | } |
Paul Stewart | 735eab5 | 2013-03-29 09:19:23 -0700 | [diff] [blame] | 64 | } else if (status == WPASupplicant::kEAPStatusStarted) { |
| 65 | LOG(INFO) << "EAP: Authentication starting."; |
| 66 | is_eap_in_progress_ = true; |
| 67 | } |
| 68 | |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | void SupplicantEAPStateHandler::Reset() { |
| 73 | is_eap_in_progress_ = false; |
| 74 | tls_error_ = ""; |
| 75 | } |
| 76 | |
| 77 | } // namespace shill |