![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
#include "nilorea/n_log.h"#include "nilorea/n_network.h"#include "nilorea/n_str.h"#include "nilorea/n_x509.h"#include <pthread.h>#include <stdio.h>#include <string.h>Go to the source code of this file.
Data Structures | |
| struct | SRV_ARG |
| Carries the served leaf certificate to the SNI pick callback. More... | |
Macros | |
| #define | SSL_HOSTNAME_PORT "27433" |
| Port the local TLS listener binds for this test. | |
| #define | SSL_HOSTNAME_RIGHT "right.test" |
| Name the served leaf certificate is actually issued for. | |
| #define | SSL_HOSTNAME_WRONG "wrong.test" |
| Name that certificate does NOT carry. | |
Functions | |
| int | main (void) |
| static int | pick_cert (const char *sni, N_STR **cert_pem, N_STR **key_pem, void *user_data) |
| SNI pick callback: always serve the one leaf this test minted. | |
| static void * | server_thread (void *a) |
| Accept TLS connections until asked to stop, serving the same leaf to all. | |
| static int | try_connect (const char *ask, const char *ca_path, int verify, int *out_verify_ok) |
Connect asking for ask and report what verification concluded. | |
| struct SRV_ARG |
Carries the served leaf certificate to the SNI pick callback.
Definition at line 58 of file ex_network_ssl_hostname.c.
| Data Fields | ||
|---|---|---|
| N_STR * | cert | |
| N_STR * | key | |
| int | ready | |
| #define SSL_HOSTNAME_PORT "27433" |
Port the local TLS listener binds for this test.
Definition at line 51 of file ex_network_ssl_hostname.c.
Referenced by main(), server_thread(), and try_connect().
| #define SSL_HOSTNAME_RIGHT "right.test" |
Name the served leaf certificate is actually issued for.
Definition at line 53 of file ex_network_ssl_hostname.c.
Referenced by main().
| #define SSL_HOSTNAME_WRONG "wrong.test" |
Name that certificate does NOT carry.
Definition at line 55 of file ex_network_ssl_hostname.c.
Referenced by main().
| int main | ( | void | ) |
Definition at line 126 of file ex_network_ssl_hostname.c.
References SRV_ARG::cert, N_STR::data, free_nstr, SRV_ARG::key, LOG_ERR, LOG_INFO, n_log, n_x509_generate_ca(), n_x509_mint_host_cert(), netw_close(), netw_connect_to(), netw_unload_openssl(), NETWORK_IPV4, SRV_ARG::ready, server_thread(), set_log_level(), SSL_HOSTNAME_PORT, SSL_HOSTNAME_RIGHT, SSL_HOSTNAME_WRONG, try_connect(), u_sleep(), and N_STR::written.
SNI pick callback: always serve the one leaf this test minted.
| sni | The name the client asked for (ignored: the point is that it may differ). |
| cert_pem | Receives a copy of the leaf certificate. |
| key_pem | Receives a copy of its key. |
| user_data | The SRV_ARG. |
Definition at line 72 of file ex_network_ssl_hostname.c.
References SRV_ARG::cert, SRV_ARG::key, and nstrdup().
Referenced by server_thread().
|
static |
Accept TLS connections until asked to stop, serving the same leaf to all.
| a | The SRV_ARG. |
Definition at line 85 of file ex_network_ssl_hostname.c.
References netw_accept_ssl_with_sni_cb(), netw_close(), netw_make_listening(), NETWORK_IPV4, pick_cert(), SRV_ARG::ready, and SSL_HOSTNAME_PORT.
|
static |
Connect asking for ask and report what verification concluded.
| ask | Hostname the client asks for (and expects on the certificate). |
| ca_path | File holding the CA that issued the served leaf. |
| verify | 1 to enable peer verification, 0 to leave it off. |
| out_verify_ok | Receives 1 when the identity matched, 0 otherwise. |
Definition at line 110 of file ex_network_ssl_hostname.c.
References netw_close(), netw_ssl_connect_client_to(), netw_ssl_do_handshake(), netw_ssl_get_verify_result(), netw_ssl_set_ca(), netw_ssl_set_verify(), NETWORK_IPV4, and SSL_HOSTNAME_PORT.
Referenced by main().