本文整理汇总了C++中do_handshake函数的典型用法代码示例。如果您正苦于以下问题:C++ do_handshake函数的具体用法?C++ do_handshake怎么用?C++ do_handshake使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了do_handshake函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: client_handshake_read_cb
static void client_handshake_read_cb(uv_stream_t* stream, ssize_t nread, uv_buf_t buf)
{
server_ctx *ctx = (server_ctx *)stream->data;
if (nread < 0) {
if (buf.len) // If buf is set, we need to free it
free(buf.base);
uv_close((uv_handle_t*)stream, handshake_client_close_cb); // Then close the connection
return;
} else if (!nread) {
free(buf.base);
return;
}
memcpy(ctx->handshake_buffer + ctx->buffer_len, buf.base, nread);
shadow_decrypt(ctx->handshake_buffer + ctx->buffer_len, &ctx->encoder, nread);
ctx->buffer_len += nread;
if (!ctx->handshake_buffer) {
FATAL("Should not call this anymore");
}
free(buf.base);
do_handshake(stream);
}
开发者ID:sqbing,项目名称:shadowsocks-libuv,代码行数:26,代码来源:server.c
示例2: check_rehandshake
static void
check_rehandshake (socket_st * socket, int ret)
{
if (socket->secure && ret == GNUTLS_E_REHANDSHAKE)
{
/* There is a race condition here. If application
* data is sent after the rehandshake request,
* the server thinks we ignored his request.
* This is a bad design of this client.
*/
printf ("*** Received rehandshake request\n");
/* gnutls_alert_send( session, GNUTLS_AL_WARNING, GNUTLS_A_NO_RENEGOTIATION); */
ret = do_handshake (socket);
if (ret == 0)
{
printf ("*** Rehandshake was performed.\n");
}
else
{
printf ("*** Rehandshake Failed.\n");
}
}
}
开发者ID:Chronic-Dev,项目名称:gnutls,代码行数:25,代码来源:cli.c
示例3: test_version_rollback
test_code_t
test_version_rollback (gnutls_session session)
{
int ret;
if (tls1_ok == 0)
return TEST_IGNORE;
/* here we enable both SSL 3.0 and TLS 1.0
* and we connect using a 3.1 client hello version,
* and a 3.0 record version. Some implementations
* are buggy (and vulnerable to man in the middle
* attacks which allow a version downgrade) and this
* connection will fail.
*/
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_ALL_PROTOCOLS (session);
ADD_ALL_MACS (session);
ADD_ALL_KX (session);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
_gnutls_record_set_default_version (session, 3, 0);
ret = do_handshake (session);
if (ret != TEST_SUCCEED)
return ret;
if (tls1_ok != 0 && gnutls_protocol_get_version (session) == GNUTLS_SSL3)
return TEST_FAILED;
return TEST_SUCCEED;
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:32,代码来源:tests.c
示例4: assert
/* 发送数据
* * 返回: < 0 错误,0 成功,1 需要重读,2 需要重写
*/
int32 ssl_io::send()
{
assert( "io send fd invalid",_fd > 0 );
if ( !_handshake ) return do_handshake();
size_t bytes = _send->data_size();
assert( "io send without data",bytes > 0 );
int32 len = SSL_write( X_SSL( _ssl_ctx ),_send->data_pointer(),bytes );
if ( expect_true(len > 0) )
{
_send->subtract( len );
return ((size_t)len) == bytes ? 0 : 2;
}
int32 ecode = SSL_get_error( X_SSL( _ssl_ctx ),len );
if ( SSL_ERROR_WANT_WRITE == ecode ) return 2;
// 非主动断开,打印错误日志
if ( (SSL_ERROR_ZERO_RETURN == ecode)
|| (SSL_ERROR_SYSCALL == ecode && 0 == errno) )
{
return -1;
}
SSL_ERROR( "ssl io send" );
return -1;
}
开发者ID:changnet,项目名称:MServer,代码行数:31,代码来源:ssl_io.cpp
示例5: test_server_cas
/* Prints the trusted server's CAs. This is only
* if the server sends a certificate request packet.
*/
test_code_t
test_server_cas (gnutls_session session)
{
int ret;
if (verbose == 0)
return TEST_IGNORE;
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_ALL_PROTOCOLS (session);
ADD_ALL_MACS (session);
ADD_ALL_KX (session);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
gnutls_certificate_client_set_retrieve_function (xcred, cert_callback);
ret = do_handshake (session);
gnutls_certificate_client_set_retrieve_function (xcred, NULL);
if (ret == TEST_FAILED)
return ret;
return TEST_SUCCEED;
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:28,代码来源:tests.c
示例6: test_certificate
test_code_t
test_certificate (gnutls_session session)
{
int ret;
if (verbose == 0)
return TEST_IGNORE;
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_ALL_PROTOCOLS (session);
ADD_ALL_MACS (session);
ADD_ALL_KX (session);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret == TEST_FAILED)
return ret;
printf ("\n");
print_cert_info (session, hostname);
return TEST_SUCCEED;
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:26,代码来源:tests.c
示例7: input_fn
/*
* TLS Server Constructor
*/
TLS_Server::TLS_Server(std::tr1::function<size_t (byte[], size_t)> input_fn,
std::tr1::function<void (const byte[], size_t)> output_fn,
const TLS_Policy& policy,
RandomNumberGenerator& rng,
const X509_Certificate& cert,
const Private_Key& cert_key) :
input_fn(input_fn),
policy(policy),
rng(rng),
writer(output_fn)
{
state = 0;
cert_chain.push_back(cert);
private_key = PKCS8::copy_key(cert_key, rng);
try {
active = false;
writer.set_version(TLS_V10);
do_handshake();
active = true;
}
catch(std::exception& e)
{
if(state)
{
delete state;
state = 0;
}
writer.alert(FATAL, HANDSHAKE_FAILURE);
throw Stream_IO_Error(std::string("TLS_Server: Handshake failed: ") +
e.what());
}
}
开发者ID:BenjaminSchiborr,项目名称:safe,代码行数:38,代码来源:tls_server.cpp
示例8: test_srp
test_code_t
test_srp (gnutls_session session)
{
int ret;
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_ALL_PROTOCOLS (session);
ADD_ALL_MACS (session);
ADD_KX (session, GNUTLS_KX_SRP);
srp_detected = 0;
gnutls_srp_set_client_credentials_function (srp_cred,
_test_srp_username_callback);
gnutls_credentials_set (session, GNUTLS_CRD_SRP, srp_cred);
ret = do_handshake (session);
gnutls_srp_set_client_credentials_function (srp_cred, NULL);
if (srp_detected != 0)
return TEST_SUCCEED;
else
return TEST_FAILED;
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:28,代码来源:tests.c
示例9: test_tls_disable
/* Advertize both TLS 1.0 and SSL 3.0. If the connection fails,
* but the previous SSL 3.0 test succeeded then disable TLS 1.0.
*/
test_code_t
test_tls_disable (gnutls_session_t session)
{
int ret;
if (tls1_ok != 0)
return TEST_IGNORE;
sprintf (prio_str,
INIT_STR ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES ":%s:" ALL_MACS
":" ALL_KX ":%s", protocol_str, rest);
_gnutls_priority_set_direct (session, prio_str);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret == TEST_FAILED)
{
/* disable TLS 1.0 */
if (ssl3_ok != 0)
{
strcpy (protocol_str, "+VERS-SSL3.0");
}
}
return ret;
}
开发者ID:MihirKulkarni,项目名称:TLS_extension,代码行数:29,代码来源:tests.c
示例10: test_tls1_1_fallback
test_code_t
test_tls1_1_fallback (gnutls_session session)
{
int ret;
if (tls1_1_ok)
return TEST_IGNORE;
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_PROTOCOL3 (session, GNUTLS_TLS1_1, GNUTLS_TLS1, GNUTLS_SSL3);
ADD_ALL_MACS (session);
ADD_ALL_KX (session);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret != TEST_SUCCEED)
return TEST_FAILED;
if (gnutls_protocol_get_version (session) == GNUTLS_TLS1)
return TEST_SUCCEED;
else if (gnutls_protocol_get_version (session) == GNUTLS_SSL3)
return TEST_UNSURE;
return TEST_FAILED;
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:27,代码来源:tests.c
示例11: test_tls1_1_fallback
test_code_t
test_tls1_1_fallback (gnutls_session_t session)
{
int ret;
if (tls1_1_ok)
return TEST_IGNORE;
sprintf (prio_str,
INIT_STR ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES
":+VERS-TLS1.1:+VERS-TLS1.0:+VERS-SSL3.0:" ALL_MACS ":" ALL_KX
":%s", rest);
_gnutls_priority_set_direct (session, prio_str);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret != TEST_SUCCEED)
return TEST_FAILED;
if (gnutls_protocol_get_version (session) == GNUTLS_TLS1)
return TEST_SUCCEED;
else if (gnutls_protocol_get_version (session) == GNUTLS_SSL3)
return TEST_UNSURE;
return TEST_FAILED;
}
开发者ID:MihirKulkarni,项目名称:TLS_extension,代码行数:27,代码来源:tests.c
示例12: test_tls_disable
/* Advertize both TLS 1.0 and SSL 3.0. If the connection fails,
* but the previous SSL 3.0 test succeeded then disable TLS 1.0.
*/
test_code_t
test_tls_disable (gnutls_session session)
{
int ret;
if (tls1_ok != 0)
return TEST_IGNORE;
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_ALL_PROTOCOLS (session);
ADD_ALL_MACS (session);
ADD_ALL_KX (session);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret == TEST_FAILED)
{
/* disable TLS 1.0 */
if (ssl3_ok != 0)
{
protocol_priority[0] = GNUTLS_SSL3;
protocol_priority[1] = 0;
}
}
return ret;
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:31,代码来源:tests.c
示例13: test_rsa_pms
test_code_t
test_rsa_pms (gnutls_session session)
{
int ret;
/* here we enable both SSL 3.0 and TLS 1.0
* and try to connect and use rsa authentication.
* If the server is old, buggy and only supports
* SSL 3.0 then the handshake will fail.
*/
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_ALL_PROTOCOLS (session);
ADD_ALL_MACS (session);
ADD_KX (session, GNUTLS_KX_RSA);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret == TEST_FAILED)
return TEST_FAILED;
if (gnutls_protocol_get_version (session) == GNUTLS_TLS1)
return TEST_SUCCEED;
return TEST_UNSURE;
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:26,代码来源:tests.c
示例14: handlerThread
void handlerThread(int csockIn)
{
int sopt = 1, csock = csockIn;
ws_ctx_t *ws_ctx;
bool useHixie = TRUE;
ws_ctx = do_handshake(csock, &useHixie);
if (ws_ctx == NULL) {
handler_msg("No connection after handshake\n");
}
else
{
settings.handler(ws_ctx, useHixie);
if (pipe_error) {
handler_emsg("Closing due to SIGPIPE\n");
}
}
if (ws_ctx) {
ws_socket_free(ws_ctx);
} else {
shutdown(csock, SHUT_RDWR);
close(csock);
}
handler_msg("handler exit\n");
}
开发者ID:dew111,项目名称:websockify,代码行数:26,代码来源:websocket.c
示例15: client_handshake_domain_resolved
static void client_handshake_domain_resolved(uv_getaddrinfo_t *resolver, int status, struct addrinfo *res)
{
server_ctx *ctx = (server_ctx *)resolver->data;
if (status) {
if (uv_last_error(ctx->client.loop).code == UV_ENOENT) {
LOGI("Resolve error, NXDOMAIN");
} else {
SHOW_UV_ERROR(ctx->client.loop);
}
HANDLE_CLOSE((uv_handle_t*)(void *)&ctx->client, handshake_client_close_cb);
uv_freeaddrinfo(res);
free(resolver);
return;
}
ctx->remote_ip = ((struct sockaddr_in*)(res->ai_addr))->sin_addr.s_addr;
if (do_handshake((uv_stream_t *)(void *)&ctx->client)) {
int n = uv_read_start((uv_stream_t *)(void *)&ctx->client, client_handshake_alloc_cb, client_handshake_read_cb);
if (n) {
HANDLE_CLOSE((uv_handle_t*)(void *)&ctx->client, handshake_client_close_cb);
SHOW_UV_ERROR(ctx->client.loop);
}
}
uv_freeaddrinfo(res);
free(resolver);
}
开发者ID:Sandalphon,项目名称:shadowsocks-libuv,代码行数:28,代码来源:server.c
示例16: SSL_set_connect_state
/* 准备连接状态
*/
int32 ssl_io::init_connect( int32 fd )
{
if ( init_ssl_ctx( fd ) < 0 ) return -1;
_fd = fd;
SSL_set_connect_state( X_SSL( _ssl_ctx ) );
return do_handshake();
}
开发者ID:changnet,项目名称:MServer,代码行数:11,代码来源:ssl_io.cpp
示例17: test_bye
test_code_t
test_bye (gnutls_session_t session)
{
int ret;
char data[20];
int secs = 6;
#ifndef _WIN32
int old;
signal (SIGALRM, got_alarm);
#endif
sprintf (prio_str, INIT_STR
ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES ":%s:" ALL_MACS ":"
ALL_KX ":%s", protocol_str, rest);
_gnutls_priority_set_direct (session, prio_str);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret == TEST_FAILED)
return ret;
ret = gnutls_bye (session, GNUTLS_SHUT_WR);
if (ret < 0)
return TEST_FAILED;
#ifndef _WIN32
old = siginterrupt (SIGALRM, 1);
alarm (secs);
#else
setsockopt ((int) gnutls_transport_get_ptr (session), SOL_SOCKET,
SO_RCVTIMEO, (char *) &secs, sizeof (int));
#endif
do
{
ret = gnutls_record_recv (session, data, sizeof (data));
}
while (ret > 0);
#ifndef _WIN32
siginterrupt (SIGALRM, old);
#else
if (WSAGetLastError () == WSAETIMEDOUT ||
WSAGetLastError () == WSAECONNABORTED)
alrm = 1;
#endif
if (ret == 0)
return TEST_SUCCEED;
if (alrm == 0)
return TEST_UNSURE;
return TEST_FAILED;
}
开发者ID:MihirKulkarni,项目名称:TLS_extension,代码行数:56,代码来源:tests.c
示例18: test_bye
test_code_t
test_bye (gnutls_session session)
{
int ret;
char data[20];
int old, secs = 6;
#ifndef _WIN32
signal (SIGALRM, got_alarm);
#endif
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_ALL_PROTOCOLS (session);
ADD_ALL_MACS (session);
ADD_ALL_KX (session);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret == TEST_FAILED)
return ret;
ret = gnutls_bye (session, GNUTLS_SHUT_WR);
if (ret < 0)
return TEST_FAILED;
#ifndef _WIN32
old = siginterrupt (SIGALRM, 1);
alarm (secs);
#else
setsockopt (gnutls_transport_get_ptr (session), SOL_SOCKET, SO_RCVTIMEO,
(char *) &secs, sizeof (int));
#endif
do
{
ret = gnutls_record_recv (session, data, sizeof (data));
}
while (ret > 0);
#ifndef _WIN32
siginterrupt (SIGALRM, old);
#else
if (WSAGetLastError () == WSAETIMEDOUT ||
WSAGetLastError () == WSAECONNABORTED)
alrm = 1;
#endif
if (ret == 0)
return TEST_SUCCEED;
if (alrm == 0)
return TEST_UNSURE;
return TEST_FAILED;
}
开发者ID:uvbs,项目名称:SupportCenter,代码行数:56,代码来源:tests.c
示例19: execute_test
static int execute_test(SSL_TEST_FIXTURE fixture)
{
int ret = 0;
SSL_CTX *server_ctx = NULL, *server2_ctx = NULL, *client_ctx = NULL;
SSL_TEST_CTX *test_ctx = NULL;
HANDSHAKE_RESULT result;
test_ctx = SSL_TEST_CTX_create(conf, fixture.test_app);
if (test_ctx == NULL)
goto err;
#ifndef OPENSSL_NO_DTLS
if (test_ctx->method == SSL_TEST_METHOD_DTLS) {
server_ctx = SSL_CTX_new(DTLS_server_method());
if (test_ctx->servername_callback != SSL_TEST_SERVERNAME_CB_NONE) {
server2_ctx = SSL_CTX_new(DTLS_server_method());
OPENSSL_assert(server2_ctx != NULL);
}
client_ctx = SSL_CTX_new(DTLS_client_method());
}
#endif
if (test_ctx->method == SSL_TEST_METHOD_TLS) {
server_ctx = SSL_CTX_new(TLS_server_method());
if (test_ctx->servername_callback != SSL_TEST_SERVERNAME_CB_NONE) {
server2_ctx = SSL_CTX_new(TLS_server_method());
OPENSSL_assert(server2_ctx != NULL);
}
client_ctx = SSL_CTX_new(TLS_client_method());
}
OPENSSL_assert(server_ctx != NULL && client_ctx != NULL);
OPENSSL_assert(CONF_modules_load(conf, fixture.test_app, 0) > 0);
if (!SSL_CTX_config(server_ctx, "server")
|| !SSL_CTX_config(client_ctx, "client")) {
goto err;
}
if (server2_ctx != NULL && !SSL_CTX_config(server2_ctx, "server2"))
goto err;
result = do_handshake(server_ctx, server2_ctx, client_ctx, test_ctx);
ret = check_test(result, test_ctx);
err:
CONF_modules_unload(0);
SSL_CTX_free(server_ctx);
SSL_CTX_free(server2_ctx);
SSL_CTX_free(client_ctx);
SSL_TEST_CTX_free(test_ctx);
if (ret != 1)
ERR_print_errors_fp(stderr);
return ret;
}
开发者ID:Bloody99,项目名称:openssl,代码行数:56,代码来源:ssl_test.c
示例20: worker_cb
static void worker_cb(int fd, short flags, void *arg)
{
struct Worker *w = arg;
const char *err;
char buf[128];
int res;
size_t outlen;
w->pending = 0;
if (w->wstate == HANDSHAKE) {
err = do_handshake(w, fd);
add_error(w, err);
} else if (w->wstate == CONNECTED) {
if (flags & EV_READ) {
res = tls_read(w->ctx, buf, sizeof buf, &outlen);
if (res == TLS_READ_AGAIN) {
wait_for_event(w, EV_READ);
} else if (res == TLS_WRITE_AGAIN) {
wait_for_event(w, EV_WRITE);
} else if (res == 0) {
if (outlen > 0 && w->is_server) {
tls_write(w->ctx, "END", 3, &outlen);
w->wstate = CLOSED;
} else if (outlen == 0) {
w->wstate = CLOSED;
} else {
wait_for_event(w, EV_READ);
}
} else {
add_error(w, "bad pkt");
}
} else {
add_error(w, "EV_WRITE?");
}
}
if (w->wstate == CLOSED && w->ctx) {
res = tls_close(w->ctx);
if (res == 0) {
tls_free(w->ctx);
w->ctx = NULL;
} else if (res == TLS_READ_AGAIN) {
wait_for_event(w, EV_READ);
} else if (res == TLS_WRITE_AGAIN) {
wait_for_event(w, EV_WRITE);
} else {
tls_free(w->ctx);
w->ctx = NULL;
}
}
if (!w->pending && w->ctx) {
errx(1, "missed event setup: %s flags=%d state=%d", w->is_server ? "S":"C", flags, w->wstate);
}
return;
}
开发者ID:greenplum-db,项目名称:libusual,代码行数:55,代码来源:test_tls.c
注:本文中的do_handshake函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论