]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
nts: define type for credentials
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 11 Feb 2021 10:05:25 +0000 (11:05 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 11 Feb 2021 15:13:39 +0000 (16:13 +0100)
Add a NKSN_Credentials type to avoid referring to it as void *.

nts_ke_client.c
nts_ke_server.c
nts_ke_session.c
nts_ke_session.h
test/unit/nts_ke_session.c

index d99346d2ed3b05da99cb1cb069671dde3fb530b5..5e87fe44e624087031b6b975e31c02de80d2f76c 100644 (file)
@@ -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;
 
 /* ================================================== */
index 7a45903acb30a2b2b51e2f19998d05e257d6db69..4303f70a0b25fef06777c80ef04376babe1f0826 100644 (file)
@@ -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;
 
 /* ================================================== */
 
index ac6df257620f53fb4ab79b2b3c41c6bdc153c0a6..822df217537a4a94fbc55ca08344037260d615af 100644 (file)
@@ -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;
 
index a5647d5ef00fbf266234845749d3785b3c4a9f1f..e5d3ccf6e94e4f88c37405b2300bd57bfc039637 100644 (file)
@@ -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. */
index 1465ac98d2f383b0b9d62ad1fe26ea88c5d98688..0aadc54f581dd1cea00761f4409d77b8a1aca889 100644 (file)
@@ -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();