コード例 #1
0
ファイル: sslcomm.c プロジェクト: superqqgto/pos2.0
static int ReadPemFile(uchar *pszAppFileName, uchar *psCA, uchar *psCert, uchar *psPrivatekey)
{
	int		fd, iRet, iTempLen;
	uchar	*ptr1, *ptr2 ;
	uchar ucBuf[MAX_PEM_ELN+1]; 
	uchar pos_ca_buf[2048];
	uchar pos_cer_buf[2048];
	uchar pos_privatekey_buf[2048];

	if (pszAppFileName == NULL)
	{
		return -1;
	}
	//打开文件
	fd = open(pszAppFileName, O_RDWR);
	if (fd < 0)
	{	
		return fd;
	}
	
	//读取文件
	memset(ucBuf, 0, sizeof(ucBuf));
	iRet = read(fd, ucBuf, MAX_PEM_ELN);
	if (iRet < 0)
	{
		ScrClrLine(6,9);
		ScrPrint(0, 6, 1, "READ FILE ERR:%d", iRet);
		PubWaitKey(30);
		close(fd);
		return iRet;	
	}	
	close(fd);

	//Get CERTIFICATE
	if ((ptr1 = strstr(ucBuf, "-----BEGIN CERTIFICATE-----")) && 
		(ptr2 = strstr(ucBuf, "-----END CERTIFICATE-----")) )
	{
		memset(pos_cer_buf, 0, sizeof(pos_cer_buf));
		iTempLen = strlen(ptr1) - strlen(ptr2) - strlen("-----BEGIN CERTIFICATE-----\n");
		memcpy(pos_cer_buf, ptr1+strlen("-----BEGIN CERTIFICATE-----\n"), iTempLen);
	}
	else
	{
		ScrClrLine(6,9);
		ScrPrint(0, 6, 1, "UNFOUND CERT");
		PubWaitKey(30);

		return -2;	
	}	

  	memset(pos_privatekey_buf, 0, sizeof(pos_privatekey_buf));
  	memset(pos_ca_buf, 0, sizeof(pos_ca_buf));

	//out data
	memcpy(psCA, pos_ca_buf, strlen(pos_ca_buf));
	memcpy(psCert, pos_cer_buf, strlen(pos_cer_buf));
	memcpy(psPrivatekey, pos_privatekey_buf, strlen(pos_privatekey_buf));

	return 0;
}
コード例 #2
0
ファイル: keyManage.c プロジェクト: x-lugoo/pos
//1.RSA 2,TMK 3,Active TMK
void KeyDownload(void)
{
    int iRet; 

    memcpy(&glCurAcq, &glSysParam.stAcqList[1], sizeof(ACQUIRER));  //set the default  Acq by richard 20170223

    iRet = RsaKeyDownload();
    if(iRet !=0)
    {
        ScrClrLine(2, 7);
        PubDispString(_T("RSA DOWN ERR"), 3 | DISP_LINE_CENTER);
        PubWaitKey(3);
        return;
    }

    iRet = TmkDownload();
    if(iRet !=0)
    {
        ScrClrLine(2, 7);
        PubDispString(_T("TMK DOWN ERR"), 3 | DISP_LINE_CENTER);
        PubWaitKey(3);
        return;
    }

    iRet = TmkActivation();
    if(iRet !=0)
    {
        ScrClrLine(2, 7);
        PubDispString(_T("TMK ACTIVE ERR"), 3 | DISP_LINE_CENTER);
        PubWaitKey(3);
    }
    else 
    {
        PubBeepOk();
        ScrClrLine(2, 7);
        PubDispString(_T("DOWNLOAD SUCCESS!"), 3 | DISP_LINE_CENTER);
        PubWaitKey(3);
    }

}
コード例 #3
0
ファイル: keyManage.c プロジェクト: x-lugoo/pos
void TerminalSignOn(void)
{
    int iRet; 
    ST_KEY_INFO KeyInfoIn = {0};
    ST_KCV_INFO KcvInfoIn = {0};

    memcpy(&glCurAcq, &glSysParam.stAcqList[1], sizeof(ACQUIRER));  //set the default  Acq by richard 20170223

    iRet = TransInit(LOGON);
    if( iRet!=0 )
    {
        return iRet;
    }

    SaveRevInfo(FALSE); //for test, TODO need to delete, 

    ScrCls();
    PubDispString(_T("TERM SIGNON"), 0 | DISP_LINE_LEFT | DISP_LINE_REVER);

    SetKeyCommfield(KEY_TYPE_TPK);

    //set field63
    memcpy(glSendPack.sField63, "\x00\x03", 2);
    memcpy(glSendPack.sField63+2, "000", 3);

    iRet = SendRecvPacket();
    if(iRet!=0)
    {
        return iRet;
    }

    if( memcmp(glProcInfo.stTranLog.szRspCode, "00", 2)!=0 )
    {
        return -1;
    }
    
    //TODO , deal with other response field data.

    //get the TPK and check value
    KeyInfoIn.iDstKeyLen  = 16;
    KcvInfoIn.aucCheckBuf[0] = 0x04;
    memcpy(KeyInfoIn.aucDstKeyValue, glRecvPack.sField62+2, 16);
    memcpy(KcvInfoIn.aucCheckBuf+1, glRecvPack.sField62+18, 4);

    KeyInfoIn.ucSrcKeyType = PED_TMK;
    KeyInfoIn.ucSrcKeyIdx  = CUP_TMK_ID;
    KeyInfoIn.ucDstKeyType = PED_TPK;
    KeyInfoIn.ucDstKeyIdx  = CUP_TPK_ID;
    KcvInfoIn.iCheckMode = 0x01;

    iRet = PedWriteKey(&KeyInfoIn, &KcvInfoIn);
    if(iRet != 0)
    {
        ScrClrLine(2, 7);
        PubDispString(_T("SignOn Failed!"), 3 | DISP_LINE_CENTER);
        PubWaitKey(3);
    }
    else 
    {
        PubBeepOk();
        ScrClrLine(2, 7);
        PubDispString(_T("SignOn SUCCESS!"), 3 | DISP_LINE_CENTER);
        PubWaitKey(3);
    }
    
}