aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-02-21 18:34:39 -0500
committerIan Moffett <ian@osmora.org>2025-02-21 18:34:39 -0500
commit5dab783345c40400811602dfe2a427ec1110af98 (patch)
tree901b0347b2a9cd9f6502064a92c88aae6be87980
parentb734dcbbdf93a68d1275c50cd4f01d85d7c83661 (diff)
auth: Only generate new master session key once
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--lib/libostp/auth.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/libostp/auth.c b/lib/libostp/auth.c
index 80f3d63..c1489d4 100644
--- a/lib/libostp/auth.c
+++ b/lib/libostp/auth.c
@@ -36,6 +36,7 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <errno.h>
#include <string.h>
@@ -46,6 +47,13 @@ struct session_td_args {
};
/*
+ * keypair: Master session keypair.
+ * g_have_link: True when one or more link(s) are established.
+ */
+static struct x25519_keypair keypair;
+bool g_have_link = false;
+
+/*
* Check a password to see if it matches with
* the hash in /etc/shadow by using the pwcheck
* script. Returns 0 on success.
@@ -147,12 +155,14 @@ session_td(void *args)
tmp->c->authed = 1;
free(args);
return NULL;
+#endif
+
+ return NULL;
}
int
handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_request *srq)
{
- struct x25519_keypair keypair;
struct session_td_args *sargs;
struct ostp_session *session;
int error;
@@ -163,11 +173,12 @@ handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_reque
return -1;
}
- printf("Generating keys...\n");
-
- if (gen_x25519_keypair(&keypair) < 0) {
- printf("Key generation failed!\n");
- return -1;
+ /* Generate a new keypair if we have no link */
+ if (!g_have_link) {
+ if (gen_x25519_keypair(&keypair) < 0) {
+ printf("Key generation failed!\n");
+ return -1;
+ }
}
/* Send back our our public key */
@@ -201,5 +212,6 @@ handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_reque
return error;
}
+ g_have_link = true;
return 0;
}