Node.js Encrypted Lantronix XPort Comms

The Lantronix XPort is a popular embedded "device server" which is effectively an ethernet card for microcontrollers. It provides transparent ethernet connectivity to a serial device sonnected via a simple TTL USART.

There is a version of this device that supports 256-bit AES-CFB encryption and the protocol is quite simple, but the documentation is not easy to find and is marked confidential. It seems they'd prefer you use their binary libraries to mitigate support load, though they do have a FIPS certified implementation.

This code example shows how to make a connection to an XPort that has been configured for encryption with the same key. The XPort simply expects the first 16 bytes it receives on a fresh connection to be the IV it needs to setup decryption, then simply send CFB coded ciphertext. Done.

At the bottom is just a two way pipe to your console. It is a serial device after all.

'use strict';  
var crypto = require('crypto'),  
    duplexer = require('duplexer2'),
    net = require('net');

var key = new Buffer(  
var iv = crypto.randomBytes(16);

var cryptstream = crypto.createCipheriv('AES-256-CFB', key, iv);  
var decryptstream = crypto.createDecipheriv('AES-256-CFB', key, iv);

var socket = new net.Socket();

socket.connect({host: '', port: 10001});

socket.on('connect', function() {  
  console.log('connected, sending iv');
  // Send IV

  // Pipe streams
  let duplex = duplexer(cryptstream, decryptstream);