29 char auth_header[1024];
30 if (httpd_req_get_hdr_value_str(req,
"Authorization", auth_header, 1024) !=
35 String auth_header_str(auth_header);
36 int space_pos = auth_header_str.indexOf(
' ');
37 if (space_pos == -1) {
41 String auth_type = auth_header_str.substring(0, space_pos);
42 if (auth_type !=
"Digest") {
46 String auth_str = auth_header_str.substring(space_pos + 1);
51 if (userhash ==
"true") {
53 if (username != ref_username) {
65 String algorithm =
extract_param(
"algorithm", auth_str,
false);
73 if (realm ==
"" || nonce ==
"" || uri ==
"" || response ==
"" ||
74 opaque ==
"" || nc ==
"" || cnonce ==
"") {
79 int count = strtol(nc.c_str(), NULL, 16);
83 if (nonce_status == 0) {
85 }
else if (nonce_status == -1) {
94 int method = req->method;
107 method_str =
"DELETE";
115 String a2 = method_str +
":" + uri;
116 String expected_response =
MD5(
MD5(a1) +
":" + nonce +
":" + nc +
":" +
117 cnonce +
":" + qop +
":" +
MD5(a2));
119 return response == expected_response ? 1 : 0;
148 String timestamp_str = String(millis());
149 String to_hash = timestamp_str +
":" +
secret_;
150 String hash =
MD5(to_hash);
151 String nonce = timestamp_str +
" " + hash;
155 size_t output_length;
156 mbedtls_base64_encode((
unsigned char*)encoded,
sizeof(encoded),
157 &output_length, (uint8_t*)nonce.c_str(),
159 encoded[output_length] =
'\0';
160 String nonce_str(encoded);
162 nonces_.push_front({nonce, 1});
167 std::list<NonceData>::iterator it;
168 String decoded_nonce;
170 size_t output_length;
172 mbedtls_base64_decode((
unsigned char*)decoded,
sizeof(decoded),
173 &output_length, (uint8_t*)nonce.c_str(),
175 decoded[output_length] =
'\0';
176 decoded_nonce = String(decoded);
178 if (it->nonce == decoded_nonce) {
185 String timestamp_str = decoded_nonce.substring(0, nonce.indexOf(
' '));
186 unsigned long timestamp = timestamp_str.toInt();
191 it->count = count + 1;
195 String timestamp_str = it->nonce.substring(0, it->nonce.indexOf(
' '));
196 unsigned long timestamp = timestamp_str.toInt();
206 String quote = quoted ?
"\"" :
"";
207 int start = auth_str.indexOf(param +
"=" + quote);
211 start += param.length() + 1 + (quoted ? 1 : 0);
212 int end = auth_str.indexOf(quoted ? quote :
",", start);
214 end = auth_str.length();
216 return auth_str.substring(start, end);