<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Dabbler &#187; Python</title>
	<atom:link href="http://sethjust.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://sethjust.com</link>
	<description>If it ain&#039;t broke, fix it!</description>
	<lastBuildDate>Sun, 14 Aug 2011 18:56:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Map Tiles with Python + GDAL</title>
		<link>http://sethjust.com/2011/07/13/map-tiles-with-python-gdal/</link>
		<comments>http://sethjust.com/2011/07/13/map-tiles-with-python-gdal/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 21:36:55 +0000</pubDate>
		<dc:creator>sethjust</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[gdal]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://sethjust.com/?p=341</guid>
		<description><![CDATA[After getting GPSDrive running on OS X I started looking into different sources for maps. The GPSDrive wiki has a couple of interesting pages about this: one on creating maps and one on map sources. The second page pointed me to the LibreMap Project which has a complete collection of  USGS 1:24000 (large scale) topographic maps for the [...]]]></description>
			<content:encoded><![CDATA[<p>After <a href="http://sethjust.com/2011/07/13/gpsdrive-on-os-x/">getting GPSDrive running on OS X</a> I started looking into different sources for maps. The GPSDrive wiki has a couple of interesting pages about this: one on <a href="http://sourceforge.net/apps/mediawiki/gpsdrive/index.php?title=Creating_maps">creating maps</a> and one on <a href="http://sourceforge.net/apps/mediawiki/gpsdrive/index.php?title=Data_sources">map sources</a>. The second page pointed me to <a href="http://libremap.org/">the LibreMap Project</a> which has a complete collection of  USGS 1:24000 (large scale) topographic maps for the entire US. These files are distributed as high-resolution GeoTIFF files, along with <a href="http://en.wikipedia.org/wiki/World_file">world files</a>, so the maps are fully geotagged. This means that they contain all of the information needed to generate GPSDrive-friendly map tiles, but GPSDrive will not read them directly. The <a href="http://sourceforge.net/apps/mediawiki/gpsdrive/index.php?title=Creating_maps">creating maps</a> page gives some (heavily out-of-date) advice on how to use the <span style="font-family: monospace;">gdal_slice.sh</span> script distributed with GPSDrive to create map tiles using the tools from <a href="http://gdal.org/">GDAL</a>. Sadly, this script is completely unusable on OS X, because of incompatibilities in the command line tools that are used by the shell script. After spending about five minutes trying to tune it to work with the tools that Apple ships, I completely gave up and looked into other approaches.</p>
<p>Luckily, I quickly found out that GDAL ships with Python bindings. I installed GDAL from <a href="https://trac.osgeo.org/gdal/wiki/DownloadSource">source</a> using the <a href="https://trac.osgeo.org/gdal/wiki/BuildingOnUnix">instructions</a> from their wiki. To make sure it built with Python modules I ran <span style="font-family: monospace;">./configure &#8211;with-python</span>. After that <span style="font-family: monospace;">make</span> and <span style="font-family: monospace;">sudo make install</span> ran without a hitch.</p>
<p>I then set about re-implementing <span style="font-family: monospace;">gdal_slice.sh</span> in Python. Once I got a handle on how to use the Python bindings it was fairly easy to write. You can find the script <a href="http://homepage.sethjust.com/files/gdal_slice.txt">here</a>.</p>
<p>Using <span style="font-family: monospace;">gdal_slice.py</span> is very similar to using <span style="font-family: monospace;">gdal_slice.sh</span>:</p>
<pre>$ ./gdal_slice.py -h
Usage: gdal_slice.py [options] FILENAME

Options:
  -h, --help            show this help message and exit
  -o OVERLAP, --overlap=OVERLAP
                        percentage tiles will overlap. should be at least 20%
  -a, --add             write map info to map_koord.txt in current working
                        directory
  -m, --map             use *_map folders for output; use if input image is
                        UTM. Default behavior
  -t, --topo            use *_top folders for output; use if input image is
                        not UTM
  -v, --verbose         enable debugging output</pre>
<p>The biggest difference is that <span style="font-family: monospace;">gdal_slice.py</span> does not perform any format conversion; it will write maps to TIFF files. Although the file size is decidedly larger than that of PNGs, my version of GDAL is unable to create PNGs, and disk space is (fairly) cheap. If I&#8217;m motivated I&#8217;ll get around to adding a format option, at least to allow conversion to PNG.</p>
<p>Running <span style="font-family: monospace;">gdal_slice.py filename.ext</span> will create a folder named filename_map (or _top, if you use the -t flag) that contains a set of 1280&#215;1024 TIFF files, as well as a map_koord_draft.txt file. Moving this folder into GPSDrive&#8217;s map directory, and merging filename_[map|top]/map_koord_draft.txt with map_koord.txt will make the new maps available to GPSDrive. Note that filename.ext must be in the current working directory, as the script handles filenames/paths somewhat naivëly.</p>
<p>So far I&#8217;ve only tested this with GeoTIFFs from LibreMaps, but it seems to work great, with the caveat that LibreMaps&#8217; files include the borders of map, and my script doesn&#8217;t do any cropping, so you see borders if you&#8217;re near the edges of quads. This doesn&#8217;t bother me terribly much, but you may need to turn mapsets on and off in the Map Control dialog to see the appropriate images.</p>
<p><b>Update 7-14-11:</b> I&#8217;ve modified the script with an additional flag (-a) that will automatically merge the generated map_koords file with map_koord.txt in the current working directory. This means that if you run the script from inside .gpsdrive/maps with the -a flag the generated tiles will be automatically added to GPSDrive&#8217;s database. The script avoids creating duplicate entries in map_koord.txt, as well as alphabetizing all entries.</p>
<p>I&#8217;ve modified the documentation here, as well as the links, to reference the latest version.</p>
]]></content:encoded>
			<wfw:commentRss>http://sethjust.com/2011/07/13/map-tiles-with-python-gdal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Sign your email like Randall Waterhouse</title>
		<link>http://sethjust.com/2011/07/11/sign-your-email-like-randall-waterhouse/</link>
		<comments>http://sethjust.com/2011/07/11/sign-your-email-like-randall-waterhouse/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 00:57:04 +0000</pubDate>
		<dc:creator>sethjust</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[Mail.app]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[thunderbird]]></category>

		<guid isPermaLink="false">http://sethjust.com/?p=307</guid>
		<description><![CDATA[Neal Stephenson&#8217;s novel Cryptonomicon is a fascinating book; I&#8217;m re-reading it for the umpteenth time and loving it every bit as much as when I first read it in 7th grade. One thing that caught my attention on this reading (especially in light of my recent GPS post) is the way that one of the main [...]]]></description>
			<content:encoded><![CDATA[<p>Neal Stephenson&#8217;s novel <em><a href="http://www.amazon.com/gp/product/B004R96U4A/ref=as_li_ss_tl?ie=UTF8&#038;tag=dabbler-20&#038;linkCode=as2&#038;camp=217145&#038;creative=399373&#038;creativeASIN=B004R96U4A">Cryptonomicon</a><img src="http://www.assoc-amazon.com/e/ir?t=&#038;l=as2&#038;o=1&#038;a=B004R96U4A&#038;camp=217145&#038;creative=399373" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></em> is a fascinating book; I&#8217;m re-reading it for the umpteenth time and loving it every bit as much as when I first read it in 7th grade. One thing that caught my attention on this reading (especially in light of my recent <a href="http://sethjust.com/2011/07/10/gpsd-under-os-x-revisited/">GPS post</a>) is the way that one of the main characters, Randall Lawrence Waterhouse, signs his email:</p>
<blockquote><p>Randall Lawrence Waterhouse</p>
<p>Current meatspace coordinates, hot from the GPS receiver card in my laptop:</p>
<p>8 degrees, 52.33 minutes N latitude 117 degrees, 42.75 minutes E longitude</p>
<p>Nearest geographical feature: Palawan, the Philippines</p></blockquote>
<p>(from <a href="http://www.euskalnet.net/larraorma/crypto/slide51.html">http://www.euskalnet.net/larraorma/crypto/slide51.html</a>)</p>
<p>Using GPSd&#8217;s python bindings, and the free, CC-licenced RESTful API from <a href="http://geonames.org">GeoNames.org</a>, I wrote a short python script that will produce a similar output:</p>
<blockquote><p>Seth Just</p>
<p>Current meatspace coordinates, hot from the GPS receiver card in my laptop:</p>
<p>41.751 N latitude, 111.807 W longitude</p>
<p>Nearest geographical feature: Logan Canyon, Utah, United States</p></blockquote>
<p>The core of the script is two functions &#8212; one that gets GPS coordinates from GPSd, and a second that does a lookup for geographical features (mountains, canyons, islands, etc) on <a href="http://geonames.org">GeoNames.org</a>. For more details, see the final section of this post.</p>
<h2>Using gpssig.py</h2>
<p>To use gpssig.py, first download it from <a href="http://homepage.sethjust.com/files/gpssig.txt">here</a>, and change the extension to .py.</p>
<p>In order to be useful as an email signature, I had to produce output in HTML format, which allows almost any mail client to use the output as a signature. I&#8217;ve gone through the effort of setting it up with the two clients I use the most: Mozilla Thunderbird and Apple&#8217;s Mail.app. Of these two, Thunderbird has documented support for HTML signatures (see <a href="http://opensourcearticles.com/thunderbird_15/english/part_03">here</a> for details), and should be the most like other email clients. This script has been tested on Mac OS X Snow Leopard, and should run on Linux without problems (although I haven&#8217;t tried it on versions of python higher than 2.6.1).</p>
<p>Using gpssig.py takes two steps: first configure your Mail client to take a signature from a file, and then configure gpssig.py to run automatically to update that file.</p>
<p>Thunderbird is relatively easy to set up with an HTML signature. Because it only supports one signature per account, you simply need to tell it to draw that signature from a file. Under each account&#8217;s settings there&#8217;s an option to &#8220;Attach the signature from a file&#8221; (see <a href="http://opensourcearticles.com/thunderbird_15/english/part_03">here</a> for a detailed howto). I chose to use ~/.signature.html, but you can use any file you&#8217;d like to, just remember the location you choose.</p>
<p>Mail.app is a more finicky beast &#8212; although the script supports it, I recommend using Thunderbird, mainly because Mail only refreshes its signatures from files on every launch, whereas Thunderbird will read the file each time you compose a message. However, if that limitation is acceptable (if you don&#8217;t move very much, perhaps), it will work just fine. The main issue with Mail.app is that it doesn&#8217;t store signatures in an HTML file, but instead in the proprietary <a href="http://en.wikipedia.org/wiki/Webarchive">.webarchive</a> format. These files can be found in ~/Library/Mail/Signatures. To use gpssig.py with Mail, you need to follow steps 4&amp;5 from <a href="http://bytes.com/topic/macosx/insights/825900-setup-html-signatures-apple-mail-mail-app">http://bytes.com/topic/macosx/insights/825900-setup-html-signatures-apple-mail-mail-app</a>. First create a new signature (under Preferences-&gt;Signatures). This will create a new file in the signature folder &#8212; take note of the file name. You will use this file name to configure gpssig.py.</p>
<p>gpssig.py is configured with command line options:</p>
<pre>Usage: gpssig.py [options] NAME FILENAME
Note: NAME should be enclosed in quotes, unless it contains no spaces.

Options:
  -h, --help   show this help message and exit
  --no-gps     don't attempt to get coordinates from GPS
  -a, --amail  generate files for Apple's Mail.app (.webarchive)
  --lat=LAT    default latitude, if GPS is unavailable
  --lon=LON    default longitude, if GPS is unavailable</pre>
<p>The simplest way to use it is manually &#8212; simply running it whenever you want to update your signature. For example, I use <span style="font-family:monospace;">./gpssig.py &#8211;lat=41.752 &#8211;lon=-111.793 &#8216;Seth Just&#8217; ~/.signature.html</span> to generate a signature for Thunderbird.</p>
<p>If you want to make this automatic, you&#8217;ll need to have the script run automatically. On OS X you&#8217;ll need to use launchd, while on linux you need cron. Both of these make setting up repeating actions very easy &#8212; see <a href="https://arunxjacob.wordpress.com/2008/08/28/mac-launchd-and-launchctl-the-osx-alternative-to-cron/">here</a> for information on launchd and <a href="https://arunxjacob.wordpress.com/2008/08/28/mac-launchd-and-launchctl-the-osx-alternative-to-cron/">here</a> for information on cron.</p>
<p>Sadly I haven&#8217;t yet figured out a way to run the script whenever you write an email &#8212; if I figure it out, I&#8217;ll be sure to post something.</p>
<h2>The Script</h2>
<p>gpssig.py is built around three major functions &#8212; one gets coordinates from GPSd, one gets geographical feature information from</p>
<p>The function I use to get GPS information is a bit hacky &#8212; there doesn&#8217;t seem to be terribly much documentation on GPSd&#8217;s python bindings, so I made do with what I could figure out:</p>

<div class="wp_codebox"><table><tr id="p3074"><td class="code" id="p307code4"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> NoGPSError <span style="color: black;">&#40;</span><span style="color: #008000;">Exception</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">pass</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_lat_lon<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># GPSd Python bindings</span>
  <span style="color: #ff7700;font-weight:bold;">import</span> gps
&nbsp;
  <span style="color: #808080; font-style: italic;"># Create GPS object</span>
  session = gps.<span style="color: black;">gps</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># Set GPS object as an iterator over reports from GPSd</span>
  session.<span style="color: black;">stream</span><span style="color: black;">&#40;</span>gps.<span style="color: black;">WATCH_ENABLE</span>|gps.<span style="color: black;">WATCH_NEWSTYLE</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># Loop until we get a report with lat and lon. The limit of 5 loops should be more than enough -- my gps never takes more than three when it has a lock</span>
  i = <span style="color: #ff4500;">0</span>
  <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">try</span>:
      session.<span style="color: black;">next</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
      lat, lon = session.<span style="color: black;">data</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'lat'</span><span style="color: black;">&#93;</span>, session.<span style="color: black;">data</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'lon'</span><span style="color: black;">&#93;</span>
      <span style="color: #ff7700;font-weight:bold;">break</span>
    <span style="color: #ff7700;font-weight:bold;">except</span>:
      <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>i <span style="color: #66cc66;">&amp;</span>gt<span style="color: #66cc66;">;</span> <span style="color: #ff4500;">5</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">raise</span> NoGPSError 
      i += <span style="color: #ff4500;">1</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">return</span> lat, lon</pre></td></tr></table></div>

<p>The other function is more straightforward &#8212; it makes two http requests to <a href="http://geonames.org">GeoNames.org</a> to get the nearest geographical feature and locality. It then combines those responses in a way that should provide a good response almost anywhere in the world (provided that GeoNames has good, local data). I&#8217;ve tested it with a variety of coordinates (provided by <a href="http://www.getlatlon.com/">http://www.getlatlon.com/</a>), and the responses seem to be pretty good.</p>

<div class="wp_codebox"><table><tr id="p3075"><td class="code" id="p307code5"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> get_geo_string<span style="color: black;">&#40;</span>lat, lon<span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># Modules for REST/XML request from GeoNames</span>
  <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
  <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">xml</span>.<span style="color: black;">etree</span> <span style="color: #ff7700;font-weight:bold;">import</span> ElementTree <span style="color: #ff7700;font-weight:bold;">as</span> ET
&nbsp;
  <span style="color: #808080; font-style: italic;"># Request the name of the nearest geographical feature</span>
  placename = ET.<span style="color: black;">parse</span><span style="color: black;">&#40;</span>
      <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://api.geonames.org/findNearby?lat=&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;&amp;lng=&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lon<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;&amp;featureClass=T&amp;username=sethjust&quot;</span><span style="color: black;">&#41;</span>
      <span style="color: black;">&#41;</span>
  subdiv = ET.<span style="color: black;">parse</span><span style="color: black;">&#40;</span>
      <span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;http://api.geonames.org/countrySubdivision?lat=&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;&amp;lng=&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lon<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;&amp;username=sethjust&quot;</span><span style="color: black;">&#41;</span>
      <span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># Format and return place, region, country</span>
  <span style="color: #ff7700;font-weight:bold;">try</span>:
    country = subdiv.<span style="color: black;">getiterator</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;countryName&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">text</span>
  <span style="color: #ff7700;font-weight:bold;">except</span>:
    <span style="color: #ff7700;font-weight:bold;">try</span>:
      country = placename.<span style="color: black;">getiterator</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;countryName&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">text</span>
    <span style="color: #ff7700;font-weight:bold;">except</span>:
      country = <span style="color: #483d8b;">''</span>
  <span style="color: #ff7700;font-weight:bold;">try</span>:
    region = subdiv.<span style="color: black;">getiterator</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;adminName1&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">text</span>
  <span style="color: #ff7700;font-weight:bold;">except</span>:
    region = <span style="color: #483d8b;">''</span>
  <span style="color: #ff7700;font-weight:bold;">try</span>:
    name = placename.<span style="color: black;">getiterator</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;name&quot;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">text</span>
  <span style="color: #ff7700;font-weight:bold;">except</span>:
    name = <span style="color: #483d8b;">''</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">if</span> country:
    <span style="color: #ff7700;font-weight:bold;">if</span> region:
      <span style="color: #ff7700;font-weight:bold;">if</span> name:
        result = <span style="color: #483d8b;">&quot;%s, %s, %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>name, region, country<span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">else</span>:
        result = <span style="color: #483d8b;">&quot;%s, %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>region, country<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">else</span>:
      <span style="color: #ff7700;font-weight:bold;">if</span> name:
        result = <span style="color: #483d8b;">&quot;%s, %s&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>name, country<span style="color: black;">&#41;</span>
      <span style="color: #ff7700;font-weight:bold;">else</span>:
        result = country
  <span style="color: #ff7700;font-weight:bold;">else</span>:
    result = <span style="color: #483d8b;">&quot;unknown&quot;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">return</span> result</pre></td></tr></table></div>

<p>Finally, the main method of the program parses arguments, determines what coordinates to use, gets the geographical feature string, and then generates the proper HTML and copies it into the correct place.</p>

<div class="wp_codebox"><table><tr id="p3076"><td class="code" id="p307code6"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>__name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span><span style="color: black;">&#41;</span>:
  <span style="color: #808080; font-style: italic;"># Parse command line options</span>
  <span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">optparse</span> <span style="color: #ff7700;font-weight:bold;">import</span> OptionParser
  <span style="color: #dc143c;">parser</span> = OptionParser<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Usage: %prog [options] NAME FILENAME<span style="color: #000099; font-weight: bold;">\n</span>Note: NAME should be enclosed in quotes, unless it contains no spaces.&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;--no-gps&quot;</span>, action=<span style="color: #483d8b;">&quot;store_true&quot;</span>, dest=<span style="color: #483d8b;">&quot;nogps&quot;</span>, default=<span style="color: #008000;">False</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;don't attempt to get coordinates from GPS&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;-a&quot;</span>, <span style="color: #483d8b;">&quot;--amail&quot;</span>, action=<span style="color: #483d8b;">&quot;store_true&quot;</span>, dest=<span style="color: #483d8b;">&quot;amail&quot;</span>, default=<span style="color: #008000;">False</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;generate files for Apple's Mail.app (.webarchive)&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;--lat&quot;</span>, action=<span style="color: #483d8b;">&quot;store&quot;</span>, <span style="color: #008000;">type</span>=<span style="color: #483d8b;">&quot;float&quot;</span>, dest=<span style="color: #483d8b;">&quot;lat&quot;</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;default latitude, if GPS is unavailable&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #dc143c;">parser</span>.<span style="color: black;">add_option</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;--lon&quot;</span>, action=<span style="color: #483d8b;">&quot;store&quot;</span>, <span style="color: #008000;">type</span>=<span style="color: #483d8b;">&quot;float&quot;</span>, dest=<span style="color: #483d8b;">&quot;lon&quot;</span>, <span style="color: #008000;">help</span>=<span style="color: #483d8b;">&quot;default longitude, if GPS is unavailable&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
  options, args = <span style="color: #dc143c;">parser</span>.<span style="color: black;">parse_args</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">try</span>: <span style="color: #ff7700;font-weight:bold;">assert</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>args<span style="color: black;">&#41;</span> == <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">AssertionError</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;You must provide NAME FILENAME<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">print_help</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">try</span>: <span style="color: #ff7700;font-weight:bold;">assert</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>options.<span style="color: black;">lat</span><span style="color: #66cc66;">!</span>=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> <span style="color: black;">&#40;</span>options.<span style="color: black;">lon</span><span style="color: #66cc66;">!</span>=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> | <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>options.<span style="color: black;">lat</span>==<span style="color: #008000;">None</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> <span style="color: black;">&#40;</span>options.<span style="color: black;">lon</span>==<span style="color: #008000;">None</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">AssertionError</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;You must provide both lat and lon arguments<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
    <span style="color: #dc143c;">parser</span>.<span style="color: black;">print_help</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># Modules for creating signature file</span>
  <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">tempfile</span>, <span style="color: #dc143c;">os</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">try</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>options.<span style="color: black;">nogps</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">raise</span> NoGPSError
    lat, lon = get_lat_lon<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Got %f, %f from gps&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>lat, lon<span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">except</span> NoGPSError:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">not</span> options.<span style="color: black;">nogps</span><span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Failed to get coordinates from GPS&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
      <span style="color: #ff7700;font-weight:bold;">assert</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>options.<span style="color: black;">lat</span><span style="color: #66cc66;">!</span>=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">&amp;</span> <span style="color: black;">&#40;</span>options.<span style="color: black;">lon</span><span style="color: #66cc66;">!</span>=<span style="color: #008000;">None</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #008000;">AssertionError</span>:
      <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;No default coordinates provided; exiting&quot;</span>
      exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    lat, lon = options.<span style="color: black;">lat</span>, options.<span style="color: black;">lon</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Using %f, %f as coordinates&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>lat, lon<span style="color: black;">&#41;</span>
&nbsp;
  geostring = get_geo_string<span style="color: black;">&#40;</span>lat, lon<span style="color: black;">&#41;</span>
&nbsp;
  lac, loc = <span style="color: #483d8b;">'N'</span>, <span style="color: #483d8b;">'E'</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> lat <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0</span>:
    lat <span style="color: #66cc66;">*</span>= -<span style="color: #ff4500;">1</span>
    lac = <span style="color: #483d8b;">'S'</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> lon <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">0</span>:
    lon <span style="color: #66cc66;">*</span>= -<span style="color: #ff4500;">1</span>
    loc = <span style="color: #483d8b;">'W'</span>
&nbsp;
  <span style="color: #008000;">file</span> = <span style="color: #dc143c;">tempfile</span>.<span style="color: black;">NamedTemporaryFile</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;html&gt;&lt;body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;p&gt;&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>args<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;p&gt;&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Current meatspace coordinates, hot from the GPS receiver card in my laptop:&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;p&gt;&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%.3f %s latitude, %.3f %s longitude&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>lat, lac, lon, loc<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;p&gt;&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Nearest geographical feature: &quot;</span> + geostring<span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/p&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
  <span style="color: #008000;">file</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;&lt;/html&gt;&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #008000;">file</span>.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>options.<span style="color: black;">amail</span><span style="color: black;">&#41;</span>:
    <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;textutil -convert webarchive -output &quot;</span> + args<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> + <span style="color: #483d8b;">&quot; &quot;</span> + <span style="color: #008000;">file</span>.<span style="color: black;">name</span><span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;cp &quot;</span> + <span style="color: #008000;">file</span>.<span style="color: black;">name</span> + <span style="color: #483d8b;">&quot; &quot;</span> + args<span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://sethjust.com/2011/07/11/sign-your-email-like-randall-waterhouse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>GPSd under OS X (revisited)</title>
		<link>http://sethjust.com/2011/07/10/gpsd-under-os-x-revisited/</link>
		<comments>http://sethjust.com/2011/07/10/gpsd-under-os-x-revisited/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 04:07:27 +0000</pubDate>
		<dc:creator>sethjust</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[gps]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[program]]></category>

		<guid isPermaLink="false">http://sethjust.com/?p=305</guid>
		<description><![CDATA[It&#8217;s been almost 2 and half years since I originally posted about GPSd and OS X. That post got quite a bit of traffic for a while, but a whole lot has changed since then. If you&#8217;re interested in some in-depth background information, you should check out the old post; this post is mostly about [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been almost 2 and half years since I originally posted about <a href="http://sethjust.com/2009/01/13/gpsd-under-os-x/">GPSd and OS X</a>. That post got quite a bit of traffic for a while, but a whole lot has changed since then. If you&#8217;re interested in some in-depth background information, you should check out the old post; this post is mostly about the changes in the GPSd project since then, and the process of getting it running on OS X.</p>
<p>Two and a half years ago, GPSd had just released version 2.38. The latest version, which I just downloaded, is 2.96. Most significantly, GPSd has updated their communication protocol from a simple character-command format to one based on JSON-packed data. Further, they&#8217;ve built a significant portion of the project around python, and consequently built better python interfaces into the project.</p>
<p>OS X has also been updated, from whatever 10.5.x was current three Januaries ago, to 10.6.8. Luckily, the under-the-hood changes that Snow Leopard brought to the table should only make compiling software easier.</p>
<p>Building GPSd is a whole lot easier than it was the last time I went through all of this. I downloaded the latest source package (from <a href="http://prdownload.berlios.de/gpsd/gpsd-2.96bis.tar.gz">http://prdownload.berlios.de/gpsd/gpsd-2.96bis.tar.gz</a>). The bundled INSTALL file lists only python and py-gtk2 as dependencies, which makes compilation easy, given that python comes bundled with OS X. Although py-gtk2 is available through MacPorts (using <span style="font-family: monospace;">sudo port install py-gtk2</span>) I chose to avoid install the ridiculously long list of dependencies that it requires, as it is only required for the graphical test client (xgps), and GPSd also ships the perfectly functional command-line tool cgps, which provides the same information, albeit in a more sparse manner.</p>
<p>The actual build process is surprisingly easy: I ran <span style="font-family: monospace;">./configure &#8211;x-includes=/usr/X11R6/include</span>, as suggested by the INSTALL file. As this indicated no issues, I ran <span style="font-family: monospace;">make</span> and <span style="font-family: monospace;">sudo make install</span>, which ran without a hitch, and gave me a working set of gps tools.</p>
<p>At this point it is possible for me to attach my GPS (see my old post for information about getting devices up and running), run <span style="font-family: monospace;">gpsd -n /dev/cu.usbserial</span>, and then use <span style="font-family: monospace;">cgps</span>to get coordinates, date, and satellite information. However, this isn&#8217;t everything &#8212; all of the python based GPSd tools, such as gpsprof, still don&#8217;t work. This is because of Apple&#8217;s slightly special python distribution &#8212; while GPSd&#8217;s <span style="font-family: monospace;">sudo make install</span> puts python modules into /usr/local/lib/python2.6/site-packages/, they need to be in /Library/Python/2.6/site-packages/. Instead of having to install these manually, you can use the bundled python install script to put the modules in the correct path by running <span style="font-family: monospace;">sudo python setup.py install</span> (thanks to <a href="http://docs.python.org/install/index.html">http://docs.python.org/install/index.html</a>).</p>
<p>Now that I have the most recent GPSd up and running I&#8217;m hoping to do some fun things with it. If I do, you&#8217;ll see it here!</p>
]]></content:encoded>
			<wfw:commentRss>http://sethjust.com/2011/07/10/gpsd-under-os-x-revisited/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Web Laundry, Smart Cards, Python and OS X Smorgasbord</title>
		<link>http://sethjust.com/2011/06/14/laundry-smart-cards/</link>
		<comments>http://sethjust.com/2011/06/14/laundry-smart-cards/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 00:22:11 +0000</pubDate>
		<dc:creator>sethjust</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[laundry]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[smart card]]></category>
		<category><![CDATA[stored value]]></category>

		<guid isPermaLink="false">http://sethjust.com/?p=285</guid>
		<description><![CDATA[Disclaimer: This article is for informational purposes, the author shall not be held liable for any actions taken on the basis of the information presented. I do not condone fraud, theft, or other malfeasance. In September 2010, Hans Viksler posted an article about the insecurity of the stored-value smart card system used by Web Laundry (now [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">Disclaimer: This article is for informational purposes, the author shall not be held liable for any actions taken on the basis of the information presented. I do not condone fraud, theft, or other malfeasance.</span></p>
<p>In September 2010, <a rel="author" href="http://www.blogger.com/profile/09056609859376859009">Hans Viksler</a> posted an <a href="http://ihackiam.blogspot.com/2010/09/web-laundry-insecurity.html">article</a> about the insecurity of the stored-value smart card system used by <a href="http://weblaundry.com/">Web Laundry</a> (now <a href="http://www.washlaundry.com/">Wash Laundry</a>). I&#8217;ll let that article stand on its own &#8212; it gives a good overview of the bone-headed system that the engineers there had in place. In short, they used a secure memory card made by Atmel (specifically, from the CryptoMemory line), the AT88SC0404C (datasheet <a href="http://www.atmel.com/dyn/resources/prod_documents/doc5211.pdf" class="broken_link">here</a>), but neglected to change the default master password. This means that all you need to read or write the stored data is a ISO-7816-3 compliant smart card reader.</p>
<p>This is where my story starts &#8212; this summer I&#8217;m living in a dorm that uses a Web Laundry stored value system. That was enough of a push for me to buy a smart card reader, seeing as I&#8217;d always wanted to play with them, and this looked like a good opportunity. I picked up a smart card reader from Amazon.com, an <a id="static_txt_preview" href="http://www.amazon.com/gp/product/B0012K5P02/ref=as_li_ss_tl?ie=UTF8&amp;tag=dabbler-20&amp;linkCode=as2&amp;camp=217153&amp;creative=399349&amp;creativeASIN=B0012K5P02">SCM Microsystems SCR3310</a>. It was both cheap and, according to the manufacturer&#8217;s <a href="https://www.scmmicro.com/security/view_product_en.php?PID=4">product page</a>, offers full ISO 7816, CCID and PC/SC compatibility (i.e. all of the relevant standards), as well as drivers for OS X, which is my primary operating system for the time being.</p>
<p>Doing some research, it turns out that Apple ships a (modified) version of the open-source <a href="http://pcsclite.alioth.debian.org/">PCSC Lite</a> framework for smart card integration. This means that all I would need to get up and running was a driver for my device and a way to interface it. Once the reader arrived I installed the drivers, and ran pcsctest (from PCSC Lite) on the command line. Sadly, all I got was an error message:</p>
<pre>Testing SCardEstablishContext    : Service not available.</pre>
<p>Googling told me that the appropriate services are supposed to start whenever a smart card reader with appropriate drivers is plugged in, which made this error all the more confusing. Luckily, I found <a href="http://support.scmmicro.com/forum/viewtopic.php?f=10&amp;t=552">this thread</a> on SCM&#8217;s forums &#8212; it seems that the driver they have posted doesn&#8217;t include the USB identifiers for the version of the reader I had, but a helpful poster left instructions to modify a plist file in the driver (mirrored <a href="http://homepage.sethjust.com/files/SCM3310_OSX.html">here</a> for archival purposes). With that, I was up and running!</p>
<p>pcsctest spat out useful output this time around:</p>
<pre>$ pcsctest

MUSCLE PC/SC Lite Test Program

Testing SCardEstablishContext    : Command successful.
Testing SCardGetStatusChange
Please insert a working reader   : Command successful.
Testing SCardListReaders         : Command successful.
Reader 01: SCM SCR 3310 00 00
Enter the reader number          : 1
Waiting for card insertion
                                 : Command successful.
Testing SCardConnect             : Command successful.
Testing SCardStatus              : Command successful.
Current Reader Name              : SCM SCR 3310 00 00
Current Reader State             : 0x34
Current Reader Protocol          : 0x0
Current Reader ATR Size          : 8 (0x8)
Current Reader ATR Value         : 3B B2 11 00 10 80 00 04
Testing SCardDisconnect          : Command successful.
Testing SCardReleaseContext      : Command successful.</pre>
<p>That left me with the issue of interacting with the smart card somehow. In case you hadn&#8217;t guessed from the post title, that solution was Python. Specifically, the pyscard bindings for PCSC Lite, from <a href="http://pyscard.sourceforge.net/">pyscard.sourceforge.net</a>. There&#8217;s a nice array of examples, and so I wrote up a python script for interacting with <em>this particular </em>CryptoMemory card, based on the command set from the datasheet and the examples. It&#8217;s not as polished or feature-rich as the software Hans posted, but if you&#8217;re running OS X or Linux, it should be helpful. At the moment this script is extremely rough &#8212; it gets the job done, but in an ugly and unsafe way. I&#8217;m posting it <a href="http://homepage.sethjust.com/files/CryptoMemory.txt">here</a>, but you <strong>SHOULD NOT USE IT IF YOU DON&#8217;T KNOW WHAT YOU&#8217;RE DOING</strong>. If you aren&#8217;t careful, it will mess up your card. Hopefully I&#8217;ll have time to wrap it all in a library that will abstract away the messiness and provide nice features like exception handling; if I do, you&#8217;ll see it here.</p>
<p>Using my script I was able to verify Hans&#8217; findings &#8212; although the card is configured to require cryptographic authentication to access the user zones (where the goodies can be found), the password is left at the default value, which makes overwriting the access registers and conducting a replay attack (as demonstrated by the video in his post) a walk in the park. Following his example, I won&#8217;t post any information on how the cards store their values, but it&#8217;s surprising that this security hole still isn&#8217;t fixed, seeing as it would cost nothing to overwrite the master password when they first configure the cards.</p>
<p>Hopefully this post will give some of you who&#8217;ve wanted to work with smart cards a push in that direction &#8212; although there are a few hurdles along the way, it&#8217;s an interesting area to work on. I&#8217;m hoping to move on from poking at other people&#8217;s cards and start using my new hardware for authentication and encryption.</p>
<p>Happy hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://sethjust.com/2011/06/14/laundry-smart-cards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Sexy Alphabet Image Generator</title>
		<link>http://sethjust.com/2010/05/31/erotic-alphabet-image-generator/</link>
		<comments>http://sethjust.com/2010/05/31/erotic-alphabet-image-generator/#comments</comments>
		<pubDate>Mon, 31 May 2010 21:58:57 +0000</pubDate>
		<dc:creator>sethjust</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[alphabet]]></category>
		<category><![CDATA[erotic]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[sex]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://sethjust.com/?p=178</guid>
		<description><![CDATA[When my girlfriend came across this erotic alphabet, the first thing she wanted was to be able  to spell out various things with it. Add a pinch of python and php and the result is the Erotic Alphabet Image Generator. The source code of the script used to generate the images is available here.]]></description>
			<content:encoded><![CDATA[<p>When my girlfriend came across <a href="http://sexoteric.com/blog/index.php/__show_article/_a000018-001091.htm">this</a> erotic alphabet, the first thing she wanted was to be able  to spell out various things with it. Add a pinch of python and php and the result is the <a href="http://homepage.sethjust.com/erotic_alphabet/">Erotic Alphabet Image Generator</a>.</p>
<p>The source code of the script used to generate the images is available <a href="http://homepage.sethjust.com/files/erotic_alphabet_image_generator.txt">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sethjust.com/2010/05/31/erotic-alphabet-image-generator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>More Mandelbrot</title>
		<link>http://sethjust.com/2009/12/19/more-mandelbrot/</link>
		<comments>http://sethjust.com/2009/12/19/more-mandelbrot/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 00:27:19 +0000</pubDate>
		<dc:creator>sethjust</dc:creator>
				<category><![CDATA[Math]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[program]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://sethjust.com/?p=122</guid>
		<description><![CDATA[I just recently revisited the M-Set code from my Perl Snippets post. The code I had was pretty ugly, so I decided to rewrite it in Python. The result is not only a lot cleaner and easier to understand, but it&#8217;s also a lot faster: $ time python mandel.py &#62; \dev\null real 0m0.051s user 0m0.036s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sethjust.com/wp-content/uploads/2010/05/mandel_py.png"><img class="alignright size-medium wp-image-222" title="mandel_py" src="http://sethjust.com/wp-content/uploads/2010/05/mandel_py-300x229.png" alt="" width="300" height="229" /></a>I just recently revisited the M-Set code from my <a href="http://sethjust.com/2009/03/24/perl-snippets/">Perl Snippets</a> post. The code I had was pretty ugly, so I decided to rewrite it in Python. The result is not only a lot cleaner and easier to understand, but it&#8217;s also a lot faster:</p>
<pre>$ time python mandel.py &gt; \dev\null
real	0m0.051s
user	0m0.036s
sys	0m0.010s
$ time perl mandel.pl &gt; \dev\null
real	0m3.518s
user	0m3.463s
sys	0m0.029s</pre>
<p>You can find the code <a href="http://homepage.sethjust.com/files/mandel.txt">here</a>.</p>
<p>This script works well for zooms, as long as you stay below a few thousand iterations. The following picture was generated with x=-1.1887204, y=-0.3032472, width=0.01 and 150 iterations.</p>
<p style="text-align: center;"><a href="http://sethjust.com/wp-content/uploads/2009/12/mandel_py_zoom.png"><img class="size-medium wp-image-224 aligncenter" title="mandel_py_zoom" src="http://sethjust.com/wp-content/uploads/2009/12/mandel_py_zoom-300x229.png" alt="" width="300" height="229" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sethjust.com/2009/12/19/more-mandelbrot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

