cryptoapi - Adding Response from TSA to CRYPT_SIGN_MESSAGE_PARA for CryptSignMessage (c++, Crypto Api) -
i'm struggling how must add response tsa server cryptsignmessage?
using pkcs#7. have message digest , sign cryptsignmessage crypto api. so:
// initialize signature structure. crypt_sign_message_para sigparams; sigparams.cbsize = sizeof(crypt_sign_message_para); sigparams.dwmsgencodingtype = my_encoding_type; sigparams.psigningcert = hcontext; sigparams.hashalgorithm.pszobjid = szoid_rsa_sha1rsa; sigparams.hashalgorithm.parameters.cbdata = null; sigparams.cmsgcert = 1; sigparams.rgpmsgcert = &hcontext; sigparams.dwinnercontenttype = 0; sigparams.cmsgcrl = 0; sigparams.cunauthattr = 0; sigparams.dwflags = 0; sigparams.pvhashauxinfo = null; sigparams.cauthattr = 0; sigparams.rgauthattr = null; // first, size of signed blob. if(cryptsignmessage( &sigparams, false, 1, messagearray, messagesizearray, null, &cbsignedmessageblob)) { printf("%d bytes needed encoded blob.", cbsignedmessageblob); } else { myhandleerror(); freturn = false; exit_signmessage(); } // allocate memory signed blob. if(!(pbsignedmessageblob = (byte*)malloc(cbsignedmessageblob))) { myhandleerror(); exit_signmessage(); } // signed message blob. if(cryptsignmessage( &sigparams, true, 1, messagearray, messagesizearray, pbsignedmessageblob, &cbsignedmessageblob)) { printf("the message signed successfully. \n"); // pbsignedmessageblob contains signed blob. freturn = true; } else { myhandleerror(); freturn = false; exit_signmessage(); }
now want use tsa server timestamp digest, i'm not sure how include this. have rfc3161 timestamp request; send tsa , receive rfc3161 timestamp response (probably using libcurl). how should incorporate response sigparams? must extract timestamptoken , store unauthenticated counter signature? like:
crypt_attr_blob cablob[1]; crypt_attribute ca[1]; cablob[0].cbdata = tstresponsesize; cablob[0].pbdata = tstresponse; // response tsa ca[0].pszobjid = "1.2.840.113549.9.6"; // object identifier counter signature ca[0].cvalue = 1; ca[0].rgvalue = cablob;
and set sigparams:
sigparams.cunauthatt = 1; sigparams.rgunauthattr = ca;
any advice appreciated. thanks, magda
Comments
Post a Comment