<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Parody Error</title>
	<atom:link href="http://geremycondra.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://geremycondra.net</link>
	<description>code and commentary</description>
	<lastBuildDate>Thu, 05 May 2011 02:32:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='geremycondra.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/b29491f84003333064558a2be8391b8a?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Parody Error</title>
		<link>http://geremycondra.net</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://geremycondra.net/osd.xml" title="Parody Error" />
	<atom:link rel='hub' href='http://geremycondra.net/?pushpress=hub'/>
		<item>
		<title>Fixing timing attacks in Python</title>
		<link>http://geremycondra.net/2011/04/18/fixing-timing-attacks-in-python/</link>
		<comments>http://geremycondra.net/2011/04/18/fixing-timing-attacks-in-python/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 05:35:23 +0000</pubDate>
		<dc:creator>geremycondra</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://geremycondra.net/?p=65</guid>
		<description><![CDATA[So, a discussion came up on python-mentors about how to fix some of the timing attacks that I talked about in my pycon talk, and specifically how to solve them in a general way. I&#8217;ve previously tried to do this &#8230; <a href="http://geremycondra.net/2011/04/18/fixing-timing-attacks-in-python/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geremycondra.net&amp;blog=7543850&amp;post=65&amp;subd=geremycondra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, a discussion came up on python-mentors about how to fix some of the timing attacks that I talked about in my <a href="http://pycon.blip.tv/file/4879979/">pycon talk</a>, and specifically how to solve them in a general way. I&#8217;ve previously tried to do this using multiprocessing- which works pretty well assuming that you&#8217;re able to fork without biting the memory bullet and that the return value of the function you&#8217;re wrapping is pickleable. If either of those things aren&#8217;t true though, you have a problem- and so I tried today to do it with threading. Here&#8217;s the result:</p>
<p><pre class="brush: python;">
#! /usr/bin/env python3

import time
import queue
import threading
import functools

class ConstantTime:
    &quot;&quot;&quot;Runs for a fixed period of time, then returns no matter what.

    The `timeout` argument specifies, within the limits imposed by the host
    operating system, the amount of time this function will run for.

    The `margin_of_error` argument specifies how long before the timeout to
    begin trying to claw our way back out of the decorated function. It should
    be at least as long as you expect it to take to exit from an arbitrary point 
    in the decorated function.

    Both are specified in seconds.
    &quot;&quot;&quot;

    def __init__(self, timeout=1, margin_of_error=.1):
        self.timeout = timeout
        self.inner_timeout = timeout - margin_of_error

    def __call__(self, f):
        @functools.wraps(f)
        def inner(*args, **kwargs):
            # this will wait for a fixed period of time before join()ing 
            def sleeper(): time.sleep(self.timeout)
        
            # this pushes the return value back up to us
            q = queue.Queue()
            def wrap(*args, **kwargs):
                q.put_nowait(f(*args, **kwargs))

            # create the thread objects
            timed_t = threading.Thread(target=wrap, args=args, kwargs=kwargs)
            timer_t = threading.Thread(target=sleeper)

            # set the daemon flag on the timed thread so we can exit if we must
            timed_t.daemon = True

            # we start the timed thread first and let the margin of error
            # soak up the difference.
            timed_t.start()
            timer_t.start()
            timed_t.join(timeout=self.inner_timeout)
            timer_t.join()

            # now we try to return, blowing up properly if we don't have a legit
            # return value
            try:
                return q.get_nowait()
            except queue.Empty:
                raise Exception(&quot;Exited wrapped function before it completed&quot;)

        # return the wrapped function to complete the decoration
        return inner
</pre></p>
<p>Works ok, right? Not so fast. </p>
<p><pre class="brush: python;">
@ConstantTime(timeout=2)
def f(n):
    return pow(65537, 2 &gt;&gt; n)

@ConstantTime(timeout=2)
def g(n):
    while n:
        time.sleep(1.5)
        n -= 1
</pre></p>
<p>These two things will behave very differently here; the first, which does not release the GIL, will sit and spin no matter how hard we try to get out of it. The second, which does release the GIL, will exit on time. This effectively means that the code above will leak how long the last GIL-locking operation takes after the buzzer if one happens to be occurring when that happens. Not a good sign- and it goes to show you how hard it can be to engineer these things right.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geremycondra.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geremycondra.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geremycondra.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geremycondra.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/geremycondra.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/geremycondra.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/geremycondra.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/geremycondra.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geremycondra.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geremycondra.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geremycondra.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geremycondra.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geremycondra.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geremycondra.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geremycondra.net&amp;blog=7543850&amp;post=65&amp;subd=geremycondra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://geremycondra.net/2011/04/18/fixing-timing-attacks-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9b71dd5e57d30017322d9abc6d353e55?s=96&#38;d=identicon&#38;r=R" medium="image">
			<media:title type="html">geremycondra</media:title>
		</media:content>
	</item>
		<item>
		<title>Playing with Landslide</title>
		<link>http://geremycondra.net/2011/04/10/playing-with-landslide/</link>
		<comments>http://geremycondra.net/2011/04/10/playing-with-landslide/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 22:46:39 +0000</pubDate>
		<dc:creator>geremycondra</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://geremycondra.wordpress.com/?p=46</guid>
		<description><![CDATA[I frequently find myself in the position of needing a fairly good-looking presentation in a big fat hurry, and up till now I&#8217;ve only really had two choices for dealing with that: Write it in Latex, get a great looking &#8230; <a href="http://geremycondra.net/2011/04/10/playing-with-landslide/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geremycondra.net&amp;blog=7543850&amp;post=46&amp;subd=geremycondra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I frequently find myself in the position of needing a fairly good-looking presentation in a big fat hurry, and up till now I&#8217;ve only really had two choices for dealing with that:</p>
<ol>
<li>Write it in Latex, get a great looking presentation three days after I need it.</li>
<li>Use Google Docs, get a terrible looking presentation just in time to have it hated by my audience.</li>
</ol>
<p>Obviously, neither of these is a good option, and when I got scheduled to give a short presentation this last Friday I set out to find an alternative. What I found is called <a title="Landslide" href="https://github.com/adamzap/landslide" target="_blank">Landslide</a>.</p>
<p>So, what is it? Basically it lets you write your slides like a sanely formatted Markdown document and turn them into a web-ready presentation. You can see an example <a title="here" href="http://slides.html5rocks.com/#landing-slide" target="_blank">here</a>. Why am I excited about that? Three reasons:</p>
<ol>
<li>It lets me use Markdown extensions, including justinvh&#8217;s <a title="Latex-Markdown extension" href="https://github.com/justinvh/Markdown-LaTeX" target="_blank">Markdown-Latex extension</a>. That means that I can insert Latex mathematical notation and get Latex-quality results. Excellent!</li>
<li>It produces even better-looking slides than Beamer, and they can include video- a sore point in dealing with Latex.</li>
<li>It&#8217;s ridiculously fast to write- no heavy syntax, no messy \begin{&#8230;} \end{&#8230;}. It&#8217;s like they Huffman coded Latex.</li>
</ol>
<p>So, I&#8217;m quite happy. The only thing I wasn&#8217;t happy about was the PITA that was finding and installing everything on Ubuntu. In the event that anybody&#8217;s interested, here&#8217;s what I had to do:</p>
<p>First, grab landslide (you&#8217;ll need git, setuptools, and <strong>python</strong>-markdown) from the link above. Run the setup script just like you would normally.</p>
<p>After that, you&#8217;ll need to download and install the Latex-Markdown extension. I had to make some minor modifications (available <a title="here" href="https://github.com/debatem1/Markdown-LaTeX" target="_blank">here</a>) to use it, but YMMV. Once you&#8217;ve done that, copy it to your Markdown extensions folder. For me, it was easier just to run:</p>
<p><pre class="brush: bash;">

user@host: ~$ find /usr/lib | grep markdown/extensions

</pre></p>
<p>than to try and reason about where that might actually be. Copy the latex.py file into that directory and make sure its permissions match.</p>
<p>After that, you just have to use Landslide itself. Fortunately, it&#8217;s very easy to use- I just run:</p>
<p><pre class="brush: bash;">

user@host: ~$ landslide -x latex -t tango slides.md

</pre></p>
<p>where slides.md is the path to the Markdown file where my slides are defined and Tango is my preferred theme.</p>
<p>Pretty awesome, really.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geremycondra.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geremycondra.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geremycondra.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geremycondra.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/geremycondra.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/geremycondra.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/geremycondra.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/geremycondra.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geremycondra.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geremycondra.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geremycondra.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geremycondra.wordpress.com/46/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geremycondra.wordpress.com/46/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geremycondra.wordpress.com/46/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geremycondra.net&amp;blog=7543850&amp;post=46&amp;subd=geremycondra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://geremycondra.net/2011/04/10/playing-with-landslide/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9b71dd5e57d30017322d9abc6d353e55?s=96&#38;d=identicon&#38;r=R" medium="image">
			<media:title type="html">geremycondra</media:title>
		</media:content>
	</item>
		<item>
		<title>New blog!</title>
		<link>http://geremycondra.net/2011/04/10/new-blog-2/</link>
		<comments>http://geremycondra.net/2011/04/10/new-blog-2/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 01:02:19 +0000</pubDate>
		<dc:creator>geremycondra</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://geremycondra.wordpress.com/?p=54</guid>
		<description><![CDATA[Trying once again to make this blog thing work. Wish me luck!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geremycondra.net&amp;blog=7543850&amp;post=54&amp;subd=geremycondra&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Trying once again to make this blog thing work. Wish me luck!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/geremycondra.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/geremycondra.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/geremycondra.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/geremycondra.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/geremycondra.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/geremycondra.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/geremycondra.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/geremycondra.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/geremycondra.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/geremycondra.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/geremycondra.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/geremycondra.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/geremycondra.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/geremycondra.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=geremycondra.net&amp;blog=7543850&amp;post=54&amp;subd=geremycondra&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://geremycondra.net/2011/04/10/new-blog-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9b71dd5e57d30017322d9abc6d353e55?s=96&#38;d=identicon&#38;r=R" medium="image">
			<media:title type="html">geremycondra</media:title>
		</media:content>
	</item>
	</channel>
</rss>
