Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mbedtls: trace with double-lines #13321

Closed
gvanem opened this issue Apr 9, 2024 · 3 comments
Closed

mbedtls: trace with double-lines #13321

gvanem opened this issue Apr 9, 2024 · 3 comments
Labels

Comments

@gvanem
Copy link
Contributor

gvanem commented Apr 9, 2024

I did this

I built libcurl for multiple SSL-backends (including MBedTLS) and with
-DMBEDTLS_DEBUG=1 -DMBEDTLS_DEBUG_C=1 -DCURLDEBUG=1 in my CFLAGS.
But the result of running:

  set CURL_SSL_BACKEND=mbedtls
  curl --trace-ascii mbedtls-trace.txt https://example.com

or:

  curl --trace-ascii - https://example.com > mbedtls-trace.txt

looks awful:

  ...
  == Info: Didn't find Session ID in cache for host HTTPS://example.com:443
  == Info: ALPN: curl offers h2,http/1.1
  == Info: => handshake

  == Info: => flush output

  == Info: <= flush output

  == Info: client state: MBEDTLS_SSL_HELLO_REQUEST
  ...

Since the function mbed_debug() already gets the line with \n termination.
And then infof() adds another \n to the output. Hence I stripped off the last \n and it looks better:

--- a/vtls/mbedtls.c 2024-04-08 15:10:01
+++ b/vtls/mbedtls.c 2024-04-09 06:42:19
@@ -164,13 +164,25 @@
                        int line_nb, const char *line)
 {
   struct Curl_easy *data = NULL;
+  const char *nl;
+  int   len;

   if(!context)
     return;

   data = (struct Curl_easy *)context;
+  nl = strrchr (line, '\n');
+  if (nl)
+     len = nl - line;
+  else
+     len = strlen(line);
+  infof(data, "%.*s", len, line);
-  infof(data, "%s", line);
   (void) level;
 }
 #endif

But as an added bonus, I'd like that a curl -vv https://example.com 2> mbedtls-trace.txt (verbose level 2), to
include the filename and line from MBedTls:

  if (data->set.verbose >= 2)
     infof(data, "%s(%u): %.*s", f_name, line_nb, len, line);
  else
     infof(data, "%.*s", len, line);

But that seems impossible now. How is this supposed to be handled?

I expected the following

No empty lines (like for other SSL-backends),

curl/libcurl version

curl 8.7.2-DEV (x86_64-pc-win32) from git master yesterday.

operating system

Win-10.

@bagder
Copy link
Member

bagder commented Apr 9, 2024

But that seems impossible now. How is this supposed to be handled?

curl has no "verbose levels" so it is not handled at all.

@bagder bagder added the TLS label Apr 9, 2024
@gvanem
Copy link
Contributor Author

gvanem commented Apr 9, 2024

I'll rephrase; How could this be handled?

Including the filename and line from MBedTls could IMHO be useful.

@bagder
Copy link
Member

bagder commented Apr 9, 2024

I'll rephrase; How could this be handled?

Usually we do it with a build condition. A special define that we set when we want to debug that particular section of the code and then we get more detailed debug-logging.

bagder added a commit that referenced this issue Apr 12, 2024
To avoid double newlines in the output.

Reported-by: Gisle Vanem
Fixes #13321
@bagder bagder closed this as completed in 68ce971 Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants