⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test1.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
/* 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: Test1.cxx,v 1.33 2006/03/16 17:01:58 vfajardo Exp $ // A test program for EAP API.// Written by Victor Fajardo#include <iostream>#include <ace/OS.h>#include <ace/Signal.h>#include <ace/Event_Handler.h>#include <ace/Get_Opt.h>#include <boost/shared_ptr.hpp>#include "eap.hxx"#include "eap_peerfsm.hxx"#include "eap_authfsm.hxx"#include "eap_identity.hxx"#include "eap_policy.hxx"#include "eap_method_registrar.hxx"#include "eap_fsm.hxx"#include "eap_log.hxx"#include "eap_md5.hxx"#include "pana_client_fsm.h"#include "pana_paa_factory.h"#include "user_db.h"#include "pana_auth_script.h"class MyPeerSwitchStateMachine;class MyStandAloneAuthSwitchStateMachine;class MyBackendAuthSwitchStateMachine;class MyPassThroughAuthSwitchStateMachine;class PeerData;class StandAloneAuthApplication;class BackendAuthApplication;class PassThroughAuthApplication;static std::string gUserName;static std::string gPasswd;static std::string gPacAddrFromEp;/// Task class used in this sample program.class EapTask : public AAA_Task{ public:  /// Constructor.  EapTask() : AAA_Task(AAA_SCHED_FIFO, "EAP") {}  /// Destructor.  ~EapTask() {}};/// This class defines an EAP transport.  When an EAP message is sent/// to a particular entity (e.g., an entity may be peer, standalone/// authenticator, backend authenticator or passthrough authenticator/// depending on the role of the sender, Transmit() method of the/// Channel object of the receiving entity is called.  Transmit()/// method can have sub-channels which is used for distinguishing different/// types of messages.class Channel { public:  Channel() {}  virtual ~Channel() {}  virtual void Transmit(AAAMessageBlock *msg)=0;  virtual void Transmit(AAAMessageBlock *msg, int subChannel)=0;};// Class definition for authenticator identity method for my application.class MyEapAuthIdentityStateMachine : public EapAuthIdentityStateMachine{  friend class EapMethodStateMachineCreator<MyEapAuthIdentityStateMachine>;public:  MyEapAuthIdentityStateMachine(EapSwitchStateMachine &s)    : EapAuthIdentityStateMachine(s) {}   // Reimplemented from EapAuthIdentityStateMachine.  ProcessIdentityResult ProcessIdentity(std::string& identity)   {    if (USER_DB_LOOKUP(identity)) {        std::cout << "Valid Identity received : " << identity << std::endl;        return EapAuthIdentityStateMachine::Success;    }    std::cout << "Invalid Identity received : " << identity << std::endl;    return EapAuthIdentityStateMachine::Failure;  }private:  ~MyEapAuthIdentityStateMachine() {} };// Class definition for peer MD5-Challenge method for my application.class MyEapPeerMD5ChallengeStateMachine   : public EapPeerMD5ChallengeStateMachine{  friend class EapMethodStateMachineCreator<MyEapPeerMD5ChallengeStateMachine>;public:  MyEapPeerMD5ChallengeStateMachine(EapSwitchStateMachine &s)    : EapPeerMD5ChallengeStateMachine(s) {}   // Reimplemented from EapPeerMD5ChallengeStateMachine.  void InputPassphrase()   {    std::cout << "Input password: " << std::endl;    if (gPasswd.length() > 0) {        Passphrase() = gPasswd;    }    else {        std::cin >> Passphrase();    }  }private:  ~MyEapPeerMD5ChallengeStateMachine() {} };// Class definition for authenticator MD5-Challenge method for my application.class MyEapAuthMD5ChallengeStateMachine   : public EapAuthMD5ChallengeStateMachine{  friend class EapMethodStateMachineCreator<MyEapPeerMD5ChallengeStateMachine>;public:  MyEapAuthMD5ChallengeStateMachine(EapSwitchStateMachine &s)    : EapAuthMD5ChallengeStateMachine(s) {}   // Reimplemented from EapPeerMD5ChallengeStateMachine.  void InputPassphrase()   {    std::string &passphrase = Passphrase();    size_t pos;    std::string userName;    std::string &identity = AuthSwitchStateMachine().PeerIdentity();    if ((pos = identity.find('@')) != std::string::npos) {       userName.assign(identity.substr(0, pos));    }    else {       userName = identity;    }    AAA_UserEntry *e = USER_DB_LOOKUP(userName);    if (e) {        passphrase.assign(e->m_Passphrase);    }  }private:  ~MyEapAuthMD5ChallengeStateMachine() {} };class MyPeerSwitchStateMachine: public EapPeerSwitchStateMachine{ public:  MyPeerSwitchStateMachine(ACE_Reactor &r, EapJobHandle& h)       : EapPeerSwitchStateMachine(r, h) {}  void Send(AAAMessageBlock *b);  void Success();  void Failure();  void Notification(std::string &str);  void Abort();  std::string& InputIdentity(); private:  std::string identity;};class MyStandAloneAuthSwitchStateMachine   : public EapStandAloneAuthSwitchStateMachine{ public:  MyStandAloneAuthSwitchStateMachine(ACE_Reactor &r, EapJobHandle& h) :       EapStandAloneAuthSwitchStateMachine(r, h) {}  void Send(AAAMessageBlock *b);  void Success(AAAMessageBlock *b);  void Success();  void Failure(AAAMessageBlock *b);  void Failure();  void Abort();};class PeerApplication : public AAA_JobData,                        public PANA_ClientEventInterface{ public:  PeerApplication(PANA_Node &n, ACE_Semaphore &sem) :     pacSession(n, *this),    handle(EapJobHandle(AAA_GroupedJob::Create(n.Task().Job(), this, "peer"))),    eap(boost::shared_ptr<MyPeerSwitchStateMachine>	(new MyPeerSwitchStateMachine(*n.Task().reactor(), handle))),    semaphore(sem),    md5Method(EapContinuedPolicyElement(EapType(4)))  {    eap->Policy().InitialPolicyElement(&md5Method);    pacSession.EnableDhcpBootstrap() = true;  }  virtual ~PeerApplication() { }  MyPeerSwitchStateMachine& Eap() { return *eap; }  ACE_Semaphore& Semaphore() { return semaphore; }  void EapStart(bool &nap) {     eap->Stop();     eap->Start();  }  void ChooseISP(const PANA_CfgProviderList &list,                 PANA_CfgProviderInfo *&choice) {  }  void EapRequest(AAAMessageBlock *request,                  bool nap) {     eap->Receive(request);  }  void EapAltReject() {  }  void Authorize(PANA_AuthorizationArgs &args) {     PANA_AuthScriptCtl::Print(args);     static bool reauth = false;     if (! reauth) {         pacSession.EapReAuthenticate();         reauth = true;     }     else {         std::string msg = "--- message from client ---";         pacSession.SendNotification(msg);     }  }  bool IsKeyAvailable(diameter_octetstring_t &key) {     return false;  }  bool ResumeSession() {      return false;  }  void Disconnect(ACE_UINT32 cause) {      eap->Stop();      // semaphore.release();  }  void Notification(diameter_octetstring_t &msg) {      std::cout << "PANA notification: " << msg << std::endl;      // pacSession.Stop();  }  void Error(ACE_UINT32 resultCode) {   }  PANA_PacSession &pac() {       return pacSession;   } private:  PANA_PacSession pacSession;  EapJobHandle handle;  boost::shared_ptr<MyPeerSwitchStateMachine> eap;  ACE_Semaphore &semaphore;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -