Ejemplo n.º 1
0
/*
    Return the number of bytes read. Return -1 on errors and EOF. Distinguish EOF via mprIsSocketEof.
    If non-blocking, may return zero if no data or still handshaking.
 */
PUBLIC ssize sslRead(Webs *wp, void *buf, ssize len)
{
    WebsSocket      *sp;
    char            ebuf[ME_GOAHEAD_LIMIT_STRING];
    ulong           serror;
    int             rc, error, retries, i;

    if (wp->ssl == 0 || len <= 0) {
        return -1;
    }
    /*
        Limit retries on WANT_READ. If non-blocking and no data, then this can spin forever.
     */
    sp = socketPtr(wp->sid);
    retries = 5;
    for (i = 0; i < retries; i++) {
        rc = SSL_read(wp->ssl, buf, (int) len);
        if (rc < 0) {
            error = SSL_get_error(wp->ssl, rc);
            if (error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_CONNECT || error == SSL_ERROR_WANT_ACCEPT) {
                continue;
            }
            serror = ERR_get_error();
            ERR_error_string_n(serror, ebuf, sizeof(ebuf) - 1);
            trace(5, "SSL_read %s", ebuf);
        }
        break;
    }
    if (rc <= 0) {
        error = SSL_get_error(wp->ssl, rc);
        if (error == SSL_ERROR_WANT_READ) {
            rc = 0;
        } else if (error == SSL_ERROR_WANT_WRITE) {
            rc = 0;
        } else if (error == SSL_ERROR_ZERO_RETURN) {
            sp->flags |= SOCKET_EOF;
            rc = -1;
        } else if (error == SSL_ERROR_SYSCALL) {
            sp->flags |= SOCKET_EOF;
            rc = -1;
        } else if (error != SSL_ERROR_ZERO_RETURN) {
            serror = ERR_get_error();
            ERR_error_string_n(serror, ebuf, sizeof(ebuf) - 1);
            trace(4, "OpenSSL: connection with protocol error: %s", ebuf);
            rc = -1;
            sp->flags |= SOCKET_EOF;
        }
    } else if (SSL_pending(wp->ssl) > 0) {
        socketHiddenData(sp, SSL_pending(wp->ssl), SOCKET_READABLE);
    }
    return rc;
}
Ejemplo n.º 2
0
int sycSSL_pending(SSL *ssl) {
   int result;
   Debug1("SSL_pending(%p)", ssl);
   result = SSL_pending(ssl);
   Debug1("SSL_pending() -> %d", result);
   return result;
}
Ejemplo n.º 3
0
static gboolean sock_check(GSource *source)
{
	SockInfo *sock = ((SockSource *)source)->sock;
	struct timeval timeout = {0, 0};
	fd_set fds;
	GIOCondition condition = sock->condition;

#if USE_SSL
	if (sock->ssl) {
		if (condition & G_IO_IN) {
			if (SSL_pending(sock->ssl) > 0)
				return TRUE;
			if (SSL_want_write(sock->ssl))
				condition |= G_IO_OUT;
		}

		if (condition & G_IO_OUT) {
			if (SSL_want_read(sock->ssl))
				condition |= G_IO_IN;
		}
	}
#endif

	FD_ZERO(&fds);
	FD_SET(sock->sock, &fds);

	select(sock->sock + 1,
	       (condition & G_IO_IN)  ? &fds : NULL,
	       (condition & G_IO_OUT) ? &fds : NULL,
	       NULL, &timeout);

	return FD_ISSET(sock->sock, &fds) != 0;
}
Ejemplo n.º 4
0
gint ssl_peek(SSL *ssl, gchar *buf, gint len)
{
	gint err, ret;

	if (SSL_pending(ssl) == 0) {
		if (fd_check_io(SSL_get_rfd(ssl), G_IO_IN) < 0)
			return -1;
	}

	ret = SSL_peek(ssl, buf, len);

	switch ((err = SSL_get_error(ssl, ret))) {
	case SSL_ERROR_NONE:
		return ret;
	case SSL_ERROR_WANT_READ:
	case SSL_ERROR_WANT_WRITE:
		errno = EAGAIN;
		return -1;
	case SSL_ERROR_ZERO_RETURN:
		return 0;
	default:
		g_warning("SSL_peek() returned error %d, ret = %d\n", err, ret);
		if (ret == 0)
			return 0;
		return -1;
	}
}
Ejemplo n.º 5
0
LWS_VISIBLE int
lws_ssl_capable_read(struct libwebsocket_context *context,
		     struct libwebsocket *wsi, unsigned char *buf, int len)
{
	int n;

