本文整理汇总了C++中SSL_get_wbio函数的典型用法代码示例。如果您正苦于以下问题:C++ SSL_get_wbio函数的具体用法?C++ SSL_get_wbio怎么用?C++ SSL_get_wbio使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SSL_get_wbio函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dtls1_retransmit_message
int
dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off,
int *found)
{
int ret;
/* XDTLS: for now assuming that read/writes are blocking */
pitem *item;
hm_fragment *frag ;
unsigned long header_length;
PQ_64BIT seq64;
/*
OPENSSL_assert(s->init_num == 0);
OPENSSL_assert(s->init_off == 0);
*/
/* XDTLS: the requested message ought to be found, otherwise error */
pq_64bit_init(&seq64);
pq_64bit_assign_word(&seq64, seq);
item = pqueue_find(s->d1->sent_messages, seq64);
pq_64bit_free(&seq64);
if ( item == NULL)
{
fprintf(stderr, "retransmit: message %d non-existant\n", seq);
*found = 0;
return 0;
}
*found = 1;
frag = (hm_fragment *)item->data;
if ( frag->msg_header.is_ccs)
header_length = DTLS1_CCS_HEADER_LENGTH;
else
header_length = DTLS1_HM_HEADER_LENGTH;
memcpy(s->init_buf->data, frag->fragment,
frag->msg_header.msg_len + header_length);
s->init_num = frag->msg_header.msg_len + header_length;
dtls1_set_message_header_int(s, frag->msg_header.type,
frag->msg_header.msg_len, frag->msg_header.seq, 0,
frag->msg_header.frag_len);
s->d1->retransmitting = 1;
ret = dtls1_do_write(s, frag->msg_header.is_ccs ?
SSL3_RT_CHANGE_CIPHER_SPEC : SSL3_RT_HANDSHAKE);
s->d1->retransmitting = 0;
(void)BIO_flush(SSL_get_wbio(s));
return ret;
}
示例2: test_dtls_unprocessed
static int test_dtls_unprocessed(int testidx)
{
SSL_CTX *sctx = NULL, *cctx = NULL;
SSL *serverssl1 = NULL, *clientssl1 = NULL;
BIO *c_to_s_fbio, *c_to_s_mempacket;
int testresult = 0;
if (!TEST_true(create_ssl_ctx_pair(DTLS_server_method(),
DTLS_client_method(), &sctx,
&cctx, cert, privkey)))
return 0;
if (!TEST_true(SSL_CTX_set_cipher_list(cctx, "AES128-SHA")))
goto end;
c_to_s_fbio = BIO_new(bio_f_tls_dump_filter());
if (!TEST_ptr(c_to_s_fbio))
goto end;
/* BIO is freed by create_ssl_connection on error */
if (!TEST_true(create_ssl_objects(sctx, cctx, &serverssl1, &clientssl1,
NULL, c_to_s_fbio)))
goto end;
if (testidx == 1)
certstatus[RECORD_SEQUENCE] = 0xff;
/*
* Inject a dummy record from the next epoch. In test 0, this should never
* get used because the message sequence number is too big. In test 1 we set
* the record sequence number to be way off in the future. This should not
* have an impact on the record replay protection because the record should
* be dropped before it is marked as arrived
*/
c_to_s_mempacket = SSL_get_wbio(clientssl1);
c_to_s_mempacket = BIO_next(c_to_s_mempacket);
mempacket_test_inject(c_to_s_mempacket, (char *)certstatus,
sizeof(certstatus), 1, INJECT_PACKET_IGNORE_REC_SEQ);
if (!TEST_true(create_ssl_connection(serverssl1, clientssl1,
SSL_ERROR_NONE)))
goto end;
testresult = 1;
end:
SSL_free(serverssl1);
SSL_free(clientssl1);
SSL_CTX_free(sctx);
SSL_CTX_free(cctx);
return testresult;
}
示例3: 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;
}
示例4: dtls1_shutdown
int dtls1_shutdown(SSL *s)
{
int ret;
#ifndef OPENSSL_NO_SCTP
BIO *wbio;
wbio = SSL_get_wbio(s);
if (wbio != NULL && BIO_dgram_is_sctp(wbio) &&
!(s->shutdown & SSL_SENT_SHUTDOWN)) {
ret = BIO_dgram_sctp_wait_for_dry(wbio);
if (ret < 0)
return -1;
if (ret == 0)
BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN, 1,
NULL);
}
#endif
ret = ssl3_shutdown(s);
#ifndef OPENSSL_NO_SCTP
BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN, 0, NULL);
#endif
return ret;
}
示例5: ssl_encrypt
int ssl_encrypt(SSL *s, const char *in, int len, char **out)
{
int i;
if (!BIO_eof(SSL_get_wbio(s))) {
fprintf(stderr, "ssl_encrypt: Someone left data in the wbio!\n");
fprintf(stderr, "In particular, this data:\n");
fflush(stderr);
char *data;
long data_len = BIO_get_mem_data(SSL_get_wbio(s), &data);
//hexdump(data, data_len);
return -1;
}
i = SSL_write(s, in, len);
if (i < 0) {
fprintf(stderr, "ssl_encrypt: SSL_write returned < 0\n");
fflush(stderr);
return -1;
}
return fetch_data_from_bio(s, out);
}
示例6: close
void sstream::open(const char *host, const char *service, size_t size)
{
if(server)
return;
close();
tcpstream::open(host, service, size);
if(!is_open() || !ssl)
return;
SSL_set_fd((SSL *)ssl, getsocket());
if(SSL_connect((SSL *)ssl) > 0)
bio = SSL_get_wbio((SSL *)ssl);
}
示例7: 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;
}
示例8: ocaml_ssl_flush
CAMLprim value ocaml_ssl_flush(value socket)
{
CAMLparam1(socket);
SSL *ssl = SSL_val(socket);
BIO *bio;
caml_enter_blocking_section();
bio = SSL_get_wbio(ssl);
if(bio)
{
/* TODO: raise an error */
assert(BIO_flush(bio) == 1);
}
caml_leave_blocking_section();
CAMLreturn(Val_unit);
}
示例9: PerformIO
bool BaseSSLProtocol::PerformIO() {
//1. Put the data from SSL output buffer inside our protocol output buffer
if (!_outputBuffer.ReadFromBIO(SSL_get_wbio(_pSSL))) {
FATAL("Unable to transfer data from outBIO to outputBuffer");
return false;
}
//2. Enqueue the protocol for outbound if we have data that needs to be sent
if (GETAVAILABLEBYTESCOUNT(_outputBuffer) > 0) {
if (_pFarProtocol != NULL) {
return _pFarProtocol->EnqueueForOutbound();
}
}
//3. Done
return true;
}
示例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;
}
示例11: OCTX
IoSecureSocket *IoSecureServer_tlsWrap(IoSecureServer *self, IoObject *locals, IoMessage *msg)
{
SSL_CTX *ctx = OCTX(self);
IoSocket *sock = IoMessage_locals_socketArgAt_(msg, locals, 0);
IoNumber *port = IoObject_getSlot_(sock, IOSYMBOL("port"));
SSL *ssl = SSL_new(ctx);
SSL_set_fd(ssl, IoSocket_rawDescriptor(sock));
set_nonblocking(SSL_get_rbio(ssl));
set_nonblocking(SSL_get_wbio(ssl));
SSL_set_accept_state(ssl);
SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE |
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
IoIPAddress *ioaddr = IoIPAddress_new(IoObject_state(self));
IPAddress *iaddr = IoIPAddress_rawIPAddress(ioaddr);
IPAddress_setIp_(iaddr, "0.0.0.0");
IPAddress_setPort_(iaddr, IoNumber_asLong(port));
IoSecureSocket *ssock = IoSecureSocket_newWithSSL_IP_(IoObject_state(self), ssl, ioaddr);
return ssock;
}
示例12: tcpstream
sstream::sstream(const TCPServer *tcp, secure::server_t scontext, size_t size) :
tcpstream(tcp, size)
{
context *ctx = (context *)scontext;
ssl = NULL;
bio = NULL;
server = true;
if(ctx && ctx->ctx && ctx->err() == secure::OK)
ssl = SSL_new(ctx->ctx);
if(!is_open() || !ssl)
return;
SSL_set_fd((SSL *)ssl, getsocket());
if(SSL_accept((SSL *)ssl) > 0)
bio = SSL_get_wbio((SSL *)ssl);
}
示例13: dtls1_check_timeout_num
int dtls1_check_timeout_num(SSL *s)
{
s->d1->timeout.num_alerts++;
/* Reduce MTU after 2 unsuccessful retransmissions */
if (s->d1->timeout.num_alerts > 2)
{
s->d1->mtu = BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_GET_FALLBACK_MTU, 0, NULL);
}
if (s->d1->timeout.num_alerts > DTLS1_TMO_ALERT_COUNT)
{
/* fail the connection, enough alerts have been sent */
SSLerr(SSL_F_DTLS1_CHECK_TIMEOUT_NUM,SSL_R_READ_TIMEOUT_EXPIRED);
return -1;
}
return 0;
}
示例14: dtls1_check_timeout_num
int dtls1_check_timeout_num(SSL *s) {
s->d1->num_timeouts++;
/* Reduce MTU after 2 unsuccessful retransmissions */
if (s->d1->num_timeouts > DTLS1_MTU_TIMEOUTS &&
!(SSL_get_options(s) & SSL_OP_NO_QUERY_MTU)) {
long mtu = BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_GET_FALLBACK_MTU, 0,
NULL);
if (mtu >= 0 && mtu <= (1 << 30) && (unsigned)mtu >= dtls1_min_mtu()) {
s->d1->mtu = (unsigned)mtu;
}
}
if (s->d1->num_timeouts > DTLS1_MAX_TIMEOUTS) {
/* fail the connection, enough alerts have been sent */
OPENSSL_PUT_ERROR(SSL, dtls1_check_timeout_num, SSL_R_READ_TIMEOUT_EXPIRED);
return -1;
}
return 0;
}
示例15: SSL_get_wbio
int SSLConnection::flush()
{
BIO *pBIO = SSL_get_wbio(m_ssl);
if (!pBIO)
return 0;
m_iWant = 0;
int ret = BIO_flush(pBIO);
if (ret != 1)
ret = checkError(ret);
//1 means BIO_flush succeed.
switch (ret)
{
case 1:
return LS_DONE;
case 0:
return LS_AGAIN;
case -1:
default:
return LS_FAIL;
}
}