• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ BIO_set_nbio函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中BIO_set_nbio函数的典型用法代码示例。如果您正苦于以下问题:C++ BIO_set_nbio函数的具体用法?C++ BIO_set_nbio怎么用?C++ BIO_set_nbio使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了BIO_set_nbio函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: gw_malloc

/*
 * XXX bad assumption here that conn_wrap_fd for SSL can only happens
 * for the server side!!!! FIXME !!!!
 */
Connection *conn_wrap_fd(int fd, int ssl)
{
    Connection *conn;

    if (socket_set_blocking(fd, 0) < 0)
        return NULL;

    conn = gw_malloc(sizeof(*conn));
    conn->inlock = mutex_create();
    conn->outlock = mutex_create();
    conn->claimed = 0;

    conn->outbuf = octstr_create("");
    conn->outbufpos = 0;
    conn->inbuf = octstr_create("");
    conn->inbufpos = 0;

    conn->fd = fd;
    conn->connected = yes;
    conn->read_eof = 0;
    conn->io_error = 0;
    conn->output_buffering = DEFAULT_OUTPUT_BUFFERING;

    conn->registered = NULL;
    conn->callback = NULL;
    conn->callback_data = NULL;
    conn->callback_data_destroyer = NULL;
    conn->listening_pollin = 0;
    conn->listening_pollout = 0;
#ifdef HAVE_LIBSSL
    /*
     * do all the SSL magic for this connection
     */
    if (ssl) {
        conn->ssl = SSL_new(global_server_ssl_context);
        conn->peer_certificate = NULL;

        /* SSL_set_fd can fail, so check it */
        if (SSL_set_fd(conn->ssl, conn->fd) == 0) {
            /* SSL_set_fd failed, log error and return NULL */
            error(errno, "SSL: OpenSSL: %.256s", ERR_error_string(ERR_get_error(), NULL));
            conn_destroy(conn);
            return NULL;
        }
        /* SSL_set_verify(conn->ssl, 0, NULL); */

        /* set read/write BIO layer to non-blocking mode */
        BIO_set_nbio(SSL_get_rbio(conn->ssl), 1);
        BIO_set_nbio(SSL_get_wbio(conn->ssl), 1);

        /* set accept state , SSL-Handshake will be handled transparent while SSL_[read|write] */
         SSL_set_accept_state(conn->ssl);
    } else {
        conn->ssl = NULL;
        conn->peer_certificate = NULL;
    }
#endif /* HAVE_LIBSSL */

    return conn;
}
开发者ID:pwhelan,项目名称:kannel,代码行数:64,代码来源:conn.c


示例2: zc_socket_ssl_handshake

int 
zc_socket_ssl_handshake(zcSocket *s)
{
    int ret;
    int err;
    int sockstate, nonblocking;

    /* just in case the blocking state of the socket has been changed */
    nonblocking = !s->blocked; //(self->Socket->sock_timeout >= 0.0);
    BIO_set_nbio(SSL_get_rbio(s->ssl), nonblocking);
    BIO_set_nbio(SSL_get_wbio(s->ssl), nonblocking);

    /* Actually negotiate SSL connection */
    /* XXX If SSL_do_handshake() returns 0, it's also a failure. */
    sockstate = 0;

    do {
        ret = SSL_do_handshake(s->ssl);
        err = SSL_get_error(s->ssl, ret);

        if (err == SSL_ERROR_WANT_READ) {
            sockstate = zc_socket_select(s, 0); //check_socket_and_wait_for_timeout(s->fd, 0);
        } else if (err == SSL_ERROR_WANT_WRITE) {
            sockstate = zc_socket_select(s, 1); //check_socket_and_wait_for_timeout(s->fd, 1);
        } else {
            sockstate = ZC_SSL_SOCKET_OPERATION_OK;
        }
        if (sockstate == ZC_SSL_SOCKET_HAS_TIMED_OUT) {
            //PyErr_SetString(PySSLErrorObject, ERRSTR("The handshake operation timed out"));
            ZCWARN("The handshake operation timed out");
            return ZC_ERR;
        } else if (sockstate == ZC_SSL_SOCKET_HAS_BEEN_CLOSED) {
            //PyErr_SetString(PySSLErrorObject, ERRSTR("Underlying socket has been closed."));
            ZCWARN("Underlying socket has been closed.");
            return ZC_ERR;
        } else if (sockstate == ZC_SSL_SOCKET_TOO_LARGE_FOR_SELECT) {
            //PyErr_SetString(PySSLErrorObject, ERRSTR("Underlying socket too large for select()."));
            ZCWARN("Underlying socket too large for select().");
            return ZC_ERR;
        } else if (sockstate == ZC_SSL_SOCKET_IS_NONBLOCKING) {
            break;
        }
    } while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
    if (ret < 1) {
        ZCWARN("handshak error:%d", ret);
        return ZC_ERR;
    }
        //return PySSL_SetError(self, ret, __FILE__, __LINE__);

    if (s->peer_cert)
        X509_free (s->peer_cert);

    if ((s->peer_cert = SSL_get_peer_certificate(s->ssl))) {
        X509_NAME_oneline(X509_get_subject_name(s->peer_cert), s->server, X509_NAME_MAXLEN);
        X509_NAME_oneline(X509_get_issuer_name(s->peer_cert), s->issuer, X509_NAME_MAXLEN);
    }

    return ZC_OK;
}
开发者ID:zhaoweikid,项目名称:zocle,代码行数:59,代码来源:sockets_win32.c


