Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_network_ssl_hostname.c File Reference
#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>
Include dependency graph for ex_network_ssl_hostname.c:

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.

Data Structure Documentation

◆ SRV_ARG

struct SRV_ARG

Carries the served leaf certificate to the SNI pick callback.

Examples
ex_network_ssl_hostname.c.

Definition at line 58 of file ex_network_ssl_hostname.c.

Collaboration diagram for SRV_ARG:
Data Fields
N_STR * cert
N_STR * key
int ready

Macro Definition Documentation

◆ SSL_HOSTNAME_PORT

#define SSL_HOSTNAME_PORT   "27433"

Port the local TLS listener binds for this test.

Examples
ex_network_ssl_hostname.c.

Definition at line 51 of file ex_network_ssl_hostname.c.

Referenced by main(), server_thread(), and try_connect().

◆ SSL_HOSTNAME_RIGHT

#define SSL_HOSTNAME_RIGHT   "right.test"

Name the served leaf certificate is actually issued for.

Examples
ex_network_ssl_hostname.c.

Definition at line 53 of file ex_network_ssl_hostname.c.

Referenced by main().

◆ SSL_HOSTNAME_WRONG

#define SSL_HOSTNAME_WRONG   "wrong.test"

Name that certificate does NOT carry.

Examples
ex_network_ssl_hostname.c.

Definition at line 55 of file ex_network_ssl_hostname.c.

Referenced by main().

Function Documentation

◆ main()

◆ pick_cert()

int pick_cert ( const char * sni,
N_STR ** cert_pem,
N_STR ** key_pem,
void * user_data )
static

SNI pick callback: always serve the one leaf this test minted.

Parameters
sniThe name the client asked for (ignored: the point is that it may differ).
cert_pemReceives a copy of the leaf certificate.
key_pemReceives a copy of its key.
user_dataThe SRV_ARG.
Returns
0 to proceed with the handshake.
Examples
ex_network_ssl_hostname.c.

Definition at line 72 of file ex_network_ssl_hostname.c.

References SRV_ARG::cert, SRV_ARG::key, and nstrdup().

Referenced by server_thread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ server_thread()

void * server_thread ( void * a)
static

Accept TLS connections until asked to stop, serving the same leaf to all.

Parameters
aThe SRV_ARG.
Returns
NULL always.

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.

Here is the call graph for this function:

◆ try_connect()

int try_connect ( const char * ask,
const char * ca_path,
int verify,
int * out_verify_ok )
static

Connect asking for ask and report what verification concluded.

Parameters
askHostname the client asks for (and expects on the certificate).
ca_pathFile holding the CA that issued the served leaf.
verify1 to enable peer verification, 0 to leave it off.
out_verify_okReceives 1 when the identity matched, 0 otherwise.
Returns
1 when the handshake completed, 0 when it did not.
Examples
ex_network_ssl_hostname.c.

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().

Here is the call graph for this function:
Here is the caller graph for this function: