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

📄 server_test_tls.cxx

📁 Diameter协议栈
💻 CXX
📖 第 1 页 / 共 2 页
字号:
    identityMethod.AddContinuedPolicyElement	(&methodTls, EapContinuedPolicyElement::PolicyOnSuccess);         eap->Policy().InitialPolicyElement(&identityMethod);    eap->NeedInitialRequestToSend(false);    this->Start();  }  void Start() throw(AAA_Error)  {     DiameterEapServerSession::Start();   }  /// This virtual function is called when an EAP server session is  /// aborted due to enqueue failure of a job or an event inside  /// Diametger EAP server state machine.  void Abort()  {    std::cout << "Diameter EAP server session aborted." << std::endl;    DiameterEapServerSession::Stop();    Eap().Stop();  }  MyBackendAuthSwitchStateMachine& Eap() { return *eap; }  /// This virtual function is called when an EAP-Response message is  /// passed to the EAP backend authenticator.  void ForwardEapResponse(std::string &eapMsg);  // Modified by Santiago Zapata Hernandez for UMU// New    /// Authorization function called from Authorize() function.    bool AuthorizeEapMasterSessionKey	(AAA_ScholarAttribute<diameter_octetstring_t> &eapMasterSessionKey)    {	std::cout << "Setting master session key" << std::endl;	if (userNameValidate)	{	    eapMasterSessionKey.Set (((MyEapAuthTlsStateMachine &) (eap->MethodStateMachine ())).MSK ());	}	return true;    }// End New  bool ValidateUserName(const diameter_utf8string_t &userName)  {// Modified by Santiago Zapata Hernandez for UMU// Old#if 0    if (userName == "ohba")      return true;    else      return false;#endif// New    userNameValidate = (userName == "ohba");    return userNameValidate;// End New  } private:  EapJobHandle handle;  boost::shared_ptr<MyBackendAuthSwitchStateMachine> eap;  EapContinuedPolicyElement identityMethod;  EapContinuedPolicyElement methodTls;  bool initial;// Modified by Santiago Zapata Hernandez for UMU// New    bool userNameValidate;// End New};// ----------------- Definition --------------void MyBackendAuthSwitchStateMachine::Send(AAAMessageBlock *b)  {    std::cout << "EAP Request sent from backend authenticator" 	      << std::endl;    std::string eapMsg(b->base(), b->length());    JobData(Type2Type<MyDiameterEapServerSession>()).SignalContinue(eapMsg);  }void MyBackendAuthSwitchStateMachine::Success(AAAMessageBlock *b)  {    std::cout << "EAP Success sent from backend authenticator" 	      << std::endl;    std::string eapMsg(b->base(), b->length());    JobData(Type2Type<MyDiameterEapServerSession>()).SignalSuccess(eapMsg);// Modified by Santiago Zapata Hernandez for UMU// New    EAPTLS_session_t_auth * session_auth = ((MyEapAuthTlsStateMachine &) MethodStateMachine ()).get_tls_session ();    AAAMessageBlock * skey_auth = EAPTLSCrypto_callbacks::eaptls_gen_mppe_keys (session_auth->get_master_key (),										session_auth->get_client_random (),										session_auth->get_server_random ());    EAP_LOG (LM_DEBUG, "Auth TLS session key\n");    print_cadena ((ACE_Byte *) skey_auth->base (), skey_auth->length ());// End New    Stop();  }void MyBackendAuthSwitchStateMachine::Success()  {    std::cout << "Success without an EAP Success" << std::endl;    std::string eapMsg("");    JobData(Type2Type<MyDiameterEapServerSession>()).SignalSuccess(eapMsg);    Stop();  }void MyBackendAuthSwitchStateMachine::Failure(AAAMessageBlock *b)  {    std::cout << "EAP Failure sent from backend authenticator" 	      << std::endl;    std::string eapMsg(b->base(), b->length());    JobData(Type2Type<MyDiameterEapServerSession>()).SignalFailure(eapMsg);    Stop();  }void MyBackendAuthSwitchStateMachine::Failure()  {    std::cout << "Failure without an EAP Failure" << std::endl;    std::string eapMsg("");    JobData(Type2Type<MyDiameterEapServerSession>()).SignalFailure(eapMsg);    Stop();  }void MyBackendAuthSwitchStateMachine::Abort()  {    std::cout << "Session aborted for an error in state machine" << std::endl;    Stop();  }void MyDiameterEapServerSession::ForwardEapResponse(std::string &eapMsg){  std::cout << "EAP Response forwarded to backend authenticator" 	    << std::endl;  AAAMessageBlock *msg;  if (eapMsg.length() > 0)    {      msg = AAAMessageBlock::Acquire((ACE_UINT32)eapMsg.length());      msg->copy((char*)eapMsg.data(), eapMsg.length());      if (initial)	{	  initial=false;	  Eap().Start(msg);    // The initial EAP-Response message.	}      else	{	  Eap().Receive(msg);	}      msg->release();    }}typedef AAAServerSessionClassFactory<MyDiameterEapServerSession> MyServerFactory;class MyInitializer{ public:  MyInitializer(AAA_Task &t, AAAApplicationCore &appCore)     : task(t), applicationCore(appCore),       myAuthFactory(MyServerFactory(2000, AAA_STYPE_AUTHENTICATION))  {    Start();  }  ~MyInitializer()   {    Stop();  } private:  void Start()  {    InitTask();    InitApplicationCore();    InitEap();    applicationCore.RegisterServerSessionFactory(&myAuthFactory);  }  void Stop() {}  void InitTask()  {     try {        task.Start(10);     }     catch (...) {        ACE_ERROR((LM_ERROR, "(%P|%t) Server: Cannot start task\n"));        exit(1);     }  }  void InitApplicationCore()  {    ACE_DEBUG((LM_DEBUG, "[%N] Application starting\n"));    if (applicationCore.Open("config/server.local.xml",                             task) != AAA_ERR_SUCCESS)      {	ACE_ERROR((LM_ERROR, "[%N] Can't open configuraiton file."));	exit(1);      }  }  void InitEap()  {    ACE_DEBUG((LM_DEBUG, "[%N] EAP initialization.\n"));    methodRegistrar.registerMethod      (std::string("Identity"), EapType(1),        Authenticator, myAuthIdentityCreator);  methodRegistrar.registerMethod    (std::string("TLS"), EapType(TLS_METHOD_TYPE),      Authenticator, myAuthTlsCreator);  }  AAA_Task &task;  AAAApplicationCore &applicationCore;  EapMethodRegistrar methodRegistrar;  EapMethodStateMachineCreator<MyEapAuthTlsStateMachine>   myAuthTlsCreator;  EapMethodStateMachineCreator<MyEapAuthIdentityStateMachine>   myAuthIdentityCreator;  MyServerFactory myAuthFactory;};intmain(int argc, char *argv[]){  AAA_Task task;  AAAApplicationCore applicationCore;  MyInitializer initializer(task, applicationCore);  while (1)       ACE_OS::sleep(1);  return 0;}

⌨️ 快捷键说明

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