Openssl: The tool, not the lib – a mini-howto

January 8, 2008

OpenSSLDid you know that the tool OpenSSL which is shipped with the OpenSSL-distribution can do more than just create certificates of all kind for your webserver? It can also do other fancy stuff like calculating MD5-checksum or other digests. You can use it as a tool for encrypting or decrypting files. It can deal with encrypted S/MIME-emails or as a simple SSL-enabled TCP-client. And server!

I’m not going too much into detail and I won’t (and can’t) tell you about every nuance of this program, but there’s always the manualpage if you like to know more.

Introduction

You can use the program openssl in two modes. In interactive mode you get the openssl-prompt and can enter commands. You remain in that openssl-shell until you quit. The other mode is just giving it enough parameters on the command-line so that it does your work.

Here I show you a simple interactive session.

$ openssl
OpenSSL> md5
Hello, World!
(CTRL+D)

bea8252ff4e80f41719ea13cdf007273
OpenSSL> sha1 /etc/hosts
SHA1(/etc/hosts)= 9eae810b5ddc9de42768cf67a3d4c7486c7ed609
OpenSSL> enc -a -bf -e
enter bf-cbc encryption password: 123
Verifying - enter bf-cbc encryption password: 123
Oh Hi! I upgraded your Ram.
(CTRL+D)

U2FsdGVkX19127MRtfOvh9pU631VpV7Wc1loeOTpXWLGwX2raPBKJef8ONdcDYpd
OpenSSL> enc -a -bf -d
enter bf-cbc decryption password: 123
U2FsdGVkX19127MRtfOvh9pU631VpV7Wc1loeOTpXWLGwX2raPBKJef8ONdcDYpd
(CTRL+D)

Oh Hi! I upgraded your Ram.
OpenSSL> exit

Listing 1: Interactive OpenSSL session example. Text in italics is the user’s input.

In Listing 1 I showed you some of the features the openssl-program supports. MD5-checksumming of interactively entered text. SHA1-checksumming of files on the harddrive. ASCII-armoured Blowfish-encryption. Neat, eh?

Now for a more complex example-session on the command-line:

$ openssl md5 < /etc/hosts
09cff0c342cf543c82aa514e9edcf21b
$ openssl enc -aes-256-cbc -salt -a -e hosts.aes
enter aes-256-cbc encryption password: 123
Verifying - enter aes-256-cbc encryption password: 123
$ cat hosts.aes
U2FsdGVkX1+yYaXzHyDiGhX4Pqhesz1a73xy/w54fGN5FrVmjzXBc9ON1n3R3eqk
8kOMLO+GuHF9fj4GzIDVP+/JKQdsfiOdknSmxPno3f65jtgUQoYBjIv0rE8LMyiV
/i4gY8sGsRhHtqo+a/Udj1Kwu34QU5sL8BZR9GStp91TR8Z7nitd1Of66PK0mqUy
X96k6Cj6e0pYhqUHFoXZTBrDPUoCzoLKcRKDngtwr6ySOUJuFGaxaZZVNpnOfDhy
i1W7xJkY8AXMxuh7zB6nVO0RggXB0R+53CNOp2NXOpiO4xSIXSAIbCXj/NGzziWn
Ur1MpRNV/jmHIMNBe1RSpfrCYLkwX1naE1cHAYBC3+2f+gwpw8NmpvM1yZsGBatE
qDzhPwe3Q5X9vpcCYMl7oQ/ldXXKZQXV9GPM+SMPpuB6vZLgIuNY42AZ/sJXPw0V
kBqMN+jwIdjPilkuOmNkINV6K/3TuO895nB4DZtxovcIjtC4AoYgd+en9bMCB7aF
$ openssl enc -aes-256-cbc -salt -a -d < hosts.aes | \
openssl md5

enter aes-256-cbc decryption password: 123
09cff0c342cf543c82aa514e9edcf21b

Listing 2: An example command-line session using AES for encryption.

As you see, an interactive-session and regular invocation from the shell is no real difference. I’ll therefor only show the examples on the command-line.

Checksums and Message Digests

Supported digests-families: md, sha, others
Invocation: openssl dgst [-md5|-sha1|...]

Example 1: MD5-checkum of a file

$ openssl dgst -md5 < /etc/hosts
09cff0c342cf543c82aa514e9edcf21b

Example 2: SHA256-checksum of a file

$ openssl dgst -sha256 < /etc/hosts
63c001b38a72383a38b8f6b4f5ea3d7e45ca663d0723a4f2b61e054a1abddc38

Symmetric encryption/decryption

