mirror of https://github.com/openssl/openssl.git
quic ddd demos: update makefile and demo sources
Update makefile and fix some signedness issues in the demo sources. Drop stray "\n" in the host-port format string that prevented ddd-01 from working (this was also noticed by Neil H). Also, determine the length of the message we are sending and send that many bytes (rather than send sizeof the buffer storing the message). These changes are part of https://github.com/openssl/project/issues/253 Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/22542)
This commit is contained in:
parent
bcc04ab287
commit
d1338fcf12
|
@ -1,29 +1,43 @@
|
||||||
#
|
#
|
||||||
# To run the demos when linked with a shared library (default):
|
# To run the demos when linked with a shared library (default) ensure that
|
||||||
|
# libcrypto and libssl are on the library path. For example to run the
|
||||||
|
# ddd-01-conn-blocking-tls demo:
|
||||||
#
|
#
|
||||||
# LD_LIBRARY_PATH=../.. make test
|
# LD_LIBRARY_PATH=../../.. ./ddd-01-conn-blocking-tls
|
||||||
|
#
|
||||||
|
# Building ddd-06-mem-uv-tls and ddd-06-mem-uv-quic requires the
|
||||||
|
# library libuv and header file. On Ubuntu, they are provided by the
|
||||||
|
# package "libuv1-dev".
|
||||||
|
|
||||||
|
TESTS_BASE = ddd-01-conn-blocking \
|
||||||
|
ddd-02-conn-nonblocking \
|
||||||
|
ddd-02-conn-nonblocking-threads \
|
||||||
|
ddd-03-fd-blocking \
|
||||||
|
ddd-04-fd-nonblocking \
|
||||||
|
ddd-05-mem-nonblocking \
|
||||||
|
ddd-06-mem-uv
|
||||||
|
|
||||||
TESTS_BASE=ddd-01-conn-blocking ddd-02-conn-nonblocking ddd-02-conn-nonblocking-threads \
|
|
||||||
ddd-03-fd-blocking ddd-04-fd-nonblocking ddd-05-mem-nonblocking ddd-06-mem-uv
|
|
||||||
TESTS = $(foreach x,$(TESTS_BASE),$(x)-tls $(x)-quic)
|
TESTS = $(foreach x,$(TESTS_BASE),$(x)-tls $(x)-quic)
|
||||||
|
|
||||||
CFLAGS = -I../../../include -O3 -g -Wall
|
CFLAGS = -I../../../include -g -Wall -Wsign-compare
|
||||||
LDFLAGS = -L../../..
|
LDFLAGS = -L../../..
|
||||||
LDLIBS = -lcrypto -lssl
|
LDLIBS = -lcrypto -lssl
|
||||||
|
|
||||||
|
CC_CMD = $(CC) $(CFLAGS) $(LDFLAGS) -o "$@" "$<" $(LDLIBS)
|
||||||
|
|
||||||
all: $(TESTS)
|
all: $(TESTS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(TESTS) *.o
|
rm -f $(TESTS) *.o
|
||||||
|
|
||||||
ddd-06-mem-uv-tls: ddd-06-mem-uv.c
|
ddd-%-tls: ddd-%.c
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o "$@" "$<" $(LDLIBS) -luv
|
$(CC_CMD)
|
||||||
|
|
||||||
ddd-06-mem-uv-quic: ddd-06-mem-uv.c
|
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -DUSE_QUIC -o "$@" "$<" $(LDLIBS) -luv
|
|
||||||
|
|
||||||
ddd-%-quic: ddd-%.c
|
ddd-%-quic: ddd-%.c
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -DUSE_QUIC -o "$@" "$<" $(LDLIBS)
|
$(CC_CMD) -DUSE_QUIC
|
||||||
|
|
||||||
ddd-%-tls: ddd-%.c
|
ddd-%-uv-tls: ddd-%-uv.c
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) -o "$@" "$<" $(LDLIBS)
|
$(CC_CMD) -luv
|
||||||
|
|
||||||
|
ddd-%-uv-quic: ddd-%-uv.c
|
||||||
|
$(CC_CMD) -luv -DUSE_QUIC
|
||||||
|
|
|
@ -141,15 +141,15 @@ int main(int argc, char **argv)
|
||||||
SSL_CTX *ctx = NULL;
|
SSL_CTX *ctx = NULL;
|
||||||
BIO *b = NULL;
|
BIO *b = NULL;
|
||||||
char buf[2048];
|
char buf[2048];
|
||||||
int l, res = 1;
|
int l, mlen, res = 1;
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf(stderr, "usage: %s host port\n", argv[0]);
|
fprintf(stderr, "usage: %s host port\n", argv[0]);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(host_port, sizeof(host_port), "%s:%s\n", argv[1], argv[2]);
|
snprintf(host_port, sizeof(host_port), "%s:%s", argv[1], argv[2]);
|
||||||
snprintf(msg, sizeof(msg),
|
mlen = snprintf(msg, sizeof(msg),
|
||||||
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
||||||
|
|
||||||
ctx = create_ssl_ctx();
|
ctx = create_ssl_ctx();
|
||||||
|
@ -160,11 +160,12 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
b = new_conn(ctx, host_port);
|
b = new_conn(ctx, host_port);
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
fprintf(stderr, "could not create conn\n");
|
fprintf(stderr, "could not create connection\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx(b, msg, sizeof(msg)) < sizeof(msg)) {
|
l = tx(b, msg, mlen);
|
||||||
|
if (l < mlen) {
|
||||||
fprintf(stderr, "tx error\n");
|
fprintf(stderr, "tx error\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Demo 2: Client — Managed Connection — Asynchronous Nonblocking
|
* Demo 2: Client — Managed Connection — Nonblocking
|
||||||
* ==============================================================
|
* ==============================================================
|
||||||
*
|
*
|
||||||
* This is an example of (part of) an application which uses libssl in an
|
* This is an example of (part of) an application which uses libssl in an
|
||||||
|
@ -260,7 +260,7 @@ int main(int argc, char **argv)
|
||||||
static char tx_msg[384], host_port[300];
|
static char tx_msg[384], host_port[300];
|
||||||
const char *tx_p = tx_msg;
|
const char *tx_p = tx_msg;
|
||||||
char rx_buf[2048];
|
char rx_buf[2048];
|
||||||
int res = 1, l, tx_len = sizeof(tx_msg)-1;
|
int res = 1, l, tx_len;
|
||||||
int timeout = 2000 /* ms */;
|
int timeout = 2000 /* ms */;
|
||||||
APP_CONN *conn = NULL;
|
APP_CONN *conn = NULL;
|
||||||
SSL_CTX *ctx = NULL;
|
SSL_CTX *ctx = NULL;
|
||||||
|
@ -271,7 +271,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(host_port, sizeof(host_port), "%s:%s", argv[1], argv[2]);
|
snprintf(host_port, sizeof(host_port), "%s:%s", argv[1], argv[2]);
|
||||||
snprintf(tx_msg, sizeof(tx_msg),
|
tx_len = snprintf(tx_msg, sizeof(tx_msg),
|
||||||
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
||||||
|
|
||||||
ctx = create_ssl_ctx();
|
ctx = create_ssl_ctx();
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
#include <openssl/ssl.h>
|
#include <openssl/ssl.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Demo 2: Client — Managed Connection — Asynchronous Nonblocking
|
* Demo 2: Client — Managed Connection — Nonblocking
|
||||||
* ==============================================================
|
* ==============================================================
|
||||||
*
|
*
|
||||||
* This is an example of (part of) an application which uses libssl in an
|
* This is an example of (part of) an application which uses libssl in an
|
||||||
|
@ -316,7 +316,7 @@ int main(int argc, char **argv)
|
||||||
static char tx_msg[384], host_port[300];
|
static char tx_msg[384], host_port[300];
|
||||||
const char *tx_p = tx_msg;
|
const char *tx_p = tx_msg;
|
||||||
char rx_buf[2048];
|
char rx_buf[2048];
|
||||||
int res = 1, l, tx_len = sizeof(tx_msg)-1;
|
int res = 1, l, tx_len;
|
||||||
#ifdef USE_QUIC
|
#ifdef USE_QUIC
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
#else
|
#else
|
||||||
|
@ -335,7 +335,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(host_port, sizeof(host_port), "%s:%s", argv[1], argv[2]);
|
snprintf(host_port, sizeof(host_port), "%s:%s", argv[1], argv[2]);
|
||||||
snprintf(tx_msg, sizeof(tx_msg),
|
tx_len = snprintf(tx_msg, sizeof(tx_msg),
|
||||||
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
||||||
|
|
||||||
ctx = create_ssl_ctx();
|
ctx = create_ssl_ctx();
|
||||||
|
|
|
@ -136,7 +136,7 @@ void teardown_ctx(SSL_CTX *ctx)
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int rc, fd = -1, l, res = 1;
|
int rc, fd = -1, l, mlen, res = 1;
|
||||||
static char msg[300];
|
static char msg[300];
|
||||||
struct addrinfo hints = {0}, *result = NULL;
|
struct addrinfo hints = {0}, *result = NULL;
|
||||||
SSL *ssl = NULL;
|
SSL *ssl = NULL;
|
||||||
|
@ -148,7 +148,7 @@ int main(int argc, char **argv)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(msg, sizeof(msg),
|
mlen = snprintf(msg, sizeof(msg),
|
||||||
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
||||||
|
|
||||||
ctx = create_ssl_ctx();
|
ctx = create_ssl_ctx();
|
||||||
|
@ -190,7 +190,8 @@ int main(int argc, char **argv)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx(ssl, msg, sizeof(msg)-1) < sizeof(msg)-1) {
|
l = tx(ssl, msg, mlen);
|
||||||
|
if (l < mlen) {
|
||||||
fprintf(stderr, "tx error\n");
|
fprintf(stderr, "tx error\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
* This is an example of (part of) an application which uses libssl in an
|
* This is an example of (part of) an application which uses libssl in an
|
||||||
* asynchronous, nonblocking fashion. The client is responsible for creating the
|
* asynchronous, nonblocking fashion. The client is responsible for creating the
|
||||||
* socket and passing it to libssl. The functions show all interactions with
|
* socket and passing it to libssl. The functions show all interactions with
|
||||||
* libssl the application makes, and wouldn hypothetically be linked into a
|
* libssl the application makes, and would hypothetically be linked into a
|
||||||
* larger application.
|
* larger application.
|
||||||
*/
|
*/
|
||||||
typedef struct app_conn_st {
|
typedef struct app_conn_st {
|
||||||
|
@ -297,7 +297,7 @@ int main(int argc, char **argv)
|
||||||
static char tx_msg[300];
|
static char tx_msg[300];
|
||||||
const char *tx_p = tx_msg;
|
const char *tx_p = tx_msg;
|
||||||
char rx_buf[2048];
|
char rx_buf[2048];
|
||||||
int l, tx_len = sizeof(tx_msg)-1;
|
int l, tx_len;
|
||||||
#ifdef USE_QUIC
|
#ifdef USE_QUIC
|
||||||
struct timeval timeout;
|
struct timeval timeout;
|
||||||
#else
|
#else
|
||||||
|
@ -316,7 +316,7 @@ int main(int argc, char **argv)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(tx_msg, sizeof(tx_msg),
|
tx_len = snprintf(tx_msg, sizeof(tx_msg),
|
||||||
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
||||||
|
|
||||||
ctx = create_ssl_ctx();
|
ctx = create_ssl_ctx();
|
||||||
|
|
|
@ -356,7 +356,7 @@ int main(int argc, char **argv)
|
||||||
static char tx_msg[300];
|
static char tx_msg[300];
|
||||||
const char *tx_p = tx_msg;
|
const char *tx_p = tx_msg;
|
||||||
char rx_buf[2048];
|
char rx_buf[2048];
|
||||||
int l, tx_len = sizeof(tx_msg)-1;
|
int l, tx_len;
|
||||||
int timeout = 2000 /* ms */;
|
int timeout = 2000 /* ms */;
|
||||||
APP_CONN *conn = NULL;
|
APP_CONN *conn = NULL;
|
||||||
struct addrinfo hints = {0}, *result = NULL;
|
struct addrinfo hints = {0}, *result = NULL;
|
||||||
|
@ -367,7 +367,7 @@ int main(int argc, char **argv)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(tx_msg, sizeof(tx_msg),
|
tx_len = snprintf(tx_msg, sizeof(tx_msg),
|
||||||
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n",
|
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n",
|
||||||
argv[1]);
|
argv[1]);
|
||||||
|
|
||||||
|
|
|
@ -294,7 +294,7 @@ static void net_read_alloc(uv_handle_t *handle,
|
||||||
static void on_rx_push(APP_CONN *conn)
|
static void on_rx_push(APP_CONN *conn)
|
||||||
{
|
{
|
||||||
int srd, rc;
|
int srd, rc;
|
||||||
size_t buf_len = 4096;
|
int buf_len = 4096;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (!conn->app_read_cb)
|
if (!conn->app_read_cb)
|
||||||
|
@ -696,6 +696,7 @@ static void post_write_get(APP_CONN *conn, int status, void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
char tx_msg[300];
|
char tx_msg[300];
|
||||||
|
int mlen;
|
||||||
|
|
||||||
static void post_connect(APP_CONN *conn, int status, void *arg)
|
static void post_connect(APP_CONN *conn, int status, void *arg)
|
||||||
{
|
{
|
||||||
|
@ -707,8 +708,8 @@ static void post_connect(APP_CONN *conn, int status, void *arg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wr = app_write(conn, tx_msg, sizeof(tx_msg)-1, post_write_get, NULL);
|
wr = app_write(conn, tx_msg, mlen, post_write_get, NULL);
|
||||||
if (wr < sizeof(tx_msg)-1) {
|
if (wr < mlen) {
|
||||||
fprintf(stderr, "error writing request");
|
fprintf(stderr, "error writing request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -726,7 +727,7 @@ int main(int argc, char **argv)
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(tx_msg, sizeof(tx_msg),
|
mlen = snprintf(tx_msg, sizeof(tx_msg),
|
||||||
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
"GET / HTTP/1.0\r\nHost: %s\r\n\r\n", argv[1]);
|
||||||
|
|
||||||
ctx = create_ssl_ctx();
|
ctx = create_ssl_ctx();
|
||||||
|
|
Loading…
Reference in New Issue