ENCRIRC -- An application level encrypting IRC proxy
(because IRC SSL does not save your from the voyeur sysadmin)

OVERVIEW

  IRC is insecure, it's a plaintext protocol. Everyone can sniff
  your connections. In order to fix this problem, many clients
  and servers have now support for SSL, so your client will connect
  and the IRC server via a secure SSL connection, and no
  one between you and your server can read what is passing.

  This have problems too, see this picture:


  [Alice] <--- ssl ---> [SERVER] <--- ssl ---> [Bob]

  Even if the connection is encrypted between Alice and SERVER, like
  it is between Bob and SERVER, inside the server, i.e. inside the
  IRCd deamon, the data is passing in plaintext. This means that
  the sysadmin can read everything you write, regardless of the
  use of SSL.

  If it's a small IRC network, you have to fear about voyeur sysadmins,
  if it's a big network, you have to fear about government asking
  about logs to big ISPs and so on... you already know this story.

  So what's the solution? To have an IRC client that will send
  encrypted messages over the IRC protocol, using a well known
  and belived secure block cipher, and a key that only Bob and Alice
  know. This is often accomplished thanks to client-specific plugins
  for xchat, IRSSI, mirc, and other clients, but there are tons of different
  clients for IRC, and it's not always possible to find a compatible
  encryption plugin between different clients. Fortunately there is a
  solution, that's to write an IRC "repeater" or "proxy" that is sit in
  the middle between the IRC client and the SERVER, of both Alice and Bob:

  [Alice] <--> Encrirc <--> [SERVER] <--> Encrirc <--> [Bob]

  It does not matter if the connection between Encrirc and the Server
  is secure or not, everything will be encrypted before to pass from
  the internet. Also the Server administrator will not be able to
  read nothing, only Alice and Bob have the right key to encrypt/decrypt
  messages.

  Of course, Alice and Bob, need a secure channel to share an Encrirc key,
  but to do so they just have to use PGP or GPG and the email.

  (NOTE: for details on the encryption algorithm and scheme used
   jump to the end of this tutorial.)

INSTALLATION

  Encrirc is a Tcl script that can run on Linux, Windows, MacosX, and every
  other platform where a Tcl interpreter is available. The required
  version of Tcl is 8.4. You don't need any kind of Tcl extension to run
  Encrirc, in most Linux distribution where a Tcl interpreter is installed
  by default you'll just have to execute the 'encrirc' file.

  If you want to install the script in a fixed location, just copy
  the 'encrirc' file in some place, like this:

  % cp encrirc /home/antirez/bin/

  or to install it system-wise (as root type)

  # cp encrirc /usr/local/bin/

  NOTE for SSL users: if you want to use Encrirc against SSL servers
  you need to install the Tcl 'tls' extension. If you are using Debian
  just type: "apt-get install tcltls".

SUPPORTED CLIENTS

  For a list of supported IRC clients read the CLIENTS file in this
  distribution.

TUTORIAL

  In order to run encrirc, you need a keyring. A keyring is a collection
  of keys associated with a list of IRC nicknames or channel names.
  A keyring file is just a plaintext file containing a key in every line
  followed by a list of nick or channels separated by spaces.
  The following is an example of keyring file.

  89e48eef349001109c193ea2da2e9a20 joe joex jo*
  24acbf02990348417b49a350f6368e0e pat patric
  2c4d6760c1520e3b1de3d2a570341c4e alice myalice
  d6230a79f69674bae59f540a3361ccec #encrirc

  To match more than a nick you can use the '*' wildcard, that works
  like in the unix shell.

