bool PPatchServer::ProcessClient(PClient *Client, PPatchState *State) { static const u8 HANDSHAKE0A[6]={0xfe, 0x03, 0x00, 0x80, 0x03, 0x6b}; if(!State) { PatchStateMap::iterator node = ClientStates.find(Client); if(node == ClientStates.end()) return false; State = node->second; } ConnectionTCP *Socket = Client->getTCPConn(); if(State->mWaitSend && Socket->getSendBufferSize()==0) return false; if(State->mState==PPatchState::PS_CONNECTED) { Console->Print("Sending Handshake 0A"); Socket->write(HANDSHAKE0A, sizeof(HANDSHAKE0A)); //short unsigned int packet = (short unsigned int) HANDSHAKE0A; //Socket->write(htons(packet)); State->mState = PPatchState::PS_HANDSHAKE0; Socket->flushSendBuffer(); } int PacketSize=0; const u8 *Packet = Socket->read(&PacketSize); if(PacketSize > 0) { switch(State->mState) { case PPatchState::PS_HANDSHAKE1 : case PPatchState::PS_HANDSHAKE0 : Console->Print("Handling Handshake 0 and 1"); return HandleHandshake(Client, State, Packet, PacketSize); case PPatchState::PS_VERSIONREQUEST : Console->Print("Handling Client Versionsrequest"); return HandleVersionRequest(Client, State, Packet, PacketSize); case PPatchState::PS_GETPATCHORFILE : case PPatchState::PS_SENDPATCH : case PPatchState::PS_SENDFILE : Console->Print("Getpatchforfile, sendpatch, sendfile"); return HandleFileRequests(Client, State, Packet, PacketSize); default: break; } } return true; }
DWORD DispatchFunctions(po::variables_map argsMap,po::options_description& config) { DWORD dwError = ERROR_SUCCESS; if (argsMap.count("version")) { dwError = HandleVersionRequest(); BAIL_ON_ERROR(dwError); } if (argsMap.count("gencert")) { if(!argsMap.count("privkey") || !argsMap.count("cert") || !argsMap.count("config") ) { std::cout << "Error : To generate a certificate we need access to a private key." << "Example : certool --gencert --privkey=<filename> --cert=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } if ( ParserConfigFile(config, argConfig) != 0 ) { std::cout << "Unable to read the config file"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleGenCert(); BAIL_ON_ERROR(dwError); } if (argsMap.count("genkey")) { if(!argsMap.count("privkey") || !argsMap.count("pubkey")) { std::cout << "Error : To generate a key pair we need public and private key files names to write to." << "Example : certool --genkey --privkey=<filename> --pubkey=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleGenKey(); BAIL_ON_ERROR(dwError); } if(argsMap.count("revokecert")) { if(!argsMap.count("cert")) { std::cout << "Error : To revoke a cert, you need a path to the certificate" << "Example : certool --revokecert --cert=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleRevokeCert(); BAIL_ON_ERROR(dwError); } if(argsMap.count("viewcert")) { if(!argsMap.count("cert")) { std::cout << "Error : To view a cert, you need a path to the certificate" << "Example : certool --viewcert --cert=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleViewCert(); BAIL_ON_ERROR(dwError); } if(argsMap.count("getrootca")) { dwError = HandleGetRootCA(); BAIL_ON_ERROR(dwError); } if(argsMap.count("enumcert")) { if(!argsMap.count("filter")) { std::cout << "Error : To enum certs, you need to specify certificate status" << "Example: certool --enumcert --filter=revoked\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleEnumCerts(); BAIL_ON_ERROR(dwError); } if (argsMap.count("genCIScert")) { if(!argsMap.count("privkey") || !argsMap.count("cert") || !argsMap.count("config") ) { std::cout << "Error : To generate a certificate we need access to a private key." << "Example : certool --genCIScert --privkey=<filename> --cert=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleGenCISCert(); BAIL_ON_ERROR(dwError); } if(argsMap.count("status")) { if(!argsMap.count("cert")) { std::cout << "Error : To check the status of a cert, you need a path to the certificate" << "Example : certool --status --cert=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleStatusCert(); BAIL_ON_ERROR(dwError); } if(argsMap.count("vxls")){ if (!argsMap.count("prv") || !argsMap.count("trs") || !argsMap.count("rvk") || !argsMap.count("all")){ std::cout << "No Store Argument found, Enumerating Private Store:\n"; argStorePrivate = true; } dwError = HandleVecsEnum(); BAIL_ON_ERROR(dwError); } if ( argsMap.count("getcrl")){ if(!argsMap.count("crl")) { std::cout << "Error : to download a CRL file, you need a path to the CRL file" << "Example : certool --getcrl --crl=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleGetCRL(); BAIL_ON_ERROR(dwError); } if ( argsMap.count("gencrl")){ dwError = HandleGenCRL(); BAIL_ON_ERROR(dwError); } if(argsMap.count("crlinfo")){ if(!argsMap.count("crl")) { std::cout << "Error : CRL file Path is missing" << "Example : certool --crlinfo --crl=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleCRLInfo(); BAIL_ON_ERROR(dwError); } if(argsMap.count("viewcrl")) { if(!argsMap.count("crl")) { std::cout << "Error : CRL file Path is missing" << "Example : certool --viewcrl --crl=<filename> \n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandlePrintCRL(); BAIL_ON_ERROR(dwError); } if (argsMap.count("genselfcacert")) { if(!argsMap.count("outprivkey")) { std::cout << "Error : No private key file specified.\n" << "Example : certool --genselfcacert --outprivkey=<filename> --outcert=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } else if(!argsMap.count("outcert")) { std::cout << "Error : No certficate file specified.\n" << "Example : certool --genselfcacert --outprivkey=<filename> --outcert=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } else if(!argsMap.count("config")) { std::cout << "Error : No configuration file specified.\n" << "Example : certool --genselfcacert --outprivkey=<filename> --outcert=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } if ( ParserConfigFile(config, argConfig) != 0 ) { std::cout << "Unable to read the config file"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleGenSelfCert(); BAIL_ON_ERROR(dwError); } if (argsMap.count("gencsrfromcert")) { if(!argsMap.count("privkey")) { std::cout << "Error : No private key file specified.\n" << "Example : certool --gencsrfromcert --privkey=<filename> --cert=<filename> --csrfile=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } else if(!argsMap.count("csrfile")) { std::cout << "Error : No output csr file specified.\n" << "Example : certool --gencsrfromcert --privkey=<filename> --cert=<filename> --csrfile=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } else if(!argsMap.count("cert")) { std::cout << "Error : No certficate file specified.\n" << "Example : certool --gencsrfromcert --privkey=<filename> --cert=<filename> --csrfile=<filename>\n"; dwError = VMCA_ARGUMENT_ERROR; BAIL_ON_ERROR(dwError); } dwError = HandleGenCSRFromCert(); BAIL_ON_ERROR(dwError); } //if(argsMap.count("viewerror")){ // dwError = HandlePrintError(); // BAIL_ON_ERROR(dwError); //} error : return dwError; }