📄 eap_backend_authfsm.cxx
字号:
/* BEGIN_COPYRIGHT *//* *//* Open Diameter: Open-source software for the Diameter and *//* Diameter related protocols *//* *//* Copyright (C) 2002-2004 Open Diameter Project *//* *//* This library is free software; you can redistribute it and/or modify *//* it under the terms of the GNU Lesser General Public License as *//* published by the Free Software Foundation; either version 2.1 of the *//* License, or (at your option) any later version. *//* *//* This library is distributed in the hope that it will be useful, *//* but WITHOUT ANY WARRANTY; without even the implied warranty of *//* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *//* Lesser General Public License for more details. *//* *//* You should have received a copy of the GNU Lesser General Public *//* License along with this library; if not, write to the Free Software *//* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *//* USA. *//* *//* In addition, when you copy and redistribute some or the entire part of *//* the source code of this software with or without modification, you *//* MUST include this copyright notice in each copy. *//* *//* If you make any changes that are appeared to be useful, please send *//* sources that include the changed part to *//* diameter-developers@lists.sourceforge.net so that we can reflect your *//* changes to one unified version of this software. *//* *//* END_COPYRIGHT */// $Id: eap_backend_authfsm.cxx,v 1.17 2004/08/10 16:41:06 vfajardo Exp $// eap_backend_authfsm.cxx: Backend Authenticator state machine// Written by Yoshihiro Ohba#include <ace/Basic_Types.h>#include <ace/Singleton.h>#include "eap.hxx"#include "eap_authfsm.hxx"#include "eap_policy.hxx"#include "eap_log.hxx"#include "eap_parser.hxx"/// Action class for EAP. class EapBackendAuthSwitchAction : public AAA_Action<EapBackendAuthSwitchStateMachine>{ public: virtual void operator()(EapBackendAuthSwitchStateMachine&) {} protected: EapBackendAuthSwitchAction() {} virtual ~EapBackendAuthSwitchAction() {}};/// State table used by EapAuthSwitchStateMachine.class EapBackendAuthSwitchStateTable_S : public AAA_StateTable<EapBackendAuthSwitchStateMachine>{ friend class ACE_Singleton<EapBackendAuthSwitchStateTable_S, ACE_Recursive_Thread_Mutex>;private: class AcDisable : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { sm.Event(EapAuthSwitchStateMachine::EvSgPortEnabled); } }; class AcBackendInitialize : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { sm.CurrentIdentifier()=0; AAAMessageBlock *msg = sm.GetRxMessage(); // If there is a received message parse it. if (!msg) { sm.Event(EvElse); return; } // Parse the header EapHeaderParser hp; EapHeader header; hp.setAppData(&header); hp.setRawData(msg); hp.parseRawToApp(); // Check code unsigned code = header.code; unsigned id = header.identifier; // Check code & identifier if (code != Response) { sm.Event(EvRxNonResp); return; } sm.CurrentIdentifier() = id; // Update the identifier // Parse the response EapResponseParser parser; EapResponse resp; parser.setAppData(&resp); parser.setRawData(msg); parser.parseRawToApp(); EapType type = resp.GetType(); if (sm.Policy().CurrentMethod() != type) { sm.Event(EvRxNonResp); return; } sm.CurrentMethod() = resp.GetType(); // Check response type. If this is a Nak message, then // generate a Nak reception event. if (type == EapType(3)) sm.Event(EvRxNak); else sm.Event(EvElse); } }; class AcPickUpMethod : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { EapType type = sm.Policy().CurrentMethod(); if (sm.Policy().SupportPickUp(type)) { // Start the pick-up method. sm.CurrentMethod() = type; sm.CreateMethodStateMachine(type, Authenticator); sm.MethodStateMachine().Start(); sm.Event(EvElse); } else { sm.Event(EvSgNoMethod); } } }; class AcSendSuccess : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { AAAMessageBlock *msg = AAAMessageBlock::Acquire(4); EAP_LOG(LM_DEBUG, "Backend: Composing Success message.\n"); // Compose the PDU. EapHeaderParser parser; EapHeader header; header.code = Success; header.identifier = sm.CurrentIdentifier(); header.length = 4; parser.setAppData(&header); parser.setRawData(msg); parser.parseAppToRaw(); // Stop retransmission timer and reset retransmission counter. sm.CancelTimer(); sm.RetransmissionCount()=0; // Make the key available. (not specified in the state machine document.) if (sm.KeyData().size()>0) sm.KeyAvailable() = true; // Call Success callback function. sm.Success(msg); msg->release(); } }; class AcSendFailure : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { AAAMessageBlock *msg = AAAMessageBlock::Acquire(4); EAP_LOG(LM_DEBUG, "Backend: Composing Failure message.\n"); // Compose the PDU. EapHeaderParser parser; EapHeader header; header.code = Failure; header.identifier = sm.CurrentIdentifier(); header.length = 4; parser.setAppData(&header); parser.setRawData(msg); parser.parseAppToRaw(); // Stop retransmission timer and reset retransmission counter. sm.CancelTimer(); sm.RetransmissionCount()=0; // Call Failure callback function. sm.Failure(msg); msg->release(); } }; class AcMethodResponse : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { EapMethodStateMachine &msm = sm.MethodStateMachine(); if (msm.IsDone()) { sm.KeyData() = msm.KeyData(); sm.MethodState() = EapAuthSwitchStateMachine::END; sm.Event(EapAuthSwitchStateMachine::EvSgEndMethod); } else { sm.MethodState() = EapAuthSwitchStateMachine::CONT; sm.Event(EvElse); } } }; class AcBuildRequest : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { // Calculate the next Identifier for the new request. ACE_Byte id = sm.CurrentIdentifier() = sm.MethodStateMachine().GetNextIdentifier(sm.CurrentIdentifier()); AAAMessageBlock *msg = sm.GetTxMessage(); // Compose the PDU. EapHeaderParser headerParser; EapHeader header; header.code = Request; header.identifier = id; header.length = msg->length(); headerParser.setAppData(&header); headerParser.setRawData(msg); headerParser.parseAppToRaw(); // Set the wr_ptr to the tail of the message. msg->wr_ptr(msg->base()+header.length); sm.Event(EvUCT); } }; class AcSendRequest : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { // Stop retransmission timer and reset retransmission counter. sm.CancelTimer(); sm.RetransmissionCount()=0; AAAMessageBlock *msg = sm.GetTxMessage(); // Call Send callback function. // Increment the retransmission count. sm.RetransmissionCount()++; // Schedule retransmssion timer EAP_LOG(LM_DEBUG, "Backend: Request sent and timer started.\n"); if (sm.RetransmissionEnabled()) sm.ScheduleTimer(EvTo, sm.RetransmissionInterval()); sm.Notify(EvUCT); // Send the messsage. sm.Send(msg); } }; class AcDoIntegrityCheck : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { EAP_LOG(LM_DEBUG, "Backend: Integrity Check.\n"); sm.MethodStateMachine().Notify (EapMethodStateMachine::EvSgIntegrityCheck); } }; class AcProposeMethod : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { EapType type = sm.Policy().CurrentMethod(); if (!type.IsVSE()) EAP_LOG(LM_DEBUG, "Backend: Trying another legacy method.\n"); else EAP_LOG(LM_DEBUG, "Backend: Trying another extended method.\n"); sm.DeleteMethodStateMachine(); sm.CurrentMethod() = type; sm.CreateMethodStateMachine(type, Authenticator); sm.MethodStateMachine().Start(); if (type == EapType(1) || type == EapType(2)) // Identity or Notification sm.MethodState() = EapAuthSwitchStateMachine::CONT; else sm.MethodState() = EapAuthSwitchStateMachine::PROPOSED; // Notify method sm.MethodStateMachine().Notify (EapMethodStateMachine::EvSgIntegrityCheck); } }; class AcDoPolicyCheck : public EapBackendAuthSwitchAction { void operator()(EapBackendAuthSwitchStateMachine &sm) { EapAuthSwitchStateMachine::EapAuthDecision decision = sm.Decision(); if (decision == EapAuthSwitchStateMachine::DecisionSuccess) sm.Event(EvSgPolicySat); else if (decision == EapAuthSwitchStateMachine::DecisionFailure)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -