aboutsummaryrefslogtreecommitdiff
path: root/src/sp/transport/tls/tls_tran_test.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-10-05 16:51:15 -0700
committerGarrett D'Amore <garrett@damore.org>2025-10-05 20:56:39 -0700
commit06d6d80f8c92ef1d3bd7c00c919e10a411183cb3 (patch)
treeedf8d4cff9b2f595ccd9e3cb4db3cf31eb13bc02 /src/sp/transport/tls/tls_tran_test.c
parentd1bd64c8251171ac8e1d4e71ab8726c2a64fd55a (diff)
downloadnng-06d6d80f8c92ef1d3bd7c00c919e10a411183cb3.tar.gz
nng-06d6d80f8c92ef1d3bd7c00c919e10a411183cb3.tar.bz2
nng-06d6d80f8c92ef1d3bd7c00c919e10a411183cb3.zip
fixes #2173 New TLS cert API - replaces the properties for CN and ALTNAMES.
This will replace the NNG_OPT_TLS_PEER_ALTNAMES and NNG_OPT_TLS_PEER_CN properties, and gives a bit more access to the certificate, as well as direct access to the raw DER form, which should allow use in other APIs.
Diffstat (limited to 'src/sp/transport/tls/tls_tran_test.c')
-rw-r--r--src/sp/transport/tls/tls_tran_test.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/sp/transport/tls/tls_tran_test.c b/src/sp/transport/tls/tls_tran_test.c
index 73c299c8..1b69c65f 100644
--- a/src/sp/transport/tls/tls_tran_test.c
+++ b/src/sp/transport/tls/tls_tran_test.c
@@ -227,11 +227,31 @@ test_tls_pipe_details(void)
p = nng_msg_get_pipe(msg);
NUTS_TRUE(nng_pipe_id(p) >= 0);
#if !defined(NNG_TLS_ENGINE_WOLFSSL) || defined(NNG_WOLFSSL_HAVE_PEER_CERT)
- char *cn;
- NUTS_PASS(nng_pipe_get_string(p, NNG_OPT_TLS_PEER_CN, &cn));
- NUTS_ASSERT(cn != NULL);
- NUTS_MATCH(cn, "127.0.0.1");
- nng_strfree(cn);
+ nng_tls_cert *cert;
+ char *name;
+ NUTS_PASS(nng_pipe_peer_cert(p, &cert));
+ NUTS_PASS(nng_tls_cert_subject(cert, &name));
+ NUTS_ASSERT(name != NULL);
+ nng_log_debug(NULL, "SUBJECT: %s", name);
+ NUTS_PASS(nng_tls_cert_issuer(cert, &name));
+ NUTS_ASSERT(name != NULL);
+ nng_log_debug(NULL, "ISSUER: %s", name);
+ NUTS_PASS(nng_tls_cert_serial_number(cert, &name));
+ NUTS_ASSERT(name != NULL);
+ nng_log_debug(NULL, "SERIAL: %s", name);
+ NUTS_PASS(nng_tls_cert_subject_cn(cert, &name));
+ NUTS_MATCH(name, "127.0.0.1");
+ NUTS_PASS(nng_tls_cert_next_alt(cert, &name));
+ nng_log_debug(NULL, "FIRST ALT: %s", name);
+ NUTS_MATCH(name, "localhost");
+ NUTS_FAIL(nng_tls_cert_next_alt(cert, &name), NNG_ENOENT);
+ struct tm when;
+ NUTS_PASS(nng_tls_cert_not_before(cert, &when));
+ nng_log_debug(NULL, "BEGINS: %s", asctime(&when));
+ NUTS_PASS(nng_tls_cert_not_after(cert, &when));
+ nng_log_debug(NULL, "EXPIRES: %s", asctime(&when));
+
+ nng_tls_cert_free(cert);
#endif
nng_msg_free(msg);
NUTS_CLOSE(s2);