From 9c2a265397821d91ec628f549516b25757f5c801 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 22 Dec 2011 23:24:54 +0100 Subject: [PATCH] Use sideband also for "proceed" handshake. This adds sideband-aware code for the next step of the connection handshake. If sideband connections are supported at both ends, the server side sends an empty sideband packet with designator SBD_PROCEED if the client was authenticated successfully. When the client receives this packet, it enters the CL_RECEIVED_PROCEED state, just as with non-sideband connections. --- client_common.c | 12 ++++++++++++ command.c | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/client_common.c b/client_common.c index eea14fa8..53f7b5a9 100644 --- a/client_common.c +++ b/client_common.c @@ -355,6 +355,18 @@ static void client_post_select(struct sched *s, struct task *t) goto out; case CL_SENT_CH_RESPONSE: /* read server response */ { + if (ct->use_sideband) { + struct sb_buffer sbb; + ret = recv_sb(ct, &s->rfds, &sbb); + if (ret <= 0) + goto out; + free(sbb.iov.iov_base); + if (sbb.band != SBD_PROCEED) + ret = -E_BAD_BAND; + else + ct->status = CL_RECEIVED_PROCEED; + goto out; + } ret = client_recv_buffer(ct, &s->rfds, buf, sizeof(buf), &n); if (ret < 0 || n == 0) goto out; diff --git a/command.c b/command.c index 5e13df66..8deb69ce 100644 --- a/command.c +++ b/command.c @@ -975,7 +975,10 @@ __noreturn void handle_connect(int fd, const char *peername) /* init stream cipher keys with the second part of the random buffer */ cc->scc.recv = sc_new(rand_buf + CHALLENGE_SIZE, SESSION_KEY_LEN); cc->scc.send = sc_new(rand_buf + CHALLENGE_SIZE + SESSION_KEY_LEN, SESSION_KEY_LEN); - ret = sc_send_buffer(&cc->scc, PROCEED_MSG); + if (cc->use_sideband) + ret = send_sb(&cc->scc, NULL, 0, SBD_PROCEED, false); + else + ret = sc_send_buffer(&cc->scc, PROCEED_MSG); if (ret < 0) goto net_err; ret = read_command(&cc->scc, &command); -- 2.39.2