当前位置: 首页>>代码示例>>C++>>正文


C++ Ticket::serializeAndEncrypt方法代码示例

本文整理汇总了C++中Ticket::serializeAndEncrypt方法的典型用法代码示例。如果您正苦于以下问题:C++ Ticket::serializeAndEncrypt方法的具体用法?C++ Ticket::serializeAndEncrypt怎么用?C++ Ticket::serializeAndEncrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ticket的用法示例。


在下文中一共展示了Ticket::serializeAndEncrypt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: handleKerberosLogin

void UserProcessingCenter::handleKerberosLogin(CMazeMsg* context)
{
    //cout<<":: kerberos login:: "<<endl;
    debug("kerberos login request");
	char *pbuf = context->getMsg();
	int rt = context->getLen();
	MBlockSocket *pclient = context->getSocket();
	UserDatabase *userdb = UserDatabase::getInstance();

	KMsgHead kmsghead;
	if(kmsghead.unserialize(pbuf,rt)!=-1)
	{
		switch(kmsghead.msgtype)
		{
			case USER_LOGIN_REQUEST:
			{
				//cout<<"::kerberos login::"<<endl;
				UserLoginRequest  req;
				if(req.unserialize(pbuf,rt)!=-1)
				{
					USERDB	*userinfo = new USERDB;

					//debug("recv req from user %d to  @time %d"<<req.uid<<"  "<<req.ts);

					bool logfind=false;

					if(req.uid!=0)
					{
                    	debug("recv req from user id to  @time--->"<<req.uid<<"  "<<req.ts);

						logfind=(userdb->get_record( req.uid,userinfo) == 0);
						debug("find user %d 's user info"<<req.uid);
					}
					else
					{
	                    debug("recv req from user email to  @time---->"<<req.emailAddr<<"  "<<req.ts);

						string emailAddr=req.emailAddr;
						string badEmail = string("[email protected]");
						if(emailAddr == badEmail)
						{
							cout<<"--------bad email--------"<<endl;
							logfind = false;
							
						}
						else
						{
							logfind=(userdb->get_record(emailAddr,userinfo) == 0);
							debug("find user %s 's user info"<<emailAddr.c_str());
						}
					}


					if(logfind)
					{
						//generate ticket and send it back to User here...
						UserLoginReply reply;
						strncpy(reply.userInfo.NickName,userinfo->NickName,24);
						strncpy(reply.userInfo.MailAddr,userinfo->MailAddr,128);
						reply.userInfo.UID=userinfo->UID;
						reply.userInfo.IP=pclient->GetPeerName().GetIP();	//TODO
						reply.userInfo.ServerPort=pclient->GetPeerName().GetPort();	//TODO
						reply.userInfo.Account=userinfo->Account;
						reply.userInfo.Level=userinfo->Level;
						reply.userInfo.LastAccountAddTime=(unsigned)userinfo->LastAddAccount;

						//get user password(key) from user database;
						string userKey=userinfo->Pwd;
						//get tgs key from config or database.
						string tgsKey ="tgskey";
						//generate a random string to be the session key shared by user and tgs.
						string sessionKey=GenRandomKey();

						unsigned ts=(unsigned)time(NULL);//the time-stamp of the ticket release.

						reply.ts   =ts;
						reply.life =TGS_TICKET_LIFE;//the life of the ticket below
						reply.privilege=0;//TODO privilege of user..
						reply.head.src=0;
						reply.head.dst=req.uid;
						reply.head.status=0;

						reply.sessionKey.set(sessionKey.c_str(),sessionKey.length());

						Ticket ticket;
						ticket.uid=req.uid;
						ticket.uaddr=0;	//TODO
						ticket.ts=ts;
						ticket.life=TGS_TICKET_LIFE;
						ticket.privilege=0;//TODO; 
						ticket.sessionKey.set(sessionKey.c_str(),sessionKey.length());

						reply.cipheredTicket=ticket.serializeAndEncrypt(tgsKey.c_str(),tgsKey.length());
						RawData result=reply.serializeAndEncrypt(userKey.c_str(),userKey.length());

						debug("AS:\tGrant ticket and session key {%s} to user %d\n"<<sessionKey.c_str()<<req.uid);
						unsigned int ip = pclient->GetPeerName().GetIP();
						string ip_str=pclient->GetPeerName().ip();
						pclient->SendPacket(result.data,result.len);

//.........这里部分代码省略.........
开发者ID:IthacaDream,项目名称:Test,代码行数:101,代码来源:UserProcessingCenter.cpp


注:本文中的Ticket::serializeAndEncrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。