nts: define type for credentials
Add a NKSN_Credentials type to avoid referring to it as void *.
This commit is contained in:
parent
0e4995e10b
commit
80e627c86b
5 changed files with 18 additions and 15 deletions
|
@ -58,7 +58,7 @@ struct NKC_Instance_Record {
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
static void *client_credentials = NULL;
|
||||
static NKSN_Credentials client_credentials = NULL;
|
||||
static int client_credentials_refs = 0;
|
||||
|
||||
/* ================================================== */
|
||||
|
|
|
@ -95,7 +95,7 @@ static int initialised = 0;
|
|||
|
||||
/* Array of NKSN instances */
|
||||
static ARR_Instance sessions;
|
||||
static void *server_credentials;
|
||||
static NKSN_Credentials server_credentials;
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
|
|
|
@ -641,7 +641,7 @@ deinit_gnutls(void)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
static void *
|
||||
static NKSN_Credentials
|
||||
create_credentials(const char *cert, const char *key, const char *trusted_certs)
|
||||
{
|
||||
gnutls_certificate_credentials_t credentials = NULL;
|
||||
|
@ -679,7 +679,7 @@ create_credentials(const char *cert, const char *key, const char *trusted_certs)
|
|||
|
||||
credentials_counter++;
|
||||
|
||||
return credentials;
|
||||
return (NKSN_Credentials)credentials;
|
||||
|
||||
error:
|
||||
LOG(LOGS_ERR, "Could not set credentials : %s", gnutls_strerror(r));
|
||||
|
@ -691,7 +691,7 @@ error:
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
void *
|
||||
NKSN_Credentials
|
||||
NKSN_CreateServerCertCredentials(const char *cert, const char *key)
|
||||
{
|
||||
return create_credentials(cert, key, NULL);
|
||||
|
@ -699,7 +699,7 @@ NKSN_CreateServerCertCredentials(const char *cert, const char *key)
|
|||
|
||||
/* ================================================== */
|
||||
|
||||
void *
|
||||
NKSN_Credentials
|
||||
NKSN_CreateClientCertCredentials(const char *trusted_certs)
|
||||
{
|
||||
return create_credentials(NULL, NULL, trusted_certs);
|
||||
|
@ -708,9 +708,9 @@ NKSN_CreateClientCertCredentials(const char *trusted_certs)
|
|||
/* ================================================== */
|
||||
|
||||
void
|
||||
NKSN_DestroyCertCredentials(void *credentials)
|
||||
NKSN_DestroyCertCredentials(NKSN_Credentials credentials)
|
||||
{
|
||||
gnutls_certificate_free_credentials(credentials);
|
||||
gnutls_certificate_free_credentials((gnutls_certificate_credentials_t)credentials);
|
||||
credentials_counter--;
|
||||
deinit_gnutls();
|
||||
}
|
||||
|
@ -758,12 +758,13 @@ NKSN_DestroyInstance(NKSN_Instance inst)
|
|||
|
||||
int
|
||||
NKSN_StartSession(NKSN_Instance inst, int sock_fd, const char *label,
|
||||
void *credentials, double timeout)
|
||||
NKSN_Credentials credentials, double timeout)
|
||||
{
|
||||
assert(inst->state == KE_STOPPED);
|
||||
|
||||
inst->tls_session = create_tls_session(inst->server, sock_fd, inst->server_name,
|
||||
credentials, priority_cache);
|
||||
(gnutls_certificate_credentials_t)credentials,
|
||||
priority_cache);
|
||||
if (!inst->tls_session)
|
||||
return 0;
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@
|
|||
#include "nts_ke.h"
|
||||
#include "siv.h"
|
||||
|
||||
typedef struct NKSN_Credentials_Record *NKSN_Credentials;
|
||||
|
||||
typedef struct NKSN_Instance_Record *NKSN_Instance;
|
||||
|
||||
/* Handler for received NTS-KE messages. A zero return code stops
|
||||
|
@ -39,11 +41,11 @@ typedef int (*NKSN_MessageHandler)(void *arg);
|
|||
/* Get server or client credentials using a server certificate and key,
|
||||
or certificates of trusted CAs. The credentials may be shared between
|
||||
different clients or servers. */
|
||||
extern void *NKSN_CreateServerCertCredentials(const char *cert, const char *key);
|
||||
extern void *NKSN_CreateClientCertCredentials(const char *trusted_certs);
|
||||
extern NKSN_Credentials NKSN_CreateServerCertCredentials(const char *cert, const char *key);
|
||||
extern NKSN_Credentials NKSN_CreateClientCertCredentials(const char *trusted_certs);
|
||||
|
||||
/* Destroy the credentials */
|
||||
extern void NKSN_DestroyCertCredentials(void *credentials);
|
||||
extern void NKSN_DestroyCertCredentials(NKSN_Credentials credentials);
|
||||
|
||||
/* Create an instance */
|
||||
extern NKSN_Instance NKSN_CreateInstance(int server_mode, const char *server_name,
|
||||
|
@ -54,7 +56,7 @@ extern void NKSN_DestroyInstance(NKSN_Instance inst);
|
|||
|
||||
/* Start a new NTS-KE session */
|
||||
extern int NKSN_StartSession(NKSN_Instance inst, int sock_fd, const char *label,
|
||||
void *credentials, double timeout);
|
||||
NKSN_Credentials credentials, double timeout);
|
||||
|
||||
/* Begin an NTS-KE message. A request should be made right after starting
|
||||
the session and response should be made in the message handler. */
|
||||
|
|
|
@ -162,7 +162,7 @@ check_finished(void *arg)
|
|||
void
|
||||
test_unit(void)
|
||||
{
|
||||
void *client_cred, *server_cred;
|
||||
NKSN_Credentials client_cred, server_cred;
|
||||
int sock_fds[2], i;
|
||||
|
||||
LCL_Initialise();
|
||||
|
|
Loading…
Reference in a new issue