diff options
| author | Brent Cook <busterb@gmail.com> | 2015-05-23 19:23:35 -0500 |
|---|---|---|
| committer | Brent Cook <busterb@gmail.com> | 2015-05-23 19:27:57 -0500 |
| commit | 901ea927ce87fe739ff2688d43bfdc3eae506b1e (patch) | |
| tree | f7fd44c4d91c799bb557b8dbccfc75477cb0c9cb | |
| parent | 1a369f0fd7f3c6b7d17d0a9b358644a7d8216fc0 (diff) | |
| download | portable-901ea927ce87fe739ff2688d43bfdc3eae506b1e.tar.gz portable-901ea927ce87fe739ff2688d43bfdc3eae506b1e.tar.bz2 portable-901ea927ce87fe739ff2688d43bfdc3eae506b1e.zip | |
flesh out libtls test program a bit, move to tests
| -rw-r--r-- | libtls-standalone/Makefile.am | 2 | ||||
| -rw-r--r-- | libtls-standalone/app/test.c | 6 | ||||
| -rw-r--r-- | libtls-standalone/configure.ac | 2 | ||||
| -rw-r--r-- | libtls-standalone/src/Makefile.am | 2 | ||||
| -rw-r--r-- | libtls-standalone/tests/Makefile.am (renamed from libtls-standalone/app/Makefile.am) | 3 | ||||
| -rw-r--r-- | libtls-standalone/tests/test.c | 51 |
6 files changed, 56 insertions, 10 deletions
diff --git a/libtls-standalone/Makefile.am b/libtls-standalone/Makefile.am index 66fe845..2581717 100644 --- a/libtls-standalone/Makefile.am +++ b/libtls-standalone/Makefile.am | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | SUBDIRS = include compat src app man | 1 | SUBDIRS = include compat src tests man |
| 2 | ACLOCAL_AMFLAGS = -I m4 | 2 | ACLOCAL_AMFLAGS = -I m4 |
| 3 | 3 | ||
| 4 | pkgconfigdir = $(libdir)/pkgconfig | 4 | pkgconfigdir = $(libdir)/pkgconfig |
diff --git a/libtls-standalone/app/test.c b/libtls-standalone/app/test.c deleted file mode 100644 index e3c3f76..0000000 --- a/libtls-standalone/app/test.c +++ /dev/null | |||
| @@ -1,6 +0,0 @@ | |||
| 1 | #include <tls.h> | ||
| 2 | |||
| 3 | int main() | ||
| 4 | { | ||
| 5 | tls_init(); | ||
| 6 | } | ||
diff --git a/libtls-standalone/configure.ac b/libtls-standalone/configure.ac index e8fb24e..ebdd850 100644 --- a/libtls-standalone/configure.ac +++ b/libtls-standalone/configure.ac | |||
| @@ -42,10 +42,10 @@ CHECK_LIBC_CRYPTO_COMPAT | |||
| 42 | AC_CONFIG_FILES([ | 42 | AC_CONFIG_FILES([ |
| 43 | Makefile | 43 | Makefile |
| 44 | include/Makefile | 44 | include/Makefile |
| 45 | app/Makefile | ||
| 46 | compat/Makefile | 45 | compat/Makefile |
| 47 | man/Makefile | 46 | man/Makefile |
| 48 | src/Makefile | 47 | src/Makefile |
| 48 | tests/Makefile | ||
| 49 | libtls.pc | 49 | libtls.pc |
| 50 | ]) | 50 | ]) |
| 51 | 51 | ||
diff --git a/libtls-standalone/src/Makefile.am b/libtls-standalone/src/Makefile.am index e821186..7844525 100644 --- a/libtls-standalone/src/Makefile.am +++ b/libtls-standalone/src/Makefile.am | |||
| @@ -3,7 +3,7 @@ AM_CFLAGS = -I$(top_srcdir)/include | |||
| 3 | lib_LTLIBRARIES = libtls.la | 3 | lib_LTLIBRARIES = libtls.la |
| 4 | 4 | ||
| 5 | libtls_la_LDFLAGS = -version-info @LIBTLS_VERSION@ -no-undefined | 5 | libtls_la_LDFLAGS = -version-info @LIBTLS_VERSION@ -no-undefined |
| 6 | libtls_la_LIBADD = -lcrypto -lssl $(PLATFORM_LDADD) | 6 | libtls_la_LIBADD = -lcrypto -lssl -lcrypto $(PLATFORM_LDADD) |
| 7 | libtls_la_LIBADD += $(top_builddir)/compat/libcompat.la | 7 | libtls_la_LIBADD += $(top_builddir)/compat/libcompat.la |
| 8 | libtls_la_LIBADD += $(top_builddir)/compat/libcompatnoopt.la | 8 | libtls_la_LIBADD += $(top_builddir)/compat/libcompatnoopt.la |
| 9 | 9 | ||
diff --git a/libtls-standalone/app/Makefile.am b/libtls-standalone/tests/Makefile.am index 75a3dd6..1a08aef 100644 --- a/libtls-standalone/app/Makefile.am +++ b/libtls-standalone/tests/Makefile.am | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | AM_CFLAGS = -I$(top_srcdir)/include | 1 | AM_CFLAGS = -I$(top_srcdir)/include |
| 2 | 2 | ||
| 3 | bin_PROGRAMS = test | 3 | check_PROGRAMS = test |
| 4 | 4 | ||
| 5 | TESTS = test | ||
| 5 | test_SOURCES = test.c | 6 | test_SOURCES = test.c |
| 6 | test_LDADD = -lcrypto -lssl $(top_builddir)/src/libtls.la | 7 | test_LDADD = -lcrypto -lssl $(top_builddir)/src/libtls.la |
diff --git a/libtls-standalone/tests/test.c b/libtls-standalone/tests/test.c new file mode 100644 index 0000000..b2b7c67 --- /dev/null +++ b/libtls-standalone/tests/test.c | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <tls.h> | ||
| 3 | |||
| 4 | int main() | ||
| 5 | { | ||
| 6 | struct tls *tls; | ||
| 7 | struct tls_config *tls_config; | ||
| 8 | size_t written, read; | ||
| 9 | char buf[4096]; | ||
| 10 | |||
| 11 | if (tls_init() != 0) { | ||
| 12 | fprintf(stderr, "tls_init failed"); | ||
| 13 | return 1; | ||
| 14 | } | ||
| 15 | |||
| 16 | if ((tls = tls_client()) == NULL) | ||
| 17 | goto err; | ||
| 18 | |||
| 19 | if ((tls_config = tls_config_new()) == NULL) | ||
| 20 | goto err; | ||
| 21 | |||
| 22 | if (tls_config_set_ciphers(tls_config, "compat") != 0) | ||
| 23 | goto err; | ||
| 24 | |||
| 25 | tls_config_insecure_noverifycert(tls_config); | ||
| 26 | tls_config_insecure_noverifyname(tls_config); | ||
| 27 | |||
| 28 | if (tls_configure(tls, tls_config) != 0) | ||
| 29 | goto err; | ||
| 30 | |||
| 31 | if (tls_connect(tls, "google.com", "443") != 0) | ||
| 32 | goto err; | ||
| 33 | |||
| 34 | if (tls_write(tls, "GET /\r\n", 7, &written) != 0) | ||
| 35 | goto err; | ||
| 36 | |||
| 37 | if (tls_read(tls, buf, sizeof(buf), &read) != 0) | ||
| 38 | goto err; | ||
| 39 | |||
| 40 | buf[read - 1] = '\0'; | ||
| 41 | puts(buf); | ||
| 42 | |||
| 43 | if (tls_close(tls) != 0) | ||
| 44 | goto err; | ||
| 45 | |||
| 46 | return 0; | ||
| 47 | |||
| 48 | err: | ||
| 49 | fprintf(stderr, "%s\n", tls_error(tls)); | ||
| 50 | return 0; | ||
| 51 | } | ||
