diff options
author | Uros Majstorovic <majstor@majstor.org> | 2018-01-22 15:25:28 +0100 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2018-01-22 15:25:28 +0100 |
commit | aee07a08bfdfd32a777a8cdd1f5f84fe56783461 (patch) | |
tree | 53b1a4dbb32b14937351904887f47ad34bbc326a | |
parent | 87c71978e556d532a5b91a653514a92acec9a1b7 (diff) |
randomized seq_out
-rw-r--r-- | code/ecp/core.c | 11 | ||||
-rw-r--r-- | code/test/vc_client_t.c | 2 |
2 files changed, 11 insertions, 2 deletions
diff --git a/code/ecp/core.c b/code/ecp/core.c index f8d3ec7..0ecb51e 100644 --- a/code/ecp/core.c +++ b/code/ecp/core.c @@ -557,6 +557,7 @@ int ecp_conn_init(ECPConnection *conn, ECPNode *node) { conn->node = *node; rv = ecp_dhkey_generate(ctx, &key); if (!rv) rv = ctx->rng(conn->nonce, ECP_AEAD_SIZE_NONCE); + if (!rv) rv = ctx->rng(&conn->seq_out, sizeof(conn->seq_out)); if (!rv) rv = conn_dhkey_new_pair(conn, &key); if (!rv) rv = conn_dhkey_new_pub_local(conn, conn->key_curr); @@ -648,6 +649,7 @@ int ecp_conn_reset(ECPConnection *conn) { if (!rv) rv = conn_dhkey_new_pub_local(conn, conn->key_curr); if (!rv) rv = ctx->rng(conn->nonce, ECP_AEAD_SIZE_NONCE); + if (!rv) rv = ctx->rng(&conn->seq_out, sizeof(conn->seq_out)); conn->flags &= ~ECP_CONN_FLAG_OPEN; #ifdef ECP_WITH_PTHREAD @@ -708,6 +710,7 @@ int ecp_conn_handle_new(ECPSocket *sock, ECPConnection *parent, unsigned char *p if (conn == NULL) return ECP_ERR_ALLOC; rv = ecp_conn_create(conn, sock, ctype); + if (!rv) rv = sock->ctx->rng(&conn->seq_out, sizeof(conn->seq_out)); if (rv) { if (sock->ctx->conn_free) sock->ctx->conn_free(conn); return rv; @@ -1146,6 +1149,7 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent, ECP unsigned char is_open = 0; unsigned char is_new = 0; unsigned char seq_check = 1; + unsigned char seq_reset = 0; ecp_seq_t seq_c, seq_p, seq_n; ecp_ack_t seq_map; ssize_t dec_size; @@ -1282,10 +1286,15 @@ ssize_t ecp_unpack(ECPSocket *sock, ECPNetAddr *addr, ECPConnection *parent, ECP } } + if ((rv == ECP_ERR_SEQ) && (payload[ECP_SIZE_PLD_HDR] == ECP_MTYPE_OPEN_REQ) && key) { + rv = ECP_OK; + seq_reset = 1; + } if (rv) goto ecp_unpack_err; } + } - } else { + if (!is_open || seq_reset) { seq_n = seq_p; seq_map = 1; diff --git a/code/test/vc_client_t.c b/code/test/vc_client_t.c index 54c657d..3a2402e 100644 --- a/code/test/vc_client_t.c +++ b/code/test/vc_client_t.c @@ -54,7 +54,7 @@ ssize_t handle_msg(ECPConnection *conn, ecp_seq_t sq, unsigned char t, unsigned unsigned char buf[1000]; strcpy((char *)buf, msg); - ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, strlen(msg)+1); + ssize_t _rv = ecp_send(conn, MTYPE_MSG, buf, 1000); if (counter % 100 == 0) { struct timeval tv; |