diff --git a/docs/Commands.txt b/docs/Commands.txt index d03259fd..96c2b089 100644 --- a/docs/Commands.txt +++ b/docs/Commands.txt @@ -178,6 +178,8 @@ ESP_AUTO_NOTIFICATION 1022 //1 byte = flag ESP_VERBOSE_BOOT 1023 //1 byte = flag ESP_WEBDAV_ON 1024 //1 byte = flag ESP_WEBDAV_PORT 1025 //4 bytes = int +ESP_STA_DNS_VALUE 1029 //4 bytes= int +ESP_SECURE_SERIAL 1033 //1 byte = flag * Get/Set Check update at boot state which can be ON, OFF [ESP402]pwd= diff --git a/esp3d/src/core/commands.cpp b/esp3d/src/core/commands.cpp index 3a9de560..cb43a551 100644 --- a/esp3d/src/core/commands.cpp +++ b/esp3d/src/core/commands.cpp @@ -253,7 +253,7 @@ bool Commands::execute_internal_command (int cmd, const char* cmd_params, level_ //do not overwrite previous authetic ation level if (auth_type == LEVEL_GUEST) { String pwd=get_param (cmd_params, "pwd="); - auth_type = AuthenticationService::authenticated_level(pwd.c_str()); + auth_type = AuthenticationService::authenticated_level(pwd.c_str(), output); } #endif //AUTHENTICATION_FEATURE //log_esp3d("Authentication = %d", auth_type); diff --git a/esp3d/src/core/espcmd/ESP103.cpp b/esp3d/src/core/espcmd/ESP103.cpp index ff3e117b..c631934a 100644 --- a/esp3d/src/core/espcmd/ESP103.cpp +++ b/esp3d/src/core/espcmd/ESP103.cpp @@ -53,7 +53,7 @@ bool Commands::ESP103(const char* cmd_params, level_authenticate_type auth_type, res += Settings_ESP3D::read_IP_String(ESP_STA_GATEWAY_VALUE); res += ", MSK:"; res += Settings_ESP3D::read_IP_String(ESP_STA_MASK_VALUE); - res += ", DNS:"; + res += ", DNS:"; res += Settings_ESP3D::read_IP_String(ESP_STA_DNS_VALUE); output->printMSG (res.c_str()); } else { //set diff --git a/esp3d/src/core/espcmd/ESP400.cpp b/esp3d/src/core/espcmd/ESP400.cpp index 0ca39fa0..82a9afae 100644 --- a/esp3d/src/core/espcmd/ESP400.cpp +++ b/esp3d/src/core/espcmd/ESP400.cpp @@ -209,6 +209,13 @@ bool Commands::ESP400(const char* cmd_params, level_authenticate_type auth_type, output->print ("\",\"H\":\"session timeout\",\"M\":\""); output->print (Settings_ESP3D::get_min_byte(ESP_SESSION_TIMEOUT)); output->print ("\"}"); + + //Secure Serial + output->print (",{\"F\":\"security/security\",\"P\":\""); + output->print (ESP_SECURE_SERIAL); + output->print ("\",\"T\":\"B\",\"V\":\""); + output->print (Settings_ESP3D::read_byte(ESP_SECURE_SERIAL)); + output->print ("\",\"H\":\"serial\",\"O\":[{\"no\":\"0\"},{\"yes\":\"1\"}]}"); #endif //AUTHENTICATION_FEATURE #ifdef HTTP_FEATURE diff --git a/esp3d/src/core/espcmd/ESP401.cpp b/esp3d/src/core/espcmd/ESP401.cpp index a075752f..9bd0104f 100644 --- a/esp3d/src/core/espcmd/ESP401.cpp +++ b/esp3d/src/core/espcmd/ESP401.cpp @@ -85,6 +85,9 @@ bool Commands::ESP401(const char* cmd_params, level_authenticate_type auth_type, case ESP_TARGET_FW: Settings_ESP3D::GetFirmwareTarget(true); break; + case ESP_SECURE_SERIAL: + serial_service.setParameters(); + break; #ifdef AUTHENTICATION_FEATURE case ESP_SESSION_TIMEOUT: AuthenticationService::setSessionTimeout(1000*60*sval.toInt()); diff --git a/esp3d/src/core/settings_esp3d.cpp b/esp3d/src/core/settings_esp3d.cpp index 714c8374..cb4cd013 100644 --- a/esp3d/src/core/settings_esp3d.cpp +++ b/esp3d/src/core/settings_esp3d.cpp @@ -118,6 +118,7 @@ #define DEFAULT_NOTIFICATION_TOKEN2 "" #define DEFAULT_NOTIFICATION_SETTINGS "" #define DEFAULT_AUTO_NOTIFICATION_STATE 1 +#define DEFAULT_SECURE_SERIAL 1 //default int values @@ -239,6 +240,9 @@ uint8_t Settings_ESP3D::get_default_byte_value(int pos) { uint8_t res; switch(pos) { + case ESP_SECURE_SERIAL: + res = DEFAULT_SECURE_SERIAL; + break; case ESP_RADIO_MODE: res = DEFAULT_ESP_RADIO_MODE; break; @@ -1068,7 +1072,7 @@ bool Settings_ESP3D::reset(bool networkonly) Settings_ESP3D::write_IP(ESP_STA_GATEWAY_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_GATEWAY_VALUE)); //STA static Mask Settings_ESP3D::write_IP(ESP_STA_MASK_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_MASK_VALUE)); - //STA static DNS + //STA static DNS Settings_ESP3D::write_IP(ESP_STA_DNS_VALUE, Settings_ESP3D::get_default_IP_value(ESP_STA_DNS_VALUE)); #endif //WIFI_FEATURE || ETH_FEATURE if (networkonly) { @@ -1095,7 +1099,8 @@ bool Settings_ESP3D::reset(bool networkonly) Settings_ESP3D::write_byte(ESP_SETUP,Settings_ESP3D::get_default_byte_value(ESP_SETUP)); //Verbose boot Settings_ESP3D::write_byte(ESP_VERBOSE_BOOT,Settings_ESP3D::get_default_byte_value(ESP_VERBOSE_BOOT)); - + //Secure Serial + Settings_ESP3D::write_byte(ESP_SECURE_SERIAL,Settings_ESP3D::get_default_byte_value(ESP_SECURE_SERIAL)); #if defined(DISPLAY_DEVICE) && defined(DISPLAY_TOUCH_DRIVER) //Calibration done (internal only) Settings_ESP3D::write_byte(ESP_CALIBRATION,Settings_ESP3D::get_default_byte_value(ESP_CALIBRATION)); diff --git a/esp3d/src/core/settings_esp3d.h b/esp3d/src/core/settings_esp3d.h index 04147c35..475bab24 100644 --- a/esp3d/src/core/settings_esp3d.h +++ b/esp3d/src/core/settings_esp3d.h @@ -105,6 +105,7 @@ #define ESP_WEBDAV_ON 1024 //1 byte = flag #define ESP_WEBDAV_PORT 1025 //4 bytes= int #define ESP_STA_DNS_VALUE 1029 //4 bytes= int +#define ESP_SECURE_SERIAL 1033 //1 byte = flag //Hidden password diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index d29c7582..7981d0cf 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a90" +#define FW_VERSION "3.0.0.a91" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/authentication/authentication_service.cpp b/esp3d/src/modules/authentication/authentication_service.cpp index 81b04db9..b6d416b5 100644 --- a/esp3d/src/modules/authentication/authentication_service.cpp +++ b/esp3d/src/modules/authentication/authentication_service.cpp @@ -48,7 +48,7 @@ uint8_t AuthenticationService::_current_nb_ip = 0; //#define ALLOW_MULTIPLE_SESSIONS //check authentification -level_authenticate_type AuthenticationService::authenticated_level(const char * pwd) +level_authenticate_type AuthenticationService::authenticated_level(const char * pwd, ESP3DOutput * output) { #ifdef AUTHENTICATION_FEATURE level_authenticate_type auth_type = LEVEL_GUEST; @@ -60,7 +60,13 @@ level_authenticate_type AuthenticationService::authenticated_level(const char * if (isuser (pwd) && (auth_type != LEVEL_ADMIN)) { auth_type = LEVEL_USER; } + return auth_type; } else { + if(output) { + if (output->client() !=ESP_HTTP_CLIENT) { + return auth_type; + } + } #if defined (HTTP_FEATURE) if (_webserver) { if (_webserver->hasHeader ("Authorization") ) { @@ -92,6 +98,7 @@ level_authenticate_type AuthenticationService::authenticated_level(const char * return auth_type; #else (void)pwd; + (void)output; return LEVEL_ADMIN; #endif //AUTHENTICATION_FEATURE } diff --git a/esp3d/src/modules/authentication/authentication_service.h b/esp3d/src/modules/authentication/authentication_service.h index 07479af1..9be9d676 100644 --- a/esp3d/src/modules/authentication/authentication_service.h +++ b/esp3d/src/modules/authentication/authentication_service.h @@ -32,6 +32,7 @@ const char DEFAULT_ADMIN_LOGIN [] = "admin"; const char DEFAULT_USER_LOGIN [] = "user"; #include "../../include/esp3d_config.h" +#include "../../core/esp3doutput.h" #if defined (AUTHENTICATION_FEATURE) #if defined (HTTP_FEATURE) #include @@ -58,7 +59,7 @@ typedef void Authwebserver; class AuthenticationService { public: - static level_authenticate_type authenticated_level(const char * pwd = nullptr); + static level_authenticate_type authenticated_level(const char * pwd = nullptr, ESP3DOutput * output= nullptr); #ifdef AUTHENTICATION_FEATURE static bool begin(Authwebserver * webserver); static void end(); diff --git a/esp3d/src/modules/serial/serial_service.cpp b/esp3d/src/modules/serial/serial_service.cpp index 9775b9fa..47023ed1 100644 --- a/esp3d/src/modules/serial/serial_service.cpp +++ b/esp3d/src/modules/serial/serial_service.cpp @@ -26,6 +26,7 @@ #if COMMUNICATION_PROTOCOL == MKS_SERIAL #include "../mks/mks_service.h" #endif //COMMUNICATION_PROTOCOL == MKS_SERIAL +#include "../authentication/authentication_service.h" //Serial Parameters #define ESP_SERIAL_PARAM SERIAL_8N1 @@ -59,6 +60,7 @@ SerialService::SerialService() { _buffer_size = 0; _started = false; + _needauthentication = true; } //Destructor @@ -79,12 +81,23 @@ void ESP3DSerialTaskfn( void * parameter ) } #endif //ARDUINO_ARCH_ESP32 +//extra parameters that do not need a begin +void SerialService::setParameters() +{ +#if defined (AUTHENTICATION_FEATURE) + _needauthentication = (Settings_ESP3D::read_byte (ESP_SECURE_SERIAL)==0)?false:true; +#else + _needauthentication = false; +#endif //AUTHENTICATION_FEATURE +} + //Setup Serial bool SerialService::begin() { _lastflush = millis(); //read from settings long br = Settings_ESP3D::read_uint32(ESP_BAUD_RATE); + setParameters(); _buffer_size = 0; //change only if different from current if (br != baudRate() || (ESP_RX_PIN != -1) || (ESP_TX_PIN != -1)) { @@ -197,7 +210,7 @@ void SerialService::flushbuffer() ESP3DOutput output(ESP_SERIAL_CLIENT); _buffer[_buffer_size] = 0x0; //dispatch command - esp3d_commands.process(_buffer, _buffer_size, &output); + esp3d_commands.process(_buffer, _buffer_size, &output,_needauthentication?LEVEL_GUEST:LEVEL_ADMIN); _lastflush = millis(); _buffer_size = 0; } diff --git a/esp3d/src/modules/serial/serial_service.h b/esp3d/src/modules/serial/serial_service.h index cd4460e0..943318b4 100644 --- a/esp3d/src/modules/serial/serial_service.h +++ b/esp3d/src/modules/serial/serial_service.h @@ -30,6 +30,7 @@ class SerialService : public Print public: SerialService(); ~SerialService(); + void setParameters(); bool begin(); bool end(); void updateBaudRate(long br); @@ -73,6 +74,7 @@ public: } private: bool _started; + bool _needauthentication; uint32_t _lastflush; uint8_t _buffer[ESP3D_SERIAL_BUFFER_SIZE + 1]; //keep space of 0x0 terminal size_t _buffer_size; diff --git a/esp3d/src/modules/update/update_service.cpp b/esp3d/src/modules/update/update_service.cpp index 3ae6de27..49f264bd 100644 --- a/esp3d/src/modules/update/update_service.cpp +++ b/esp3d/src/modules/update/update_service.cpp @@ -148,7 +148,8 @@ const char * SysboolKeysVal[] = {"Active_Printer_LCD", "Active_WebSocket", "Active_Telnet", "Active_BT", - "Boot_verbose" + "Boot_verbose", + "Secure_serial" } ; const uint16_t SysboolKeysPos[] = {ESP_PRINTER_LCD_FLAG, @@ -157,7 +158,8 @@ const uint16_t SysboolKeysPos[] = {ESP_PRINTER_LCD_FLAG, ESP_WEBSOCKET_FLAG, ESP_TELNET_FLAG, ESP_BT_FLAG, - ESP_VERBOSE_BOOT + ESP_VERBOSE_BOOT, + ESP_SECURE_SERIAL } ; const char * NetbyteKeysVal[] = {