flesh out libtls test program a bit, move to tests
This commit is contained in:
7
libtls-standalone/tests/Makefile.am
Normal file
7
libtls-standalone/tests/Makefile.am
Normal file
@@ -0,0 +1,7 @@
|
||||
AM_CFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
check_PROGRAMS = test
|
||||
|
||||
TESTS = test
|
||||
test_SOURCES = test.c
|
||||
test_LDADD = -lcrypto -lssl $(top_builddir)/src/libtls.la
|
51
libtls-standalone/tests/test.c
Normal file
51
libtls-standalone/tests/test.c
Normal file
@@ -0,0 +1,51 @@
|
||||
#include <stdio.h>
|
||||
#include <tls.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
struct tls *tls;
|
||||
struct tls_config *tls_config;
|
||||
size_t written, read;
|
||||
char buf[4096];
|
||||
|
||||
if (tls_init() != 0) {
|
||||
fprintf(stderr, "tls_init failed");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ((tls = tls_client()) == NULL)
|
||||
goto err;
|
||||
|
||||
if ((tls_config = tls_config_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
if (tls_config_set_ciphers(tls_config, "compat") != 0)
|
||||
goto err;
|
||||
|
||||
tls_config_insecure_noverifycert(tls_config);
|
||||
tls_config_insecure_noverifyname(tls_config);
|
||||
|
||||
if (tls_configure(tls, tls_config) != 0)
|
||||
goto err;
|
||||
|
||||
if (tls_connect(tls, "google.com", "443") != 0)
|
||||
goto err;
|
||||
|
||||
if (tls_write(tls, "GET /\r\n", 7, &written) != 0)
|
||||
goto err;
|
||||
|
||||
if (tls_read(tls, buf, sizeof(buf), &read) != 0)
|
||||
goto err;
|
||||
|
||||
buf[read - 1] = '\0';
|
||||
puts(buf);
|
||||
|
||||
if (tls_close(tls) != 0)
|
||||
goto err;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
fprintf(stderr, "%s\n", tls_error(tls));
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user