Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
ex_network_sni.c File Reference
#include "nilorea/n_common.h"
#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 <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <openssl/ssl.h>
#include <openssl/x509.h>
Include dependency graph for ex_network_sni.c:

Go to the source code of this file.

Data Structures

struct  CA_CTX
 CA used by the server to mint per-host leaves. More...
struct  SRV
 server worker context More...

Macros

#define MSG_LEN   18
 fixed exchange message length (both messages are 17 chars + NUL)
#define SNI_HOST   "test.host.example"
 the host name the client requests via SNI

Functions

static NETWORK * bind_free (char *port_out, size_t port_out_len)
int main (int argc, char **argv)
static int pick_cb (const char *sni, N_STR **cert_pem, N_STR **key_pem, void *user_data)
void process_args (int argc, char **argv)
static void * server_fn (void *p)

Data Structure Documentation

◆ CA_CTX

struct CA_CTX

CA used by the server to mint per-host leaves.

Examples
ex_network_alpn.c, and ex_network_sni.c.

Definition at line 61 of file ex_network_alpn.c.

Collaboration diagram for CA_CTX:
Data Fields
N_STR * cert the CA certificate PEM
N_STR * key the CA private key PEM

◆ SRV

struct SRV

server worker context

Examples
ex_network_alpn.c, ex_network_sni.c, and ex_network_ssl_nonblock.c.

Definition at line 67 of file ex_network_alpn.c.

Collaboration diagram for SRV:
Data Fields
CA_CTX * ca the CA to mint leaves with
SSL_CTX * ctx shared server ctx (owned by main)
char h2_path[128] the :path of the last HTTP/2 request
int h2_requests requests served over HTTP/2
NETWORK * listen the listening socket

listening NETWORK

int ok set to 1 once the server completed the exchange
int rounds_done how many connections it served
char selected[3][32] what ALPN the server answered per round

Macro Definition Documentation

◆ MSG_LEN

#define MSG_LEN   18

fixed exchange message length (both messages are 17 chars + NUL)

Examples
ex_network_sni.c, and ex_network_ssl_nonblock.c.

Definition at line 45 of file ex_network_sni.c.

Referenced by main(), server_fn(), and server_fn().

◆ SNI_HOST

#define SNI_HOST   "test.host.example"

the host name the client requests via SNI

Examples
ex_network_sni.c.

Definition at line 43 of file ex_network_sni.c.

Referenced by main().

Function Documentation

◆ bind_free()

NETWORK * bind_free ( char * port_out,
size_t port_out_len )
static

Definition at line 119 of file ex_network_sni.c.

References netw_close(), netw_make_listening(), and NETWORK_IPALL.

Here is the call graph for this function:

◆ main()

◆ pick_cb()

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

Definition at line 93 of file ex_network_sni.c.

References CA_CTX::cert, CA_CTX::key, LOG_DEBUG, n_log, and n_x509_mint_host_cert().

Here is the call graph for this function:

◆ process_args()

void process_args ( int argc,
char ** argv )

Definition at line 61 of file ex_network_sni.c.

References LOG_DEBUG, LOG_ERR, LOG_INFO, LOG_NOTICE, LOG_NULL, and set_log_level().

Here is the call graph for this function:

◆ server_fn()

void * server_fn ( void * p)
static

Definition at line 101 of file ex_network_sni.c.

References SRV::ca, SRV::listen, LOG_NOTICE, MSG_LEN, n_log, netw_accept_ssl_with_sni_cb(), netw_close(), SRV::ok, pick_cb(), recv_ssl_data(), and send_ssl_data().

Here is the call graph for this function: