Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Entwicklung
    4. Adapter Passwort entschlüsseln

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Adapter Passwort entschlüsseln

    This topic has been deleted. Only users with topic management privileges can see it.
    • 6
      652145 last edited by

      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();
      }
      
      UncleSam 1 Reply Last reply Reply Quote 0
      • UncleSam
        UncleSam Developer @652145 last edited by

        @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).

        6 1 Reply Last reply Reply Quote 0
        • 6
          652145 @UncleSam last edited by

          @unclesam Deine Änderungen haben auf Anhieb funktioniert.

          Vielen Dank für die schnelle Hilfe.

          1 Reply Last reply Reply Quote 1
          • Meistertr
            Meistertr Developer last edited by

            @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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            Support us

            ioBroker
            Community Adapters
            Donate

            520
            Online

            31.9k
            Users

            80.1k
            Topics

            1.3m
            Posts

            3
            4
            359
            Loading More Posts
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes
            Reply
            • Reply as topic
            Log in to reply
            Community
            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
            The ioBroker Community 2014-2023
            logo