Статус: Участник
Группы: Участники
Зарегистрирован: 21.08.2009(UTC) Сообщений: 21 Откуда: Москва
|
По настоянию руководства выкладываю исходник проги. Может так будет проще... Код:PCCERT_CONTEXT my_CryptGetSignerCertificateCallback_function(void *pvGetArg,DWORD dwCertEncodingType,PCERT_INFO pSignerId,HCERTSTORE hMsgCertStore)
{
return (PCCERT_CONTEXT)pvGetArg;
}
int main(int argc, char* argv[])
{
HCERTSTORE hCMSCertStore = NULL;
PCCERT_CONTEXT pCert = NULL;
DWORD i = 1,c,j=0,k;
DWORD cbContent = 0;
BYTE signature[128];
BYTE hexSig[64];
BYTE * pbContent1;
const BYTE * pbContent;
FILE * inFile, * f = fopen("signed-data.txt","r");
if( f == NULL )
{
puts("file not found");
exit( EXIT_FAILURE );
}
while ( fgetc(f) != EOF )
++cbContent;
if( fseek(f,0,SEEK_SET) != 0 )
{
puts("fseek failed");
fclose(f);
f = fopen("signed-data.txt","r");
if( f == NULL )
{
puts("file not found");
return -1;
}
}
pbContent1 = (BYTE *)malloc(cbContent+1);
for( i = 0; i < cbContent; ++i )
pbContent1[i] = (BYTE)fgetc(f);
pbContent = pbContent1;
hCMSCertStore = CertOpenStore(CERT_STORE_PROV_FILENAME_A,CODE_TYPE,0,0,"CMS.p7b");
if(hCMSCertStore == NULL)
{
puts("store not open");
exit( EXIT_FAILURE );
}
doPure = TRUE;
output = fopen("out","w+");
if( !readGlobalConfig( "" ) )
{
puts("error readGlobalConfig");
exit( EXIT_FAILURE );
}
if( ( inFile = fopen( "CMS.p7b", "rb" ) ) == NULL )
{
puts("error fopen");
exit( EXIT_FAILURE );
}
fseek( inFile, 0, SEEK_SET );
printAsn1( inFile, 0, LENGTH_MAGIC, 0 );
fclose( inFile );
fclose(output);
output = fopen("out","r");
fseek(output,-1*(33+64*4),SEEK_END);
while( ( c = fgetc(output) ) != EOF )
{
if( c == ' ' || c == '\n' || c == '}' )
continue;
signature[j] = (BYTE)c;
++j;
}
for ( i = 0, k = 0 ; i < 64; ++i )
{
for ( j = 0 ; j < 2; ++j, ++k )
{
if( signature[k] >= 'A' && signature[k] <= 'F' )
c = (int)signature[k] - 'A'+10;
else if ( signature[k] >= '0' && signature[k] <= '9' )
c = (int)signature[k] - '0';
if( j == 0 )
hexSig[i] = (BYTE)c*0x10;
else
hexSig[i] += (BYTE)c;
}
}
DWORD cSig=64;
CRYPT_VERIFY_MESSAGE_PARA msgPara;
while( ( pCert = CertFindCertificateInStore(hCMSCertStore,CODE_TYPE,1,CERT_FIND_ANY,NULL,pCert) ) != NULL )
{
ZeroMemory(&msgPara, sizeof(msgPara));
msgPara.cbSize = sizeof(CRYPT_VERIFY_MESSAGE_PARA);
msgPara.dwMsgAndCertEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
msgPara.hCryptProv = NULL;//hCryptProv;
msgPara.pfnGetSignerCertificate = NULL;//&my_CryptGetSignerCertificateCallback_function;
msgPara.pvGetArg = (void *)pCert;
if( !CryptVerifyDetachedMessageSignature(&msgPara,1,hexSig,cSig,1,&pbContent,&cbContent,NULL) )
{
printf("%x\n",GetLastError());
}
}
if( !CertFreeCertificateContext(pCert) )
puts("Certificate not cleaned");
if( !CertCloseStore(hCMSCertStore,CERT_CLOSE_STORE_CHECK_FLAG) )
puts("Store not closed");
printf("\nHello World!\n");
fclose(f);
return 0;
}
|