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

make HTTP Update Server more secure #2104

Merged
merged 12 commits into from
Jun 7, 2016
Merged

Conversation

me-no-dev
Copy link
Collaborator

  • added option for authentication
  • added option to change the url for upload

public:
ESP8266HTTPUpdateServer(bool serial_debug=false);
void setup(ESP8266WebServer *server=NULL);
void setup(ESP8266WebServer *server, const char * path="/update", const char * username=NULL, const char * password=NULL);
Copy link
Member

Choose a reason for hiding this comment

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

Let's use a pair of overloaded functions instead of a function with bunch of default arguments here.
I.e.

void setup(ESP8266WebServer *server); // used to keep code backward compatible, calls setup(server, "/update", NULL, NULL)
void setup(ESP8266WebServer *server, const char * path); // optional, add this if you want... not really necessary IMO. calls setup(server, path, NULL, NULL);
void setup(ESP8266WebServer *server, const char * path, const char* username, const char* password); // new overload, all arguments are required

Reason for such a design is that it's easier to refactor/extend/deprecate an interface based on overloaded functions compared to an interface which uses function with many default arguments. This was very obvious with ESP8266HTTPClient and ESP8266HTTPUpdate, which used default arguments heavily. It was really painful to separate functions which needed TLS from the ones which didn't...

@codecov-io
Copy link

codecov-io commented Jun 6, 2016

Current coverage is 26.31%

Merging #2104 into master will not change coverage

@@             master      #2104   diff @@
==========================================
  Files            19         19          
  Lines          3634       3634          
  Methods         328        328          
  Messages          0          0          
  Branches        585        585          
==========================================
  Hits            956        956          
  Misses         2513       2513          
  Partials        165        165          

Powered by Codecov. Last updated by 32bd42b...b3fe814

@me-no-dev
Copy link
Collaborator Author

better?


void loop(void){
httpServer.handleClient();
delay(1);
Copy link
Member

Choose a reason for hiding this comment

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

Delay not needed here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah... was in the other example, so I left it there thinking might be needed. I'll remove it from both

@me-no-dev
Copy link
Collaborator Author

done

@me-no-dev
Copy link
Collaborator Author

let me add one more thing. message to the browser is a bit cryptic :)

Me No Dev added 2 commits June 6, 2016 14:26
interesting, the meta did not refresh if the successResponse is put in
"R"
_server->on(path, HTTP_POST, [&](){
if(!_authenticated)
return _server->requestAuthentication();
_server->send(200, "text/html", Update.hasError() ? _failedResponse : _successResponse);
ESP.restart();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@igrr you think maybe we should not reboot if Update failed?

Copy link
Member

Choose a reason for hiding this comment

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

I'll merge this as is, let's address this in a separate pull request. I think a good idea would be to add update callbacks similar to ESP8266HTTPUpdate (client). Actually maybe we need to review APIs of HTTP update client and HTTP update server and make them more uniform. Let's discuss further on gitter.

@igrr igrr merged commit a7ced9c into esp8266:master Jun 7, 2016
@me-no-dev me-no-dev deleted the secure-http-update branch July 4, 2016 17:52
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