	if (!wsi->ssl)
		return lws_ssl_capable_read_no_ssl(context, wsi, buf, len);
	
	wsi->buffered_reads_pending = 0;

	n = SSL_read(wsi->ssl, buf, len);
	if (n >= 0) {
		/* 
		 * if it was our buffer that limited what we read,
		 * check if SSL has additional data pending inside SSL buffers.
		 * 
		 * Because these won't signal at the network layer with POLLIN
		 * and if we don't realize, this data will sit there forever
		 */
		if (n == len && wsi->ssl && SSL_pending(wsi->ssl)) {
			context->ssl_flag_buffered_reads = 1;
			wsi->buffered_reads_pending = 1;
		}
		
		return n;
	}
	n = SSL_get_error(wsi->ssl, n);
	if (n ==  SSL_ERROR_WANT_READ || n ==  SSL_ERROR_WANT_WRITE)
		return LWS_SSL_CAPABLE_MORE_SERVICE;

	return LWS_SSL_CAPABLE_ERROR; 
}
Ejemplo n.º 6
0
int ssl::read(std::vector<unsigned char>& buf) {
  int bytes_read;

  if((bytes_read = SSL_read(_ssl.get(), buf.data(), (int)buf.size())) < 0) {
    return -1;
  }
  else if(!bytes_read) {
    _eof = true;
  }

  // Make sure all bytes are read
  int pending = SSL_pending(_ssl.get());

  // Update number of bytes in buf
  buf.resize(bytes_read + pending);
  if(pending) {
    if((bytes_read = SSL_read(_ssl.get(), &buf.data()[bytes_read], (int)buf.size() - bytes_read)) < 0) {
      return -1;
    }
    else if(!bytes_read) {
      _eof = true;
    }
  }

  return 0;
}
Ejemplo n.º 7
0
ssize_t hr_ssl_read(struct corerouter_peer *main_peer) {
        struct corerouter_session *cs = main_peer->session;
        struct http_session *hr = (struct http_session *) cs;

	hr_ssl_clear_errors();

        // try to always leave 4k available
        if (uwsgi_buffer_ensure(main_peer->in, uwsgi.page_size)) return -1;
        int ret = SSL_read(hr->ssl, main_peer->in->buf + main_peer->in->pos, main_peer->in->len - main_peer->in->pos);
        if (ret > 0) {
                // fix the buffer
                main_peer->in->pos += ret;
                // check for pending data
                int ret2 = SSL_pending(hr->ssl);
                if (ret2 > 0) {
                        if (uwsgi_buffer_fix(main_peer->in, main_peer->in->len + ret2 )) {
                                uwsgi_cr_log(main_peer, "cannot fix the buffer to %d\n", main_peer->in->len + ret2);
                                return -1;
                        }
                        if (SSL_read(hr->ssl, main_peer->in->buf + main_peer->in->pos, ret2) != ret2) {
                                uwsgi_cr_log(main_peer, "SSL_read() on %d bytes of pending data failed\n", ret2);
                                return -1;
                        }
                        // fix the buffer
                        main_peer->in->pos += ret2;
                }
#ifdef UWSGI_SPDY
                if (hr->spdy) {
                        //uwsgi_log("RUNNING THE SPDY PARSER FOR %d bytes\n", main_peer->in->pos);
                        return spdy_parse(main_peer);
                }
#endif
                return http_parse(main_peer);
        }

        int err = SSL_get_error(hr->ssl, ret);

	if (err == SSL_ERROR_ZERO_RETURN || err == 0) return 0;

        if (err == SSL_ERROR_WANT_READ) {
                cr_reset_hooks_and_read(main_peer, hr_ssl_read);
                return 1;
        }

        else if (err == SSL_ERROR_WANT_WRITE) {
                cr_write_to_main(main_peer, hr_ssl_read);
                return 1;
        }

        else if (err == SSL_ERROR_SYSCALL) {
		if (errno != 0)
                	uwsgi_cr_error(main_peer, "hr_ssl_read()");
        }

        else if (err == SSL_ERROR_SSL && uwsgi.ssl_verbose) {
                ERR_print_errors_fp(stderr);
        }

        return -1;
}
Ejemplo n.º 8
0
int decode_ssl_input(h2o_socket_t *sock)
{
    assert(sock->ssl != NULL);
    assert(sock->ssl->handshake.cb == NULL);

    while (sock->ssl->input.encrypted->size != 0 || SSL_pending(sock->ssl->ssl)) {
        int rlen;
        h2o_iovec_t buf = h2o_buffer_reserve(&sock->input, 4096);
        if (buf.base == NULL)
            return errno;
        { /* call SSL_read (while detecting SSL renegotiation and reporting it as error) */
            int did_write_in_read = 0;
            sock->ssl->did_write_in_read = &did_write_in_read;
            rlen = SSL_read(sock->ssl->ssl, buf.base, (int)buf.len);
            sock->ssl->did_write_in_read = NULL;
            if (did_write_in_read)
                return EIO;
        }
        if (rlen == -1) {
            if (SSL_get_error(sock->ssl->ssl, rlen) != SSL_ERROR_WANT_READ) {
                return EIO;
            }
            break;
        } else if (rlen == 0) {
            break;
        } else {
            sock->input->size += rlen;
        }
    }

    return 0;
}
Ejemplo n.º 9
0
static ssize_t
http_ssl_read(void *cookie, char *buf, size_t len)
{
	int nr, err;
	http_ssl_cookie_t *hsc = (http_ssl_cookie_t *)cookie;
	size_t total = 0;

	do {
		nr = SSL_read(hsc->ssl, buf + total, len - total);
		if (nr > 0) {
			total += (size_t)nr;
		} else {
			err = SSL_get_error(hsc->ssl, nr);
			switch (err) {
			case SSL_ERROR_ZERO_RETURN:
				goto read_out;
				break;
			case SSL_ERROR_WANT_WRITE:
			case SSL_ERROR_WANT_READ:
				break;
			default:
				if (debug_mode)
					ERR_print_errors_fp(stderr);
				if (total == 0)
					total = (ssize_t)-1;
				goto read_out;
			}
		}
	} while ((total < len) && SSL_pending(hsc->ssl));

read_out:

	return (ssize_t)total;
}
Ejemplo n.º 10
0
bool SSLSocket::waitForData() {
  if (m_data->m_ssl_active && SSL_pending(m_data->m_handle)) {
    return true;
  }

  return Socket::waitForData();
}
Ejemplo n.º 11
0
static ssize_t
ssl_read_socket(SSL* ssl, char *buf, size_t len)
{
	int nr, err;
	size_t total = 0;

	do {
		nr = SSL_read(ssl, buf + total, len - total);
		if (nr > 0) {
			total += (size_t)nr;
		} else {
			err = SSL_get_error(ssl, nr);
			switch (err) {
			case SSL_ERROR_ZERO_RETURN:
				goto read_out;
				break;
			case SSL_ERROR_WANT_WRITE:
			case SSL_ERROR_WANT_READ:
				break;
			case SSL_ERROR_SYSCALL:
				if (ERR_get_error() == 0)
					goto read_out;
			default:
				if (total == 0)
					total = (ssize_t)-1;
				logit(LOG_ERR, "SSL_read %s! (err: %d)", "FAILED", err);
				goto read_out;
			}
		}
	} while ((total < len) && SSL_pending(ssl));

read_out:

	return (ssize_t)total;
}
Ejemplo n.º 12
0
void SSLClient::process(bool bInRead)
{
    for (;;){
        switch (state){
        case SSLWrite:
            write();
            break;
        case SSLConnect:
            connect();
            break;
        case SSLAccept:
            accept();
            break;
        case SSLShutdown:
            shutdown();
            break;
        case SSLConnected:
            if (!bInRead && (SSL_pending(pSSL) > 0))
                notify->read_ready();
            break;
        }
        char b[2048];
        int i = BIO_read(wBIO, b, sizeof(b));
        if (i == 0) return;
        if (i > 0){
            sock->write(b, i);
            continue;
        }
        if (i < 0){
            if (!BIO_should_retry(wBIO))
                notify->error_state(I18N_NOOP("SSL write error"));
            return;
        }
    }
}
Ejemplo n.º 13
0
int roadmap_ssl_read (void *context, void *buffer, int buffer_size)
{
   int read;
   RoadMapSslIO ssl_io_ctx = (RoadMapSslIO) context;
   int received = 0;
   int err;
   do
   {
      read = SSL_read( ssl_io_ctx->ssl, buffer, buffer_size );

      buffer_size -= read;
      buffer += read;

      if ( ( err = SSL_get_error( ssl_io_ctx->ssl, read ) ) == SSL_ERROR_NONE )
      {
         received += read;
      }
      else
      {
         roadmap_log ( ROADMAP_ERROR, "Error (%d) in SSL_read: %s !!", err, ERR_error_string( err, NULL ) );
         received = 0;
         break;
      }

   } while ( SSL_pending( ssl_io_ctx->ssl ) && ( buffer_size > 0 ) );

   return received;
}
Ejemplo n.º 14
0
bool Curl_cyassl_data_pending(const struct connectdata* conn, int connindex)
{
  if(conn->ssl[connindex].handle)   /* SSL is in use */
    return (0 != SSL_pending(conn->ssl[connindex].handle)) ? TRUE : FALSE;
  else
    return FALSE;
}
Ejemplo n.º 15
0
static ssize_t mssl_read(void *cookie, char *buf, size_t len)
{
	_dprintf("%s()\n", __FUNCTION__);

	mssl_cookie_t *kuki = cookie;
	int total = 0;
	int n, err;

	do {
		n = SSL_read(kuki->ssl, &(buf[total]), len - total);
		_dprintf("SSL_read(max=%d) returned %d\n", len - total, n);

		err = SSL_get_error(kuki->ssl, n);
		switch (err) {
		case SSL_ERROR_NONE:
			total += n;
			break;
		case SSL_ERROR_ZERO_RETURN:
			total += n;
			goto OUT;
		case SSL_ERROR_WANT_WRITE:
		case SSL_ERROR_WANT_READ:
			break;
		default:
			_dprintf("%s(): SSL error %d\n", __FUNCTION__, err);
			mssl_print_err(kuki->ssl);
			if (total == 0) total = -1;
			goto OUT;
		}
	} while ((len - total > 0) && SSL_pending(kuki->ssl));

OUT:
	_dprintf("%s() returns %d\n", __FUNCTION__, total);
	return total;
}
Ejemplo n.º 16
0
int SSLSocket::read(void *buffer, unsigned long size) {
    ssl_internal_stack *stack;
    stack = (ssl_internal_stack *)idata;
    if(SSL_pending(stack->ssl) == 0) {
        ((char *)buffer)[0] = 0;
        return 0;
    }
    int ret;
    if((ret = SSL_read(stack->ssl, buffer, size)) <= 0) {
        switch(SSL_get_error(stack->ssl, ret)) {
        case SSL_ERROR_ZERO_RETURN:
            throw SSLConnectionClosed();
            break;
        case SSL_ERROR_WANT_WRITE:
        case SSL_ERROR_WANT_READ:
            throw SSLConnectionIsBusy();
            break;
        case SSL_ERROR_WANT_CONNECT:
        case SSL_ERROR_WANT_ACCEPT:
            throw NotConnected();
            break;
        case SSL_ERROR_WANT_X509_LOOKUP:
            throw CertificateLookupPending();
            break;
        case SSL_ERROR_SYSCALL:
        case SSL_ERROR_SSL:
            throw SSLGeneric();
            break;
        }
    }
    return ret;
}
Ejemplo n.º 17
0
static int s_sockexCanRead( PHB_SOCKEX pSock, HB_BOOL fBuffer, HB_MAXINT timeout )
{
   if( pSock->inbuffer )
      return 1;
   else if( pSock->sd == HB_NO_SOCKET )
   {
      hb_socketSetError( HB_SOCKET_ERR_INVALIDHANDLE );
      return -1;
   }
   else if( SSL_pending( HB_SSLSOCK_GET( pSock )->ssl ) )
   {
      long len;

      if( pSock->buffer == NULL )
      {
         if( pSock->readahead <= 0 )
            pSock->readahead = HB_SSLSOCK_READAHEAD;
         pSock->buffer = ( HB_BYTE * ) hb_xgrab( pSock->readahead );
      }
      len = hb_ssl_socketRead( HB_SSLSOCK_GET( pSock ), pSock->sd,
                               pSock->buffer, pSock->readahead, 0 );
      if( len > 0 )
      {
         pSock->inbuffer = len;
         len = 1;
      }
      return ( int ) len;
   }
   return fBuffer ? 0 : hb_socketSelectRead( pSock->sd, timeout );
}
Ejemplo n.º 18
0
/*
 * call-seq:
 *    ssl.sysread(length) => string
 *    ssl.sysread(length, buffer) => buffer
 *
 * === Parameters
 * * +length+ is a positive integer.
 * * +buffer+ is a string used to store the result.
 */
