PDA

View Full Version : Problem including openSSL Crypto headers to Qt Application



nbkhwjm
19th November 2008, 16:07
I have an application that needs some crypto libs from OpenSSL.

the application is uses other SSL functions fine, like https etc (so QT already has SSL built in), but i want to encrypt a password in the INI with blowfish so i need to include some openssl headers.

I cannot the application to build when i include it..

Example:
I tried the following:


extern{#include "openssl/evp.h";}

and

#include <openssl/evp.h>

What is the proper way to declare these includes so Qt will find them?


One question I have is the use of < > and where the application will look for these files. where should they be located for the app to see them?

I know that if i use " (quotes) then it looks in the source directory.

Platform Linux (ubuntu) GCC and Commercial Qt version. 4.4.1

Thanks

wysota
19th November 2008, 16:46
Qt doesn't find includes. Your compiler (or preprocessor to be exact) does. So you have to include the header just like any other include on your system. But is your problem related to including a header file or linking against the crypto library? What is the exact error message you get?

nbkhwjm
19th November 2008, 16:50
Errors:

QtTest -L/usr/local/Trolltech/Qt-4.4.1/lib -lQtGui -L/usr/X11R6/lib -lSM -lICE -lXext -lX11 -lQtNetwork -lQtCore -lz -lm -lrt -ldl -lpthread
cryptobfuscate.o: In function `CryptObfuscate::cryptData(QByteArray const&, QByteArray const&, int)':
cryptobfuscate.cpp:(.text+0xb20): undefined reference to `EVP_md5'
cryptobfuscate.cpp:(.text+0xb27): undefined reference to `EVP_bf_cbc'
cryptobfuscate.cpp:(.text+0xb58): undefined reference to `EVP_BytesToKey'
cryptobfuscate.cpp:(.text+0xb6e): undefined reference to `EVP_CIPHER_CTX_init'
cryptobfuscate.cpp:(.text+0xb73): undefined reference to `EVP_bf_cbc'
cryptobfuscate.cpp:(.text+0xb9c): undefined reference to `EVP_CipherInit_ex'
cryptobfuscate.cpp:(.text+0xbd6): undefined reference to `EVP_CipherUpdate'
cryptobfuscate.cpp:(.text+0xc00): undefined reference to `EVP_CipherFinal_ex'
cryptobfuscate.cpp:(.text+0xc38): undefined reference to `EVP_CIPHER_CTX_cleanup'
collect2: ld returned 1 exit status
make: *** [printsend] Error 1


This is the code that this is referring to:


//OpenSSL blowfish encryption

//TODO: Modify to include other encryption algo - (passed by name)

QByteArray CryptObfuscate::cryptData(const QByteArray& data, const QByteArray& password, int cmd)

{





const char initValue[] = "5f7a20de";

const char salt[] = "72jadg07";



unsigned char *buf;

unsigned char *ebuf;

int ebuflen,padlen;

unsigned char iv[EVP_MAX_IV_LENGTH], key[EVP_MAX_KEY_LENGTH];

EVP_CIPHER_CTX ectx;



buf = new unsigned char[data.size()];

ebuf = new unsigned char[data.size() + EVP_MAX_BLOCK_LENGTH ];



memcpy(iv,initValue,sizeof(iv));



if(EVP_BytesToKey(EVP_bf_cbc(), EVP_md5(), reinterpret_cast< const unsigned char*>(salt),

reinterpret_cast< const unsigned char*>(password.constData()) , password.size(), 1, key, iv) <= 0)

return QByteArray();



EVP_CIPHER_CTX_init(&ectx);

truncated . . . .

wysota
19th November 2008, 17:21
This is not a problem with including, this is a problem with linking. Add LIBS+=-lcrypto to your project file and rerun qmake.

nbkhwjm
19th November 2008, 17:41
Ok that worked to complete compile, but now SegFault on main(), i'll work through that...

Thanks

nbkhwjm
19th November 2008, 17:54
All fixed thanks