Unfortunately, it does not seem possible to get the CERT_CONTEXT pointer to
the server's SSL certificate from WinInet. The IE dialog that shows the
server certificate is implemented inside WinInet, and so has access to the
internal data structure that stores the CERT_CONTEXT handle of the server
certificate.
The lpszSubjectInfo field of the INTERNET_CERTIFICATE_INFO structure
contains the subject name of the server certificate. But the structure does
not provide a handle to the certificate store. Without the certificate store
handle, I don't know how you can map the subject name to a CERT_CONTEXT.
(With the certificate store handle, you could use the
CertFindCertificateInStore API.)
You should ask for help on the microsoft.public.platformsdk.security
newsgroup (where the CryptoAPI experts hang out). Is it possible to somehow
get a handle to the certificate store (that would contain the server
certificate that WinInet has received during the SSL negotiation) using the
Crypto API's? Perhaps there is a way to enumerate all the cert stores, for
example.
Another solution to consider is using the WinHTTP API. WinHTTP is a Win32
API similar to WinInet; it was designed primarily for multi-user
server-based applications and NT services, but can also be used in desktop
client apps. The WinHttpQueryOption API contains a
WINHTTP_OPTION_SERVER_CERT_CONTEXT option that provides the server
certificate's CERT_CONTEXT handle. However, WinHTTP has limited platform
support compared to WinInet (WinHTTP is available in Windows 2000 SP3/SP4,
Windows XP SP1 and Windows Server 2003).
Hope that helps.
Stephen
Post by Matt FletcherIs it possible to extract an SSL server certificate from WinInet? I know
that if I use InternetQueryOption with flag
INTERNET_OPTION_SECURITY_CERTIFICATE or
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT then I can get some information
about the certificate, but how can I get the actual certificate (as IE
itself does).
TIA
Matt Fletcher