From: Daniel Salzman Date: Wed, 10 Apr 2024 07:08:25 +0000 (+0200) Subject: libknot: rename knot_quic_creds and related functions to knot_creds... X-Git-Tag: v3.4.0~110^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a73f9f73660980c307da2f9afa335a4f1cb20368;p=thirdparty%2Fknot-dns.git libknot: rename knot_quic_creds and related functions to knot_creds... --- diff --git a/distro/pkg/deb/libknot14.symbols b/distro/pkg/deb/libknot14.symbols index 81753f533a..17c321018b 100644 --- a/distro/pkg/deb/libknot14.symbols +++ b/distro/pkg/deb/libknot14.symbols @@ -8,6 +8,10 @@ libknot.so.14 libknot14 #MINVER# KNOT_DB_LMDB_RDONLY@Base 3.3.0 KNOT_DB_LMDB_WRITEMAP@Base 3.3.0 KNOT_DUMP_STYLE_DEFAULT@Base 3.3.0 + knot_creds_cert@Base 3.4.0 + knot_creds_free@Base 3.4.0 + knot_creds_init@Base 3.4.0 + knot_creds_init_peer@Base 3.4.0 knot_ctl_accept@Base 3.3.0 knot_ctl_alloc@Base 3.3.0 knot_ctl_bind@Base 3.3.0 @@ -120,15 +124,10 @@ libknot.so.14 libknot14 #MINVER# knot_quic_conn_local_port@Base 3.3.0 knot_quic_conn_new_stream@Base 3.3.0 knot_quic_conn_next_timeout@Base 3.3.3 - knot_quic_conn_pin@Base 3.3.0 knot_quic_conn_rtt@Base 3.3.0 knot_quic_conn_stream_free@Base 3.3.0 - knot_quic_creds_cert@Base 3.3.0 - knot_quic_free_creds@Base 3.3.0 knot_quic_handle@Base 3.3.0 knot_quic_hanle_expiry@Base 3.3.3 - knot_quic_init_creds@Base 3.3.0 - knot_quic_init_creds_peer@Base 3.3.0 knot_quic_send@Base 3.3.0 knot_quic_session_available@Base 3.3.0 knot_quic_session_load@Base 3.3.0 @@ -188,6 +187,18 @@ libknot.so.14 libknot14 #MINVER# knot_tcp_sweep@Base 3.3.0 knot_tcp_table_free@Base 3.3.0 knot_tcp_table_new@Base 3.3.0 + knot_tls_conn_del@Base 3.4.0 + knot_tls_conn_new@Base 3.4.0 + knot_tls_ctx_free@Base 3.4.0 + knot_tls_ctx_new@Base 3.4.0 + knot_tls_handshake@Base 3.4.0 + knot_tls_pin@Base 3.4.0 + knot_tls_pin_check@Base 3.4.0 + knot_tls_recv@Base 3.4.0 + knot_tls_recv_dns@Base 3.4.0 + knot_tls_send@Base 3.4.0 + knot_tls_send_dns@Base 3.4.0 + knot_tls_session@Base 3.4.0 knot_tsig_add@Base 3.3.0 knot_tsig_append@Base 3.3.0 knot_tsig_client_check@Base 3.3.0 diff --git a/src/knot/query/quic-requestor.c b/src/knot/query/quic-requestor.c index 680d983dcc..7492efd79b 100644 --- a/src/knot/query/quic-requestor.c +++ b/src/knot/query/quic-requestor.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 CZ.NIC, z.s.p.o. +/* Copyright (C) 2024 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -156,7 +156,7 @@ int knot_qreq_connect(struct knot_quic_reply **out, int fd, struct sockaddr_storage *remote, struct sockaddr_storage *local, - const struct knot_quic_creds *local_creds, + const struct knot_creds *local_creds, const uint8_t *peer_pin, uint8_t peer_pin_len, bool *reused_fd, @@ -179,8 +179,7 @@ int knot_qreq_connect(struct knot_quic_reply **out, r->send_reply = qr_send_reply; r->free_reply = qr_free_reply; - struct knot_quic_creds *creds = knot_quic_init_creds_peer(local_creds, - peer_pin, peer_pin_len); + struct knot_creds *creds = knot_creds_init_peer(local_creds, peer_pin, peer_pin_len); if (creds == NULL) { free(r); return KNOT_ENOMEM; @@ -190,7 +189,7 @@ int knot_qreq_connect(struct knot_quic_reply **out, knot_quic_table_t *table = knot_quic_table_new(1, QUIC_BUF_SIZE, QUIC_BUF_SIZE, 0, creds); if (table == NULL) { - knot_quic_free_creds(creds); + knot_creds_free(creds); free(r); return KNOT_ENOMEM; } @@ -294,7 +293,7 @@ void knot_qreq_close(struct knot_quic_reply *r, bool send_close) knot_quic_table_rem(conn, table); knot_quic_cleanup(&conn, 1); if (table != NULL) { - knot_quic_free_creds(table->creds); + knot_creds_free(table->creds); } knot_quic_table_free(table); free(r); diff --git a/src/knot/query/quic-requestor.h b/src/knot/query/quic-requestor.h index c606d6c9d8..083254d3ad 100644 --- a/src/knot/query/quic-requestor.h +++ b/src/knot/query/quic-requestor.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 CZ.NIC, z.s.p.o. +/* Copyright (C) 2024 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,7 +23,7 @@ int knot_qreq_connect(struct knot_quic_reply **out, int fd, struct sockaddr_storage *remote, struct sockaddr_storage *local, - const struct knot_quic_creds *local_creds, + const struct knot_creds *local_creds, const uint8_t *peer_pin, uint8_t peer_pin_len, bool *reused_fd, diff --git a/src/knot/query/requestor.c b/src/knot/query/requestor.c index 7e7ae0cbba..9d3a1b6979 100644 --- a/src/knot/query/requestor.c +++ b/src/knot/query/requestor.c @@ -215,7 +215,7 @@ knot_request_t *knot_request_make_generic(knot_mm_t *mm, const struct sockaddr_storage *remote, const struct sockaddr_storage *source, knot_pkt_t *query, - const struct knot_quic_creds *creds, + const struct knot_creds *creds, const query_edns_data_t *edns, const knot_tsig_key_t *tsig_key, const uint8_t *pin, @@ -266,7 +266,7 @@ knot_request_t *knot_request_make_generic(knot_mm_t *mm, knot_request_t *knot_request_make(knot_mm_t *mm, const conf_remote_t *remote, knot_pkt_t *query, - const struct knot_quic_creds *creds, + const struct knot_creds *creds, const query_edns_data_t *edns, knot_request_flag_t flags) { diff --git a/src/knot/query/requestor.h b/src/knot/query/requestor.h index 97d9d04d4e..241be040d1 100644 --- a/src/knot/query/requestor.h +++ b/src/knot/query/requestor.h @@ -74,7 +74,7 @@ typedef struct { knot_sign_context_t sign; /*!< Required for async. DDNS processing. */ - const struct knot_quic_creds *creds; + const struct knot_creds *creds; size_t pin_len; uint8_t pin[]; } knot_request_t; @@ -110,7 +110,7 @@ knot_request_t *knot_request_make_generic(knot_mm_t *mm, const struct sockaddr_storage *remote, const struct sockaddr_storage *source, knot_pkt_t *query, - const struct knot_quic_creds *creds, + const struct knot_creds *creds, const query_edns_data_t *edns, const knot_tsig_key_t *tsig_key, const uint8_t *pin, @@ -126,7 +126,7 @@ knot_request_t *knot_request_make_generic(knot_mm_t *mm, knot_request_t *knot_request_make(knot_mm_t *mm, const conf_remote_t *remote, knot_pkt_t *query, - const struct knot_quic_creds *creds, + const struct knot_creds *creds, const query_edns_data_t *edns, knot_request_flag_t flags); diff --git a/src/knot/query/tls-requestor.c b/src/knot/query/tls-requestor.c index 01385dbe93..a466b9f565 100644 --- a/src/knot/query/tls-requestor.c +++ b/src/knot/query/tls-requestor.c @@ -21,19 +21,18 @@ #include "libknot/quic/tls.h" int knot_tls_req_ctx_init(knot_tls_req_ctx_t *ctx, int fd, - const struct knot_quic_creds *local_creds, + const struct knot_creds *local_creds, const uint8_t *peer_pin, uint8_t peer_pin_len, int io_timeout_ms) { - struct knot_quic_creds *creds = knot_quic_init_creds_peer(local_creds, - peer_pin, peer_pin_len); + struct knot_creds *creds = knot_creds_init_peer(local_creds, peer_pin, peer_pin_len); if (creds == NULL) { return KNOT_ENOMEM; } ctx->ctx = knot_tls_ctx_new(creds, io_timeout_ms, false); if (ctx->ctx == NULL) { - knot_quic_free_creds(creds); + knot_creds_free(creds); return KNOT_ENOMEM; } @@ -49,7 +48,7 @@ int knot_tls_req_ctx_init(knot_tls_req_ctx_t *ctx, int fd, void knot_tls_req_ctx_deinit(knot_tls_req_ctx_t *ctx) { if (ctx != NULL && ctx->ctx != NULL) { - knot_quic_free_creds(ctx->ctx->creds); + knot_creds_free(ctx->ctx->creds); knot_tls_conn_del(ctx->conn); knot_tls_ctx_free(ctx->ctx); memset(ctx, 0, sizeof(*ctx)); diff --git a/src/knot/query/tls-requestor.h b/src/knot/query/tls-requestor.h index a3103ff97b..535bbe8860 100644 --- a/src/knot/query/tls-requestor.h +++ b/src/knot/query/tls-requestor.h @@ -28,8 +28,6 @@ typedef struct knot_tls_req_ctx { struct knot_tls_conn *conn; } knot_tls_req_ctx_t; -struct knot_quic_creds; - /*! * \brief Initialize TLS requestor context. * @@ -43,7 +41,7 @@ struct knot_quic_creds; * \return KNOT_E* */ int knot_tls_req_ctx_init(knot_tls_req_ctx_t *ctx, int fd, - const struct knot_quic_creds *local_creds, + const struct knot_creds *local_creds, const uint8_t *peer_pin, uint8_t peer_pin_len, int io_timeout_ms); diff --git a/src/knot/server/server.c b/src/knot/server/server.c index 0ad47b1371..2a1285e5fe 100644 --- a/src/knot/server/server.c +++ b/src/knot/server/server.c @@ -609,7 +609,7 @@ static int init_creds(server_t *server, conf_t *conf) log_debug("QUIC/TLS, using self-generated key '%s' with " "one-time certificate", key_file); } - server->quic_creds = knot_quic_init_creds(cert_file, key_file); + server->quic_creds = knot_creds_init(cert_file, key_file); free(cert_file); if (server->quic_creds == NULL) { log_error("QUIC/TLS, failed to initialize server credentials with key '%s'", @@ -901,7 +901,7 @@ void server_deinit(server_t *server) global_sessticket_pool = NULL; knot_unreachables_deinit(&global_unreachables); - knot_quic_free_creds(server->quic_creds); + knot_creds_free(server->quic_creds); } static int server_init_handler(server_t *server, int index, int thread_count, @@ -1577,7 +1577,7 @@ size_t server_cert_pin(server_t *server, uint8_t *out, size_t out_size) size_t bin_pin_size = sizeof(bin_pin); gnutls_x509_crt_t cert = NULL; if (server->quic_creds != NULL && - knot_quic_creds_cert(server->quic_creds, &cert) == KNOT_EOK && + knot_creds_cert(server->quic_creds, &cert) == KNOT_EOK && gnutls_x509_crt_get_key_id(cert, GNUTLS_KEYID_USE_SHA256, bin_pin, &bin_pin_size) == GNUTLS_E_SUCCESS) { pin_size = knot_base64_encode(bin_pin, bin_pin_size, out, out_size); diff --git a/src/knot/server/server.h b/src/knot/server/server.h index 77c4171418..8aa0093598 100644 --- a/src/knot/server/server.h +++ b/src/knot/server/server.h @@ -31,7 +31,7 @@ struct server; struct knot_xdp_socket; -struct knot_quic_creds; +struct knot_creds; /*! * \brief I/O handler structure. @@ -129,7 +129,7 @@ typedef struct server { zone_backup_ctxs_t backup_ctxs; /*! \brief Crendentials context for QUIC. */ - struct knot_quic_creds *quic_creds; + struct knot_creds *quic_creds; } server_t; /*! diff --git a/src/libknot/quic/quic_conn.c b/src/libknot/quic/quic_conn.c index 7617e6f427..420eb0b663 100644 --- a/src/libknot/quic/quic_conn.c +++ b/src/libknot/quic/quic_conn.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 CZ.NIC, z.s.p.o. +/* Copyright (C) 2024 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,7 +45,7 @@ static int cmp_expiry_heap_nodes(void *c1, void *c2) _public_ knot_quic_table_t *knot_quic_table_new(size_t max_conns, size_t max_ibufs, size_t max_obufs, - size_t udp_payload, struct knot_quic_creds *creds) + size_t udp_payload, struct knot_creds *creds) { size_t table_size = max_conns * BUCKETS_PER_CONNS; diff --git a/src/libknot/quic/quic_conn.h b/src/libknot/quic/quic_conn.h index ca21a5b193..689b133cdd 100644 --- a/src/libknot/quic/quic_conn.h +++ b/src/libknot/quic/quic_conn.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2023 CZ.NIC, z.s.p.o. +/* Copyright (C) 2024 CZ.NIC, z.s.p.o. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ #define MAX_STREAMS_PER_CONN 10 // this limits the number of un-finished streams per conn (i.e. if response has been recvd with FIN, it doesn't count) struct ngtcp2_cid; // declaration taken from wherever in ngtcp2 -struct knot_quic_creds; +struct knot_creds; struct knot_quic_reply; struct knot_sweep_stats; @@ -119,7 +119,7 @@ typedef struct knot_quic_table { void (*log_cb)(const char *); const char *qlog_dir; uint64_t hash_secret[4]; - struct knot_quic_creds *creds; + struct knot_creds *creds; struct heap *expiry_heap; knot_quic_cid_t *conns[]; } knot_quic_table_t; @@ -136,7 +136,7 @@ typedef struct knot_quic_table { * \return Allocated table, or NULL. */ knot_quic_table_t *knot_quic_table_new(size_t max_conns, size_t max_ibufs, size_t max_obufs, - size_t udp_payload, struct knot_quic_creds *creds); + size_t udp_payload, struct knot_creds *creds); /*! * \brief Free QUIC table including its contents. diff --git a/src/libknot/quic/tls.c b/src/libknot/quic/tls.c index a945d36e8c..1dee7f7dc7 100644 --- a/src/libknot/quic/tls.c +++ b/src/libknot/quic/tls.c @@ -37,7 +37,7 @@ #define EAGAIN_MAX_FOR_GNUTLS 10 // gnutls_record_recv() has been observed to return GNUTLS_E_AGAIN repetitively and excessively, leading to infinite loops. This limits the number of re-tries. _public_ -knot_tls_ctx_t *knot_tls_ctx_new(struct knot_quic_creds *creds, unsigned io_timeout, +knot_tls_ctx_t *knot_tls_ctx_new(struct knot_creds *creds, unsigned io_timeout, bool server) { knot_tls_ctx_t *res = calloc(1, sizeof(*res)); diff --git a/src/libknot/quic/tls.h b/src/libknot/quic/tls.h index 4b4ecfc6b9..ca87079e18 100644 --- a/src/libknot/quic/tls.h +++ b/src/libknot/quic/tls.h @@ -14,6 +14,15 @@ along with this program. If not, see . */ +/*! + * \file + * + * \brief Pure TLS functionality. + * + * \addtogroup quic + * @{ + */ + #pragma once #include @@ -21,7 +30,7 @@ #include typedef struct knot_tls_ctx { - struct knot_quic_creds *creds; + struct knot_creds *creds; unsigned handshake_timeout; unsigned io_timeout; bool server; @@ -50,7 +59,7 @@ typedef struct knot_tls_conn { * * \return Initialized context or NULL. */ -knot_tls_ctx_t *knot_tls_ctx_new(struct knot_quic_creds *creds, unsigned io_timeout, +knot_tls_ctx_t *knot_tls_ctx_new(struct knot_creds *creds, unsigned io_timeout, bool server); /*! @@ -127,3 +136,5 @@ ssize_t knot_tls_recv_dns(knot_tls_conn_t *conn, void *data, size_t size); * \return Either exactly 'size' or a negative error code. */ ssize_t knot_tls_send_dns(knot_tls_conn_t *conn, void *data, size_t size); + +/*! @} */ diff --git a/src/libknot/quic/tls_common.c b/src/libknot/quic/tls_common.c index e290772de1..210c59dddb 100644 --- a/src/libknot/quic/tls_common.c +++ b/src/libknot/quic/tls_common.c @@ -31,14 +31,14 @@ #include "libknot/attribute.h" #include "libknot/error.h" -typedef struct knot_quic_creds { +typedef struct knot_creds { gnutls_certificate_credentials_t tls_cert; gnutls_anti_replay_t tls_anti_replay; gnutls_datum_t tls_ticket_key; bool peer; uint8_t peer_pin_len; uint8_t peer_pin[]; -} knot_quic_creds_t; +} knot_creds_t; static int tls_anti_replay_db_add_func(void *dbf, time_t exp_time, const gnutls_datum_t *key, @@ -148,10 +148,9 @@ finish: } _public_ -struct knot_quic_creds *knot_quic_init_creds(const char *cert_file, - const char *key_file) +struct knot_creds *knot_creds_init(const char *cert_file, const char *key_file) { - knot_quic_creds_t *creds = calloc(1, sizeof(*creds)); + knot_creds_t *creds = calloc(1, sizeof(*creds)); if (creds == NULL) { return NULL; } @@ -186,16 +185,16 @@ struct knot_quic_creds *knot_quic_init_creds(const char *cert_file, return creds; fail: - knot_quic_free_creds(creds); + knot_creds_free(creds); return NULL; } _public_ -struct knot_quic_creds *knot_quic_init_creds_peer(const struct knot_quic_creds *local_creds, - const uint8_t *peer_pin, - uint8_t peer_pin_len) +struct knot_creds *knot_creds_init_peer(const struct knot_creds *local_creds, + const uint8_t *peer_pin, + uint8_t peer_pin_len) { - knot_quic_creds_t *creds = calloc(1, sizeof(*creds) + peer_pin_len); + knot_creds_t *creds = calloc(1, sizeof(*creds) + peer_pin_len); if (creds == NULL) { return NULL; } @@ -220,7 +219,7 @@ struct knot_quic_creds *knot_quic_init_creds_peer(const struct knot_quic_creds * } _public_ -int knot_quic_creds_cert(struct knot_quic_creds *creds, struct gnutls_x509_crt_int **cert) +int knot_creds_cert(struct knot_creds *creds, struct gnutls_x509_crt_int **cert) { if (creds == NULL || cert == NULL) { return KNOT_EINVAL; @@ -241,7 +240,7 @@ int knot_quic_creds_cert(struct knot_quic_creds *creds, struct gnutls_x509_crt_i } _public_ -void knot_quic_free_creds(struct knot_quic_creds *creds) +void knot_creds_free(struct knot_creds *creds) { if (creds == NULL) { return; @@ -259,7 +258,7 @@ void knot_quic_free_creds(struct knot_quic_creds *creds) _public_ int knot_tls_session(struct gnutls_session_int **session, - struct knot_quic_creds *creds, + struct knot_creds *creds, const char *priority, const char *alpn, bool early_data, @@ -355,7 +354,7 @@ error: _public_ int knot_tls_pin_check(struct gnutls_session_int *session, - struct knot_quic_creds *creds) + struct knot_creds *creds) { if (creds->peer_pin_len == 0) { return KNOT_EOK; diff --git a/src/libknot/quic/tls_common.h b/src/libknot/quic/tls_common.h index 60af7fb586..821018ec6e 100644 --- a/src/libknot/quic/tls_common.h +++ b/src/libknot/quic/tls_common.h @@ -14,6 +14,15 @@ along with this program. If not, see . */ +/*! + * \file + * + * \brief Credentials handling common to QUIC and TLS. + * + * \addtogroup quic + * @{ + */ + #pragma once #include @@ -24,7 +33,7 @@ struct gnutls_session_int; struct gnutls_x509_crt_int; -struct knot_quic_creds; +struct knot_creds; /*! * \brief Init server TLS certificate for DoQ. @@ -34,8 +43,7 @@ struct knot_quic_creds; * * \return Initialized creds. */ -struct knot_quic_creds *knot_quic_init_creds(const char *cert_file, - const char *key_file); +struct knot_creds *knot_creds_init(const char *cert_file, const char *key_file); /*! * \brief Init peer TLS certificate for DoQ. @@ -46,9 +54,9 @@ struct knot_quic_creds *knot_quic_init_creds(const char *cert_file, * * \return Initialized creds. */ -struct knot_quic_creds *knot_quic_init_creds_peer(const struct knot_quic_creds *local_creds, - const uint8_t *peer_pin, - uint8_t peer_pin_len); +struct knot_creds *knot_creds_init_peer(const struct knot_creds *local_creds, + const uint8_t *peer_pin, + uint8_t peer_pin_len); /*! * \brief Gets the certificate from credentials. @@ -58,12 +66,12 @@ struct knot_quic_creds *knot_quic_init_creds_peer(const struct knot_quic_creds * * * \return KNOT_E* */ -int knot_quic_creds_cert(struct knot_quic_creds *creds, struct gnutls_x509_crt_int **cert); +int knot_creds_cert(struct knot_creds *creds, struct gnutls_x509_crt_int **cert); /*! * \brief Deinit server TLS certificate for DoQ. */ -void knot_quic_free_creds(struct knot_quic_creds *creds); +void knot_creds_free(struct knot_creds *creds); /*! * \brief Initialize GnuTLS session with credentials, ALPN, etc. @@ -78,7 +86,7 @@ void knot_quic_free_creds(struct knot_quic_creds *creds); * \return KNOT_E* */ int knot_tls_session(struct gnutls_session_int **session, - struct knot_quic_creds *creds, + struct knot_creds *creds, const char *priority, const char *alpn, bool early_data, @@ -106,4 +114,6 @@ void knot_tls_pin(struct gnutls_session_int *session, uint8_t *pin, * \return KNOT_EOK or KNOT_EBADCERTKEY */ int knot_tls_pin_check(struct gnutls_session_int *session, - struct knot_quic_creds *creds); + struct knot_creds *creds); + +/*! @} */ diff --git a/src/utils/kxdpgun/main.c b/src/utils/kxdpgun/main.c index 3384dbb8fd..4ea1756d2b 100644 --- a/src/utils/kxdpgun/main.c +++ b/src/utils/kxdpgun/main.c @@ -485,7 +485,7 @@ void *xdp_gun_thread(void *_ctx) knot_tcp_table_t *tcp_table = NULL; #ifdef ENABLE_QUIC knot_quic_table_t *quic_table = NULL; - struct knot_quic_creds *quic_creds = NULL; + struct knot_creds *quic_creds = NULL; list_t quic_sessions; init_list(&quic_sessions); #endif // ENABLE_QUIC @@ -502,7 +502,7 @@ void *xdp_gun_thread(void *_ctx) } if (ctx->quic) { #ifdef ENABLE_QUIC - quic_creds = knot_quic_init_creds_peer(NULL, NULL, 0); + quic_creds = knot_creds_init_peer(NULL, NULL, 0); if (quic_creds == NULL) { ERR2("failed to initialize QUIC context"); return NULL; @@ -930,7 +930,7 @@ void *xdp_gun_thread(void *_ctx) WALK_LIST_DELSAFE(n, nxt, quic_sessions) { knot_quic_session_load(NULL, n); } - knot_quic_free_creds(quic_creds); + knot_creds_free(quic_creds); #endif // ENABLE_QUIC char recv_str[40] = "", lost_str[40] = "", err_str[40] = "";