Supported cipher-families: AES, Blowfish, CAST, DES, RC
Invocation: openssl enc [-$cypher] [-a] [-e|-d] outfile

Example 3: Encryption and decryption using ASCII-armour and AES128

-a – causes openssl to create BASE64-encoded output rather than binary output
-e – set encryption mode
-d – set decryption mode
-aes128 – use AES 128 bit cipher

$ openssl enc -a -aes128 -e hosts.aes
enter aes-128-cbc encryption password: 123
Verifying - enter aes-128-cbc encryption password: 123
$ openssl enc -a -aes128 -d < hosts.aes
enter aes-128-cbc decryption password: 123
127.0.0.1 localhost.localdomain localhost

Use openssl as a simple SSL-client

Wouldn’t it be cool to have something like telnet, but speaks SSL? He? Just for testing? Yeah, that’d be neat.

Invocation: openssl s_client -connect ${host}:${port}

Example 4: Hitting an SSL-enabled webserver
Since this example is rather long, I’ve uploaded this listing: Downloading listing

There’s more to explore!

Hope you liked it. Why don’t you just know try to…

  • explore the RSA-commands and find out how to do encrypt, decrypt, sign and verify manually?
  • improvise a SSL-enabled webserver serving a single file using the s_server-command?
  • do funky md5/crypt/Apache password-hash stuff with the passwd-command?

Have fun!


Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 License.


Draft posting: Advanced ssh usage

February 22, 2007

(This article is a draft and work in progress. Expect changes in the next couple of hours. This note will be removed when the article is finished, however, I’ll send updates every now and then for online-review by friends. Comments by anyone are welcome. Please use the comment-function.)

Time for a more technical posting. In my work as an IT guy I realised quite a few times that advanced knowledge about ssh and how it’s working almost non-existant. People are still stuck the the good old “ssh user@host” and plaintext-authentication scheme they still know from rlogin and telnet. Time to clean up and show the people what ssh – especially OpenSSH and putty – can do. I know that there’re plenty of howto but they seem to be obscure for the general user-audience. So I give another try. Let’s go.

(Note: Other implementations of ssh besides OpenSSH and Putty – like F-Secure’s ssh-server for UNIX – are not covered here. Key-conversion can be a mess or at least it used to be when I was last using it on Solaris.)

0. Introduction

0.1 What’s this all about?

You might only know the usual ssh-stuff; means “ssh -l user remotehost” or probably “ssh user@remotehost“, which is equivalent. When it asks for a password you’d enter the password of the user “user” on the machine “remotehost“. You probably also heard of things like “public keys”, “tunnels”, “port forwarding”, “X forwarding” but you never got a hang on it. In this article I’m going to cover exactly those topics.

0.2 How’s this article organised?

In the first chapter I’m going to lose a couple of words about public-key encryption in general and how this applies to ssh. In the second chapter I’ll head over to tunnels and portforwarding. Although X-forwarding is basically the same, I’m going to put that in the third chapter. The fourth chapter will deal with the ssh-agent and finally, in the last chapter, I’m going to give some configuration hints of the ssh-demon.

1. Public keys, ssh and all the other crap

1.1 Why is the traditional authentication scheme spoiled?

Authentication? What means that? It means that the system you’re about to log on recognises – authenticates – you. In UNIX-system that means you have to give a username which exists in /etc/passwd, and a password which is stored – encrypted – in the file /etc/shadow.

The traditional username/password scheme has – in my opinion – three practical major disadvantages: If lots of people need to acces the same account – let’s say, “oracle“, “superad“, “informix” or “tsp99” – a lot of people need to be aware of the password-of-the-day. That’s, speaking of security, a bad idea. (1) Because a lot of people log on using that password the adminstrator of the system might be tempted to choose an easy password which is not so hard to remember. (2) Which leads to the second problem, that the password might be easy to guess. (3) The third problem arises: How do you tell someone the password on a safe channel? Phone conversations and unencrypted internet-communication is easy to tap.

How can we do this better? There’s an answer. Public key authentication.

1.2 Public key authentication

Public-what-the-heck you might think.What you probably know about encryption is “hey, I got this encryption-thing, if I want to encrypt something I give a secret password, give this password to my buddy so that he can decrypt it”. Fine. Problem (1) solved. Problem (2) can be solved with a complicated password. But problem (3) still exist: how to you tell your friend the secret password? You better do that in person, rather than on the phone.

So a couple of clever scientists invented the so called “Public Key Encryption Scheme“, also known as “Assymetric Encryption“. What does that mean? Example:

