Skip to content
82 changes: 82 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
name: Static analysis

on: [push, pull_request, workflow_dispatch]

jobs:
cppcheck:
runs-on: ubuntu-latest
permissions: read-all

steps:
- uses: actions/checkout@v4

- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get -y install \
build-essential \
autoconf \
automake \
gnutls-dev \
libkeyutils-dev \
libnl-3-dev \
libnl-genl-3-dev \
libglib2.0-dev

- name: Install tools
run: |
sudo apt-get install -y bear cppcheck

- name: Configure
run: |
./autogen.sh
./configure --with-systemd

- name: Generate compile commands
run: |
bear -- make

- name: Run Cppcheck
run: |
echo "::group::Cppcheck Analysis"
cppcheck --enable=all -I. \
--suppress=missingIncludeSystem \
--suppress=unusedFunction \
src/
echo "::endgroup::"

lizard:
runs-on: ubuntu-latest
permissions: read-all

steps:
- uses: actions/checkout@v4

- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get -y install \
build-essential \
autoconf \
automake \
gnutls-dev \
libkeyutils-dev \
libnl-3-dev \
libnl-genl-3-dev \
libglib2.0-dev

- name: Install tools
run: |
pip3 install lizard bandit[toml]

- name: Configure
run: |
./autogen.sh
./configure --with-systemd

