]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
doh debug: log timestamp of OPENSSLKEYLOGFILE creation
authorPetr Špaček <petr.spacek@nic.cz>
Tue, 22 Oct 2019 11:26:04 +0000 (13:26 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Wed, 20 Nov 2019 12:17:38 +0000 (13:17 +0100)
modules/http/debug_opensslkeylog.c

index 9677c9512c226852f8815371c5893526ee2e146b..5e97e2f7af3a1537ab1f8008ea059810c63707d6 100644 (file)
@@ -47,9 +47,6 @@
 #   define OPENSSL_SONAME   "libssl.so"
 #endif
 
-#define FIRSTLINE   "# SSL key logfile generated by sslkeylog.c\n"
-#define FIRSTLINE_LEN (sizeof(FIRSTLINE) - 1)
-
 /* When building for OpenSSL 1.1.0 or newer, no headers are required. */
 #ifdef NO_OPENSSL_102_SUPPORT
 typedef struct ssl_st SSL;
@@ -112,10 +109,14 @@ static void init_keylog_file(void)
 
     const char *filename = getenv("OPENSSLKEYLOGFILE");
     if (filename) {
-        keylog_file_fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0644);
+       /* ctime output is max 26 bytes, POSIX 1003.1-2017 */
+       keylog_file_fd = open(filename, O_WRONLY | O_APPEND | O_CREAT, 0644);
         if (keylog_file_fd >= 0 && lseek(keylog_file_fd, 0, SEEK_END) == 0) {
+            time_t timenow = time(NULL);
+            char txtnow[30] = { '#', ' ', 0 };
+           ctime_r(&timenow, txtnow + 2);
             /* file is opened successfully and there is no data (pos == 0) */
-            write(keylog_file_fd, FIRSTLINE, FIRSTLINE_LEN);
+            write(keylog_file_fd, txtnow, strlen(txtnow));
         }
     }
 }