Clarify the use of the WINHTTP_STATUS_CALLBACK function for SSL status codes


I am writing some WinHttp code in C. I am sending SSL requests, and to handle SSL errors, I register the WINHTTP_STATUS_CALLBACK function by calling WinHttpSetStatusCallback with the dwNotificationFlags parameter set to WINHTTP_CALLBACK_STATUS_SECURE_FAILURE.

The documentation for WINHTTP_STATUS_CALLBACK indicates that with a callback with dwInternetStatus= WINHTTP_CALLBACK_STATUS_SECURE_FAILURE this means that

One or more errors were encountered while receiving a Secure Sockets Layer (SSL) certificate from the server. The lpvStatusInformation parameter contains a flag. For more information, see Description for lpvStatusInformation.

Now the parameter lpvStatusInformationis entered as LPVOID. But I take it from the document in the documentation that it is not considered as a pointer in the case of WINHTTP_CALLBACK_STATUS_SECURE_FAILURE.

The document lpvStatusInformationsays:

If the dwInternetStatus parameter is WINHTTP_CALLBACK_STATUS_SECURE_FAILURE, this parameter can be one of the following values.

... And these values ​​are one of these hexadecimal values: 1,2,4,8,10,20,40. (See WinHttp.h)

This seems pretty clear to me. I do not have to unlink the pointer to get the value. lpvStatusInformationcontains a hexadecimal value, not a pointer.

Am I interpreting this correctly?


, . ! lpvStatusInformation 0x0104f288. , . OR'ing ( DWORD). . , 0x8, WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA, , , .


, ?

:

void CALLBACK Iirf_WinHttpSslStatusCallback( HINTERNET hInternet,
                                             DWORD_PTR context,
                                             DWORD code,
                                             void * pInfo,
                                             DWORD infoLength)
{
    if (code == WINHTTP_CALLBACK_STATUS_SECURE_FAILURE) {
        ConfigInfo * cfg = (ConfigInfo *) context; // app-specific structure
        DWORD details = (DWORD) pInfo; // do not de-reference??
        CHAR buffer[32];
        CHAR * statusDescription = NULL;

        switch (details) {
            case WINHTTP_CALLBACK_STATUS_FLAG_CERT_REV_FAILED:
                statusDescription = "CERT_REV_FAILED";
                break;

            case WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CERT:
                statusDescription = "INVALID_CERT";
                break;

            case WINHTTP_CALLBACK_STATUS_FLAG_CERT_REVOKED:
                statusDescription = "CERT_REVOKED";
                break;

            case WINHTTP_CALLBACK_STATUS_FLAG_INVALID_CA:
                statusDescription = "INVALID_CA";
                break;

            case WINHTTP_CALLBACK_STATUS_FLAG_CERT_CN_INVALID:
                statusDescription = "CERT_CN_INVALID";
                break;

            case WINHTTP_CALLBACK_STATUS_FLAG_CERT_DATE_INVALID:
                statusDescription = "CERT_DATE_INVALID";
                break;

            case WINHTTP_CALLBACK_STATUS_FLAG_SECURITY_CHANNEL_ERROR:
                statusDescription = "SECURITY_CHANNEL_ERROR";
                break;

            default:
                statusDescription = buffer;
                sprintf_s(buffer, 32, "stat(0x%08X) len(%d)",
                          details, infoLength);
                break;
        }

        LogMessage(cfg, 1, "SslStatusCallback: %s", statusDescription);
    }
}
+3
1

. lpvStatusInformation - . DWORD * , , , .

+6

Source: https://habr.com/ru/post/1783910/


All Articles