Skip to content

REST API C++ - HTTPS Certificate option #199

@shivendra6782

Description

@shivendra6782

Hi,

I have used below code using WinHTTP to use certificate, but now I moved to CPPRESTSDK and want to set the certificate for HTTPS but I am not getting any option in REST API. or its automatically verified when using HTTPS connection and set_validate_certificates(true);
Please suggest if my understanding is correct or not.

OS- Windows
hRequest = WinHttpOpenRequest(hConnect, L"POST", L"/auth",
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
NULL);
//WINHTTP_FLAG_SECURE);
/hRequest = WinHttpOpenRequest(hConnect, L"POST", L"/auth",
L"HTTP/1.1", WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_REFRESH);
WINHTTP_FLAG_SECURE);
/
if (!hRequest) {
Clog::traceLog(ERRORLOG, "WinHttpOpenRequest:Error %d has occurred.", GetLastError());
iRetVal = SDP_ERROR_WINHTTP_INTERNAL_ERROR;
}
else {
hMyStore = CertOpenSystemStore(0, TEXT("MY"));
if (hMyStore)
{
pCertContext = CertFindCertificateInStore(hMyStore,
X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
0,
CERT_FIND_SUBJECT_STR,
(LPVOID)szCertName, //Subject string in the certificate.
NULL);
if (!pCertContext)
{
WinHttpSetOption(hRequest,
WINHTTP_OPTION_CLIENT_CERT_CONTEXT,
(LPVOID)pCertContext,
sizeof(CERT_CONTEXT));
CertFreeCertificateContext(pCertContext);
}
CertCloseStore(hMyStore, 0);

Thanks,
Shivendra

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions