PDA

View Full Version : Building and using SSL with QSslSocket



nopcode
16th July 2008, 17:57
I'm having zero luck in getting Qt4 to build in order to use the QsslSocket class. I've downloaded and installed the openssl for Windows, and copied the openssl folder into qt4\includes so that it can be used, but I'm getting the following when compiling:

cl -c -FIqt_pch.h -Yuqt_pch.h -Fptmp\obj\debug_shared\QtNetworkd_pch.pch -nologo -Zm200 -Zc:wchar_t- -Zi -MDd -W3 -w34100 -w34189 -GR -EHsc -DQT_SHARED -DQT_THREAD_SUPPORT -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_EDITION=QT_EDITION_DESKTOP -DQT_BUILD_NETWORK_LIB -DQT_NO_USING_NAMESPACE -DQT_MAKEDLL -DQT_NO_CAST_TO_ASCII -DQT_ASCII_CAST_WARNINGS -DQT_MOC_COMPAT -D_USE_MATH_DEFINES -DQT_DLL -DQT_CORE_LIB -I"..\..\include\QtCore" -I"..\..\include\QtCore" -I"..\..\include" -I"..\..\include\QtNetwork" -I"tmp\rcc\debug_shared" -I"tmp" -I"..\3rdparty\zlib" -I"kernel" -I"..\..\include\ActiveQt" -I"tmp\moc\debug_shared" -I"." -I"..\..\mkspecs\win32-msvc2008" -Fotmp\obj\debug_shared\ @c:\temp\nm6E1.tmp
qsslcertificate.cpp
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ')' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ';' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2040: 'LPCSTR' : 'ocsp_response_st' differs in levels of indirection from 'const CHAR *'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2059: syntax error : ')'
qsslkey.cpp
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ')' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ';' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2040: 'LPCSTR' : 'ocsp_response_st' differs in levels of indirection from 'const CHAR *'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2059: syntax error : ')'
qsslsocket.cpp
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ')' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ';' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2040: 'LPCSTR' : 'ocsp_response_st' differs in levels of indirection from 'const CHAR *'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2059: syntax error : ')'
qsslsocket_openssl.cpp
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ')' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ';' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2040: 'LPCSTR' : 'ocsp_response_st' differs in levels of indirection from 'const CHAR *'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2059: syntax error : ')'
qsslsocket_openssl_symbols.cpp
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ')' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2143: syntax error : missing ';' before 'constant'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2040: 'LPCSTR' : 'ocsp_response_st' differs in levels of indirection from 'const CHAR *'
C:\Qt\4.4.0\include\openssl/ossl_typ.h(176) : error C2059: syntax error : ')'

FWIW, I'm using the commercial license version and VS2008, and openssl Win32OpenSSL-0_9_8h install. I've tried it with both configure -openssl and configure -openssl-linked

Suggestions?

nopcode
17th July 2008, 15:26
I figured it out: in the openssl/ossl_typ.h header, there is a forward typedef at the bottom that reads:
typedef struct ocsp_response_st OCSP_RESPONSE;
the ocsp_response_st is defined in openssl/ocsp.h, but you cannot include that one before ossl_typ.h because it depends upon defines in the other - circular reference. Apparently other compilers are not as picky as VS2008.
I fixed this by moving the typdef from the ossl_typ.h file to the ocsp.h file where the stuct ocsp_response_st is defined at.

wxisaac
22nd October 2008, 10:14
According to OpenSSL recent patch towards file ossl_typ.h to fix this issue, the reason is "CryptoAPI uses this too". This explain the strange error message. So it's due to the difference of Windows SDK between v5.0 & v6.0 instead of the "pickyness" for VS2008 compiling fails while VS2005 works.

wxisaac
22nd October 2008, 10:25
It's really nuisance to get name conflict while link components especially from different vendor. Namespace separation is really a good practice.