<?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/"
	>

<channel>
	<title>Simon Josefsson&#039;s blog &#187; gnu</title>
	<atom:link href="http://blog.josefsson.org/tag/gnu/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.josefsson.org</link>
	<description></description>
	<lastBuildDate>Thu, 11 Oct 2012 20:32:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F&amp;language=en_US&amp;category=text&amp;title=Simon+Josefsson%26%23039%3Bs+blog&amp;tags=blog" type="text/html" />
		<item>
		<title>Portable Symmetric Key Container (PSKC) Library</title>
		<link>http://blog.josefsson.org/2012/10/11/portable-symmetric-key-container-pskc-library/</link>
		<comments>http://blog.josefsson.org/2012/10/11/portable-symmetric-key-container-pskc-library/#comments</comments>
		<pubDate>Thu, 11 Oct 2012 20:32:10 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[crypto]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[oath]]></category>
		<category><![CDATA[otp]]></category>
		<category><![CDATA[pskc]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=514</guid>
		<description><![CDATA[For the past weeks I have been working on implementing RFC 6030, also known as Portable Symmetric Key Container (PSKC). So what is PSKC? The Portable Symmetric Key Container (PSKC) format is used to transport and provision symmetric keys to <a class="more-link" href="http://blog.josefsson.org/2012/10/11/portable-symmetric-key-container-pskc-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For the past weeks I have been working on implementing <a href="http://tools.ietf.org/html/rfc6030">RFC 6030</a>, also known as Portable Symmetric Key Container (PSKC). So what is PSKC? The Portable Symmetric Key Container (PSKC) format is used to transport and provision symmetric keys to cryptographic devices or software.</p>
<p>My PSKC Library allows you to parse, validate and generate PSKC data. The PSKC Library is written in C, uses <a href="http://www.xmlsoft.org/">LibXML</a>, and is licensed under <a href="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html">LGPLv2+</a>. In practice, PSKC is most commonly used to transport secret keys for OATH HOTP/TOTP devices (and other OTP devices) between the personalization machine and the OTP validation server. Yesterday I released <a href="http://lists.nongnu.org/archive/html/oath-toolkit-help/2012-10/msg00000.html">version 2.0.0</a> of <a href="http://www.nongnu.org/oath-toolkit/">OATH Toolkit</a> with the new PSKC Library. See my earlier <a href="https://blog.josefsson.org/2011/01/20/introducing-the-oath-toolkit/">introduction to OATH Toolkit</a> for background. OATH Toolkit is packaged for Debian/Ubuntu and I hope to refresh the package to include libpskc/pskctool soon.</p>
<p>To get a feeling for the PSKC data format, consider the most minimal valid PSKC data:</p>
<pre>&lt;?xml version="1.0"?&gt;
&lt;KeyContainer xmlns="urn:ietf:params:xml:ns:keyprov:pskc" Version="1.0"&gt;
  &lt;KeyPackage/&gt;
&lt;/KeyContainer&gt;</pre>
<p>The library can easily be used to export PSKC data into a comma-separated value (CSV) format, in fact the <a href="http://www.nongnu.org/oath-toolkit/libpskc-api/pskc-tutorial-quickstart.html">PSKC library tutorial</a> concludes with that as an example. There is complete <a href="http://www.nongnu.org/oath-toolkit/libpskc-api/pskc-reference.html">API documentation</a> for the library. The command line tool is more useful for end-users and allows you to parse and inspect PSKC data. Below is an illustration of how you would use it to parse some PSKC data, first we show the content of a file &#8220;pskc-figure2.xml&#8221;:</p>
<pre>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;KeyContainer Version="1.0"
	      Id="exampleID1"
	      xmlns="urn:ietf:params:xml:ns:keyprov:pskc"&gt;
  &lt;KeyPackage&gt;
    &lt;Key Id="12345678"
         Algorithm="urn:ietf:params:xml:ns:keyprov:pskc:hotp"&gt;
      &lt;Issuer&gt;Issuer-A&lt;/Issuer&gt;
      &lt;Data&gt;
        &lt;Secret&gt;
          &lt;PlainValue&gt;MTIzNA==
          &lt;/PlainValue&gt;
        &lt;/Secret&gt;
      &lt;/Data&gt;
    &lt;/Key&gt;
  &lt;/KeyPackage&gt;
&lt;/KeyContainer&gt;</pre>
<p>Here is how you would parse and pretty print that PSKC data:</p>
<pre>jas@latte:~$ pskctool -c pskc-figure2.xml 
Portable Symmetric Key Container (PSKC):
	Version: 1.0
	Id: exampleID1
	KeyPackage 0:
		DeviceInfo:
		Key:
			Id: 12345678
			Issuer: Issuer-A
			Algorithm: urn:ietf:params:xml:ns:keyprov:pskc:hotp
			Key Secret (base64): MTIzNA==

jas@latte:~$</pre>
<p>For more information, see the <a href="http://www.nongnu.org/oath-toolkit/">OATH Toolkit website</a> and the <a href="http://www.nongnu.org/oath-toolkit/libpskc-api/index.html">PSKC Library Manual</a>.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=514&amp;md5=ba2df03ff5047becc4472a6b6746ac41" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2012/10/11/portable-symmetric-key-container-pskc-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2012%2F10%2F11%2Fportable-symmetric-key-container-pskc-library%2F&amp;language=en_GB&amp;category=text&amp;title=Portable+Symmetric+Key+Container+%28PSKC%29+Library&amp;description=For+the+past+weeks+I+have+been+working+on+implementing+RFC+6030%2C+also+known+as+Portable+Symmetric+Key+Container+%28PSKC%29.+So+what+is+PSKC%3F+The+Portable+Symmetric+Key+Container+%28PSKC%29...&amp;tags=crypto%2Cdebian%2Cgnu%2Coath%2Cotp%2Cpskc%2Csecurity%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Unattended SSH with Smartcard</title>
		<link>http://blog.josefsson.org/2011/10/11/unattended-ssh-with-smartcard/</link>
		<comments>http://blog.josefsson.org/2011/10/11/unattended-ssh-with-smartcard/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 09:34:41 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[debian]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gnupg]]></category>
		<category><![CDATA[openpgp]]></category>
		<category><![CDATA[smartcard]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=413</guid>
		<description><![CDATA[I have several backup servers that run the excellent rsnapshot software, which uses Secure Shell (SSH) for remote access. The SSH private key of the backup server can be a weak link in the overall security. To see how it <a class="more-link" href="http://blog.josefsson.org/2011/10/11/unattended-ssh-with-smartcard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have several backup servers that run the excellent <a href="http://rsnapshot.org/">rsnapshot</a> software, which uses <a href="http://en.wikipedia.org/wiki/Secure_Shell">Secure Shell (SSH)</a> for remote access.  The SSH private key of the backup server can be a weak link in the overall security.  To see how it can be a problem, consider if someone breaks into your backup server and manages to copy your SSH private key, they will now have the ability to login to all machines that you take backups off (and that should be all of your machines, right?).</p>
<p>The traditional way to mitigate SSH private key theft is by password protecting the private key.  This works poorly in an unattended server environment because either the decryption password needs to be stored in disk (where the attacker can read it) or the decrypted private key has to be available in decrypted form in memory (where attacker can read it).</p>
<p>A better way to deal with the problem is to move the SSH private key to a smartcard.  The idea is that the private key cannot be copied by an attacker who roots your backup server.  (Careful readers may have spotted a flaw here, and I need to explain one weakness with my solution: an attacker will still be able to login to all your systems by going through your backup server, however it will require an open inbound network connection to your backup server and the attacker will never know what your private key is.  What this does is to allow you to more easily do damage control by removing the smartcard from the backup server.)</p>
<p>In this writeup, I&#8217;ll explain how to accomplish all this on a <a href="http://www.debian.org/">Debian</a>/<a href="http://www.ubuntu.com/">Ubuntu</a>-system using a <a href="http://g10code.com/p-card.html">OpenPGP smartcard</a>, a <a href="http://www.gemalto.com/products/pc_link_readers/#USB_Shell_Token_v2">Gemalto USB Shell Token v2</a> with gpg-agent/scdaemon from <a href="http://www.gnupg.org/">GnuPG</a> together with <a href="http://www.openssh.org/">OpenSSH</a>.<br />
<img src="http://www.gemalto.com/products/pc_link_readers/download/blackcaseopened.jpg"><br />
<span id="more-413"></span><br />
First we need to install some packages.  The goal is to configure <a href="http://www.openssh.org/">OpenSSH</a> to talk to the <a href="http://www.gnupg.org/documentation/manuals/gnupg-devel/Invoking-GPG_002dAGENT.html">gpg-agent</a> which will start and talk to <a href="http://www.gnupg.org/documentation/manuals/gnupg-devel/Invoking-SCDAEMON.html">scdaemon</a> which in turn talks to <a href="http://pcsclite.alioth.debian.org/pcsclite.html">pcscd</a> which talks to the smart card reader.  For some strange reason, the scdaemon binary is shipped with GnuPG&#8217;s S/MIME interface in the <a href="http://packages.debian.org/sid/gpgsm">gpgsm</a> package.</p>
<pre>
# apt-get install pcscd gnupg-agent gpgsm
</pre>
<p>The above command should install and start <code>pcscd</code> and if all works well, you should be able to check the status of the smartcard using GnuPG.</p>
<pre>
# gpg --card-status
</pre>
<p>You need to initialize the smartcard and generate a private key on it, again using GnuPG.  If you trust GnuPG more than the smartcard to generate a good private key, you may generate the private key using GnuPG and then move it onto the smartcard (hint: use the <code>keytocard</code> command). Make sure you don&#8217;t leave a copy of the private key on the same machine!</p>
<pre>
# gpg --card-edit
gpg: detected reader `Gemalto GemPC Key 00 00'
...
gpg/card&gt; admin
Admin commands are allowed

gpg/card&gt; name
Cardholder's surname: 
Cardholder's given name: host.example.org
gpg: 3 Admin PIN attempts remaining before card is permanently locked

Please enter the Admin PIN
gpg: gpg-agent is not available in this session
                 
gpg/card&gt; lang
Language preferences: en

gpg/card&gt; generate
Make off-card backup of encryption key? (Y/n) n

Please enter the PIN
What keysize do you want for the Signature key? (2048) 
What keysize do you want for the Encryption key? (2048) 
What keysize do you want for the Authentication key? (2048) 
Please specify how long the key should be valid.
         0 = key does not expire
      &lt;n&gt;  = key expires in n days
      &lt;n&gt;w = key expires in n weeks
      &lt;n&gt;m = key expires in n months
      &lt;n&gt;y = key expires in n years
Key is valid for? (0) 
Key does not expire at all
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) &lt;heinrichh@duesseldorf.de&gt;"

Real name: host.example.org
Email address: 
Comment: 
You selected this USER-ID:
    "host.example.org"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
gpg: existing key will be replaced
gpg: please wait while key is being generated ...
gpg: key generation completed (33 seconds)
gpg: signatures created so far: 0
gpg: existing key will be replaced
gpg: please wait while key is being generated ...
gpg: key generation completed (18 seconds)
gpg: signatures created so far: 1
gpg: signatures created so far: 2
gpg: existing key will be replaced
gpg: please wait while key is being generated ...
gpg: key generation completed (23 seconds)
gpg: signatures created so far: 3
gpg: signatures created so far: 4
gpg: key 12345678 marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   1  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 1u
pub   2048R/12345678 2011-09-19
      Key fingerprint = 1234 5678 1234 5678 1234  5678 1234 5678 1234 5678
uid                  host.example.org
sub   2048R/23456789 2011-09-19
sub   2048R/34567890 2011-09-19


gpg/card&gt; quit
# 
</pre>
<p>Now for the interesting part.  OpenSSH talks to an agent for private key handling, and GnuPG&#8217;s gpg-agent supports this protocol when the <code>--enable-ssh-support</code> parameter is given.  During startup, gpg-agent will print some environment variables that needs to be set when <code>ssh</code> is run.  Normally gpg-agent is invoked by the Xsession.d login scripts, so that the environment variables are inherited by all your processes.  However, for an unattended machine without any normal login process, we need to write a script to start gpg-agent.  First do these manual steps, to confirm that everything works.</p>
<pre>
# gpg-agent --daemon --enable-ssh-support > /var/run/gpg-agent-info.env
# . /var/run/gpg-agent-info.env
# ssh-add -L
ssh-rsa AAAAB3N... cardno:000500000BD8
#
</pre>
<p>If the final step printed a SSH public id, the (sometimes) tricky part in getting the hardware to work is (hopefully) complete.  What remains is to script things so that <code>gpg-agent</code> is started on boot and to make sure that your backup scripts has the proper environment variables before launching whatever processes will launch <code>ssh</code>.  Further, since we will be running unattended, we need a mechanism to unlock the smartcard using a PIN interactively once on each boot of the machine.  I prefer manually entering the PIN on every boot over having the PIN stored in a file on the disk.</p>
<p>I will use the <code>/etc/rc.local</code> mechanism to start gpg-agent, like this:</p>
<pre>
# cat> /etc/rc.local 
#!/bin/sh -e
exec gpg-agent --daemon --enable-ssh-support 
    --pinentry-program /usr/local/sbin/pinentry-unattended 
    --write-env-file /var/run/gpg-agent-info.env
^D
</pre>
<p>The astute reader will now ask what <code>/usr/local/sbin/pinentry-unattended</code> is and why it is needed.  Now here is the situation. scdaemon will normally query the user for a PIN using a tool called <code>pinentry</code> which reads and write to the user&#8217;s TTY directly.  This won&#8217;t work in unattended mode, so we want the scdaemon to signal failure here &#8212; unless we are actually unlocking the smartcard manually.  Here is the entire script:</p>
<pre>
#!/bin/sh
# /usr/local/sbin/pinentry-unattended -- by Simon Josefsson
if test x"$PINENTRY_USER_DATA" = xinteractive; then
    exec pinentry "$@"
fi
exit 1
</pre>
<p>What remains is a script to unlock the smartcard by providing the PIN.  This is typically invoked manually if the server has restarted for some reason.  Don&#8217;t worry, any ssh sessions invoked by cron until you have managed to unlock the smartcard will fail with an authentication error &#8212; it won&#8217;t hang waiting for a PIN to be entered.</p>
<pre>
#!/bin/sh
# /usr/local/sbin/unlock-smartcard -- by Simon Josefsson.
. /var/run/gpg-agent-info.env; export GPG_AGENT_INFO SSH_AUTH_SOCK SSH_AGENT_PID
gpg-connect-agent 'scd killscd' /bye > /dev/null
while ! gpg-connect-agent 'scd serialno' /bye | grep -q SERIALNO; do
    sleep 1
done
PINENTRY_USER_DATA=interactive
export PINENTRY_USER_DATA
checkpin
</pre>
<p>And the script <code>checkpin</code> is as follows:</p>
<pre>
#!/bin/sh
# /usr/local/sbin/checkpin -- by Simon Josefsson.
id=`gpg-connect-agent 'scd serialno' /bye | head -1 | cut -d  -f3`
gpg-connect-agent "scd checkpin $id" /bye | grep -q OK
</pre>
<p>At this point, you should have everything configured and installed.  Don&#8217;t forget to <code>chmod +x</code> the scripts.  The typical use-pattern is as follows.  After the machine has been started, gpg-agent is running but the smartcard is not unlocked with the PIN.  You need to manually login to the machine and run &#8216;unlock-smartcard&#8217; and enter the PIN.  In the script that runs the backup jobs, invoked via cron, make sure that the first line of the scripts reads (assuming Bourne shell script syntax):</p>
<pre>
. /var/run/gpg-agent-info.env; export GPG_AGENT_INFO SSH_AUTH_SOCK SSH_AGENT_PID
</pre>
<p>To avoid needlessly attempting ssh connections if the smartcard is not unlocked, your backup script can also call the <code>checkpin</code> code and abort if it doesn&#8217;t return true.</p>
<pre>
checkpin || exit 1
</pre>
<p>Some final words about debugging.  A basic command to run to check that the GnuPG side is working is <code>gpg --card-status</code>, it should print some information about the smartcard if successful.  To check that the SSH agent part is working, use <code>ssh-add -L</code>.   If you get error messages, try killing the <code>scdaemon</code> process by running <code>killall -9 scdaemon</code> and let <code>gpg-agent</code> respawn a new <code>scdaemon</code> process.</p>
<p>That&#8217;s it!  If you like my writeup, please flattr it. <img src='http://blog.josefsson.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=413&amp;md5=d00761ad67a832bbd4d0b66e4905c99c" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2011/10/11/unattended-ssh-with-smartcard/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2011%2F10%2F11%2Funattended-ssh-with-smartcard%2F&amp;language=en_GB&amp;category=text&amp;title=Unattended+SSH+with+Smartcard&amp;description=I+have+several+backup+servers+that+run+the+excellent+rsnapshot+software%2C+which+uses+Secure+Shell+%28SSH%29+for+remote+access.+The+SSH+private+key+of+the+backup+server+can+be+a...&amp;tags=debian%2Cgnu%2Cgnupg%2Copenpgp%2Csecurity%2Csmartcard%2Cssh%2Cubuntu%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Introducing the OATH Toolkit</title>
		<link>http://blog.josefsson.org/2011/01/20/introducing-the-oath-toolkit/</link>
		<comments>http://blog.josefsson.org/2011/01/20/introducing-the-oath-toolkit/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 16:09:37 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[hotp]]></category>
		<category><![CDATA[ietf]]></category>
		<category><![CDATA[oath]]></category>
		<category><![CDATA[oath toolkit]]></category>
		<category><![CDATA[ocra]]></category>
		<category><![CDATA[totp]]></category>
		<category><![CDATA[two-factor]]></category>
		<category><![CDATA[yubikey]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=317</guid>
		<description><![CDATA[I am happy to announce a project that I have been working quietly on for about a year: the OATH Toolkit. OATH stands for Open AuTHentication and is an organization that specify standards around authentication. That is a pretty broad <a class="more-link" href="http://blog.josefsson.org/2011/01/20/introducing-the-oath-toolkit/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I am happy to announce a project that I have been working quietly on for about a year: the <a href="http://www.nongnu.org/oath-toolkit/">OATH Toolkit</a>.  OATH stands for <a href="http://www.openauthentication.org/">Open AuTHentication</a> and is an organization that specify standards around authentication.  That is a pretty broad focus, but practically it has translated into work on specifying standards around deploying and using electronic token based user authentication such as the <a href="http://www.yubico.com/">YubiKey</a>.</p>
<p><center><img src="http://static.yubico.com/var/uploads/press/_press_yubikeyandkeys_.jpg" alt="YubiKey" width="140" height="60"/></center></p>
<p>OATH&#8217;s most visible specification has been the HOTP algorithm which is a way to generate event-based <a href="http://en.wikipedia.org/wiki/One-time_password">one-time passwords</a> from a shared secret using HMAC-SHA1.   HOTP has been published through the <a href="http://www.ietf.org/">IETF</a> as <a href="http://tools.ietf.org/html/rfc4226">RFC 4226</a>.  Built on top of HOTP is the time-based variant called TOTP, which requires a clock in the token.  OATH do some other work too, like specifying a data format for transferring the token configuration data (e.g., serial number and shared secret) called PSKC.<br />
<span id="more-317"></span><br />
The aim of my project OATH Toolkit is to provide an implementation of various OATH related technologies.  I&#8217;m intentionally leaving it open ended because you never know what they may specify that I find interesting.  However, the primary goal has been to focus on HOTP and TOTP.  Throughout 2010, the project was called HOTP Toolkit but that name made it difficult to support TOTP in a non-confusing way. During the last month, after discussion with <a href="http://www.dynalogin.org/">Daniel Pocock on Dynalogin</a> which is a potential consumer of my package, I took the time to create a fork of the HOTP Toolkit and the OATH Toolkit was born.</p>
<p>Now what does the OATH Toolkit actually do?  Primarily it provides a library called <b>liboath</b> that implements HOTP and TOTP.  Liboath is a relatively small library, and my goal is to keep it well documented and of high quality.  There is <a href="http://www.nongnu.org/oath-toolkit/reference/liboath-oath.html">GTK-DOC generated API documentation</a>.  Of course there is a command line tool to go with it, called <b>oathtool</b> which makes working with HOTP/TOTP from the command line easier.  It can generate and validate one-time passwords.  Let&#8217;s say you want to generate the first four OTP based on the dummy key 1234.</p>
<blockquote><p>jas@latte:~$ oathtool -w4 1234<br />
376439<br />
299783<br />
041392<br />
819202<br />
158134<br />
jas@latte:~$
</p></blockquote>
<p>By default the tool is using HOTP, but you can switch it into TOTP mode with the <b>&#8211;totp</b> parameter.  The output OTP will now depend on the current time on your machine, unless you specify the time manually using the <b>&#8211;now</b> parameter.</p>
<blockquote><p>jas@latte:~$ oathtool &#8211;now=&#8221;2011-01-20 15:46 UTC&#8221; &#8211;totp 1234<br />
527971<br />
jas@latte:~$
</p></blockquote>
<p>The tool can do more, check the <a href="http://www.nongnu.org/oath-toolkit/man-oathtool.html">oathtool man page</a> for all the details.</p>
<p>The final component of the OATH Toolkit is a PAM module <b>pam_oath</b>.  With it, you can login to your machine using an OTP and optionally a password.  Right now the user and password management is simplistic, but that should improve over time.  To setup single-factor authentication for <b>su</b> you would create a file containing the user information and HOTP key as /etc/users.oath like this:</p>
<blockquote><p>HOTP root &#8211; 1234</p></blockquote>
<p>Then configure PAM to use the pam_oath module like this in /etc/pam.d/su:</p>
<blockquote><p>auth requisite pam_oath.so debug usersfile=/etc/users.oath window=20
</p></blockquote>
<p>The user file will be rewritten every time you <b>su</b> to hold the current state.  There is a <a href="http://git.savannah.gnu.org/cgit/oath-toolkit.git/tree/pam_oath/README">README for the PAM-module</a> with more documentation.</p>
<p>That&#8217;s it for an intro!  From the <a href="http://www.nongnu.org/oath-toolkit/">OATH Toolkit webpage</a> we link to binary packages for <a href="http://www.debian.org/">Debian</a> and <a href="http://www.ubuntu.com/">Ubuntu</a> so please try the OATH Toolkit yourself and provide feedback to the <a href="http://lists.nongnu.org/mailman/listinfo/oath-toolkit-help">oath-toolkit-help mailing list</a>.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=317&amp;md5=485d8c1eeb2f1540768ab7f0f980efad" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2011/01/20/introducing-the-oath-toolkit/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2011%2F01%2F20%2Fintroducing-the-oath-toolkit%2F&amp;language=en_GB&amp;category=text&amp;title=Introducing+the+OATH+Toolkit&amp;description=I+am+happy+to+announce+a+project+that+I+have+been+working+quietly+on+for+about+a+year%3A+the+OATH+Toolkit.+OATH+stands+for+Open+AuTHentication+and+is+an+organization...&amp;tags=gnu%2Chotp%2Cietf%2Coath%2Coath+toolkit%2Cocra%2Csecurity%2Ctotp%2Ctwo-factor%2Cyubikey%2Cblog" type="text/html" />
	</item>
		<item>
		<title>GNU SASL with SCRAM-SHA-1-PLUS</title>
		<link>http://blog.josefsson.org/2010/11/17/gnu-sasl-with-scram-sha-1-plus/</link>
		<comments>http://blog.josefsson.org/2010/11/17/gnu-sasl-with-scram-sha-1-plus/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 23:24:48 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[gsasl]]></category>
		<category><![CDATA[ietf]]></category>
		<category><![CDATA[sasl]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[scram]]></category>
		<category><![CDATA[tls]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=224</guid>
		<description><![CDATA[I have finished the SCRAM implementation in GNU SASL. The remaining feature to be added were support for the &#8220;enhanced&#8221; SCRAM-SHA-1-PLUS variant instead of just the normal SCRAM-SHA-1 mechanism. The difference is that the latter supports channel bindings to TLS, <a class="more-link" href="http://blog.josefsson.org/2010/11/17/gnu-sasl-with-scram-sha-1-plus/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have finished the <a href="http://www.gnu.org/software/gsasl/manual/html_node/SCRAM_002dSHA_002d1.html">SCRAM</a> implementation in <a href="http://www.gnu.org/software/gsasl/">GNU SASL</a>.  The remaining feature to be added were support for the &#8220;enhanced&#8221; SCRAM-SHA-1-PLUS variant instead of just the normal SCRAM-SHA-1 mechanism.  The difference is that the latter supports channel bindings to TLS, which makes it possible to detect man-in-the-middle attacks even if TLS is not used with server authentication.  In <a href="http://www.gnutls.org/">GnuTLS</a> we recently added an API for applications to extract channel bindings, which you will need to use in order to use SCRAM-SHA-1-PLUS.  I announced the experimental <a href="http://lists.gnu.org/archive/html/help-gsasl/2010-11/msg00004.html">version 1.5.4 release</a> together with a <a href="http://lists.gnu.org/archive/html/help-gsasl/2010-11/msg00005.html">writeup on how to test it</a>.  With this, our support for SCRAM should be complete.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=224&amp;md5=6240d8f89c1cd47151326265bf44a94c" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2010/11/17/gnu-sasl-with-scram-sha-1-plus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2010%2F11%2F17%2Fgnu-sasl-with-scram-sha-1-plus%2F&amp;language=en_GB&amp;category=text&amp;title=GNU+SASL+with+SCRAM-SHA-1-PLUS&amp;description=I+have+finished+the+SCRAM+implementation+in+GNU+SASL.+The+remaining+feature+to+be+added+were+support+for+the+%26%238220%3Benhanced%26%238221%3B+SCRAM-SHA-1-PLUS+variant+instead+of+just+the+normal+SCRAM-SHA-1+mechanism.+The...&amp;tags=gnu%2Cgsasl%2Csasl%2Cscram%2Ctls%2Cblog" type="text/html" />
	</item>
		<item>
		<title>GS2-KRB5 using GNU SASL and MIT Kerberos for Windows</title>
		<link>http://blog.josefsson.org/2010/09/27/gs2-krb5-using-gnu-sasl-and-mit-kerberos-for-windows/</link>
		<comments>http://blog.josefsson.org/2010/09/27/gs2-krb5-using-gnu-sasl-and-mit-kerberos-for-windows/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 12:14:58 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[gsasl]]></category>
		<category><![CDATA[ietf]]></category>
		<category><![CDATA[kerberos]]></category>
		<category><![CDATA[sasl]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gs2-krb5]]></category>
		<category><![CDATA[gss-api]]></category>
		<category><![CDATA[kfw]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=162</guid>
		<description><![CDATA[I have blogged about GNU SASL and GS2-KRB5 with the native Kerberos on Mac OS X before, so the next logical step has been to support GS2-KRB5 on Windows through MIT Kerberos for Windows (KfW). With the latest release of <a class="more-link" href="http://blog.josefsson.org/2010/09/27/gs2-krb5-using-gnu-sasl-and-mit-kerberos-for-windows/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have blogged about <a href="http://blog.josefsson.org/2010/03/31/gs2-krb5-in-gnu-sasl-150/">GNU SASL and GS2-KRB5 with the native Kerberos on Mac OS X</a> before, so the next logical step has been to support GS2-KRB5 on Windows through MIT Kerberos for Windows (KfW).  With the latest release of <a href="http://lists.gnu.org/archive/html/help-gsasl/2010-09/msg00001.html">GNU SASL 1.5.2</a> I have added support for the KfW GSS-API library.  There were several issues in completing this due to problems with KfW, but I won&#8217;t bore you with those details.</p>
<p>What is important is to demonstrate how GNU SASL can now talk IMAP authenticated with GS2-KRB5 using KfW on native Windows.<span id="more-162"></span>  Below are two screenshots. The first shows how the MIT Network Identity Manager is invoked automatically to get a ticket.  The next screenshot is showing the completed GS2-KRB5 login.<br />
<img src="http://josefsson.org/gsasl4win/gsasl-kfw3.png" alt="GSASL+KFW+GS2-KRB5 part 1" /><br />
<img src="http://josefsson.org/gsasl4win/gsasl-kfw4.png" alt="GSASL+KFW+GS2-KRB5 part 2" /></p>
<p>I have prepared <a href="http://josefsson.org/gsasl4win/">GNU SASL with KfW binaries</a>.  The manual contains a new section about <a href="http://www.gnu.org/software/gsasl/manual/html_node/Kerberos-on-Windows.html">Kerberos on Windows</a> with details how to build it.  The <a href="http://josefsson.org/gsasl4win/Makefile">build makefile</a> is available too, if you want to build your own.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=162&amp;md5=c51c93f75973d6680b2d589029cefe2f" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2010/09/27/gs2-krb5-using-gnu-sasl-and-mit-kerberos-for-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2010%2F09%2F27%2Fgs2-krb5-using-gnu-sasl-and-mit-kerberos-for-windows%2F&amp;language=en_GB&amp;category=text&amp;title=GS2-KRB5+using+GNU+SASL+and+MIT+Kerberos+for+Windows&amp;description=I+have+blogged+about+GNU+SASL+and+GS2-KRB5+with+the+native+Kerberos+on+Mac+OS+X+before%2C+so+the+next+logical+step+has+been+to+support+GS2-KRB5+on+Windows+through...&amp;tags=gnu%2Cgs2-krb5%2Cgsasl%2Cgss-api%2Ckerberos%2Ckfw%2Cwindows%2Cblog" type="text/html" />
	</item>
		<item>
		<title>GS2-KRB5 in GNU SASL 1.5.0</title>
		<link>http://blog.josefsson.org/2010/03/31/gs2-krb5-in-gnu-sasl-150/</link>
		<comments>http://blog.josefsson.org/2010/03/31/gs2-krb5-in-gnu-sasl-150/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 23:10:22 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[gsasl]]></category>
		<category><![CDATA[ietf]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gs2]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[sasl]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=147</guid>
		<description><![CDATA[I have worked in the IETF on the specification for the next generation GSSAPI-to-SASL bridge called GS2 (see my status page for background) for a couple of years now. The specification is (finally!) in the RFC editor&#8217;s queue, and is <a class="more-link" href="http://blog.josefsson.org/2010/03/31/gs2-krb5-in-gnu-sasl-150/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have worked in the <a href="http://www.ietf.org/">IETF</a> on the specification for the next generation GSSAPI-to-SASL bridge called GS2 (see <a href="http://josefsson.org/sasl-gs2/">my status page</a> for background) for a couple of years now.   The specification is (finally!) in the RFC editor&#8217;s queue, and is supposed to be stable and final although we are still tuning some details.  The next step is to implement the protocol and do interop testing.  A couple of months of implementation and testing work culminated in tonight&#8217;s release of GNU SASL 1.5.0 (see announcement <a href="http://lists.gnu.org/archive/html/help-gsasl/2010-03/msg00014.html">here</a>).  Or should I say that the work can now begin&#8230;<br />
<span id="more-147"></span><br />
To get you started with GS2-KRB5 here is a brief walk-through on installing GNU SASL 1.5.0 on a Mac OS X machine and using it to connect to my GS2-KRB5 interop server.  I&#8217;m assuming you have already installed a compiler on your system.  Start by downloading and installing GNU SASL:</p>
<pre>
wget -q ftp://alpha.gnu.org/gnu/gsasl/gsasl-1.5.0.tar.gz
tar xfz gsasl-1.5.0.tar.gz 
cd gsasl-1.5.0
./configure --prefix=$HOME CFLAGS=-g
make all check install
</pre>
<p>Next you need to configure Kerberos on your system.  If you have already have a configuration, make sure to take a backup of your configuration files.  First let&#8217;s tell your machine about my interop Kerberos V5 realm by creating a file ~/Library/Preferences/edu.mit.Kerberos with the following content:</p>
<pre>
[libdefaults]
        default_realm = interop.josefsson.org

[realms]
        interop.josefsson.org = {
                kdc = interop.josefsson.org:88
        }

[domain_realm]
        interop.josefsson.org = interop.josefsson.org
</pre>
<p>Next get a ticket for a dummy user.  Use the password &#8216;pass&#8217; at the prompt:</p>
<pre>
espresso:~ jas$ kinit user@interop.josefsson.org
Please enter the password for user@interop.josefsson.org: 
espresso:~ jas$ klist
Kerberos 5 ticket cache: 'API:Initial default ccache'
Default principal: user@interop.josefsson.org

Valid Starting     Expires            Service Principal
03/31/10 00:59:04  03/31/10 10:59:02  krbtgt/interop.josefsson.org@interop.josefsson.org
	renew until 01/01/70 01:00:00

klist: No Kerberos 4 tickets in credentials cache
espresso:~ jas$ 
</pre>
<p>Next connect to my test IMAP server using the command-line &#8216;gsasl&#8217; tool (long lines cut for legibility):</p>
<pre>
espresso:~ jas$ ~/bin/gsasl interop.josefsson.org -auser
Trying `interop.josefsson.org'...
* OK IMAP4rev1
. CAPABILITY
* CAPABILITY ... AUTH=GS2-KRB5
. OK CAPABILITY Completed
. AUTHENTICATE GS2-KRB5
+ 
biwsAQBuggINMIICCa...
+ YHEGCSqGSIb3EgEC...

. OK AUTHENTICATE GS2-KRB5 authentication successful
Client authentication finished (server trusted)...
Enter application data (EOF to finish):
. list "" "*"
* LIST (NoInferiors) NIL INBOX
* LIST (NoInferiors) "/" .bashrc
* LIST (NoInferiors) "/" .bash_logout
* LIST (NoInferiors) "/" .profile
* LIST (NoInferiors) "/" .bash_history
. OK LIST Completed
. logout
* BYE Session terminating.
. OK LOGOUT Completed
Session finished...
. LOGOUT
espresso:~ jas$ 
</pre>
<p>There!  You have just completed a GS2-KRB5 authenticated session.</p>
<p>Of course, this works just as well on your favorite GNU/Linux system, but I thought I&#8217;d explain it for a non-GNU platform and GSS-API library to show that the code is quite portable despite its experimental status.</p>
<p>Btw, the server is running <a href="http://www.gnu.org/software/shishi/">GNU Shishi</a> as the Kerberos V5 KDC and <a href="http://www.gnu.org/software/mailutils/">GNU MailUtils</a> as the IMAP server.  The IMAP server is using GNU SASL in server mode.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=147&amp;md5=6c43a2f659823137c02bc45069de7e44" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2010/03/31/gs2-krb5-in-gnu-sasl-150/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2010%2F03%2F31%2Fgs2-krb5-in-gnu-sasl-150%2F&amp;language=en_GB&amp;category=text&amp;title=GS2-KRB5+in+GNU+SASL+1.5.0&amp;description=I+have+worked+in+the+IETF+on+the+specification+for+the+next+generation+GSSAPI-to-SASL+bridge+called+GS2+%28see+my+status+page+for+background%29+for+a+couple+of+years+now.+The...&amp;tags=gnu%2Cgs2%2Cgsasl%2Chowto%2Cietf%2Csasl%2Csecurity%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Fellowship interview</title>
		<link>http://blog.josefsson.org/2010/01/08/fellowship-interview/</link>
		<comments>http://blog.josefsson.org/2010/01/08/fellowship-interview/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 14:01:18 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[advocacy]]></category>
		<category><![CDATA[fsf]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=144</guid>
		<description><![CDATA[At FSCONS I met Stian Rødven Eide who is doing a series of fellowship interviews for FSF Europe. He recently posted an interview with me.]]></description>
			<content:encoded><![CDATA[<p>At <a href="http://fscons.org/">FSCONS</a> I met Stian Rødven Eide who is doing a series of <a href="http://blogs.fsfe.org/fellowship-interviews/">fellowship interviews</a> for <a href="http://www.fsfe.org/">FSF Europe</a>.  He recently posted an <a href="http://blogs.fsfe.org/fellowship-interviews/?p=98">interview with me</a>.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=144&amp;md5=0af7f4b5a283ed56278660139f22e0a1" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2010/01/08/fellowship-interview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2010%2F01%2F08%2Ffellowship-interview%2F&amp;language=en_GB&amp;category=text&amp;title=Fellowship+interview&amp;description=At+FSCONS+I+met+Stian+R%C3%B8dven+Eide+who+is+doing+a+series+of+fellowship+interviews+for+FSF+Europe.+He+recently+posted+an+interview+with+me.&amp;tags=fsf%2Cgnu%2Cinterview%2Csecurity%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Nordic Free Software Award 2009</title>
		<link>http://blog.josefsson.org/2009/11/15/nordic-free-software-award-2009/</link>
		<comments>http://blog.josefsson.org/2009/11/15/nordic-free-software-award-2009/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 15:13:05 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[advocacy]]></category>
		<category><![CDATA[general]]></category>
		<category><![CDATA[award]]></category>
		<category><![CDATA[fscons]]></category>
		<category><![CDATA[gnu]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=141</guid>
		<description><![CDATA[Last night at FSCONS I was awarded the Nordic Free Software Award, sharing the price with Daniel Stenberg who incidentally (or perhaps not) I have been collaborating with on some projects. Receiving a price like this is a great motivator <a class="more-link" href="http://blog.josefsson.org/2009/11/15/nordic-free-software-award-2009/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last night at <a href="http://www.fscons.org/">FSCONS</a> I was awarded the <a href="http://fscons.org/award">Nordic Free Software Award</a>, sharing the price with <a href="http://daniel.haxx.se/">Daniel Stenberg</a> who incidentally (or perhaps not) I have been collaborating with on some projects.   Receiving a price like this is a great motivator and I feel humbled when thinking about the many excellent hackers that were attending the FSCONS that cheered <i>me</i> on.  Thank you everyone.</p>
<p>Now back to coding.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=141&amp;md5=c6db087cb65115e17c2e724743e84227" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2009/11/15/nordic-free-software-award-2009/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2009%2F11%2F15%2Fnordic-free-software-award-2009%2F&amp;language=en_GB&amp;category=text&amp;title=Nordic+Free+Software+Award+2009&amp;description=Last+night+at+FSCONS+I+was+awarded+the+Nordic+Free+Software+Award%2C+sharing+the+price+with+Daniel+Stenberg+who+incidentally+%28or+perhaps+not%29+I+have+been+collaborating+with+on+some...&amp;tags=award%2Cfscons%2Cgnu%2Cblog" type="text/html" />
	</item>
		<item>
		<title>Thread Safe Functions</title>
		<link>http://blog.josefsson.org/2009/06/23/thread-safe-functions/</link>
		<comments>http://blog.josefsson.org/2009/06/23/thread-safe-functions/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 20:17:02 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[gsasl]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[reentrant]]></category>
		<category><![CDATA[sasl]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[thread safety]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=104</guid>
		<description><![CDATA[I have read Russel Coker&#8217;s nice article on identifying use of thread unsafe functions. This reminded me of a script I wrote a long time ago that is part of GNU SASL&#8216;s regression suite: threadsafety. As you can see, my <a class="more-link" href="http://blog.josefsson.org/2009/06/23/thread-safe-functions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have read <a href="http://etbe.coker.com.au/2009/06/14/finding-thread-unsafe-code/">Russel Coker&#8217;s nice article on identifying use of thread unsafe functions</a>.  This reminded me of a script I wrote a long time ago that is part of <a href="http://www.gnu.org/software/gsasl/">GNU SASL</a>&#8216;s regression suite: <a href="http://git.savannah.gnu.org/cgit/gsasl.git/tree/tests/threadsafety?id=8b699b8f45db2a1afaf226dc8a37e852530edee9">threadsafety</a>.</p>
<p>As you can see, my script looks for <a href="http://www.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_01">functions mentioned in the latest POSIX specification as being thread unsafe</a>.  In the last POSIX release, they actually removed some older interfaces (e.g., gethostbyname) so the script also checks for <a href="http://www.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_09.html#tag_02_09_01">thread-unsafe functions mentioned in one older POSIX specification</a>.</p>
<p>Russel&#8217;s approach is to look for man pages of functions ending with <code>_r</code> and labeling the non-<code>_r</code>-function as a thread unsafe function.  Russel&#8217;s and my approach are quite different, so I wanted to compare the results.  There is potential for me to add more functions to search for.  I still want to preserve my approach of explicitly listing known thread unsafe functions, though.</p>
<p>Running Russel&#8217;s command, I get a list of functions that my script catches that Russel&#8217;s doesn&#8217;t, and vice versa.  For reference, the functions that my script catches that Russel&#8217;s doesn&#8217;t are:</p>
<p><code>basename catgets dbm_clearerr dbm_close dbm_delete dbm_error dbm_fetch dbm_firstkey dbm_nextkey dbm_open dbm_store dirname dlerror endgrent endpwent endutxent ftw gcvt getc_unlocked getchar_unlocked getenv getopt getutxent getutxid getutxline inet_ntoa l64a lgamma lgammaf lgammal localeconv nftw nl_langinfo putc_unlocked putchar_unlocked putenv pututxline setenv setgrent setpwent setutxent strsignal system unsetenv wcstombs wctomb</code></p>
<p>The list contains lgamma, lgammaf, and lgammal which are all excluded by Russel&#8217;s command.  I don&#8217;t understand why &#8212; according to the man page, the functions uses a global variable for sign, which doesn&#8217;t seem thread safe.  So it seems right to include them?</p>
<p>What&#8217;s more interesting (for me) is the list of functions that Russel&#8217;s script catches that my script currently doesn&#8217;t.  Here is the list:</p>
<p><code>erand48 ether_aton ether_ntoa fgetgrent fgetpwent fgetspent getaliasbyname getaliasent gethostbyname2 getmntent getnetgrent getrpcbyname getrpcbynumber getrpcent getspent getspnam getutent getutid getutline initstate jrand48 lcong48 nrand48 qecvt qfcvt random seed48 setstate sgetspent srand48 srandom tmpnam</code></p>
<p>I started looking into each function. For <code>erand48</code> there is a <code>erand48_r</code> function in glibc, and the former does indeed seem to use a global variable.  However, as far as I can tell from the POSIX specification, <code>erand48</code> should be thread safe.  So I filed a <a href="http://sourceware.org/bugzilla/show_bug.cgi?id=10320">glibc bug about it</a>.  The same concern may hold for <code>jrand48</code>, <code>lcong48</code>, <code>nrand48</code>, <code>seed48</code>, and <code>srand48</code>.</p>
<p>I noticed that <code>initstate</code>, <code>random</code>, <code>setstate</code>, and <code>srandom</code> are defined by latest POSIX, but not mentioned as a thread-unsafe functions.  Possibly a bug in the POSIX specification?</p>
<p>I also noticed that I had missed to include <code>tmpnam</code> even though it is mentioned separately in the POSIX link.</p>
<p>The rest of the functions are not documented by POSIX, and presumably thread unsafe (although I didn&#8217;t read the man page or source code for each of them).</p>
<p>In the end, I ended up adding several new functions to check for.  The latest script is always available from:</p>
<p><a href="http://git.savannah.gnu.org/cgit/gsasl.git/tree/tests/threadsafety">http://git.savannah.gnu.org/cgit/gsasl.git/tree/tests/threadsafety</a></p>
<p>So, finally, did the updated script catch any use of thread-unsafe functions in GNU SASL?   Nope.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=104&amp;md5=5af8f95e2b7950537c4d910069750b50" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2009/06/23/thread-safe-functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2009%2F06%2F23%2Fthread-safe-functions%2F&amp;language=en_GB&amp;category=text&amp;title=Thread+Safe+Functions&amp;description=I+have+read+Russel+Coker%26%238217%3Bs+nice+article+on+identifying+use+of+thread+unsafe+functions.+This+reminded+me+of+a+script+I+wrote+a+long+time+ago+that+is+part+of...&amp;tags=gnu%2Creentrant%2Csasl%2Cthread%2Cthread+safety%2Cblog" type="text/html" />
	</item>
		<item>
		<title>FSCONS / Nordic Free Software Award Nomination</title>
		<link>http://blog.josefsson.org/2008/10/14/nordic-free-software-award-nomination/</link>
		<comments>http://blog.josefsson.org/2008/10/14/nordic-free-software-award-nomination/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 09:59:51 +0000</pubDate>
		<dc:creator>simon</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[award]]></category>
		<category><![CDATA[fscons]]></category>
		<category><![CDATA[gnu]]></category>

		<guid isPermaLink="false">http://blog.josefsson.org/?p=59</guid>
		<description><![CDATA[The Free Software &#038; Culture conference FSCONS is held in Gothenburg October 24-26th. Having been there and given talks last year, I can recommend it for anyway interested in what&#8217;s going on the free software and culture world. I&#8217;m happy <a class="more-link" href="http://blog.josefsson.org/2008/10/14/nordic-free-software-award-nomination/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://fscons.org">Free Software &#038; Culture conference FSCONS</a> is held in Gothenburg October 24-26th.  Having been there and given talks last year, I can recommend it for anyway interested in what&#8217;s going on the free software and culture world.</p>
<p>I&#8217;m happy and proud to notice that I have been <a href="http://fscons.org/award/">nominated for their award</a>, for my work on security packages for the <a href="http://www.gnu.org/">GNU project</a>.  Too bad I cannot make it to the conference this year.</p>
 <p><a href="http://blog.josefsson.org/?flattrss_redirect&amp;id=59&amp;md5=fcee929d7c0e43abe8bbe5c5023470ac" title="Flattr" target="_blank"><img src="https://blog.josefsson.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.josefsson.org/2008/10/14/nordic-free-software-award-nomination/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" title="Flattr this!" href="https://flattr.com/submit/auto?user_id=jas&amp;popout=1&amp;url=http%3A%2F%2Fblog.josefsson.org%2F2008%2F10%2F14%2Fnordic-free-software-award-nomination%2F&amp;language=en_GB&amp;category=text&amp;title=FSCONS+%2F+Nordic+Free+Software+Award+Nomination&amp;description=The+Free+Software+%26%23038%3B+Culture+conference+FSCONS+is+held+in+Gothenburg+October+24-26th.+Having+been+there+and+given+talks+last+year%2C+I+can+recommend+it+for+anyway+interested+in+what%26%238217%3Bs...&amp;tags=award%2Cfscons%2Cgnu%2Cblog" type="text/html" />
	</item>
	</channel>
</rss>
