Ejemplo n.º 1
0
// 认证
void CClientAuth::Auth(CClient *cl, Msg *pMsg)
{
	if (!cl || !pMsg)
		return;
	
	netData::Auth msg;
	_CHECK_PARSE_(pMsg, msg);

	const std::string secret = GetSecret(cl->GetClientID());
	if (!secret.empty())
	{
		msg.set_secret(secret);
		LoginCenterConnect.SendMsgToServer(Config.GetCenterServerID(), msg, LOGIN_TYPE_MAIN, LOGIN_SUB_AUTH, cl->GetClientID());
		// 这边发消息之后,Center那边就会有玩家账号的记录
		// 需要确保玩家在这个操作之后的所有情况都能正确通知移除保存的记录
		LoginClientMgr.SetClientAuthSucceed(cl->GetClientID());
	}
	else
	{
		RunStateError("Auth失败!没有握手!clientid:%d,account:%s", cl->GetClientID(), msg.account().c_str());
		netData::AuthRet sendMsg;
		sendMsg.set_ncode(netData::AuthRet::EC_HANDSHAKE);
		LoginClientMgr.SendMsg(cl, sendMsg, LOGIN_TYPE_MAIN, LOGIN_SUB_AUTH_RET);
	}
}
Ejemplo n.º 2
0
void init(){

#if 0
	//デバッグ用最終的にはここを消すこと!
	init_key = GetKey();
	init_secret = GetSecret();
#else
	init_key = "";
	init_secret = "";
	std::string retnum = "";

	TCHAR buf[MAX_PATH*1024] = "";
	std::string LineReadText = "\0";
	HANDLE hkey = CreateFile( _T("option.ini"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
	if( hkey != INVALID_HANDLE_VALUE ){  //本当に開くことができたか
		DWORD readsize;
		ReadFile( hkey,buf, sizeof(buf), &readsize, NULL );
		buf[readsize] = TEXT('\0');	//末尾に'\0'が無いので付加
		CloseHandle( hkey );
		int LineNum=0;
		for(int i=0;buf[i]>0&&LineNum<=4;i++){
			if(buf[i]=='\r'||buf[i]=='\n'){}
			else if(1 == LineNum){ retnum += buf[i]; }
			else if(3 == LineNum){ init_key += buf[i]; }
			else if(4 == LineNum){ init_secret += buf[i]; }
			if(buf[i]=='\n'){ LineNum++; }
		}
		ReturnNum = atoi(retnum.c_str());
	}
#endif
}
Ejemplo n.º 3
0
bool CKey::IsValid()
{
    if (!fSet)
        return false;

    bool fCompr;
    CSecret secret = GetSecret(fCompr);
    CKey key2;
    key2.SetSecret(secret, fCompr);
    return GetPubKey() == key2.GetPubKey();
}
Ejemplo n.º 4
0
// 挑战
void CClientAuth::Challenge(CClient *cl, Msg *pMsg)
{
	if (!cl || !pMsg)
		return;

	netData::Challenge msg;
	_CHECK_PARSE_(pMsg, msg);

	netData::ChallengeRet sendMsg;
	if (msg.shmac() == GetSecret(cl->GetClientID()))
		sendMsg.set_ncode(netData::ChallengeRet::EC_SUCC);
	else
		sendMsg.set_ncode(netData::ChallengeRet::EC_FAIL);

	LoginClientMgr.SendMsg(cl, sendMsg, LOGIN_TYPE_MAIN, LOGIN_SUB_CHALLENGE_RET);
}
int CGXDLMSAssociationLogicalName::GetValue(int index, unsigned char* parameters, int length, CGXDLMSVariant& value)
{
	if (index == 1)
	{
		GXHelpers::AddRange(value.byteArr, m_LN, 6);
		value.vt = DLMS_DATA_TYPE_OCTET_STRING;
		return ERROR_CODES_OK;
	}
    if (index == 2)
    {			
		vector<unsigned char> Packets;
		int ret = GetObjects(Packets);
		value = Packets;
		return ret;            
    }
    if (index == 3)
    {         
        value = GetAssociatedPartnersId();
		return ERROR_CODES_OK;
    }
    if (index == 4)
    {         
        value = GetApplicationContextName();
		return ERROR_CODES_OK;
    }
    if (index == 5)
    {            
        value = GetXDLMSContextInfo();
		return ERROR_CODES_OK;
    }
    if (index == 6)
    {         
        value = GetAuthenticationMechanismMame();
		return ERROR_CODES_OK;
    }
    if (index == 7)
    {         
        value = GetSecret();
		return ERROR_CODES_OK;
    }        
	if (index == 8)
	{		
		value = (unsigned char)m_AssociationStatus;
		return ERROR_CODES_OK;
	}
	return ERROR_CODES_INVALID_PARAMETER;
}
Ejemplo n.º 6
0
int main(int argc, char** argv)
{
   int i = 0;
   SHACopr copr;
   SHAUser user;
   FileEntry fe = {"COPR",0};
   uchar *authSecret;
   int authlen;
   char test[2] = {'y',0};
   long balance;

   copr.portnum = 0;
   user.portnum = 0;

   puts("\nStarting SHA initrov Application\n");

   // check for required port name
   if (argc != 2)
   {
      printf("1-Wire Net name required on command line!\n"
             " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" "
             "(Linux DS2480),\"{1,5}\" (Win32 TMEX)\n");
      exit(1);
   }

   if((user.portnum = copr.portnum = owAcquireEx(argv[1])) < 0)
   {
      printf("Failed to acquire port.\n");
      exit(2);
   }

#ifdef COPRVM
   if(!GetCoprVM(&copr, &fe))
      exit(1);
#else
   puts("\nPlease place coprocessor token on the 1-Wire bus.\n");

   while(!FindCoprSHA(&copr, &fe))
   {
      if(owHasErrors())
         msDelay(10);
   }

   printf("Found device: ");
   PrintSerialNum(copr.devAN);
   puts("\n");
#endif

   authlen = GetSecret("System Authentication Secret", &authSecret);

   EnterString("Reformat the secret for DS1961S compatibility", test, 1, 1);
   if(test[0] == 'y')
   {
      ReformatSecretFor1961S(authSecret, authlen);
      PrintHex(authSecret, authlen);
      printf("\n");
      copr.ds1961Scompatible = 0x55;
   }

   puts("\nPlease place user token on the 1-Wire bus.\n");
   do
   {
      while(!FindNewSHA(user.portnum, user.devAN, (i==0)))
      {
         if(owHasErrors())
         {  
            OWERROR_DUMP(stdout);
            msDelay(10);
         }
      }
      i++;
   }
   while(user.devAN[7]==copr.devAN[7]);
   // just check the crc of the two devices

   balance = 100;
   EnterNum("\nInitial Balance in Cents?\n", 5, &balance, 0, 0xFFFFF);

   printf("Installing Service Data on device: ");
   PrintSerialNum(user.devAN);
   puts("\n");
   if(InstallServiceData(&copr, &user, authSecret, authlen, (int)balance))
   {
      puts("User token successfully set up");
   }
   else
   {
      puts("User token setup failed");
      OWERROR_DUMP(stdout);
   }

   // and we're done
   owRelease(copr.portnum);

   // program is about to exit, but we may as well free these
   // up anyways...
   free(authSecret);

   return 0;
}