Adding New Drive to a RAID1 Array

Last week I finally bought a second HDD for my home directory so I could have some redundancy in case a drive fails. Lucky for me, I had the foresight to put the single drive I had been using on a RAID1 array all by its lonesome self way back when. After installing my new HDD, I found myself tasked with adding to the array. Simple, right? Yes, but with one caveat.

After installing and partitioning the drive properly, add it to the array with:

1
mdadm --add /dev/mdX /dev/sdXX

Since the array was only set up to have one drive, the new drive will get added as a spare. Check /proc/mdstat to confirm this…

1
2
md4: active raid1 sdb1[1](S) sda1[0]
   1953512312 blocks super 1.2[1/1][U]

This isn’t what I want! Well, here’s the catch: there’s one more (very simple) step; grow the array to the new number of drives.

1
mdadm --grow /dev/mdX --raid-devices=Y

…where Y is the new number of drives. And now, to check /proc/mdstat:

1
2
3
md4 : active raid1 sdb1[1] sda1[0]
      1953512312 blocks super 1.2 [2/1] [U_]
      [>....................]  recovery =  2.1% (41879104/1953512312) finish=516.9min speed=61630K/sec

Perfect! The new drive is on equal playing field with the existing drive and is being brought up to speed with the data on the existing drive.

Ahh, data redundancy. :)

Simple Public Key Encryption with RSA and OpenSSL

Hey you! This post is outdated!

Take a look at a more correct, detailed, and useful one. What’s the advantage? The EVP functions do implicit symmetric encryption for you so you don’t get hung up on the max length limitations of RSA. Plus, it has an AES implementation.

Disclaimer: I am NOT a crypto expert. Don’t take the information here as 100% correct; you should verify it yourself. You are dangerously bad at crypto.


Last month I wrapped up my Alsa Volume Control server project. To test it, I exposed the server to my public Internet connection and within a few hours, my friend was using the lack of authentication to change the volume on my computer from his apartment. It may not be a serious security hole, and funny as it may be, it would certainly be annoying if someone had malicious intentions in mind. The simple solution is just disable the port forward so the server is only accessible via my LAN, but what fun is that? What if I feel like changing my volume from anywhere for whatever stupid reason I may have?! Thus, I needed to add authentication to the server, which means I also a needed a way to encrypt credentials as they went over the network. And so I opened up the OpenSSL documentation to figure out how to encrypt and decrypt simple messages with RSA in C. Here’s a quick summary…

First up, to do anything with RSA we need a public/private key pair. I assume the reader knows the basic theory behind RSA so I won’t go into the math inside a key pair. If you’re interested, here’s a good write-up on the math behind RSA.

1
RSA *keypair = RSA_generate_key(2048, 3, NULL, NULL);

Here we’re using the RSA_generate_key function to generate an RSA public and private key which is stored in an RSA struct. The key length is the first parameter; in this case, a pretty secure 2048 bit key (don’t go lower than 1024, or 4096 for the paranoid), and the public exponent (again, not I’m not going into the math here), is the second parameter.

So we have our key pair. Cool. So how do we encrypt something with it?

CodePSU: Hosting an ICPC-style Programming Competition

Just over a month ago the other officers of the Penn State ACM and I were approached by the president of the newly-formed Penn State of Association of Women in Computing to co-host a programming competition which would come to be known as CodePSU. We set the date of the event and had roughly one month to plan everything. Most of the logistical (location, food, times) and financial (sponsors, prizes) were not handled by me. Rather, I tasked myself with designing and implementing a code submission system that allowed teams to upload solutions to problems to the judges. The catch? It had to be fast. We would have three judges judging 60 people’s code multiple times in just three hours. It also had to be secure. We couldn’t allow teams to figure out what test cases we where judging the problems with or allow them to get access to other teams code. If that wasn’t enough, we also had to support C, C++ and Java.

Sublime Text Color Scheme in Eclipse

If you don’t know about Sublime Text 2 you should click on that link right now. Sublime is by far my favorite GUI text editor (I still love you vi and nano), but when doing Android development it’s impossible to beat the convenience that the Android plugin for Eclipse provides. However, the default color scheme is Eclipse is nothing like that of Sublime’s. Thus, here’s how to get the Sublime color scheme (and a lot more) in Eclipse.

First, install the Eclipse Color Scheme Plugin. Then, in Eclipse, go Window > Preferences > General > Appearance > Color Theme and select the Sublime Text color scheme. If it isn’t already there, you can download it from the Eclipse Color Themes’ website.

And that’s it! Simple.

Ubuntu server 11.10 and Courier-IMAP

My weekend project was to set up an SMTP and IMAP server on my home server so I could finally have my own mail server and be free from the prying eyes of the large email hosts.

Most of this process was relatively simple thanks to this wonderful guide from the Ubuntu help site. However, I ran into one problem: the courier-IMAP server would not accept any connections with the default configuration. A quick look in the mail log revealed:

1
2
3
dovecot: master: Fatal: execv(/usr/lib/dovecot/imap-login) failed: No such file or directory
dovecot: master: Error: service(imap-login): child 7466 returned error 84 (exec() failed)
dovecot: master: Error: service(imap-login): command startup failed, throttling

Lo and behold, /usr/lib/dovecot/imap-login did not exist. Furthermore, locate imap-login returned nothing so I concluded that this binary was no where to be found on my system. However, apt-file search imap-login showed that the package dovecot-imapd provided imap-login. I went ahead to install it to find that courier-imap and dovecot-imapd conflict with one another and apt won’t allow them both to be installed. So, my hack-ish workaround, copy the binaries I needed out of the directory, uninstall dovecot-imap and reinstall courier-imap. For those who just want the “solution”:

1
2
3
4
5
sudo apt-get install dovecot-imapd
cp /usr/lib/dovecot/{imap,imap-login} ~/
sudo apt-get remove dovecot-imapd
sudo apt-get install courier-imap
sudo cp ~/{imap,imap-login} /usr/lib/dovecot/

Obviously, this is not an ideal solution. Most likely, courier will break with a future update since imap-login won’t be updated, but hopefully this dependency problem will be sorted by then.