Discussion:
Internet_option_security_certificate_struct problem
(too old to reply)
Mike Downey
2004-06-18 19:28:22 UTC
Permalink
I can't get any certficate information to come in. I am trying two
different SSL connection sites.
Has anyone else ever got this to work? If so what am I doing wrong?

Thanks for the help.

the site I am trying to connect to is https://secure.carbiz.com There is a
valid certificate on that site and i want to read the items of that
certificate.
I have also tried another site but cannot get it to work. Anyone have any
suggestions?


here is my code :

Private Sub Command1_Click()

Dim hInternet As Long
Dim hInstance As Long
Dim hSession As Long
Dim hRequest As Long
Dim lngRet As Long
Dim HtmlVersion As INTERNET_VERSION_INFO
Dim sBuffer As String
Dim sBufferSize As Long
Dim Cert As INTERNET_CERTIFICATE_INFO
Dim CertSize As Long
Dim bres As Long
Dim VersionInfo As INTERNET_VERSION_INFO
Dim VerInfoSize As Long

hInstance = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_PRECONFIG, _
"", "", 0)
'INTERNET_DEFAULT_HTTPS_PORT = 443
hSession = InternetConnect(hInstance, cboURL.Text, 443, _
"", "", INTERNET_SERVICE_HTTP, 0, 0)
hRequest = HttpOpenRequest(hSession, _
"GET", _
cboURL.Text, _
vbNullString, _
vbNullString, _
0, _
INTERNET_FLAG_SECURE, _
0)

lngRet = InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
0)
CertSize = Len(Cert)
lngRet = InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
CertSize)

MsgBox (Cert.lpszIssuerInfo)
MsgBox (Cert.ftStart)


End Sub
Stephen Sulzer
2004-06-18 19:47:03 UTC
Permalink
You have to send the request first (using HttpSendRequest) before you can
query for the server's certificate. WinInet doesn't create the SSL
connection with the server until HttpSendRequest. If you are sending a POST
request, you do not need to send the entire request (eg., the POST data)
during HttpSendRequest. You can send just the HTTP headers, then query for
the server's certificate. If the server's certificate is acceptable, then
complete the request by sending the POST data using InternetWriteFile, and
finally, tell WinInet you have completed sending the request using
HttpEndRequest.
Post by Mike Downey
I can't get any certficate information to come in. I am trying two
different SSL connection sites.
Has anyone else ever got this to work? If so what am I doing wrong?
Thanks for the help.
the site I am trying to connect to is https://secure.carbiz.com There is a
valid certificate on that site and i want to read the items of that
certificate.
I have also tried another site but cannot get it to work. Anyone have any
suggestions?
Private Sub Command1_Click()
Dim hInternet As Long
Dim hInstance As Long
Dim hSession As Long
Dim hRequest As Long
Dim lngRet As Long
Dim HtmlVersion As INTERNET_VERSION_INFO
Dim sBuffer As String
Dim sBufferSize As Long
Dim Cert As INTERNET_CERTIFICATE_INFO
Dim CertSize As Long
Dim bres As Long
Dim VersionInfo As INTERNET_VERSION_INFO
Dim VerInfoSize As Long
hInstance = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_PRECONFIG, _
"", "", 0)
'INTERNET_DEFAULT_HTTPS_PORT = 443
hSession = InternetConnect(hInstance, cboURL.Text, 443, _
"", "", INTERNET_SERVICE_HTTP, 0, 0)
hRequest = HttpOpenRequest(hSession, _
"GET", _
cboURL.Text, _
vbNullString, _
vbNullString, _
0, _
INTERNET_FLAG_SECURE, _
0)
lngRet = InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
0)
CertSize = Len(Cert)
lngRet = InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
CertSize)
MsgBox (Cert.lpszIssuerInfo)
MsgBox (Cert.ftStart)
End Sub
Mike Downey
2004-06-18 20:42:00 UTC
Permalink
thank you stephen I try that and get back here if there are any problems.

