Skip to content

Commit

Permalink
session wrapper UPDATE remove unused crl funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
roman authored and michalvasko committed Jul 4, 2024
1 parent 84ec0ce commit 790c736
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 159 deletions.
85 changes: 0 additions & 85 deletions src/session_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
#define _GNU_SOURCE

#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <poll.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

#include <curl/curl.h>
Expand Down Expand Up @@ -393,20 +391,6 @@ nc_tls_pem_to_privkey_wrap(const char *privkey_data)
return pkey;
}

int
nc_tls_import_crl_path_wrap(const char *path, void *crl_store)
{
int rc;

rc = mbedtls_x509_crl_parse_file(crl_store, path);
if (rc) {
ERR(NULL, "Failed to import CRL from file \"%s\" (%s).", path, nc_get_mbedtls_str_err(rc));
return 1;
}

return 0;
}

int
nc_server_tls_add_crl_to_store_wrap(const unsigned char *crl_data, size_t size, void *crl_store)
{
Expand Down Expand Up @@ -979,75 +963,6 @@ nc_client_tls_load_trusted_certs_wrap(void *cert_store, const char *file_path, c
return 0;
}

int
nc_client_tls_load_crl_wrap(void *crl_store, const char *file_path, const char *dir_path)
{
int rc, ret = 0;
DIR *dir = NULL;
struct dirent *entry;
struct stat st = {0};
char *path = NULL;

if (file_path && (rc = mbedtls_x509_crl_parse_file(crl_store, file_path))) {
ERR(NULL, "Loading CRL from file \"%s\" failed (%s).", file_path, nc_get_mbedtls_str_err(rc));
return 1;
}

if (dir_path) {
/* parse the CRLs in the directory one by one */
dir = opendir(dir_path);
if (!dir) {
ERR(NULL, "Failed to open directory \"%s\" (%s).", dir_path, strerror(errno));
return 1;
}

while ((entry = readdir(dir))) {
if (!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) {
/* skip current and parent directory */
continue;
}

rc = asprintf(&path, "%s/%s", dir_path, entry->d_name);
NC_CHECK_ERRMEM_GOTO(rc == -1, ret = 1; path = NULL, cleanup);

if (stat(path, &st) == -1) {
if (errno == ENOENT) {
/* broken symbolic link, ignore */
free(path);
path = NULL;
continue;
} else {
ERR(NULL, "Failed to get information about \"%s\" (%s).", path, strerror(errno));
ret = 1;
goto cleanup;
}
}

if (!S_ISREG(st.st_mode)) {
/* not a regular file, ignore */
free(path);
path = NULL;
continue;
}

rc = mbedtls_x509_crl_parse_file(crl_store, path);
if (rc) {
WRN(NULL, "Loading CRL from file \"%s\" failed (%s), skipping.", path, nc_get_mbedtls_str_err(rc));
}

free(path);
path = NULL;
}
}

cleanup:
free(path);
if (dir) {
closedir(dir);
}
return ret;
}

int
nc_client_tls_set_hostname_wrap(void *tls_session, const char *hostname)
{
Expand Down
55 changes: 0 additions & 55 deletions src/session_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,49 +197,6 @@ nc_tls_pem_to_privkey_wrap(const char *privkey_data)
return pkey;
}

int
nc_tls_import_crl_path_wrap(const char *path, void *crl_store)
{
int ret = 0, rc;
X509_CRL *crl = NULL;
FILE *f;

f = fopen(path, "r");
if (!f) {
ERR(NULL, "Unable to open CRL file \"%s\".", path);
return 1;
}

/* try PEM first */
crl = PEM_read_X509_CRL(f, NULL, NULL, NULL);
if (crl) {
/* success */
goto ok;
}

/* PEM failed, try DER */
rewind(f);
crl = d2i_X509_CRL_fp(f, NULL);
if (!crl) {
ERR(NULL, "Reading CRL from file \"%s\" failed.", path);
ret = 1;
goto cleanup;
}

ok:
rc = X509_STORE_add_crl(crl_store, crl);
if (!rc) {
ERR(NULL, "Error adding CRL to store (%s).", ERR_reason_error_string(ERR_get_error()));
ret = 1;
goto cleanup;
}

cleanup:
fclose(f);
X509_CRL_free(crl);
return ret;
}

int
nc_server_tls_add_crl_to_store_wrap(const unsigned char *crl_data, size_t size, void *crl_store)
{
Expand Down Expand Up @@ -707,18 +664,6 @@ nc_client_tls_load_trusted_certs_wrap(void *cert_store, const char *file_path, c
return 0;
}

int
nc_client_tls_load_crl_wrap(void *crl_store, const char *file_path, const char *dir_path)
{
if (!X509_STORE_load_locations(crl_store, file_path, dir_path)) {
ERR(NULL, "Loading CRLs from file \"%s\" or directory \"%s\" failed (%s).",
file_path, dir_path, ERR_reason_error_string(ERR_get_error()));
return 1;
}

return 0;
}

int
nc_client_tls_set_hostname_wrap(void *tls_session, const char *hostname)
{
Expand Down
19 changes: 0 additions & 19 deletions src/session_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,6 @@ int nc_tls_add_cert_to_store_wrap(void *cert, void *cert_store);
*/
void * nc_tls_pem_to_privkey_wrap(const char *privkey_data);

/**
* @brief Imports CRL from a file.
*
* @param[in] path Path to the CRL file.
* @param[in] crl_store CRL store to import the CRL to.
* @return 0 on success, non-zero on fail.
*/
int nc_tls_import_crl_path_wrap(const char *path, void *crl_store);

/**
* @brief Parses and adds a CRL to a CRL store.
*
Expand Down Expand Up @@ -413,16 +404,6 @@ int nc_client_tls_load_cert_key_wrap(const char *cert_path, const char *key_path
*/
int nc_client_tls_load_trusted_certs_wrap(void *cert_store, const char *file_path, const char *dir_path);

/**
* @brief Load client's CRLs.
*
* @param[in] crl_store CRL store.
* @param[in] file_path Path to the file with CRLs.
* @param[in] dir_path Path to the directory with CRLs.
* @return 0 on success, non-zero on fail.
*/
int nc_client_tls_load_crl_wrap(void *crl_store, const char *file_path, const char *dir_path);

/**
* @brief Set the hostname for the TLS session.
*
Expand Down

0 comments on commit 790c736

Please sign in to comment.