Alice and Bob, the famous protagonists in cryptography, both create two files on their computers. One file is called the private key, the other one is called the public key. If Alice and Bob want to communicate in private, encrypted, they exchange their public keys. So Alice gets Bob’s public key and Bob gets Alice’c public key. Alice and Bob keep their secret key – well secret. They never give them away. Never ever. Secret. You see?

Now comes the important point: Public Keys only encrypt. Secret Keys only decrypt. The consequence? If Alice wants to write an encrypted email to Bob, she takes her message to Bob and uses Bob’s public key to encrypt the message. She sends that encrypted message to Bob. Bob takes his Private Key and can decrypt Alice’s message. Bob’s secret key and public key form a keypair. Both keys are one-way-keys, designed to do that specific purpose.

So why are those keys files and not passwords you want to ask? There’s no need for a password. Since the public keys can nothing do but encrypt, Alice can upload her public key to some website (also known as keyserver in the GPG-world) so that anyone who wants to send her an encrypted email can just use that key. Only Alice, with her secret key, can decrypt the message. As an extra precaution Alice’s secret key is encrypted with a traditional symmetric-encryption-scheme using a passphrase she choses, so that if someone steals her private key from her computer can’t use it.

Fancy, don’t you think?

1.3 Public Keys and OpenSSH

So how does this all apply to ssh? Easy. Ssh can, additionally to the traditional UNIX-password, also make use of the Public Key Encryption. But it doesn’t really use that scheme for encryption, but rather for authentication!

How? Quite easy. Imagine you’re working for the TAC (technical assistance centre) of some big company and you want to access a customer’s oracle server. You’d need access to the user “oracle” and “root” in that case. The customer would be rather stupid to give you the passwords over the phone or via email for obvious reasons.

So, what do you do? Let’s say Alice works for GreatInnovations Ltd. and does service for Bob’s ScrewedCompany AG’s Oracle database. She needs access to the user “oracle”. Alice now creates a keypair on her laptop – a secret and a private key. Alice keeps the secret key on her laptop and sends the public key to ScrewedCompany AG.

In openssh (Alice’s computer is called “castor”):

Create a “DSA”-keypair and choses a passphrase:

alice@castor:~$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/alice/.ssh/id_dsa): <enter>
Enter passphrase (empty for no passphrase): blabla123
Enter same passphrase again: blabla123
Your identification has been saved in /home/alice/.ssh/id_dsa.
Your public key has been saved in /home/alice/.ssh/id_dsa.pub.
The key fingerprint is:
9e:36:f0:fd:9e:10:3d:00:b9:69:56:36:4c:20:da:e9 alice@castor
alice@castor:~$

Ok, now Alice created a keypair. Alice also notes down the fingerprint of her keypair. The fingerprint is unique to every keypair and Bob needs it to verify that the key Alice will send him is the correct key.

What files do we have by now? Let’s change to the directory ~alice/.ssh and check what’s there:

alice@castor:~$ cd .ssh
alice@castor:~/.ssh$ ls
id_dsa id_dsa.pub
alice@castor:~/.ssh$

So, we have two files. The file named id_dsa ist Alice’s secret key – protected by the passphrase blabla123 – and the public key named id_dsa.pub. How do those keys look like? Let’s have a look at those keys:

alice@castor:~/.ssh$ cat id_dsa
-----BEGIN DSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,B5EE64D31AC8CE4F

NQU9YWg2DKX8rToZ/TtaeEphGxADpVPxUQhnl9sFmDSZlne0dE1Mp7+S+xny9YjU
GiWaFIQLCFkdquc5uTigNoPrmZse8NG2djbtu8+rU7Vi3jYK8YvK7mROgUQSaJ2u
++TqlfHfW9zk2by2sbjpHPgMHQSud2ANIFVqGRYvUDJq8fTEB0AqodOsv5phl5WV
9s4dx6CrRvoinoiFfTwaI8F7gYQbJ9YvVcaMGxEEjmqwQQm5LCLRD3xOmNKefC03
REodEUcwnrvD+R2RE9ldHk28eh9/4CJHOTB1GWHez6NfbrjlZJACDXO5UjSqdPXn
hM/i8o+I7WOQ4iMSH8L0Zdyg4EATlXIc0rO3xIpTdFBNaG3V1A4ZnuL5HTGv68I6
74GtQntQwjQVCUOCvxBC0PQN+esC9rwJ6Fj/JSj+50TIkdV4worxUa3NjRg4AKwU
y37B0m/dWGHNnhr4G79TmUYlujriCfMdZ9zjizNae8pZyi696xvpDpRHoHIWsusR
nUmwLNDv50DcN2BukFrGShJ2tfcwYCB63ytgd9arEwd1grpEiFGLVM2YN8XpO/py
aVLiNcV9z+9eFRLuEwX4mw==
-----END DSA PRIVATE KEY-----

