当前位置: 编程技术>c/c++/嵌入式
使用pthread库实现openssl多线程ssl服务端和客户端
来源: 互联网 发布时间:2014-10-23
本文导语: 服务端代码如下: 代码如下:#include #include #include #include #ifndef _WIN32#include #include #include #include #include #include #else#include #include #endif#include "pthread.h"#include #include #include #include #include #include #define CERTF "certs/sslservercert.pem"#define...
服务端代码如下:
代码如下:
#include
#include
#include
#include
#ifndef _WIN32
#include
#include
#include
#include
#include
#include
#else
#include
#include
#endif
#include "pthread.h"
#include
#include
#include
#include
#include
#include
#define CERTF "certs/sslservercert.pem"
#define KEYF "certs/sslserverkey.pem"
#define CAFILE "certs/cacert.pem"
pthread_mutex_t mlock=PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t *lock_cs;
static long *lock_count;
#define CHK_NULL(x) if ((x)==NULL) { printf("nulln"); }
#define CHK_ERR(err,s) if ((err)==-1) { printf(" -1 n"); }
#define CHK_SSL(err) if ((err)==-1) { printf(" -1 n");}
#define CAFILE "certs/cacert.pem"
int verify_callback_server(int ok, X509_STORE_CTX *ctx)
{
printf("verify_callback_server n");
return ok;
}
int SSL_CTX_use_PrivateKey_file_pass(SSL_CTX *ctx,char *filename,char *pass)
{
EVP_PKEY *pkey=NULL;
BIO *key=NULL;
key=BIO_new(BIO_s_file());
BIO_read_filename(key,filename);
pkey=PEM_read_bio_PrivateKey(key,NULL,NULL,pass);
if(pkey==NULL)
{
printf("PEM_read_bio_PrivateKey err");
return -1;
}
if (SSL_CTX_use_PrivateKey(ctx,pkey)