示例3: zc_socket_ssl_send

int
zc_socket_ssl_send(zcSocket *s, char *buf, int blen)
{
    //char *data;
    int len;
    //int count;
    int sockstate;
    int err;
    int nonblocking;

    /* just in case the blocking state of the socket has been changed */
    nonblocking =  !s->blocked; //(self->Socket->sock_timeout >= 0.0);
    BIO_set_nbio(SSL_get_rbio(s->ssl), nonblocking);
    BIO_set_nbio(SSL_get_wbio(s->ssl), nonblocking);

    //sockstate = check_socket_and_wait_for_timeout(self->Socket, 1);
    sockstate = zc_socket_select(s, 1);
    if (sockstate == ZC_SSL_SOCKET_HAS_TIMED_OUT) {
        ZCWARN("The write operation timed out");
        return ZC_ERR;
    } else if (sockstate == ZC_SSL_SOCKET_HAS_BEEN_CLOSED) {
        ZCWARN("Underlying socket has been closed.");
        return ZC_ERR;
    } else if (sockstate == ZC_SSL_SOCKET_TOO_LARGE_FOR_SELECT) {
        ZCWARN("Underlying socket too large for select().");
        return ZC_ERR;
    }
    do {
        err = 0;
        len = SSL_write(s->ssl, buf, blen);
        err = SSL_get_error(s->ssl, len);
 
        if (err == SSL_ERROR_WANT_READ) {
            sockstate = zc_socket_select(s, 0);
        } else if (err == SSL_ERROR_WANT_WRITE) {
            sockstate = zc_socket_select(s, 1);
        } else {
            sockstate = ZC_SSL_SOCKET_OPERATION_OK;
        }
        if (sockstate == ZC_SSL_SOCKET_HAS_TIMED_OUT) {
            ZCWARN("The write operation timed out");
            return ZC_ERR;
        } else if (sockstate == ZC_SSL_SOCKET_HAS_BEEN_CLOSED) {
            ZCWARN("Underlying socket has been closed.");
            return ZC_ERR;
        } else if (sockstate == ZC_SSL_SOCKET_IS_NONBLOCKING) {
            break;
        }
    } while (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE);
    if (len > 0)
        //return PyInt_FromLong(len);
        return len;
    else
        //return PySSL_SetError(self, len, __FILE__, __LINE__);
        return len;
}
开发者ID:zhaoweikid,项目名称:zocle,代码行数:56,代码来源:sockets_win32.c


示例4: lws_tls_server_new_nonblocking

int
lws_tls_server_new_nonblocking(struct lws *wsi, lws_sockfd_type accept_fd)
{
#if !defined(USE_WOLFSSL)
	BIO *bio;
#endif

	errno = 0;
	wsi->tls.ssl = SSL_new(wsi->vhost->tls.ssl_ctx);
	if (wsi->tls.ssl == NULL) {
		lwsl_err("SSL_new failed: %d (errno %d)\n",
			 lws_ssl_get_error(wsi, 0), errno);

		lws_tls_err_describe();
		return 1;
	}

	SSL_set_ex_data(wsi->tls.ssl, openssl_websocket_private_data_index, wsi);
	SSL_set_fd(wsi->tls.ssl, (int)(long long)accept_fd);

#ifdef USE_WOLFSSL
#ifdef USE_OLD_CYASSL
	CyaSSL_set_using_nonblock(wsi->tls.ssl, 1);
#else
	wolfSSL_set_using_nonblock(wsi->tls.ssl, 1);
#endif
#else

	SSL_set_mode(wsi->tls.ssl, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER |
				   SSL_MODE_RELEASE_BUFFERS);
	bio = SSL_get_rbio(wsi->tls.ssl);
	if (bio)
		BIO_set_nbio(bio, 1); /* nonblocking */
	else
		lwsl_notice("NULL rbio\n");
	bio = SSL_get_wbio(wsi->tls.ssl);
	if (bio)
		BIO_set_nbio(bio, 1); /* nonblocking */
	else
		lwsl_notice("NULL rbio\n");
#endif

#if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK)
		if (wsi->vhost->tls.ssl_info_event_mask)
			SSL_set_info_callback(wsi->tls.ssl, lws_ssl_info_callback);
#endif

	return 0;
}
开发者ID:PKRoma,项目名称:libwebsockets,代码行数:49,代码来源:openssl-server.c


