-
Notifications
You must be signed in to change notification settings - Fork 204
/
opensslbio.h
81 lines (70 loc) · 1.63 KB
/
opensslbio.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef OPENSSLBIO_H_INCLUDED
#define OPENSSLBIO_H_INCLUDED
#include "config.h"
#include<malloc.h>
#include<openssl/ssl.h>
#include<openssl/bio.h>
#include<openssl/err.h>
struct ssl_info
{
SSL *ssl;
SSL_CTX *ctx;
};
int ssl_init_info(int *server_fd,ssl_info *sslinfo);
int ssl_free_info(ssl_info *sslinfo);
typedef SSL ssl_context;
#if OPENSSLDL
#include "openssldl.h"
#endif // OPENSSLDL
inline int SslRecv(SSL* ssl, unsigned char* buffer, int ilen)
{
#if OPENSSLDL
int r=SslRead(ssl,buffer,ilen);
switch(SslGetError(ssl,r)){
#else
int r=SSL_read(ssl,buffer,ilen);
switch(SSL_get_error(ssl,r)){
#endif
case SSL_ERROR_NONE:
return r;
case SSL_ERROR_ZERO_RETURN:
return 0;
case SSL_ERROR_WANT_READ:
return -1;
case SSL_ERROR_WANT_WRITE:
return -1;
}
return -2;
}
inline int ssl_free_info(ssl_info *sslinfo)
{
#if OPENSSLDL
// SslShutdown( sslinfo->ssl );
SslFree( sslinfo->ssl );
SslCtxFree( sslinfo->ctx );
#else
SSL_shutdown( sslinfo->ssl );
SSL_free( sslinfo->ssl );
SSL_CTX_free( sslinfo->ctx );
#endif //
return 0;
}
inline int init_ssl_session(){
return 0;
}
inline int ssl_lib_init(){
#if OPENSSLDL
const char *err=AbreSSL();
if(err!=NULL)
{
printf("OpenSSL init fail.\r\nPlease check if the OpenSSL is installed. \r\n%s not found.\r\n",err);
exit(0);
}
#else
SSL_library_init();
SSL_load_error_strings();
OpenSSL_add_all_algorithms();
#endif
return 0;
}
#endif // OPENSSLBIO_H_INCLUDED