-
Notifications
You must be signed in to change notification settings - Fork 203
/
opensslbio.cpp
71 lines (63 loc) · 1.83 KB
/
opensslbio.cpp
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
#include "config.h"
#include <string.h>
#include "mytime.h"
#include "opensslbio.h"
#if OPENSSL
static SSL_SESSION *sess = NULL;
int ssl_init_info(int *server_fd,ssl_info *sslinfo)
{
#if OPENSSLDL
if(SslMethodV23){
sslinfo->ctx = (SSL_CTX*)SslCtxNew (SslMethodV23());
}else if(TlsMethod){
sslinfo->ctx = (SSL_CTX*)SslCtxNew (TlsMethod());
}else{
printf("openssl error\r\n");
}
SslCtxCtrl(sslinfo->ctx,SSL_CTRL_SET_SESS_CACHE_MODE,SSL_SESS_CACHE_CLIENT,NULL);
sslinfo->ssl = SslNew(sslinfo->ctx);
if (sess != NULL)
{
SsLSetSession(sslinfo->ssl, sess);
}
SslSetFd(sslinfo->ssl,*server_fd);
SslSetConnectState (sslinfo->ssl);
int r=0;
while ((r = SslDoHandshake(sslinfo->ssl)) != 1) {
int err = SslGetError(sslinfo->ssl, r);
if (err == SSL_ERROR_WANT_WRITE) {
} else if (err == SSL_ERROR_WANT_READ) {
} else {
return -1;
}
//CPU sleep
sleeps(1);
}
sess = SsLGet1Session(sslinfo->ssl);
#else
sslinfo->ctx = (SSL_CTX*)SSL_CTX_new (SSLv23_method());
SSL_CTX_set_session_cache_mode(sslinfo->ctx,SSL_SESS_CACHE_CLIENT);
sslinfo->ssl = SSL_new(sslinfo->ctx);
if (sess != NULL)
{
SSL_set_session(sslinfo->ssl, sess);
}
SSL_set_fd(sslinfo->ssl,*server_fd);
SSL_set_connect_state (sslinfo->ssl);
int r=0;
//·
while ((r = SSL_do_handshake(sslinfo->ssl)) != 1) {
int err = SSL_get_error(sslinfo->ssl, r);
if (err == SSL_ERROR_WANT_WRITE) {
} else if (err == SSL_ERROR_WANT_READ) {
} else {
return -1;
}
//CPU sleep
sleeps(1);
}
sess = SSL_get1_session(sslinfo->ssl);
#endif // OPENSSLDL
return 0;
}
#endif