alice@castor:~/.ssh$ cat id_dsa.pub
ssh-dss AAAAB3NzaC1kc3MAAACBAIECqUDgpN/nvhAyS+5LftVt5Oa1U+I2tHeeYlq6rjl8dNDX8gkr
SsjHmJCnO5QwGUwW/Y6egfYW8HlKpDSHUciJyW6IyiriuTwvEmOTv42RP6+6IeJ1sIVcFhihCcDQ7QEX
7+aY44SgHD9k9nu+SDWkDV/gHStlXmh+Fx02zUYlAAAAFQDCY2xbkBj6H8eMeHusrI1hh68AWwAAAIBB
WHUqWdlHWFqN1eYDlJ7/VPl4EvprxgKV+BHslYCmlEtKY2JDYlQTmYP39Sy4J5XKlJyuGDPtalrDAFjJ
VrqezbkzZMP9jUIaa8GGSi4l4Lf5xbNijTQObbqn3f+PJf2CzTtrQrmm0dzPV/KQ0VxXq0VQd4wNTDp4
nPLmOwV57QAAAIB5OKAt+KtU8wiUJN5h6JcWFcO0LcBxXjyIHip/bvNlIhciwmpMbWmWHB3xtmJCV/ul
aGeKpH5U6mzh1E9grn7+x6aRPQcyZfyGs7MjqmsjvAtOGTsD0QPpzApYB0x1DMUz68fQarmiqvMVLEAa
Enu385aLE+0CeWMTrtbtzVLIaQ== alice@castor
alice@castor:~/.ssh$

You see, the keys are a lot of gibberish, but actually nothing Alice and Bob have to worry about.

Alice now sends the file id_dsa.pub – her public key – to her customer Bob, working for ScrewedCompany AG.

Now suppose the customer’s Oracle-server is called neelix and Alice should get access to the user oracle on this machine. The customer therefore logs into neelix as user oracle and copies Alice’s public key for the user oracle to ~oracle/.

Just assume the key was copied to the machine by some means (scp, copy&paste, never mind). Suppose Bob stored Alice’s public key under the name of “id_dsa.pub-alice“. The first thing Bob from ScrewedCompany AG has to do is verifying the fingerprint of Alice’s public key:

oracle@neelix:~$ ssh-keygen -l -f id_dsa.pub-alice
1024 9e:36:f0:fd:9e:10:3d:00:b9:69:56:36:4c:20:da:e9 id_dsa.pub-alice

Bob now compares all the number to what Alice told him what her fingerprint is. Note: Alice shouldn’t tell Bob the fingerprint in the same email as in the one she sent her public-key! Why? Because if someone pretended to be Alice he could send Bob his own, but false, public key – and if the fingerprint would be included, it would surely match! So Alice gives Bob a call and tells here the numbers.

Now that we know that Alice’s key Bob got is the same key Alice really sent, Bob can install Alice’s key so that she can work as user oracle on host neelix.

oracle@neelix:~$ mkdir .ssh
oracle@neelix:~$ chmod 700 .ssh
oracle@neelix:~$ cat id_dsa.pub-alice >> .ssh/authorized_keys

(Note: The mkdir and chmod are only necessary if a directory .ssh didn’t yet exists. I assume it doesn’t since you’re reading this so this might be your first time)

Bob now installed Alice’s public key to the user oracle on the host neelix.

What now? Nothing! That’s it. Alice can now login to neelix as user oracle without actually knowing the password of user oracle; she only needs to know the passphrase of the secret key belonging to the public key Bob installed. Suppose Alice is logged in on machine castor as user alice and wants to log on as user oracle on host neelix:

alice@castor:~$ ssh oracle@neelix
The authenticity of host 'neelix (2001:5c0:8bf4::1)' can't be established.
RSA key fingerprint is 6d:50:18:85:f7:da:68:73:74:18:0b:9c:f9:e3:32:45.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'neelix,2001:5c0:8bf4::1' (RSA) to the list of known hosts.
Enter passphrase for key '/home/alice/.ssh/id_dsa': blabla123
Linux neelix 2.6.8-3-686-smp #1 SMP Thu Sep 7 04:39:15 UTC 2006 i686 GNU/Linux
oracle@neelix:~$

