Tuesday, July 31, 2012

White IPA Recipe

Not too long ago the folks at Deschutes Brewing out in Bend cooked up a White IPA, which is a hybrid of Belgian style white ale and India Pale Ale.  I liked it, quite a bit actually.  When the time came to make another beer, I decided to take a crack a recipe of my own.
I need to say at this point that I have not actually tasted this beer.  I actually just brewed it yesterday.  Anyway, here we go.

Ingredients:
  • 2 pounds Pilsner malt
  • 1 pound uncracked flaked wheat
  • 1 pound uncracked flaked oats
  • 2 pounds Brewer's Gold light DME
  • 4 pounds wheat DME
  • 20 AAUs Columbus hops (bitter)
  • 4 oz Cascade hops (aroma, split in half)
  • 0.5 oz curacao sweet orange peel
  • 11 oz light Belgian candi sugar syrup (this just happened to be how much I had)
  • Wyeast 3944 or some other Belgian ale yeast
Procedure
  1. Steep the grains in 1 gallon of 150 degree Fahrenheit water for 30 minutes.
  2. Rinse the grains in another gallon of 150 degree water.
  3. Dilute steeping and rinsing water to 3 gallons and bring to a boil. 
  4. Stir in the barley extract and add the bittering hops.  Boil for 45 minutes.
  5. Add the wheat extract, orange peel, and 2 ounces of the aroma hops, boil for 15 minutes.
  6. Pour into fermenter, dilute to 5 gallons, chill to pitching temperature, and pitch yeast.
  7. Rack to secondary when krausen falls and dry hop with the remaining Cascade hops.
After this is bottled and conditioned I'll update the post.

Friday, July 27, 2012

World's Cheapest Software Defined Radio (SDR)

How it began
Somewhere I read about using a cheap USB HDTV dongle for a software-defined radio receiver.  The dongle needed to be built with a RTL2832U chipset and an E4000 tuner.  The thing works from 62 MHz to around 1.7 GHz.  There's also a somewhat risky modification that allows it to pick up the HF bands, but I haven't yet tried that. 
I found one on eBay for the outrageous price of $17.  The downside is it took about three weeks to show up.

Appearances can be deceiving

After I made sure it indeed showed up on the USB bus I followed the following steps, gleaned from various blogs.  As always, I did all this stuff in a Linux environment , but it can be done under Windows or Mac OS.  Doing this stuff on a Mac is probably pretty similar.

Compile and install rtl-sdr
You will need the libusb dev headers.  If you're using a Debian based system, simply run apt-get install libusb-1.0-0-dev.

 Clone the git repository with  git clone git://git.osmocom.org/rtl-sdr.git
Make a build directory and enter it
mkdir rtl-sdr/build
cd rtl-sdr/build
Create the makefile
cmake ../
Build and install rtl-sdr
make
make install
Rtl-sdr will now be built in /usr/local.  At this point, you should be able to test the dongle.   For some reason $LD_LIBRARY_PATH was unset on my system, and there was an issue with the permissions for the USB device as well.  I ended up running as root and setting the $LD_LIBRARY_PATH

 root@gregor:~/sources/rtl-sdr/build# export LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:/lib
root@gregor:~/sources/rtl-sdr/build#  /usr/local/bin/rtl_test
Found 1 device(s):
  0:  Generic RTL2832U (e.g. hama nano)

Using device 0: Generic RTL2832U (e.g. hama nano)
Found Elonics E4000 tuner
Supported gain values (18): -1.0 1.5 4.0 6.5 9.0 11.5 14.0 16.5 19.0 21.5 24.0 29.0 34.0 42.0 43.0 45.0 47.0 49.0
Reading samples in async mode...



Compile gnuradio
Most software for the dongle depends upon GNU Radio, so you must install it.  Patch Von Braun has built a shell script which will compile gnuradio for you, if you're running a Debian based system.  You can get it here.


redacted@gregor:~/sources$ wget http://www.sbrac.org/files/build-gnuradio
--2012-07-25 18:39:00--  http://www.sbrac.org/files/build-gnuradio
Resolving www.sbrac.org (www.sbrac.org)... 174.142.32.20
Connecting to www.sbrac.org (www.sbrac.org)|174.142.32.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 29181 (28K) [text/plain]
Saving to: `build-gnuradio'

100%[====================================================================================================================================================================================================>] 29,181      97.8K/s   in 0.3s   

2012-07-25 18:39:01 (97.8 KB/s) - `build-gnuradio' saved [29181/29181]
redacted@gregor:~/sources$ chmod a+x build-gnuradio

redacted@gregor:~/sources$ ./build-gnuradio

The script will automatically take care of any dependencies and build gnuradio, with support for the Realtek dongle.  The output is quite long, so it has been omitted.   It may take some time to finish.

After the build finishes, there are  are some applications which depend upon gnuradio that you can install.


