本文整理汇总了C++中BIO_set_mem_eof_return函数的典型用法代码示例。如果您正苦于以下问题:C++ BIO_set_mem_eof_return函数的具体用法?C++ BIO_set_mem_eof_return怎么用?C++ BIO_set_mem_eof_return使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了BIO_set_mem_eof_return函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: 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;
}
开发者ID:dsoprea,项目名称:janus-gateway,代码行数:60,代码来源:dtls.c
示例2: tnet_dtls_socket_create
tnet_dtls_socket_handle_t* tnet_dtls_socket_create(struct tnet_socket_s* wrapped_sock, struct ssl_ctx_st* ssl_ctx)
{
#if !HAVE_OPENSSL || !HAVE_OPENSSL_DTLS
TSK_DEBUG_ERROR("OpenSSL or DTLS not enabled");
return tsk_null;
#else
tnet_dtls_socket_t* socket;
if (!wrapped_sock || !ssl_ctx){
TSK_DEBUG_ERROR("Invalid parameter");
return tsk_null;
}
if ((socket = tsk_object_new(tnet_dtls_socket_def_t))) {
const tsk_bool_t set_mtu = TNET_SOCKET_TYPE_IS_DGRAM(wrapped_sock->type) || 1; //!\ This is required even if the local transport is TCP/TLS because the relayed (TURN) transport could be UDP
socket->wrapped_sock = tsk_object_ref(wrapped_sock);
if (!(socket->ssl = SSL_new(ssl_ctx))) {
TSK_DEBUG_ERROR("SSL_new(CTX) failed [%s]", ERR_error_string(ERR_get_error(), tsk_null));
TSK_OBJECT_SAFE_FREE(socket);
return tsk_null;
}
if (set_mtu) {
SSL_set_options(socket->ssl, SSL_OP_NO_QUERY_MTU);
SSL_set_mtu(socket->ssl, TNET_DTLS_MTU - 28);
socket->ssl->d1->mtu = TNET_DTLS_MTU - 28;
}
if (!(socket->rbio = BIO_new(BIO_s_mem())) || !(socket->wbio = BIO_new(BIO_s_mem()))){
TSK_DEBUG_ERROR("BIO_new_socket(%d) failed [%s]", socket->wrapped_sock->fd, ERR_error_string(ERR_get_error(), tsk_null));
if (socket->rbio){
BIO_free(socket->rbio);
}
if (socket->wbio){
BIO_free(socket->wbio);
}
TSK_OBJECT_SAFE_FREE(socket);
return tsk_null;
}
BIO_set_mem_eof_return(socket->rbio, -1);
BIO_set_mem_eof_return(socket->wbio, -1);
SSL_set_bio(socket->ssl, socket->rbio, socket->wbio);
SSL_set_mode(socket->ssl, SSL_MODE_AUTO_RETRY);
SSL_set_read_ahead(socket->ssl, 1);
if (set_mtu) {
BIO_ctrl(SSL_get_wbio(socket->ssl), BIO_CTRL_DGRAM_SET_MTU, TNET_DTLS_MTU - 28, NULL);
}
if ((socket->verify_peer = (SSL_CTX_get_verify_mode(ssl_ctx) != SSL_VERIFY_NONE))){
TSK_DEBUG_INFO("SSL cert verify: ON");
socket->verify_peer = tsk_true;
SSL_set_verify(socket->ssl, (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT), _tnet_dtls_verify_cert);
}
else {
TSK_DEBUG_ERROR("Verity not enabled");
}
SSL_set_app_data(socket->ssl, socket);
}
return socket;
#endif
}
开发者ID:NewComerBH,项目名称:doubango,代码行数:59,代码来源:tnet_dtls.c
示例3: create_ssl_objects
/*
* NOTE: Transfers control of the BIOs - this function will free them on error
*/
int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)
{
SSL *serverssl = NULL, *clientssl = NULL;
BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;
if (*sssl != NULL)
serverssl = *sssl;
else if (!TEST_ptr(serverssl = SSL_new(serverctx)))
goto error;
if (*cssl != NULL)
clientssl = *cssl;
else if (!TEST_ptr(clientssl = SSL_new(clientctx)))
goto error;
if (SSL_is_dtls(clientssl)) {
if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))
|| !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))
goto error;
} else {
if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))
|| !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))
goto error;
}
if (s_to_c_fbio != NULL
&& !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))
goto error;
if (c_to_s_fbio != NULL
&& !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))
goto error;
/* Set Non-blocking IO behaviour */
BIO_set_mem_eof_return(s_to_c_bio, -1);
BIO_set_mem_eof_return(c_to_s_bio, -1);
/* Up ref these as we are passing them to two SSL objects */
SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);
BIO_up_ref(s_to_c_bio);
BIO_up_ref(c_to_s_bio);
SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);
*sssl = serverssl;
*cssl = clientssl;
return 1;
error:
SSL_free(serverssl);
SSL_free(clientssl);
BIO_free(s_to_c_bio);
BIO_free(c_to_s_bio);
BIO_free(s_to_c_fbio);
BIO_free(c_to_s_fbio);
return 0;
}
开发者ID:danielctull-forks,项目名称:openssl,代码行数:58,代码来源:ssltestlib.c
示例4: _pInBIO
DTLSBio::DTLSBio() :
_pInBIO(0), /* we use memory read bios */
_pOutBIO(0),
_pSSL(0),
_pSocket(0)
{
//
// Create the bios
//
_pInBIO = BIO_new(BIO_s_mem());
_pOutBIO = BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(_pInBIO, -1);
BIO_set_mem_eof_return(_pOutBIO, -1);
}
开发者ID:joegen,项目名称:oss_core,代码行数:15,代码来源:DTLSBio.cpp
示例5: cms_copy_content
static int cms_copy_content(BIO *out, BIO *in, unsigned int flags)
{
struct sockaddr_in sa;
unsigned char buf[4096];
int r = 0, i;
BIO *tmpout = NULL;
if (out == NULL)
tmpout = BIO_new(BIO_s_null());
else if (flags & CMS_TEXT)
{
tmpout = BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(tmpout, 0);
}
else
tmpout = out;
if(!tmpout)
{
CMSerr(CMS_F_CMS_COPY_CONTENT,ERR_R_MALLOC_FAILURE);
goto err;
}
/* Read all content through chain to process digest, decrypt etc */
for (;;)
{
i=BIO_read(in,buf,sizeof(buf));
if (i <= 0)
{
if (BIO_method_type(in) == BIO_TYPE_CIPHER)
{
if (!BIO_get_cipher_status(in))
goto err;
}
if (i < 0)
goto err;
break;
}
if (tmpout && (BIO_write(tmpout, buf, i, 0, sa) != i))
goto err;
}
if(flags & CMS_TEXT)
{
if(!SMIME_text(tmpout, out))
{
CMSerr(CMS_F_CMS_COPY_CONTENT,CMS_R_SMIME_TEXT_ERROR);
goto err;
}
}
r = 1;
err:
if (tmpout && (tmpout != out))
BIO_free(tmpout);
return r;
}
开发者ID:serhatkiyak,项目名称:OpenSSL_TFO,代码行数:60,代码来源:cms_smime.c
示例6: memory_bio_new
static PyObject *
memory_bio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
BIO *bio = NULL;
PySSLMemoryBIO *self = NULL;
if (!PyArg_ParseTuple(args, ":MemoryBIO"))
RETURN_ERROR(NULL);
bio = BIO_new(BIO_s_mem());
if (bio == NULL)
RETURN_ERROR("failed to allocate BIO");
/* Since our BIO is non-blocking an empty read() does not indicate EOF,
* just that no data is currently available. The SSL routines should retry
* the read, which we can achieve by calling BIO_set_retry_read(). */
BIO_set_retry_read(bio);
BIO_set_mem_eof_return(bio, -1);
self = (PySSLMemoryBIO *) type->tp_alloc(type, 0);
if (self == NULL)
RETURN_ERROR(NULL);
self->bio = bio; bio = NULL;
self->eof_written = 0;
error:
if (bio != NULL) BIO_free(bio);
return (PyObject *) self;
}
开发者ID:geertj,项目名称:gruvi,代码行数:30,代码来源:sslcompat.c
示例7: printf
bool Parser::init() {
if (!ssl) {
printf("Error: dtls::Parser::init() failed because the `ssl` member hasn't been set yet.\n");
return false;
}
/* in bio */
{
in_bio = BIO_new(BIO_s_mem());
if (!in_bio) {
printf("Error: dtls::Parser::init() failed because we can't create our in_bio.\n");
return false;
}
BIO_set_mem_eof_return(in_bio, -1); /* see: https://www.openssl.org/docs/crypto/BIO_s_mem.html */
}
/* out bio */
{
out_bio = BIO_new(BIO_s_mem());
if (!out_bio) {
printf("Error: dtls::Parser::init() failed because can't create out out_bio.\n");
/* @todo cleanup. */
return false;
}
BIO_set_mem_eof_return(out_bio, -1); /* see: https://www.openssl.org/docs/crypto/BIO_s_mem.html */
}
/* set info callback */
SSL_set_info_callback(ssl, dtls_parse_ssl_info_callback);
/* set in and output bios. */
SSL_set_bio(ssl, in_bio, out_bio);
if (mode == DTLS_MODE_SERVER) {
SSL_set_accept_state(ssl); /* in case we're a server */
}
else if(mode == DTLS_MODE_CLIENT) {
//SSL_set_connect_state(ssl); /* in case we're a client */
printf("dtls::Parser - error: not yet handling client state for dtls::Parser().\n");
exit(1);
}
return true;
}
开发者ID:UIKit0,项目名称:WebRTC,代码行数:47,代码来源:Parser.cpp
示例8: create_dtls_transport
struct dtls_transport *
create_dtls_transport(struct rtcdc_peer_connection *peer,
const struct dtls_context *context)
{
if (peer == NULL || peer->transport == NULL || context == NULL || context->ctx == NULL)
return NULL;
struct dtls_transport *dtls = (struct dtls_transport *)calloc(1, sizeof *dtls);
if (dtls == NULL)
return NULL;
peer->transport->dtls = dtls;
SSL *ssl = SSL_new(context->ctx);
if (ssl == NULL)
goto trans_err;
dtls->ssl = ssl;
BIO *bio = BIO_new(BIO_s_mem());
if (bio == NULL)
goto trans_err;
BIO_set_mem_eof_return(bio, -1);
dtls->incoming_bio = bio;
bio = BIO_new(BIO_s_mem());
if (bio == NULL)
goto trans_err;
BIO_set_mem_eof_return(bio, -1);
dtls->outgoing_bio = bio;
SSL_set_bio(dtls->ssl, dtls->incoming_bio, dtls->outgoing_bio);
EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
SSL_set_options(dtls->ssl, SSL_OP_SINGLE_ECDH_USE);
SSL_set_tmp_ecdh(dtls->ssl, ecdh);
EC_KEY_free(ecdh);
if (0) {
trans_err:
peer->transport->dtls = NULL;
SSL_free(ssl);
free(dtls);
dtls = NULL;
}
return dtls;
}
开发者ID:biddyweb,项目名称:librtcdc,代码行数:46,代码来源:dtls.c
示例9: BIO_new
BIO *BIO_mem_dummy()
{
static BIO *dummyBIO = NULL;
if(!dummyBIO)
{
dummyBIO = BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(dummyBIO, -1);
}
return dummyBIO;
}
开发者ID:ADTSH,项目名称:io,代码行数:10,代码来源:common.c
示例10: memory_bio_write_eof
static PyObject *
memory_bio_write_eof(PySSLMemoryBIO *self, PyObject *args)
{
self->eof_written = 1;
/* After an EOF is written, a zero return from read() should be a real EOF
* i.e. it should not be retried. Clear the SHOULD_RETRY flag. */
BIO_clear_retry_flags(self->bio);
BIO_set_mem_eof_return(self->bio, 0);
Py_RETURN_NONE;
}
开发者ID:geertj,项目名称:gruvi,代码行数:11,代码来源:sslcompat.c
示例11: krx_ssl_init
/* this sets up the SSL* */
int krx_ssl_init(krx* k, int isserver, info_callback cb) {
/* create SSL* */
k->ssl = SSL_new(k->ctx);
if(!k->ssl) {
printf("Error: cannot create new SSL*.\n");
return -1;
}
/* info callback */
SSL_set_info_callback(k->ssl, cb);
/* bios */
k->in_bio = BIO_new(BIO_s_mem());
if(k->in_bio == NULL) {
printf("Error: cannot allocate read bio.\n");
return -2;
}
BIO_set_mem_eof_return(k->in_bio, -1); /* see: https://www.openssl.org/docs/crypto/BIO_s_mem.html */
k->out_bio = BIO_new(BIO_s_mem());
if(k->out_bio == NULL) {
printf("Error: cannot allocate write bio.\n");
return -3;
}
BIO_set_mem_eof_return(k->out_bio, -1); /* see: https://www.openssl.org/docs/crypto/BIO_s_mem.html */
SSL_set_bio(k->ssl, k->in_bio, k->out_bio);
/* either use the server or client part of the protocol */
if(isserver == 1) {
SSL_set_accept_state(k->ssl);
}
else {
SSL_set_connect_state(k->ssl);
}
return 0;
}
开发者ID:roxlu,项目名称:krx_rtc,代码行数:42,代码来源:text_ssl2.c
示例12: BIO_new
static BIO *cms_get_text_bio(BIO *out, unsigned int flags)
{
BIO *rbio;
if (out == NULL)
rbio = BIO_new(BIO_s_null());
else if (flags & CMS_TEXT) {
rbio = BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(rbio, 0);
} else
rbio = out;
return rbio;
}
开发者ID:crypto-org-ua,项目名称:openssl-ua,代码行数:12,代码来源:cms_smime.c
示例13: ssl_Connection_bio_shutdown
@return: None\n\
";
static PyObject *
ssl_Connection_bio_shutdown(ssl_ConnectionObj *self, PyObject *args)
{
if (self->from_ssl == NULL)
{
PyErr_SetString(PyExc_TypeError, "Connection sock was not None");
return NULL;
}
BIO_set_mem_eof_return(self->into_ssl, 0);
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:svpcom,项目名称:pyopenssl-pypy,代码行数:16,代码来源:connection.c
示例14: gzb64_init
Gzb64* gzb64_init()
{
int zret;
Gzb64* gzb64 = (Gzb64*) malloc(sizeof(Gzb64));
if( gzb64 == NULL ) { fprintf(stderr, "Failed to malloc\n"); exit(EXIT_FAILURE); }
/* Encode */
/* setup zlib encode struc */
gzb64->gz_encode_strm.zalloc = Z_NULL;
gzb64->gz_encode_strm.zfree = Z_NULL;
gzb64->gz_encode_strm.opaque = Z_NULL;
zret = deflateInit2 (& gzb64->gz_encode_strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
windowBits | GZIP_ENCODING, 8,
Z_DEFAULT_STRATEGY);
if(zret < 0) zerr(zret);
gzb64->encode_gzout_buffer = evbuffer_new();
/* setup base64 encoder */
gzb64->b64_encoder = BIO_new(BIO_f_base64());
BIO_set_flags(gzb64->b64_encoder, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer
gzb64->encode_output_buffer = BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(gzb64->encode_output_buffer, 0);
gzb64->b64_encoder = BIO_push(gzb64->b64_encoder, gzb64->encode_output_buffer);
/* Decode */
gzb64->decode_input_buffer = evbuffer_new();
/* setup base64 decoder */
gzb64->b64_decoder = BIO_new(BIO_f_base64());
BIO_set_flags(gzb64->b64_decoder, BIO_FLAGS_BASE64_NO_NL); //Do not use newlines to flush buffer
gzb64->decode_output_buffer = evbuffer_new();
/* setup zlib decode struc */
gzb64->gz_decode_strm.avail_in = 0;
gzb64->gz_decode_strm.next_in = Z_NULL;
zret = inflateInit2 (& gzb64->gz_decode_strm, windowBits | ENABLE_ZLIB_GZIP);
if(zret < 0) zerr(zret);
/* State */
gzb64->encoded_last_chunk = false;
gzb64->decoded_last_chunk = false;
return gzb64;
}
开发者ID:nfvproject,项目名称:TFM,代码行数:47,代码来源:compress.c
示例15: CMS_dataFinal
int CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio)
{
ASN1_OCTET_STRING **pos = CMS_get0_content(cms);
if (!pos)
return 0;
/* If ebmedded content find memory BIO and set content */
if (*pos && ((*pos)->flags & ASN1_STRING_FLAG_CONT))
{
BIO *mbio;
unsigned char *cont;
long contlen;
mbio = BIO_find_type(cmsbio, BIO_TYPE_MEM);
if (!mbio)
{
CMSerr(CMS_F_CMS_DATAFINAL, CMS_R_CONTENT_NOT_FOUND);
return 0;
}
contlen = BIO_get_mem_data(mbio, &cont);
/* Set bio as read only so its content can't be clobbered */
BIO_set_flags(mbio, BIO_FLAGS_MEM_RDONLY);
BIO_set_mem_eof_return(mbio, 0);
ASN1_STRING_set0(*pos, cont, contlen);
(*pos)->flags &= ~ASN1_STRING_FLAG_CONT;
}
switch (OBJ_obj2nid(cms->contentType))
{
case NID_pkcs7_data:
case NID_pkcs7_enveloped:
case NID_pkcs7_encrypted:
case NID_id_smime_ct_compressedData:
/* Nothing to do */
return 1;
case NID_pkcs7_signed:
return cms_SignedData_final(cms, cmsbio);
case NID_pkcs7_digest:
return cms_DigestedData_do_final(cms, cmsbio, 0);
default:
CMSerr(CMS_F_CMS_DATAFINAL, CMS_R_UNSUPPORTED_TYPE);
return 0;
}
}
开发者ID:Chenhx,项目名称:moai-dev,代码行数:46,代码来源:cms_lib.c
示例16: MutatingFilterStream
SSLStream::SSLStream(Stream::ptr parent, bool client, bool own, SSL_CTX *ctx)
: MutatingFilterStream(parent, own)
{
MORDOR_ASSERT(parent);
clearSSLError();
if (ctx)
m_ctx.reset(ctx, &nop<SSL_CTX *>);
else
m_ctx.reset(SSL_CTX_new(client ? SSLv23_client_method() :
SSLv23_server_method()), &SSL_CTX_free);
if (!m_ctx) {
MORDOR_ASSERT(hasOpenSSLError());
MORDOR_THROW_EXCEPTION(OpenSSLException(getOpenSSLErrorMessage()))
// << boost::errinfo_api_function("SSL_CTX_new");
;
}
// Auto-generate self-signed server cert
if (!ctx && !client) {
std::shared_ptr<X509> cert;
std::shared_ptr<EVP_PKEY> pkey;
mkcert(cert, pkey, 1024, rand(), 365);
SSL_CTX_use_certificate(m_ctx.get(), cert.get());
SSL_CTX_use_PrivateKey(m_ctx.get(), pkey.get());
}
m_ssl.reset(SSL_new(m_ctx.get()), &SSL_free);
if (!m_ssl) {
MORDOR_ASSERT(hasOpenSSLError());
MORDOR_THROW_EXCEPTION(OpenSSLException(getOpenSSLErrorMessage()))
// << boost::errinfo_api_function("SSL_CTX_new");
;
}
m_readBio = BIO_new(BIO_s_mem());
m_writeBio = BIO_new(BIO_s_mem());
if (!m_readBio || !m_writeBio) {
if (m_readBio) BIO_free(m_readBio);
if (m_writeBio) BIO_free(m_writeBio);
MORDOR_ASSERT(hasOpenSSLError());
MORDOR_THROW_EXCEPTION(OpenSSLException(getOpenSSLErrorMessage()))
// << boost::errinfo_api_function("BIO_new");
;
}
BIO_set_mem_eof_return(m_readBio, -1);
SSL_set_bio(m_ssl.get(), m_readBio, m_writeBio);
}
开发者ID:zalemwoo,项目名称:mordor-base,代码行数:45,代码来源:ssl.cpp
示例17: BIO_new_mem_buf
OpenSSLCertificate* OpenSSLCertificate::FromPEMString(
const std::string& pem_string, int* pem_length) {
BIO* bio = BIO_new_mem_buf(const_cast<char*>(pem_string.c_str()), -1);
if (!bio)
return NULL;
(void)BIO_set_close(bio, BIO_NOCLOSE);
BIO_set_mem_eof_return(bio, 0);
X509 *x509 = PEM_read_bio_X509(bio, NULL, NULL,
const_cast<char*>("\0"));
char *ptr;
int remaining_length = BIO_get_mem_data(bio, &ptr);
BIO_free(bio);
if (pem_length)
*pem_length = pem_string.length() - remaining_length;
if (x509)
return new OpenSSLCertificate(x509);
else
return NULL;
}
开发者ID:Abhi347,项目名称:s3eTxmpp,代码行数:19,代码来源:opensslidentity.cpp
示例18: OCTX
IoSecureSocket *IoSecureServer_dtlsWrap(IoSecureServer *self, IoObject *locals, IoMessage *msg)
{
SSL_CTX *ctx = OCTX(self);
IoSocket *sock = IoObject_getSlot_(self, IOSYMBOL("socket"));
IoIPAddress *ioip = IoMessage_locals_addressArgAt_(msg, locals, 0);
IPAddress *ip = IoIPAddress_rawIPAddress(ioip);
struct sockaddr *addr = IPAddress_sockaddr(ip);
IoNumber *port = IoObject_getSlot_(sock, IOSYMBOL("port"));
int fd = IoSocket_rawDescriptor(sock);
SSL *ssl = SSL_new(ctx);
BIO *rbio = BIO_new(BIO_s_mem());
BIO_set_mem_eof_return(rbio, -1);
BIO *wbio = BIO_new_dgram(fd, BIO_NOCLOSE);
BIO_dgram_set_peer(wbio, addr);
SSL_set_bio(ssl, rbio, wbio);
SSL_set_accept_state(ssl);
set_nonblocking(wbio);
SSL_set_mode(ssl, SSL_MODE_ENABLE_PARTIAL_WRITE |
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
IoSecureSocket *ssock = IoSecureSocket_newWithSSL_IP_(IoObject_state(self), ssl, ioip);
return ssock;
}
开发者ID:ADTSH,项目名称:io,代码行数:22,代码来源:IoSecureServer.c
示例19: MORDOR_LOG_TRACE
void
SSLStream::wantRead()
{
if (m_readBuffer.readAvailable() == 0) {
MORDOR_LOG_TRACE(g_log) << this << " parent()->read(32768)";
const size_t result = parent()->read(m_readBuffer, 32768);
MORDOR_LOG_TRACE(g_log) << this << " parent()->read(32768): " << result;
if (result == 0) {
BIO_set_mem_eof_return(m_readBio, 0);
return;
}
}
MORDOR_ASSERT(m_readBuffer.readAvailable());
const iovec iov = m_readBuffer.readBuffer(~0, false);
MORDOR_ASSERT(iov.iov_len > 0);
const int written = BIO_write(m_readBio, (char *)iov.iov_base, iov.iov_len);
MORDOR_ASSERT(written > 0);
if (written > 0) {
m_readBuffer.consume(written);
}
MORDOR_LOG_DEBUG(g_log) << this << " wantRead(): " << written;
}
开发者ID:zalemwoo,项目名称:mordor-base,代码行数:22,代码来源:ssl.cpp
示例20: create_sctp_transport
struct sctp_transport *
create_sctp_transport(struct rtcdc_peer_connection *peer)
{
if (peer == NULL || peer->transport == NULL)
return NULL;
struct sctp_transport *sctp = (struct sctp_transport *)calloc(1, sizeof *sctp);
if (sctp == NULL)
return NULL;
peer->transport->sctp = sctp;
sctp->local_port = random_integer(10000, 60000);
if (g_sctp_ref == 0) {
usrsctp_init(0, sctp_data_ready_cb, NULL);
usrsctp_sysctl_set_sctp_ecn_enable(1);
}
g_sctp_ref++;
usrsctp_register_address(sctp);
struct socket *s = usrsctp_socket(AF_CONN, SOCK_STREAM, IPPROTO_SCTP,
sctp_data_received_cb, NULL, 0, peer);
if (s == NULL)
goto trans_err;
sctp->sock = s;
BIO *bio = BIO_new(BIO_s_mem());
if (bio == NULL)
goto trans_err;
BIO_set_mem_eof_return(bio, -1);
sctp->incoming_bio = bio;
bio = BIO_new(BIO_s_mem());
if (bio == NULL)
goto trans_err;
BIO_set_mem_eof_return(bio, -1);
sctp->outgoing_bio = bio;
#ifdef DEBUG_SCTP
int sd;
struct sockaddr_in stub_addr;
memset(&stub_addr, 0, sizeof stub_addr);
inet_pton(AF_INET, "127.0.0.1", &stub_addr.sin_addr);
stub_addr.sin_family = AF_INET;
sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
stub_addr.sin_port = htons(60001);
bind(sd, (const struct sockaddr *)&stub_addr, sizeof stub_addr);
stub_addr.sin_port = htons(60002);
connect(sd, (const struct sockaddr *)&stub_addr, sizeof stub_addr);
sctp->incoming_stub = sd;
sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
stub_addr.sin_port = htons(60002);
bind(sd, (const struct sockaddr *)&stub_addr, sizeof stub_addr);
stub_addr.sin_port = htons(60001);
connect(sd, (const struct sockaddr *)&stub_addr, sizeof stub_addr);
sctp->outgoing_stub = sd;
#endif
struct linger lopt;
lopt.l_onoff = 1;
lopt.l_linger = 0;
usrsctp_setsockopt(s, SOL_SOCKET, SO_LINGER, &lopt, sizeof lopt);
struct sctp_paddrparams peer_param;
memset(&peer_param, 0, sizeof peer_param);
peer_param.spp_flags = SPP_PMTUD_DISABLE;
peer_param.spp_pathmtu = 1200;
usrsctp_setsockopt(s, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &peer_param, sizeof peer_param);
struct sctp_assoc_value av;
av.assoc_id = SCTP_ALL_ASSOC;
av.assoc_value = 1;
usrsctp_setsockopt(s, IPPROTO_SCTP, SCTP_ENABLE_STREAM_RESET, &av, sizeof av);
uint32_t nodelay = 1;
usrsctp_setsockopt(s, IPPROTO_SCTP, SCTP_NODELAY, &nodelay, sizeof nodelay);
struct sctp_initmsg init_msg;
memset(&init_msg, 0, sizeof init_msg);
init_msg.sinit_num_ostreams = RTCDC_MAX_OUT_STREAM;
init_msg.sinit_max_instreams = RTCDC_MAX_IN_STREAM;
usrsctp_setsockopt(s, IPPROTO_SCTP, SCTP_INITMSG, &init_msg, sizeof init_msg);
struct sockaddr_conn sconn;
memset(&sconn, 0, sizeof sconn);
sconn.sconn_family = AF_CONN;
sconn.sconn_port = htons(sctp->local_port);
sconn.sconn_addr = (void *)sctp;
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
sconn.sconn_len = sizeof *sctp;
#endif
usrsctp_bind(s, (struct sockaddr *)&sconn, sizeof sconn);
sctp->deferred_messages = g_async_queue_new();
// modified by uniray7
sctp->peer = peer;
//====================
//.........这里部分代码省略.........
开发者ID:TopPano,项目名称:librtcdc,代码行数:101,代码来源:sctp.c
注:本文中的BIO_set_mem_eof_return函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论