示例5: set_nonblocking

void set_nonblocking(BIO *bio)
{
	if(BIO_method_type(bio) == BIO_TYPE_CONNECT)
	{
		BIO_set_nbio(bio, 1);
	}
	if(BIO_method_type(bio) == BIO_TYPE_ACCEPT)
	{
		BIO_set_nbio_accept(bio, 1);
	}
	#ifdef DTLS_IMPLEMENTED
	if(BIO_method_type(bio) == BIO_TYPE_DGRAM)
	{
		int fd = BIO_get_fd(bio, NULL);
#ifdef WIN32
	unsigned long nonzero = 1;
	
	SocketResetErrorStatus();
		ioctlsocket(fd, FIONBIO, &nonzero);
#else
		fcntl(fd, F_SETFL, FASYNC | O_NONBLOCK);
#endif
	}
	#endif
}
开发者ID:ADTSH,项目名称:io,代码行数:25,代码来源:common.c


示例6: LUA_FUNCTION

static LUA_FUNCTION(openssl_bio_nbio)
{
  BIO* bio = CHECK_OBJECT(1, BIO, "openssl.bio");
  int nbio = lua_toboolean(L, 2);
  int ret = BIO_set_nbio(bio, nbio);
  return openssl_pushresult(L, ret);
}
开发者ID:Shaddy1884,项目名称:lua-openssl,代码行数:7,代码来源:bio.c


示例7: engine_alloc

ms_conn* engine_alloc(VALUE klass, VALUE* obj) {
  ms_conn* conn;

  *obj = Data_Make_Struct(klass, ms_conn, 0, engine_free, conn);

  conn->read = BIO_new(BIO_s_mem());
  BIO_set_nbio(conn->read, 1);

  conn->write = BIO_new(BIO_s_mem());
  BIO_set_nbio(conn->write, 1);

  conn->ssl = 0;
  conn->ctx = 0;

  return conn;
}
开发者ID:RobotJiang,项目名称:puma,代码行数:16,代码来源:mini_ssl.c


示例8: resolv_and_connect_wout_SSL

static enum pbpal_resolv_n_connect_result resolv_and_connect_wout_SSL(pubnub_t *pb)
{
    PUBNUB_LOG_TRACE("resolv_and_connect_wout_SSL\n");
    if (NULL == pb->pal.socket) {
        char const*origin = PUBNUB_ORIGIN_SETTABLE ? pb->origin : PUBNUB_ORIGIN;
        PUBNUB_LOG_TRACE("pb=%p: Don't have BIO\n", pb);
        pb->pal.socket = BIO_new_connect((char*)origin);
    }
    if (NULL == pb->pal.socket) {
        return pbpal_resolv_resource_failure;
    }
    BIO_set_conn_port(pb->pal.socket, "http");

    BIO_set_nbio(pb->pal.socket, !pb->options.use_blocking_io);

    WATCH_ENUM(pb->options.use_blocking_io);
    if (BIO_do_connect(pb->pal.socket) <= 0) {
        if (BIO_should_retry(pb->pal.socket)) {
            return pbpal_connect_wouldblock;
        }
        ERR_print_errors_cb(print_to_pubnub_log, NULL);
        PUBNUB_LOG_ERROR("BIO_do_connect failed\n");
        return pbpal_connect_failed;
    }

    PUBNUB_LOG_TRACE("pb=%p: BIO connected\n", pb);
    {
        int fd = BIO_get_fd(pb->pal.socket, NULL);
        socket_set_rcv_timeout(fd, pb->transaction_timeout_ms);
    }

    return pbpal_connect_success;
}
开发者ID:pubnub,项目名称:c-core,代码行数:33,代码来源:pbpal_resolv_and_connect_openssl.c


