diff --git a/src/tlcp.c b/src/tlcp.c index cbe94630..1e580831 100644 --- a/src/tlcp.c +++ b/src/tlcp.c @@ -595,7 +595,7 @@ int tlcp_do_connect(TLS_CONNECT *conn) tls_send_alert(conn, TLS_alert_decrypt_error); goto end; } - tls_trace("Connection established!\n"); + printf("Connection established!\n"); conn->protocol = TLS_protocol_tlcp; diff --git a/src/tls.c b/src/tls.c index 176d479d..4616f8ae 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1721,8 +1721,6 @@ int tls_send(TLS_CONNECT *conn, const uint8_t *in, size_t inlen, size_t *sentlen tls_trace("send ApplicationData\n"); - format_bytes(stderr, 0, 0, "tls_send: payload", in, inlen); - if (tls_record_set_type(record, TLS_record_application_data) != 1 || tls_record_set_protocol(record, conn->protocol) != 1 || tls_record_set_length(record, inlen) != 1) { diff --git a/tools/tlcp_client.c b/tools/tlcp_client.c index 62b739bd..d04e7477 100644 --- a/tools/tlcp_client.c +++ b/tools/tlcp_client.c @@ -85,7 +85,7 @@ int tlcp_client_main(int argc, char *argv[]) int sock; TLS_CTX ctx; TLS_CONNECT conn; - char buf[100] = {0}; + char buf[1000] = {0}; size_t len = sizeof(buf); char send_buf[1024] = {0}; size_t send_len; @@ -180,31 +180,49 @@ bad: goto end; } + fd_set fds; + + for (;;) { size_t sentlen; - memset(send_buf, 0, sizeof(send_buf)); - if (!fgets(send_buf, sizeof(send_buf), stdin)) { - if (feof(stdin)) { - tls_shutdown(&conn); - goto end; - } else { - continue; - } - } - if (tls_send(&conn, (uint8_t *)send_buf, strlen(send_buf), &sentlen) != 1) { - fprintf(stderr, "%s: send error\n", prog); + + FD_ZERO(&fds); + FD_SET(conn.sock, &fds); + FD_SET(0, &fds); + + if (select(conn.sock + 1, &fds, NULL, NULL, NULL) < 0) { + fprintf(stderr, "%s: select failed\n", prog); goto end; } - { + if (FD_ISSET(conn.sock, &fds)) { memset(buf, 0, sizeof(buf)); len = sizeof(buf); - if (tls_recv(&conn, (uint8_t *)buf, sizeof(len), &len) != 1) { + + if (tls_recv(&conn, (uint8_t *)buf, sizeof(buf), &len) != 1) { goto end; } + buf[len] = 0; printf("%s\n", buf); + + } + if (FD_ISSET(0, &fds)) { + memset(send_buf, 0, sizeof(send_buf)); + + if (!fgets(send_buf, sizeof(send_buf), stdin)) { + if (feof(stdin)) { + tls_shutdown(&conn); + goto end; + } else { + continue; + } + } + if (tls_send(&conn, (uint8_t *)send_buf, strlen(send_buf), &sentlen) != 1) { + fprintf(stderr, "%s: send error\n", prog); + goto end; + } } }