Thursday, October 07, 2010

HTTPS + Basic Auth: Java vs Ruby

For the past couple of weeks I've been working on automating the process of creating an OVA. I considered various tools for the automation but for various reasons that aren't especially relevant here, I ended up going with rake running on top of JRuby. Net result is that for most of the logic I'm writing I have the option of doing it the Java way or the Ruby way. Almost without fail I found myself preferring the more concise Ruby solutions.

Then I found myself needing to do an HTTP GET with basic authentication over HTTPS and verify the server's SSL certificate. Here's the interesting bits of the rakefile with the Java solution:

require 'java'

java.lang.System.setProperty('', 'mykeystore')
java.lang.System.setProperty('', 'password')

class MyAuthenticator <
def getPasswordAuthentication()'userid','password').toCharArray())

task :testjava do
huc ='').openConnection()
print huc.inputStream.to_io.readlines

It's a bit screwy that I have to replace a global authenticator to supply credentials for a single host, but this is just a rakefile so I didn't feel too bad about cutting corners in MyAuthenticator.

Here's the equivalent Ruby code:

require 'net/https'
require 'uri'

task :testruby do
https ='', 443)
https.use_ssl = true
https.ca_file = 'foo.crt'
https.verify_mode = OpenSSL::SSL::VERIFY_PEER

request ='/abc')
request.basic_auth 'userid', 'password'
response = https.request(request)

print response.body

Open-uri would have improved the Ruby code dramatically but as far as I can tell open-uri has some hardcoded assumptions about using the machine-wide CA certs. Setting the userid/password per request is nice, but Java wins the certificate handling hands-down. Ruby has a marginal LOC lead for a single request, but Java catches up as soon as you make the second HTTP request.

Chalk up a rare win for Java on this one.

Friday, September 28, 2007

WIMP no more?

As I was about to fall asleep last night, the acronym WIMP came up in my steam-of-consciousness mental meanderings. For those of you who haven't been around sufficiently long to remember WIMP, it stood for (I believe, and assuming my senility isn't too far advanced) Windows, Icons, Menus, Pointer. While everyone takes this type of user interface for granted today, it was all the rage when personal computers first got sufficiently powerful to sport GUIs.

Anyway, back to last night. It occurred to me that my use of windows and menus has fallen precipitously over the past few years and is in danger of disappearing altogether. As I do more and more of my daily computing on the web, some curious things have happened.

Things that I used to accomplish by switching windows I now do by switching tabs in my browser. My personal email, to-do lists, news, reading material, etc. are all accessed via the web now. In fact, on a typical day I only spend non-trivial amounts of time in 4 different windows: my web browser, Lotus Notes (which I wish fervently I didn't have to use), a command line window and emacs.

Similarly, I almost NEVER use menus anymore. I long ago learned the mouse-click or keyboard shortcut for everything that I typically do and I find myself annoyed whenever I have to actually LOOK for something in an application's menus. Since web pages don't have the luxury of adding items to the browser's menus, web designers have found other ways to expose their functionality (rollover text, GUI's that morph in real-time, etc.).

So for me, at least, WIMP is dead. Long live...uh...TIP (tabs, icons, pointers)!...or WILT (web apps, icons, links, tabs)!...or something else!

Wednesday, September 26, 2007

Ex Post Forko

This may be unique to me, but I often find myself wanting to retroactively control-click a link on a web page. The following scenario seems to happen to me all too frequently:

1. I Google something & get the results back.
2. One of the search results looks promising, so I click it.
3. The page turns out to be interesting, but not really what I'm looking for at the moment.

At this point what I really want to do is rewind the clock a few seconds and control-click on the link in the search results to farm the interesting-but-not-immediately-relevant page to another tab for future consideration. Accomplishing this requires a click on the back button, scanning the page to find the link, then a control-click on the link. Am I the only one that would find it useful to do this with a single click/keystroke?

If there's anyone out there looking to write a Firefox plugin, could you please write an "ex post forko" extension that does this is with a single gesture? Control-forward comes to mind as a good candidate, but I'll take whatever I can get.

Wednesday, May 30, 2007

