OpenVPN
Data Structures | Macros | Functions | Variables
test_pkcs11.c File Reference
#include "syshead.h"
#include "manage.h"
#include "base64.h"
#include "run_command.h"
#include "xkey_common.h"
#include "cert_data.h"
#include "pkcs11.h"
#include "ssl.h"
#include <setjmp.h>
#include <cmocka.h>
#include "test_common.h"
Include dependency graph for test_pkcs11.c:

Go to the source code of this file.

Data Structures

struct  test_cert
 

Macros

#define token_name   "Test Token"
 
#define PIN   "12345"
 
#define HASHSIZE   20
 

Functions

void crypto_print_openssl_errors (const unsigned int flags)
 Retrieve any occurred OpenSSL errors and print those errors.
 
int parse_line (const char *line, char **p, const int n, const char *file, const int line_num, msglvl_t msglevel, struct gc_arena *gc)
 
char * x509_get_subject (openvpn_x509_cert_t *cert, struct gc_arena *gc)
 
void query_user_clear (void)
 Wipes all data put into all of the query_user structs.
 
bool query_user_exec_builtin (void)
 Loop through configured query_user slots, using the built-in method for querying the user.
 
void query_user_add (char *prompt, size_t prompt_len, char *resp, size_t resp_len, bool echo)
 
void purge_user_pass (struct user_pass *up, const bool force)
 
char * management_query_pk_sig (struct management *man, const char *b64_data, const char *algorithm)
 
int digest_sign_verify (EVP_PKEY *privkey, EVP_PKEY *pubkey)
 
void init_cert_data (void)
 
bool get_user_pass_cr (struct user_pass *up, const char *auth_file, const char *prefix, const unsigned int flags, const char *unused)
 Retrieves the user credentials from various sources depending on the flags.
 
static void sha1_fingerprint (X509 *x509, uint8_t *hash, int capacity)
 
static int init (void **state)
 
static int cleanup (void **state)
 
static int setup_pkcs11 (void **state)
 
static int teardown_pkcs11 (void **state)
 
static struct test_certlookup_cert_byhash (uint8_t *sha1)
 
static void test_pkcs11_ids (void **state)
 
static void test_tls_ctx_use_pkcs11 (void **state)
 
static void test_tls_ctx_use_pkcs11__management (void **state)
 
int main (void)
 

Variables

struct managementmanagement
 
static struct test_cert certs [5]
 
static bool pkcs11_id_management
 
static char softhsm2_tokens_path [] = "softhsm2_tokens_XXXXXX"
 
static char softhsm2_conf_path [] = "softhsm2_conf_XXXXXX"
 
int num_certs
 
static const char * pkcs11_id_current
 
struct env_settest_set
 

Macro Definition Documentation

◆ HASHSIZE

#define HASHSIZE   20

Definition at line 43 of file test_pkcs11.c.

◆ PIN

#define PIN   "12345"

Definition at line 42 of file test_pkcs11.c.

◆ token_name

#define token_name   "Test Token"

Definition at line 41 of file test_pkcs11.c.

Function Documentation

◆ cleanup()

static int cleanup ( void **  state)
static

◆ crypto_print_openssl_errors()

void crypto_print_openssl_errors ( const unsigned int  flags)

Retrieve any occurred OpenSSL errors and print those errors.

Note that this function uses the not thread-safe OpenSSL error API.

Parameters
flagsFlags to indicate error type and priority.

Definition at line 51 of file test_pkcs11.c.

References msg.

◆ digest_sign_verify()

int digest_sign_verify ( EVP_PKEY *  privkey,
EVP_PKEY *  pubkey 
)

Referenced by test_tls_ctx_use_pkcs11().

◆ get_user_pass_cr()

bool get_user_pass_cr ( struct user_pass up,
const char *  auth_file,
const char *  prefix,
const unsigned int  flags,
const char *  auth_challenge 
)

Retrieves the user credentials from various sources depending on the flags.

Parameters
upThe user_pass structure to store the retrieved credentials.
auth_fileThe path to the authentication file. Might be NULL.
prefixThe prefix to prepend to user prompts.
flagsAdditional flags to control the behavior of the function.
auth_challengeThe authentication challenge string.
Returns
true if the user credentials were successfully retrieved, false otherwise.

Definition at line 159 of file test_pkcs11.c.

References GET_USER_PASS_NEED_STR, GET_USER_PASS_PASSWORD_ONLY, M_NONFATAL, msg, user_pass::password, PIN, pkcs11_id_current, pkcs11_id_management, and strncpynt().

◆ init()

static int init ( void **  state)
static

◆ init_cert_data()

