diff options
Diffstat (limited to 'lib/libostp/auth.c')
| -rw-r--r-- | lib/libostp/auth.c | 42 | 
1 files changed, 8 insertions, 34 deletions
| diff --git a/lib/libostp/auth.c b/lib/libostp/auth.c index 559e3b3..b807485 100644 --- a/lib/libostp/auth.c +++ b/lib/libostp/auth.c @@ -125,36 +125,6 @@ send_motd(struct ostp_client *c, const unsigned char *session_key)      }  } -static int -session_run(struct ostp_listener *lp, const unsigned char *session_key) -{ -    struct ostp_client *c; -    char buf[4096]; -    size_t len; - -    while (1) { -        for (int i = 1; i < MAX_CLIENTS; ++i) { -            c = &lp->clients[i]; -            if (c->sockfd <= 0) -                continue; -            if (FD_ISSET(c->sockfd, &lp->client_fds) <= 0) -                continue; - -            len = recv_frame(c->sockfd, sizeof(buf) - 1, session_key, buf); -            if (len < 0) { -                printf("recv_frame() failure, packet lost\n"); -                continue; -            } -            if (len == 0) { -                return 0; -            } -            if (lp->on_recv != NULL) { -                lp->on_recv(c, buf, len); -            } -        } -    } -} -  static void *  session_td(void *args)  { @@ -174,7 +144,7 @@ session_td(void *args)      }      send_motd(tmp->c, tmp->session_key); -    session_run(tmp->lp, tmp->session_key); +    tmp->c->authed = 1;      free(args);      return NULL;  } @@ -184,7 +154,7 @@ handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_reque  {      struct x25519_keypair keypair;      struct session_td_args *sargs; -    unsigned char *session_key; +    struct ostp_session *session;      int error;      if (REQUIRE_USER_AUTH && !ISSET(srq->options, SESSION_REQ_USER)) { @@ -207,8 +177,12 @@ handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_reque          return error;      } +    /* Setup client session descriptor */ +    session = &c->session; +    session->sockfd = c->sockfd; +      printf("Deriving session key...\n"); -    error = gen_session_key(keypair.privkey, srq->pubkey, &session_key); +    error = gen_session_key(keypair.privkey, srq->pubkey, &session->session_key);      if (error < 0) {          return error;      } @@ -221,7 +195,7 @@ handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_reque      sargs->c = c;      sargs->lp = lp; -    sargs->session_key = session_key; +    sargs->session_key = session->session_key;      error = pthread_create(&c->td, NULL, session_td, sargs);      if (error != 0) {          return error; | 