thanks!
Mike
Post by Stephen Sulzer
You have to send the request first (using HttpSendRequest) before you can
query for the server's certificate. WinInet doesn't create the SSL
connection with the server until HttpSendRequest. If you are sending a POST
request, you do not need to send the entire request (eg., the POST data)
during HttpSendRequest. You can send just the HTTP headers, then query for
the server's certificate. If the server's certificate is acceptable, then
complete the request by sending the POST data using InternetWriteFile, and
finally, tell WinInet you have completed sending the request using
HttpEndRequest.
Post by Mike Downey
I can't get any certficate information to come in. I am trying two
different SSL connection sites.
Has anyone else ever got this to work? If so what am I doing wrong?
Thanks for the help.
the site I am trying to connect to is https://secure.carbiz.com There
is
Post by Stephen Sulzer
a
Post by Mike Downey
valid certificate on that site and i want to read the items of that
certificate.
I have also tried another site but cannot get it to work. Anyone have any
suggestions?
Private Sub Command1_Click()
Dim hInternet As Long
Dim hInstance As Long
Dim hSession As Long
Dim hRequest As Long
Dim lngRet As Long
Dim HtmlVersion As INTERNET_VERSION_INFO
Dim sBuffer As String
Dim sBufferSize As Long
Dim Cert As INTERNET_CERTIFICATE_INFO
Dim CertSize As Long
Dim bres As Long
Dim VersionInfo As INTERNET_VERSION_INFO
Dim VerInfoSize As Long
hInstance = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_PRECONFIG, _
"", "", 0)
'INTERNET_DEFAULT_HTTPS_PORT = 443
hSession = InternetConnect(hInstance, cboURL.Text, 443, _
"", "", INTERNET_SERVICE_HTTP, 0, 0)
hRequest = HttpOpenRequest(hSession, _
"GET", _
cboURL.Text, _
vbNullString, _
vbNullString, _
0, _
INTERNET_FLAG_SECURE, _
0)
lngRet = InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
0)
CertSize = Len(Cert)
lngRet = InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
CertSize)
MsgBox (Cert.lpszIssuerInfo)
MsgBox (Cert.ftStart)
End Sub
Mike Downey
2004-06-21 14:55:24 UTC
Permalink
Stephen.

Thanks for the help. i am getting an error of 6 which is an invalid
handle.

here is how i have modified my code :

the url that I am hitting is secure.carbiz.com
Sorry for asking so many questions. hopefully this thread will help
everyone else out too.


Private Sub Command1_Click()

Dim HINTERNET As Long
Dim hInstance As Long
Dim hSession As Long
Dim hRequest As Long
Dim hReq As Long
Dim lngRet As Long
Dim HtmlVersion As INTERNET_VERSION_INFO
Dim sBuffer As String
Dim sBufferSize As Long
Dim Cert As INTERNET_CERTIFICATE_INFO
Dim CertSize As Long
Dim bres As Long
Dim VersionInfo As INTERNET_VERSION_INFO
Dim VerInfoSize As Long

hInstance = InternetOpen(App.EXEName, INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0)
hSession = InternetConnect(hInstance, CheckUrl, 443, _
vbNullString, vbNullString, INTERNET_SERVICE_HTTP, 0, 0)
hRequest = HttpOpenRequest(hSession, "GET", GetUrlObject, _
"HTTP/1.0", vbNullString, 0, INTERNET_FLAG_SECURE, 0)

If CBool(hRequest) Then
If HttpSendRequest(hRequest, vbNullString, 0, vbNullString, 0) Then
Else
MsgBox ("Error with HttpSendRequest " & Err.LastDllError)
End If
If Err.LastDllError = 0 Then
If InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
CertSize) Then
Else
MsgBox ("Problem with SecurityCertStruct 1 " &
Err.LastDllError)
End If

CertSize = Len(Cert)
If InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
CertSize) Then
Else
MsgBox ("Problem with SecurityCertStruct 2 " &
Err.LastDllError)
End If

