Skip to content

Commit 1e03c0e

Browse files
committed
tlshd: Store remote peerids in a GArray
The number of remote peer IDs passed back from the TLS library is not known in advance. Use a flexible array to handle one-at-a-time storage of the peerids as they are retrieved. Signed-off-by: Chuck Lever <[email protected]>
1 parent b967c32 commit 1e03c0e

File tree

4 files changed

+14
-17
lines changed

4 files changed

+14
-17
lines changed

src/tlshd/client.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,9 @@ static void tlshd_tls13_client_psk_handshake_one(struct tlshd_handshake_parms *p
404404

405405
tlshd_log_debug("start ClientHello handshake");
406406
tlshd_start_tls_handshake(session, parms);
407-
if (!parms->session_status) {
407+
if (!parms->session_status)
408408
/* PSK uses the same identity for both client and server */
409-
parms->num_remote_peerids = 1;
410-
parms->remote_peerid[0] = peerid;
411-
}
409+
g_array_append_val(parms->remote_peerids, peerid);
412410

413411
gnutls_deinit(session);
414412

src/tlshd/netlink.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,9 @@ static const struct tlshd_handshake_parms tlshd_default_handshake_parms = {
321321
.x509_privkey = TLS_NO_PRIVKEY,
322322
.peerids = NULL,
323323
.num_peerids = 0,
324+
.remote_peerids = NULL,
324325
.msg_status = 0,
325326
.session_status = EIO,
326-
327-
.num_remote_peerids = 0,
328327
};
329328

330329
/**
@@ -347,6 +346,8 @@ int tlshd_genl_get_handshake_parms(struct tlshd_handshake_parms *parms)
347346

348347
*parms = tlshd_default_handshake_parms;
349348

349+
parms->remote_peerids = g_array_new(FALSE, FALSE, sizeof(key_serial_t));
350+
350351
ret = tlshd_genl_sock_open(&nls);
351352
if (ret)
352353
return ret;
@@ -415,17 +416,19 @@ void tlshd_genl_put_handshake_parms(struct tlshd_handshake_parms *parms)
415416
if (parms->keyring)
416417
keyctl_unlink(parms->keyring, KEY_SPEC_SESSION_KEYRING);
417418
free(parms->peerids);
419+
g_array_free(parms->remote_peerids, TRUE);
418420
}
419421

420422
static int tlshd_genl_put_remote_peerids(struct nl_msg *msg,
421423
struct tlshd_handshake_parms *parms)
422424
{
423-
unsigned int i;
425+
key_serial_t peerid;
426+
guint i;
424427
int err;
425428

426-
for (i = 0; i < parms->num_remote_peerids; i++) {
427-
err = nla_put_s32(msg, HANDSHAKE_A_DONE_REMOTE_AUTH,
428-
parms->remote_peerid[i]);
429+
for (i = 0; i < parms->remote_peerids->len; i++) {
430+
peerid = g_array_index(parms->remote_peerids, key_serial_t, i);
431+
err = nla_put_s32(msg, HANDSHAKE_A_DONE_REMOTE_AUTH, peerid);
429432
if (err < 0) {
430433
tlshd_log_nl_error("nla_put peer id", err);
431434
return -1;

src/tlshd/server.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ static int tlshd_server_psk_cb(gnutls_session_t session,
331331
}
332332

333333
/* PSK uses the same identity for both client and server */
334-
parms->remote_peerid[0] = psk;
335-
parms->num_remote_peerids = 1;
334+
g_array_append_val(parms->remote_peerids, psk);
336335
return 0;
337336
}
338337

@@ -468,8 +467,7 @@ static int tlshd_quic_server_psk_cb(gnutls_session_t session, const char *userna
468467
}
469468

470469
/* PSK uses the same identity for both client and server */
471-
parms->remote_peerid[0] = psk;
472-
parms->num_remote_peerids = 1;
470+
g_array_append_val(parms->remote_peerids, psk);
473471
return 0;
474472
}
475473

src/tlshd/tlshd.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@ struct tlshd_handshake_parms {
4141
key_serial_t x509_privkey;
4242
key_serial_t *peerids;
4343
unsigned int num_peerids;
44+
GArray *remote_peerids;
4445
int msg_status;
4546

4647
unsigned int session_status;
47-
48-
unsigned int num_remote_peerids;
49-
key_serial_t remote_peerid[10];
5048
};
5149

5250
/* client.c */

0 commit comments

Comments
 (0)