The question “The authenticity of host 'neelix (2001:5c0:8bf4::1)' can't be established.” occurs only the first time a user connects to a certain host. You probably know that. Type “yes” to acknowledge the fact.

Then the host asks for the passphrase. Important: This is the passphrase Alice gave when she created the keypair. This is not the UNIX-password of the user oracle on the host neelix! Don’t forget that! If you just thought “what the hell?” please reread the chapter, you fundamently got it wrong.

Voila! That’s it. No magic. No bells, no whistles.

Summary:

  1. Alice creates a keypair and sends her public key to Bob: "ssh-keygen -t dsa"
  2. Bob verifies the fingerprint of Alice’s public key: "ssh-keygen -f id_dsa.pub-alice -l"
  3. Bob installs the public key of Alice to the file ~oracle/.ssh/authorized_keys by just appending it

Using public key isn’t diffucult. It is easy, although more work than telling someone a password on the phone. But you gain so much additional security that it’s worth it! Both in private and corporate environments.

Useful hint: Did you know…?

That there’s a clever little program called ssh-copy-id which automates the process of setting up the file authorized_keys on the remote host? Suppose the user root on host neelix has a copy of Alice’s public-key, knows the password of user oracle and wants to install it to the user oracle. Example:

neelix:~# ssh-copy-id -i id_dsa.pub-alice oracle@neelix
10
Password: <UNIX password for user oracle>
Now try logging into the machine, with "ssh 'oracle@neelix'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
neelix:~#

Alice know can log into oracle’s account on neelix. Additional node: ssh-copy-id works from everywhere on the network and can be used for both, plaintext (password) and public-key authentication.

What might go wrong:

You should be aware of a few things, things might might go wrong. If you look at a public key you might notice – or not – that the complete key in the file id_dsa.pub is all in one single line of text. If you copy&paste the key to the authorized_keys files make sure that you don’t introduce linefeeds or carriage-returns accidently. This will screw up the whole authorized_keys file. F-Secure’s ssh-client implementation for Windows is notoriously infamous for adding CR/LFs automagically.

1.4 Creating and using public-keys with putty for Windows

We now know how to create, install and use ssh-keys in UNIX-environments using OpenSSH. Time to explain how a Windows-client can create and use key-pairs.

Putty is a well known, stable and popular free ssh-client implemtation for Windows-systems. Putty can look back on to a long and successful history. From all the people I know who run Windows and use ssh, Putty is their ssh-client of choice. Putty is pretty lightweight, with a small memory-footprint and just easy to use; it also has a lot of very interesting and easy to use features, like tunneling ssh through http-proxies and an easy way to setup tunnels and portforwarding.

In this part of the article I’m going to use the programs putty and puttgen. They both can be downloaded for free from the Putty-website.

1.5 Generating key-pairs with puttgen

We start with firing up the program puttygen. The start-screen looks like that:

Puttygen Mainscreen

Now Alice wants to create a new keypair. Alice want’s a DSA-key with the size of 1024 bit – a sensible default, but not the default of Putty, it still uses RSA-keys as the default. In the parameter-section Alice checks the button “SSH-2 DSA” and presses the button “Generate”. A new screen appears asking Alice to wiggle around her mousebutton aboce the windows. Puttgen uses the mouse-movements to get some random data – that’s better than the pseudo-random-number generator Windows uses:

Puttygen Generate Keypair

After wiggleing the mouse around for a couple of times, the key is generated, resulting in that screen:

Puttygen New Key

What next? First: Alice has to write down the fingerprint of her key for future reference. Now she has to give her passphrase – we stick with blabla123 – she enters it into the fields “Key passphrase” and “Confirm passphrase”. Next she has to save both, the public-key and private-key, to some location on her harddrive, pressing the buttons “Save public key” and “Save private key” accordingly – chose a location which is safe – means only Alice can access it – and not to some network-share or into a directory which everyone on the system can access. “My Documents” might be a good place.

Now comes the “ugly” part; not really ugly, but not self-explaining either. Putty uses, for the public-keys it generates, a different format then the one OpenSSH on the server would expect (means: the key is not in one line of text, as I alredy pointed out in the last chapter). That’s why the public-key is displayed on the screen, luckily denoted with the text “Public key for pasting into OpenSSH authorized_key file“. So, do it – mark all the text in that textarea, copy it, open Notepad, make sure “Format -> Word Wrap” is disabled , paste it, do not attempt to modify anything of the text and save it to a file. This is the public-key Alice has to send to Bob, not anything else.

It’s a bit dodgy, but it works – if you know that you need to do it exactly that way.