MsgBox (Cert.lpszIssuerInfo)
MsgBox (Cert.ftStart)
End If
Else
' HttpOpenRequest failed
MsgBox ("HttpOpenRequest call failed; Error code: " &
Err.LastDllError & ".")
End If

End Sub
Post by Mike Downey
thank you stephen I try that and get back here if there are any problems.
thanks!
Mike
Post by Stephen Sulzer
You have to send the request first (using HttpSendRequest) before you can
query for the server's certificate. WinInet doesn't create the SSL
connection with the server until HttpSendRequest. If you are sending a
POST
Post by Stephen Sulzer
request, you do not need to send the entire request (eg., the POST data)
during HttpSendRequest. You can send just the HTTP headers, then query for
the server's certificate. If the server's certificate is acceptable, then
complete the request by sending the POST data using InternetWriteFile, and
finally, tell WinInet you have completed sending the request using
HttpEndRequest.
Post by Mike Downey
I can't get any certficate information to come in. I am trying two
different SSL connection sites.
Has anyone else ever got this to work? If so what am I doing wrong?
Thanks for the help.
the site I am trying to connect to is https://secure.carbiz.com
There
Post by Mike Downey
is
Post by Stephen Sulzer
a
Post by Mike Downey
valid certificate on that site and i want to read the items of that
certificate.
I have also tried another site but cannot get it to work. Anyone have
any
Post by Stephen Sulzer
Post by Mike Downey
suggestions?
Private Sub Command1_Click()
Dim hInternet As Long
Dim hInstance As Long
Dim hSession As Long
Dim hRequest As Long
Dim lngRet As Long
Dim HtmlVersion As INTERNET_VERSION_INFO
Dim sBuffer As String
Dim sBufferSize As Long
Dim Cert As INTERNET_CERTIFICATE_INFO
Dim CertSize As Long
Dim bres As Long
Dim VersionInfo As INTERNET_VERSION_INFO
Dim VerInfoSize As Long
hInstance = InternetOpen(App.EXEName,
INTERNET_OPEN_TYPE_PRECONFIG,
Post by Mike Downey
_
Post by Stephen Sulzer
Post by Mike Downey
"", "", 0)
'INTERNET_DEFAULT_HTTPS_PORT = 443
hSession = InternetConnect(hInstance, cboURL.Text, 443, _
"", "", INTERNET_SERVICE_HTTP, 0, 0)
hRequest = HttpOpenRequest(hSession, _
"GET", _
cboURL.Text, _
vbNullString, _
vbNullString, _
0, _
INTERNET_FLAG_SECURE, _
0)
lngRet = InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
0)
CertSize = Len(Cert)
lngRet = InternetQueryOptionA(hRequest, _
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, _
Cert, _
CertSize)
MsgBox (Cert.lpszIssuerInfo)
MsgBox (Cert.ftStart)
End Sub
Stephen Sulzer
2004-06-21 21:20:18 UTC
Permalink
What WinInet API call is returning the INVALID_HANDLE error?

I don't see anything wrong with your code, except that you shouldn't test
for Err.LastDllError = 0. You should use the Err.LastDllError value only
when the API call indicates (by returning FALSE or NULL) that an error
actually occurred. If HttpSendRequest returns TRUE, then query for the
certificate structure; do not test Err.LastDllError = 0 to determine if
HttpSendRequest succeeded.

Stephen
Mike Downey
2004-06-22 12:22:54 UTC
Permalink
the HttpSendRequest is returning the INvalid_Handle Error code 6.

thanks again stephen.

mike
Post by Stephen Sulzer
What WinInet API call is returning the INVALID_HANDLE error?
I don't see anything wrong with your code, except that you shouldn't test
for Err.LastDllError = 0. You should use the Err.LastDllError value only
when the API call indicates (by returning FALSE or NULL) that an error
actually occurred. If HttpSendRequest returns TRUE, then query for the
certificate structure; do not test Err.LastDllError = 0 to determine if
HttpSendRequest succeeded.
Stephen
Continue reading on narkive:
Loading...