void init_cert_data ( void  )

Definition at line 144 of file test_pkcs11.c.

References cert1, cert2, cert3, cert4, certs, cname1, cname2, cname3, cname4, privkey1, privkey2, privkey3, and privkey4.

Referenced by init().

◆ lookup_cert_byhash()

static struct test_cert * lookup_cert_byhash ( uint8_t *  sha1)
static

Definition at line 349 of file test_pkcs11.c.

References test_cert::cert, certs, test_cert::hash, and HASHSIZE.

Referenced by test_pkcs11_ids().

◆ main()

int main ( void  )

◆ management_query_pk_sig()

char * management_query_pk_sig ( struct management man,
const char *  b64_data,
const char *  algorithm 
)

Definition at line 111 of file test_pkcs11.c.

◆ parse_line()

int parse_line ( const char *  line,
char **  p,
const int  n,
const char *  file,
const int  line_num,
msglvl_t  msglevel,
struct gc_arena gc 
)

Definition at line 63 of file test_pkcs11.c.

◆ purge_user_pass()

void purge_user_pass ( struct user_pass up,
const bool  force 
)

Definition at line 104 of file test_pkcs11.c.

References secure_memzero().

◆ query_user_add()

void query_user_add ( char *  prompt,
size_t  prompt_len,
char *  resp,
size_t  resp_len,
bool  echo 
)

Definition at line 94 of file test_pkcs11.c.

◆ query_user_clear()

void query_user_clear ( void  )

Wipes all data put into all of the query_user structs.

Definition at line 75 of file test_pkcs11.c.

Referenced by query_user_SINGLE().

◆ query_user_exec_builtin()

bool query_user_exec_builtin ( void  )

Loop through configured query_user slots, using the built-in method for querying the user.

This method uses the console/TTY directly.

Returns
True if executing all the defined steps completed successfully

Loop through configured query_user slots, using the built-in method for querying the user.

Default method for querying user using default stdin/stdout on a console. This needs to be available as a backup interface for the alternative implementations in case they cannot query through their implementation specific methods.

If no alternative implementation is declared, a wrapper in console.h will ensure query_user_exec() will call this function instead.

Definition at line 88 of file test_pkcs11.c.

◆ setup_pkcs11()

static int setup_pkcs11 ( void **  state)
static

Definition at line 312 of file test_pkcs11.c.

References tls_libctx.

Referenced by main().

◆ sha1_fingerprint()

static void sha1_fingerprint ( X509 *  x509,
uint8_t *  hash,
int  capacity 
)
static

Definition at line 184 of file test_pkcs11.c.

Referenced by init(), test_pkcs11_ids(), and test_tls_ctx_use_pkcs11().

◆ teardown_pkcs11()

static int teardown_pkcs11 ( void **  state)
static

Definition at line 331 of file test_pkcs11.c.

References SIZE, and tls_libctx.

Referenced by main().

◆ test_pkcs11_ids()

static void test_pkcs11_ids ( void **  state)
static

◆ test_tls_ctx_use_pkcs11()

static void test_tls_ctx_use_pkcs11 ( void **  state)
static

◆ test_tls_ctx_use_pkcs11__management()

static void test_tls_ctx_use_pkcs11__management ( void **  state)
static

Definition at line 467 of file test_pkcs11.c.

References pkcs11_id_management, and test_tls_ctx_use_pkcs11().

Referenced by main().

◆ x509_get_subject()

char * x509_get_subject ( openvpn_x509_cert_t cert,
struct gc_arena gc 
)

Variable Documentation

◆ certs

struct test_cert certs[5]
static

◆ management

Definition at line 46 of file test_pkcs11.c.

◆ num_certs

int num_certs

Definition at line 138 of file test_pkcs11.c.

Referenced by init(), and test_pkcs11_ids().

◆ pkcs11_id_current

const char* pkcs11_id_current
static

Definition at line 139 of file test_pkcs11.c.

Referenced by get_user_pass_cr(), and test_tls_ctx_use_pkcs11().

◆ pkcs11_id_management

bool pkcs11_id_management
static

◆ softhsm2_conf_path

char softhsm2_conf_path[] = "softhsm2_conf_XXXXXX"
static

Definition at line 137 of file test_pkcs11.c.

Referenced by cleanup(), and init().

◆ softhsm2_tokens_path

char softhsm2_tokens_path[] = "softhsm2_tokens_XXXXXX"
static

Definition at line 136 of file test_pkcs11.c.

Referenced by cleanup(), and init().

◆ test_set

struct env_set* test_set

Definition at line 140 of file test_pkcs11.c.

Referenced by cleanup(), and init().