Note:Conversions -> Export OpenSSH key” exports the private-key to OpenSSH-format, not the public-key. The public-key has to be saved manually by the methode described above. This command is useful if Alice wants to use the same key-pair also on her UNIX-workstation, if she prefers not to have different keys.

1.6 Using ssh key-pairs with putty

I assume you’ve worked with putty before. So fire up Putty, load or create the data for the connection to oracle@neelix and head straigt to the menu “Connection -> SSH -> auth”. There you see, in the group “Authentication parameters”, the textbox “Private key file for authentication”. Hit “Browse” and chose the private-key (the one with the suffix .ppk) you’ve created earlier with Puttygen:

Putty Connection -> SSH -> auth

Then just press “Open” or go back to the main-menu to save the configuration first. First putty will ask you for the username, say “oracle”, but then – instead of asking for a password – it asks you for a passphrase. Enter the passphrase you gave earlier when creating the key, Voila:

Putty Auth
So much for how to use putty and public-key authentication. It’s not complicated at all.

2. Tunneling

What’s tunneling? Technically speaking it means to forward remote ports to local ports, or local port to forward to remote ports.

What does that mean in plain english? Imagine Alice has a mysql-database running on castor. She uses it as her internal-troubleticket-system for her company GreatInnovations Ltd. – obvisioully she’s not goint o give anyone direct access to her database via direct socket-connects to the database-server – her server only listens to localhot – means 127.0.0.1. Good for her! A security-lesson was learned.

Now Alice is working in the datacenter of ScrewedCompany AG, doing some emergency-work on the customer’s system. She sitting in front of the cluster-console of her customer’s productive system but now realizes that she needs to query her database. What possibilities does she have? The easiest way would be to login to her database-server via ssh, fire up “mysql” and enter here queries. But what a lame example would that make, we were about to talk about tunnels, weren’t we? :) So Alice instead wants to use the local mysql-program on the customer’s server, directly connecting to the database in GreatInnovations Ltd.’s datacenter. But for security-reasons the server doesn’t listen on it’s public IP-address, as I already pointed out earlier.

So Alice needs to find a way to somehow get a connection from the customer’s machine to her database serverwithout compromising security. There’s a way. A simple way using ssh.

2.1 Getting remote services to your local machine

(tbd)

2.2 Getting local services to a remote machine

(tbd)

2.3 Combinations of all above

(tbd)


Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 License.


Tech Tags:

TOR howto: Accessing Freenode Via Tor step-by-step for Windows

October 11, 2006

TOR logoA couple of people onthe freenode.net IRC-network asked today the same question: How to get access to freenode using TOR according to their instructions. The real problem is not the methode, but the way how to get to that point. I decided to create a small step-by-step howto.

Overview

To gain access to Freenode using TOR the Freenode-staff wants TOR-users to use their hidden service which can only be accessed after creating an account there. To get an account you need to have a GPG keypair. I’ll describe step by step how to create a keypair.

I got one problem with this website: It is notoriously clipping all pictures to a certain width – if the screenshot isn’t clearly visible, vlick on it to see the complete screenshot. Sorry for that.

Step 1: Download GnuPG for Windows and install it

First, you need to grab the GnuPG software: ftp://ftp.gnupg.org/gcrypt/binary/gnupg-w32cli-1.4.5.exe

After downloading it, open the file and follow the installation instructions, clicking next, next next, peck, peck (“even a chicken can install Debian”). When asked for the path, accept the default or note down where you installed it:

GPG Install Screenshot
Finish the installation through clicking “Next” mucho times. All should be set now.

Step 2: Create a GPG keypair on the Windows-commandline

Now we’re about to create a keypair. This is quite simple, but involves a bit of typing:

  1. Press Start
  2. Choose “Run”
  3. Type cmd

CMD Start
After pressing “OK”, the Windows commandline appears. There you have to change to the correct directory through typing "cd C:\Program Files\GNU\GnuPG". If you did it correctly, typing the command “cd” should yield the result "C:\Program Files\GNU\GnuPG":

CMD Screenshot

Voilá! Now it’s time to create the keypair. To do this, you enter the command "gpg --gen-key" and follow the instructions step-by-step, accepting the defaults, choosing a reasonably secure passphrase to encrypt your private key. Note note or better remember your passphrase, you’ll need it:

GPG Instructions

Now you created a keypair which is appropriate to use for the Freenode IRC-network. Do not close that window.

Step 3: Create a signed password hash inside the IRC-server