Multimode
The first SDR application I installed was "Multimode Radio Receiver".  It is just that.

Here we can see what things look like around the aircraft band.  Please note that this is with the rather lousy antenna the dongle came with.  It isn't even close to being correct for this wavelength, so it isn't really picking much up.

It should be noted that Multimode has a scan feature that although a bit cranky, is quite interesting.  I've had a problem with it starting to scan from 150 MHz, no matter what I specify i the GUI.  A fairly clunky workaround was to edit the default values (this is a Python program, so no recompile is needed).  If I have time and a patch isn't released before I do I'll probably spend some time with WinPDB

Gqrx
Another app I tried out is gqrx.  It is a little bit more polished than Multimode, but it doesn't have the scan feature.  Here it is on a local FM station.


Conclusion
This dongle is a pretty powerful tool at a pretty cheap price.  I'm going to do a followup post once I'm more familiar with doing things in GNU Radio, and if I come across any software that I find to be particularly neat.  I'm a busy man though, so no promises as to when.

Sources
I didn't do this in a vacuum, so it is only fair that I list where I learned things.


GNU Radio and librtlsdr with Realtek RTL2832U/Elonics E4000 software defined radio receiver.


RTLSDR supported hardware

Sunday, May 27, 2012

Rehabbing Old Axes

The axe may well have been the first tool humans ever developed.  Examples have been found that were made by Homo Habilis in the lower Paleolithic era, meaning that axes have been around longer than modern humans.

Various religious orders throughout history have used axes as symbols..  They have also been used as symbols of military power and authority (see the Roman fasces).  These factors have lead to axes having a place in a lot of folklore, as well as other more modern forms of mass media.

I had a couple of axes that were in pretty sorry shape.  I'm not really sure where I got one of them, and I got  the other (the double bladed one) at a garage sale for the princely sum of $2.

You can see that the handles were in pretty sad shape, and that the heads were rusted.  The double bladed axe had probably been used to chop something other than wood as well.  I removed the handles by placing the axe heads in a vise and driving them out with a hammer and a metal rod used as an ersatz punch.  The single bladed axe took a while, but the handle for the double bladed one came out after two hits.  Some moron had tried to simply glue the handle in.


