Add a LF to the keylog line and return the number of bytes written or 0 if * writing fails. * see: https://www.ietf.org/archive/id/draft-thomson-tls-keylogfile-00.html https://github.com/tlswg/sslkeylogfile */
| 118 | https://github.com/tlswg/sslkeylogfile |
| 119 | */ |
| 120 | static int write_keylog_line(const char* filename, const char *line) |
| 121 | { |
| 122 | FILE *keylog_fp = nullptr; |
| 123 | char buf[256]; /* current keylog maximum line length is 195 */ |
| 124 | size_t line_len = strlen(line); |
| 125 | |
| 126 | if(line_len == 0 || line_len > sizeof(buf) - 2) { |
| 127 | /* Empty line or too big to fit in a LF and NULL. */ |
| 128 | return 0; |
| 129 | } |
| 130 | keylog_fp = fopen(filename, "a"); |
| 131 | if (keylog_fp) { |
| 132 | memcpy(buf, line, line_len); |
| 133 | if(line[line_len - 1] != '\n') { |
| 134 | buf[line_len++] = '\n'; |
| 135 | } |
| 136 | buf[line_len] = '\0'; |
| 137 | fputs(buf, keylog_fp); |
| 138 | fclose(keylog_fp); |
| 139 | } |
| 140 | return line_len-1; |
| 141 | } |
| 142 | |
| 143 | static void sip_tls_keylog_callback(const SSL *ssl, const char *line) |
| 144 | { |
no outgoing calls
no test coverage detected