示例9: handshake

static int
handshake (struct stream_data *data)
{
	int ret;
	int finished;

	SSL_library_init();
	SSL_load_error_strings();
	
	data->ssl_ctx = SSL_CTX_new(TLSv1_method());
	if(!data->ssl_ctx) return IKS_NOMEM;
	
	data->ssl = SSL_new(data->ssl_ctx);
	if(!data->ssl) return IKS_NOMEM;
	
	if( SSL_set_fd(data->ssl, (int)(intptr_t)data->sock) != 1 ) return IKS_NOMEM;
	
	/* Set both the read and write BIO's to non-blocking mode */
	BIO_set_nbio(SSL_get_rbio(data->ssl), 1);
	BIO_set_nbio(SSL_get_wbio(data->ssl), 1);

	finished = 0;
	
	do
	{
		ret = SSL_connect(data->ssl);
		
		if( ret != 1 ) 
		{
			if( wait_for_data(data, ret, 1) != IKS_OK ) 
			{
				finished = 1; 
				SSL_free(data->ssl);
			}
		}
	} while( ret != 1 && finished != 1 );
	
	if( ret == 1 )
	{
		data->flags &= (~SF_TRY_SECURE);
		data->flags |= SF_SECURE;
	
		iks_send_header (data->prs, data->server);
	}
	
	return ret == 1 ? IKS_OK : IKS_NET_TLSFAIL;
}
开发者ID:areski,项目名称:FreeSWITCH,代码行数:47,代码来源:stream.c


示例10: conn_init_client_ssl

static int conn_init_client_ssl(Connection *ret, Octstr *certkeyfile)
{
    ret->ssl = SSL_new(global_ssl_context);

    /*
     * The current thread's error queue must be empty before
     * the TLS/SSL I/O operation is attempted, or SSL_get_error()
     * will not work reliably.
     */
    ERR_clear_error();

    if (certkeyfile != NULL) {
        SSL_use_certificate_file(ret->ssl, octstr_get_cstr(certkeyfile),
                                 SSL_FILETYPE_PEM);
        SSL_use_PrivateKey_file(ret->ssl, octstr_get_cstr(certkeyfile),
                                SSL_FILETYPE_PEM);
        if (SSL_check_private_key(ret->ssl) != 1) {
            error(0, "conn_open_ssl: private key isn't consistent with the "
                     "certificate from file %s (or failed reading the file)",
                  octstr_get_cstr(certkeyfile));
            return -1;
        }
    }

    /* SSL_set_fd can fail, so check it */
    if (SSL_set_fd(ret->ssl, ret->fd) == 0) {
        /* SSL_set_fd failed, log error */
        error(errno, "SSL: OpenSSL: %.256s", ERR_error_string(ERR_get_error(), NULL));
        return -1;
    }

    /*
     * make sure the socket is non-blocking while we do SSL_connect
     */
    if (socket_set_blocking(ret->fd, 0) < 0) {
        return -1;
    }
    BIO_set_nbio(SSL_get_rbio(ret->ssl), 1);
    BIO_set_nbio(SSL_get_wbio(ret->ssl), 1);

    SSL_set_connect_state(ret->ssl);
    
    return 0;
}
开发者ID:pwhelan,项目名称:kannel,代码行数:44,代码来源:conn.c


示例11: ssl_setup_socket

/** Associate an SSL object with a socket and return it.
 * \param sock socket descriptor to associate with an SSL object.
 * \return pointer to SSL object.
 */
SSL *
ssl_setup_socket(int sock)
{
  SSL *ssl;
  BIO *bio;

  ssl = SSL_new(ctx);
  bio = BIO_new_socket(sock, BIO_NOCLOSE);
  BIO_set_nbio(bio, 1);
  SSL_set_bio(ssl, bio, bio);
  return ssl;
}
开发者ID:tkrajcar,项目名称:pypenn,代码行数:16,代码来源:myssl.c


示例12: ssl_setup_socket

/** Associate an SSL object with a socket and return it.
 * \param sock socket descriptor to associate with an SSL object.
 * \return pointer to SSL object.
 */
SSL *
ssl_setup_socket(int sock)
{
  SSL *ssl;
  BIO *bio;

  ssl = ssl_alloc_struct();
  bio = BIO_new_socket(sock, BIO_NOCLOSE);
  BIO_set_nbio(bio, 1);
  SSL_set_bio(ssl, bio, bio);
  return ssl;
}
开发者ID:zetafunction,项目名称:pennmush-mirror,代码行数:16,代码来源:myssl.c


