Controlling Access to Serial Service on NRF

Posted on
  • I'd like to secure the serial service so that it's only available to connect to within a minute or so of powering on Espruino. The idea is to secure the javascript if someone doesn't have access to power cycling the device or pressing a physical button. Is it possible to disable this service or possibly change the device to non-connectable after a minute of powering on?

  • you mean the bluetooth console? there are several ways, check http://www.espruino.com/BLE+Security
    Also I have somewhere a variant of code mentioned there that dynamically creates whitelist of allowed devices. You basically need to hold button first time you connect to allow connection from new device and adding to whitelist for next time otherwise it will refuse the connection. Will search for it and post it.

  • @fanoush thanks for the link. Lots of good options there, somehow missed that in the documentation. Will probably go with the changing the connectable option to false after a minute of pressing a button or powering up.

  • Here is snippet of code I use

    NRF.whitelist=[];
    NRF.on('connect',function(addr) {
      if (!NRF.whitelist.includes(addr)){
        if (BTN1.read()){ // add to whitelist when button is held while connecting
          NRF.whitelist.push(addr);
          vibrate(1,1,100,0);
        } else
            NRF.disconnect();
      }
      NRF.connection = { addr: addr };
      NRF.connected=true;
      NRF.setRSSIHandler((rssi)=>{NRF.connecti­on.RSSI=rssi;});
    });
    
    NRF.on('disconnect',function(reason) {
      NRF.connected=false;
      NRF.connection = {};
      NRF.lastReason=reason; // google BLE hci status codes
    });
    

    It also vibrates on connection (my custom code) and maintains active connection with rssi value as extra NRF object properties, also on disconnect it keeps the reason. This code is not needed for this simple whitelisting and can be removed.

  • Thanks, this is great!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Controlling Access to Serial Service on NRF

Posted by Avatar for noahneibaron @noahneibaron

Actions