EXAMPLE I : Bob and Alice want to talk in a secure way.

  -- Generating the key --

  Both Bob and Alice need to download and install encrirc.

  After the installation, Alice generates a key using the following
  command:

  % encrirc genkey bob alice

  The output will be something like:

  76afffc51d128444c7b91501ca49e487 bob alice

  Alice puts the above line into a keyring file "/home/alice/keyring.txt"
  and send this line to Bob USING PGP/GPG or any other secure channel.

  Bob puts the above line into a keyring file "/home/bob/keyring.txt"


  -- Running the program --

  Now they are ready to run encrirc and connect to IRC.

  Bob will run encrirc using this command line:

  % encrirc 8000 irc.yourircserver.org 6667 /home/alice/keyring.txt

  Alice will use the same, but with her keyring file pathname:

  % encrirc 8000 irc.yourircserver.org 6667 /home/alice/keyring.txt

  What this line means?

  It means: Listen on my local port 8000, when I connect using my
  IRC client to server 127.0.0.1 (or localhost), port 8000, proxy
  my connection to the real server "irc.yourircserver.org" port 6667,
  using as keyring for encryption /home/alice/keyring.txt.

  If you want to use an SSL server, add "/ssl" to the port number,
  like in this example:

  % encrirc 8000 irc.yourircserver.org 9999/ssl /home/alice/keyring.txt

  -- Connecting to the server ---

  Now both Alice and Bob can run their IRC client, and connect to
  IRC using "127.0.0.1" as server, and 8000 as port.4

  Now assuming the Alice's nick is "alice", and the Bob's nick is "bob",
  Alice can open a encrypted querry with Bob, using "?bob" as destination
  nick. Something like:

  /msg ?bob hello, this is an encrypted message

  or better, if your client support it:

  /query ?bob

  the client will open a new window or tab, and Alice will be free
  to have a long chat with Bob, all encrypted. Bob will receive
  the decrypted messages as originated from the nick "?alice".

  That's all, happy encrypted query. Or read more to know how to
  use encrirc to build encrypted channels with many users.

EXAMPLE II : Encrypted channel.

  You are a comunity of users that want to build an encrypted IRC
  channel #foobar. Everything passing in that channel will be encrypted.
  External people can join the channel, but will see only things like
  this:

  <antirez> >encrirc<099838233|35aec1feb62c0529|5b932c56d460dd26bec9427a480800ff2a949229e2e99bde768d1b30c4bd44a7503a86c67b3d261990363943accf599e68f80c48f8327bb2e25dbeadb4f1fb44889218f1743afe0e35b46971995e467c3ccc521cd3e22876f9a31e6a9481c08e78b4f432b3b343230e5ae84932fa1c72

  Not very helpful :) (If you want to know the details of the encryption
  please read at the end of this file).

  -- Generating the key and running encrirc ---

  % encrirc genkey '#foobar'4

  (note that you need to quote the channle name using '')

  The output will be something like:

  76afffc51d128444c7b91501ca49e487 #foobar

  Now send (again, over a secure channel like GPG/PGP) the above
  line to all the users of this encrypted channel. They will put
  this line in their keyrings, start encrirc using the usual command
  line:

  % encrirc 8000 irc.yourircserver.org 6667 /home/username/keyring.txt

  -- Using the encrypted channel --

  Every user will connect using the IRC client to 127.0.0.1 port 8000,
  and join #foobar. All will be encrypted, you will notice it because
  every line on the channel will appear originating from nicks starting
  with the '?' character.

  -- How to send unencrypted messages to encrypted channels --

  Prefix your message with "plaintext:". This does not work for
  queries (private messages), where it makes less sense and is better
  that no string will pass in clear at all.

ENCRYPTION DETAILS

  Every decent program that is about encryption should explain very
  well how the encryption works, so experts can check if it's just
  "snake oil", or real security. This is my attempt to explain it.

  ALGORITHMS USED:

  We use blowfish as block cipher, in CBC mode

  the hash function used is MD5

  ENCRYPTION SCHEME:

  Every message is encrypted using the key relative to the destination
  nick or channel, with blowfish in CBC mode, using as initialization
  vector a 64 bit pseudo-random Initialization Vector.

  The message is send over the network as:

  >encrirc< || KEYID || IV || BLOWFISH(k, P || HMAC(k, P))

  k         -> A 128 bit key
  >encrirc< -> A fixed prefix for every encrypted messages.
  KEYID     -> Is the key identifier. The first 64 bits of MD5(k)
  IV        -> A pseudorandom 64 bit string
  P         -> The plaintext with spaces to be 80 chars long

  NOTES:

  The padding of 'P' is used so that the ciphertext is always of
  fixed length, the eavesdropper can't tell the length of the message.

  The pseudorandom IV makes sure that the same message will encrypt
  in a different ciphertext.

  The KEYID is used to avoid to brute-force all the keys in the keyring.

  The HMAC is checked at every message received to make sure there
  is no corruption. Corrupted messages are not sent to the user,
  but instead a warning is sent.

AUTHOR

  Salvatore antirez Sanfilippo <antirez@invece.org>

LICENSE

  This software is released under the GPL license.
  See the COPYING file for more information.
