Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_x509.c File Reference

X.509 helpers implementation: CA generation and per-host leaf minting. More...

#include "nilorea/n_x509.h"
#include "nilorea/n_common.h"
#include "nilorea/n_log.h"
#include <arpa/inet.h>
#include <string.h>
#include <openssl/bn.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
+ Include dependency graph for n_x509.c:

Go to the source code of this file.

Macros

#define N_X509_KEY_BITS   2048
 RSA modulus size in bits used for the CA and leaf keys.
 
#define N_X509_SAN_BUF   300
 buffer size for a subjectAltName value string
 
#define N_X509_SERIAL_BITS   64
 random serial number size in bits
 

Functions

static int add_ext (X509 *issuer, X509 *subject, int nid, const char *value)
 
static int bio_to_nstr (BIO *bio, N_STR **out)
 
static EVP_PKEY * gen_rsa (int bits)
 
static int host_is_ip (const char *host)
 
int n_x509_generate_ca (const char *cn, int days, N_STR **ca_cert_pem, N_STR **ca_key_pem)
 Generate a self-signed certificate authority (CA) keypair and cert.
 
int n_x509_keypair_pem (int bits, N_STR **key_pem)
 Generate an RSA private key and return it as a PEM string.
 
int n_x509_mint_host_cert (const char *host, const N_STR *ca_cert_pem, const N_STR *ca_key_pem, int days, N_STR **leaf_cert_pem, N_STR **leaf_key_pem)
 Mint a per-host leaf certificate signed by the given CA.
 
static int pkey_to_pem (EVP_PKEY *pkey, N_STR **out)
 
static int set_cn (X509_NAME *name, const char *cn)
 
static int set_random_serial (X509 *x)
 
static int x509_to_pem (X509 *x, N_STR **out)
 

Detailed Description

X.509 helpers implementation: CA generation and per-host leaf minting.

Author
Castagnier Mickael
Version
1.0

Definition in file n_x509.c.

Macro Definition Documentation

◆ N_X509_KEY_BITS

#define N_X509_KEY_BITS   2048

RSA modulus size in bits used for the CA and leaf keys.

Definition at line 51 of file n_x509.c.

◆ N_X509_SAN_BUF

#define N_X509_SAN_BUF   300

buffer size for a subjectAltName value string

Definition at line 55 of file n_x509.c.

◆ N_X509_SERIAL_BITS

#define N_X509_SERIAL_BITS   64

random serial number size in bits

Definition at line 53 of file n_x509.c.

Function Documentation

◆ add_ext()

static int add_ext ( X509 *  issuer,
X509 *  subject,
int  nid,
const char *  value 
)
static

Definition at line 110 of file n_x509.c.

Referenced by n_x509_generate_ca(), and n_x509_mint_host_cert().

+ Here is the caller graph for this function:

◆ bio_to_nstr()

static int bio_to_nstr ( BIO *  bio,
N_STR **  out 
)
static

Definition at line 59 of file n_x509.c.

References char_to_nstr_ex().

Referenced by pkey_to_pem(), and x509_to_pem().

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

◆ gen_rsa()

static EVP_PKEY * gen_rsa ( int  bits)
static

Definition at line 144 of file n_x509.c.

Referenced by n_x509_generate_ca(), n_x509_keypair_pem(), and n_x509_mint_host_cert().

+ Here is the caller graph for this function:

◆ host_is_ip()

static int host_is_ip ( const char *  host)
static

Definition at line 133 of file n_x509.c.

Referenced by n_x509_mint_host_cert().

+ Here is the caller graph for this function:

◆ pkey_to_pem()

static int pkey_to_pem ( EVP_PKEY *  pkey,
N_STR **  out 
)
static

Definition at line 71 of file n_x509.c.

References bio_to_nstr().

Referenced by n_x509_generate_ca(), n_x509_keypair_pem(), and n_x509_mint_host_cert().

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

◆ set_cn()

static int set_cn ( X509_NAME *  name,
const char *  cn 
)
static

Definition at line 126 of file n_x509.c.

Referenced by n_x509_generate_ca(), and n_x509_mint_host_cert().

+ Here is the caller graph for this function:

◆ set_random_serial()

static int set_random_serial ( X509 *  x)
static

Definition at line 95 of file n_x509.c.

References N_X509_SERIAL_BITS.

Referenced by n_x509_generate_ca(), and n_x509_mint_host_cert().

+ Here is the caller graph for this function:

◆ x509_to_pem()

static int x509_to_pem ( X509 *  x,
N_STR **  out 
)
static

Definition at line 83 of file n_x509.c.

References bio_to_nstr().

Referenced by n_x509_generate_ca(), and n_x509_mint_host_cert().

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