From a41cb33afaee0adc6fdf3b8c69b9fb545dc15a96 Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Sun, 2 Aug 2020 16:23:39 -0700 Subject: [PATCH] wininet: Move INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT handling to helper. Signed-off-by: Daniel Lehman Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/wininet/http.c | 62 ++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 56c995805b2..220493718c3 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -2083,6 +2083,38 @@ static DWORD str_to_buffer(const WCHAR *str, void *buffer, DWORD *size, BOOL uni } } +static DWORD get_security_cert_struct(http_request_t *req, INTERNET_CERTIFICATE_INFOA *info) +{ + PCCERT_CONTEXT context; + DWORD len; + + context = (PCCERT_CONTEXT)NETCON_GetCert(req->netconn); + if(!context) + return ERROR_NOT_SUPPORTED; + + memset(info, 0, sizeof(*info)); + info->ftExpiry = context->pCertInfo->NotAfter; + info->ftStart = context->pCertInfo->NotBefore; + len = CertNameToStrA(context->dwCertEncodingType, + &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, NULL, 0); + info->lpszSubjectInfo = LocalAlloc(0, len); + if(info->lpszSubjectInfo) + CertNameToStrA(context->dwCertEncodingType, + &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, + info->lpszSubjectInfo, len); + len = CertNameToStrA(context->dwCertEncodingType, + &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, NULL, 0); + info->lpszIssuerInfo = LocalAlloc(0, len); + if(info->lpszIssuerInfo) + CertNameToStrA(context->dwCertEncodingType, + &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, + info->lpszIssuerInfo, len); + info->dwKeySize = NETCON_GetCipherStrength(req->netconn); + + CertFreeCertificateContext(context); + return ERROR_SUCCESS; +} + static DWORD HTTPREQ_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode) { http_request_t *req = (http_request_t*)hdr; @@ -2235,8 +2267,6 @@ static DWORD HTTPREQ_QueryOption(object_header_t *hdr, DWORD option, void *buffe } case INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT: { - PCCERT_CONTEXT context; - if(!req->netconn) return ERROR_INTERNET_INVALID_OPERATION; @@ -2245,33 +2275,7 @@ static DWORD HTTPREQ_QueryOption(object_header_t *hdr, DWORD option, void *buffe return ERROR_INSUFFICIENT_BUFFER; } - context = (PCCERT_CONTEXT)NETCON_GetCert(req->netconn); - if(context) { - INTERNET_CERTIFICATE_INFOA *info = (INTERNET_CERTIFICATE_INFOA*)buffer; - DWORD len; - - memset(info, 0, sizeof(*info)); - info->ftExpiry = context->pCertInfo->NotAfter; - info->ftStart = context->pCertInfo->NotBefore; - len = CertNameToStrA(context->dwCertEncodingType, - &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, NULL, 0); - info->lpszSubjectInfo = LocalAlloc(0, len); - if(info->lpszSubjectInfo) - CertNameToStrA(context->dwCertEncodingType, - &context->pCertInfo->Subject, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, - info->lpszSubjectInfo, len); - len = CertNameToStrA(context->dwCertEncodingType, - &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, NULL, 0); - info->lpszIssuerInfo = LocalAlloc(0, len); - if(info->lpszIssuerInfo) - CertNameToStrA(context->dwCertEncodingType, - &context->pCertInfo->Issuer, CERT_SIMPLE_NAME_STR|CERT_NAME_STR_CRLF_FLAG, - info->lpszIssuerInfo, len); - info->dwKeySize = NETCON_GetCipherStrength(req->netconn); - CertFreeCertificateContext(context); - return ERROR_SUCCESS; - } - return ERROR_NOT_SUPPORTED; + return get_security_cert_struct(req, (INTERNET_CERTIFICATE_INFOA*)buffer); } case INTERNET_OPTION_CONNECT_TIMEOUT: if (*size < sizeof(DWORD))