Wednesday, June 27, 2012

Teaching Firefox to use a CAC

Some of the sites I use require a CAC smart card to establish SSL access. (Forge.mil is an example of this.) Chrome and IE (shudder) are both smart enough to use a smart card for certificates out of the box on Windows. Unfortunately, Firefox doesn't seem to be set up to do it without some adjustment. These are the steps I used to enable smart cards (CAC) in Firefox.

First, you need some kind of client library that provides what Firefox needs. Two options for this are Active Client (standard use by DoD and other government agencies) and OpenSC. I chose OpenSC just because it seems to be fairly light weight and easy to install.

First, download and install OpenSC from it's web site. (http://www.opensc-project.org/opensc/wiki) Installation was fairly brain dead and easy. Unfortunately, it did NOT actually enable Firefox with the smart cards, so I had to use some older, more drastic methods.

I used and older set of instructions as a reference that popped up in Google: http://www.opensc-project.org/opensc/wiki/MozillaSteps. To do this, basically do the following:

  1. Firefox: Tools > Options: Advanced tab
  2. Manage Security Devices
  3. "Load" a new security device
    1. Name as "OpenSC PKCS#11 Module"
    2. Browse to C:\Windows\System32\, choose opensc-pkcs11.dll
  4. Click Ok, Ok, ..., Ok to finish everything
Now, when you access a CAC-required web site, it should pop up a box and ask you to select a smart card certificate. The interface isn't as pretty as either IE or Chrome, but it seems to work.

Update: I've noticed that accessing other SSL sites seems to be slightly broken now, so I'm not sure if this is a problem with OpenSC, or whether something else is going on.

Friday, January 13, 2012

Excellent plugin to view Firefox browsing trail as a hierarchical tree

I found a great plugin (add-on) for Firefox called "Tree Style Tab" that does an awesome job of organizing your open browser tabs in a hierarchical fashion that keeps track of nesting and the order in which you followed a trail while you chase down pages and information. It allows me to see the history of how I chased links and opened more tabs to go deeper down a search tree while researching some particular item. It gives an indication of the browser path or trail that you followed to get to a particular page in a tree hierarchy. It's similar to what I would call a "browser history tree" but is really about your current windows and tabs more than history.

Firefox Tree Style Tab Add-In


My problem: I use browser tabs. A lot. Meaning: it is not uncommon for me to have 50-100 of them open in 10-12 different windows at any given time. I usually know it's time to restart Firefox when it starts bumping up against the 2GB memory limit of a 32 bit process and I get 0.5 second delays when I type key strokes as it trundles through 2 GB of RAM trying to figure out what to do. Call it ADD, or whatever, but I use lots of browser tabs.

A typical use case for me is to chase down a technical solution to some problem I'm working on. It usually involves scouring Google and following trails of links looking for relevant information. One of the big drivers for having sooo many tabs is that I lose the ones I actually want to bookmark or otherwise make note of get lost among the other ones. I often want to go back up the tree a few pages to chase down the next set of potentially relevant links. Soon, I end up with so many horizontal tabs and windows that I can't keep track of ones that are actually useful as I assemble various pieces of the technical solution. The Tree Style Tab plugin allows me to get back up to the Google (or other) search that spawned my most recent train of thought. A similar case happens if I'm shopping for some technical item (e.g. a new PC) and need to do research around prices, specifications, etc. etc.

Awesome tool. I highly recommend it. I think it should be a standard feature of all browsers. Now, I just wish they had a version for Chrome, as well.


Sunday, December 11, 2011

Custom resolution for Ubuntu VM running in VirtualBox on Linux

So, I've got a Ubuntu server linux box where I run VirtualBox VM's, including an Ubuntu Desktop machine that I remotely display on my Windows box. (Yeah, I know, confusing and overly complicated.) Anyway, when running Gnome on the Ubuntu desktop, the maximum resolution it would give me was 1360x768. Since I have a 1920x1200 monitor on my Windows machine where I run my X server, I wanted a bigger Ubuntu desktop.

The most useful post I found was this: http://www.ubuntugeek.com/how-change-display-resolution-settings-using-xrandr.html

I ran the following commands:

  1. cvt 1680 1050 -- get a X modeline similar to "1680x1050_60.00" 146.25.... (more numbers)
  2. xrandr --newmode {output of the previous modeline}
  3. xrandr --addmode VBOX1 1680x1050_60.00 (causes the X display to flash)
  4. Use System > Preferences > Monitors to pick my new resolution
Voila. Easy, peasy. Works great now.


Friday, November 4, 2011

Windows 7 idle screen saver doesn't start with KVM and wireless mouse

