G
Guest
Hi
I am trying to build a small client-server program using OpenSSL functions. I get errors on trying to build the program using Visual Studio .Net (Visual C++ 7.0). I am new to Visual Studio environment, pls bear with me if this one is a trivial question
Here's the procedure I followed
(1) Copied libeay32.lib and ssleay32.lib to C:\program files\Microsoft Visual Studio .NET\Vc7\li
(2) Copied the OpenSSL header files to c:\program files\MicrosoftVisual Studio .NET\Vc7\include\openssl folde
(3) On building the program, I get the following errors
SSL error LNK2019: unresolved external symbol _ERR_print_errors_fp referenced in function _handle_erro
SSL error LNK2019: unresolved external symbol _SSL_load_error_strings referenced in function _init_OpenSS
SSL error LNK2019: unresolved external symbol _SSL_library_init referenced in function _init_OpenSS
SSL error LNK2019: unresolved external symbol _THREAD_setup referenced in function _init_OpenSS
SSL error LNK2019: unresolved external symbol _BIO_read referenced in function _do_server_loo
SSL error LNK2019: unresolved external symbol _ERR_remove_state referenced in function _server_threa
SSL error LNK2019: unresolved external symbol _BIO_free referenced in function _server_threa
SSL error LNK2019: unresolved external symbol _BIO_pop referenced in function _mai
SSL error LNK2019: unresolved external symbol _BIO_ctrl referenced in function _mai
SSL error LNK2019: unresolved external symbol _BIO_new_accept referenced in function _mai
SSL fatal error LNK1120: 10 unresolved external
I understand that the tool is unable to obtain symbols for these SSL functions. Isn't it sufficient that I copy these libraries to the location specified in step (1) ? Would this suffice as it's in the standard path where Visual Studio should look for the library ? Am I overlooking some cruical aspect here
Any help in this regard would be much appreciated
Thanks
Krishnan
Here's the complete program
------------------------------------------------------------------------------
Server.c
#include "common.h
#define CERTFILE "server.pem
SSL_CTX *setup_server_ctx(void
SSL_CTX *ctx
ctx = SSL_CTX_new(SSLv23_method( ))
if (SSL_CTX_use_certificate_chain_file(ctx, CERTFILE) != 1
int_error("Error loading certificate from file")
if (SSL_CTX_use_PrivateKey_file(ctx, CERTFILE, SSL_FILETYPE_PEM
!= 1
int_error("Error loading private key from file")
return ctx
int do_server_loop(SSL *ssl
int err, nread
char buf[80]
d
for (nread = 0; nread < sizeof(buf); nread += err
err = SSL_read(ssl, buf + nread, sizeof(buf) - nread)
if (err <= 0
break
fprintf(stdout, "%s", buf)
while (err > 0)
return (SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) ? 1 : 0
void THREAD_CC server_thread(void *arg
SSL *ssl = (SSL *)arg
#ifndef WIN3
pthread_detach(pthread_self( ))
#endi
if (SSL_accept(ssl) <= 0
int_error("Error accepting SSL connection")
fprintf(stderr, "SSL Connection opened\n")
if (do_server_loop(ssl)
SSL_shutdown(ssl)
els
SSL_clear(ssl)
fprintf(stderr, "SSL Connection closed\n")
SSL_free(ssl)
ERR_remove_state(0)
#ifdef WIN3
_endthread( )
#endi
int main(int argc, char *argv[]
BIO *acc, *client
SSL *ssl
SSL_CTX *ctx
THREAD_TYPE tid
init_OpenSSL( )
seed_prng( )
ctx = setup_server_ctx( )
acc = BIO_new_accept(PORT)
if (!acc
int_error("Error creating server socket")
if (BIO_do_accept(acc) <= 0
int_error("Error binding server socket")
for (;;
if (BIO_do_accept(acc) <= 0
int_error("Error accepting connection")
client = BIO_pop(acc)
if (!(ssl = SSL_new(ctx))
int_error("Error creating SSL context")
SSL_set_bio(ssl, client, client)
THREAD_CREATE(tid, (void *)server_thread, ssl)
}
SSL_CTX_free(ctx);
BIO_free(acc);
return 0;
}
--------------------------------------------------------------------------------
Common.h
#ifndef COMMON_H
#define COMMON_H
#include <string.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include "reentrant.h"
#ifndef WIN32
#include <pthread.h>
#define THREAD_CC
#define THREAD_TYPE pthread_t
#define THREAD_CREATE(tid, entry, arg) pthread_create(&(tid), NULL, (entry), (arg))
#else
#include <windows.h>
#define THREAD_CC __cdecl
#define THREAD_TYPE DWORD
#define THREAD_CREATE(tid, entry, arg) do { _beginthread((entry), 0,
(arg)); (tid) =
GetCurrentThreadId(); } while (0)
#endif
#define PORT "16001"
#define SERVER "localhost"
#define CLIENT "localhost"
#define int_error(msg) handle_error(__FILE__, __LINE__, msg)
void handle_error(const char *file, int lineno, const char *msg);
void init_OpenSSL(void);
int verify_callback(int ok, X509_STORE_CTX *store);
long post_connection_check(SSL *ssl, char *host);
void seed_prng(void);
#endif /* COMMON_H */
--------------------------------------------------------------------------------
I am trying to build a small client-server program using OpenSSL functions. I get errors on trying to build the program using Visual Studio .Net (Visual C++ 7.0). I am new to Visual Studio environment, pls bear with me if this one is a trivial question
Here's the procedure I followed
(1) Copied libeay32.lib and ssleay32.lib to C:\program files\Microsoft Visual Studio .NET\Vc7\li
(2) Copied the OpenSSL header files to c:\program files\MicrosoftVisual Studio .NET\Vc7\include\openssl folde
(3) On building the program, I get the following errors
SSL error LNK2019: unresolved external symbol _ERR_print_errors_fp referenced in function _handle_erro
SSL error LNK2019: unresolved external symbol _SSL_load_error_strings referenced in function _init_OpenSS
SSL error LNK2019: unresolved external symbol _SSL_library_init referenced in function _init_OpenSS
SSL error LNK2019: unresolved external symbol _THREAD_setup referenced in function _init_OpenSS
SSL error LNK2019: unresolved external symbol _BIO_read referenced in function _do_server_loo
SSL error LNK2019: unresolved external symbol _ERR_remove_state referenced in function _server_threa
SSL error LNK2019: unresolved external symbol _BIO_free referenced in function _server_threa
SSL error LNK2019: unresolved external symbol _BIO_pop referenced in function _mai
SSL error LNK2019: unresolved external symbol _BIO_ctrl referenced in function _mai
SSL error LNK2019: unresolved external symbol _BIO_new_accept referenced in function _mai
SSL fatal error LNK1120: 10 unresolved external
I understand that the tool is unable to obtain symbols for these SSL functions. Isn't it sufficient that I copy these libraries to the location specified in step (1) ? Would this suffice as it's in the standard path where Visual Studio should look for the library ? Am I overlooking some cruical aspect here
Any help in this regard would be much appreciated
Thanks
Krishnan
Here's the complete program
------------------------------------------------------------------------------
Server.c
#include "common.h
#define CERTFILE "server.pem
SSL_CTX *setup_server_ctx(void
SSL_CTX *ctx
ctx = SSL_CTX_new(SSLv23_method( ))
if (SSL_CTX_use_certificate_chain_file(ctx, CERTFILE) != 1
int_error("Error loading certificate from file")
if (SSL_CTX_use_PrivateKey_file(ctx, CERTFILE, SSL_FILETYPE_PEM
!= 1
int_error("Error loading private key from file")
return ctx
int do_server_loop(SSL *ssl
int err, nread
char buf[80]
d
for (nread = 0; nread < sizeof(buf); nread += err
err = SSL_read(ssl, buf + nread, sizeof(buf) - nread)
if (err <= 0
break
fprintf(stdout, "%s", buf)
while (err > 0)
return (SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) ? 1 : 0
void THREAD_CC server_thread(void *arg
SSL *ssl = (SSL *)arg
#ifndef WIN3
pthread_detach(pthread_self( ))
#endi
if (SSL_accept(ssl) <= 0
int_error("Error accepting SSL connection")
fprintf(stderr, "SSL Connection opened\n")
if (do_server_loop(ssl)
SSL_shutdown(ssl)
els
SSL_clear(ssl)
fprintf(stderr, "SSL Connection closed\n")
SSL_free(ssl)
ERR_remove_state(0)
#ifdef WIN3
_endthread( )
#endi
int main(int argc, char *argv[]
BIO *acc, *client
SSL *ssl
SSL_CTX *ctx
THREAD_TYPE tid
init_OpenSSL( )
seed_prng( )
ctx = setup_server_ctx( )
acc = BIO_new_accept(PORT)
if (!acc
int_error("Error creating server socket")
if (BIO_do_accept(acc) <= 0
int_error("Error binding server socket")
for (;;
if (BIO_do_accept(acc) <= 0
int_error("Error accepting connection")
client = BIO_pop(acc)
if (!(ssl = SSL_new(ctx))
int_error("Error creating SSL context")
SSL_set_bio(ssl, client, client)
THREAD_CREATE(tid, (void *)server_thread, ssl)
}
SSL_CTX_free(ctx);
BIO_free(acc);
return 0;
}
--------------------------------------------------------------------------------
Common.h
#ifndef COMMON_H
#define COMMON_H
#include <string.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include "reentrant.h"
#ifndef WIN32
#include <pthread.h>
#define THREAD_CC
#define THREAD_TYPE pthread_t
#define THREAD_CREATE(tid, entry, arg) pthread_create(&(tid), NULL, (entry), (arg))
#else
#include <windows.h>
#define THREAD_CC __cdecl
#define THREAD_TYPE DWORD
#define THREAD_CREATE(tid, entry, arg) do { _beginthread((entry), 0,
(arg)); (tid) =
GetCurrentThreadId(); } while (0)
#endif
#define PORT "16001"
#define SERVER "localhost"
#define CLIENT "localhost"
#define int_error(msg) handle_error(__FILE__, __LINE__, msg)
void handle_error(const char *file, int lineno, const char *msg);
void init_OpenSSL(void);
int verify_callback(int ok, X509_STORE_CTX *store);
long post_connection_check(SSL *ssl, char *host);
void seed_prng(void);
#endif /* COMMON_H */
--------------------------------------------------------------------------------