Curl not working with Digest Authentication

I'm using curl on a OpenWrt device to fetch images from a network camera. The problem is that the camera supports only Digest Authentication and I'm unable to get it to work on OpenWrt. Here's the curl command I'm using:

curl --user "username:password" "camera-address-here" --digest -o "snapshot.jpg"

If I run that on my Windows PC with Curl 7.55.1 the camera first returns a 401 (with realm, nonce etc) and curl re-issues another request with appropriate authorization and the request succesfully returns the image. I've managed to get it to work in both command prompt and PHP. However, if I run the exact same command (or php code) on OpenWrt, the second request never gets fired. Any ideas how to solve the problem? The curl version on OpenWrt is "7.60.0 (arm-openwrt-linux-gnu) libcurl/7.60.0 mbedTLS/2.16.3"

The problem is very similar as described in this archived thread:
https://forum.archive.openwrt.org/viewtopic.php?id=72803

Just for others who might be interested in the topic:
I created a PHP script that does two curl requests: The first one gets the auth stuff (realm,nonce,opaque,qop) and calculates the hashes of combined strings with md5 and generates the required auth header for Digest Authentication. The generated header is then passed to the next curl request, which fetches the actual image. I'm still doing some optimization/refactoring to make the code a bit clearer, but I could share it here in case anyone's interested.

2 Likes

The curl package in OpenWrt is built without digest authentication:

config LIBCURL_CRYPTO_AUTH
        bool "Enable cryptographic authentication"
        default n

You could rebuild it with this option enabled, using the OpenWrt SDK .

Another option is wget from the wget package (GNU variant) or from the uclient-fetch package (OpenWrt's tiny wget clone).

2 Likes

Hi
yep the post is old, but,here it is a nice way

#!/usr/bin/env python3

import requests
from requests.auth import HTTPDigestAuth

url = 'http://ip:port/ISAPI/System/reboot'
username = 'user'
password = 'password'
print(requests.put(url, auth=HTTPDigestAuth(username, password)).content,)