I noticed after installing Windows 7 on my machine that it no longer goes to screen saver when the machine sits idle for a while. Originally, I suspected this was due to the KVM that I had hooked up. It must be sending some kind of heartbeat signal which keeps the screen from going idle. Some googling revealed there was a known issue with using a MS wireless mouse that can cause this problem. The fix was to install some optional Windows Update fixes that deal with HID drivers. After installing the fix, it started going to sleep properly on my desktop. Unfortunately, I don't seem to have the same update options available for my Windows 7 Professional Dell laptop, so I'm not sure if it's a global fix.

In the end, I discovered that the real cause was, in fact, the old-school MS wireless mouse. I replaced it with a newer one and the problem magically went away on both my laptop and desktop machines.

Tuesday, October 25, 2011

Repairing 'svnsync: malformed file' error with subversion


I recently had a sync or other failure of svnsync which left me with a bum repository. Every time we tried to do svnsync, it reported "svnsync: malformed file." I got the same error with all svnadmin access.

I found this link: http://subversion.tigris.org/ds/viewMessage.do?dsForumId=1065&dsMessageId=1892873&orderBy=createDate&orderType=desc and provided some good clues. I noticed that my file in db\revprops\0 had junk in it instead of normal stuff. It should have looked like this:

K 8
svn:date
V 27
2010-07-21T02:55:12.203323Z
K 17
svn:sync-from-url
V 45
https://portal.secureci.com/svn/secureci
K 18
svn:sync-from-uuid
V 36
b443ad56-1e36-4a4f-97ef-7144cc153033
K 24
svn:sync-last-merged-rev
V 1
0
END


What I did to fix it:

  • cd c:/temp
  • svnadmin create svn-sync2
  • Copy hooks/pre-revprop-change.bat file from broken repository to new one
  • svnsync --username svnsync initialize file:///c:/temp/svn-sync2 https://portal.secureci.com/svn/securci
  • Copy the db/revprops/0/0 file from the new repos to the broken one
  • Edit the 0 file and fix the 'sync-last-merged-rev' entry to have the correct number.
    • Look in db/revprops/2 (or highest number) and locate the most recent numbered file (e.g., 2437)
    • Change '0' value below "V 1" to be "2437"
    • Change the V1 line to be "V 4" for 4 character length
  • Run 'svnadmin verify .' in the main directory of your broken repository to make sure that it has everything intact. (This may take a little while.)
  • Run 'svnsync --username svnsync synchronize file:///c:/SecureCIdata/svn/repos/secureci' and make sure synchronization goes smoothly
That's it. Syncing should work normally now.

Wednesday, October 5, 2011

DOS batch file stderr redirection

I never remember the whether the syntax of DOS file redirection is similar to normal Unix file redirection. It is. So I'm writing it down where I can find it.

CALL .\somescript.bat >> logfile.log 2>&1

Of note, I recently learned that redirecting output from a PowerShell script does NOT work very well and gives file handle errors. That's another story, entirely.

Common DOS batch file error handling mistakes I make

I write a decent amount of batch scripts now days to automate things on windows server boxes. Unfortunately, I don't do it quite frequently enough to remember all the crazy syntax of DOS commands. One of these errors is error handling. These are the things I commonly need to deal with.

I found this page (and site) very helpful for all DOS related stuff: http://www.robvanderwoude.com/errorlevel.php

  1. Use "IF %ERRORLEVEL% NEQ 0 SET MYERROR=1" to record whether the previous command resulted in an error code. Alternately, you can check for "IF ERRORLEVEL 1 ..." if you want to look for a specific error level.
  2. Be cautious of manipulations with ERRORLEVEL. It's not really an environment variable like other variables. In particular, do NOT ever use "set ERRORLEVEL=5" or similar. It will corrupt any further use of %ERRORLEVEL% syntax by fixing it at a value.
  3. Use "CALL FOO.BAT" instead of just "FOO.BAT" when calling subscripts. Otherwise, when that script completes it will not return to the current script.
  4. Use "EXIT /B 1" to return an exit code from your script. If you use "EXIT 1" it will exit the entire command shell, including closing your current window if it's running in one.
  5. Consider using SETLOCAL and ENDLOCAL within your script to prevent temporary environment variables from carrying through to outer shells.

Below is an example script.


:: Sample script with some error handling
SETLOCAL
SET MYPARAM=%1
if "%MYPARAM%"=="" goto :USAGE

CALL .\childscript.bat %MYPARAM%
if %ERRORLEVEL% NEQ 0 set MYERROR=1

echo.
echo Finished child script. Handling errors now...

if %MYERROR%==1 GOTO :ERROR

echo It worked!
ENDLOCAL
set SOME_EXTERNAL_VARIABLE=1


GOTO :EOF
:USAGE
echo Please provide a command line parameter.
EXIT /B 2


:ERROR
echo It didn't work, dude.
EXIT /B 1 

Update: I was wrong about the ERRORLEVEL syntax earlier, so I updated after some testing.