Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ssl try #105

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LIB_WS = libws.a
INCLUDE = include
CFLAGS += -Wall -Wextra -O2
CFLAGS += -I $(INCLUDE) -std=c99 -pedantic
LDLIBS = $(LIB_WS) -pthread
LDLIBS = $(LIB_WS) -pthread -lssl -lcrypto
ARFLAGS = cru
MCSS_DIR ?= /usr/bin/
MANPAGES = doc/man/man3
Expand Down
Empty file added cert/cert.pem
Empty file.
Empty file added cert/key.pem
Empty file.
26 changes: 25 additions & 1 deletion examples/echo/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ void onmessage(ws_cli_conn_t client,
* ws_sendframe_bin()
* ws_sendframe_bin_bcast()
*/
#ifdef ENABLE_OPENSSL
ws_sendframe_txt(client, (char*)msg);
#else
ws_sendframe_bcast(8080, (char *)msg, size, type);
#endif
}

/**
Expand All @@ -116,6 +120,23 @@ void onmessage(ws_cli_conn_t client,
*/
int main(void)
{
#ifdef ENABLE_OPENSSL
ws_socket(&(struct ws_server){
/*
* Bind host:
* localhost -> localhost/127.0.0.1
* 0.0.0.0 -> global IPv4
* :: -> global IPv4+IPv6 (DualStack)
*/
.host = "0.0.0.0",
.port = 8443,
.thread_loop = 0,
.timeout_ms = 1000,
.evs.onopen = &onopen,
.evs.onclose = &onclose,
.evs.onmessage = &onmessage
});
#else
ws_socket(&(struct ws_server){
/*
* Bind host:
Expand All @@ -124,13 +145,16 @@ int main(void)
* :: -> global IPv4+IPv6 (DualStack)
*/
.host = "0.0.0.0",
.port = 8080,
.port = 8443,
.thread_loop = 0,
.timeout_ms = 1000,
.evs.onopen = &onopen,
.evs.onclose = &onclose,
.evs.onmessage = &onmessage
});
#endif



/*
* If you want to execute code past ws_socket(), set
Expand Down
4 changes: 2 additions & 2 deletions extra/toyws/toyws.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ int tws_receiveframe(struct tws_ctx *ctx, char **buff,
{
cur_byte = next_byte(ctx, &ret);
if (cur_byte < 0)
return (ret == 0 ? frame_length : ret);
return (ret == 0 ? frame_length : (uint64_t)ret);

*buf = cur_byte;
}
Expand All @@ -406,5 +406,5 @@ int tws_receiveframe(struct tws_ctx *ctx, char **buff,
/* Fill other infos. */
*frm_type = opcode;

return (ret == 0 ? frame_length : ret);
return (ret == 0 ? frame_length : (uint64_t)ret);
}
5 changes: 5 additions & 0 deletions include/ws.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,13 @@ extern "C" {
/**@}*/

#ifndef AFL_FUZZ
#ifdef ENABLE_OPENSSL
#define SEND(client,buf,len) SSL_write((client)->ssl, (buf), (len))
#define RECV(client,buf,len) SSL_read((client)->ssl, (buf), (len))
#else
#define SEND(client,buf,len) send_all((client), (buf), (len), MSG_NOSIGNAL)
#define RECV(fd,buf,len) recv((fd)->client_sock, (buf), (len), 0)
#endif
#else
#define SEND(client,buf,len) write(fileno(stdout), (buf), (len))
#define RECV(fd,buf,len) read((fd)->client_sock, (buf), (len))
Expand Down
Loading
Loading