示例13: _ios

Connection::Connection(Context& ctx, std::ios& ios, OpenMode omode)
: _ios(&ios)
, _connected(false)
, _in(0)
, _out(0)
, _ssl(0)
{
    // Create the SSL objects
    _in  = BIO_new( BIO_s_mem() );
    _out = BIO_new( BIO_s_mem() );
    _ssl = SSL_new( ctx.impl()->ctx() );

    // Connect the BIO
    BIO_set_nbio(_in, 1);
    BIO_set_nbio(_out, 1);
    SSL_set_bio(_ssl, _in, _out);

    if(omode == Accept)
        SSL_set_accept_state(_ssl);
    else
        SSL_set_connect_state(_ssl);

    assert(_ssl);
}
开发者ID:3Nigma,项目名称:frayon,代码行数:24,代码来源:Connection.cpp


示例14: ssl_connect

int
ssl_connect(thread_t * thread)
{
	SOCK *sock_obj = THREAD_ARG(thread);
	int ret;

	sock_obj->ssl = SSL_new(req->ctx);
	sock_obj->bio = BIO_new_socket(sock_obj->fd, BIO_NOCLOSE);
	BIO_set_nbio(sock_obj->bio, 1);	/* Set the Non-Blocking flag */
	SSL_set_bio(sock_obj->ssl, sock_obj->bio, sock_obj->bio);
	ret = SSL_connect(sock_obj->ssl);

	DBG("  SSL_connect return code = %d on fd:%d\n", ret, thread->u.fd);
	ssl_printerr(SSL_get_error(sock_obj->ssl, ret));

	return (ret > 0) ? 1 : 0;
}
开发者ID:Addision,项目名称:LVS,代码行数:17,代码来源:ssl.c


示例15: set_blocking

void set_blocking(BIO *bio)
{
	if(BIO_method_type(bio) == BIO_TYPE_CONNECT)
	{
		BIO_set_nbio(bio, 0);
	}
	if(BIO_method_type(bio) == BIO_TYPE_ACCEPT)
	{
		BIO_set_nbio_accept(bio, 0);
	}
#ifdef DTLS_IMPLEMENTED
	if(BIO_method_type(bio) == BIO_TYPE_DGRAM)
	{
  		int fd, flags;
  		if((fd = BIO_get_fd(bio, NULL)))       
  		{ 
    		flags = fcntl(fd, F_GETFL);
    		flags &= ~O_NONBLOCK;
    		fcntl(fd, F_SETFL, flags);
  		}
	}
#endif
}
开发者ID:ADTSH,项目名称:io,代码行数:23,代码来源:common.c


示例16: HANDSHAKE_RESULT_new