MacBook adventures: Additional Proggies

By sheer coincidence, I appear to have purchased my MacBook about the same time Bob Sutor got his Mac. By even sheerer coincidence, we both use Ubuntu as well. And we both work for IBM. This is getting spooky. I'm almost glad I missed his talk at UNC a few months ago -- the universe might have imploded if we were in the same vicinity.

Anyway, this is my first (well, first-and-a-half if you count the blog entry I almost-posted about locating a new screen background) blog entry about setting up my new MacBook. Today's ramblings are about additional programs I've installed on the Mac to make myself more comfortable. Mac purists (sorry John, that's you) will probably scoff at some of these, but productivity trumps purity everyday in my world.

Safari was ok as far as it went, but that wasn't quite far enough. Gmail's chat didn't work. David Heinemeier-Hansson is somewhat enamored of Camino, and after using it for a month or so I have to concur. Gmail is working fine & it's done a bangup job on every webpage I care about thus far.

Next had to go (no tabs?! WTF?!). iTerm is the replacement, but even it has some uglies that need to be configured around. In particular, I was pulling my hair out until I figured out how to create a new keyboard profile that sends option as meta. The bookmarks with associated commands and corresponding keyboard shortcuts are nice too. Emacs over ssh to the Ubuntu box is looking pretty good with Monaco 10.

Lastly (for this post, at least): Carbon Emacs. I drank the emacs koolaid in college about 18 years ago and Meta-X has been my constant companion ever since. It was a pleasant surprise to run across a Macified flavor of my favorite tool and defer an onerous retraining of the fingers for a few more years (ctrl-P is NOT print, damnit!).

More to come...

Wednesday, April 25, 2007

Adventures with XP and Ubuntu

About a month ago I got a new laptop at work. A nice one (or at least, nicer than my old one) -- a Lenovo ThinkPad T60p. The little bundle of computing power has a Core 2 Duo processor, 3GB of memory and a 100GB hard drive. Emboldened by the success stories of Sam Ruby and Jason McGee, I installed PartitionMagic 8.0, shrank the XP partition down to 65GB and carved out 35GB to install Ubuntu. As I said, this was about a month ago. I use Ubuntu on my custom-built desktop at home (which is another, even longer story), and knew that Feisty Fawn was due in mid-April so I decided to leave the partition empty.

Fast forward to April 19. Feisty Fawn goes public! Woohoo! Fire up BitTorrent, snag the ISO's (i386, BTW -- I got burned putting AMD64 binaries on my home machine) and start the install. On the whole, I'd say it went pretty cleanly. Had to click through a few quasi-nasty messages about using non-open video drivers for the ATI chips in the laptop, but that's far better than the old status quo. So I'm sitting there looking at my newly-installed Ubuntu 7.04 desktop and it occurs to me that I've done this all wrong...

I expect I could have mounted my NTFS partition as read-only under Ubuntu, but there are still several internal things at IBM that only run cleanly under Windows XP. Things like accessing printers, submitting expenses and building presentations. I'd spend a significant portion of my time rebooting back and forth between Ubuntu and XP. It occurred to me that I could get all the things I wanted from Ubuntu (rich command line tools, real filesystem, superior editors, etc.) by running it in a virtual machine -- I didn't need to let it own the entire machine! No problem, I figured, I'll just boot back to XP, use PartitionMagic to rejoin the partitions and host Ubuntu under VMware. That's when the fun began.

Apparently installing grub on the boot partition modifies the master boot record (MBR) in such a way that PartitionMagic can't recognize it anymore. PM steadfastly reported error 117 and refused to even start. That sucked. So I googled various combinations of "remove", "grub", "fix" and "MBR". The universal solution seemed to be to boot off the XP CD, go into recovery mode and do "fdisk /mbr". Except I don't have an XP CD -- we have a group of folks at work that install XP for us and we never see the CD's. That sucked even more.

I was desperate. So desperate that I made it all the way to the 3rd page of Google results before I ran across exactly what I was looking for on the Novell website. 15 minutes later, the partition was gone. An hour after that, Ubuntu was running under VMware and things have been peachy ever sine. Thank you Novell!