понедельник, 19 декабря 2016 г.

Automatically respawning socat.

When user disconnects from socat the process terminates, so you have to restart it.
To automate this process, you can use /etc/inittab.


Here
2345 -- is enumeration of runlevels for which process is started,
s1 -- is a unique sequence of 1-4 characters which identifies an entry in inittab.

This socat configuration is used to provide access to serial port (UART / RS-485) over TCP/IP.

воскресенье, 20 ноября 2016 г.

Using Makefile with MSVC on example of libsqlite3_unicode

Cygwin Makefile can be used for building C programs with Visual Studio C compiler in simple regular way without .sln files.

Here I have an examaple on GitHub: https://github.com/Zensey/sqlite3_unicode
It is an minimized extension w/o external dependencies, which adds support of Unicode to sqlite3 used for search and sort operations with non-latin strings.

To build this extension under Windows platform simply run make in Cygwin terminal or run mk.cmd. Below you can see how this Makefile is arranged. Note, that variable M is used to set target architecture of executable object.


вторник, 8 ноября 2016 г.

Setup Syncthing as a service on Windows

To setup and start Syncthing as a service:
- download Syncthing, unpack
- download nssm.exe and put it into directory of syncthing
- put syncthing-svc-setup-win32.bat script into directory of syncthing
- run syncthing-svc-setup-win32.bat as Administrator

понедельник, 3 октября 2016 г.

How to enumerate serial ports using Setup API (win32)

For me using setupapi is the most strait-forward method to retrieve a list of serial ports on Windows.
I should note, that this code works well on XP and higher.



Example of output:

I'm going to offer this code to guys of node-serialport, because current method doesn't work well on some setups with antivir.


Update: The patch is ready https://github.com/Zensey/node-serialport/commit/b4c8e830d248c4f7e3be0fd0d2cd56a18159f2d9


References:
1. https://social.msdn.microsoft.com/Forums/vstudio/en-US/2555943e-0c69-4357-a85b-d6540bcaaf84/using-setupapi-to-return-all-guiddevclassdisplay?forum=vcgeneral
2. http://stackoverflow.com/a/3439805
3. https://gist.github.com/Zensey/7bd7781a28d6be306be5cdd70539dc65

SSH over TLS/SSL

This method is appliable to situation when you are at restricted network where connection to external ssh is not allowed. In addition to interactive ssh connect to server you can setup persistent reverse tunnel to server in order to login from server to client.

On server:

Install stunnel:

$ sudo apt-get install stunnel4

$ openssl genrsa 1024 > stunnel.key
$ openssl req -new -key stunnel.key -x509 -days 1000 -out stunnel.crt
$ cat stunnel.crt stunnel.key > stunnel.pem

$ sudo mv stunnel.pem /etc/stunnel/


Edit stunnel config file: /etc/stunnel/stunnel.conf

^where 1.1.1.1 -- is your server external ip.

Also edit /etc/default/stunnel4. Set param Enabled=1
Then start stunnel4 service.

On client:

Install socat:
$ sudo apt-get install socat

Add to file .ssh/config


Connect to your server:
$ ssh user@1.1.1.1

Reverse tunnel with AutoSSH:

First of all add user without shell:

$ sudo useradd -m -s /bin/false autossh

Now login, make a new key and copy it to the server:

$ sudo su -s /bin/bash autossh
autossh@pc:...$ cd ~
autossh@pc:~$ ssh-keygen
autossh@pc:~$ ssh-copy-id -i .ssh/id_rsa.pub remote@1.1.1.1

Also add this to .ssh/config of user autossh:


To start reverse tunnel execute:
To auto-start reverse tunnel during system start add to /etc/rc.local:

Now you can test your reverse tunnel from server:
$ ssh -p 5001 user@localhost


пятница, 5 августа 2016 г.

GOST 28147-89 cypher in JavaScript

I'd like to indroduce you my implementation of GOST 28147-89 cypher also known as Magma in JavaScript.

This cypher is used in "Carrdex IMS", an Access Contol System produced by Carddex LLC, to verify and protect identification data of MIFARE proximity cards.

My implementation is pretty small in size, but has support of Cipher Feedback Mode. Its overall 100 lines of source code and has no dependencies.

Below follows an example of how you can use it.