mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-07 16:23:38 +03:00
Ota hashed password (#2292)
* Add option to give ArduinoOTA a hashed value of the password hashed password can be safely stored on flash * Switch to separate method to accept the hash * Calculate the hash of plain passwords at setup * missed line * Remove underscores from local variable
This commit is contained in:
parent
c4f9f102ce
commit
e83f30a78d
@ -82,6 +82,16 @@ String ArduinoOTAClass::getHostname() {
|
||||
}
|
||||
|
||||
void ArduinoOTAClass::setPassword(const char * password) {
|
||||
if (!_initialized && !_password.length() && password) {
|
||||
MD5Builder passmd5;
|
||||
passmd5.begin();
|
||||
passmd5.add(password);
|
||||
passmd5.calculate();
|
||||
_password = passmd5.toString();
|
||||
}
|
||||
}
|
||||
|
||||
void ArduinoOTAClass::setPasswordHash(const char * password) {
|
||||
if (!_initialized && !_password.length() && password) {
|
||||
_password = password;
|
||||
}
|
||||
@ -206,13 +216,7 @@ void ArduinoOTAClass::_onRx(){
|
||||
return;
|
||||
}
|
||||
|
||||
MD5Builder _passmd5;
|
||||
_passmd5.begin();
|
||||
_passmd5.add(_password);
|
||||
_passmd5.calculate();
|
||||
String passmd5 = _passmd5.toString();
|
||||
|
||||
String challenge = passmd5 + ":" + String(_nonce) + ":" + cnonce;
|
||||
String challenge = _password + ":" + String(_nonce) + ":" + cnonce;
|
||||
MD5Builder _challengemd5;
|
||||
_challengemd5.begin();
|
||||
_challengemd5.add(challenge);
|
||||
|
@ -34,6 +34,7 @@ class ArduinoOTAClass
|
||||
void setHostname(const char *hostname);
|
||||
String getHostname();
|
||||
void setPassword(const char *password);
|
||||
void setPasswordHash(const char *password);
|
||||
void onStart(THandlerFunction fn);
|
||||
void onEnd(THandlerFunction fn);
|
||||
void onError(THandlerFunction_Error fn);
|
||||
|
@ -24,7 +24,11 @@ void setup() {
|
||||
// ArduinoOTA.setHostname("myesp8266");
|
||||
|
||||
// No authentication by default
|
||||
// ArduinoOTA.setPassword((const char *)"123");
|
||||
// ArduinoOTA.setPassword("admin");
|
||||
|
||||
// Password can be set with it's md5 value as well
|
||||
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
|
||||
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
|
||||
|
||||
ArduinoOTA.onStart([]() {
|
||||
String type;
|
||||
|
Loading…
x
Reference in New Issue
Block a user