Blowfish encryption plugin for Colloquy
_Do you want to skip all this text and just get the Colloquy Blowfish Plugin?
Then click here.
Lately, IRC channels where I hang started using Blowfish encryption for all messages sent to the channel. mIRC and eggdrop support Blowfish pretty easily, but there was nothing for Colloquy (the IRC client I use - Mac OS X only) to encrypt & decrypt Blowfish encrypted messages.
So I started looking for a way to encrypt & decrypt Blowfish messages using a Colloquy plugin. Colloquy allows all sort of plugins: AppleScript, Python, Obj-C, etc. I tried to use the Python template plugin, but it wouldn’t even load on Colloquy, spitting some error on load. So I downloaded existing plugins to see how they worked. Most of them seems to use the AppleScript API, and it seems easy enough for my purpose.
Now I needed code to encrypt & decrypt Blowfish messages. Google suggested a Java class that allowed easy encryption & decryption. Adding a simple main method in it, I was able to encrypt & decrypt messages via the command line by passing the key & message as arguments. While this worked just fine, launching the JVM each time I received a message or I sent a message was quite resource-consuming, even with my dual G5.
So I started looking for C or C++ code that would do the same thing. After trying many implementation, I decided to try to compile the eggdrop Blowfish module by itself. I had to change a couple of things to make the blowfish.c file compile alone, but I made it. I also added a new main function to be able to use the encrypt & decrypt functions from the command-line, which worked just fine, and was much faster than the previous Java implementation I used.
Note to Java haters: The Java implementation I used was slower because I had to start the JVM each time I wanted to encrypt or decrypt a message. If I had the JVM already running, and a service that would listen for encrypt & decrypt commands on a socket or something, it would very probably have been almost as fast as the C implementation I currently use. I just wanted to go with the more minimalist approach I could find, so I opted for the C program.
So now, I was receiving encrypted messages in Colloquy, my AppleScript plugin was called for each message, and I was able to change the received message into it’s unencrypted form by calling my Blowfish command-line program. Sent messages followed a similar path: Colloquy > AppleScript plugin > command-line encryption > IRC server.
The only problem I had now was special characters. Bold, underline & colors IRC characters were not correctly handled by the AppleScript plugin. So I took the HTML-ized version of the message to be sent and translated all the HTML tags I found into IRC characters. For received message, I did the reverse: I translated IRC characters into HTML tags and passed that new string to Colloquy for display.
Limitations: For sent messages, I only translate specific colors into standard IRC colors; I used the quick picks at the bottom of the “Show Colors” panel in Colloquy. So the colors that will be sent correctly when encrypted are: #FF0000 (red), #44B958 (green), #0013FF (blue), and #EBB51B (orange). All others colors will be replaced with black when sent.
Received message don’t have this limitation, so colors in received messages should pretty much always look OK.
Also, my plugin doesn’t support background colors, so messages containing those might look weird when decrypted.
That’s it. I now have working Blowfish in my Colloquy, and so can you.
You can download the latest version of the Colloquy Blowfish Plugin (version 04) for PowerPC or Intel.
Version 02 fixes a small problem with messages containing colors > 9 (IRC color codes 10 to 15). Those messages would not be shown in Colloquy because of this problem.
Version 03 allows to send or receive unencrypted messages in normally encrypted channel or private messages for messages that start with +p.
Version 04 fixes a problem with % in sent messages, and adds support for multiple channels using just one plugin.