I assume that you already have access to the Freenode-network and that you just want to do “the real thing”. Now, inside your IRC-client, create a hash with the command "/quote makepass <password>" where <password> is your choosen password. I take "schwubbdiwupp" as an example:

IRC

Note down the complete hash, whith all dollar- and slash-signs. Even better, copy it to the Windows Clipboard, you need it in the next step.

Step 4: Get Freenode’s key from the keyserver

Since you need to encrypt to the Freenode-staff and sign the message with your key, you need the GPG-key opf the freenode-staff. Just download it with the command: "gpg --keyserver pgpkeys.pca.dfn.de --recv-keys 035D6B1D"

Import Freenode GPG key

Step 5: Sign your nickname with the hash

The next step signs the hash you just created and your nickname with the GPG private key you created in step 2. Go back to the window where GPG was and enter the following command, replacing my nickname "yalla" and my has "$1$8HQdxmzs$MiTG6Spl1HPb5iB4iIdmb/" with your hash:
echo "yalla $1$8HQdxmzs$MiTG6Spl1HPb5iB4iIdmb/" | gpg --gnupg -sea -r 035D6B1D"

It will first ask you for the passphrase you used in step 2 to create your keypair; enter it. Next it will tell you something like: “It is NOT certain that the key belongs to the person named in the user ID. If you *really* know what you are doing, you may answer the next question with yes.” – you can safely say “yes” here:

Sign nickname and hash, encrypt to freenode’s key

Step 6, prepare email to Freenode:

Copy everything starting from "-----BEGING PGP MESSAGE-----" until "-----END PGP MESSAGE-----" to a file and save it to a safe location. This is the encrypted message with your nickname and hash which you will be sending to Freenode; but you also have to include your public key. This is done by typing the command "gpg --armor --export your@email.address":

Public Key

Copy and paste this output to a safe location.

Step 7, last step:

No write an email to the Freenode-staff including your public key and encrypted message you’ve created in step 5 and 6.

Conclusion:

OK, this is the hard way to do it, but it’s the prefered way. Hope that helps.


Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 License.


Tech Tags:


A few privacy notes regarding TOR

September 29, 2006

TOR logoI had a couple of discussions in the last weeks with various people about anonymity and privacy on the internet. Since TOR is a tool to maintain privacy it deserves some words how avoid user-errors you could make while using TOR. Interestingly those errors are not only of technical, but also of human/social nature.

I’d like to point out a few Do’s and Don’ts and points you should keep in mind when using the TOR-network.

Do’s:

  • Clear Private Data: Before and after using TOR flush your cache and delete all cookies. In Firefox you just need to press “CTRL+SHIFT+Del” or go to “Tools -> Clear Private Data”.
  • Call up links manually: If you visit a website where you find a link which you want to access with TOR, copy the link and insert it manually into the address-bar; this prevents a referer to be send to the host you want to visit. Again: Copy link; Clear Private Data; enable TOR; open new Tab; insert link.
  • Configure SOCKS correctly: If you use Firefox and a SOCKS-connection, be sure to set Firefox’s variable network.proxy.socks_remote_dns to true – if you forget that you’re leaking the name of the server you want to connect to to the DNS-system.
  • Close all tabs before proceeding: If you’re using Switchproxy and enable TOR, be sure that all Tabs are closed; all tabs get reloaded, and if session-ids were encoded in the URL, the remote host got your new (TOR) IP-address.

Don’ts:

  • Never send personal data: Do never ever enter any personal data into any website while using TOR. TOR’s intention is to hide your identity, so never enter private information. You can do that during normal surfing withotu TOR.
  • Never send usernames/passwords: Never ever enter any usernames or password trough non-SSL connections. The TOR-exit-node could sniff on his network-interface and grab the username/password pair.
  • Don’t trust TOR fully: Do not forget that the TOR-network is run by volunteers and that there’s absolutely no guarantee that one or more nodes could be compromised. Do not totally rely on TOR if it could endanger your or others life or property.

If you have any questions or suggestions, you’re welcome to use the comment-function.


Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 License.

Tech Tags:


TOR howto: Using TOR through a ssh-tunnel

September 28, 2006

TOR logoI’m a fan of TOR, the anonymizing network. It let’s me access the Internet anonymously and I don’t need to fear that anyone might use the data from their big Lawful Interception Points against me. It also prevents evil companies from correlating my web-surfing behaviour and connecting it to my IP-address.

I ain’t no criminal, i just don’t like it when people assume by default that I’m maybe a criminal, become one in the future, or use data which show my personal surfing-habits. I support the TOR-network actively trough a small monthly donation and through running my own TOR-server. I’m also willing to tell anyone how to use TOR effectively.

