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

📄 test3.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
         }       std::cout << "Assigning key" << std::endl;       key.assign(eap.KeyData().data(), eap.KeyData().size());       return true;     }     return false;   }   void Notification(diameter_octetstring_t &msg) {       std::cout << "PANA notification: " << msg << std::endl;   }   bool IsUserAuthorized() {      return true;   }   void Disconnect(ACE_UINT32 cause) {      eap.Stop();   }   void Timeout(PANA_TID id) {      eap.Stop();   }   void Error(ACE_UINT32 resultCode) {       eap.Stop();   }   EapPassThroughAuthSwitchStateMachine& Eap() {       return eap;    }   PANA_PaaSession &Pana() {      return paaSession;   }   Channel &BackendTxChannel() {      return backendTxChannel;   }   PANA_PaaSession &PaaSession() {      return paaSession;   } protected:  PANA_PaaSession paaSession;  MyPassThroughAuthSwitchStateMachine &eap;  LocalBackendTxChannel backendTxChannel;};class BackendAuthChannel : public Channel{ public:  BackendAuthChannel(MyBackendAuthSwitchStateMachine &s)    : eap(s), firstMessage(true) {}  void Transmit(AAAMessageBlock *msg=0)   {     if (firstMessage)      {	msg ? eap.Start(msg) : eap.Start();	firstMessage = false;      }    else      {	eap.Receive(msg);       }  }  void Transmit(AAAMessageBlock *msg, int) {}  void Transmit(AAAMessageBlock *msg, std::string &key) {}  MyBackendAuthSwitchStateMachine &eap;  bool firstMessage;};class PeerApplication : public AAA_JobData{ public:  PeerApplication(EapTask &task, ACE_Semaphore &sem) :     handle(EapJobHandle(AAA_GroupedJob::Create(task.Job(), this, "peer"))),    eap(boost::shared_ptr<MyPeerSwitchStateMachine>	(new MyPeerSwitchStateMachine(*task.reactor(), handle))),    semaphore(sem),    channel(task.node, *eap, sem),    method(EapContinuedPolicyElement(EapType(ARCHIE_METHOD_TYPE)))  {    eap->Policy().InitialPolicyElement(&method);  }  ~PeerApplication()   {}  PeerChannel &Channel() { return channel; }  MyPeerSwitchStateMachine& Eap() { return *eap; }  ACE_Semaphore& Semaphore() { return semaphore; } private:  EapJobHandle handle;  boost::shared_ptr<MyPeerSwitchStateMachine> eap;  ACE_Semaphore &semaphore;  PeerChannel channel;  EapContinuedPolicyElement method;};// My application session (not used in this test program).class PassThroughAuthApplication : public AAA_JobData{ public:    PassThroughAuthApplication(PANA_PaaSessionChannel &ch,                               bool pickup=false)    : handle(EapJobHandle	     (AAA_GroupedJob::Create              (ch.Node().Task().Job(), this, "passthrough"))),      eap(boost::shared_ptr<MyPassThroughAuthSwitchStateMachine>	  (new MyPassThroughAuthSwitchStateMachine           (*ch.Node().Task().reactor(), handle))),      channel(ch, *eap),      backendRxChannel(0),      method(EapContinuedPolicyElement(EapType(1)))  {      if (pickup)        eap->Policy().InitialPolicyElement(&method);  }  ~PassThroughAuthApplication() {}  void Start(Channel *rxBackend)  {     backendRxChannel = rxBackend;  }  Channel& BackendTxChannel() { return channel.BackendTxChannel(); }  Channel& BackendRxChannel() { return *backendRxChannel; }      MyPassThroughAuthSwitchStateMachine& Eap() { return *eap; }  PANA_PaaSession &Pana() { return channel.Pana(); }   private:  EapJobHandle handle;  boost::shared_ptr<MyPassThroughAuthSwitchStateMachine> eap;  PassThroughAuthChannel channel;  Channel *backendRxChannel;  EapContinuedPolicyElement method;};// My application session (not used in this test program).class BackendAuthApplication : public AAA_JobData{ public:  BackendAuthApplication(EapTask &task, bool pickup=false)    : handle(EapJobHandle	     (AAA_GroupedJob::Create(task.Job(), this, "backend"))),      eap(boost::shared_ptr<MyBackendAuthSwitchStateMachine>	  (new MyBackendAuthSwitchStateMachine(*task.reactor(), handle))),      rxChannel(BackendAuthChannel(*eap)),      txChannel(0),      identityMethod(EapContinuedPolicyElement(EapType(1))),      archieMethod(EapContinuedPolicyElement(EapType(ARCHIE_METHOD_TYPE)))  {    // Policy settings for the authenticator    identityMethod.AddContinuedPolicyElement      (&archieMethod, EapContinuedPolicyElement::PolicyOnSuccess);    eap->Policy().InitialPolicyElement(&identityMethod);    if (pickup)      {	eap->NeedInitialRequestToSend(false);      }  }  ~BackendAuthApplication() {}  void Start(Channel *c)   {     txChannel = c;  }  void Start(Channel *c, AAAMessageBlock *b)   {     txChannel = c;  }  Channel* RxChannel() { return &rxChannel; }  Channel& TxChannel() { return *txChannel; }  MyBackendAuthSwitchStateMachine& Eap() { return *eap; } private:  EapJobHandle handle;  boost::shared_ptr<MyBackendAuthSwitchStateMachine> eap;  BackendAuthChannel rxChannel;  Channel *txChannel;  EapContinuedPolicyElement identityMethod;  EapContinuedPolicyElement archieMethod;};// ----------------- Definition --------------void MyPeerSwitchStateMachine::Send(AAAMessageBlock *b){  std::cout << "EAP Response sent from peer" << std::endl;  JobData(Type2Type<PeerApplication>()).Channel().pana.EapSendResponse(b);}void MyPeerSwitchStateMachine::Success()  {    std::cout << "Authentication success detected at peer" << std::endl;    std::cout << "Welcome to the world, " 	      << PeerIdentity() 	      << " !!!" << std::endl;  JobData(Type2Type<PeerApplication>()).Channel().pana.EapSuccess();  }void MyPeerSwitchStateMachine::Failure()  {    std::cout << "Authentication failure detected at peer" << std::endl;    std::cout << "Sorry, " 	      << PeerIdentity() 	      << " try next time !!!" << std::endl;    Stop();    JobData(Type2Type<PeerApplication>()).Channel().pana.EapFailure();    JobData(Type2Type<PeerApplication>()).Semaphore().release();  }void MyPeerSwitchStateMachine::Notification(std::string &str)  {    std::cout << "Following notification received" << std::endl;    std::cout << str << std::endl;  }void MyPeerSwitchStateMachine::Abort()  {    std::cout << "Peer aborted for an error in state machine" << std::endl;    JobData(Type2Type<PeerApplication>()).Channel().pana.EapFailure();    JobData(Type2Type<PeerApplication>()).Semaphore().release();  }std::string& MyPeerSwitchStateMachine::InputIdentity()   {    if (gUserName.length() > 0) {        return gUserName;    }    std::cout << "Input username (within 10sec.): " << std::endl;    std::cin >> identity;    std::cout << "username = " << identity << std::endl;    return identity;  }void MyPassThroughAuthSwitchStateMachine::Send(AAAMessageBlock *b)  {    std::cout << "EAP Request sent from passthrough authenticator" 	      << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).        Pana().EapSendRequest(b);  }void MyPassThroughAuthSwitchStateMachine::Success(AAAMessageBlock *b)  {    std::cout << "EAP Success sent from passthrough authenticator" 	      << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).        Pana().EapSuccess(b);  }void MyPassThroughAuthSwitchStateMachine::Success()  {    std::cout << "Success without an EAP Success" << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).        Pana().EapSuccess();  }void MyPassThroughAuthSwitchStateMachine::Failure(AAAMessageBlock *b)  {    std::cout << "EAP Failure sent from passthrough authenticator" 	      << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).        Pana().EapFailure(b);    Stop();  }void MyPassThroughAuthSwitchStateMachine::Failure()  {    std::cout << "Failure without an EAP Failure" << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).        Pana().EapFailure();    Stop();  }void MyPassThroughAuthSwitchStateMachine::Abort()  {    std::cout << "Session aborted for an error in state machine" << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).        Pana().EapFailure();    Stop();  }void MyPassThroughAuthSwitchStateMachine::ForwardResponse(AAAMessageBlock *b)  {    // if this is the first message from the peer, then create the    // authenticator on the EAP server and start it.    if (b)	std::cout << "Passthrough authenticator is forwarding an EAP-Response "		  << "to EAP server" << std::endl;    else	std::cout << "Passthrough authenticator is sending a null EAP message"	          << "to EAP server to start EAP." << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).      BackendRxChannel().Transmit(b);  }void MyBackendAuthSwitchStateMachine::Send(AAAMessageBlock *b)  {    std::cout << "EAP Request sent from authenticator" << std::endl;    JobData(Type2Type<BackendAuthApplication>()).TxChannel().Transmit(b, 1);  }void MyBackendAuthSwitchStateMachine::Success(AAAMessageBlock *b)  {    if (!KeyAvailable())      {	std::cout << "Error: key is not available" << std::endl;	Abort();	return;      }    for (int i=0; i<32; i++)      {	char c[100];	const char* p = KeyData().data();	sprintf(c, "%02X ", *(unsigned char*)(p+i));	std::cout << c;	if ((i+1) % 16 == 0) std::cout << std::endl;	        }    std::cout << std::endl;    std::cout << "EAP Success sent from authenticator" << std::endl;    JobData(Type2Type<BackendAuthApplication>()).      TxChannel().Transmit(b, KeyData());  }void MyBackendAuthSwitchStateMachine::Success()  {    std::cout << "Success without an EAP Success" << std::endl;  }void MyBackendAuthSwitchStateMachine::Failure(AAAMessageBlock *b)  {    std::cout << "EAP Failure sent from authenticator" << std::endl;    JobData(Type2Type<BackendAuthApplication>()).TxChannel().Transmit(b, 3);    Stop();  }void MyBackendAuthSwitchStateMachine::Failure()  {    std::cout << "Failure without an EAP Failure" << std::endl;    Stop();  }void MyBackendAuthSwitchStateMachine::Abort()  {    std::cout << "Session aborted for an error in state machine" << std::endl;    Stop();  }class PassThroughAuthAppFactory : public PANA_PaaSessionFactory{   public:      PassThroughAuthAppFactory(EapTask &t) :          PANA_PaaSessionFactory(t.node), task(t) { }      PANA_PaaSession *Create() {         BackendAuthApplication *b = new BackendAuthApplication(task);          PassThroughAuthApplication *p = new PassThroughAuthApplication             (*this);         p->Start(b->RxChannel());         b->Start(&p->BackendTxChannel());         return &(p->Pana());      }   protected:      EapTask &task;};int main(int argc, char **argv){  std::string cfgfile;  std::string userdb;  bool b_client = false;  // Gather command line options  ACE_Get_Opt opt(argc, argv, "cf:u:U:", 1);      for (int c; (c = opt()) != (-1); ) {      switch (c) {          case 'f': cfgfile.assign(opt.optarg); break;          case 'c': b_client = true; break;          case 'u': userdb.assign(opt.optarg); break;              case 'U': gUserName.assign(opt.optarg); break;      }  }  if ((opt.argc() < 1) || (cfgfile.length() == 0)) {    std::cout << "Usage: pana_test3 [-c] -f [configuration file]" << std::endl;    return (0);  }  else if (! b_client && (userdb.length() == 0)) {    std::cout << "Usage: pana_test [-c] -f [configuration file] -u [user db]" << std::endl;    return (0);  }    // Initialize the log.  EapLogMsg_S::instance()->open("EAP", ACE_Log_Msg::STDERR);  EapLogMsg_S::instance()->enable_debug_messages();  // Register the mapping from EapType to the creator of the  // user-defined method class for each user-defined method  // implementation.  EapMethodStateMachineCreator<MyEapAuthIdentityStateMachine>     myAuthIdentityCreator;  EapMethodStateMachineCreator<MyEapPeerArchieStateMachine>     myPeerArchieCreator;  EapMethodStateMachineCreator<MyEapAuthArchieStateMachine>     myAuthArchieCreator;  EapMethodRegistrar methodRegistrar;  methodRegistrar.registerMethod    (std::string("Identity"), EapType(1),      Authenticator, myAuthIdentityCreator);  methodRegistrar.registerMethod    (std::string("Archie"), EapType(ARCHIE_METHOD_TYPE),      Peer, myPeerArchieCreator);  methodRegistrar.registerMethod    (std::string("Archie"), EapType(ARCHIE_METHOD_TYPE),      Authenticator, myAuthArchieCreator);  EapTask task(cfgfile);    try {    // Task starts with two threads in the thread pool.    task.Start(5);  }  catch (...) {    std::cout << "Task failed to start" << std::endl;    exit(1);  }  // Set shared secret.  char secret[64] = { char(0x70),  char(0x3a),  char(0x97),  char(0x9c),                      char(0xc5),  char(0xd7),  char(0xb0),  char(0x8d),                      char(0x37),  char(0x5c),  char(0x10),  char(0xd7),                      char(0x60),  char(0xfb),  char(0x7f),  char(0x51),                      char(0x54),  char(0x50),  char(0xec),  char(0x65),                      char(0x9e),  char(0x14),  char(0xdb),  char(0x35),                      char(0x41),  char(0xb),  char(0xae),  char(0xd8),                      char(0x50),  char(0x2b),  char(0x5c),  char(0x3b),                      char(0x5e),  char(0x6c),  char(0xbf),  char(0x77),                      char(0xe7),  char(0x1a),  char(0xe0),  char(0x5b),                      char(0x5),  char(0xe0),  char(0xf7),  char(0xb0),                      char(0xcb),  char(0x83),  char(0xff),  char(0x24),                      char(0x6e),  char(0x87),  char(0x49),  char(0xcf),                      char(0x7f),  char(0xc6),  char(0x1b),  char(0xc2),                      char(0xcf),  char(0x64),  char(0x13),  char(0xc6),                      char(0xd5),  char(0xb3),  char(0x5f),  char(0x9) };  sharedSecret = std::string((char*)secret, sizeof secret);  try {     if (b_client) {         ACE_Semaphore semaphore(0);         PeerApplication peerApp(task, semaphore);	 peerApp.Channel().Discover();         semaphore.acquire();         task.Stop();     }     else {         USER_DB_OPEN(userdb);         PassThroughAuthAppFactory factory(task);         while (true); // TBD: have a clean exit here         task.Stop();         USER_DB_CLOSE();     }  }  catch (PANA_Exception &e) {      std::cout << "PANA exception: " << e.description() << std::endl;  }  catch (...) {      std::cout << "Unknown exception ... aborting" << std::endl;  }  return 0;}

⌨️ 快捷键说明

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