NEWS
Adapter Passwort entschlüsseln
-
Hallo Zusammen,
Ich finde den ioBroker absolut super cool.
Nun möchte ich gerne mal versuchen, einen eigenen Adapter zu schreiben.
Ich bin blutiger Anfänger in der Adapterentwicklung.Der Adapter soll im Mode "schedule" laufen.
Die Adapterkonfig beinhaltet unter anderem ein Passwort das ich verschlüsselt speichere, was soweit auch funktioniert.
Nun muss das Passwort beim Aufruf des Adapters entschlüsselt werden.
Dies gelingt mir im Moment nicht, deshalb die Frage an euch Experte hier.
Wie müsste die Anpassung in der main.js sein, damit mir das Entschlüssen gelingt?
Inhalt der main.js:
* jshint -W097 */ /* jshint strict: false */ /* jslint node: true */ 'use strict'; const utils = require('@iobroker/adapter-core'); const adapterName = require('./package.json').name.split('.').pop(); class modeshedule extends utils.Adapter { constructor(options) { super({ ...options, name: adapterName, }); this.killTimeout = null; this.on('ready', this.onReady.bind(this)); this.on('unload', this.onUnload.bind(this)); } // Fuktion um das Passwort zu entschlüssen function decrypt(key, value) { let result = ""; for (let i = 0; i < value.length; ++i) { result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i)); } this.log.debug("password decrypt ready"); return result; } async onReady() { this.log.info("onReady wird aufgerufen"); this.getForeignObject("system.config", (err, obj) => { if (obj && obj.native && obj.native.secret) { //noinspection JSUnresolvedVariable this.config.password = decrypt(obj.native.secret, this.config.password); } else { //noinspection JSUnresolvedVariable this.config.password = decrypt("Zgfr56gFe87jJOM", this.config.password); } let pass = this.config.password; this.log.info("Passwort lautet : " + pass); this.killTimeout = setTimeout(this.stop.bind(this), 5000); } onUnload(callback) { try { if (this.killTimeout) { this.log.debug('clearing kill timeout'); clearTimeout(this.killTimeout); } this.log.debug('cleaned everything up...'); callback(); } catch (e) { callback(); } } } // @ts-ignore parent is a valid property on module if (module.parent) { // Export the constructor in compact mode /** * @param {Partial<ioBroker.AdapterOptions>} [options={}] */ module.exports = (options) => new modeshedule(options); } else { // otherwise start the instance directly new modeshedule(); } -
Hallo Zusammen,
Ich finde den ioBroker absolut super cool.
Nun möchte ich gerne mal versuchen, einen eigenen Adapter zu schreiben.
Ich bin blutiger Anfänger in der Adapterentwicklung.Der Adapter soll im Mode "schedule" laufen.
Die Adapterkonfig beinhaltet unter anderem ein Passwort das ich verschlüsselt speichere, was soweit auch funktioniert.
Nun muss das Passwort beim Aufruf des Adapters entschlüsselt werden.
Dies gelingt mir im Moment nicht, deshalb die Frage an euch Experte hier.
Wie müsste die Anpassung in der main.js sein, damit mir das Entschlüssen gelingt?
Inhalt der main.js:
* jshint -W097 */ /* jshint strict: false */ /* jslint node: true */ 'use strict'; const utils = require('@iobroker/adapter-core'); const adapterName = require('./package.json').name.split('.').pop(); class modeshedule extends utils.Adapter { constructor(options) { super({ ...options, name: adapterName, }); this.killTimeout = null; this.on('ready', this.onReady.bind(this)); this.on('unload', this.onUnload.bind(this)); } // Fuktion um das Passwort zu entschlüssen function decrypt(key, value) { let result = ""; for (let i = 0; i < value.length; ++i) { result += String.fromCharCode(key[i % key.length].charCodeAt(0) ^ value.charCodeAt(i)); } this.log.debug("password decrypt ready"); return result; } async onReady() { this.log.info("onReady wird aufgerufen"); this.getForeignObject("system.config", (err, obj) => { if (obj && obj.native && obj.native.secret) { //noinspection JSUnresolvedVariable this.config.password = decrypt(obj.native.secret, this.config.password); } else { //noinspection JSUnresolvedVariable this.config.password = decrypt("Zgfr56gFe87jJOM", this.config.password); } let pass = this.config.password; this.log.info("Passwort lautet : " + pass); this.killTimeout = setTimeout(this.stop.bind(this), 5000); } onUnload(callback) { try { if (this.killTimeout) { this.log.debug('clearing kill timeout'); clearTimeout(this.killTimeout); } this.log.debug('cleaned everything up...'); callback(); } catch (e) { callback(); } } } // @ts-ignore parent is a valid property on module if (module.parent) { // Export the constructor in compact mode /** * @param {Partial<ioBroker.AdapterOptions>} [options={}] */ module.exports = (options) => new modeshedule(options); } else { // otherwise start the instance directly new modeshedule(); }@652145 Du musst nichts selber verschlüsseln oder entschlüsseln.
Setze in der io-package.json einfach folgende Einträge:
"encryptedNative": ["meinFeldDasVerschlüsseltWerdenSoll"], "protectedNative": ["meinFeldDasVerschlüsseltWerdenSoll"],Ein Beispiel findest du hier.
Dazu solltest du noch die js-controller dependency auf minimum 3.1 setzen (wenn ich mich nicht irre - das fehlt im obigen Beispiel noch).
-
@652145 Du musst nichts selber verschlüsseln oder entschlüsseln.
Setze in der io-package.json einfach folgende Einträge:
"encryptedNative": ["meinFeldDasVerschlüsseltWerdenSoll"], "protectedNative": ["meinFeldDasVerschlüsseltWerdenSoll"],Ein Beispiel findest du hier.
Dazu solltest du noch die js-controller dependency auf minimum 3.1 setzen (wenn ich mich nicht irre - das fehlt im obigen Beispiel noch).
-
@UncleSam ist das richtig, wenn ich das über den js-Controller verschlüsseln lasse, dass beim download der config, dass das pw im klartext da steht? oder hab ich noch irgendwo einen fehler?
https://github.com/iobroker-community-adapters/ioBroker.wolf-smartset
Hey! Du scheinst an dieser Unterhaltung interessiert zu sein, hast aber noch kein Konto.
Hast du es satt, bei jedem Besuch durch die gleichen Beiträge zu scrollen? Wenn du dich für ein Konto anmeldest, kommst du immer genau dorthin zurück, wo du zuvor warst, und kannst dich über neue Antworten benachrichtigen lassen (entweder per E-Mail oder Push-Benachrichtigung). Du kannst auch Lesezeichen speichern und Beiträge positiv bewerten, um anderen Community-Mitgliedern deine Wertschätzung zu zeigen.
Mit deinem Input könnte dieser Beitrag noch besser werden 💗
Registrieren Anmelden