- name: Run Lizard Complexity Analysis
run: |
echo "::group::Complexity Analysis"
lizard --CCN 15 src/ || true
echo "::endgroup::"
6 changes: 4 additions & 2 deletions src/tlshd/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <sys/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -171,14 +171,16 @@ static void tlshd_x509_log_issuers(const gnutls_datum_t *req_ca_rdn, int nreqs)
{
char issuer_dn[256];
size_t len;
int i, ret;
int i;

if (nreqs < 1)
return;

tlshd_log_debug("Server's trusted authorities:");

for (i = 0; i < nreqs; i++) {
int ret;

len = sizeof(issuer_dn);
ret = gnutls_x509_rdn_get(&req_ca_rdn[i], issuer_dn, &len);
if (ret >= 0)
Expand Down
2 changes: 1 addition & 1 deletion src/tlshd/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <sys/types.h>
#include <sys/socket.h>
Expand Down
4 changes: 2 additions & 2 deletions src/tlshd/handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <sys/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -64,7 +64,7 @@ static void tlshd_save_nagle(gnutls_session_t session, int *saved)
IPPROTO_TCP, TCP_NODELAY, saved, &len);
if (ret < 0) {
tlshd_log_perror("getsockopt (NODELAY)");
saved = 0;
*saved = 0;
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tlshd/keyring.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <sys/types.h>
#include <sys/socket.h>
Expand Down
4 changes: 2 additions & 2 deletions src/tlshd/ktls.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <sys/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -540,7 +540,7 @@ int tlshd_gnutls_priority_init(void)
* Returns GNUTLS_E_SUCCESS on success, otherwise an error code.
*/
int tlshd_gnutls_priority_set(gnutls_session_t session,
struct tlshd_handshake_parms *parms,
const struct tlshd_handshake_parms *parms,
unsigned int psk_len)
{
gnutls_priority_t priority = tlshd_gnutls_priority_x509;
Expand Down
2 changes: 1 addition & 1 deletion src/tlshd/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <stdbool.h>
#include <unistd.h>
Expand Down
4 changes: 2 additions & 2 deletions src/tlshd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <sys/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -56,7 +56,7 @@ static const struct option longopts[] = {
{ NULL, 0, NULL, 0 }
};

static void usage(char *progname)
static void usage(const char *progname)
{
fprintf(stderr, "usage: %s [-chsv]\n", progname);
}
Expand Down
11 changes: 6 additions & 5 deletions src/tlshd/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <sys/types.h>
#include <sys/stat.h>
Expand Down Expand Up @@ -283,8 +283,8 @@ static int tlshd_genl_valid_handler(struct nl_msg *msg, void *arg)
struct tlshd_handshake_parms *parms = arg;
struct sockaddr_storage addr;
struct sockaddr *sap = NULL;
const char *peername = NULL;
socklen_t salen, optlen;
char *peername = NULL;
int err;

tlshd_log_debug("Parsing a valid netlink message\n");
Expand Down Expand Up @@ -390,8 +390,8 @@ static const struct tlshd_handshake_parms tlshd_default_handshake_parms = {
*/
int tlshd_genl_get_handshake_parms(struct tlshd_handshake_parms *parms)
{
const struct nlmsghdr *hdr;
int family_id, err, ret;
struct nlmsghdr *hdr;
struct nl_sock *nls;
struct nl_msg *msg;

Expand Down Expand Up @@ -480,9 +480,10 @@ static int tlshd_genl_put_remote_peerids(struct nl_msg *msg,
{
key_serial_t peerid;
guint i;
int err;

for (i = 0; i < parms->remote_peerids->len; i++) {
int err;

peerid = g_array_index(parms->remote_peerids, key_serial_t, i);
err = nla_put_s32(msg, HANDSHAKE_A_DONE_REMOTE_AUTH, peerid);
if (err < 0) {
Expand All @@ -500,7 +501,7 @@ static int tlshd_genl_put_remote_peerids(struct nl_msg *msg,
*/
void tlshd_genl_done(struct tlshd_handshake_parms *parms)
{
struct nlmsghdr *hdr;
const struct nlmsghdr *hdr;
struct nl_sock *nls;
struct nl_msg *msg;
int family_id, err;
Expand Down
14 changes: 9 additions & 5 deletions src/tlshd/quic.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* 02110-1301, USA.
*/

#include <config.h>

#include <gnutls/abstract.h>
#include <sys/socket.h>
#include <linux/tls.h>
Expand All @@ -26,7 +28,6 @@
#include <unistd.h>
#include <glib.h>

#include "config.h"
#include "tlshd.h"

#ifdef HAVE_GNUTLS_QUIC
Expand Down Expand Up @@ -106,7 +107,7 @@ static int quic_secret_func(gnutls_session_t session, gnutls_record_encryption_l
struct tlshd_quic_conn *conn = gnutls_session_get_ptr(session);
gnutls_cipher_algorithm_t type = gnutls_cipher_get(session);
struct quic_crypto_secret secret = {};
int sockfd, ret, len = sizeof(secret);
int sockfd, len = sizeof(secret);

if (conn->completed)
return 0;
Expand Down Expand Up @@ -134,6 +135,8 @@ static int quic_secret_func(gnutls_session_t session, gnutls_record_encryption_l
}
if (secret.level == QUIC_CRYPTO_APP) {
if (conn->is_serv) {
int ret;

ret = gnutls_session_ticket_send(session, 1, 0);
if (ret) {
tlshd_log_gnutls_error(ret);
Expand Down Expand Up @@ -383,13 +386,14 @@ static int quic_handshake_recvmsg(int sockfd, struct tlshd_quic_msg *msg)
return ret;
}

static int quic_handshake_completed(struct tlshd_quic_conn *conn)
static int quic_handshake_completed(const struct tlshd_quic_conn *conn)
{
return conn->completed || conn->errcode;
}

static int quic_handshake_crypto_data(struct tlshd_quic_conn *conn, uint8_t level,
const uint8_t *data, size_t datalen)
static int quic_handshake_crypto_data(const struct tlshd_quic_conn *conn,
uint8_t level, const uint8_t *data,
size_t datalen)
{
gnutls_session_t session = conn->session;
int ret;
Expand Down
8 changes: 5 additions & 3 deletions src/tlshd/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* 02110-1301, USA.
*/

#include "config.h"
#include <config.h>

#include <sys/types.h>
#include <sys/socket.h>
Expand Down Expand Up @@ -80,15 +80,17 @@ static void tlshd_x509_server_put_privkey(void)
static void tlshd_x509_log_issuers(const gnutls_datum_t *req_ca_rdn, int nreqs)
{
char issuer_dn[256];
size_t len;
int i, ret;
int i;

if (nreqs < 1)
return;

tlshd_log_debug("Server's trusted authorities:");

for (i = 0; i < nreqs; i++) {
size_t len;
int ret;

len = sizeof(issuer_dn);
ret = gnutls_x509_rdn_get(&req_ca_rdn[i], issuer_dn, &len);
if (ret >= 0)
Expand Down
2 changes: 1 addition & 1 deletion src/tlshd/tlshd.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern int tlshd_keyring_link_session(const char *keyring);
extern unsigned int tlshd_initialize_ktls(gnutls_session_t session);
extern int tlshd_gnutls_priority_init(void);
extern int tlshd_gnutls_priority_set(gnutls_session_t session,
struct tlshd_handshake_parms *parms,
const struct tlshd_handshake_parms *parms,
unsigned int psk_len);
extern void tlshd_gnutls_priority_deinit(void);

Expand Down