static HANDSHAKE_RESULT *do_handshake_internal(
    SSL_CTX *server_ctx, SSL_CTX *server2_ctx, SSL_CTX *client_ctx,
    const SSL_TEST_CTX *test_ctx, SSL_SESSION *session_in,
    SSL_SESSION **session_out)
{
    SSL *server, *client;
    BIO *client_to_server, *server_to_client;
    HANDSHAKE_EX_DATA server_ex_data, client_ex_data;
    CTX_DATA client_ctx_data, server_ctx_data, server2_ctx_data;
    HANDSHAKE_RESULT *ret = HANDSHAKE_RESULT_new();
    int client_turn = 1, shutdown = 0;
    peer_status_t client_status = PEER_RETRY, server_status = PEER_RETRY;
    handshake_status_t status = HANDSHAKE_RETRY;
    unsigned char* tick = NULL;
    size_t tick_len = 0;
    SSL_SESSION* sess = NULL;
    const unsigned char *proto = NULL;
    /* API dictates unsigned int rather than size_t. */
    unsigned int proto_len = 0;

    memset(&server_ctx_data, 0, sizeof(server_ctx_data));
    memset(&server2_ctx_data, 0, sizeof(server2_ctx_data));
    memset(&client_ctx_data, 0, sizeof(client_ctx_data));

    configure_handshake_ctx(server_ctx, server2_ctx, client_ctx, test_ctx,
                            &server_ctx_data, &server2_ctx_data, &client_ctx_data);

    server = SSL_new(server_ctx);
    client = SSL_new(client_ctx);
    OPENSSL_assert(server != NULL && client != NULL);

    configure_handshake_ssl(server, client, test_ctx);
    if (session_in != NULL) {
        /* In case we're testing resumption without tickets. */
        OPENSSL_assert(SSL_CTX_add_session(server_ctx, session_in));
        OPENSSL_assert(SSL_set_session(client, session_in));
    }

    memset(&server_ex_data, 0, sizeof(server_ex_data));
    memset(&client_ex_data, 0, sizeof(client_ex_data));

    ret->result = SSL_TEST_INTERNAL_ERROR;

    client_to_server = BIO_new(BIO_s_mem());
    server_to_client = BIO_new(BIO_s_mem());

    OPENSSL_assert(client_to_server != NULL && server_to_client != NULL);

    /* Non-blocking bio. */
    BIO_set_nbio(client_to_server, 1);
    BIO_set_nbio(server_to_client, 1);

    SSL_set_connect_state(client);
    SSL_set_accept_state(server);

    /* The bios are now owned by the SSL object. */
    SSL_set_bio(client, server_to_client, client_to_server);
    OPENSSL_assert(BIO_up_ref(server_to_client) > 0);
    OPENSSL_assert(BIO_up_ref(client_to_server) > 0);
    SSL_set_bio(server, client_to_server, server_to_client);

    ex_data_idx = SSL_get_ex_new_index(0, "ex data", NULL, NULL, NULL);
    OPENSSL_assert(ex_data_idx >= 0);

    OPENSSL_assert(SSL_set_ex_data(server, ex_data_idx,
                                   &server_ex_data) == 1);
    OPENSSL_assert(SSL_set_ex_data(client, ex_data_idx,
                                   &client_ex_data) == 1);

    SSL_set_info_callback(server, &info_cb);
    SSL_set_info_callback(client, &info_cb);

    /*
     * Half-duplex handshake loop.
     * Client and server speak to each other synchronously in the same process.
     * We use non-blocking BIOs, so whenever one peer blocks for read, it
     * returns PEER_RETRY to indicate that it's the other peer's turn to write.
     * The handshake succeeds once both peers have succeeded. If one peer
     * errors out, we also let the other peer retry (and presumably fail).
     */
    for(;;) {
        if (client_turn) {
            client_status = do_handshake_step(client, shutdown);
            status = handshake_status(client_status, server_status,
                                      1 /* client went last */);
        } else {
            server_status = do_handshake_step(server, shutdown);
            status = handshake_status(server_status, client_status,
                                      0 /* server went last */);
        }

        switch (status) {
        case HANDSHAKE_SUCCESS:
            if (shutdown) {
                ret->result = SSL_TEST_SUCCESS;
                goto err;
            } else {
                client_status = server_status = PEER_RETRY;
                shutdown = 1;
                client_turn = 1;
//.........这里部分代码省略.........
开发者ID:Beatzevo,项目名称:openssl,代码行数:101,代码来源:handshake_helper.c


示例17: openconnect_open_https


//.........这里部分代码省略.........
			}

			stack = PEM_X509_INFO_read_bio(b, NULL, NULL, NULL);
			BIO_free(b);

			if (!stack) {
				vpn_progress(vpninfo, PRG_ERR,
					     _("Failed to read certs from CA file '%s'\n"),
					     vpninfo->cafile);
				openconnect_report_ssl_errors(vpninfo);
				SSL_CTX_free(vpninfo->https_ctx);
				vpninfo->https_ctx = NULL;
				close(ssl_sock);
				return -ENOENT;
			}

			store = SSL_CTX_get_cert_store(vpninfo->https_ctx);

			while ((info = sk_X509_INFO_pop(stack))) {
				if (info->x509)
					X509_STORE_add_cert(store, info->x509);
				if (info->crl)
					X509_STORE_add_crl(store, info->crl);
				X509_INFO_free(info);
			}
			sk_X509_INFO_free(stack);
		} else
#endif
		if (vpninfo->cafile) {
			if (!SSL_CTX_load_verify_locations(vpninfo->https_ctx, vpninfo->cafile, NULL)) {
				vpn_progress(vpninfo, PRG_ERR,
					     _("Failed to open CA file '%s'\n"),
					     vpninfo->cafile);
				openconnect_report_ssl_errors(vpninfo);
				SSL_CTX_free(vpninfo->https_ctx);
				vpninfo->https_ctx = NULL;
				close(ssl_sock);
				return -EINVAL;
			}
		}

	}
	https_ssl = SSL_new(vpninfo->https_ctx);
	workaround_openssl_certchain_bug(vpninfo, https_ssl);

	https_bio = BIO_new_socket(ssl_sock, BIO_NOCLOSE);
	BIO_set_nbio(https_bio, 1);
	SSL_set_bio(https_ssl, https_bio, https_bio);

	vpn_progress(vpninfo, PRG_INFO, _("SSL negotiation with %s\n"),
		     vpninfo->hostname);

	while ((err = SSL_connect(https_ssl)) <= 0) {
		fd_set wr_set, rd_set;
		int maxfd = ssl_sock;

		FD_ZERO(&wr_set);
		FD_ZERO(&rd_set);

		err = SSL_get_error(https_ssl, err);
		if (err == SSL_ERROR_WANT_READ)
			FD_SET(ssl_sock, &rd_set);
		else if (err == SSL_ERROR_WANT_WRITE)
			FD_SET(ssl_sock, &wr_set);
		else {
			vpn_progress(vpninfo, PRG_ERR, _("SSL connection failure\n"));
			openconnect_report_ssl_errors(vpninfo);
			SSL_free(https_ssl);
			close(ssl_sock);
			return -EINVAL;
		}

		cmd_fd_set(vpninfo, &rd_set, &maxfd);
		select(maxfd + 1, &rd_set, &wr_set, NULL, NULL);
		if (is_cancel_pending(vpninfo, &rd_set)) {
			vpn_progress(vpninfo, PRG_ERR, _("SSL connection cancelled\n"));
			SSL_free(https_ssl);
			close(ssl_sock);
			return -EINVAL;
		}
	}

	if (verify_peer(vpninfo, https_ssl)) {
		SSL_free(https_ssl);
		close(ssl_sock);
		return -EINVAL;
	}

	vpninfo->ssl_fd = ssl_sock;
	vpninfo->https_ssl = https_ssl;

	/* Stash this now, because it might not be available later if the
	   server has disconnected. */
	vpninfo->peer_cert = SSL_get_peer_certificate(vpninfo->https_ssl);

	vpn_progress(vpninfo, PRG_INFO, _("Connected to HTTPS on %s\n"),
		     vpninfo->hostname);

	return 0;
}
开发者ID:shahrdad1,项目名称:openconnect,代码行数:101,代码来源:openssl.c