static VALUE
ossl_ssl_read(int argc, VALUE *argv, VALUE self)
{
  SSL *ssl;
  int ilen, nread = 0;
  VALUE len, str;

  rb_scan_args(argc, argv, "11", &len, &str);
  ilen = NUM2INT(len);

  if(NIL_P(str)) {
    str = rb_str_new(0, ilen);
  } else {
    StringValue(str);
    rb_str_modify(str);
    rb_str_resize(str, ilen);
  }

  if(ilen == 0) return str;

  Data_Get_Struct(self, SSL, ssl);
  int fd = rb_io_fd(ossl_ssl_get_io(self));

  if (ssl) {
    if(SSL_pending(ssl) <= 0)
      rb_thread_wait_fd(fd);
    for (;;) {
      nread = SSL_read(ssl, RSTRING_PTR(str), RSTRING_LEN(str));
      switch(ssl_get_error(ssl, nread)) {
      case SSL_ERROR_NONE:
        goto end;
      case SSL_ERROR_ZERO_RETURN:
        rb_eof_error();
      case SSL_ERROR_WANT_WRITE:
        rb_io_wait_writable(fd);
        continue;
      case SSL_ERROR_WANT_READ:
        rb_io_wait_readable(fd);
        continue;
      case SSL_ERROR_SYSCALL:
        if(ERR_peek_error() == 0 && nread == 0) rb_eof_error();
        rb_sys_fail(0);
      default:
        ossl_raise(eSSLError, "SSL_read:");
      }
    }
  }
  else {
    ID id_sysread = rb_intern("sysread");
    rb_warning("SSL session is not started yet.");
    return rb_funcall(ossl_ssl_get_io(self), id_sysread, 2, len, str);
  }

end:
  rb_str_set_len(str, nread);
  OBJ_TAINT(str);

  return str;
}
Ejemplo n.º 19
0
static inline int hasSocketPendingData (irc_dcc_session_t *dcc) {
#if defined (ENABLE_SSL)
    if (dcc->ssl) {
        return SSL_pending(dcc->ssl_ctx) != 0;
    }
#endif
    return 0;
}
Ejemplo n.º 20
0
LWS_VISIBLE int
lws_ssl_pending(struct lws *wsi)
{
	if (!wsi->ssl)
		return 0;

	return SSL_pending(wsi->ssl);
}
Ejemplo n.º 21
0
int fdinfo_pending(struct fdinfo *fdn)
{
#ifdef HAVE_OPENSSL
    if (o.ssl && fdn->ssl)
        return SSL_pending(fdn->ssl);
#endif
    return 0;
}
Ejemplo n.º 22
0
int
as_tls_read_pending(as_socket* sock)
{
	// Return the number of pending bytes in the TLS encryption
	// buffer.  If we aren't using TLS return 0.
	//
	return sock->ctx ? SSL_pending(sock->ssl) : 0;
}
Ejemplo n.º 23
0
/*
    Return the number of bytes read. Return -1 on errors and EOF. Distinguish EOF via mprIsSocketEof.
    If non-blocking, may return zero if no data or still handshaking.
 */
