Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

eap_authfsm.hxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 // $Id: eap_authfsm.hxx,v 1.26 2004/06/17 21:13:36 yohba Exp $
00034 
00035 // eap_authfsm.hxx:  Authenticator state machine
00036 // Written by Yoshihiro Ohba
00037 
00038 #ifndef __EAP_AUTHFSM_HXX__
00039 #define __EAP_AUTHFSM_HXX__
00040 
00041 #include <ace/Basic_Types.h>
00042 #include <string>
00043 #include "eap.hxx"
00044 #include "eap_fsm.hxx"
00045 #include "eap_method_registrar.hxx"
00046 
00047 
00050 class EAP_EXPORTS EapAuthSwitchStateMachine : public EapSwitchStateMachine
00051 {
00052 public:
00053 
00056   void Receive(AAAMessageBlock*);
00057 
00067   virtual void Success(AAAMessageBlock *b)=0;
00068 
00071   virtual void Success()=0;
00072 
00082   virtual void Failure(AAAMessageBlock *b)=0;
00083 
00086   virtual void Failure()=0;
00087 
00090   inline ACE_UINT16& MaxRetransmissionCount() 
00091   { return maxRetransmissionCount; }
00092 
00095   inline ACE_UINT16& RetransmissionInterval() 
00096   { return retransmissionInterval; }
00097 
00099   //  inline ACE_Byte CurrentIdentifier() { return currentIdentifier; }
00100 
00102   virtual inline bool IsEapBackend(void) { return false; }
00103 
00105   inline bool RetransmissionEnabled() { return (retransmissionInterval != 0); }
00106 
00109   inline void NeedInitialRequestToSend(bool b) { needInitialRequestToSend=b; }
00110 
00113   inline bool NeedInitialRequestToSend() { return needInitialRequestToSend; }
00114 
00116   inline std::string& NotificationString() { return notificationString; }
00117 
00119   inline ACE_UINT16& RetransmissionCount() { return retransmissionCount; }
00120 
00121   enum EapAuthDecision {
00122       DecisionSuccess,
00123       DecisionFailure,
00124       DecisionContinue,
00125       DecisionPassthrough
00126   };
00127 
00129   virtual EapAuthDecision Decision();
00130 
00133 
00134   enum EapAuthMethodState {
00135     PROPOSED=0,
00136     CONT,
00137     END,     
00138   };
00139 
00140 
00141   EapAuthMethodState& MethodState();
00142 
00144   enum event {
00145     EvRxMsg=-1,                 // Message reception event passed from
00146                                 // application via
00147                                 // EapSession::Receive().
00148     EvSgPortEnabled=-2,         // Port enabled event passed from
00149                                 // application.
00150     EvSgValidResp=-3,           // Event for integrity check success
00151                                 // with continueing method (passed
00152                                 // from methods).
00153     EvSgInvalidResp=-4,         // Integrity check failure event
00154                                 // passed from methods.
00155     EvSgEndMethod=-5,           // Event for integrity check sucess
00156                                 // with end method (passed from
00157                                 // methods).
00158     EvSgRestart=-6,             // Event generated to start the state
00159                                 // machine as a non-backend server.
00160     EvSgAaaContinue=-7,         // Event generated when AAA continues.
00161 
00162     EvSgAaaSuccess=-8,          // Event generated when AAA succeeds.
00163 
00164     EvSgAaaFailure=-9,          // Event generated when AAA fails.
00165   };
00166 
00167 protected:
00168 
00169 
00170   EapAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h) 
00171     : EapSwitchStateMachine(r, h),
00172       discardCount(0),
00173       retransmissionCount(0),
00174       maxRetransmissionCount(defaultMaxRetransmissionCount),
00175       retransmissionInterval(defaultRetransmissionInterval),
00176       needInitialRequestToSend(true)
00177   {}
00178 
00179   virtual ~EapAuthSwitchStateMachine() {}
00180 
00181   static const ACE_UINT16 defaultMaxRetransmissionCount;
00182   static const ACE_UINT16 defaultRetransmissionInterval;
00183 
00184   ACE_UINT16 discardCount;
00185   ACE_UINT16 retransmissionCount;
00186   ACE_UINT16 maxRetransmissionCount;
00187   ACE_UINT16 retransmissionInterval;  // Set this value to zero when
00188                                       // retransmission is disabled.
00189   std::string notificationString;     // Used for sending notification
00190                                       // to the per.
00191   bool needInitialRequestToSend;
00192 
00194   EapAuthMethodState methodState;
00195 };
00196 
00199 class EAP_EXPORTS EapStandAloneAuthSwitchStateMachine : 
00200     public EapAuthSwitchStateMachine,
00201     public EapStateMachine<EapStandAloneAuthSwitchStateMachine>
00202 {
00203  public:
00204 
00205   void Start() throw(AAA_Error)
00206   {
00207     // Set the current policy element to point to the initial policy
00208     // element.
00209     policy.CurrentPolicyElement(policy.InitialPolicyElement());
00210 
00211     // Delete the last executed method if any.
00212     DeleteMethodStateMachine();
00213 
00214     // Initialize the state machine.
00215     EapStateMachine<EapStandAloneAuthSwitchStateMachine>::Start();
00216 
00217     // Initialize key stuff.
00218     keyData.resize(0);
00219     keyAvailable=false;
00220 
00221     // Generate the initial event.
00222     Notify(EapAuthSwitchStateMachine::EvSgRestart);
00223   }
00224 
00225   inline void Notify(AAA_Event ev)
00226   {
00227     try {
00228       EapStateMachine<EapStandAloneAuthSwitchStateMachine>::Notify(ev);
00229     }
00230     catch (int i) {
00231           ACE_UNUSED_ARG(i);
00232       EAP_LOG(LM_DEBUG, "Nofify() failed.\n");
00233       Abort();
00234     }
00235   }
00236 
00237 protected:
00238   EapStandAloneAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h);
00239 
00240   virtual ~EapStandAloneAuthSwitchStateMachine();
00241 };
00242 
00245 class EAP_EXPORTS EapBackendAuthSwitchStateMachine :
00246     public EapAuthSwitchStateMachine,
00247     public EapStateMachine<EapBackendAuthSwitchStateMachine>
00248 {
00249 public:
00250 
00251   void Start() throw(AAA_Error)
00252   {
00253     // Set the current policy element to point to the initial policy
00254     // element.
00255     policy.CurrentPolicyElement(policy.InitialPolicyElement());
00256 
00257     // Initialize the state machine.
00258     EapStateMachine<EapBackendAuthSwitchStateMachine>::Start();
00259 
00260     // Initialize key stuff.
00261     keyData.resize(0);
00262     keyAvailable=false;
00263 
00264     // Generate the initial event.
00265     Notify(EapAuthSwitchStateMachine::EvSgRestart);
00266   }
00267 
00268   inline void Notify(AAA_Event ev)
00269   {
00270     try {
00271       EapStateMachine<EapBackendAuthSwitchStateMachine>::Notify(ev);
00272     }
00273     catch (int i) {
00274           ACE_UNUSED_ARG(i);
00275       EAP_LOG(LM_DEBUG, "Nofify() failed.\n");
00276       Abort();
00277     }
00278   }
00279 
00281   void Start(AAAMessageBlock *msg);
00282 
00283   inline bool IsEapBackend(void) { return true; }
00284 
00285 protected:
00286   EapBackendAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h);
00287 
00288   virtual ~EapBackendAuthSwitchStateMachine();
00289 };
00290 
00293 class EAP_EXPORTS EapPassThroughAuthSwitchStateMachine : 
00294     public EapAuthSwitchStateMachine,
00295     public EapStateMachine<EapPassThroughAuthSwitchStateMachine>
00296 {
00297 public:
00298 
00299   void Start() throw(AAA_Error)
00300   {
00301     // Set the current policy element to point to the initial policy
00302     // element.
00303     policy.CurrentPolicyElement(policy.InitialPolicyElement());
00304 
00305     // Initialize the state machine.
00306     EapStateMachine<EapPassThroughAuthSwitchStateMachine>::Start();
00307 
00308     // Initialize key stuff.
00309     keyData.resize(0);
00310     keyAvailable=false;
00311 
00312     // Generate the initial event.
00313     Notify(EapAuthSwitchStateMachine::EvSgRestart);
00314   }
00315 
00316   inline void Notify(AAA_Event ev)
00317   {
00318     try {
00319       EapStateMachine<EapPassThroughAuthSwitchStateMachine>::Notify(ev);
00320     }
00321     catch (int i) {
00322       ACE_UNUSED_ARG(i);
00323       EAP_LOG(LM_DEBUG, "Nofify() failed.\n");
00324       Abort();
00325     }
00326   }
00327 
00331   virtual void ForwardResponse(AAAMessageBlock *msg)=0;
00332 
00334   inline EapMessageQueue& AAARxQueue() throw() { return aaaRxQueue; }
00335 
00337   ACE_Byte GetNextIdentifier(ACE_Byte id) { return id; }
00338 
00340   EapAuthDecision Decision();
00341 
00343   void AAA_Success(AAAMessageBlock *msg) throw(int)
00344   {
00345     // Check if this is operating in passthorugh mode.
00346     if (Decision() != DecisionPassthrough)
00347       {
00348         EAP_LOG(LM_ERROR, "Not operating in pass-through mode");
00349         throw -1;
00350       }
00351 
00352     if (msg)
00353       AAARxQueue().enqueue_tail(AAAMessageBlock::Acquire(msg));
00354 
00355     Notify(EvSgAaaSuccess);
00356   }
00357 
00359   void AAA_Failure(AAAMessageBlock *msg) throw(int)
00360   {
00361     // Check if this is operating in passthorugh mode.
00362     if (Decision() != DecisionPassthrough)
00363       {
00364         EAP_LOG(LM_ERROR, "Not operating in pass-through mode.\n");
00365         throw -1;
00366       }
00367 
00368     if (msg)
00369       AAARxQueue().enqueue_tail(AAAMessageBlock::Acquire(msg));
00370 
00371     Notify(EvSgAaaFailure);
00372   }
00373 
00376   void AAA_Continue(AAAMessageBlock *msg) throw(int)
00377   {
00378     // Check if this is operating in passthorugh mode.
00379     if (Decision() != DecisionPassthrough)
00380       {
00381         EAP_LOG(LM_ERROR, "Not operating in pass-through mode.\n");
00382         throw -1;
00383       }
00384 
00385     if (!msg)
00386       {
00387         EAP_LOG(LM_ERROR, "AAAContinue must contain non-null msg.\n");
00388         throw -1;
00389       }
00390     AAARxQueue().enqueue_tail(AAAMessageBlock::Acquire(msg));
00391     Notify(EvSgAaaContinue);
00392   }
00393 
00394 protected:
00395   EapPassThroughAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle &h);
00396   virtual ~EapPassThroughAuthSwitchStateMachine();
00397 
00399   EapMessageQueue aaaRxQueue;
00400 };
00401 
00402 #endif // __EAP_AUTHFSM_HXX__

Generated on Fri Jun 25 19:16:16 2004 for EAP State Machine by doxygen 1.3.5