示例18: context_connect

static int
context_connect(lua_State *T)
{
	struct lem_ssl_context *c;
	const char *hostname;
	int port;
	BIO *bio;
	SSL *ssl;
	int ret;
	const char *msg;
	struct lem_ssl_stream *s;

	luaL_checktype(T, 1, LUA_TUSERDATA);
	c = lua_touserdata(T, 1);
	hostname = luaL_checkstring(T, 2);
	port = (int)luaL_optnumber(T, 3, -1);

	if (c->ctx == NULL) {
		lua_pushnil(T);
		lua_pushliteral(T, "closed");
		return 2;
	}

	bio = BIO_new(BIO_s_connect());
	if (bio == NULL) {
		lua_pushnil(T);
		lua_pushfstring(T, "error creating BIO: %s",
		                ERR_reason_error_string(ERR_get_error()));
		return 2;
	}
	BIO_set_conn_hostname(bio, hostname);
	if (port > 0)
		BIO_set_conn_int_port(bio, (char *)&port);
	BIO_set_nbio(bio, 1);

	ssl = SSL_new(c->ctx);
	if (ssl == NULL) {
		lua_pushnil(T);
		lua_pushfstring(T, "error creating SSL connection: %s",
		                ERR_reason_error_string(ERR_get_error()));
		return 2;
	}
	SSL_set_bio(ssl, bio, bio);

	ret = SSL_connect(ssl);
	switch (SSL_get_error(ssl, ret)) {
	case SSL_ERROR_NONE:
		lem_debug("SSL_ERROR_NONE");
		s = stream_new(T, ssl, NULL, 0);
		return 1;

	case SSL_ERROR_ZERO_RETURN:
		lem_debug("SSL_ERROR_ZERO_RETURN");
		msg = "connection closed unexpectedly";
		break;

	case SSL_ERROR_WANT_READ:
		lem_debug("SSL_ERROR_WANT_READ");
		lua_settop(T, 0);
		s = stream_new(T, ssl, connect_handler, EV_READ);
		s->T = T;
		ev_io_start(EV_G_ &s->w);
		return lua_yield(T, 1);

	case SSL_ERROR_WANT_WRITE:
		lem_debug("SSL_ERROR_WANT_WRITE");
	case SSL_ERROR_WANT_CONNECT:
		lem_debug("SSL_ERROR_WANT_CONNECT");
		lua_settop(T, 0);
		s = stream_new(T, ssl, connect_handler, EV_WRITE);
		s->T = T;
		ev_io_start(EV_G_ &s->w);
		return lua_yield(T, 1);

	case SSL_ERROR_SYSCALL:
		lem_debug("SSL_ERROR_SYSCALL");
		{
			long e = ERR_get_error();

			if (e)
				msg = ERR_reason_error_string(e);
			else if (ret == 0)
				msg = "connection closed unexpectedly";
			else
				msg = strerror(errno);

		}
		break;

	case SSL_ERROR_SSL:
		lem_debug("SSL_ERROR_SSL");
		msg = ERR_reason_error_string(ERR_get_error());
		break;

	default:
		lem_debug("SSL_ERROR_* (default)");
		msg = "unexpected error from SSL library";
	}

	lua_pushnil(T);
//.........这里部分代码省略.........
开发者ID:esmil,项目名称:lem-ssl,代码行数:101,代码来源:context.c


示例19: StartPollThread

int32 StartPollThread(void* punt)
{
	MSNP* mainClass = (MSNP*) punt;

	MSN::NotificationServerConnection* mainConnection = mainClass->GetConnection();
	mainConnection->connect("messenger.hotmail.com", 1863);
	while (1) {
		fflush(stdout);
		if (kPollSockets == NULL)
			continue;

		poll(kPollSockets, kSocketsCount, 3);

		for (int i = 0; i < kSocketsCount; i++) {
			if (kPollSockets[i].fd == -1) {
				continue;
			}
			if (kPollSockets[i].revents & POLLHUP) {
				kPollSockets[i].revents = 0;
				continue;
			}
			if (kPollSockets[i].revents & (POLLIN | POLLOUT | POLLPRI)) {
				MSN::Connection *c;

				c = mainConnection->connectionWithSocket((void*)kPollSockets[i].fd);

				if (c != NULL) {
					// TODO make the ssl code more styled and less bugged
					if (kSocketsSsl[i].isSSL && !kSocketsSsl[i].isConnected) {
						BIO *bio_socket_new;
						SSL_METHOD *meth=NULL;
						meth=const_cast<SSL_METHOD*>(SSLv23_client_method());
						SSL_library_init();
						kSocketsSsl[i].ctx = SSL_CTX_new(meth);
						kSocketsSsl[i].ssl = SSL_new(kSocketsSsl[i].ctx);
						bio_socket_new = BIO_new_socket(kPollSockets[i].fd, BIO_CLOSE);
						if (!kSocketsSsl[i].ssl)
							break;
						BIO_set_nbio(bio_socket_new, 0);
						SSL_set_bio(kSocketsSsl[i].ssl, bio_socket_new, bio_socket_new);
						SSL_set_mode(kSocketsSsl[i].ssl, SSL_MODE_AUTO_RETRY);

						// TODO - fix-me - not async and buggy
						// and handle errors
						/*int ret =*/ SSL_connect(kSocketsSsl[i].ssl);
						kSocketsSsl[i].isConnected = true;
					}

					if (c->isConnected() == false)
						c->socketConnectionCompleted();

					if (kPollSockets[i].revents & POLLIN) {
						if (kSocketsSsl[i].isSSL && kSocketsSsl[i].isConnected) {
							 if (SSL_want_read(kSocketsSsl[i].ssl)) {
								 kPollSockets[i].revents = 0;
								 continue;
							 }
						}
						c->dataArrivedOnSocket();
					}

					if (kPollSockets[i].revents & POLLOUT) {
						c->socketIsWritable();
					}
				}
			}

			if (kPollSockets[i].revents & (POLLERR | POLLNVAL)) {
				MSN::Connection *c;

				c = mainConnection->connectionWithSocket((void*)kPollSockets[i].fd);

				if (c != NULL) {
					delete c;
				}
				kPollSockets[i].fd = -1;
				kPollSockets[i].revents = 0;
				continue;
			}
		}
		
		if (kPollSockets[0].revents & POLLIN) {
			kPollSockets[0].revents = 0;
		}
	}
	return 0;
}
开发者ID:ModeenF,项目名称:Caya,代码行数:87,代码来源:MSN.cpp


示例20: BIO_set_nbio_shim

long BIO_set_nbio_shim(BIO *b, long enabled) {
    return BIO_set_nbio(b, enabled);
}
开发者ID:Heather,项目名称:rust-openssl,代码行数:3,代码来源:openssl_shim.c



注:本文中的BIO_set_nbio函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ BIO_set_retry_read函数代码示例发布时间:2022-05-30
下一篇:
C++ BIO_set_mem_eof_return函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap