Skip to content

Commit

Permalink
* (bluefox) Corrected error with no credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Aug 16, 2022
1 parent 88e06df commit 2937c69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Some kind of WAF/proxy/entry Server should be put before ioBroker. (e.g. nginx i
### **WORK IN PROGRESS**
-->
## Changelog
### 1.2.0 (2022-08-16)
### **WORK IN PROGRESS**
* (bluefox) Corrected error with no credentials
* (bluefox) Added JSON config and made refactoring
* (atl285) Corrected handling of SSL certificates

Expand Down
12 changes: 0 additions & 12 deletions io-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@
"name": "geofency",
"version": "1.2.0",
"news": {
"1.2.0": {
"en": "Added JSON config and made refactoring\nCorrected handling of SSL certificates",
"de": "Hinzugefügt JSON config und gemacht Refactoring\nKorrigierte Handhabung von SSL-Zertifikaten",
"ru": "Добавил конфиг JSON и сделал рефакторинг\nИсправлена обработка SSL сертификатов",
"pt": "Adicionado JSON config e feito refactoring\nManuseio correto de certificados SSL",
"nl": "_\nVertaling:",
"fr": "Ajout de la configuration JSON et refactoring\nManipulation corrigée des certificats SSL",
"it": "Aggiunto JSON config e fatto refactoring\nGestione corretta dei certificati SSL",
"es": "Añadido JSON config y hecho refactoring\nManejo corregido de certificados SSL",
"pl": "Added JSON konfiguje i dostosowuje do regeneracji\nPoprawne traktowanie certyfikatów SSL",
"zh-cn": "增加联合协商会,并重新准备\n职业证书的处理"
},
"1.1.1": {
"en": "Prevent warning logs for newly added states in last release",
"de": "Warnungsprotokolle für neu hinzugefügte Zustände in der letzten Version verhindern",
Expand Down
39 changes: 18 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,26 @@ function requestProcessor(req, res) {
const auth = req.headers.authorization; // auth is in base64(username:password) so we need to decode the base64
adapter.log.debug(`Authorization Header is: ${JSON.stringify(auth)}`);

let username = '';
let password = '';
let request_valid = true;
if (auth && checkUser.length > 0 && checkPass.length > 0) {
const tmp = auth.split(' '); // Split on a space, the original auth looks like "Basic Y2hhcmxlczoxMjM0NQ==" and we need the 2nd part
const buf = new Buffer(tmp[1], 'base64'); // create a buffer and tell it the data coming in is base64
const plain_auth = buf.toString(); // read it back out as a string

adapter.log.debug(`Decoded Authorization ${plain_auth}`);
// At this point plain_auth = "username:password"
const creds = plain_auth.split(':'); // split on a ':'
username = creds[0];
password = creds[1];
if (username !== checkUser || password !== checkPass) {
adapter.log.warn('User credentials invalid');
request_valid = false;
let requestValid = true;
if (checkUser && checkPass) {
if (!auth) {
adapter.log.warn('Authorization Header missing but user/pass defined');
requestValid = false;
} else {
const tmp = auth.split(' '); // Split on a space, the original auth looks like "Basic Y2hhcmxlczoxMjM0NQ==" and we need the 2nd part
const plainAuth = Buffer.from(tmp[1], 'base64').toString(); // create a buffer and tell it the data coming in is base64

adapter.log.debug(`Decoded Authorization ${plainAuth}`);
// At this point plainAuth = "username:password"
const [username, password] = plainAuth.split(':'); // split on a ':'
if (username !== checkUser || password !== checkPass) {
adapter.log.warn('User credentials invalid');
requestValid = false;
}
}
}
/*else {
adapter.log.warn("Authorization Header missing but user/pass defined");
request_valid = false;
}*/
if (!request_valid) {

if (!requestValid) {
res.statusCode = 403;
res.end();
return;
Expand Down

0 comments on commit 2937c69

Please sign in to comment.