Dienstag, 29. August 2017

send encrypted files using certificates and OpenSSL

The whole process is separated in two steps, encrypt of the content at the sender using the receivers certificate and decrypt it at the receiver using the private key.

We start with two files, cert.pfx which is the PKCS#12 keystore with the certificate and secretfile.txt which holds some text content that should be kept secret.

Encrypt

If you have a certificate in an keystore, like PKCS#12, the first step is to extract the certificate that contains the public key.

# extract certificate -> certificate in cert.pem
openssl pkcs12 -in cert.pfx -nokeys -out cert.pem

Now do the encryption using the S/MIME functionality of OpenSSL, the result is a PKCS#7 file. We use the AES 256 cipher which is pretty safe.

# using pkcs#7 format, using the S/MIME option in OpenSSL
openssl smime -encrypt -aes256 -in secretfile.txt -outform pem -out secretfile.txt.p7 cert.pem



Decrypt

The receiver is the only one who holds the private key, so the only one who can decrypt the content. First we need to extract the private key from the keystore.

#extract private key from keystore -> private key in key.pem
openssl pkcs12 -in cert.pfx -nocerts -out key.pem -nodes

Decrypt the content using the private key.

# using pkcs#7 format, using the S/MIME option in OpenSSL
openssl smime -decrypt -aes256 -inform pem -in secretfile.txt.p7 -out secretfile_receiver.txt -inkey key.pem

Don't forget to keep the private key in a save place or simply delete it after using it.

Donnerstag, 3. August 2017

Install Node.js on Ubuntu 17.04

The Node.js version that comes with the standard Ubuntu repositories is quite outdated, at least when you think of the fast development cycles recently. But Node.js offers an additional repository to get the latest stable release. To install this a script is available that needs to be downloaded and executed. This is for the version 8 of node.

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

check the versions

nodejs --version
npm --version

Install Visual Studio Code on Ubuntu 17.04


Visual Studio Code is an awesome code editor, especially for web projects. Though it comes from Microsoft and the name implies it, this has nothing to do with Visual Studio as it is used for Windows development. It is rather based on Node.js and is lightweight and fast.

First I tried the installation using snap. This adds the latest version and also keeps it up-to-date

sudo snap install --classic vscode

Unfortunately the installation just installed the binary without doing any desktop integration. I was able to start it in bash with 

/snap/bin/vscode

But I do not like old style command line or better I don't want to keep all the commands in mind to start a desktop program.

So I downloaded it here https://code.visualstudio.com/insiders and installed it with



sudo dpkg -i code_1.14.2-1500506907_amd64.deb

sudo apt-get install -f

sudo apt-get update

This made a complete install with all the desktop integration.