int 
getUserData(UserData *data)
{
	long ret;
    PTEID_ID pteid_id;

	ret = PTEID_Init ( 0 );
	if (ret != PTEID_OK) {
		pteiderror ( "PTEID_Init", ret );
	}
	
	ret = PTEID_SetSODChecking(0);
	if (ret != PTEID_OK) {
		pteiderror ( "PTEID_SetSODChecking", ret );
	return 0;
	}

	ret = PTEID_GetID ( &pteid_id );
	if (ret != PTEID_OK) {
		pteiderror ( "PTEID_GetID", ret );
	}
	
	ret = PTEID_Exit ( 0 );
	if (ret != PTEID_OK) {
		pteiderror ( "PTEID_Exit", ret );
	}
	
	strncpy(data->name, pteid_id.name, PTEID_MAX_NAME_LEN);
	data->name[PTEID_MAX_NAME_LEN -1] = '\0';
	strncpy(data->numBI, pteid_id.numBI, PTEID_MAX_NUMBI_LEN);
	data->numBI[PTEID_MAX_NUMBI_LEN -1] = '\0';

	return 0;
}
Beispiel #2
0
int test_Basic(const char *name, void (*test_fct)(FILE *f, int Ocsp, int Crl), void (*test_virtual)(FILE *f, int Ocsp, int Crl), const char *folder, const char *reader, int bVerify, int Ocsp, int Crl)
{

	PTEID_Status tStatus = {0};
	long lHandle = 0;
	long lRet = 0;
	FILE *f=NULL;
	
	int i = 0;
	int j = 0;

	int iOcsp = 0;
	int iCrl = 0;
	char buffer[50];

	time_t timeStart;
	time_t timeStop;

	time(&timeStart);


	for(i=0;i<3;i++)
	{
		if(Ocsp>=0 && Ocsp<=2)
			i=Ocsp;

		switch(i)
		{
		case 0: iOcsp=PTEID_OCSP_CRL_NOT_USED;	break;
		case 1: iOcsp=PTEID_OCSP_CRL_OPTIONAL;	break;
		case 2: iOcsp=PTEID_OCSP_CRL_MANDATORY;	break;
		}

		for(j=0;j<3;j++)
		{
			if(Crl>=0 && Crl<=2)
				j=Crl;

			switch(j)
			{
			case 0: iCrl=PTEID_OCSP_CRL_NOT_USED;	break;
			case 1: iCrl=PTEID_OCSP_CRL_OPTIONAL;	break;
			case 2: iCrl=PTEID_OCSP_CRL_MANDATORY;	break;
			}

			if(NULL == (f=FileOpen(name, folder, bVerify, i, j)))
				return -1;

			PrintTestHeader(f,name);
			sprintf_s(buffer, sizeof(buffer), "%s (OCSP=%d - CRL=%d)",name,i,j);
			PrintHeader(f,buffer);

			PrintTestFunction(f,"PTEID_Init");
			tStatus = PTEID_Init((char*)reader, iOcsp, iCrl, &lHandle);
			PrintStatus(f,"PTEID_Init",&tStatus);
			if(PTEID_OK != tStatus.general)
			{
				PrintTestFunction(f,"PTEID_Exit");
				tStatus = PTEID_Exit();
				PrintStatus(f,"PTEID_Exit",&tStatus);
				//Don't warn if both parameter are set to mandatory, that's not allow
				if(iOcsp!=PTEID_OCSP_CRL_MANDATORY || iCrl!=PTEID_OCSP_CRL_MANDATORY)
					PrintWARNING(f,"Initialisation failed");
				
				FileClose(f);
				lRet = FileVerify(name, folder, bVerify, i, j);

				if(Crl>=0 && Crl<=2)
					break;
				else
					continue;
			}

			test_fct(f,Ocsp,Crl);

			PrintTestFunction(f,"PTEID_Exit");
			tStatus = PTEID_Exit();
			PrintStatus(f,"PTEID_Exit",&tStatus);

			//Virtual Reader
			if(test_virtual)
			{
 				PrintHeader(f,"INIT VIRTUAL READER");

				PrintTestFunction(f,"PTEID_Init(VIRTUAL)");
				tStatus = PTEID_Init("VIRTUAL", iOcsp, iCrl, &lHandle);
				PrintStatus(f,"PTEID_Init",&tStatus);
				if(PTEID_OK != tStatus.general)
				{
					PrintTestFunction(f,"PTEID_Exit");
					tStatus = PTEID_Exit();
					PrintWARNING(f,"Initialisation failed");
					PrintStatus(f,"PTEID_Exit",&tStatus);

					FileClose(f);
					lRet = FileVerify(name, folder, bVerify, i, j);

					if(Crl>=0 && Crl<=2)
						break;
					else
						continue;
				}

				test_virtual(f,Ocsp,Crl);

				PrintTestFunction(f,"PTEID_Exit");
				tStatus = PTEID_Exit();
				PrintStatus(f,"PTEID_Exit",&tStatus);
			}

			FileClose(f);
			lRet = FileVerify(name, folder, bVerify, i, j);

			if(Crl>=0 && Crl<=2)
				break;
		}

		if(Ocsp>=0 && Ocsp<=2)
			break;
	}

	time(&timeStop);

	printf("TOTAL TEST TIME = %.0lf secondes\n\n",difftime(timeStop,timeStart));

	return lRet;
}
Beispiel #3
0
int main(int argc, char* argv[])
{
    PTEID_Status tStatus = {0};
    PTEID_ID_Data idData = {0};
    PTEID_Address adData = {0};
    PTEID_Certif_Check tCheck = {0};
	PTEID_Bytes Picture = {0};
	FILE* pPictureFile = NULL;

    long lHandle = 0;
    tStatus = PTEID_Init("", 0, 0, &lHandle);
	if(PTEID_OK != tStatus.general)
	{
		tStatus = PTEID_Exit();
		printf("Initialisation failed\n");
		printf("Exiting...\n");
		return -1;
	}

    // Read ID Data
    tStatus = PTEID_GetID(&idData, &tCheck);
	printf(  "\n################################### IDENTITY ###################################\n");
	if(PTEID_OK == tStatus.general)
    {
		printf("CARD NUMBER:             : %s\n", idData.cardNumber);
		printf("CHIP NUMBER:             : %s\n", idData.chipNumber);
		printf("VALIDITY                 : %s - %s\n", idData.validityDateBegin, idData.validityDateEnd);
		printf("MUNICIALITY              : %s\n", idData.municipality);
		printf("NATIONAL NUMBER          : %s\n", idData.nationalNumber);
		printf("LASTNAME                 : %s\n", idData.name);
		printf("FISTNAMES                : %s %s %s\n", idData.firstName1, idData.firstName2, idData.firstName3);
		printf("NATIONALITY              : %s\n", idData.nationality);
		printf("BIRTHPLACE               : %s\n", idData.birthLocation);
		printf("BIRTHDATE                : %s\n", idData.birthDate);
		printf("GENDER                   : %s\n", idData.sex);
    }
	else
	{
		tStatus = PTEID_Exit();
		printf("Retrieveing identity data failed\n");
		printf("Exiting...\n");
		return -1;
	}

    memset(&tCheck, 0, sizeof(PTEID_Certif_Check));

    // Read Address Data
    tStatus = PTEID_GetAddress(&adData, &tCheck);
	printf(  "\n################################### ADDRESS ####################################\n");
	if(PTEID_OK == tStatus.general)
    {
        printf("STREET:                  : %s %s %s\n", adData.street, adData.streetNumber, adData.boxNumber);
		printf("ZIP:                     : %s\n", adData.zip);
		printf("MUNICIPALITY:            : %s\n", adData.municipality);
		printf("COUNTRY:                 : %s\n", adData.country);
    }
	else
	{
		tStatus = PTEID_Exit();
		printf("Retrieveing address data failed\n");
		printf("Exiting...\n");
		return -1;
	}

	// Read Picture
	Picture.data = (BYTE*)malloc(10*sizeof(BYTE));
	Picture.length = 10;
	tStatus = PTEID_GetPicture(&Picture, &tCheck);

	if (tStatus.general == PTEID_E_INSUFFICIENT_BUFFER)
	{
		free(Picture.data);
		Picture.data = (BYTE*)malloc(Picture.neededlength);
		Picture.length = Picture.neededlength;
	}

	tStatus = PTEID_GetPicture(&Picture, &tCheck);

	printf(  "\n################################### PICTURE ####################################\n");
	if(PTEID_OK == tStatus.general)
	{
		char fileName[256];
		strcpy(fileName,idData.nationalNumber);
		strcat(fileName,".jpg");
		pPictureFile = fopen(fileName,"w+b");
		fwrite(Picture.data,sizeof(BYTE),Picture.length,pPictureFile);
		fclose(pPictureFile);
		pPictureFile = NULL;
		printf("PICTURE FILE             : %s\n",fileName);
	}
	else
	{
		tStatus = PTEID_Exit();
		printf("Retrieveing picture failed\n");
		printf("Exiting...\n");
		return -1;
	}

    tStatus = PTEID_Exit();

	return 0;
}