PR_USER_X509_CERTIFICATE PROP for assign a certificate to contact

G

Gancev

Hi,
I am trying to make a code that will import certificate file for contact
using c++.
The think is i didnt found anithing on the net but with outlook spy and MFC
mapi i conclude that PR_USER_X509_CERTIFICATE is the value where the
certificate(s) should be stored. This is the part of the code i use to assign
the certificate to a contact item in outlook:
{
#define PR_USER_X509_CERTIFICATE PROP_TAG( PT_MV_BINARY, 0x3A70)
#define MY_ENCODING_TYPE (PKCS_7_ASN_ENCODING | X509_ASN_ENCODING)
HCERTSTORE hSystemStore;
HCERTSTORE hFileStore;
PCCERT_CONTEXT pCertContext = NULL;
TCHAR pszNameString[256];
BYTE* pbElement;
DWORD cbElement;
//open certificate from file

hSystemStore = CertOpenSystemStore(0,L"CA"));
hFileStore =
CertOpenStore(CERT_STORE_PROV_FILENAME,MY_ENCODING_TYPE,NULL,0,L"c:\\irenaCert.cer" ));
pCertContext=CertEnumCertificatesInStore(hSystemStore,pCertContext));

//assign the certificate to contact
IMessage *imsg=0;
imsg=(IMessage *)(contactItem.get_MAPIOBJECT());
SPropValue propCer;
propCer.dwAlignPad=0;
propCer.ulPropTag=PR_USER_X509_CERTIFICATE;
propCer.Value.MVbin.cValues = 1;
SBinary binSig;
binSig.lpb=pCertContext->pbCertEncoded;
binSig.cb=pCertContext->cbCertEncoded;
propCer.Value.MVbin.lpbin = &binSig;
propCer.Value.MVbin.lpbin->lpb = pCertContext->pbCertEncoded; //lpbCertBlob;
propCer.Value.MVbin.lpbin->cb =pCertContext->cbCertEncoded; //cbCertBlob;
LPSPropProblemArray pProblemArray=0;
HRESULT resProp=imsg->SetProps(1,(LPSPropValue)&propCer,&pProblemArray);
resProp=imsg->SaveChanges(FORCE_SAVE);
free(pbElement);
CertCloseStore(hSystemStore,0);
}

So everything goues fine and the value is set but the outlook cannot
recognize the certificate. I found out that the problem is in binary data
format and size and here i need help . How to generate the binary data so the
outlook can reconize the certificate.

Thanks,
Stojan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top