Commit 86e6cc35 authored by Ian Goldberg's avatar Ian Goldberg

Record the time the last COMMIT was sent from a master context

This will be used to clear the committed key from the master context
once we don't expect any more instances of our buddy to respond with a
DHKEY message.
parent 7c669243
......@@ -59,6 +59,8 @@ void otrl_auth_dump(FILE *f, const OtrlAuthInfo *auth)
fprintf(f, "\n Proto version = %d\n", auth->protocol_version);
fprintf(f, "\n Lastauthmsg = %s\n",
auth->lastauthmsg ? auth->lastauthmsg : "(nil)");
fprintf(f, "\n Commit sent time = %ld\n",
(long) auth->commit_sent_time);
}
#endif
......@@ -90,6 +92,7 @@ void otrl_auth_new(struct context *context)
memset(auth->secure_session_id, 0, 20);
auth->secure_session_id_len = 0;
auth->lastauthmsg = NULL;
auth->commit_sent_time = 0;
auth->context = context;
}
......@@ -128,6 +131,7 @@ void otrl_auth_clear(OtrlAuthInfo *auth)
auth->secure_session_id_len = 0;
free(auth->lastauthmsg);
auth->lastauthmsg = NULL;
auth->commit_sent_time = 0;
}
/*
......
......@@ -22,6 +22,7 @@
#define __AUTH_H__
#include <gcrypt.h>
#include <time.h>
#include "dh.h"
......@@ -75,6 +76,12 @@ typedef struct {
(base-64 encoded) we sent,
in case we need to
retransmit it. */
time_t commit_sent_time; /* The time we last sent the
lastauthmsg, if it was a
COMMIT message, and this is
a master context. 0
otherwise. */
} OtrlAuthInfo;
#include "privkey-t.h"
......
......@@ -451,14 +451,23 @@ static gcry_error_t send_or_error_auth(const OtrlMessageAppOps *ops,
if (msg && *msg) {
fragment_and_send(ops, opdata, context, msg,
OTRL_FRAGMENT_SEND_ALL, NULL);
time_t now = time(NULL);
/* Update the "last sent" fields, unless this is a version 3
* message typing to update the master context (as happens
* when sending a v3 COMMIT message, for example). */
if (context != context->m_context ||
context->auth.protocol_version != 3) {
context->context_priv->lastsent = time(NULL);
context->context_priv->lastsent = now;
otrl_context_update_recent_child(context, 1);
}
/* If this is a master context, and we're sending a COMMIT
* message, update the commit_sent_time timestamp, so we can
* expire it. */
if (context == context->m_context &&
context->auth.authstate == OTRL_AUTHSTATE_AWAITING_DHKEY) {
context->auth.commit_sent_time = now;
}
}
} else {
if (ops->handle_msg_event) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment