diff --git a/CMakeLists.txt b/CMakeLists.txt index 47f86ba..f86fbb6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ else () set (CMAKE_C_STANDARD 99) endif () -set(VERSION 0.2.0) +set(VERSION 0.2.1) option(DEBUG "compile with debug symbol" OFF) option(BUNDLE_CIVETWEB "bundle civetweb with uts-server" OFF) diff --git a/ChangeLog.rst b/ChangeLog.rst index b5afea4..4cb1789 100644 --- a/ChangeLog.rst +++ b/ChangeLog.rst @@ -1,6 +1,11 @@ Changelogs ========== +0.2.1 +----- + +* [fix ] fix compilation for newer GCC (>10.2) (global variable definition issue + 0.2.0 ----- diff --git a/README.rst b/README.rst index 8f45419..eee3b8a 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,11 @@ Micro `RFC 3161 Time-Stamp `_ server writt ---- +Demo +---- + +A demo is accessible here: https://uts-server.kakwalab.ovh/ + License ------- 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/inc/http_staticpage.h b/inc/http_staticpage.h new file mode 100644 index 0000000..43f8e39 --- /dev/null +++ b/inc/http_staticpage.h @@ -0,0 +1,118 @@ +const char *content_static_page = \ + "" \ + "" \ + "" \ + " " \ + " 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" \ + "
" \ + "
" \ + "" \ + ""; + +int static_page_size = 0; diff --git a/inc/utils.h b/inc/utils.h index a18e6bb..3b90e3f 100644 --- a/inc/utils.h +++ b/inc/utils.h @@ -18,7 +18,3 @@ int set_params(rfc3161_context *ct, char *conf_file, char *conf_wd); static char *rand_string(char *str, size_t size); void free_uts_context(rfc3161_context *ct); const char *null_undef(const char *in); - -// some global variable to handle signals -int g_uts_sig_up; -int g_uts_sig; diff --git a/src/lib/http.c b/src/lib/http.c index 60c2915..c1efd96 100644 --- a/src/lib/http.c +++ b/src/lib/http.c @@ -8,6 +8,10 @@ #include #include #include +#include "http_staticpage.h" + +extern int g_uts_sig_up; +extern int g_uts_sig; static char *rand_string(char *str, size_t size) { const char charset[] = "1234567890ABCDEF"; @@ -191,8 +195,16 @@ int rfc3161_handler(struct mg_connection *conn, void *context) { free(content); } else { // default reply if we don't have a time-stamp request - resp_code = 200; - mg_printf(conn, STATIC_PAGE); + if (static_page_size == 0) { + static_page_size = 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)static_page_size); + mg_write(conn, content_static_page, static_page_size); } // initialize a serial_id if not created by create_response if (serial_id == NULL) { @@ -276,6 +288,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; @@ -302,6 +322,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); diff --git a/src/lib/rfc3161.c b/src/lib/rfc3161.c index e8b6865..3cf0cb2 100644 --- a/src/lib/rfc3161.c +++ b/src/lib/rfc3161.c @@ -269,7 +269,7 @@ int create_response(rfc3161_context *ct, char *query, int query_len, BN_free(serial_bn); } else { serial_hex = calloc(SERIAL_ID_SIZE, sizeof(char)); - strncpy(serial_hex, " NO ID ", SERIAL_ID_SIZE + 2); + strncpy(serial_hex, " NO ID ", SERIAL_ID_SIZE + 4); } #endif #ifdef OPENSSL_API_1_0 diff --git a/src/lib/utils.c b/src/lib/utils.c index cb18d66..5543c5b 100644 --- a/src/lib/utils.c +++ b/src/lib/utils.c @@ -12,6 +12,10 @@ #include #include +// some global variable to handle signals +int g_uts_sig_up; +int g_uts_sig; + static void signal_handler_general(int sig_num) { g_uts_sig = sig_num; }