I soaked the heads in old motor oil (I'd just changed the oil in my car) overnight to soften up the rust.  After that I used a drill-mounted wire brush and orbital sander to clear the rust off.



I then sharpened the heads with an angle grinder and belt sander, and applied a few coats of paint.

After this, I began the rehafting process.  First the handle is inserted into he head.

The next step in the process is to drive the wedge into the notch in the end of the axe handle


After the wedge is driven into place, it is secured with a metal clip.  I had issues with the clip the handle came with bending, so I just used a fence staple.





After repeating the process on the double bladed axe, I now have two perfectly good axes.


It could be argued that I may have been better off just buying a couple of new axes and calling it a day.  It certainly would've saved me a bit of time.  None the less, I'm glad I did this.  I get tired of how disposable things are.  It felt good to take "worthless junk" and make it into a good, useful tool.

Wednesday, March 28, 2012

Reusing Threads in Perl

For all its warts, Perl is a powerful programming language that will continue to be used for some time.  If programming languages were people, Perl would be your crazy uncle with a very cluttered but very well stocked workshop.  One of its more powerful features is the threads api.

I have noticed that programs which create and join a lot of threads seem to consume more and more memory.  I'm not sure why this happens, but I think it is because the memory allocated when the threads are created isn't deallocated when they are joined.  (This is speculation).

The solution to this is to create a batch of threads which will run for the entire life of your program.  Instead of being joined and returning, they instead communicate via queues created using Perl's thread-safe Thread::Queue library.

In the name of full disclosure I need to state that I could not have done this without the pool_reuse.pl example found here. The aim of this article is to supplement the provided example by providing a more verbose explanation, as well as an example where data is received from the threads. 

Several queues are created.  First we make a queue which holds the ids of threads which aren't currently busy.   After this is done, we run through a loop where we create an input queue, an output queue, and a thread.  In our example,  the threads are for functions which add a random number to the input.  The input and output queues are passed as arguments.  The queues are assigned to values in hashes, keyed by the thread ids.

When we want to do actual work, we dequeue an available thread from the thread queue.  We'll then store which thread we are using in a data structure of some kind, and then dequeue  that thread's output queue later.  It is important to keep track of which queues we are using, because dequeue is a blocking operation.  If you try to dequeue an empty queue, it will simply sit there until something has been enqueued.  Depending upon how you've written things, that could be never.


Please see the example below:


#!/usr/bin/perl
use threads;
use threads::shared;
use Thread::Queue;
use strict;

#sentinal variable for threads
my $finished :shared = 0;
#number of threads
my $numThreads = 10;
my %inputQueues;
my %outputQueues;
my $threadQueue = Thread::Queue->new();
for (my $i = 0; $i < $numThreads; $i ++) {
    #create input queue for the thread
    my $inputQueue = Thread::Queue->new();
    #create output queue for the thread
    my $outputQueue = Thread::Queue->new();
    my $thread = threads->new(\&randomAdd,$inputQueue,$outputQueue);
    my $tid = $thread->tid();
    $inputQueues{$tid} = $inputQueue;
    $outputQueues{$tid} = $outputQueue;
}

#signal handler for clean exit

$SIG{'SIGINT'} = $SIG{'SIGTERM'} =
    sub {
        $finished = 1;
        $threadQueue->enqueue(0,-1);
    };

my @initialValues;

#fill up the array with random numbers
for (my $i = 0; $i < 10; $i ++) {
    push @initialValues, int(rand(100));
}

for (my $i = 0; $i < 10; $i ++) {
    print "$i\n";
    my @output;
    my @tids;
    foreach my $value (@initialValues) {
        #dequeue a thread
        my $tid = $threadQueue->dequeue();
        push @tids, $tid;
        $inputQueues{$tid}->enqueue($value);
    }
    foreach my $tid (@tids) {
        push @output, $outputQueues{$tid}->dequeue();
    }
    print "old value     new value\n";
    for (my $j = 0; $j < 10; $j++) {
        print "$initialValues[$j]          $output[$j]\n";
        $initialValues[$j] += $output[$j];   
    }
    print "\n";
    sleep 1;
}
$finished = 1;

foreach my $thread (threads->list()) {
    $inputQueues{$thread->tid()}->enqueue(-1);
    $thread->join();
}
exit(0);




sub randomAdd {
    #add a random number to the data input from the queue.
    #put the results in the output queue
    my ($inputQueue,$outputQueue) = @_;
    my $tid = threads->tid();
    while (! $finished) {
        #put ourselves in the queue so we are avilable
        $threadQueue->enqueue($tid);
        #pull input from queue
        my $inVal = $inputQueue->dequeue();
        if ($inVal >= 0)  {
            my $outVal = $inVal + int(rand(100));
            #enqueue data in output queue
            $outputQueue->enqueue($outVal);   
        } else {
            return;
        }
    }
    return;
}

Sunday, January 8, 2012

DIY Wort Chiller

One of the more annoying parts of the brewing process is waiting for your wort (flavored grain tea, beer to be) to cool off enough to pitch your yeast.  A device called a wort chiller allows you to greatly reduce the time spent doing this.

I'm going to do a little show and tell for the one I just built (entirely from hardware store components), but we're going to need to talk a little bit about thermodynamics first.

All materials have a property called specific heat.  This is how much energy (in Joules) which must be added or removed from a gram of the material in order to change its temperature by one degree Celsius.  For water (which even the heaviest beer consists mainly of) this is 4.186 Joules, which is a lot higher than most things.  A standard five gallon batch of beer will weigh just shy of 19 kilograms.  In order to get it down to yeast pitching temperature you will be trying to lower it from  just below 100 Celsius to around 24 Celsius.  Simple arithmetic dictates that we need to remove about 6 million Joules from your wort.

The other thing about thermodynamics is how heat behaves.  It flows from the areas with the most heat to those with the least until it is evenly distributed throughout the material.  This is why putting ice in your drink cools it off, and why the ice melts.  We're going to build a device to insert into our wort that will absorb heat from it, and carry that heat away.  This will be done by running water through tubing which has been submerged in the wort.

This is a 20' section of 3/8 copper tubing, purchased at a nationwide hardware store that rhymes with Gnome Repo.  My girlfriend and I wrapped it around our kitchen fire extinguisher (it was a two person job).  Enough tubing was left out to allow it to hang over the edge of the fermenter bucket.  We probably could've made it more uniform, but considering that neither of us had ever worked with copper tubing before I think we did a pretty good job.

Now that I had a really cool copper coil, I had to set it up so I could run some water through it.

Here we have a 3/8" Ander-Lign compression fitting attached to the end of the tubing.  A 1/2" pipe nipple then connects the connector for a garden hose.  The Ander-Lign fitting does not require a compression sleeve, you simply fit it to the tubing and apply torque.


Another Ander-Lign fitting is attached to the opposite end of the tubing.  It has a 1/2" to 3/4" adapter installed, so a garden hose can be attached to the output of the wort chiller.  This will allow the water to be used for other purposes (waste not, want not) or simply carry it away from the area.

While testing the chiller for leaks, I found it to be very cold to the touch.  I sincerely hope that it will significantly reduce the time spent waiting for my wort to cool.


Thursday, December 15, 2011

Slinging yourself around the internet

Sometimes your need to use the Internet, but you have a connection you can't exactly trust (coffee shop and hotel wifi come to mind).  In other situations you may feel a need to hide your real IP address, possibly for security reasons.

There are more than a few tools which you can use to do these sort of things.  This post will focus on some of the more popular tools.  I am assuming that you are both running Unix of some kind or other, and know how to use it.  There probably are equivalent tools for Windows, but I am not familiar with them.

I am not going to tell you exactly how to install each and every one of these tools, because it varies from system to system, but I will provide basic information about how to use them.  I also suggest verifying that things are actually working before moving any sensitive information.

Additionally, these tools only work for TCP connections.  UDP will not work.

SSH Tunnels
If you have a Unix system, you probably have SSH installed.   People usually use it  to connect to other machines (pretty much as as an encrypted replacement for telnet) or to copy files from one machine to another.

SSH has a feature that even extremely skilled people are not always familiar with.  You can open a tunnel across the SSH session to another host.  When you start up the tunnel, it opens a port on your local machine.  If you connect to this port, the connection runs across the ssh connection and out the machine you connected to, to a host and port combination you specified when you created the tunnel.

Picture this scenario: you're out of town, and you want to take a look at your bank's web site.  Your only internet connection is an open wifi network, and having played with a sniffer or two in your day, you not want to send your banking information across such a network.  Back at home the router connected to your cable modem is configured to forward SSH to one of your computers (and a dynamic dns entry to go along with it), and a computer running a SOCKS proxy on 192.168.1.7.
You fire up a terminal window and type:
ssh myhomecomputer.dyndns.org -L1081:192.168.1.7:1080 , and then log in as normal.  After that, you configure your web browser to connect to a SOCKS proxy running on port 1081 on your local machine, then browse away.  

Everything your browser does now runs across your strongly encrypted SSH connection.  

It is important to note that you can use tunnels for a lot of things other than SOCKS proxies.  If you want to lock down access to a web based application, you can make a white list consisting of a single host and then open tunnels through that machine.

Proxychains
You now know how to run your applications which allow you to specify a proxy across a tunnel, but not all applications allow you to do that.  This is where a handy tool called  proxychains comes into play.

Proxychains is a pretty powerful tool, it actually allows you to run your connection through a series of different proxy servers.  However, this complexity is outside the scope of this post. If you simply specify a single proxy server (in this case localhost and the port you've opened) in the [ProxyList] section of the config file.  This is enough for basic functionality.


Once this is done, simply type: proxychains [command].  Your application will now seamlessly run across the proxy.

TOR
TOR, or The Onion Router is an anonymity tool originally developed by the US Navy, later the EFF, and currently by the TOR project.  While the technical details of how TOR works should be read about by the user, all that will be mentioned in this post is that TOR encrypts traffic and conceals its source.  When TOR is up and running on a system, it starts a SOCKS proxy that listens on port 9050.  If you point a SOCKS aware application at that port, it should go across the TOR network.
There is a tool similar to Proxychains called torsocks.  It is also used in a very similar manner (torsocks command).

Conclusion
You now have a basic idea of how to securely tunnel through part of the Internet to another part.  Please be aware that a good number of these tools are under constant development, so they may not behave exactly as specified.  The important things to grasp are the concepts of tunnels and proxies.  If those are understood, you should be able to correct for any minor differences encountered.



Wednesday, December 14, 2011

Why root access matters

I have long held the belief that a person should have complete and total control of his digital devices.  While this is largely because I think if a person shells out for a high tech toy, she should be able to run whatever software she likes, tweak any and all settings, and so on.  Some insufficiently suspicious folks called me paranoid when I would mention that without full control of the device, you can't be sure that all the software running on it is benign.

About two weeks ago, it was learned that several cell phone carriers have been shipping Android phones with a hidden application called CarrierIQ installed.  This application can do things like monitor the phone's location via GPS, and check signal quality as well.  In addition to this, it can monitor text messages for specific strings and what URLs have been visited.

Yesterday, the FBI declined a Freedom of Information Act request about the software on the grounds that the information was related to "a pending or prospective law enforcement proceeding".  Today, the EFF reported that they believe keystroke data is being inadvertently transmitted to third parties.


It is important to note that at least some (if not all) of the information CarrierIQ gathers does serve legitimate diagnostic purposes.  In my line of work we occasionally need to perform packet inspection to resolve various network issues.  There is a very large and very real potential for privacy abuse here, but it doesn't happen.  While it is true that there are a variety of policies and procedures to make sure that our customers' privacy is respected, we simply don't have the time to dig through other people's packets. 


Carrier IQ probably is not slinging your text messages and browsing history off to the CIA (that'd be much easier to do on the carrier's network anyway).  None the less, if people had full control of their phones in the first place, this application would not have been hidden, and not gone unnoticed for an undetermined period of time.


Anyone who hides things from you on devices you own or tries to keep you in a walled garden is not your friend.