static ssize readOss(MprSocket *sp, void *buf, ssize len)
{
    OpenSocket      *osp;
    int             rc, error, retries, i;

    osp = (OpenSocket*) sp->sslSocket;
    assert(osp);

    if (osp->handle == 0) {
        return MPR_ERR_BAD_STATE;
    }
    /*
        Limit retries on WANT_READ. If non-blocking and no data, then this could spin forever.
     */
    retries = 5;
    for (i = 0; i < retries; i++) {
        rc = SSL_read(osp->handle, buf, (int) len);
        if (rc < 0) {
            error = SSL_get_error(osp->handle, rc);
            if (error == SSL_ERROR_WANT_READ || error == SSL_ERROR_WANT_CONNECT || error == SSL_ERROR_WANT_ACCEPT) {
                continue;
            }
            mprLog("info mpr ssl openssl", 5, "SSL_read %s", getOssError(sp));
        }
        break;
    }
    if (rc <= 0) {
        error = SSL_get_error(osp->handle, rc);
        if (error == SSL_ERROR_WANT_READ) {
            rc = 0;
        } else if (error == SSL_ERROR_WANT_WRITE) {
            rc = 0;
        } else if (error == SSL_ERROR_ZERO_RETURN) {
            sp->flags |= MPR_SOCKET_EOF;
            rc = -1;
        } else if (error == SSL_ERROR_SYSCALL) {
            sp->flags |= MPR_SOCKET_EOF;
            rc = -1;
        } else if (error != SSL_ERROR_ZERO_RETURN) {
            /* SSL_ERROR_SSL */
            mprLog("info mpr ssl openssl", 4, "%s", getOssError(sp));
            rc = -1;
            sp->flags |= MPR_SOCKET_EOF;
        }
    } else {
        if (!(sp->flags & MPR_SOCKET_SERVER) && !sp->secured) {
            if (checkPeerCertName(sp) < 0) {
                return MPR_ERR_BAD_STATE;
            }
        }
        setSecured(sp);
        if (SSL_pending(osp->handle) > 0) {
            sp->flags |= MPR_SOCKET_BUFFERED_READ;
            mprRecallWaitHandlerByFd(sp->fd);
        }
    }
    return rc;
}
Ejemplo n.º 24
0
int32
POP3Protocol::ReceiveLine(BString &line)
{
	int32 len = 0;
	bool flag = false;

	line = "";

	struct timeval tv;
	tv.tv_sec = POP3_RETRIEVAL_TIMEOUT / 1000000;
	tv.tv_usec = POP3_RETRIEVAL_TIMEOUT % 1000000;

	struct fd_set readSet;
	FD_ZERO(&readSet);
	FD_SET(fSocket, &readSet);

	int result;
#ifdef USE_SSL
	if (fUseSSL && SSL_pending(fSSL))
		result = 1;
	else
#endif
	result = select(fSocket + 1, &readSet, NULL, NULL, &tv);

	if (result > 0) {
		while (true) {
			// Hope there's an end of line out there else this gets stuck.
			int32 bytesReceived;
			uint8 c = 0;
#ifdef USE_SSL
			if (fUseSSL)
				bytesReceived = SSL_read(fSSL, (char*)&c, 1);
			else
#endif
			bytesReceived = recv(fSocket, &c, 1, 0);
			if (bytesReceived < 0)
				return errno;

			if (c == '\n' || bytesReceived == 0 /* EOF */)
				break;

			if (c == '\r') {
				flag = true;
			} else {
				if (flag) {
					len++;
					line += '\r';
					flag = false;
				}
				len++;
				line += (char)c;
			}
		}
	} else
		return errno;

	return len;
}
Ejemplo n.º 25
0
int
SPDYF_openssl_is_pending(struct SPDY_Session *session)
{
	/* From openssl docs:
	 * BUGS
SSL_pending() takes into account only bytes from the TLS/SSL record that is currently being processed (if any). If the SSL object's read_ahead flag is set, additional protocol bytes may have been read containing more TLS/SSL records; these are ignored by SSL_pending().
	 */
	return SSL_pending(session->io_context) > 0 ? SPDY_YES : SPDY_NO;
}
Ejemplo n.º 26
0
int
openssl_pending(openssl_con *con) {
  if (con->con) {
    int pending = SSL_pending(con->con);
    /*log_dbg("openssl_pending(%d)", pending);*/
    return pending;
  }
  return 0;
}
Ejemplo n.º 27
0
int	HttpsRetriever::openssl_poll (int fd, double timeout, int wait_for, void *ctx)
{
	  SSL *ssl = (SSL *) ctx;
	  if (timeout == 0)
	    return 1;
	  if (SSL_pending (ssl))
	    return 1;
	 // return select_fd (fd, timeout, wait_for);
}
Ejemplo n.º 28
0
LWS_VISIBLE int
lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len)
{
	struct lws_context *context = wsi->context;
	struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
	int n;

	if (!wsi->ssl)
		return lws_ssl_capable_read_no_ssl(wsi, buf, len);

	n = SSL_read(wsi->ssl, buf, len);
	/* manpage: returning 0 means connection shut down */
	if (!n)
		return LWS_SSL_CAPABLE_ERROR;

	if (n < 0) {
		n = SSL_get_error(wsi->ssl, n);
		if (n ==  SSL_ERROR_WANT_READ || n ==  SSL_ERROR_WANT_WRITE)
			return LWS_SSL_CAPABLE_MORE_SERVICE;

		return LWS_SSL_CAPABLE_ERROR;
	}

	/*
	 * if it was our buffer that limited what we read,
	 * check if SSL has additional data pending inside SSL buffers.
	 *
	 * Because these won't signal at the network layer with POLLIN
	 * and if we don't realize, this data will sit there forever
	 */
	if (n != len)
		goto bail;
	if (!wsi->ssl)
		goto bail;
	if (!SSL_pending(wsi->ssl))
		goto bail;
	if (wsi->pending_read_list_next)
		return n;
	if (wsi->pending_read_list_prev)
		return n;
	if (pt->pending_read_list == wsi)
		return n;

	/* add us to the linked list of guys with pending ssl */
	if (pt->pending_read_list)
		pt->pending_read_list->pending_read_list_prev = wsi;

	wsi->pending_read_list_next = pt->pending_read_list;
	wsi->pending_read_list_prev = NULL;
	pt->pending_read_list = wsi;

	return n;
bail:
	lws_ssl_remove_wsi_from_buffered_list(wsi);

	return n;
}
Ejemplo n.º 29
0
static bool Curl_cyassl_data_pending(const struct connectdata* conn,
                                     int connindex)
{
  const struct ssl_connect_data *connssl = &conn->ssl[connindex];
  if(BACKEND->handle)   /* SSL is in use */
    return (0 != SSL_pending(BACKEND->handle)) ? TRUE : FALSE;
  else
    return FALSE;
}
Ejemplo n.º 30
0
Archivo: ssl.c Proyecto: eddix/luasec
/**
 * Check if there is data in the buffer.
 */
static int meth_dirty(lua_State *L)
{
  int res = 0;
  p_ssl ssl = (p_ssl) luaL_checkudata(L, 1, "SSL:Connection");
  if (ssl->state != ST_SSL_CLOSED)
    res = !buffer_isempty(&ssl->buf) || SSL_pending(ssl->ssl);
  lua_pushboolean(L, res);
  return 1;
}