esp-idf: HTTP Digest Auth fails to connect (IDFGH-4009)

Hi, I’m trying to connect to a lighttpd server in order to make a GET request with this chunk of code:

        esp_http_client_config_t config = {
            .url = "https://192.168.1.50/00AA11442233.json",
            .cert_pem = root_cert_pem_start,
            .auth_type = HTTP_AUTH_TYPE_DIGEST,
            .username = "espUpdateUser",
            .password = "123456",
            .skip_cert_common_name_check = 1,
            .transport_type = HTTP_TRANSPORT_OVER_SSL,
            .method = HTTP_METHOD_GET,
        };
        esp_http_client_handle_t client = esp_http_client_init(&config);
        esp_err_t err = esp_http_client_perform(client);

and I’m getting this GuruMeditation:

D (23:47:57.567) HTTP_AUTH: Digest espUpdateUser Authorized users only 123456

Guru Meditation Error: Core  0 panic'ed (LoadProhibited). Exception was unhandled.

Core  0 register dump:
PC      : 0x400014fd  PS      : 0x00060730  A0      : 0x80146018  A1      : 0x3ffd20a0  
A2      : 0x00000000  A3      : 0xfffffffc  A4      : 0x000000ff  A5      : 0x0000ff00  
A6      : 0x00ff0000  A7      : 0xff000000  A8      : 0x00000000  A9      : 0x3ffda758  
A10     : 0x3ffda738  A11     : 0x3ffdb538  A12     : 0x00000020  A13     : 0x00000001  
A14     : 0x3ffda720  A15     : 0x3ffda650  SAR     : 0x00000008  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xffffffff  

Backtrace:0x400014fa:0x3ffd20a0 0x40146015:0x3ffd20b0 0x4014339d:0x3ffd23c0 0x400f1216:0x3ffd2480 0x400f0007:0x3ffd24e0 0x400f0d9e:0x3ffd2500 0x400d544d:0x3ffd2520
0x40146015: _svfprintf_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:1528

0x4014339d: asprintf at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/asprintf.c:74

0x400f1216: http_auth_digest at /home/tokyo/esp-idf/v4.2/components/esp_http_client/lib/http_auth.c:132

0x400f0007: esp_http_client_prepare at /home/tokyo/esp-idf/v4.2/components/esp_http_client/esp_http_client.c:503

0x400f0d9e: esp_http_client_perform at /home/tokyo/esp-idf/v4.2/components/esp_http_client/esp_http_client.c:930

0x400d544d: app at /home/tokyo/Documentos/Proyectos/BASE/build/../main/app_main.c:151

After some research I figured out that the server does not set the “opaque” header file during the authentication, so the line https://github.com/espressif/esp-idf/blob/8bc19ba893e5544d571a753d82b44a84799b94b1/components/esp_http_client/esp_http_client.c#L1359 returns a NULL pointer which cannot be referenced in further steps.

I’m not totally sure if it’s mandatory for the server to set the opaque field (I have not foud how to set this in lighttpd nor apache)? For the moment I modified the line quoted above in order to return an empty null-terminated string and works, but I’m sure there is another way to do. Any suggestion?

KR

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@zzzh it’s working on 5.1.1 image

@shubhamkulkarni97 the problem is related to enabling NEWLIB_NANO_FORMAT.

I think you should open a new issue.

What made you think that?

@KaeLL , did you open a new issue?

Why is this closed, seems not fixed yet?

Hi @atlasoft,

RFC states the following about opaque field:

opaque

      A string of data, specified by the server, that SHOULD be returned
      by the client unchanged in the Authorization header field of
      subsequent requests with URIs in the same protection space.  It is
      RECOMMENDED that this string be Base64 or hexadecimal data.

This does not mention opaque as optional field and indicates an issue related to server.

Thanks, Shubham