From 84afefe39bbc65f4c8a9a89f6ebdc94b8ae88f24 Mon Sep 17 00:00:00 2001 From: Joao Alves Date: Wed, 22 Sep 2021 08:52:57 +0100 Subject: [PATCH] Correction to static page length. Correction to static page HTML. Return 404 for favicon.ico. --- inc/http.h | 122 ------------------------------------------------- src/lib/http.c | 22 ++++++++- 2 files changed, 21 insertions(+), 123 deletions(-) diff --git a/inc/http.h b/inc/http.h index ed2c7bd..e89e902 100644 --- a/inc/http.h +++ b/inc/http.h @@ -6,125 +6,3 @@ struct tuser_data { }; int http_server_start(char *conffile, char *conf_wd, bool stdout_dbg); - -#define STATIC_PAGE \ - "HTTP/1.1 200 OK\r\n" \ - "Content-Type: text/html\r\n" \ - "Content-Length: 2774\r\n" \ - "\r\n" \ - "" \ - "" \ - " " \ - " uts-server" \ - " " \ - " " \ - "" \ - "" \ - "" \ - "
" \ - " uts-server, a simple RFC 3161 timestamp server" \ - "
" \ - "
" \ - " For timestamping a file with OpenSSL and curl, run the following " \ - "commands" \ - " (setting the $UTS_SERVER_URL, $FILE and $FILE_TIMESTAMP variables):" \ - "
" \ - " openssl ts -query -data \"$FILE\" -out " \ - "\"ts_req.ts\";
" \ - " curl \"$UTS_SERVER_URL\" \\
" \ - "      -H \"Content-Type: " \ - "application/timestamp-query\" \\
" \ - "      -f -g --data-binary \"@ts_req.ts\" -o " \ - "\"$FILE_TIMESTAMP\"" \ - "
" \ - " For verifying the timestamp with OpenSSL, download the CA and the " \ - "signer cert, and run the following command:" \ - "
" \ - " openssl ts -verify -in \"$FILE_TIMESTAMP\" \\
" \ - "      -data \"$FILE\" " \ - "-CAfile ca.pem -untrusted tsa_cert.pem" \ - "
" \ - " " \ - "
" \ - "
" \ - "
" \ - " uts-server" \ - " • © 2019 • Pierre-François Carpentier • Released under the MIT " \ - "License" \ - "
" \ - "
" \ - "" \ - "" diff --git a/src/lib/http.c b/src/lib/http.c index ea402e9..ca810e8 100644 --- a/src/lib/http.c +++ b/src/lib/http.c @@ -8,6 +8,7 @@ #include #include #include +#include "http_staticpage.h" extern int g_uts_sig_up; extern int g_uts_sig; @@ -195,7 +196,17 @@ int rfc3161_handler(struct mg_connection *conn, void *context) { } else { // default reply if we don't have a time-stamp request resp_code = 200; - mg_printf(conn, STATIC_PAGE); + //char *content_static = calloc(4096, sizeof(char)); + //strncpy(content_static, STATIC_PAGE, 4096); + content_length = strlen(content_static_page); + mg_printf(conn, + "HTTP/1.1 200 OK\r\n" + "Content-Type: text/html\r\n" + "Content-Length: %d\r\n" + "\r\n", + (int)content_length); + mg_write(conn, content_static_page, content_length); + //free(content_static); } // initialize a serial_id if not created by create_response if (serial_id == NULL) { @@ -279,6 +290,14 @@ int cert_serve_handler(struct mg_connection *conn, void *context) { return 1; } +int notfound_handler(struct mg_connection *conn, void *context) { + /* In this handler, we ignore the req_info and send the file "filename". */ + const struct mg_request_info *request_info = mg_get_request_info(conn); + rfc3161_context *ct = (rfc3161_context *)context; + mg_send_http_error(conn, 404, ""); + return 1; +} + int http_server_start(char *conffile, char *conf_wd, bool stdout_dbg) { struct mg_context *ctx; struct mg_callbacks callbacks; @@ -305,6 +324,7 @@ int http_server_start(char *conffile, char *conf_wd, bool stdout_dbg) { ctx = mg_start(&callbacks, &user_data, ct->http_options); if (ctx != NULL) { mg_set_request_handler(ctx, "/", rfc3161_handler, (void *)ct); + mg_set_request_handler(ctx, "/favicon.ico", notfound_handler, (void *)ct); mg_set_request_handler(ctx, "/ca.pem", ca_serve_handler, (void *)ct); mg_set_request_handler(ctx, "/tsa_cert.pem", cert_serve_handler, (void *)ct);