本文整理汇总了C++中SSL_set_connect_state函数的典型用法代码示例。如果您正苦于以下问题:C++ SSL_set_connect_state函数的具体用法?C++ SSL_set_connect_state怎么用?C++ SSL_set_connect_state使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SSL_set_connect_state函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_connect_callback
void on_connect_callback(uv_connect_t* con, int status) {
Client* c = static_cast<Client*>(con->data);
if(status == -1) {
printf("ERROR: on_connect_callback \n");//, uv_err_name(uv_last_error(c->loop)));
::exit(0);
}
int r = uv_read_start((uv_stream_t*)&c->socket, on_alloc_callback, on_read_callback);
if(r == -1) {
printf("ERROR: uv_read_start error: \n");//, uv_err_name(uv_last_error(c->loop)));
::exit(0);
}
const char* http_request_tpl = "" \
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
"User-Agent: uv_www_client/0.1\r\n"
"Accept: */*\r\n"
"Connection: close\r\n"
"\r\n";
char http_request[1024];
sprintf(http_request, http_request_tpl, c->page, c->host);
c->addAppData(http_request);
printf("APP DATA: %zu\n", c->buffer_out.size());
c->ssl = SSL_new(c->ssl_ctx);
c->read_bio = BIO_new(BIO_s_mem());
c->write_bio = BIO_new(BIO_s_mem());
SSL_set_bio(c->ssl, c->read_bio, c->write_bio);
SSL_set_connect_state(c->ssl);
r = SSL_do_handshake(c->ssl);
on_event(c);
}
示例2: httpconnection_on_connect
void httpconnection_on_connect(uv_connect_t* req, int status) {
HTTPConnection* c = static_cast<HTTPConnection*>(req->data);
if(status == -1) {
RX_ERROR("> cannot connect: %s:", uv_strerror(uv_last_error(c->loop)));
RX_ERROR("@ todo should be `delete` the connection here?");
return;
}
int r = uv_read_start((uv_stream_t*)c->sock, httpconnection_on_alloc, httpconnection_on_read);
if(r) {
RX_ERROR("> uv_read_start() failed: %s", uv_strerror(uv_last_error(c->loop)));
RX_ERROR("@ todo should be `delete` the connection here?");
return;
}
if(c->ssl) {
SSL_set_connect_state(c->ssl);
SSL_do_handshake(c->ssl);
c->buffer->update();
}
// trigger the output buffer
c->buffer->flushOutputBuffer();
}
示例3: swSSL_create
int swSSL_create(swConnection *conn, SSL_CTX* ssl_context, int flags)
{
SSL *ssl = SSL_new(ssl_context);
if (ssl == NULL)
{
swWarn("SSL_new() failed.");
return SW_ERR;
}
if (!SSL_set_fd(ssl, conn->fd))
{
long err = ERR_get_error();
swWarn("SSL_set_fd() failed. Error: %s[%ld]", ERR_reason_error_string(err), err);
return SW_ERR;
}
if (flags & SW_SSL_CLIENT)
{
SSL_set_connect_state(ssl);
}
else
{
SSL_set_accept_state(ssl);
}
conn->ssl = ssl;
conn->ssl_state = 0;
return SW_OK;
}
示例4: er_dtls_connection_start
void er_dtls_connection_start(ErDtlsConnection *self, gboolean is_client)
{
g_return_if_fail(ER_IS_DTLS_CONNECTION(self));
ErDtlsConnectionPrivate *priv = self->priv;
g_return_if_fail(priv->send_closure);
g_return_if_fail(priv->ssl);
g_return_if_fail(priv->bio);
LOG_TRACE(self, "locking @ start");
g_mutex_lock(&priv->mutex);
LOG_TRACE(self, "locked @ start");
priv->is_alive = TRUE;
priv->timeout_set = FALSE;
priv->bio_buffer = NULL;
priv->bio_buffer_len = 0;
priv->bio_buffer_offset = 0;
priv->keys_exported = FALSE;
priv->is_client = is_client;
if (priv->is_client) {
SSL_set_connect_state(priv->ssl);
} else {
SSL_set_accept_state(priv->ssl);
}
log_state(self, "initial state set");
openssl_poll(self);
log_state(self, "first poll done");
priv->thread = NULL;
LOG_TRACE(self, "unlocking @ start");
g_mutex_unlock(&priv->mutex);
}
示例5: key_state_ssl_init
void
key_state_ssl_init(struct key_state_ssl *ks_ssl, const struct tls_root_ctx *ssl_ctx, bool is_server, struct tls_session *session)
{
ASSERT(NULL != ssl_ctx);
ASSERT(ks_ssl);
CLEAR (*ks_ssl);
ks_ssl->ssl = SSL_new (ssl_ctx->ctx);
if (!ks_ssl->ssl)
msg (M_SSLERR, "SSL_new failed");
/* put session * in ssl object so we can access it
from verify callback*/
SSL_set_ex_data (ks_ssl->ssl, mydata_index, session);
ks_ssl->ssl_bio = getbio (BIO_f_ssl (), "ssl_bio");
ks_ssl->ct_in = getbio (BIO_s_mem (), "ct_in");
ks_ssl->ct_out = getbio (BIO_s_mem (), "ct_out");
#ifdef BIO_DEBUG
bio_debug_oc ("open ssl_bio", ks_ssl->ssl_bio);
bio_debug_oc ("open ct_in", ks_ssl->ct_in);
bio_debug_oc ("open ct_out", ks_ssl->ct_out);
#endif
if (is_server)
SSL_set_accept_state (ks_ssl->ssl);
else
SSL_set_connect_state (ks_ssl->ssl);
SSL_set_bio (ks_ssl->ssl, ks_ssl->ct_in, ks_ssl->ct_out);
BIO_set_ssl (ks_ssl->ssl_bio, ks_ssl->ssl, BIO_NOCLOSE);
}
示例6: Curl_SSL_Close
/*
* This function is called when an SSL connection is closed.
*/
void Curl_SSL_Close(struct connectdata *conn)
{
if(conn->ssl[FIRSTSOCKET].use) {
int i;
/*
ERR_remove_state() frees the error queue associated with
thread pid. If pid == 0, the current thread will have its
error queue removed.
Since error queue data structures are allocated
automatically for new threads, they must be freed when
threads are terminated in oder to avoid memory leaks.
*/
ERR_remove_state(0);
for(i=0; i<2; i++) {
struct ssl_connect_data *connssl = &conn->ssl[i];
if(connssl->handle) {
(void)SSL_shutdown(connssl->handle);
SSL_set_connect_state(connssl->handle);
SSL_free (connssl->handle);
connssl->handle = NULL;
}
if(connssl->ctx) {
SSL_CTX_free (connssl->ctx);
connssl->ctx = NULL;
}
connssl->use = FALSE; /* get back to ordinary socket usage */
}
}
}
示例7: tnet_dtls_socket_set_setup
int tnet_dtls_socket_set_setup(tnet_dtls_socket_handle_t* handle, tnet_dtls_setup_t setup)
{
#if !HAVE_OPENSSL || !HAVE_OPENSSL_DTLS
TSK_DEBUG_ERROR("OpenSSL or DTLS not enabled");
return -200;
#else
tnet_dtls_socket_t* socket = handle;
if (!socket){
TSK_DEBUG_ERROR("Invalid parameter");
return -1;
}
switch ((socket->setup = setup)){
case tnet_dtls_setup_passive:
SSL_set_accept_state(socket->ssl);
break;
case tnet_dtls_setup_active:
case tnet_dtls_setup_actpass:
case tnet_dtls_setup_none:
if (setup != tnet_dtls_setup_active){
TSK_DEBUG_WARN("using setup=%s is not a good idea", TNET_DTLS_SETUP_NAMES[setup]);
}
SSL_set_connect_state(socket->ssl);
break;
default:
TSK_DEBUG_ERROR("%d not valid value for DTLS setup", (int32_t)setup);
break;
}
return 0;
#endif
}
示例8: DEBUGP
/* Perform the SSL handshake on file descriptor FD, which is assumed
to be connected to an SSL server. The SSL handle provided by
OpenSSL is registered with the file descriptor FD using
fd_register_transport, so that subsequent calls to fd_read,
fd_write, etc., will use the corresponding SSL functions.
Returns 1 on success, 0 on failure. */
int HttpsRetriever::ssl_connect(int fd )
{
SSL *ssl;
DEBUGP (("Initiating SSL handshake.\n"));
assert (ssl_ctx != NULL);
ssl = SSL_new (ssl_ctx);
if (!ssl)
goto error;
if (!SSL_set_fd (ssl, fd))
goto error;
SSL_set_connect_state (ssl);
if (SSL_connect (ssl) <= 0 || ssl->state != SSL_ST_OK)
goto error;
/* Register FD with Wget's transport layer, i.e. arrange that our
functions are used for reading, writing, and polling. */
//fd_register_transport (fd, openssl_read, openssl_write, openssl_poll,
// openssl_peek, openssl_close, ssl);
//DEBUGP (("Handshake successful; connected socket %d to SSL handle 0x%0*lx\n",
//fd, PTR_FORMAT (ssl)));
return 1;
error:
DEBUGP (("SSL handshake failed.\n"));
print_errors ();
if (ssl)
SSL_free (ssl);
return 0;
return -1 ;
}
示例9: openssl_init_info
int openssl_init_info(int server_fd,openssl_info *sslinfo)
{
sslinfo->ctx = (SSL_CTX*)SSL_CTX_new (SSLv3_method());
sslinfo->ssl = SSL_new(sslinfo->ctx);
SSL_set_fd(sslinfo->ssl,server_fd);
//·Ç×èÈû
SSL_set_connect_state (sslinfo->ssl);
//SSL_connect(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);
}
return 0;
}
示例10: io_start_tls
int
io_start_tls(struct io *io, void *ssl)
{
int mode;
mode = io->flags & IO_RW;
if (mode == 0 || mode == IO_RW)
errx(1, "io_start_tls(): full-duplex or unset");
if (io->ssl)
errx(1, "io_start_tls(): SSL already started");
io->ssl = ssl;
if (SSL_set_fd(io->ssl, io->sock) == 0) {
ssl_error("io_start_ssl:SSL_set_fd");
return (-1);
}
if (mode == IO_WRITE) {
io->state = IO_STATE_CONNECT_SSL;
SSL_set_connect_state(io->ssl);
io_reset(io, EV_WRITE, io_dispatch_connect_ssl);
} else {
io->state = IO_STATE_ACCEPT_SSL;
SSL_set_accept_state(io->ssl);
io_reset(io, EV_READ, io_dispatch_accept_ssl);
}
return (0);
}
示例11: setup_ssl
/** setup SSL on the connection */
static SSL*
setup_ssl(SSL_CTX* ctx, int fd)
{
SSL* ssl;
X509* x;
int r;
ssl = SSL_new(ctx);
if(!ssl)
ssl_err("could not SSL_new");
SSL_set_connect_state(ssl);
(void)SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
if(!SSL_set_fd(ssl, fd))
ssl_err("could not SSL_set_fd");
while(1) {
ERR_clear_error();
if( (r=SSL_do_handshake(ssl)) == 1)
break;
r = SSL_get_error(ssl, r);
if(r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE)
ssl_err("SSL handshake failed");
/* wants to be called again */
}
/* check authenticity of server */
if(SSL_get_verify_result(ssl) != X509_V_OK)
ssl_err("SSL verification failed");
x = SSL_get_peer_certificate(ssl);
if(!x)
ssl_err("Server presented no peer certificate");
X509_free(x);
return ssl;
}
示例12: TraceS
void SSLSocket::onConnect(uv_connect_t* handle, int status)
{
TraceS(this) << "On connect" << endl;
if (status) {
setUVError("SSL connect error", status);
return;
}
else
readStart();
SSL* ssl = SSL_new(_context->sslContext());
// TODO: Automatic SSL session handling.
// Maybe add a stored session to the network manager.
if (_session)
SSL_set_session(ssl, _session->sslSession());
SSL_set_connect_state(ssl);
SSL_do_handshake(ssl);
_sslAdapter.init(ssl);
_sslAdapter.flush();
//emitConnect();
onSocketConnect();
TraceS(this) << "On connect: OK" << endl;
}
示例13: sock_SSL_connect
int sock_SSL_connect(SSL **ssl_con, int sockfd)
{
int ssl_err;
SSL_CTX *ssl_ctx = NULL;
ssl_ctx = SSL_CTX_new(SSLv3_client_method());
if(!ssl_ctx) {
net_log(NET_LOG_ERR, "sock_SSL_connect: !ssl_ctx\n");
return WSOCK_ERROR;
}
*ssl_con = SSL_new(ssl_ctx);
if(!(*ssl_con)) {
net_log(NET_LOG_ERR, "sock_SSL_connect: SSL_new() failed.\n");
SSL_CTX_free(ssl_ctx);
return WSOCK_ERROR;
}
SSL_set_fd (*ssl_con, sockfd);
SSL_set_connect_state(*ssl_con);
ssl_err = SSL_connect(*ssl_con);
if(ssl_err < 0)
SSL_set_shutdown(*ssl_con,SSL_SENT_SHUTDOWN);
if(ssl_err <= 0) {
net_log(NET_LOG_ERR, "sock_SSL_connect: SSL_connect() failed.\n");
SSL_free(*ssl_con);
SSL_CTX_free(ssl_ctx);
return WSOCK_ERROR;
}
return WSOCK_OK;
}
示例14: throw
CTLSConnection::CTLSConnection(const CString &hostname, const CString &service)
throw(CTCPConnection::CConnectException)
: CTCPConnection(hostname, service),
m_TLSContext(NULL), m_TLSConnection(NULL)
{
initialize();
int ret = SSL_connect(m_TLSConnection);
if(ret == 0)
{
deallocate();
throw CConnectException(CString(
"TLS handshake failed: ") + getError(ret));
}
if(ret < 0)
{
deallocate();
throw CConnectException(CString(
"TLS handshake failed because of protocol error or connection failure: "
) + getError(ret));
}
if(ret != 1)
{
deallocate();
throw CConnectException(CString::format(
"TLS handshake returned unknown return value %d", 256, ret));
}
SSL_set_connect_state(m_TLSConnection);
}
示例15: JANUS_LOG
janus_dtls_srtp *janus_dtls_srtp_create(void *ice_component, janus_dtls_role role) {
janus_ice_component *component = (janus_ice_component *)ice_component;
if(component == NULL) {
JANUS_LOG(LOG_ERR, "No component, no DTLS...\n");
return NULL;
}
janus_ice_stream *stream = component->stream;
if(!stream) {
JANUS_LOG(LOG_ERR, "No stream, no DTLS...\n");
return NULL;
}
janus_ice_handle *handle = stream->handle;
if(!handle || !handle->agent) {
JANUS_LOG(LOG_ERR, "No handle/agent, no DTLS...\n");
return NULL;
}
janus_dtls_srtp *dtls = calloc(1, sizeof(janus_dtls_srtp));
if(dtls == NULL) {
JANUS_LOG(LOG_FATAL, "Memory error!\n");
return NULL;
}
/* Create SSL context, at last */
dtls->srtp_valid = 0;
dtls->dtls_last_msg = NULL;
dtls->dtls_last_len = 0;
dtls->ssl = SSL_new(janus_dtls_get_ssl_ctx());
if(!dtls->ssl) {
JANUS_LOG(LOG_ERR, "[%"SCNu64"] No component DTLS SSL session??\n", handle->handle_id);
janus_dtls_srtp_destroy(dtls);
return NULL;
}
SSL_set_ex_data(dtls->ssl, 0, dtls);
SSL_set_info_callback(dtls->ssl, janus_dtls_callback);
dtls->read_bio = BIO_new(BIO_s_mem());
if(!dtls->read_bio) {
JANUS_LOG(LOG_ERR, "[%"SCNu64"] Error creating read BIO!\n", handle->handle_id);
janus_dtls_srtp_destroy(dtls);
return NULL;
}
BIO_set_mem_eof_return(dtls->read_bio, -1);
dtls->write_bio = BIO_new(BIO_s_mem());
if(!dtls->write_bio) {
JANUS_LOG(LOG_ERR, "[%"SCNu64"] Error creating write BIO!\n", handle->handle_id);
janus_dtls_srtp_destroy(dtls);
return NULL;
}
BIO_set_mem_eof_return(dtls->write_bio, -1);
SSL_set_bio(dtls->ssl, dtls->read_bio, dtls->write_bio);
dtls->dtls_role = role;
if(dtls->dtls_role == JANUS_DTLS_ROLE_CLIENT) {
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Setting connect state (DTLS client)\n", handle->handle_id);
SSL_set_connect_state(dtls->ssl);
} else {
JANUS_LOG(LOG_VERB, "[%"SCNu64"] Setting accept state (DTLS server)\n", handle->handle_id);
SSL_set_accept_state(dtls->ssl);
}
/* Done */
dtls->component = component;
return dtls;
}