Click here to Skip to main content
15,888,461 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: program crashing.... Pin
VC++Maniac4-Feb-09 18:15
VC++Maniac4-Feb-09 18:15 
AnswerRe: program crashing.... Pin
_AnsHUMAN_ 4-Feb-09 18:28
_AnsHUMAN_ 4-Feb-09 18:28 
QuestionRibbon app crash on XP. Works on vista. [modified] Pin
VC++Maniac4-Feb-09 17:27
VC++Maniac4-Feb-09 17:27 
AnswerRe: Ribbon app crash on XP. Works on vista. Pin
VC++Maniac6-Feb-09 0:42
VC++Maniac6-Feb-09 0:42 
QuestionHow to play an Animation and make video render before logon through credential provider ?(Vista) [modified] Pin
wyc_xiaoben4-Feb-09 15:06
wyc_xiaoben4-Feb-09 15:06 
AnswerRe: How to play an Animation and make video render before logon through credential provider ?(Vista) Pin
Wes Aday4-Feb-09 16:00
professionalWes Aday4-Feb-09 16:00 
Questionwinhttp ssl using client certificate P12 Pin
Codey20984-Feb-09 11:17
Codey20984-Feb-09 11:17 
AnswerRe: winhttp ssl using client certificate P12 Pin
andrew7webb1-Jan-11 11:36
andrew7webb1-Jan-11 11:36 
You have probably solved this by now, but, here are the key ideas for the client:
Read the .p12 into memory.
Use PFXImportCertStore to put it into a certstore
Use WinHttpSetOption with the WINHTTP_OPTION_CLIENT_CERT_CONTEXT parameter.



HCERTSTORE PFXImportCertStoreTCHAR( CRYPT_DATA_BLOB *PFX, const TCHAR * password )
{
#if defined UNICODE || defined _UNICODE
return ::PFXImportCertStore( PFX, password, 0 );
#endif
// Have to convert char * password to wchar_t *
size_t sizeInWords= 999;
wchar_t wcstr[999];
size_t count= strlen( password );
size_t returnValue;
errno_t err= mbstowcs_s( &returnValue, wcstr, sizeInWords, (const char *)password, count );
return ::PFXImportCertStore( PFX, wcstr, 0 );
}



// Use a .pfx certificate and private key
// Note that the certificate must be associated with a private key to avoid a ERROR_WINHTTP_CLIENT_CERT_NO_PRIVATE_KEY error.
//
void setClientCertificate( const std::vector< unsigned char > & clientPfx, const TCHAR * szPassword )
{
if ( 0 == (openFlags & WINHTTP_FLAG_SECURE) ) return; // No need to send a client certificate if using plain http

// Convert a .pfx or .p12 file image to a Certificate store
CRYPT_DATA_BLOB PFX;
PFX.pbData= (BYTE *)&clientPfx[0];
PFX.cbData= clientPfx.size();

HCERTSTORE pfxStore= PFXImportCertStoreTCHAR( &PFX, szPassword );
if ( NULL == pfxStore ) throw std::pair<int,int>( __LINE__, ::GetLastError() );


// Extract the certificate from the store and pass it to WinHttp
PCCERT_CONTEXT pcontext= NULL, clientCertContext;
while ( pcontext = ::CertEnumCertificatesInStore( pfxStore, pcontext ) ){
clientCertContext= ::CertDuplicateCertificateContext( pcontext ); // CertEnumCertificatesInStore frees its passed in pcontext !

BOOL stat= ::WinHttpSetOption( hRequest, WINHTTP_OPTION_CLIENT_CERT_CONTEXT, (LPVOID)clientCertContext, sizeof(CERT_CONTEXT) );
if ( FALSE == stat ) throw std::pair<int,int>( __LINE__, ::GetLastError() );
return; // Success
}

throw std::pair<int,int>( __LINE__, ::GetLastError() ); // No certificates in the store created from the pfx/p12
}
QuestionMSI, ShellNew and Vista Ultimate.. [modified] Pin
Member 38520244-Feb-09 10:54
Member 38520244-Feb-09 10:54 
Questionvector(wstring) to System::String ? Pin
Thilek4-Feb-09 7:02
Thilek4-Feb-09 7:02 
AnswerRe: vector(wstring) to System::String ? Pin
CPallini4-Feb-09 7:57
mveCPallini4-Feb-09 7:57 
GeneralRe: vector(wstring) to System::String ? Pin
Thilek4-Feb-09 19:53
Thilek4-Feb-09 19:53 
QuestionRe: vector(wstring) to System::String ? Pin
David Crow5-Feb-09 3:39
David Crow5-Feb-09 3:39 
QuestionOLE DB network suggestions Pin
robocodeboy4-Feb-09 6:27
robocodeboy4-Feb-09 6:27 
QuestionDBCS issue Pin
David Crow4-Feb-09 5:36
David Crow4-Feb-09 5:36 
AnswerRe: DBCS issue Pin
Graham Bradshaw4-Feb-09 6:22
Graham Bradshaw4-Feb-09 6:22 
GeneralRe: DBCS issue Pin
David Crow4-Feb-09 6:47
David Crow4-Feb-09 6:47 
GeneralRe: DBCS issue Pin
Graham Bradshaw4-Feb-09 6:50
Graham Bradshaw4-Feb-09 6:50 
GeneralRe: DBCS issue Pin
David Crow4-Feb-09 6:54
David Crow4-Feb-09 6:54 
GeneralRe: DBCS issue Pin
Graham Bradshaw4-Feb-09 6:58
Graham Bradshaw4-Feb-09 6:58 
QuestionRe: DBCS issue Pin
David Crow4-Feb-09 7:10
David Crow4-Feb-09 7:10 
AnswerRe: DBCS issue Pin
Graham Bradshaw4-Feb-09 7:29
Graham Bradshaw4-Feb-09 7:29 
AnswerRe: DBCS issue - calculating the number of bytes Pin
daniel_zy6-Feb-09 7:20
daniel_zy6-Feb-09 7:20 
QuestionNeed help on how to create Group Box dynamically Pin
John5024-Feb-09 4:48
John5024-Feb-09 4:48 
AnswerRe: Need help on how to create Group Box dynamically Pin
Code-o-mat4-Feb-09 6:16
Code-o-mat4-Feb-09 6:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.