A posting on the or-talk mailinglist from today asked a simple question:

“There are 2 hosts.
Host 1 is at home (Debian-testing).
Host 2 is at my workplace (WindowsXP Pro)

I use Tor with Privoxy at home (host 1). Firefox with Torbutton plugin
works fine. So it seems everything ok.

At my workplace I use (WindowsXP, host 2) SSH port forwarding (with
Putyy) for webbrowsing. At Firefox in preferences, in connection tab I
had to set Socks host: localhost, port: 1080, using Socksv5.

I would like to use the Tor network from the host2 over SSH
portforwarding using my Debian host(2) at home.
Is it possible? If so, how can I do it?”

Yes, it’s possible without much hassle. First, you need a little bit of software on your client:

  1. putty or openssh
  2. for your convenience, the Firefox Switchproxy Plugin – it’s not actively supported anymore but IMHO nicer than Torbutton.

Next, check if TOR uses the default port and listen-address, open /etc/tor/torrc (or where your torrc is):
SocksPort 9050
SocksBindAddress 127.0.0.1

Now it all depends on if you’re using openssh or putty. With openssh it’s very simple. Open a terminal and log in to the remote-host:
host2$ ssh -L 9050:127.0.0.1:9050 user@host1

Log in, the tunnel is now active; that means, if you connect to localhost:9050 – a local connection on host2 – you get redirected to host1:9050 (more precise: 127.0.0.1:9050 on host1) through the encrypted ssh-tunnel.

With putty it’s the same, but more clicky-click. Open putty, load you configuration on go straight to “Connection -> SSH -> Tunnels“; enter 9050 for “Source port” and “127.0.0.1:9050” for “Destination” – leave everything else as it is. After pressing the “Add”-button you should see:
Putty Screenshot 2
Now it would be a good time to save your session, otherwise you’d have to enter the same information over and over again the next time you want to use the tunnel. Open the connection, voil´! There’s your tunnel.

Now for Firefox; i assume you already installed the Switchproxy-Plugin, now add a new proxy; leaving everything empty but SOCKS – fill in 127.0.0.1 and Port 9050:

Switchproxy Screenshot

Now something really important; Firefox uses, by default, the local DNS, even if you use SOCKS. That leads to the situation, that information leaks from you. Imagine you’d like to check out http://some.big.boo.bs/ – Firefox will ask your DNS (your employer’s DNS in the worst case!) for the IP-address of the host some.big.boo.bs. But that’s not necessary: You can just tell Firefox to request everything through SOCKS.

In order to do that just open a new Tab in Firefox, and enter “about:config” as the URL. You’ll see lot’s of different settings which affects the behaviour of Firefox. In the “Filter”-field enter “network.proxy.socks_remote_dns” – if “value” isn’t set to “true“, set it to “true” by double-clicking the line. Beware: If you don’t know what you’re doing don’t change any other value! You might totally screw up Firefox’s behaviour.

To check if the proxy is really active, open a connection to the website http://www.showmyip.com/ – it does the same like the usual TOR-test page at serifos, but seems to be more reliable:

Firefox Screenshot

That’s it, fairly easy – you can even configure Putty that it uses a local http-Proxy to establish the ssh-connection through it, resulting in the chain “http over SOCKS over SSH over http over TOR”. Additionally to this i also installed a normal SOCKS5-server on my server, i used danted (shipped with Debian Sarge); this is the configuration I’m using:

logoutput: syslog
internal: 127.0.0.1 port = 9051
external: 84.19.183.23
method: none
clientmethod: none
user.privileged: proxy
user.notprivileged: nobody
user.libwrap: nobody
compatibility: sameport
client pass {
from: 127.0.0.1/32 port 1-65535 to: 127.0.0.1/32
method: none
}
block {
from: 0.0.0.0/0 to: 0.0.0.0/0
command: bind
log: connect error
}
pass {
from: 127.0.0.1/32 to: 0.0.0.0/0
protocol: tcp udp
}

So what I’m doing is not only using the TOR-SOCKS running 9050 but also the danted-SOCKS running on 9051; I applied both settings to my Putty-configuration and now i can choose if I want to surf anonymously or not anonymously (for everything which needs passwords and stuff) – and all goes via a normal web-proxy.

Reclaim your privacy and anonymity! Purge all personal data before and after using TOR through “CTRL+SHIFT+Del”!

And stay human.


Creative Commons License
This work is licensed under a Creative Commons Attribution 2.5 License.

Tech Tags: