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

eap_archie_fsm.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_archie_fsm.hxx,v 1.6 2004/06/17 21:13:36 yohba Exp $
00034 
00035 // EAP-Archie state machines.
00036 // Written by Yoshihiro Ohba (yohba@tari.toshiba.com)
00037 
00038 #ifndef __EAP_ARCHIE_FSM_HXX__
00039 #define __EAP_ARCHIE_FSM_HXX__
00040 
00041 #include <ace/Reactor.h>
00042 #include <iostream>
00043 #include "eap_archie.hxx"
00044 #include "eap_peerfsm.hxx"
00045 #include "eap_authfsm.hxx"
00046 #include "eap_method_registrar.hxx"
00047 #include "eap_archie_crypto.hxx"
00048 
00050 class EAP_ARCHIE_EXPORTS EapPeerArchieStateMachine 
00051   :  public EapMethodStateMachine,
00052      public EapStateMachine<EapPeerArchieStateMachine>
00053 {
00054   friend class EapMethodStateMachineCreator<EapPeerArchieStateMachine>;
00055   friend class EapPeerArchieStateTable_S;
00056 public:
00057 
00059   void Start() throw(AAA_Error)
00060   {
00061     isDone=false;
00062     keyData.resize(0);
00063     masterKey.resize(0);
00064     history.resize(0);
00065     keyConfirmationKey.resize(0);
00066     keyEncryptionKey.resize(0);
00067     keyDerivationKey.resize(0);
00068 
00069     EapStateMachine<EapPeerArchieStateMachine>::Start();
00070   }
00071 
00073   inline void Notify(AAA_Event ev)
00074   {
00075     EapStateMachine<EapPeerArchieStateMachine>::Notify(ev);
00076   }
00077 
00080   virtual std::string& InputSharedSecret()=0;
00081 
00084   virtual std::string& InputIdentity()=0;
00085 
00087   std::string& SharedSecret() { return sharedSecret; }
00088 
00090   std::string& KCK() 
00091   { 
00092     if (keyConfirmationKey.size() != 16)
00093       keyConfirmationKey.assign(sharedSecret, 0, 16);
00094     return keyConfirmationKey; 
00095   }
00096 
00098   std::string& KEK() { 
00099     if (keyEncryptionKey.size() != 16)
00100       keyEncryptionKey.assign(sharedSecret, 16, 16);
00101     return keyEncryptionKey; 
00102   }
00103 
00105   std::string& KDK() { 
00106     if (keyDerivationKey.size() != 32)
00107       keyDerivationKey.assign(sharedSecret, 32, 32);
00108     return keyDerivationKey; 
00109   }
00110 
00112   std::string& MK() { 
00113     if (masterKey.size() != 32 && 
00114         this->PeerSwitchStateMachine().MethodState() 
00115         == EapPeerSwitchStateMachine::DONE)
00116       {
00117         // Compute the master key.
00118         std::string tmp(nonceA);
00119         tmp.append(nonceP);
00120         tmp.append("Archie session key");
00121         EapCryptoArchiePRF prf;
00122         prf(tmp, masterKey, KDK(), 32);
00123       }
00124     return masterKey; 
00125   }
00126 
00128   std::string& SessionID() { return sessionID; }
00129 
00131   std::string& PeerID() { return peerID; }
00132 
00134   std::string& AuthID() { return authID; }
00135 
00137   ArchieBinding& Binding() { return binding; }
00138 
00140   std::string& NonceA() { return nonceA; }
00141 
00143   std::string& NonceP() { return nonceP; }
00144 
00146   std::string& History() { return history; }
00147 
00148 protected:
00149   EapPeerArchieStateMachine(EapSwitchStateMachine &s);
00150 
00151   ~EapPeerArchieStateMachine() {} 
00152 
00154   std::string sharedSecret;
00155 
00157   std::string keyConfirmationKey;
00158 
00160   std::string keyEncryptionKey;
00161 
00163   std::string keyDerivationKey;
00164 
00166   std::string masterKey;
00167 
00169   std::string sessionID;
00170 
00172   std::string peerID, authID;
00173 
00175   std::string nonceP, nonceA;
00176 
00178   ArchieBinding binding;
00179 
00181   std::string history;
00182 };
00183 
00185 class EAP_ARCHIE_EXPORTS EapAuthArchieStateMachine 
00186   :  public EapMethodStateMachine,
00187      public EapStateMachine<EapAuthArchieStateMachine>
00188 {
00189   friend class EapMethodStateMachineCreator<EapAuthArchieStateMachine>;
00190   friend class EapAuthArchieStateTable_S;
00191 public:
00192 
00194   void Start() throw(AAA_Error)
00195   {
00196     keyData.resize(0);
00197     masterKey.resize(0);
00198     history.resize(0);
00199     keyConfirmationKey.resize(0);
00200     keyEncryptionKey.resize(0);
00201     keyDerivationKey.resize(0);
00202     EapStateMachine<EapAuthArchieStateMachine>::Start();
00203   }
00204 
00206   inline void Notify(AAA_Event ev)
00207   {
00208     EapStateMachine<EapAuthArchieStateMachine>::Notify(ev);
00209   }
00210 
00213   virtual std::string& InputSharedSecret()=0;
00214 
00217   virtual std::string& InputIdentity()=0;
00218 
00220   std::string& SharedSecret() { return sharedSecret; }
00221 
00223   std::string& KCK() 
00224   { 
00225     if (keyConfirmationKey.size() != 16)
00226       keyConfirmationKey.assign(sharedSecret, 0, 16);
00227     return keyConfirmationKey; 
00228   }
00229 
00231   std::string& KEK() { 
00232     if (keyEncryptionKey.size() != 16)
00233       keyEncryptionKey.assign(sharedSecret, 16, 16);
00234     return keyEncryptionKey; 
00235   }
00236 
00238   std::string& KDK() { 
00239     if (keyDerivationKey.size() != 32)
00240       keyDerivationKey.assign(sharedSecret, 32, 32);
00241     return keyDerivationKey; 
00242   }
00243 
00245   std::string& MK() { 
00246     if (masterKey.size() != 32 && IsDone())
00247       {
00248         // Compute the master key.
00249         std::string tmp(nonceA);
00250         tmp.append(nonceP);
00251         tmp.append("Archie session key");
00252         EapCryptoArchiePRF prf;
00253         prf(tmp, masterKey, KDK(), 32);
00254       }
00255     return masterKey; 
00256   }
00257 
00259   std::string& SessionID() { return sessionID; }
00260 
00262   std::string& PeerID() { return peerID; }
00263 
00265   std::string& AuthID() { return authID; }
00266 
00268   ArchieBinding& Binding() { return binding; }
00269 
00271   std::string& NonceA() { return nonceA; }
00272 
00274   std::string& NonceP() { return nonceP; }
00275 
00277   std::string& History() { return history; }
00278 
00279 protected:
00280   EapAuthArchieStateMachine(EapSwitchStateMachine &s);
00281 
00282   ~EapAuthArchieStateMachine() {} 
00283 
00285   std::string sharedSecret;
00286 
00288   std::string keyConfirmationKey;
00289 
00291   std::string keyEncryptionKey;
00292 
00294   std::string keyDerivationKey;
00295 
00297   std::string masterKey;
00298 
00300   std::string sessionID;
00301 
00303   std::string peerID, authID;
00304 
00306   std::string nonceP, nonceA;
00307 
00309   ArchieBinding binding;
00310 
00312   std::string history;
00313 };
00314 
00315 #endif //__EAP_ARCHIE_FSM_HXX__

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