HttpSendDigest("/command.cgi",user,password,dataString)
Home › Forums › Your projects › Projet control vidéo with Arduino and MD5 digest authentication.
Tagged: Arduino, Digest authentication, MD5
- This topic has 3 replies, 2 voices, and was last updated 4 years ago by
toni.
-
AuthorPosts
-
-
31 August 2020 at 15:43 #5795
Bonjour,
I allow myself to ask my project because I need your skills.
I admire your work and use it for my personal projects
today I have a professional project: to link an alarm with video surveillance.material available:
I have a set of Uniview PTZ cameras and an alarm system.My project:
I would like to control the cameras from an arduino using the API.API documentation:
https://documentcloud.adobe.com/link/track?uri=urn:aaid:scds:US:b8062a8f-f359-4a18-aa38-b8a2532a54cf
Problems:
“The API uses digest authentication” how to connect with this type of authentication ….
thank you
-
1 September 2020 at 07:34 #5895
Hi Ludopot,
I found this implementation
#include <ArduinoHttpClient.h> #include <MD5.h> HttpClient client = HttpClient(wifiConnection, adress, port); ... bool HttpSendDigest(String uri, String user, String password, String data) { //Serial.println("HttpSendDigest::POST request"); client.beginRequest(); client.post(uri,"application/x-www-form-urlencoded",data); client.endRequest(); String header =""; // read the status code and body of the response int statusCode = client.responseStatusCode(); if (client.headerAvailable()){ while(!client.endOfHeadersReached()){ header = header + char(client.readHeader()); } } String headerName = client.readHeaderName(); String headerValue = client.readHeaderValue(); String response = client.responseBody(); /* Serial.println("HttpSendDigest::Headername: "+ headerName); Serial.println("HttpSendDigest::Headervalue: "+ headerValue); Serial.println("HttpSendDigest::header: "); Serial.println(header); Serial.print("HttpSendDigest::statuscode: "); Serial.println(statusCode); Serial.println("HttpSendDigest::response: "); Serial.println(response); */ if (statusCode == 401 && headerName.equalsIgnoreCase("WWW-Authenticate")) { //Serial.println("HttpSendDigest::401+WWW-Authenticate detected"); String AuthMethod = headerValue.substring(0,headerValue.indexOf(' ')); String realm = strGetValue(headerValue,"realm=\"","\""); String nonce = strGetValue(headerValue,"nonce=\"","\""); String qop = strGetValue(headerValue,"qop=\"","\""); /* Serial.println("HttpSendDigest::AuthMethod: "+AuthMethod); Serial.println("HttpSendDigest::realm: "+realm); Serial.println("HttpSendDigest::nonce: "+nonce); Serial.println("HttpSendDigest::qop: "+qop); */ //Serial.print("HttpSendDigest::Calculate HA1..."); String HA1 = calcMD5(user+":"+realm+":"+password); //Serial.println(HA1); //Serial.print("HttpSendDigest::Calculate HA2..."); String HA2 = calcMD5("POST:"+uri); //Serial.println(HA2); String cnonce = String(random(8556822323)); //Serial.println("HttpSendDigest::cnonce: "+cnonce); //Serial.println("HttpSendDigest::Calculate authResponse..."); String authResponse =calcMD5(HA1+":"+nonce+":"+"00000001"+":"+cnonce+":"+qop+":"+HA2); //MD5(HA1:nonce:nonceCount:cnonce:qop:HA2) //Serial.println("HttpSendDigest::authResponse: "+authResponse); String authHeaderString = "Authorization: Digest username=\"" + user + "\",realm=\"" + realm + "\",nonce=\"" + nonce + "\",uri=\"" + uri + "\",cnonce=\"" + cnonce + "\",qop=auth, nc=00000001, response=\"" + authResponse + "\"";//\r\n"; //Serial.println("HttpSendDigest::authHeaderString: "+authHeaderString); //Serial.println("HttpSendDigest::---auth post---"); client.beginRequest(); client.post(uri); client.sendHeader(authHeaderString); client.sendHeader(HTTP_HEADER_CONTENT_TYPE, "application/x-www-form-urlencoded"); client.sendHeader(HTTP_HEADER_CONTENT_LENGTH, data.length()); client.beginBody(); client.print(data); client.endRequest(); //Serial.println("HttpSendDigest::---authresponse---"); header =""; // read the status code and body of the response statusCode = client.responseStatusCode(); if (client.headerAvailable()){ while(!client.endOfHeadersReached()){ header = header + char(client.readHeader()); } } headerName = client.readHeaderName(); headerValue = client.readHeaderValue(); response = client.responseBody(); /* Serial.println("HttpSendDigest::Headername: "+ headerName); Serial.println("HttpSendDigest::Headervalue: "+ headerValue); Serial.println("HttpSendDigest::header: "); Serial.println(header); Serial.print("HttpSendDigest::statuscode: "); Serial.println(statusCode); Serial.println("HttpSendDigest::response: "); Serial.println(response); */ } if (statusCode==200) { return true; } else { return false; } }
than you must call like this
But you must check if the software need HTTPS because Arduino not support that protocol.
Bye Renzo
-
1 September 2020 at 08:23 #5980
thank you ! I will test that. normally it is on port 80.
-
28 May 2021 at 11:25 #12434
toni
Sorry, but where is the library
#include <MD5.h>
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.