Resolve some typos

Use nullptr over NULL
Fix confusing regexp
Fix issue with non-compliant JWT encoding
This commit is contained in:
Rick Watson 2019-06-02 23:15:56 +01:00
parent 5d9ccd3095
commit 9c680e8826
11 changed files with 134 additions and 136 deletions

View File

@ -65,7 +65,7 @@ class APSettingsForm extends React.Component {
isAPEnabled(apSettings.provision_mode) && isAPEnabled(apSettings.provision_mode) &&
<Fragment> <Fragment>
<TextValidator <TextValidator
validators={['required', 'matchRegexp:^.{0,32}$']} validators={['required', 'matchRegexp:^.{1,32}$']}
errorMessages={['Access Point SSID is required', 'Access Point SSID must be 32 characeters or less']} errorMessages={['Access Point SSID is required', 'Access Point SSID must be 32 characeters or less']}
name="ssid" name="ssid"
label="Access Point SSID" label="Access Point SSID"
@ -75,7 +75,7 @@ class APSettingsForm extends React.Component {
margin="normal" margin="normal"
/> />
<PasswordValidator <PasswordValidator
validators={['required', 'matchRegexp:^.{0,64}$']} validators={['required', 'matchRegexp:^.{1,64}$']}
errorMessages={['Access Point Password is required', 'Access Point Password must be 64 characters or less']} errorMessages={['Access Point Password is required', 'Access Point Password must be 64 characters or less']}
name="password" name="password"
label="Access Point Password" label="Access Point Password"

View File

@ -85,7 +85,7 @@ class OTASettingsForm extends React.Component {
/> />
<PasswordValidator <PasswordValidator
validators={['required', 'matchRegexp:^.{0,64}$']} validators={['required', 'matchRegexp:^.{1,64}$']}
errorMessages={['OTA Password is required', 'OTA Point Password must be 64 characters or less']} errorMessages={['OTA Password is required', 'OTA Point Password must be 64 characters or less']}
name="password" name="password"
label="Password" label="Password"

View File

@ -49,7 +49,7 @@ class SecuritySettingsForm extends React.Component {
securitySettings ? securitySettings ?
<ValidatorForm onSubmit={this.onSubmit} ref="SecuritySettingsForm"> <ValidatorForm onSubmit={this.onSubmit} ref="SecuritySettingsForm">
<PasswordValidator <PasswordValidator
validators={['required', 'matchRegexp:^.{0,64}$']} validators={['required', 'matchRegexp:^.{1,64}$']}
errorMessages={['JWT Secret Required', 'JWT Secret must be 64 characters or less']} errorMessages={['JWT Secret Required', 'JWT Secret must be 64 characters or less']}
name="jwt_secret" name="jwt_secret"
label="JWT Secret" label="JWT Secret"

View File

@ -48,7 +48,7 @@ class UserForm extends React.Component {
<DialogContent dividers={true}> <DialogContent dividers={true}>
<TextValidator <TextValidator
validators={creating ? ['required', 'uniqueUsername', 'matchRegexp:^[a-zA-Z0-9_\\.]{1,24}$'] : []} validators={creating ? ['required', 'uniqueUsername', 'matchRegexp:^[a-zA-Z0-9_\\.]{1,24}$'] : []}
errorMessages={creating ? ['Username is required', "Username already exists", "Must be 1-24 characters: alpha numberic, '_' or '.'"] : []} errorMessages={creating ? ['Username is required', "Username already exists", "Must be 1-24 characters: alpha numeric, '_' or '.'"] : []}
name="username" name="username"
label="Username" label="Username"
className={classes.textField} className={classes.textField}
@ -58,7 +58,7 @@ class UserForm extends React.Component {
margin="normal" margin="normal"
/> />
<PasswordValidator <PasswordValidator
validators={['required', 'matchRegexp:^.{0,64}$']} validators={['required', 'matchRegexp:^.{1,64}$']}
errorMessages={['Password is required', 'Password must be 64 characters or less']} errorMessages={['Password is required', 'Password must be 64 characters or less']}
name="password" name="password"
label="Password" label="Password"

View File

@ -1,4 +1,4 @@
import React, {Fragment} from 'react'; import React, { Fragment } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
@ -67,7 +67,7 @@ class WiFiSettingsForm extends React.Component {
</ListItemAvatar> </ListItemAvatar>
<ListItemText <ListItemText
primary={selectedNetwork.ssid} primary={selectedNetwork.ssid}
secondary={"Security: "+ networkSecurityMode(selectedNetwork) + ", Ch: " + selectedNetwork.channel} secondary={"Security: " + networkSecurityMode(selectedNetwork) + ", Ch: " + selectedNetwork.channel}
/> />
<ListItemSecondaryAction> <ListItemSecondaryAction>
<IconButton aria-label="Manual Config" onClick={deselectNetwork}> <IconButton aria-label="Manual Config" onClick={deselectNetwork}>
@ -84,57 +84,57 @@ class WiFiSettingsForm extends React.Component {
return ( return (
<div> <div>
{ {
!wifiSettingsFetched ? !wifiSettingsFetched ?
<div className={classes.loadingSettings}> <div className={classes.loadingSettings}>
<LinearProgress className={classes.loadingSettingsDetails}/> <LinearProgress className={classes.loadingSettingsDetails} />
<Typography variant="h4" className={classes.loadingSettingsDetails}> <Typography variant="h4" className={classes.loadingSettingsDetails}>
Loading... Loading...
</Typography> </Typography>
</div> </div>
: wifiSettings ? : wifiSettings ?
<ValidatorForm onSubmit={onSubmit} ref="WiFiSettingsForm"> <ValidatorForm onSubmit={onSubmit} ref="WiFiSettingsForm">
{ {
selectedNetwork ? this.renderSelectedNetwork() : selectedNetwork ? this.renderSelectedNetwork() :
<TextValidator <TextValidator
validators={['required', 'matchRegexp:^.{0,32}$']} validators={['required', 'matchRegexp:^.{1,32}$']}
errorMessages={['SSID is required', 'SSID must be 32 characeters or less']} errorMessages={['SSID is required', 'SSID must be 32 characeters or less']}
name="ssid" name="ssid"
label="SSID" label="SSID"
className={classes.textField} className={classes.textField}
value={wifiSettings.ssid} value={wifiSettings.ssid}
onChange={handleValueChange('ssid')} onChange={handleValueChange('ssid')}
margin="normal" margin="normal"
/> />
} }
{ {
!isNetworkOpen(selectedNetwork) && !isNetworkOpen(selectedNetwork) &&
<PasswordValidator <PasswordValidator
validators={['matchRegexp:^.{0,64}$']} validators={['matchRegexp:^.{0,64}$']}
errorMessages={['Password must be 64 characters or less']} errorMessages={['Password must be 64 characters or less']}
name="password" name="password"
label="Password" label="Password"
className={classes.textField}
value={wifiSettings.password}
onChange={handleValueChange('password')}
margin="normal"
/>
}
<TextValidator
validators={['required', 'isHostname']}
errorMessages={['Hostname is required', "Not a valid hostname"]}
name="hostname"
label="Hostname"
className={classes.textField} className={classes.textField}
value={wifiSettings.hostname} value={wifiSettings.password}
onChange={handleValueChange('hostname')} onChange={handleValueChange('password')}
margin="normal" margin="normal"
/> />
}
<FormControlLabel className={classes.checkboxControl} <TextValidator
validators={['required', 'isHostname']}
errorMessages={['Hostname is required', "Not a valid hostname"]}
name="hostname"
label="Hostname"
className={classes.textField}
value={wifiSettings.hostname}
onChange={handleValueChange('hostname')}
margin="normal"
/>
<FormControlLabel className={classes.checkboxControl}
control={ control={
<Checkbox <Checkbox
value="static_ip_config" value="static_ip_config"
@ -145,82 +145,82 @@ class WiFiSettingsForm extends React.Component {
label="Static IP Config?" label="Static IP Config?"
/> />
{ {
wifiSettings.static_ip_config && wifiSettings.static_ip_config &&
<Fragment> <Fragment>
<TextValidator <TextValidator
validators={['required', 'isIP']} validators={['required', 'isIP']}
errorMessages={['Local IP is required', 'Must be an IP address']} errorMessages={['Local IP is required', 'Must be an IP address']}
name="local_ip" name="local_ip"
label="Local IP" label="Local IP"
className={classes.textField} className={classes.textField}
value={wifiSettings.local_ip} value={wifiSettings.local_ip}
onChange={handleValueChange('local_ip')} onChange={handleValueChange('local_ip')}
margin="normal" margin="normal"
/> />
<TextValidator <TextValidator
validators={['required', 'isIP']} validators={['required', 'isIP']}
errorMessages={['Gateway IP is required', 'Must be an IP address']} errorMessages={['Gateway IP is required', 'Must be an IP address']}
name="gateway_ip" name="gateway_ip"
label="Gateway" label="Gateway"
className={classes.textField} className={classes.textField}
value={wifiSettings.gateway_ip} value={wifiSettings.gateway_ip}
onChange={handleValueChange('gateway_ip')} onChange={handleValueChange('gateway_ip')}
margin="normal" margin="normal"
/> />
<TextValidator <TextValidator
validators={['required', 'isIP']} validators={['required', 'isIP']}
errorMessages={['Subnet mask is required', 'Must be an IP address']} errorMessages={['Subnet mask is required', 'Must be an IP address']}
name="subnet_mask" name="subnet_mask"
label="Subnet" label="Subnet"
className={classes.textField} className={classes.textField}
value={wifiSettings.subnet_mask} value={wifiSettings.subnet_mask}
onChange={handleValueChange('subnet_mask')} onChange={handleValueChange('subnet_mask')}
margin="normal" margin="normal"
/> />
<TextValidator <TextValidator
validators={['isOptionalIP']} validators={['isOptionalIP']}
errorMessages={['Must be an IP address']} errorMessages={['Must be an IP address']}
name="dns_ip_1" name="dns_ip_1"
label="DNS IP #1" label="DNS IP #1"
className={classes.textField} className={classes.textField}
value={wifiSettings.dns_ip_1} value={wifiSettings.dns_ip_1}
onChange={handleValueChange('dns_ip_1')} onChange={handleValueChange('dns_ip_1')}
margin="normal" margin="normal"
/> />
<TextValidator <TextValidator
validators={['isOptionalIP']} validators={['isOptionalIP']}
errorMessages={['Must be an IP address']} errorMessages={['Must be an IP address']}
name="dns_ip_2" name="dns_ip_2"
label="DNS IP #2" label="DNS IP #2"
className={classes.textField} className={classes.textField}
value={wifiSettings.dns_ip_2} value={wifiSettings.dns_ip_2}
onChange={handleValueChange('dns_ip_2')} onChange={handleValueChange('dns_ip_2')}
margin="normal" margin="normal"
/> />
</Fragment> </Fragment>
} }
<Button variant="contained" color="primary" className={classes.button} type="submit"> <Button variant="contained" color="primary" className={classes.button} type="submit">
Save Save
</Button> </Button>
<Button variant="contained" color="secondary" className={classes.button} onClick={onReset}> <Button variant="contained" color="secondary" className={classes.button} onClick={onReset}>
Reset Reset
</Button> </Button>
</ValidatorForm> </ValidatorForm>
: :
<div className={classes.loadingSettings}> <div className={classes.loadingSettings}>
<Typography variant="h4" className={classes.loadingSettingsDetails}> <Typography variant="h4" className={classes.loadingSettingsDetails}>
{errorMessage} {errorMessage}
</Typography> </Typography>
<Button variant="contained" color="secondary" className={classes.button} onClick={onReset}> <Button variant="contained" color="secondary" className={classes.button} onClick={onReset}>
Reset Reset
</Button> </Button>
</div> </div>
} }
</div> </div>
); );
} }

View File

@ -46,7 +46,7 @@ void APSettingsService::stopAP() {
Serial.println("Stopping captive portal"); Serial.println("Stopping captive portal");
_dnsServer->stop(); _dnsServer->stop();
delete _dnsServer; delete _dnsServer;
_dnsServer = NULL; _dnsServer = nullptr;
} }
Serial.println("Stopping software access point"); Serial.println("Stopping software access point");
WiFi.softAPdisconnect(true); WiFi.softAPdisconnect(true);

View File

@ -69,14 +69,14 @@ void ArduinoJsonJWT::parseJWT(String jwt, JsonDocument &jsonDocument) {
return; return;
} }
// must have signature of correct length // must have signature of correct length
int signatureDelimieterIndex = jwt.length() - JWT_SIG_SIZE - 1; int signatureDelimiterIndex = jwt.length() - JWT_SIG_SIZE - 1;
if (jwt.lastIndexOf('.') != signatureDelimieterIndex) { if (jwt.lastIndexOf('.') != signatureDelimiterIndex) {
return; return;
} }
// signature must be correct // signature must be correct
String signature = jwt.substring(signatureDelimieterIndex + 1); String signature = jwt.substring(signatureDelimiterIndex + 1);
jwt = jwt.substring(0, signatureDelimieterIndex); jwt = jwt.substring(0, signatureDelimiterIndex);
if (sign(jwt) != signature){ if (sign(jwt) != signature){
return; return;
} }
@ -115,7 +115,7 @@ String ArduinoJsonJWT::encode(const char *cstr, int inputLen) {
String value = String(buffer); String value = String(buffer);
// remove padding and convert to URL safe form // remove padding and convert to URL safe form
while (value.charAt(value.length() - 1) == '='){ while (value.length() > 0 && value.charAt(value.length() - 1) == '='){
value.remove(value.length() - 1); value.remove(value.length() - 1);
} }
value.replace('+', '-'); value.replace('+', '-');

View File

@ -109,7 +109,7 @@ public:
} }
virtual void handleRequest(AsyncWebServerRequest *request) override final { virtual void handleRequest(AsyncWebServerRequest *request) override final {
if(_onRequest) { if(_onRequest) {
if (request->_tempObject != NULL) { if (request->_tempObject != nullptr) {
DynamicJsonDocument _jsonDocument(_maxContentLength); DynamicJsonDocument _jsonDocument(_maxContentLength);
DeserializationError err = deserializeJson(_jsonDocument, (uint8_t*)(request->_tempObject)); DeserializationError err = deserializeJson(_jsonDocument, (uint8_t*)(request->_tempObject));
if (err == DeserializationError::Ok) { if (err == DeserializationError::Ok) {
@ -127,10 +127,10 @@ public:
virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) override final { virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) override final {
if (_onRequest) { if (_onRequest) {
_contentLength = total; _contentLength = total;
if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) { if (total > 0 && request->_tempObject == nullptr && total < _maxContentLength) {
request->_tempObject = malloc(total); request->_tempObject = malloc(total);
} }
if (request->_tempObject != NULL) { if (request->_tempObject != nullptr) {
memcpy((uint8_t*)(request->_tempObject) + index, data, len); memcpy((uint8_t*)(request->_tempObject) + index, data, len);
} }
} }

View File

@ -31,7 +31,7 @@ class AsyncJsonWebHandler: public AsyncWebHandler {
AsyncJsonWebHandler() : AsyncJsonWebHandler() :
_method(HTTP_POST|HTTP_PUT|HTTP_PATCH), _method(HTTP_POST|HTTP_PUT|HTTP_PATCH),
_onRequest(NULL), _onRequest(nullptr),
_maxContentLength(ASYNC_JSON_REQUEST_DEFAULT_MAX_SIZE), _maxContentLength(ASYNC_JSON_REQUEST_DEFAULT_MAX_SIZE),
_uri() {} _uri() {}

View File

@ -40,7 +40,7 @@ void OTASettingsService::writeToJsonObject(JsonObject& root) {
void OTASettingsService::configureArduinoOTA() { void OTASettingsService::configureArduinoOTA() {
if (_arduinoOTA){ if (_arduinoOTA){
delete _arduinoOTA; delete _arduinoOTA;
_arduinoOTA = NULL; _arduinoOTA = nullptr;
} }
if (_enabled) { if (_enabled) {
Serial.println("Starting OTA Update Service"); Serial.println("Starting OTA Update Service");

View File

@ -37,11 +37,9 @@ class Authentication {
boolean _authenticated; boolean _authenticated;
public: public:
Authentication(User& user): _user(new User(user)), _authenticated(true) {} Authentication(User& user): _user(new User(user)), _authenticated(true) {}
Authentication() : _user(NULL), _authenticated(false) {} Authentication() : _user(nullptr), _authenticated(false) {}
~Authentication() { ~Authentication() {
if (_user != NULL){ delete(_user);
delete(_user);
}
} }
User* getUser() { User* getUser() {
return _user; return _user;