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

📄 archie_test.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
      method(EapContinuedPolicyElement(EapType(ARCHIE_METHOD_TYPE)))  {    // Policy settings for the authenticator    eap->Policy().InitialPolicyElement(&method);    semaphore.acquire();  }  ~StandAloneAuthApplication() {}  void Start(Channel *c)  {     txChannel = c;    eap->Start();   }  StandAloneAuthChannel* RxChannel() { return &rxChannel; }  Channel& TxChannel() { return *txChannel; }  MyStandAloneAuthSwitchStateMachine& Eap() { return *eap; }  ACE_Semaphore& Semaphore() { return semaphore; } private:  EapJobHandle handle;  boost::shared_ptr<MyStandAloneAuthSwitchStateMachine> eap;  ACE_Semaphore &semaphore;  StandAloneAuthChannel rxChannel;  Channel *txChannel;  EapContinuedPolicyElement method;};// My application session (not used in this test program).class BackendAuthApplication : public AAA_JobData{ public:  BackendAuthApplication(EapTask &task, ACE_Semaphore &sem, bool pickup=false)    : handle(EapJobHandle	     (AAA_GroupedJob::Create(task.Job(), this, "backend"))),      eap(boost::shared_ptr<MyBackendAuthSwitchStateMachine>	  (new MyBackendAuthSwitchStateMachine(*task.reactor(), handle))),      semaphore(sem),      rxChannel(BackendAuthChannel(*eap)),      txChannel(0),      method(EapContinuedPolicyElement(EapType(ARCHIE_METHOD_TYPE)))  {    // Policy settings for the backend authenticator    eap->Policy().InitialPolicyElement(&method);    if (pickup)      {	eap->NeedInitialRequestToSend(false);      }    // Set shared secret.    unsigned char tmp[64];    RAND_bytes(tmp, sizeof tmp);    sharedSecret = std::string((char*)tmp, sizeof tmp);    semaphore.acquire();  }  ~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; }    ACE_Semaphore& Semaphore() { return semaphore; } private:  EapJobHandle handle;  boost::shared_ptr<MyBackendAuthSwitchStateMachine> eap;  ACE_Semaphore &semaphore;  BackendAuthChannel rxChannel;  Channel *txChannel;  EapContinuedPolicyElement method;  std::string sharedSecret;};// My application session (not used in this test program).class PassThroughAuthApplication : public AAA_JobData{ public:  PassThroughAuthApplication(EapTask &task, ACE_Semaphore &sem,			     bool pickup=false)    : handle(EapJobHandle	     (AAA_GroupedJob::Create(task.Job(), this, "passthrough"))),      eap(boost::shared_ptr<MyPassThroughAuthSwitchStateMachine>	  (new MyPassThroughAuthSwitchStateMachine(*task.reactor(), handle))),      semaphore(sem),      rxChannel(PassThroughAuthChannel(*eap)),      peerTxChannel(0),      backendTxChannel(0),      method(EapContinuedPolicyElement(EapType(1)))  {    if (pickup)      eap->Policy().InitialPolicyElement(&method);    semaphore.acquire();  }  ~PassThroughAuthApplication() {}  void Start(Channel *c1, Channel *c2)   {     peerTxChannel = c1;    backendTxChannel = c2;    eap->Start();   }  Channel* RxChannel() { return &rxChannel; }  Channel& PeerTxChannel() { return *peerTxChannel; }  Channel& BackendTxChannel() { return *backendTxChannel; }  MyPassThroughAuthSwitchStateMachine& Eap() { return *eap; }  ACE_Semaphore& Semaphore() { return semaphore; } private:  EapJobHandle handle;  boost::shared_ptr<MyPassThroughAuthSwitchStateMachine> eap;  ACE_Semaphore &semaphore;  PassThroughAuthChannel rxChannel;  Channel *peerTxChannel;  Channel *backendTxChannel;  EapContinuedPolicyElement method;};// ----------------- Definition --------------void MyPeerSwitchStateMachine::Send(AAAMessageBlock *b){  std::cout << "EAP Response sent from peer" << std::endl;  JobData(Type2Type<PeerApplication>()).TxChannel().Transmit(b);}void MyPeerSwitchStateMachine::Success()  {    std::cout << "Authentication success detected at peer" << std::endl;    std::cout << "Welcome to the world, " 	      << PeerIdentity() 	      << " !!!" << std::endl;    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;    Stop();    JobData(Type2Type<PeerApplication>()).Semaphore().release();  }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>()).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>()).Semaphore().release();  }std::string& MyPeerSwitchStateMachine::InputIdentity()   {    std::cout << "Input username (within 10sec.): " << std::endl;    std::cin >> identity;    std::cout << "username = " << identity << std::endl;    return identity;  }void MyStandAloneAuthSwitchStateMachine::Send(AAAMessageBlock *b)  {    std::cout << "EAP Request sent from authenticator" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).TxChannel().Transmit(b);  }void MyStandAloneAuthSwitchStateMachine::Success(AAAMessageBlock *b)  {    std::cout << "EAP Success sent from authenticator" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).TxChannel().Transmit(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;    Stop();  }void MyStandAloneAuthSwitchStateMachine::Success()  {    std::cout << "Success without an EAP Success" << std::endl;    Stop();  }void MyStandAloneAuthSwitchStateMachine::Failure(AAAMessageBlock *b)  {    std::cout << "EAP Failure sent from authenticator" << std::endl;    JobData(Type2Type<StandAloneAuthApplication>()).TxChannel().Transmit(b);    Stop();  }void MyStandAloneAuthSwitchStateMachine::Failure()  {    std::cout << "Failure without an EAP Failure" << std::endl;    Stop();  }void MyStandAloneAuthSwitchStateMachine::Abort()  {    std::cout << "Session aborted for an error in state machine" << std::endl;    Stop();    JobData(Type2Type<StandAloneAuthApplication>()).Semaphore().release();  }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());    Stop();  }void MyBackendAuthSwitchStateMachine::Success()  {    std::cout << "Success without an EAP Success" << std::endl;    Stop();  }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();    JobData(Type2Type<BackendAuthApplication>()).Semaphore().release();  }void MyPassThroughAuthSwitchStateMachine::Send(AAAMessageBlock *b)  {    std::cout << "EAP Request sent from passthrough authenticator" 	      << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).      PeerTxChannel().Transmit(b);  }void MyPassThroughAuthSwitchStateMachine::Success(AAAMessageBlock *b)  {    std::cout << "EAP Success sent from passthrough authenticator" 	      << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).      PeerTxChannel().Transmit(b);    Stop();  }void MyPassThroughAuthSwitchStateMachine::Success()  {    std::cout << "Success without an EAP Success" << std::endl;    Stop();  }void MyPassThroughAuthSwitchStateMachine::Failure(AAAMessageBlock *b)  {    std::cout << "EAP Failure sent from passthrough authenticator" 	      << std::endl;    JobData(Type2Type<PassThroughAuthApplication>()).      PeerTxChannel().Transmit(b);    Stop();  }void MyPassThroughAuthSwitchStateMachine::Failure()  {    std::cout << "Failure without an EAP Failure" << std::endl;    Stop();  }void MyPassThroughAuthSwitchStateMachine::Abort()  {    std::cout << "Session aborted for an error in state machine" << std::endl;    Stop();    JobData(Type2Type<PassThroughAuthApplication>()).Semaphore().release();  }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>()).      BackendTxChannel().Transmit(b);  }int main(int argc, char **argv){  // Initialize the log.#ifndef WIN32  EapLogMsg_S::instance()->open("EAP", ACE_Log_Msg::SYSLOG);#else  EapLogMsg_S::instance()->open("EAP", ACE_Log_Msg::STDERR);#endif  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<MyEapPeerArchieStateMachine>     myPeerArchieCreator;  EapMethodStateMachineCreator<MyEapAuthArchieStateMachine>     myAuthArchieCreator;  EapMethodRegistrar methodRegistrar;  methodRegistrar.registerMethod    (std::string("Archie"), EapType(ARCHIE_METHOD_TYPE),      Peer, myPeerArchieCreator);  methodRegistrar.registerMethod    (std::string("Archie"), EapType(ARCHIE_METHOD_TYPE),      Authenticator, myAuthArchieCreator);  int com; again:  // Input command.  std::cout << "1 - peer<->authenticator exchange" 	    << std::endl;  std::cout << "2 - peer<->passthrough authenticator<->backend authenticator"	    << std::endl;   std::cout << "    exchange (backend originates Request/Identity)" 	    << std::endl;  std::cout << "Input command (1-2) [type Ctrl-C to exit anytime] " 	    << std::endl;  std::cin >> com;  std::cout << "Input command: " << com << std::endl;  if (com!=1 && com!=2)    {      std::cout << "Invalid command" << std::endl;      goto again;    }    EapTask task;  try {    // Task starts with two threads in the thread pool.    task.Start(2);  }  catch (...) {    std::cout << "Task failed to start" << std::endl;    exit(1);  }  // Set shared secret.  unsigned char tmp[64];  RAND_bytes(tmp, sizeof tmp);  sharedSecret = std::string((char*)tmp, sizeof tmp);  ACE_Semaphore semaphore(4);  PeerApplication peerApp(task, semaphore);  StandAloneAuthApplication standAloneAuthApp(task, semaphore);  BackendAuthApplication backendAuthApp(task, semaphore);  PassThroughAuthApplication passThroughAuthApp(task, semaphore);  if (com==1)    {      peerApp.Start(standAloneAuthApp.RxChannel());      standAloneAuthApp.Start(peerApp.RxChannel());    }  else    {      peerApp.Start(passThroughAuthApp.RxChannel());      passThroughAuthApp.Start      	(peerApp.RxChannel(), backendAuthApp.RxChannel());      backendAuthApp.Start(passThroughAuthApp.RxChannel());    }  // Block until the EAP conversation completes.  semaphore.acquire();  task.Stop();  return 0;}

⌨️ 快捷键说明

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