本文整理匯總了C++中BIO_new_socket函數的典型用法代碼示例。如果您正苦於以下問題:C++ BIO_new_socket函數的具體用法?C++ BIO_new_socket怎麽用?C++ BIO_new_socket使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BIO_new_socket函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: SSL_new
SSL *ssl_new(SSL_CTX *ctx,int s)
{
BIO *sbio;
SSL *ssl;
ssl = SSL_new(ctx);
if (!ssl) return 0;
sbio = BIO_new_socket(s,BIO_NOCLOSE);
if (!sbio) return 0;
SSL_set_bio(ssl,sbio,sbio);
return ssl;
}
示例4: protocol_ssl_accept
static protocol_t *
protocol_ssl_accept(protocol_t * p, void *options)
{
protocol_t *newp;
struct sockaddr_in remote;
socklen_t addrlen;
int ret;
ssl_private_t *ssl_p = (ssl_private_t *) p->_protocol_p;
ssl_private_t *new_ssl_p;
struct sockaddr name;
char hostname[128];
flowop_options_t *flowop_options = (flowop_options_t *) options;
BIO *sbio;
newp = protocol_ssl_new();
new_ssl_p = (ssl_private_t *) newp->_protocol_p;
addrlen = (socklen_t) sizeof (remote);
uperf_debug("ssl - ssl obj waiting for accept\n");
newp->fd = accept(p->fd, (struct sockaddr *) &remote,
&addrlen);
if (newp->fd < 0) {
uperf_log_msg(UPERF_LOG_ERROR, errno, "accept");
return (NULL);
}
if (getnameinfo((const struct sockaddr *) & remote, addrlen,
hostname, sizeof (hostname), NULL, 0, 0) == 0) {
uperf_debug("ssl - Connection from %s:%d\n", hostname,
SOCK_PORT(remote));
strlcpy(newp->host, hostname, sizeof (newp->host));
newp->port = SOCK_PORT(remote);
}
if (flowop_options) {
if ((load_engine(flowop_options->engine)) == -1) {
uperf_info(
"ssl - Engine %s does NOT exist! Using the default OpenSSL softtoken",
flowop_options->engine);
}
}
sbio = BIO_new_socket(newp->fd, BIO_NOCLOSE);
if (!(new_ssl_p->ssl = SSL_new(ctx))) {
uperf_log_msg(UPERF_LOG_ERROR, 0, "SSL_new error");
return (NULL);
}
SSL_set_bio(new_ssl_p->ssl, sbio, sbio);
ret = SSL_accept(new_ssl_p->ssl);
if (my_ssl_error(new_ssl_p->ssl, ret) == 0) {
return (newp);
} else {
return (0);
}
}
示例5: main
/* Main Entry */
int main(int argc, char **argv)
{
// init connection object
Connection conn;
memset(&conn, 0, sizeof(conn));
conn.port = PORT; // assign default port
conn.host = HOST;
// Parse arguments
parseArguments(argc, argv, &conn);
// init SSL library
conn.sslContext = initSSLContext(CLIENT_CERTIFICATE, CA_CERTIFICATE);
SSL_CTX_set_options(conn.sslContext, SSL_OP_NO_SSLv2);
SSL_CTX_set_cipher_list(conn.sslContext, "SHA1");
// Connect
if (tcpConnect(&conn) < 0){
tcpDisconnect(&conn);
exit(0);
}
SSL * ssl = SSL_new(conn.sslContext);
BIO * sbio = BIO_new_socket(conn.socket, BIO_NOCLOSE);
SSL_set_bio(ssl, sbio, sbio);
int ret;
ret = SSL_connect(ssl);
if (ret <= 0){
printf(FMT_CONNECT_ERR);
handleError(ssl, ret);
}
else{
// Process Message
if (checkServerCertification(ssl) == OK){
processMessage(ssl);
}
}
// close ssl connection
if (!SSL_shutdown(ssl)){
tcpDisconnect(&conn);
SSL_shutdown(ssl);
}
SSL_free(ssl);
// Disconnect
tcpDisconnect(&conn);
destroySSLContext(conn.sslContext);
return 1;
}
示例6: SSL_new
void sslsocket::complete_secure_connect()
{
// create SSL and BIO objects and then initialize ssl client mode.
// setup SSL session now that we have TCP connection.
SSL_CTX* ctx = context_.ssl();
ssl_ = SSL_new(ctx);
if (!ssl_)
throw std::runtime_error("SSL_new failed");
// create new IO object
bio_ = BIO_new_socket(socket_, BIO_NOCLOSE);
if (!bio_)
throw std::runtime_error("BIO_new_socket failed");
// connect the IO object with SSL, this takes the ownership
// of the BIO object.
SSL_set_bio(ssl_, bio_, bio_);
ERR_clear_error();
// go into client mode.
while (true)
{
const int ret = SSL_connect(ssl_);
if (ret == 1)
break;
const int err = SSL_get_error(ssl_, ret);
switch (err)
{
case SSL_ERROR_WANT_READ:
ssl_wait_read();
break;
case SSL_ERROR_WANT_WRITE:
ssl_wait_write();
break;
case SSL_ERROR_SYSCALL:
if (ret == -1)
throw std::system_error(get_last_socket_error(),
"SSL socket I/O error");
// fallthrough intended
default:
throw std::runtime_error("SSL_connect failed");
}
}
}
示例7: hssl_server_ssl
herror_t
hssl_server_ssl(hsocket_t * sock)
{
SSL *ssl;
int ret;
BIO *sbio;
if (!enabled)
return H_OK;
log_verbose2("Starting SSL initialization for socket %d", sock->sock);
if (!(ssl = SSL_new(context)))
{
log_warn1("SSL_new failed");
return herror_new("hssl_server_ssl", HSSL_ERROR_SERVER,
"Cannot create SSL object");
}
/* SSL_set_fd(ssl, sock->sock); */
sbio = BIO_new_socket(sock->sock, BIO_NOCLOSE);
if (sbio == NULL)
{
log_error1("BIO_new_socket failed");
return NULL;
}
// BIO_set_callback(sbio, hssl_bio_cb);
sbio->method->bread = _hssl_bio_read;
SSL_set_bio(ssl, sbio, sbio);
if ((ret = SSL_accept(ssl)) <= 0)
{
herror_t err;
log_error2("SSL_accept failed (%s)", _hssl_get_error(ssl, ret));
err =
herror_new("hssl_server_ssl", HSSL_ERROR_SERVER,
"SSL_accept failed (%s)", _hssl_get_error(ssl, ret));
SSL_free(ssl);
return err;
}
sock->ssl = ssl;
return H_OK;
}
示例8: PetscSSLInitializeContext
/*@C
PetscHTTPSConnect - connect to a HTTPS server
Input Parameters:
+ host - the name of the machine hosting the HTTPS server
. port - the port number where the server is hosting, usually 443
- ctx - value obtained with PetscSSLInitializeContext()
Output Parameters:
+ sock - socket to connect
- ssl - the argument passed to PetscHTTPSRequest()
Level: advanced
.seealso: PetscOpenSocket(), PetscHTTPSRequest(), PetscSSLInitializeContext()
@*/
PetscErrorCode PetscHTTPSConnect(const char host[],int port,SSL_CTX *ctx,int *sock,SSL **ssl)
{
BIO *sbio;
PetscErrorCode ierr;
PetscFunctionBegin;
/* Connect the TCP socket*/
ierr = PetscOpenSocket(host,port,sock);CHKERRQ(ierr);
/* Connect the SSL socket */
*ssl = SSL_new(ctx);
sbio = BIO_new_socket(*sock,BIO_NOCLOSE);
SSL_set_bio(*ssl,sbio,sbio);
if (SSL_connect(*ssl) <= 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"SSL connect error");
PetscFunctionReturn(0);
}
示例9: kTLSAccept
int kTLSAccept(int handle,void **tlsssl,void **tlssession)
{
BIO *bio;
SSL *ssl;
int ofcmode;
bool flg;
if(!TLSctx){return(RETURN_NG);}
/* すでに存在するソケットを用いてBIOオブジェクトを生成する。BIOオブジェクトが破棄されてもソケットはクローズされない */
bio=BIO_new_socket(handle,BIO_NOCLOSE);
/* SSLオブジェクトを生成する */
ssl=SSL_new(TLSctx);
/* SSLオブジェクトに読み込み/書き込み用BIOオブジェクトをバインドする */
SSL_set_bio(ssl,bio,bio);
/* 認証 */
if (SSL_accept(ssl) <= 0){
kLogWrite(L_ERROR,"%s: Error accepting SSL connection",__FUNCTION__);
TLSClose(ssl,0);
return(RETURN_NG);
}
/* 非ブロックモードに変更 */
ofcmode=fcntl(handle,F_GETFL,0);
ofcmode|=O_NDELAY;
if(fcntl(handle,F_SETFL,ofcmode)){
kLogWrite(L_ERROR,"%s: Couldn't make socket nonblocking",__FUNCTION__);
TLSClose(ssl,0);
return(RETURN_NG);
}
/* Nagle アルゴリズムを無効にする */
if(!NagleFlag){
flg=true;
if(setsockopt(handle,IPPROTO_TCP,TCP_NODELAY,(char*)&flg,sizeof(flg))){
kLogWrite(L_ERROR,"%s: Couldn't setsocktopt TCP_NODELAY",__FUNCTION__);
}
}
*tlsssl=(void*)ssl;
*tlssession=(void*)SSL_get_session(ssl);
kLogWrite(L_TLS,"%s: TLS Accept socket nonblocking OK",__FUNCTION__);
return(RETURN_OK);
}
示例10: 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;
}
示例11: sslUpgrade
PUBLIC int sslUpgrade(Webs *wp)
{
WebsSocket *sptr;
BIO *bio;
assert(wp);
sptr = socketPtr(wp->sid);
if ((wp->ssl = SSL_new(sslctx)) == 0) {
return -1;
}
if ((bio = BIO_new_socket(sptr->sock, BIO_NOCLOSE)) == 0) {
return -1;
}
SSL_set_bio(wp->ssl, bio, bio);
SSL_set_accept_state(wp->ssl);
SSL_set_app_data(wp->ssl, (void*) wp);
return 0;
}
示例12: sizeof
R_API RSocket *r_socket_accept(RSocket *s) {
RSocket *sock;
socklen_t salen = sizeof (s->sa);
if (!s) {
return NULL;
}
sock = R_NEW0 (RSocket);
if (!sock) {
return NULL;
}
//signal (SIGPIPE, SIG_DFL);
sock->fd = accept (s->fd, (struct sockaddr *)&s->sa, &salen);
if (sock->fd == -1) {
if (errno != EWOULDBLOCK) {
// not just a timeout
r_sys_perror ("accept");
}
free (sock);
return NULL;
}
#if HAVE_LIB_SSL
sock->is_ssl = s->is_ssl;
if (sock->is_ssl) {
sock->sfd = NULL;
sock->ctx = NULL;
sock->bio = NULL;
BIO *sbio = BIO_new_socket (sock->fd, BIO_NOCLOSE);
sock->sfd = SSL_new (s->ctx);
SSL_set_bio (sock->sfd, sbio, sbio);
if (SSL_accept (sock->sfd) <= 0) {
r_socket_free (sock);
return NULL;
}
sock->bio = BIO_new (BIO_f_buffer ());
sbio = BIO_new (BIO_f_ssl ());
BIO_set_ssl (sbio, sock->sfd, BIO_CLOSE);
BIO_push (sock->bio, sbio);
}
#else
sock->is_ssl = 0;
#endif
return sock;
}
示例13: connect_ssl
int connect_ssl(int socket_h, SSL_CTX *client_ctx, SSL **ssl_h, BIO **s_bio, int timeout)
{
int dummy;
// FIXME handle t/o
#if 0
int rc;
struct timeval to;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(socket_h, &rfds);
to.tv_sec = timeout / 1000;
to.tv_usec = (timeout - (to.tv_sec * 1000)) * 1000;
/* wait for connection */
rc = select(socket_h + 1, &rfds, NULL, NULL, &to);
if (rc == 0)
return -2; /* timeout */
else if (rc == -1)
{
if (errno == EINTR)
return -3; /* ^C pressed */
else
return -1; /* error */
}
#endif
*ssl_h = SSL_new(client_ctx);
*s_bio = BIO_new_socket(socket_h, BIO_NOCLOSE);
SSL_set_bio(*ssl_h, *s_bio, *s_bio);
dummy = SSL_connect(*ssl_h);
if (dummy <= 0)
{
sprintf(last_error, "problem starting SSL connection: %d\n", SSL_get_error(*ssl_h, dummy));
return -1;
}
return 0;
}
示例14: tls_create
tls_t *tls_init_secondary(tls_t *master, int sock, int accept)
{
tls_t *tls = tls_create(tls_slave);
if (tls) {
tls->ctx = master->ctx;
tls->type = master->type;
tls->accept = accept ? 1 : 0;
tls->verify_outgoing = master->verify_outgoing;
tls->verify_incoming = master->verify_incoming;
tls->verify_subj_out = master->verify_subj_out;
tls->verify_subj_in = master->verify_subj_in;
tls->verify_date = master->verify_date;
tls->x509_verified = master->x509_verified;
if (!(tls->read_buffer = su_alloc(tls->home, tls_buffer_size)))
su_home_unref(tls->home), tls = NULL;
}
if (!tls)
return tls;
assert(sock != -1);
tls->bio_con = BIO_new_socket(sock, BIO_NOCLOSE);
tls->con = SSL_new(tls->ctx);
if (tls->con == NULL) {
tls_log_errors(1, "tls_init_secondary", 0);
tls_free(tls);
errno = EIO;
return NULL;
}
SSL_set_bio(tls->con, tls->bio_con, tls->bio_con);
SSL_set_mode(tls->con, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
SSL_set_ex_data(tls->con, tls_ex_data_idx, tls);
su_setblocking(sock, 0);
return tls;
}
示例15: throw
//
// Constructor
//
SSLSocket::SSLSocket(const InetAddress& address, in_port_t port, SSLContext* context)
throw(IOException, SystemException)
: Socket(address, port), _context(context), _session(NULL)
{
// TODO: check if context is != NULL
/* Connect the SSL socket */
_ssl = SSL_new(_context->_ctx);
_sbio = BIO_new_socket(_impl->_fd, BIO_NOCLOSE);
SSL_set_bio(_ssl, _sbio, _sbio);
//SSL_set_connect_state(_ssl);
// Verify certificate
if (SSL_get_verify_result(_ssl) != X509_V_OK) {
throw IOException("SSLSocket: Certificate doesn't verified");
}
_session_creation = true;
_use_client_mode = true;
}