diff --git a/.gitignore b/.gitignore index 048b48b..d7b5bba 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ tests/test_snprintf tests/test_sock tests/test_stanza tests/test_string +tests/test_xmppaddr m4/ libstrophe.project libs/ diff --git a/Makefile.am b/Makefile.am index f578a10..2409cb3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -165,6 +165,10 @@ TESTS = \ tests/test_stanza \ tests/test_resolver +if !DISABLE_TLS +TESTS += tests/test_xmppaddr +endif + check_PROGRAMS = $(TESTS) tests_check_parser_SOURCES = tests/check_parser.c tests/test.h @@ -230,6 +234,11 @@ tests_test_stanza_CFLAGS = $(STROPHE_FLAGS) tests_test_stanza_LDADD = $(STROPHE_LIBS) tests_test_stanza_LDFLAGS = -static +tests_test_xmppaddr_SOURCES = tests/test_xmppaddr.c +tests_test_xmppaddr_CFLAGS = $(STROPHE_FLAGS) -I$(top_srcdir)/src +tests_test_xmppaddr_LDADD = $(STROPHE_LIBS) +tests_test_xmppaddr_LDFLAGS = -static + format: @echo " * run clang-format on all sources" @dos2unix -q src/*.[ch] *.h tests/*.[ch] examples/*.c diff --git a/tests/cert.pem b/tests/cert.pem new file mode 100644 index 0000000..6ffe4a8 --- /dev/null +++ b/tests/cert.pem @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIICfjCCAjSgAwIBAgIIW5u5Vwn2Mv0wCgYIKoZIzj0EAwIwSzFJMEcGA1UEAwxA +dmVyeS5sb25nLnVzZXJuYW1lQHNvLnRoZS5hc24xLmxlbmd0aC5pcy5hLnZhbGlk +LmFzY2lpLmNoYXJhY3RlcjAgFw0yMTAzMDExOTExMDBaGA8yMTIxMDMwMTE5MTEw +MFowSzFJMEcGA1UEAwxAdmVyeS5sb25nLnVzZXJuYW1lQHNvLnRoZS5hc24xLmxl +bmd0aC5pcy5hLnZhbGlkLmFzY2lpLmNoYXJhY3RlcjBJMBMGByqGSM49AgEGCCqG +SM49AwEBAzIABI/tSR5cZ9iHCVw0JwmKLvV3TbxPg3kDdouB0R2WKEdEWwXMIHkE +85RReISg+9/JDaOCAQ4wggEKMAkGA1UdEwQCMAAwHQYDVR0OBBYEFPjLGyHxqlOV +nXJQ9YBrnureO8LiMB8GA1UdIwQYMBaAFPjLGyHxqlOVnXJQ9YBrnureO8LiMAsG +A1UdDwQEAwIHgDATBgNVHSUEDDAKBggrBgEFBQcDAjCBmgYDVR0RBIGSMIGPoE4G +CCsGAQUFBwgFoEIMQHZlcnkubG9uZy51c2VybmFtZUBzby50aGUuYXNuMS5sZW5n +dGguaXMuYS52YWxpZC5hc2NpaS5jaGFyYWN0ZXKBDnlldEBub3RoZXIuc2Fugg53 +d3cuc3Ryb3BoZS5pbaAdBggrBgEFBQcIBaARDA9zZWNvbmRAeG1wcC5qaWQwCgYI +KoZIzj0EAwIDOAAwNQIZAJmfqBhBMdaKCiWEuXu84K4+lznfzlRfmwIYCGRD1xk0 +9cRa3V6PVwYWz6HcdRdMUBUj +-----END CERTIFICATE----- diff --git a/tests/key.pem b/tests/key.pem new file mode 100644 index 0000000..290fff0 --- /dev/null +++ b/tests/key.pem @@ -0,0 +1,5 @@ +-----BEGIN EC PRIVATE KEY----- +MF8CAQEEGF7SsbTSOjzb97nFc7Qbt4sic+1nZk+ETqAKBggqhkjOPQMBAaE0AzIA +BI/tSR5cZ9iHCVw0JwmKLvV3TbxPg3kDdouB0R2WKEdEWwXMIHkE85RReISg+9/J +DQ== +-----END EC PRIVATE KEY----- diff --git a/tests/test_xmppaddr.c b/tests/test_xmppaddr.c new file mode 100644 index 0000000..34c774c --- /dev/null +++ b/tests/test_xmppaddr.c @@ -0,0 +1,68 @@ +/* test_xmppaddr.c +** libstrophe XMPP client library -- test routines for the xmppaddr +** certificate API's +** +** Copyright (C) 2021 Steffen Jaeckel +** +** This software is provided AS-IS with no warranty, either express +** or implied. +** +** This program is dual licensed under the MIT and GPLv3 licenses. +*/ + +#include +#include +#include + +#include "strophe.h" + +#include "test.h" + +int main() +{ + xmpp_ctx_t *ctx; + xmpp_conn_t *conn; + xmpp_log_t *log; + + char xmppaddr_num[] = "0"; + unsigned int n; + + xmpp_initialize(); + log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG); + ctx = xmpp_ctx_new(NULL, log); + conn = xmpp_conn_new(ctx); + + xmpp_conn_set_client_cert(conn, "tests/cert.pem", "tests/key.pem"); + + xmppaddr_num[0] = xmppaddr_num[0] + xmpp_conn_cert_xmppaddr_num(conn); + + COMPARE(xmppaddr_num, "2"); + + for (n = 0; n < 3; ++n) { + char *r = xmpp_conn_cert_xmppaddr(conn, n); + switch (n) { + case 0: + COMPARE(r, "very.long.username@so.the.asn1.length.is.a.valid.ascii." + "character"); + break; + case 1: + COMPARE(r, "second@xmpp.jid"); + break; + default: + if (r != NULL) { + printf("\nThere shall only be two id-on-xmppAddr SANs!\nFound " + "another one: %s\n", + r); + exit(1); + } + break; + } + free(r); + } + + xmpp_conn_release(conn); + xmpp_ctx_free(ctx); + xmpp_shutdown(); + + return 0; +}