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

Digest Authentication in Webserver Library #3053

Merged
merged 20 commits into from
Sep 18, 2017
Merged

Conversation

Lan-Hekary
Copy link
Contributor

Added and Example called HTTPAdvancedAuth to show the user how to use the auth method
the Normal Basic Auth wasn't affected as it's the default mode in the function call
the user can change the auth relm too
also added a feature to change the auth failure html content

@codecov-io
Copy link

codecov-io commented Jun 17, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@3e9caf7). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##             master   #3053   +/-   ##
========================================
  Coverage          ?   27.6%           
========================================
  Files             ?      20           
  Lines             ?    3655           
  Branches          ?     678           
========================================
  Hits              ?    1009           
  Misses            ?    2468           
  Partials          ?     178

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e9caf7...35b7c0a. Read the comment docs.

@Lan-Hekary
Copy link
Contributor Author

Hello @igrr , will this feature be added to the Master Branch ??
if it's added please close the Pull request :D

@Lan-Hekary
Copy link
Contributor Author

@igrr any news ??
I've been waiting for a long time now ..
tell me if there is are problem or modification ..

Copy link
Member

@igrr igrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, forgot about this MR again. Left some (mostly minor comments below).

One major request is to make sure new functionality does not get linked into the application if Basic auth is used. My suggestion is to add two functions, requestBasicAuthentication and requestDigestAuthentication, keep requestAuthentication for compatibility (making it call requestBasicAuthentication). This way the extra code only gets added if Digest auth is actually used in the sketch.

if(mode==BASIC_AUTH){
sendHeader("WWW-Authenticate", "Basic realm=\"" + _srealm + "\"");
}else{
_snonce=String(RANDOM_REG32,HEX)+String(RANDOM_REG32,HEX)+String(RANDOM_REG32,HEX)+String(RANDOM_REG32,HEX);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does String(val, HEX) automatically pad the string to 8 hexadecimal places, or the string can end up being shorter?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it might be a bit nicer to put this into a separate function, a la String getRandomHexString(size_t length).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String(val, HEX) in the original Arduino depends on itoa which does not support padding
But it's not a problem really
the nonce and opaque values are arbitrary in length anyway

but the idea of a function is much better as I need to call it twice ..
I will modify it right away ..

void ESP8266WebServer::requestAuthentication(){
sendHeader("WWW-Authenticate", "Basic realm=\"Login Required\"");
send(401);
void ESP8266WebServer::requestAuthentication(HTTPAuthMethod mode, const char* realm, const String& AuthFailMsg){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest authFailMsg instead of AuthFailMsg.

@@ -0,0 +1,45 @@
#include <ESP8266WiFi.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a public domain / CC0 license at the top of the sketch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this sketch from the HttpBasicAuth folder and it does not have a license ..
I am not sure of what should I put here ..
can you give an Example ??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, i mean public domain license, as in Blink example. It has been mentioned before that using LGPL license on examples is too restrictive. We already have a few such examples, and it would be better to migrate all the examples to CC0/public domain license.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I just copied the license from the next sketch in the folder .
fixed it now


const char* www_username = "admin";
const char* www_password = "esp8266";
const char* www_realm = "Custom Realm"; // allows you to set the realm of authentication Default:"Login Required"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These long comments will not fit into default Arduino IDE window.

const char* www_username = "admin";
const char* www_password = "esp8266";
const char* www_realm = "Custom Realm"; // allows you to set the realm of authentication Default:"Login Required"
String AuthFailResponse = "Authentication Failed"; // the Content of the HTML response in case of Unautherized Access Default:empty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, variable names in Arduino usually start with lowercase letter

@Lan-Hekary
Copy link
Contributor Author

thanks for the fast reply @igrr 🗡️

Concerning this :

One major request is to make sure new functionality does not get linked into the application if Basic auth is used. My suggestion is to add two functions, requestBasicAuthentication and requestDigestAuthentication, keep requestAuthentication for compatibility (making it call requestBasicAuthentication). This way the extra code only gets added if Digest auth is actually used in the sketch.

The function prototype in the header file is the following
void requestAuthentication(HTTPAuthMethod mode = BASIC_AUTH, const char* realm = NULL, const String& AuthFailMsg = String("") );

it defaults to use the Basic Auth if no parameters is passed to the function call
so the user won't feel the difference.

this code for example exactly works the same as if no modifications were added
if(!server.authenticate(www_username, www_password)) return server.requestAuthentication();

if you are worried about the extra code added .. the Bulk of the Code resides in the function authenticate and I have no Idea how to reduce it if the user prefers a Basic Auth ..
I guess it won't make a big difference in code size .. but it would simplify things a bit ..

please advise on how to proceed I will modify it as you say it if you say so :D

I am working on the other modifications in the meanwhile waiting for a reply to push the last modification

@igrr
Copy link
Member

igrr commented Sep 9, 2017

Ok, i understand. It's okay to keep the function as is (requestAuthentication with a parameter).

@Lan-Hekary
Copy link
Contributor Author

I've made the modifications you asked for
I wrote a Function to get random hex but I made it a fixed length and it's padded now
String getRandomHexString();
to avoid the hassle of dynamic allocation and to avoid any additional overhead

@Lan-Hekary
Copy link
Contributor Author

any news ?? @igrr
I think you forgot me again ..

@igrr igrr merged commit eebc5ec into esp8266:master Sep 18, 2017
@Lan-Hekary Lan-Hekary deleted the DigestAuth branch September 19, 2017 06:42
@Lan-Hekary Lan-Hekary restored the DigestAuth branch September 19, 2017 06:43
d-a-v pushed a commit to d-a-v/Arduino that referenced this pull request Sep 29, 2017
* Add Digest Auth

* Check for Opaque and Nonce

* Remove Serial Debug and fix Indentation

* Added example sketch with documentation,Fixed indentation and Defaults

* Digest Authentication minor changes + new padded 32 digit random function

* update license to public domain

* renaming functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants