📄 md5_test.cxx
字号:
md5Method(EapContinuedPolicyElement(EapType(4))), notificationMethod(EapContinuedPolicyElement(EapType(2))) { // Policy settings for the authenticator identityMethod.AddContinuedPolicyElement (&md5Method, EapContinuedPolicyElement::PolicyOnSuccess); identityMethod.AddContinuedPolicyElement (¬ificationMethod, EapContinuedPolicyElement::PolicyOnFailure); eap->Policy().InitialPolicyElement(&identityMethod); semaphore.acquire(); } ~StandAloneAuthApplication() {} void Start(Channel *c) { txChannel = c; eap->Start(); } StandAloneAuthChannel* RxChannel() { return &rxChannel; } Channel& TxChannel() { return *txChannel; } // MyEapStandAloneAuthSession& Eap() { return eap; } 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 identityMethod; EapContinuedPolicyElement md5Method; EapContinuedPolicyElement notificationMethod;};// 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), identityMethod(EapContinuedPolicyElement(EapType(1))), md5Method(EapContinuedPolicyElement(EapType(4))), notificationMethod(EapContinuedPolicyElement(EapType(2))) { // Policy settings for the backend authenticator identityMethod.AddContinuedPolicyElement (¬ificationMethod, EapContinuedPolicyElement::PolicyOnFailure); identityMethod.AddContinuedPolicyElement (&md5Method, EapContinuedPolicyElement::PolicyOnSuccess); eap->Policy().InitialPolicyElement(&identityMethod); if (pickup) { eap->NeedInitialRequestToSend(false); } 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 identityMethod; EapContinuedPolicyElement md5Method; EapContinuedPolicyElement notificationMethod;};// 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), identityMethod(EapContinuedPolicyElement(EapType(1))) { if (pickup) eap->Policy().InitialPolicyElement(&identityMethod); 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 identityMethod;};// ----------------- 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; 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() { identity = std::string("ohba");#if 0 std::cout << "Input username (within 10sec.): " << std::endl; std::cin >> identity; std::cout << "username = " << identity << std::endl;#endif 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); Stop(); JobData(Type2Type<StandAloneAuthApplication>()).Semaphore().release(); }void MyStandAloneAuthSwitchStateMachine::Success() { std::cout << "Success without an EAP Success" << std::endl; Stop(); JobData(Type2Type<StandAloneAuthApplication>()).Semaphore().release(); }void MyStandAloneAuthSwitchStateMachine::Failure(AAAMessageBlock *b) { std::cout << "EAP Failure sent from authenticator" << std::endl; JobData(Type2Type<StandAloneAuthApplication>()).TxChannel().Transmit(b); Stop(); JobData(Type2Type<StandAloneAuthApplication>()).Semaphore().release(); }void MyStandAloneAuthSwitchStateMachine::Failure() { std::cout << "Failure without an EAP Failure" << std::endl; Stop(); JobData(Type2Type<StandAloneAuthApplication>()).Semaphore().release(); }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) { std::cout << "EAP Success sent from authenticator" << std::endl; JobData(Type2Type<BackendAuthApplication>()).TxChannel().Transmit(b, 2); Stop(); JobData(Type2Type<BackendAuthApplication>()).Semaphore().release(); }void MyBackendAuthSwitchStateMachine::Success() { std::cout << "Success without an EAP Success" << std::endl; Stop(); JobData(Type2Type<BackendAuthApplication>()).Semaphore().release(); }void MyBackendAuthSwitchStateMachine::Failure(AAAMessageBlock *b) { std::cout << "EAP Failure sent from authenticator" << std::endl; JobData(Type2Type<BackendAuthApplication>()).TxChannel().Transmit(b, 3); Stop(); JobData(Type2Type<BackendAuthApplication>()).Semaphore().release(); }void MyBackendAuthSwitchStateMachine::Failure() { std::cout << "Failure without an EAP Failure" << std::endl; Stop(); JobData(Type2Type<BackendAuthApplication>()).Semaphore().release(); }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(); JobData(Type2Type<PassThroughAuthApplication>()).Semaphore().release(); }void MyPassThroughAuthSwitchStateMachine::Success() { std::cout << "Success without an EAP Success" << std::endl; Stop(); JobData(Type2Type<PassThroughAuthApplication>()).Semaphore().release(); }void MyPassThroughAuthSwitchStateMachine::Failure(AAAMessageBlock *b) { std::cout << "EAP Failure sent from passthrough authenticator" << std::endl; JobData(Type2Type<PassThroughAuthApplication>()). PeerTxChannel().Transmit(b); Stop(); JobData(Type2Type<PassThroughAuthApplication>()).Semaphore().release(); }void MyPassThroughAuthSwitchStateMachine::Failure() { std::cout << "Failure without an EAP Failure" << std::endl; Stop(); JobData(Type2Type<PassThroughAuthApplication>()).Semaphore().release(); }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.#ifdef WIN32 EapLogMsg_S::instance()->open("EAP", ACE_Log_Msg::STDERR);#else EapLogMsg_S::instance()->open("EAP", ACE_Log_Msg::SYSLOG);#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<MyEapAuthIdentityStateMachine> myAuthIdentityCreator; EapMethodStateMachineCreator<MyEapPeerMD5ChallengeStateMachine> myPeerMD5ChallengeCreator; EapMethodStateMachineCreator<MyEapAuthMD5ChallengeStateMachine> myAuthMD5ChallengeCreator; EapMethodRegistrar methodRegistrar; methodRegistrar.registerMethod (std::string("Identity"), EapType(1), Authenticator, myAuthIdentityCreator); methodRegistrar.registerMethod (std::string("MD5-Challenge"), EapType(4), Peer, myPeerMD5ChallengeCreator); methodRegistrar.registerMethod (std::string("MD5-Challenge"), EapType(4), Authenticator, myAuthMD5ChallengeCreator); 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 << "3 - peer<->passthrough authenticator<->backend authenticator" << std::endl; std::cout << " exchange (passthrough originates Request/Identity)" << std::endl; std::cout << "Input command (1-3) [type Ctrl-C to exit anytime] " << std::endl; std::cin >> com; std::cout << "Input command: " << com << std::endl; if (com<1 || com>3) { std::cout << "Invalid command" << std::endl; goto again; } bool pickup = ((com==3) ? true : false); EapTask task; task.Start(2);#if WIN32 #define num 100#else int num = 100;#endif ACE_Semaphore semaphore(4*num); std::auto_ptr<PeerApplication> peerApp[num]; std::auto_ptr<StandAloneAuthApplication> standAloneAuthApp[num]; std::auto_ptr<BackendAuthApplication> backendAuthApp[num]; std::auto_ptr<PassThroughAuthApplication> passThroughAuthApp[num]; for (int i=0; i<num; i++) { peerApp[i] = std::auto_ptr<PeerApplication> (new PeerApplication(task, semaphore)); standAloneAuthApp[i] = std::auto_ptr<StandAloneAuthApplication> (new StandAloneAuthApplication(task, semaphore)); backendAuthApp[i] = std::auto_ptr<BackendAuthApplication> (new BackendAuthApplication(task, semaphore, pickup)); passThroughAuthApp[i] = std::auto_ptr<PassThroughAuthApplication> (new PassThroughAuthApplication (task, semaphore, pickup)); if (com==1) { peerApp[i]->Start(standAloneAuthApp[i]->RxChannel()); standAloneAuthApp[i]->Start(peerApp[i]->RxChannel()); } else { peerApp[i]->Start(passThroughAuthApp[i]->RxChannel()); // Starting order of passthrough and backend authenticators are // important. if (com==2) { backendAuthApp[i]->Start(passThroughAuthApp[i]->RxChannel()); passThroughAuthApp[i]->Start (peerApp[i]->RxChannel(), backendAuthApp[i]->RxChannel()); } else { passThroughAuthApp[i]->Start (peerApp[i]->RxChannel(), backendAuthApp[i]->RxChannel()); backendAuthApp[i]->Start(passThroughAuthApp[i]->RxChannel()); } } } // Block until the EAP conversation completes. if (com==1) for (int i=0; i<2*num; i++) semaphore.acquire(); else for (int i=0; i<3*num; i++) semaphore.acquire(); task.Stop(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -