<?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>Runtux Blog &#187; english</title>
	<atom:link href="http://blog.runtux.com/category/english/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.runtux.com</link>
	<description>Neues, Interessantes, Skurriles</description>
	<lastBuildDate>Fri, 23 Sep 2011 08:09:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SIGALRM blocked forever &#8212; by init</title>
		<link>http://blog.runtux.com/2011/09/23/194/</link>
		<comments>http://blog.runtux.com/2011/09/23/194/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 08:09:43 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[skurril]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=194</guid>
		<description><![CDATA[I&#8217;m working on an embedded Linux system which allows to chose the root filesystem to boot from (flash card or NAND flash) early in the boot process. Now I was trying to get ppp (for a GSM/GPRS connection) working. But the chat-script hangs forever, it does not get a timeout. Turns out, chat uses alarm(2) [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on an embedded Linux system which allows to chose the root filesystem to boot from (flash card or NAND flash) early in the boot process. Now I was trying to get ppp (for a GSM/GPRS connection) working. But the chat-script hangs forever, it does not get a timeout. Turns out, chat uses alarm(2) to wait for a timeout. After quite some time of debugging I found out that SIGALRM is blocked (look for <code>SigBlk</code> in <code>/proc/pid/status</code>, this is the mask of blocked signals for process with <code>pid</code>).</p>
<p>After some googling I came across a <a href="http://www.landley.net/notes.html">blog entry</a> (look for September 5, 2011) that describes a bug in bash: Bash, when calling &#8220;read&#8221; with a timeout, will install a signal handler for SIGALRM and <em>longjump out of the signal handler</em>, leaving SIGALRM blocked forever.</p>
<p>The boot-script runs as init (with pid 1) and therefore will leave SIGALRM blocked for all children. My immediate workaround is to read the filesystem to boot in a sub-shell&#8230;seems the bug is fixed with newer versions of bash.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2011/09/23/194/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Skype Compression Now Published</title>
		<link>http://blog.runtux.com/2011/06/09/191/</link>
		<comments>http://blog.runtux.com/2011/06/09/191/#comments</comments>
		<pubDate>Thu, 09 Jun 2011 08:54:20 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[skype]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=191</guid>
		<description><![CDATA[A while ago I blogged about the first published information about reverse-engineering of Skype (Skypes Flux Capacitor has been released, Skypes Flux Capacitor: UDP). A missing piece in the puzzle was the arithmetic compression algorithm used by Skype, details about which were first published in Silver Needle in the Skype. Meanwhile I&#8217;ve seen source code [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I blogged about the first published information about reverse-engineering of Skype (<a href="http://blog.runtux.com/2010/08/25/167/">Skypes Flux Capacitor has been released</a>, <a href="http://blog.runtux.com/2010/10/06/176/">Skypes Flux Capacitor: UDP</a>). A missing piece in the puzzle was the arithmetic compression algorithm used by Skype, details about which were first published in <a href="http://www.blackhat.com/presentations/bh-europe-06/bh-eu-06-biondi/bh-eu-06-biondi-up.pdf">Silver Needle in the Skype</a>. Meanwhile I&#8217;ve seen source code of the compression algorithm from two different sources &#8212; one of them on a blog on <a href="http://skype-open-source.blogspot.com/">Open Source Skype</a>, although that version doesn&#8217;t seem to be available any longer on that page, try the usual sources to find &#8220;removed&#8221; internet-information. The code is both versions is different. I&#8217;ve not yet had the time to further look into this (and try out the code on actual Skype packets) but from what I&#8217;ve seen the code looks genuine. There are some questions, though, if the code works with later versions of Skype, it seems the protocol was <a href="http://skype-open-source.blogspot.com/2011/06/some-words-about-how-to-test-this.html">slightly changed recently</a>.<br />
There is also some press coverage from the interview with Efim Bushmanov, the author of the menioned blog:
<ul class="simple">
<li><a href="http://www.ewdn.com/2011/06/04/skype-reverse-engineered-by-russian-geek/">Skype reverse-engineered by Russian geek</a></li>
<li><a href="http://www.ewdn.com/2011/06/05/ewdn-exclusive-an-interview-with-efim-bushmanov/">Efim Bushmanov: &#8220;Good products can&#8217;t stay proprietary for long&#8221;</a></li>
<li><a href="http://www.eweekeurope.co.uk/interview/russian-reverse-engineer-praises-skype-30956">Russian Reverse Engineer Praises Skype</a></li>
</ul>
<p>So we now have alle the pieces of the puzzle to start writing a plugin for <a href="http://www.wireshark.org/">Wireshark</a> to give us a tool to further analyze the network traffic produced by Skype. Maybe an open source client is on the horizon now (there&#8217;s still a long way to go since we don&#8217;t know the binary formats used by the voice and video codecs in Skype, but maybe keyboard-chat is within reach now). Shameless Plug: If you have resources (money or time) to help writing a <a href="http://www.wireshark.org/">Wireshark</a> plugin for Skype, please <a href="mailto:rsc@runtux.com">contact me</a>, I&#8217;m trying to coordinate efforts in this direction.<br />
That said, there are rumors that (one of) the Skype Certificate-Authority-Key (the Root key in a certificate chain) <a href="http://skype-open-source.blogspot.com/2011/06/some-thoughts.html">was leaked</a>. Lets see what comes from this&#8230; leaking the key could make communications available to third parties or forge identities. But be aware that the makers of Skype probably already <em>do</em> have the mechanisms in place to listen into the contents of Skype traffic as was first hinted at by the <a href="http://www.blackhat.com/presentations/bh-europe-06/bh-eu-06-biondi/bh-eu-06-biondi-up.pdf">Silver Needle in the Skype</a> presentation and which I&#8217;ve mentioned in my talks on Skype (presentation material linked from my <a href="http://runtux.com/">home page</a>).<br />
Looks like Microsoft has aquired a piece of software here that perfectly fits its security record so far &#8212; this could be helped by letting independent researchers look at the Skype protocol design, but may well uncover further problems down the road. We again see here that secrecy won&#8217;t help security in the long run, we may view this as a generalisation of <a href="http://en.wikipedia.org/wiki/Kerckhoffs%27s_Principle">Kerckhoffs&#8217; Principle</a>. Opening the procotol like speculated in the article <a href="http://www.ewdn.com/2011/06/04/skype-reverse-engineered-by-russian-geek/">Skype reverse-engineered by Russian geek</a> is still a very unlikely move by Microsoft, in my view&#8230; but I would certainly welcome this.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2011/06/09/191/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LILO &#8220;junk in compressed archive&#8221; and Grub2 &#8220;out of disk&#8221; error</title>
		<link>http://blog.runtux.com/2011/01/10/186/</link>
		<comments>http://blog.runtux.com/2011/01/10/186/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 09:44:52 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=186</guid>
		<description><![CDATA[I&#8217;ve recently upgraded a Debian/Asterisk Installation on an older Soekris Net 4501 embedded hardware. After the upgrade the device didn&#8217;t boot anymore. The installed LILO bootloader produced the error message:

Initramfs unpacking failed: junk in compressed archive

and later failed with a kernel panic


VFS: Unable to mount root fs on unknown-block(0,0)

Googling for the error message found a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently upgraded a Debian/Asterisk Installation on an older Soekris <a href="http://soekris.com/net4501.htm">Net 4501</a> embedded hardware. After the upgrade the device didn&#8217;t boot anymore. The installed LILO bootloader produced the error message:</p>
<pre>
Initramfs unpacking failed: junk in compressed archive
</pre>
<p>and later failed with a kernel panic
<pre>

VFS: Unable to mount root fs on unknown-block(0,0)
</pre>
<p>Googling for the error message found a <a href="http://alien.slackbook.org/blog/initramfs-unpacking-failed-junk-in-compressed-archive/">blog entry</a> that indicated a missing LILO option &#8220;large-memory&#8221; &#8212; which wasn&#8217;t the problem in my case, the option was already present.<br />
So I booted into <a href="http://grml.org/">GRML</a> and installed grub2 instead of LILO. After a reboot, Grub2 ended up in rescue mode with the error message:</p>
<pre>
error: out of disk.
grub rescue&gt;
</pre>
<p>I could display the partitions with ls and also get a listing from my root partition but trying to list other directories produces the &#8220;out of disk&#8221; error again:
<pre>

grub rescue&gt; ls
(hd0) (hd0,msdos1) (hd1) (hd2) (hd3)
...
grub rescue&gt; ls (hd0,msdos1)/
./ ../ lost+found/ var/ etc/ media/ initrd.img usr/
...

grub rescue&gt; ls (hd0,msdos1)/boot

error: out of disk.
</pre>
<p>So my diagnosis was that the BIOS of the Soekris box is unable to address the whole (in this case 60GB) harddisk. The install had only worked before because the kernel and the /boot directory where within the BIOS-accessible area on the disk. So there are still BIOSes out there that don&#8217;t support large harddisks &#8212; I didn&#8217;t find out until now what the limit of the Soekris BIOS is. The fix after this diagnosis was easy: Shrink the root filesystem using resize2fs, create a new root partition and copy the shrunken filesystem there, resize2fs to the new partition size. Create a new small /boot partition at the start of the disk and copy the contents of the old /boot directory there. Of course this is only possible with a working rescue system, my rescue system of choice is a <a href="http://grml.org/">GRML</a> netboot setup which enables me to quickly boot any x86-based system that supports network boot.<br />
Lesson learned: For small X86 embedded hardware it still makes sense to have a small /boot partition.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2011/01/10/186/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thomas Greco in Vienna</title>
		<link>http://blog.runtux.com/2010/11/10/183/</link>
		<comments>http://blog.runtux.com/2010/11/10/183/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 12:43:34 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[money]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=183</guid>
		<description><![CDATA[Yesterday evening Thomas Greco was in Vienna. We were a mixed audience coming from different fields all interested in the money problem.
Thomas started by introducing himself and his history. He has an engineering background and worked as a college professor. Got &#8220;yanked out of the matrix in 1974&#8243;, seeing that not everything we see is [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday evening Thomas Greco was in Vienna. We were a mixed audience coming from different fields all interested in the money problem.<br />
Thomas started by introducing himself and his history. He has an engineering background and worked as a college professor. Got &#8220;yanked out of the matrix in 1974&#8243;, seeing that not everything we see is as it appears. Started asking questions about problems like war, poverty, exploitation and how to solve these problems.<br />
One day he had a book in the mail &#8220;In the Wake of Inflation Can the Church Remain Silent?&#8221;, he checked the few references and found (some of) them sound. The question why they allow the money-system to exist kept gnawing at him and he got in touch with the author, they eventually became good friends. He helped put out a second edition of the book. His questions were why the church doesn&#8217;t mention usury and why social justice if not part of their program.<br />
He participated in several land-trust, school of living and other projects and his focus narrowed down to money and banking. Over the time he helped starting several local currency projects and wrote several books which document what was learned (a joke was that much was learned from failed projects). The first two books can be downloaded from <a href="http://reinventingmoney.com/library.html">reinventingmoney.com</a>, the third is available as an <a href="http://reinventingmoney.com/documents/MoneyEbook.pdf">EBook</a>-Excerpt, for the fourth there is an excerpt at <a href="http://books.google.com/books?id=lUdPcDWQv90C&amp;printsec=frontcover&amp;dq=end+of+money&amp;hl=en&amp;ei=oGbaTPCjCIP4sga6y6SuCw&amp;sa=X&amp;oi=book_result&amp;ct=book-thumbnail&amp;resnum=1&amp;ved=0CCsQ6wEwAA#v=onepage&amp;q&amp;f=false">google books</a>. I&#8217;ve read the fourth and can recommend it as one of the most systematic treatments of our current money system problem I know. Books are:</p>
<ul class="simple">
<li><a href="http://circ2.home.mindspring.com/money_and_debt.htm">Money and Dept</a>: A Solution to the Global Crisis (2nd ed. 1990)</li>
<li><a href="http://www.ratical.org/many_worlds/cc/NMfHC/NMfHC.html">New Money</a> for Healthy Communities 1994</li>
<li><a href="http://www.chelseagreen.com/bookstore/item/money">Money</a> &#8212; Understanding and Creating Alternatives to Legal Tender 2001</li>
<li>The End of Money and the Future of Civilization 2009</li>
</ul>
<p>Tom then proceed to outline the history of money: It started out with barter exchange, the first form of money was commodity-money, various commodities like tobacco (cigarettes), flour or grain, nails and precious metals like silver and gold (highly valued in small amounts, portable, durable) served as money. What follows is symbolic money: the first bankers were goldsmiths depositing gold for their customers, the receipt from the bank about the deposit of gold served as a place-holder for the gold. When goldsmiths discovered that they could give receipts not only to people depositing gold, but also to people who came to borrow it, credit money (the 3rd form) was born. The last form is credit clearing where we keep only an account for each member and incoming money is added while outgoing money is subtracted. The main problem of credit is interest which exploits people.<br />
Then a discussion where Franz Nahrada claimed that money is always an alienation ensued. Thomas explained that the farther the relationships among people are, the higher the need for money: In the family we don&#8217;t need (and don&#8217;t want) money. With a close neighbor we expect some reciprocity (we keep in mind if the other person is always taking). For dealing with people you don&#8217;t know we need some kind of formalized structure. But he agreed that a closer community relationship is a good goal. It was mentioned that experiences without money (where you lose your wallet and have to find your way without money for some time) can be a lasting positive experience, on the other hand money may cut through relationships&#8230;<br />
In the discussion I asked about Toms view about demurrage, a negative interest rate on money. He answered that demurrage is an unnecessary &#8220;stamp scrip&#8221; (so called because some demurrage currencies use stamps that have to be bought and affixed to the banknotes) first introduced by <a href="http://en.wikipedia.org/wiki/Silvio_Gesell">Silvio Gesell</a> and that it&#8217;s unfortunate that demurrage is the only one of his proposals that is generally remembered. Demurrage currencies where successful in a time where any kind of exchange medium would have been successful. The problem demurrage tries to solve, the prevention of hording (mainly of paper currencies) could be solved by reallocating excess money to (new) businesses. I noted that Gesell also had this in mind when he argues that when depositing excess money in a bank for re-lending, he proposes that there should be no demurrage. (I&#8217;m still not fully convinced that demurrage might not be a good tool at times) We agreed that a shortcoming of Gesell is that he can only envision a central banking system while Thomas recommends the separation of money and state (I also think this currently is our best option). There is also a blog post on <a href="http://beyondmoney.net/monographs/demurrage-is-it-a-good-idea-for-a-local-currency-or-exchange-system/">demurrage</a> by Tom.<br />
During the discussion Tom remarked that due to the &#8220;Bubble and Bust Cycle&#8221; of our current money system, banks always have to find new ways to indept the people. When he studied, there were no student loans. This is a new idea that came up in the 60s. In the 90s we had the dot com bubble and the recent crisis in 2008 added a lot more dept to the private sector. He thinks we reached the end of the line, the dollar will probably be inflated out of existence. One of the outcomes of a hyper-inflation like Weimar in the 1920s is that the middle class gets wiped out. They still have savings but these won&#8217;t buy anything. Maybe the plan for after the inflation is a global currency. A question about the timeframe for these predicted events was answered that it&#8217;s hard to say, but China already has satisfied its appetite on US government bonds now buying gold. Maybe an America-wide new currency (Amero) or a global currency will be the plan. This would wipe out everyones savings and re-start the game, hopefully not everybody will go along with this.<br />
In the later discussion I asked &#8212; when Tom had talked about the Government and the central banks cooperating &#8212; that up until now I had seen the private banking as the problem and the state more in the role of a victim. Tom replied that they are cooperating and that this cooperation was introduced in the early days of the <a href="http://en.wikipedia.org/wiki/Bank_of_England">Bank of England</a> (when the king needed money for war). In a blog post <a href="http://beyondmoney.net/2010/10/28/when-will-the-dollar-die/">When will the dollar die?</a> Greco also outlines a facet of that cooperation: &#8220;National governments are unique in being able to play this role [of borrower of last resort] because of their collusive arrangement with the banking cartel.&#8221;<br />
We also had some discussions on emerging trends, barter exchanges (which aren&#8217;t really barter in the original sense of the word). Tom said that if businesses are not involved early on in an alternative currency project, it is bound to fail. Barter exchanges that only involve retailers can work to a certain degree of circulation. But for a robust system, manufacturers, employess are needed to close the circle. Not all suppliers are within a region, so we have to get regions to cooperate. Mistakes that have been made by some local exchanges (which is detrimental to their own business and the whole &#8220;industry&#8221;) are:
<ul class="simple">
<li>competition with members (taking the best things for themselves)</li>
<li>too much credit for themselves (debasing their own currency)</li>
</ul>
<p>Tom also mentioned Argentina during the discussion which had a strong social currency movement in the early 2000s with dozens of trade exchanges. The system (nearly) collapsed due to mis-managed, my question if this was induced by outsiders was answered that there were accusations of counterfeiting by the central government or other authorities but it is unclear if this is true. When he visited Argentina, there already was counterfeiting in some of the largest exchanges and they didn&#8217;t do anything about it. Now they have better safeguards.<br />
The following links are taken from the discussions (no particular order, Tom is not affiliated with any of them as far a I know but knows some of the creators as &#8220;cooperatively minded entrepreneurs&#8221;), during the discussion I noted that we would need a common protocol among different barter and community currency enterprises, so that not everybody builds his own &#8220;walled garden&#8221; which was agreed&#8230; I&#8217;ve written about that problem before when writing about <a href="http://blog.runtux.com/2009/08/04/106/">cloud computing</a>.</p>
<ul class="simple">
<li><a href="http://project.cyclos.org/">Cyclos</a>, a system for manageing lets trading circles</li>
<li><a href="http://zacle.com">zacle.com</a> an newly started web-based exchange (this takes ages to load for me with layers upon layers of javascript, that by default isn&#8217;t enabled when I surf with noscript, so not a site I&#8217;d ever use)</li>
<li><a href="http://poiu.com">poiu.com</a> , another trading system</li>
<li>community exchange network <a href="http://www.ces.org.za/">www.ces.org.za</a></li>
<li><a href="http://getsplus.com">getsplus.com</a>: a proprietary platform where a lot of money was invested, it&#8217;s a cashless trading platform which might eventually become open source</li>
<li><a href="http://virtualbarter.net">virtualbarter.net</a> an online barter exchange</li>
<li><a href="http://imsbarter.com">imsbarter.com</a> one of the biggest US barter companies</li>
<li><a href="http://www.favors.org">www.favors.org</a> a social network by Sergio Lub</li>
<li><cite>www.livingdirectory.org</cite> one of the first social networks with 60.000 people worldwide participating, has levels &#8220;identified&#8221; (a real person), &#8220;sponsor&#8221; (trust someone to sponsor other people) and &#8220;networker&#8221; (full access to the system).</li>
</ul>
<p>At the end we watched the short film <a href="http://www.youtube.com/watch?v=qBX-jaxMneo">The Essence of Money</a> (4:13) that outlines how money works. In my opinion it&#8217;s also a good illustration how a distributed money system &#8212; where every player in the game can issue his/her own money &#8212; could work. With todays electronic systems we maybe can come up with a solution that is distributed: compare this to file-sharing systems that started out as centralized systems like <a href="http://en.wikipedia.org/wiki/Napster">Napster</a> and evolved into distributed systems like <a href="http://en.wikipedia.org/wiki/Gnutella">Gnutella</a> today. The film <a href="http://www.moneyasdebt.net/">Money as Dept</a> was recommended, there seems to be a sequel, the original seems to be available in several places on the net.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2010/11/10/183/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unix Domain Sockets</title>
		<link>http://blog.runtux.com/2010/11/09/179/</link>
		<comments>http://blog.runtux.com/2010/11/09/179/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 10:13:42 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=179</guid>
		<description><![CDATA[I recently had to find a solution for a communication problem: An application running on a web-server should update configuration files that are only readable by a privileged user and these should not be directly writeable by the web-server user.
So the idea was to write an update-server running under the privileged account which receives update [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to find a solution for a communication problem: An application running on a web-server should update configuration files that are only readable by a privileged user and these should not be directly writeable by the web-server user.<br />
So the idea was to write an update-server running under the privileged account which receives update requests (and can perform additional checks) from the unprivileged web server user.<br />
One of the checks I wanted to make was that only the web-server user (www-data on debian) should be able to send update requests. So I had to find out the user sending a request via the Unix-domain socket. Google found a nice socket howto on <a href="http://blog.henning.makholm.net/2008/06/unix-domain-socket-woes.html">Henning Makholm&#8217;s blog</a> which told me most of what I needed to know: &#8220;so I ended up just checking the EUID of the client process after the connection has been accept()ed. For your reference, the way to do this is getsockopt() with SO_PEERCRED for Linux&#8221;.<br />
But one issue was remaining: I didn&#8217;t need a SOCK_STREAM socket but wanted to send datagrams to the other side (and didn&#8217;t want to fiddle with implementing my own datagram layer on top of a stream socket). With normal SOCK_DGRAM datagram sockets there is no connection &#8212; and therefore I can&#8217;t determine the user sending the datagram from the other side of the socket.<br />
Looking further I discovered that Linux has connection-oriented datagram sockets for quite some time under the name SOCK_SEQPACKET. With this type of socket you first connect() to the other side and then you send a datagram. Since now there is a connection the trick with SO_PEERCRED as described above works, too.<br />
Code for Server (python):
<pre>

from socket import socket, SOCK_SEQPACKET, AF_UNIX, SOL_SOCKET
from struct import unpack
try :
    # Not implemented in python 2.6, maybe higher
    from socket import SO_PEERCRED
except ImportError :
    SO_PEERCRED = 17 # Linux
sock = socket (AF_UNIX, SOCK_SEQPACKET)
path = '/path/to/socket'
try :
    os.remove (path)
except OSError :
    pass
sock.bind (path)
conn, adr = self.sock.accept ()
ucred = conn.getsockopt (SOL_SOCKET, SO_PEERCRED, 12)
pid, uid, gid = unpack ('LLL', ucred)
if uid... check uid:
    error...
    conn.close ()

data = conn.recv (4096)
</pre>
<p>Code for client (python):
<pre>

from socket import socket, SOCK_SEQPACKET, AF_UNIX
s = socket (AF_UNIX, SOCK_SEQPACKET)
s.connect ('path/to/socket')
s.send (.....)
s.close ()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2010/11/09/179/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Skypes Flux Capacitor: UDP</title>
		<link>http://blog.runtux.com/2010/10/06/176/</link>
		<comments>http://blog.runtux.com/2010/10/06/176/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 17:20:13 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[skype]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=176</guid>
		<description><![CDATA[I recently wrote about the broken network obfuscation code (aka Flux Capacitor) of Skype published by Sean O&#8217;Neil. At the time I wasn&#8217;t able to decrypt UDP packets. Now I&#8217;ve looked a little more closely into the Vanilla Skype documentation &#8212; which also includes some code to decrypt Skype credentials on harddisk. This code contains [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wrote about the <a href="http://blog.runtux.com/2010/08/25/167/">broken network obfuscation</a> code (aka Flux Capacitor) of Skype <a href="http://www.enrupt.com/index.php/2010/07/07/skype-biggest-secret-revealed">published by Sean O&#8217;Neil</a>. At the time I wasn&#8217;t able to decrypt UDP packets. Now I&#8217;ve looked a little more closely into the Vanilla Skype documentation &#8212; which also includes some code to decrypt Skype credentials on harddisk. This code contains a CRC implementation called CRC32. I had wrongly asumed that CRC32 of Skype would be the same as the crc32 implementation of pkzip, Ethernet, png, the POSIX cksum command etc. which is listed as &#8220;crc32&#8243; in the <a href="http://en.wikipedia.org/wiki/Cyclic_redundancy_check">CRC article on Wikipedia</a> and which is standardized in e.g. IEEE 802.3.<br />
The crc32 from the standards above inverts all the bits of the seed before using it (it uses an XOR mask of 0xFFFFFFFF) and does this again before returning the result of the CRC computation to the caller. But it uses the same polynomial as skype. So we can use an existing standard CRC implementation (e.g from the <a href="http://www.zlib.net/">zlib</a> library) as follows for computing the skype CRC:</p>
<pre>
def skype_crc (s, seed = 0xFFFFFFFF) :
    return (crc32 (s, seed ^ 0xFFFFFFFF)) ^ 0xFFFFFFFF
</pre>
<p>With this crc implementation I&#8217;m now able to also decrypt UDP (see <a href="http://project.runtux.com/skype/skype_deobfuscate.py">updated code</a>) packets. I&#8217;ve shown this some days ago at my <a href="http://linuxwochenende2010.luga.at/">talk @linuxwochenende</a>, for slides see my <a href="http://runtux.com/events.html">events page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2010/10/06/176/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Skypes Flux Capacitor has been released</title>
		<link>http://blog.runtux.com/2010/08/25/167/</link>
		<comments>http://blog.runtux.com/2010/08/25/167/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 16:55:38 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[skype]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=167</guid>
		<description><![CDATA[Skype uses an obfuscation layer for making it harder for others to analyze the Skype network traffic. This obfuscation layer has been called &#8220;Flux Capacitor&#8221; by the authors of the 2006 publications &#8220;Silver Needle in the Skype&#8221; and &#8220;Vanilla Skype&#8221;, Philippe Biondi, Fabrice Desclaux, and Kostya Kortchinsky, see the Wikipedia article on Skype for references [...]]]></description>
			<content:encoded><![CDATA[<p>Skype uses an obfuscation layer for making it harder for others to analyze the Skype network traffic. This <a href="http://en.wikipedia.org/wiki/Skype_protocol#Obfuscation_Layer">obfuscation layer</a> has been called &#8220;Flux Capacitor&#8221; by the authors of the 2006 publications &#8220;Silver Needle in the Skype&#8221; and &#8220;Vanilla Skype&#8221;, Philippe Biondi, Fabrice Desclaux, and Kostya Kortchinsky, see the <a href="http://en.wikipedia.org/wiki/Skype_protocol">Wikipedia article</a> on Skype for references about their publications. They discovered this flux capacitor code when reverse engineering the Skype binary program but didn&#8217;t dare to publish it for fear of others attacking the Skype network. They hinted at all sorts of bad things that were possible when knowing the Skype prototocol, the least of which is scanning networks behind firewalls (Skype is well known to be able to connect to the internet even in the presence of firewalls).<br />
Now this <a href="http://cryptolib.com/ciphers/skype/">Flux Capacitor code</a> has been released by a group called &#8220;Skype Reverse Engineering Team&#8221; in a blog post <a href="http://www.enrupt.com/index.php/2010/07/07/skype-biggest-secret-revealed">Skype&#8217;s Biggest Secret Revealed</a> by Sean O&#8217;Neil claiming that the code was already leaked and used by spammers. But they didn&#8217;t tell us how to use that code and defer further information to the next <a href="http://events.ccc.de/2010/07/30/27c3-we-come-in-peace-call-for-participation/">Chaos Communication Congress 27C3</a>.<br />
I certainly hope that the security holes in Skype are not that bad as feared by others. Some good can come out of it: maybe we&#8217;ll see a free Skype client in the not-too-far future. A good plan now would be to write a <a href="http://www.wireshark.org/">Wireshark</a> dissector for Skype so that we can analyze the network traffic. Unfortunately the authors didn&#8217;t tell us yet how to call that code to de-obfuscate Skype traffic. But there is plenty of information in the aforementioned publications. So I&#8217;ve written a <a href="http://project.runtux.com/skype/Makefile">Makefile</a> to create a shared library from the now released code and a <a href="http://project.runtux.com/skype/skype_deobfuscate.py">Python wrapper</a> that decrypts a single packet from a Skype network dump called <a href="http://wiki.wireshark.org/SampleCaptures?action=AttachFile&amp;do=view&amp;target=SkypeIRC.cap">SkypeIRC.cap</a> published on the <a href="http://www.wireshark.org/">Wireshark</a> page. This at least proves that the code works &#8212; the first several bytes of a Skype TCP stream decrypt to a known value.<br />
Maybe others want to use this as a starting point before more is released by the authors at the <a href="http://events.ccc.de/2010/07/30/27c3-we-come-in-peace-call-for-participation/">Chaos Communication Congress 27C3</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2010/08/25/167/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Ning eliminates free networks</title>
		<link>http://blog.runtux.com/2010/04/19/163/</link>
		<comments>http://blog.runtux.com/2010/04/19/163/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 15:21:23 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[licensing]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=163</guid>
		<description><![CDATA[That Ning now no longer supports free networks has been compared to blackmailing by some.
I also think so. But to be blackmailed there are two factors:

somebody who wants to blackmail others
a willing victim to go into the trap

You have the choice: Only use a service which at least provides a way to get your data [...]]]></description>
			<content:encoded><![CDATA[<p>That <a href="http://www.ning.com/">Ning</a> now <a href="http://blog.ning.com/2010/04/an-update-from-ning.html">no longer supports free networks</a> has been compared to blackmailing by some.<br />
I also think so. But to be blackmailed there are two factors:
<ul class="simple">
<li>somebody who wants to blackmail others</li>
<li>a willing victim to go into the trap</li>
</ul>
<p>You have the choice: Only use a service which at least provides a way to get your data out. (To be fair, it seems Ning will be offering this according to the blog entry cited above, but the details are still unclear)<br />
But: The data alone is nothing without the software. So you need a service where you can export the data <em>and</em> have open source software available to do something with the extracted data. But the first part is the crucial one: If you have only the data, software can be written&#8230;<br />
I&#8217;ve written <a href="http://blog.runtux.com/2009/08/04/106/">earlier</a> in this blog (and talked <a href="http://blog.runtux.com/2009/11/03/148/">@Manchester</a>) about the problem of vendor lock-in in &#8220;cloud computing&#8221; which is almost the same as &#8220;web 2.0 services&#8221;, namely <a href="http://en.wikipedia.org/wiki/Software_as_a_service">software as a service</a> (SAAS). Ning falls into that category as do other social network services like facebook or Xing.<br />
This boils down to what the <a href="http://www.opencloudinitiative.org/">open cloud initiative</a> has defined as <a href="http://www.opencloudinitiative.org/node/27">cloud computing openness</a>: For open content you ideally want to go for a free cloud with open APIs, open formats, open source (software), and open data.<br />
Note that facebook is no alternative to ning: People have been thrown off facebook for retrieving their data, cited in <a href="http://blogs.sun.com/bblfish/entry/scoble_gets_thrown_off_facebook">these</a> <a href="http://blogs.sun.com/bblfish/entry/data_portability_scoble_explains">two</a> entries on Henry Story&#8217;s blog.<br />
But the choice has to be made by customers (or non-paying users) of these services: Don&#8217;t use something where you lock in your data. Or your data might be at risk, or locked in, or dead.<br />
Doc Searls, co-Author of Cluetrain Manifesto and Editor of Linux Journal has written about this in a blog entry called <a href="http://blogs.law.harvard.edu/doc/2009/05/01/silos-end/">Silos End</a>: &#8220;These problems cannot be solved by the companies themselves. Companies make silos. It&#8217;s as simple as that. Left to their own devices, that&#8217;s what they do. Over and over and over again.&#8221;<br />
Ideally there would be a standardized service and hosters agree to use the same software (maybe customized in the appearance) to host services for users. A hosting standard for collaboration software. Starting with the services Facebook, Xing, etc. are offering today. We want an interchange format that everybody can use, export, import.<br />
I think a standard for these types of services will leave us with a network of hosters. This &#8212; in comparison to the status quo today &#8212; will be a distributed system, maybe a peer-to-peer system, not some big players locking in users. A common standard will hopefully keep the players honest.<br />
To get there: Lets try to evaluate replacement software for Ning. Work on interchange formats. A suitable format for contact information is the <a href="http://en.wikipedia.org/wiki/FOAF_(software)">Friend of a Friend</a> (FOAF) format endorsed by the <a href="http://www.w3.org/">W3C</a>, this is part of the <a href="http://www.w3.org/standards/semanticweb/">semantic web</a> effort.<br />
One software that comes close to this goal might be <a href="http://elgg.org/">elgg</a> &#8212; I&#8217;ve not tried it myself, but there is already a group of <a href="http://elgg.org/services.php">Elgg Service Providers</a> which comes close to the goal of a support infrastructure built around an open source project.<br />
I&#8217;ve two points of critique, one of them being more personal taste, the other related to the license. The first is that the software is in PHP. The license is the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GNU General Public License</a> which offers no protection against a service provider making own modifications to the hosted software and <em>not</em> releasing these modifications as open source software. Details are in my <a href="http://blog.runtux.com/2009/08/04/106/">earlier</a> article on the subject. So far, the team of elgg seems to play the game very open. The Source code with (yet) unrelease modifications to the software is freely accessible as a <a href="http://subversion.tigris.org/">subversion</a> software repository. Furthermore they offer <a href="http://elgg.org/download/nightly/">nightly builds</a> for download.<br />
There are many other good points, too: It offers syndication with RSS and JSON, and has an API to interconnect with software running elsewhere &#8212; which are the basic ingredients for a distributed system. The API is <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">Representational State Transfer</a> (REST) that happens to be the same mechanism on which the semantic web can be built.<br />
So lets take some steps in the direction of a system built on standardized components where no vendor can lock us in.<br />
When we get there, we&#8217;ve left Web 2.0 behind. The future is a distributed system, lets call it Web 3.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2010/04/19/163/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>OE3RSU</title>
		<link>http://blog.runtux.com/2010/02/17/157/</link>
		<comments>http://blog.runtux.com/2010/02/17/157/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 09:39:23 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[deutsch]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[neu]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=157</guid>
		<description><![CDATA[Two weeks ago I&#8217;ve finally &#8212; wanted to do this forever &#8212; passed the ham exam and got a callsign for austria. I had done some SWL (short wave listening) quite some time ago &#8212; including digital modes like RTTY. Now I can explore the sending side, too&#8230;Thanks to the Metafunk group @Metalab and to [...]]]></description>
			<content:encoded><![CDATA[<p>Two weeks ago I&#8217;ve finally &#8212; wanted to do this forever &#8212; passed the ham exam and got a callsign for austria. I had done some SWL (short wave listening) quite some time ago &#8212; including digital modes like RTTY. Now I can explore the sending side, too&#8230;Thanks to the <a href="http://metalab.at/wiki/MetaFunk">Metafunk</a> group <a href="http://metalab.at/">@Metalab</a> and to Mike, OE3MZC and Gerhard, OE3GSU for supporting our joint preparation.</p>
<p>Vor zwei Wochen habe ich endlich die Amateurfunkprüfung gemacht &#8212; ich wollte das eigentlich schon immer tun &#8212; und habe jetzt ein Rufzeichen für Österreich. Schon früher habe ich ein bisschen SWL (Kurzwellen-Hören) betrieben, inklusive digitaler Modi wie RTTY (Funkfernschreiben). Jetzt kann ich auch die Sendeseite ausprobieren&#8230; Danke an die <a href="http://metalab.at/wiki/MetaFunk">Metafunk</a> Gruppe im <a href="http://metalab.at/">Metalab</a> und an Mike, OE3MZC und Gerhard, OE3GSU für die Unterstützung unserer gemeinsame Vorbereitung.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2010/02/17/157/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get smartcards or crypto-tokens running on Debian Linux and Windows</title>
		<link>http://blog.runtux.com/2009/12/05/150/</link>
		<comments>http://blog.runtux.com/2009/12/05/150/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 16:16:23 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=150</guid>
		<description><![CDATA[This is a step-by-step Howto on installation and usage of the necessary commands to get smartcards or crypto-tokens working on Linux &#8212; and on Windows.
Smart card software on Linux consists of a driver for the card reader also called card terminal and a driver for the smartcard or token. There are two projects, OpenSC and [...]]]></description>
			<content:encoded><![CDATA[<p>This is a step-by-step Howto on installation and usage of the necessary commands to get smartcards or crypto-tokens working on Linux &#8212; and on Windows.<br />
Smart card software on Linux consists of a driver for the <em>card reader</em> also called <em>card terminal</em> and a driver for the <em>smartcard or token</em>. There are two projects, <a href="http://www.opensc-project.org/">OpenSC</a> and <a href="http://www.linuxnet.com/">MUSCLE</a>. Both projects produce drivers for card terminals (for OpenSC this sub-project is called <a href="http://www.opensc-project.org/openct/">OpenCT</a>) and for various cards. There are configuration options to make one project see the drivers of the other and vice versa.<br />
I&#8217;m using OpenCT (card terminal) and OpenSC (smart card) software because these have worked better for me &#8212; except for the pcscd daemon from the MUSCLE project that might be needed for some applications. If you&#8217;re using software that depends on a <a href="http://en.wikipedia.org/wiki/PC/SC">PC/SC</a> interface, you&#8217;ll also need to install the pcscd daemon (comes as a debian package).<br />
Manufacturers are continuously improving their smartcards and the applications that run on the card. Up to now this has created an ever-changing pile of middleware to talk to these cards. An idea to improve the situation was a programmable card: Put a Java interpreter on the card and provide applets (so-called &#8220;cardlets&#8221;) for applications. The idea claims this would improve the situation for middleware on the host. Unfortunately this isn&#8217;t quite true: The Java virtual machine on smartcards is subject to change. So we have cards with a recent JVM and old cards with an ancient (1.1 from 2001) JVM. This means the applet needed to make the card work has to be cross-compiled to an older JVM depending on the card used. And there are still a number of host configuration issues.<br />
The situation is worsened by the fact that many manufacturers of smartcards provide cards with their proprietary cardlet in the ROM of the card. This means these cards cannot be used with the applet that matches your middleware. And we&#8217;re back to the start and have to write a driver for the proprietary (this time java) middleware as before.<br />
If you&#8217;re using Java-based smartcards you need to get a card that can accept a new applet and has the necessary developer keys published. Usually these cards are called &#8220;developer version&#8221; or similar. You then can use the MCardApplet from the <a href="http://muscleplugins.alioth.debian.org/">MUSCLE plugins</a> project. I recommend to build the applet yourself &#8212; after all this is a security application where your security depends on the software running on the card. There is a section below for preparing a java card with the appropriate applet.<br />
I got the eToken PRO 32k (4.2B) working with OpenSC but not the eToken PRO 72k (Java). The first uses Siemens CardOS, the number in parentheses denotes the version number. Unfortunately these old CardOS based tokens will be discontinued, and Siemens seems to have announced end of life status for its CardOS.<br />
The 72k eToken from Aladdin uses Java and needs a Java applet. The OpenSC project claims that the Java token works with OpenSC, but it didn&#8217;t for me. Maybe the token wasn&#8217;t a developer version that can accept an applet. The token also didn&#8217;t work under windows (although it worked with the Aladdin software there, i.e., I could initialize it) and I had a recent OpenSC binary release for windows from October 2009.<br />
From the <a href="http://www.opensc-project.org/opensc/">OpenSC documentation</a>: &#8220;For programmable java cards: the support is for the card with the specific applet &#8211; if you have a different applet on your card, it might not be supported.&#8221;<br />
First steps for non-Java cards or Java-cards with MCardApplet installed (for installation of the applet, see below):<br />
Install smartcard software and card terminal framework:
<pre>

apt-get install pcscd opensc libengine-pkcs11-openssl
</pre>
<pre>
The following NEW packages will be installed:
  libengine-pkcs11-openssl libp11-0
</pre>
<p>If your smartcard reader is <em>not</em> supported by <code>pcscd</code>, you should install the <code>openct</code> package in addition to the packages above. You can then run <code>pcscd</code> on top of <code>openct</code>.<br />
After installing these programs, we need to configure pcscd to correctly use our reader. Configure <code>/etc/opensc/opensc.conf</code> to use the pcscd method, search for <code>reader_drivers</code> inside the <code>app default</code> stanza of the config file and modify this to:</p>
<pre>
reader_drivers = pcsc;
</pre>
<p>For CCID compatible readers without <code>openct</code> installed, the reader should be visible after plugging in the reader into the USB port:</p>
<pre>
Readers known about:
Nr.    Driver     Name
0      pcsc       Gemplus GemPC Key 00 00
</pre>
<p>If the card reader is not directly supported by pcscd (but is supported by openct) we need to configure <code>/etc/reader.conf.d/openct</code>, a config file of pcscd, to use OpenCT as the input method, for this the file should contain:</p>
<pre>
FRIENDLYNAME     "OpenCT"
DEVICENAME       /dev/null
LIBPATH          /usr/lib/openct-ifd.so
CHANNELID        0
</pre>
<p>after modifying this file on Debian (on non-Debian systems you&#8217;ll probably have to modify <code>/etc/reader.conf</code> directly) we have to run:</p>
<pre>
update-reader.conf
</pre>
<p>which creates a new <code>/etc/reader.conf</code>. Now stop and restart openct and pcscd in the following order:</p>
<pre>
/etc/init.d/pcscd stop
/etc/init.d/openct restart
/etc/init.d/pcscd start
</pre>
<p>When everything went OK, you should see a pcscd based reader using <code>opensc-tool</code>:</p>
<pre>
opensc-tool -l
</pre>
<pre>
Readers known about:
Nr.    Driver     Name
0      pcsc       OpenCT 00 00
</pre>
<p>Add user to &#8220;scard&#8221; group in /etc/group and log in again to have the permissions to access the card. This is necessary if you want to use a reader provided by openct without going through <code>pcscd</code>.<br />
If all else fails, you can still use <code>openct</code> without <code>pcscd</code> and set <code>reader_drivers</code> in <code>/etc/opensc/opensc.conf</code> to:</p>
<pre>
reader_drivers = openct;
</pre>
<p>Then a reader should be visible like this:
<pre>

opensc-tool -l
</pre>
<pre>
Readers known about:
Nr.    Driver     Name
0      openct     Aladdin eToken PRO 64k
1      openct     OpenCT reader (detached)
2      openct     OpenCT reader (detached)
3      openct     OpenCT reader (detached)
4      openct     OpenCT reader (detached)
</pre>
<p>Now we should be able to read the card, if there is only one token in the USB port and no other smartcard readers are installed, we can leave out the -r option (for specifying the reader to use):
<pre>

cardos-info
</pre>
<pre>
3b:f2:18:00:02:c1:0a:31:fe:58:c8:09:75
Info : CardOS V4.2B (C) Siemens AG 1994-2005
Chip type: 123
Serial number: 27 37 c0 09 2b 18
Full prom dump:
33 66 00 45 CB CB CB CB 7B FF 27 37 C0 09 2B 18 3f.E....{.'7..+.
00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ................
OS Version: 200.9 (that's CardOS M4.2b)
Current life cycle: 32 (administration)
Security Status of current DF:
Free memory : 1024
ATR Status: 0x0 ROM-ATR
Packages installed:
Ram size: 4, Eeprom size: 32, cpu type: 66, chip config: 63
Free eeprom memory: 27686
System keys: PackageLoadKey (version 0xfe, retries 10)
System keys: StartKey (version 0xff, retries 10)
Path to current DF:
</pre>
<p><b>1.&#160;&#160;&#160;Using Java-based Smartcards</b><br />
Java-based smartcards need some preparation to work with OpenSC. First you should make sure that you have a card that permits you to upload your own applet (cardlet) to the card. This usually means you need a so-called developer version. Avoid cards that have a proprietary manufacturer applet in read-only memory! You also usually need some development keys to upload a cardlet to the card.<br />
For the following instructions I&#8217;ve used the Gemalto TOP IM FIPS CY2 (Cyberflex Access 64k v2) which is an old card that has a Java virtual machine version 1.1 from 2001 (!) but the card is well established and will probably be available for some time.<br />
For the card reader I&#8217;ve used the Gemalto USB Shell V2 (GemPC Key), a CCID compatible reader. When buying a new reader, you should use one that follows the CCID specification from the <a href="www.pcscworkgroup.com">PC/SC Workgroup</a>, this ensures that OpenCT will support it. The card reader I&#8217;m using can read <a href="http://en.wikipedia.org/wiki/ID-000#ID-000">ID-000</a> format cards, also called SIM cards. These are small form-factor cards that are nice for authentication purposes. The Cyberflex card I&#8217;m using is available in ID-000. If a card isn&#8217;t available in ID-000, chances are you can make it fit using a service similar to this <a href="http://www.smartcardfocus.com/shop/ilp/id~82/p/index.shtml">SIM cutting service</a>.<br />
Preparing the card for use with OpenSC is a two-step process. The first step is to obtain the necessary applet for the card. The second is to upload the applet to the card and initialize the card with a default PIN. Note that 2048 bit keys may not work with MCardApplet with the current software versions, see <a href="#some-notes-on-key-sizes">Some notes on key sizes</a>.</p>
<p><b>1.1.&#160;&#160;&#160;Obtaining the MCardApplet for your card</b><br />
I recommend building your own version of the applet from source. Get the source code from svn://svn.debian.org/muscleplugins/trunk/MCardApplet using the source code control tool subversion:
<pre>

svn co svn://svn.debian.org/muscleplugins/trunk/MCardApplet
</pre>
<p>I had to make several changes to use Java 1.6 for cross-building for the ancient Java VM that runs on the card. My <code>Cflex.properties</code> looks like this:</p>
<pre>
CARD_NAME=Cflex
JAVA_BUILD_HOME=/usr
JC_HOME=${basedir}/depends/jc212
API_JAR=${JC_HOME}/lib/api21.jar
API_EXPORT_FILES=${JC_HOME}/api21_export_files
CAPTRANS=${basedir}/depends/jc212/bin/captransf.jar
VM_SOURCE_VERSION=1.2
VM_TARGET_VERSION=1.1
BOOTCLASSPATH=${basedir}/depends/jdk1.2.2/depends/jdk1.2.2/lib
</pre>
<p>In particular, I&#8217;m using the native java environment installed on debian lenny. This lives in /usr. Otherwise you should follow the excellent building instructions in the file <code>INSTALL</code>. Then I&#8217;ve modified the <code>javac</code> in the target named <code>compile</code> in the common.xml ant build file as follows:</p>
<pre>
&lt;target depends="precompile" name="compile"&gt;
    &lt;mkdir dir="${OUTPUT_DIR}"/&gt;
    &lt;javac debug="on"
        verbose="on"
        fork="true"
        executable="${JAVA_BUILD_HOME}/bin/javac"
        srcdir="${APPLET_SRC}"
        destdir="${OUTPUT_DIR}"
        target="${VM_TARGET_VERSION}"
        source="${VM_SOURCE_VERSION}"&gt;
        &lt;bootclasspath&gt;
            &lt;pathelement location="${BOOTCLASSPATH}"/&gt;
        &lt;/bootclasspath&gt;
        &lt;classpath&gt;
            &lt;pathelement location="${API_JAR}"/&gt;
            &lt;pathelement location="."/&gt;
            &lt;pathelement path="${java.class.path}"/&gt;
        &lt;/classpath&gt;
    &lt;/javac&gt;
&lt;/target&gt;
</pre>
<p>I&#8217;ve added the target and source options. These refer to the specific java virtual machine version we&#8217;re cross-building for. I&#8217;ve also added the bootclasspath to get the classes that are VM specific from the old java development package.<br />
This allows me to cross-build the applet for an old version of the java virtual machine without running the old java development environment which does no longer run on recent versions of Linux due to library incompatibilities.<br />
I also had to change all the backslashes in <code>common.xml</code> to forward slashes. It looks like the java compiler can handle the backslashes in path names, but the other tools cannot.<br />
Before building you should also look through <code>CflexCapabilities.properties</code> for any capabilities you want to enable which are not enabled in the default configuration. I had to enable <code>-DWITH_RSA_2048</code> and <code>-DWITH_SIGN</code> for example.<br />
For the impatiant I&#8217;m offering a <a href="http://project.runtux.com/download/CardEdgeCflex.ijc">pre-compiled version</a> of the applet. I&#8217;ll update this text with the build instructions soon.</p>
<p><b>1.2.&#160;&#160;&#160;Uploading the applet to the card</b><br />
As a preparation for this step, you should install the pcsc daemon and the pcsclite development packages on debian:
<pre>

apt-get install pcscd libpcsclite-dev
</pre>
<p>For uploading the applet to the card, I recommend using <a href="http://downloads.sourceforge.net/project/globalplatform/GPShell/GPShell-1.4.2/gpshell-1.4.2.tar.gz">gpshell</a>, a tool from the <a href="http://sourceforge.net/projects/globalplatform/">globalplatform project</a> which depends on the <a href="http://downloads.sourceforge.net/project/globalplatform/GlobalPlatform%20Library/GlobalPlatform%20Library%205.0.0/globalplatform-5.0.0.tar.gz">globalplatform library</a>. Unfortunately these are not yet packaged as Debian packages, so obtain the sourcecode to both, <a href="http://downloads.sourceforge.net/project/globalplatform/GPShell/GPShell-1.4.2/gpshell-1.4.2.tar.gz">gpshell</a> and the <a href="http://downloads.sourceforge.net/project/globalplatform/GlobalPlatform%20Library/GlobalPlatform%20Library%205.0.0/globalplatform-5.0.0.tar.gz">globalplatform library</a> . Unpack these packages and build using the normal process:</p>
<pre>
./configure
make
make install
</pre>
<p>For the <a href="http://downloads.sourceforge.net/project/globalplatform/GlobalPlatform%20Library/GlobalPlatform%20Library%205.0.0/globalplatform-5.0.0.tar.gz">globalplatform library</a> you need the development libraries for libpcsclite, available as the Debian package <code>libpcsclite-dev</code> which should be installed before the <code>./configure</code> step above.<br />
If you installed the globalplatform library without root privileges, you have to run <code>ldconfig</code> as root to make the new library available in the shared library cache.<br />
Check that your smartcard services are running (see above for how to do that) and verify that you see your card reader (or token) using:
<pre>

opensc-tool -l
</pre>
<p>The <code>gpshell</code> tool interfaces to the card via pcscd, so you should see something similar to the following:</p>
<pre>
Readers known about:
Nr.    Driver     Name
0      pcsc       Gemplus GemPC Key 00 00
</pre>
<p>Now we can proceed to upload the applet using <code>gpshell</code>. We need the following <a href="http://project.runtux.com/download/applet_install.gpshell">applet upload gpshell script</a>, put this into the file <code>applet_install.gpshell</code>, note that lines terminated with &#8220;\&#8221; need to be concatenated, gpshell currently doesn&#8217;t understand continuation lines:</p>
<pre>
enable_trace
establish_context
card_connect
select -AID a000000003000000
open_sc -security 1 -keyind 0 -keyver 0 \
   -mac_key 404142434445464748494a4b4c4d4e4f \
   -enc_key 404142434445464748494a4b4c4d4e4f
delete -AID a00000000101
delete -AID a000000001
delete -AID a0000003230101
delete -AID a00000032301
install_for_load -pkgAID a000000001 -nvCodeLimit 16000 \
   -sdAID a000000003000000
load -file CardEdgeCflex.ijc
install_for_install -instParam 00 -priv 02 -AID a00000000101 \
   -pkgAID a000000001 -instAID a00000000101 -nvDataLimit 32000
card_disconnect
release_context
</pre>
<p>and run the script with <code>gpshell</code>:</p>
<pre>
gpshell applet_install.gpshell
</pre>
<p>Finally we will have to set a default PIN for the card using <code>opensc-tool</code>:</p>
<pre>
opensc-tool -s 00:A4:04:00:06:A0:00:00:00:01:01 -s \
B0:2A:00:00:38:08:4D:75:73:63:6C:65:30:30:04:01:08:\
30:30:30:30:30:30:30:30:08:30:30:30:30:30:30:30:30:\
05:02:08:30:30:30:30:30:30:30:30:08:30:30:30:30:30:\
30:30:30:00:00:17:70:00:02:01
</pre>
<p>This sets the PIN to eight zeros, &#8220;00000000&#8243;. After this procedure the card can be used like a normal <a href="http://en.wikipedia.org/wiki/PKCS">PKCS#15</a> based card with OpenSC.</p>
<p><b>1.2.1.&#160;&#160;&#160;Some notes on using the gpshell script with other cards</b><br />
Many of the magic numbers in the gpshell script depend on the card in use and on the applet that is uploaded. An <code>AID</code> is an applet-ID. The <code>open_sc</code> command has nothing to do with OpenSC, but opens a secure channel to the card. The parameters are the developer keys of the card. In our example, the key is used twice and the hex-bytes denote the string:</p>
<pre>
@ABCDEFGHIJKLMNO
</pre>
<p>The AID used for the secure channel is different for other brands of cards. I was able to find out this AID using the following <a href="http://project.runtux.com/download/aid.gpshell">AID gpshell script</a>:</p>
<pre>
enable_trace
establish_context
card_connect
open_sc -security 1 -keyind 0 -keyver 0 \
   -mac_key 404142434445464748494a4b4c4d4e4f \
   -enc_key 404142434445464748494a4b4c4d4e4f
get_status -element 80
card_disconnect
release_context
</pre>
<p>This displays for the Gemalto TOP IM FIPS CY2:
<pre>

List of applets (AID state privileges)
a000000003000000        7       0
</pre>
<p>The delete commands remove older versions of the applet &#8212; there also was a version that had another applet ID &#8212; from the card before uploading the new version. Think of the applet living in a package named a000000001 and the applet named a00000000101. The <code>install_for_load</code> command establishes the package inside the a000000003000000 package. Then the <code>install_for_install</code> command installs the applet into non volatile memory after upload.<br />
Note that these numbers are hard-coded into the applet that is being uploaded. This is defined during compile-time and for the MCardApplet this can be configured in the <code>common.xml</code> ant-file. When packaging the compiled java classes, the build process generates <code>.cap</code> files which contain the applet ID in binary format, notably the <code>Applet.cap</code> file contains the AID of the applet.<br />
So if these numbers are changed when building a custom applet, be sure to adapt the upload commands, too. A warning here: All tools that depend on the MCardApplet expect the given AID, so changing the AID would incur a change of all tools or at least their configuration.</p>
<p><b>2.&#160;&#160;&#160;OpenVPN Preparation: Step by step process with high-level tool</b><br />
This section describes how to initialize a token, create a user key and certificate using tools that come with OpenVPN. This was only tested on Linux since the certificate handling scripts for OpenVPN are more advanced on Linux.<br />
I had to patch the <code>pkitool</code> of OpenVPN to use the <code>pkcs15-init</code> command instead of the <code>pkcs11-tool</code> command for initializing the token and creating keys. The reason is that Aladdin limits their tokens to use one key for only one purpose (encryption or signing). The <code>pkcs15-init</code> command allows the specification of the key purpose while the <code>pkcs11-tool</code> command does not.<br />
In the following we assume you are in the easy-rsa directory of OpenVPN, and you have initialized the configuration by reading the configuration in <code>vars</code>. It&#8217;s also always a good idea to have a backup of all the OpenVPN keys before starting.<br />
Initializing the token for first use (or re-using an already formatted token) THIS DESTROYS ALL DATA ON THE TOKEN:
<pre>

./pkitool --pkcs15-init 0 "Thomas Mustermann"
</pre>
<pre>
New User PIN.
Please enter User PIN:
Please type again to verify:
Unblock Code for New User PIN (Optional - press return for no PIN).
Please enter User unblocking PIN (PUK):
Please type again to verify:
</pre>
<p>If the token was already initialized, the procedure would also ask for the old password.<br />
Now we can check that everything worked, by looking at the PINs:
<pre>

pkcs15-tool --list-pins
</pre>
<p>Now we can proceed to generate a key pair and a certificate, this takes a long time:
<pre>

./pkitool --pkcs15 /usr/lib/opensc-pkcs11.so 0 45 "user cert" client27
</pre>
<p>When everything went OK, we should be able to display keys, public keys, and certificates on the token:
<pre>

pkcs15-tool --list-keys
pkcs15-tool --list-public-keys
pkcs15-tool --list-certificates
</pre>
<p><b>3.&#160;&#160;&#160;What is needed for Windows</b><br />
I&#8217;ve first installed the latest <a href="http://openvpn.net/release/openvpn-2.1_rc21-install.exe">OpenVPN installer</a>, only this package has the necessary <code>TAP</code> network driver for Linux. Only the TAP driver needs to be installed.<br />
I&#8217;ve used a compiled version of OpenVPN that comes bundled with OpenSC from the binary <a href="http://www.opensc-project.org/files/build/">windows repository</a>, I&#8217;ve used the latest</p>
<pre>
opensc-i686-w32-mingw32-007-*.*
</pre>
<p>files (from Oct 2009). For 64bit Windows (AMD64) the
<pre>

opensc-x86_64-pc-mingw32-003*.*
</pre>
<p>files should be used. Everything unpacked from these files should be installed to
<pre>

C:\Programs\OpenVPN
</pre>
<p>I&#8217;ve also created a configuration directory under that directory called <code>config</code>. In config there are the necessary certificates (root ca) and hash keys and the <code>client.ovpn</code> configuration file.<br />
When using my OpenVPN admin script, Python for windows from <a href="http://www.python.org">python.org</a> and the <code>Python WIN32</code> package are needed. In addition my <a href="http://rsclib.sourceforge.net">rsclib</a> library needs to be installed. For installing rsclib, unpack the <code>.zip</code> file and run:</p>
<pre>
setup.py install
</pre>
<p>from a command prompt. The admin script in <code>pyovpn.zip</code> has the same installation procedure.<br />
After installing everything, basic working of the smart card can be verified with the OpenSC tools:
<pre>

opensc-tool -l
cardos-info
pkcs15-tool --list-certificates
</pre>
<p><b>3.1.&#160;&#160;&#160;Aladdin Token</b><br />
For using the Aladdin eToken with Windows, the smart card tools of the manufacturer have to be installed &#8212; these include the driver for accessing the tokens. I&#8217;ve used:
<pre>

PKIClient-x32-5.00.msi
</pre>
<p>from
<pre>

eToken PKI Client 5.0 SP1 Windowsx32.zip
</pre>
<p><b>3.2.&#160;&#160;&#160;Gemalto USB Shell Token V2</b><br />
The driver for the Gemalto USB Shell Token reader can be downloaded free of charge from the <a href="http://support.gemalto.com/index.php?id=61">Gemalto website</a>.</p>
<p><b>4.&#160;&#160;&#160;Using OpenVPN with SmartCard</b><br />
OpenVPN uses a PKCS#11 provider library, on Debian this is <code>/usr/lib/opensc-pkcs11.so</code>, to access the smart card. We can show which certificates are on the card by issuing:</p>
<pre>
openvpn --show-pkcs11-ids /usr/lib/opensc-pkcs11.so
</pre>
<pre>
The following objects are available for use.
Each object shown below may be used as parameter to
--pkcs11-id option please remember to use single quote mark.

Certificate
      DN:             /C=AT/ST=AT/L=Weidling/ ...
      Serial:         03
      Serialized id:  OpenSC\x20Project/PKCS\x20 ...
</pre>
<p>Now OpenVPN can be started with the smartcard. I&#8217;m using the following additional config entries for OpenVPN &#8212; <code>pkcs11-providers</code> is set to the path of the PKCS#11 provider library:</p>
<pre>
pkcs11-providers "/usr/lib/opensc-pkcs11.so"
pkcs11-id-management
management 127.0.0.1 4711
management-query-passwords
management-hold
</pre>
<p>For Windows the provider library becomes (assuming the OpenSC tools where installed to C:ProgramsOpenVPNbin):
<pre>

pkcs11-providers "C:\\Programs\\OpenVPN\\bin\\opensc-pkcs11.dll"
</pre>
<p>The other parameters are the same as for other operating systems.<br />
Note also that the <code>askpass</code> option of OpenVPN does <em>not</em> work for querying the token password. In my experiment I had to give the token password to OpenVPN via the management interface using the config option <code>management-query-passwords</code>.<br />
This configuration tells OpenVPN to open the management interface on Port 4711 of localhost. It will ask for the passphrase of the Aladdin token on that port. Additionally we wait (<code>management-hold</code>) until a management program has opened the management interface and told OpenVPN to proceed.<br />
The <code>pkcs11-id-management</code> tells OpenVPN to accept the <code>pkcs11-id</code> to use via the management interface. With a little intelligence in the management interface we can avoid having the pkcs11-id in the configuration file (which would then be different for each user).<br />
OpenVPN can be asked via the management interface about a listing of all <code>pkcs11-ids</code>. If there is only one certificate on the card, we feed the id of the only certificate back to OpenVPN when it asks about the pkcs11-id. This can be done without user intervention.<br />
Unfortunately the feature that OpenVPN can ask the smartcard for all the certificates depends on the Token being present when OpenVPN is started. An alternative is to specify the <cite>pkcs11-id`</cite> directly in the configuration file. If this is specified, the management interface will ask for the token if it isn&#8217;t present when starting OpenVPN. The parameter to the <code>pkcs11-id</code> config parameter is the <code>Serialized id</code> from the command output above.<br />
Since I have not found any graphical user interface programs for OpenVPN that can deal with asking the user for the token passphrase, I&#8217;ve written a little command-line python script which can be run on both, Windows and Linux, and will ask the user to insert the token and specify the token passphrase.<br />
OpenVPN can be started with the script by issuing the command:
<pre>

pyovpn
</pre>
<p>in a command prompt window. The command will start openvpn and proceed to ask for necessary token passwords.<b></p>
<p>4.1.&#160;&#160;&#160;Low-level usage of the management interface</b><br />
With the <code>management-query-passwords</code> option, OpenVPN will ask the password from the management interface. After starting the OpenVPN daemon and connnecting to the managment interface on the defined port (e.g., using telnet) we see the following message:</p>
<pre>
&gt;INFO:OpenVPN Management Interface Version 1 -- type 'help' for more info
&gt;PASSWORD:Need 'OpenSC Card (New User) token' password
</pre>
<p>The password can then be entered using the password command of the managment interface:
<pre>

password 'OpenSC Card (New User) token' sehrgeheimespasswort
</pre>
<p>OpenVPN answers with:
<pre>

SUCCESS: 'OpenSC Card (New User) token' password entered, but not yet verified
</pre>
<p><b>5.&#160;&#160;&#160;Key Revocation</b><br />
Revoke a certificate:
<pre>

openssl ca  -config $KEY_CONFIG -revoke keys/02.pem
</pre>
<p>(re-) generate key revocation list (CRL):
<pre>

openssl ca  -config $KEY_CONFIG -gencrl -out keys/crl.pem
</pre>
<p><b>6.&#160;&#160;&#160;OpenVPN Preparation: Step by step process with low-level tools</b><br />
This section describes the low-level tools as used by the patched <code>pkitool</code> from OpenVPN. It does not create a certificate with OpenSSL. This is for documentation purposes only (to understand what goes on behind the scenes) and was my first approach to getting started with OpenSC.</p>
<ul>
<li>
Erase the card &#8212; if you already have a Security Officer PIN installed, you need this for erasing the card:
<pre>

pkcs15-init -E
</pre>
</li>
<li>
Create PKCS#15 structure (option &#8211;no-so-pin specified not to create security officer PIN and user PUK) on the card &#8212; note that the keys need to be between 6 and 8 characters long and should be numeric if you intend to use a keypad for key-entry (which applies mostly to smartcards not to USB tokens). Also note that if you omit &#8211;no-so-pin you should keep the Security Officer PIN secure &#8212; only with it can the token be re-formatted:
<pre>

pkcs15-init --create-pkcs15 --no-so-pin
</pre>
<pre>
New Security Officer PIN (Optional - press return for no PIN).
Please enter Security Officer PIN:
Please type again to verify:
Unblock Code for New User PIN (Optional - press return for no PIN).
Please enter User unblocking PIN (PUK):
Please type again to verify:
</pre>
</li>
<li>
The steps above can be rolled into one command:
<pre>

pkcs15-init -E --create-pkcs15 --no-so-pin
</pre>
</li>
<li>
Add an authentication (user) ID to the token with corresponding PIN and PUK:
<pre>

pkcs15-init --store-pin --auth-id 01 --label "User Name"
</pre>
<pre>
New User PIN.
Please enter User PIN:
Please type again to verify:
Unblock Code for New User PIN (Optional - press return for no PIN).
Please enter User unblocking PIN (PUK):
Please type again to verify:
</pre>
</li>
<li>
Check that everything worked, by looking at the PINs:
<pre>

pkcs15-tool --list-pins
</pre>
<pre>
PIN [Security Officer PIN]
    Com. Flags: 0x3
    ID        : ff
    Flags     : [0xB2], local, initialized, needs-padding, soPin
    Length    : min_len:6, max_len:8, stored_len:8
    Pad char  : 0x00
    Reference : 1
    Type      : ascii-numeric
    Path      : 3f005015

PIN [User Name]
    Com. Flags: 0x3
    ID        : 01
    Flags     : [0x32], local, initialized, needs-padding
    Length    : min_len:4, max_len:8, stored_len:8
    Pad char  : 0x00
    Reference : 3
    Type      : ascii-numeric
    Path      : 3f005015
</pre>
</li>
<li>
Now we can generate an RSA key on the card. Note that we could also import a PKCS-12 key onto the card, but the more secure option is to let the card generate the key (so the key will never be available outside the card). The split-key option actually generates two key-pairs, one for encryption and one for signing. There are some labelling options to attach names to the generated keys but these aren&#8217;t needed if you want only one key. You could specify an application profile with the &#8211;id option, if this isn&#8217;t given the default ID 45 (authentication purposes) is used. The command will ask for the Security officer PIN, then for the User PIN, then again for the Security officer PIN (!):
<pre>

pkcs15-init --generate-key rsa/2048 --auth-id 01 --split-key
</pre>
<p>Note that with Java smartcards the keysize 2048 might not work with the current version of the tools, see <a href="#some-notes-on-key-sizes">Some notes on key sizes</a>.
</li>
<li>
Now we can verify that the key was actually stored on the card:
<pre>

pkcs15-tool --list-keys
</pre>
<pre>
Private RSA Key [Private Key]
    Com. Flags  : 3
    Usage       : [0x4], sign
    Access Flags: [0x1D], sensitive, alwaysSensitive, neverExtract, local
    ModLength   : 2048
    Key ref     : 16
    Native      : yes
    Path        : 3f005015
    Auth ID     : 01
    ID          : 45
</pre>
</li>
<li>
List public keys:
<pre>

pkcs15-tool --list-public-keys
</pre>
<pre>
Public RSA Key [Public Key]
    Com. Flags  : 2
    Usage       : [0x4], sign
    Access Flags: [0x0]
    ModLength   : 2048
    Key ref     : 0
    Native      : no
    Path        : 3f0050153048
    Auth ID     :
    ID          : 45
</pre>
</li>
<li>
For the following steps we will need a minimum openssl config file:
<pre>

openssl_conf            = openssl_init

[ openssl_init ]
engines                 = engine_section

[ req ]
default_bits            = 2048
default_keyfile         = privkey.pem
distinguished_name      = req_distinguished_name

[ req_distinguished_name ]
countryName                     = Country Name (2 letter code)
countryName_default             = AT
countryName_min                 = 2
countryName_max                 = 2
stateOrProvinceName             = State or Province Name (full name)
stateOrProvinceName_default     = Austria
localityName                    = Locality Name (eg, city)
localityName_default            = Vienna
0.organizationName              = Organization Name (eg, company)
0.organizationName_default      = example.com
organizationalUnitName          = Organizational Unit Name (eg, section)
organizationalUnitName_default  = IT-Department
commonName                      = Common Name (eg, server\'s hostname)
commonName_max                  = 64
emailAddress                    = Email Address
emailAddress_max                = 40

[ engine_section ]
pkcs11 = pkcs11_section

[ pkcs11_section ]
engine_id = pkcs11
dynamic_path = /usr/lib/engines/engine_pkcs11.so
MODULE_PATH = /usr/lib/opensc-pkcs11.so
init = 0
</pre>
</li>
<li>
Generate a certificate request (CSR) from this key using openssl:
<pre>

CLIENT=newclient
openssl req -days 3650 -new -out $CLIENT.csr -config openssl.cnf \
  -engine pkcs11 -keyform engine -key 0:45 -sha1
</pre>
<p>This will ask for all the certificate parameters. Alternatively these can be specified using the <code>-subj</code> option of openssl (this is broken into several lines but should be assembled into one line) with the following parameter:</p>
<pre>
/C=AT/ST=Austria/L=Vienna/O=example.com/OU=IT-Department
/CN=$CLIENT/emailAddress=user@example.com
</pre>
</li>
<li>
You can view the contents of the CSR using:
<pre>

openssl req -in $CLIENT.csr -noout -text
</pre>
</li>
<li>
Now sign the certificate request with whatever tools you are using. With the pkitool of OpenVPN this would become (after having copied the certificate request newclient.csr to the keys directory):
<pre>

pkitool --sign newclient
</pre>
<p>The message about not being able to access <code>newclient.key</code> can be ignored.
</li>
<li>
You may want to delete old certificates from the token:
<pre>

pkcs15-init --delete-objects cert --id=45
</pre>
</li>
<li>
Then import the new certificate onto the token:
<pre>

pkcs15-init --store-certificate newclient.crt --id=45
</pre>
</li>
<li>
Reading a certificate from the token and output with openssl:
<pre>

pkcs15-tool --read-certificate 45 | openssl x509 -noout -text
</pre>
</li>
</ul>
<p><a name="some-notes-on-key-sizes"> </a><br />
<b>6.1.&#160;&#160;&#160;Some notes on key sizes</b><br />
Using 2048 bit keys should generally be possible with newer cards. I had some problems with these key sizes using my Java smartcard, though.<br />
After uploading the applet to the card, it is possible to create a key with either 1024 or 2048 bit. This indicates that the card <em>is</em> able to handle the large keysize. When trying to generate a CSR using openssl the command failed with:</p>
<pre>
[opensc-pkcs11] iso7816.c:99:iso7816_check_sw: No precise diagnosis
[opensc-pkcs11] muscle.c:745:msc_compute_crypt_process: returning with:
                Card command failed
[opensc-pkcs11] muscle.c:840:msc_compute_crypt: returning with:
                Card command failed
[opensc-pkcs11] card-muscle.c:749:muscle_compute_signature:
                Card signature failed: Card command failed
[opensc-pkcs11] sec.c:53:sc_compute_signature: returning with:
                Card command failed
[opensc-pkcs11] pkcs15-sec.c:273:sc_pkcs15_compute_signature:
                sc_compute_signature() failed: Card command failed
20808:error:0E06D06C:configuration file routines:NCONF_get_string:no value:
conf_lib.c:329:group=req_attributes name=unstructuredName_min
20808:error:0E06D06C:configuration file routines:NCONF_get_string:no value:
conf_lib.c:329:group=req_attributes name=unstructuredName_max
20808:error:8000A005:Vendor defined:PKCS11_rsa_sign:General Error:
p11_ops.c:97:
20808:error:0D0C3006:asn1 encoding routines:ASN1_item_sign:EVP lib:
a_sign.c:276:
</pre>
<p>Worse, after reinitializing the card in this state with:
<pre>

pkcs15-init -E --create-pkcs15 --no-so-pin
pkcs15-init --store-pin --auth-id 01 --label "User Name"
</pre>
<p>and trying to generate a smaller key, this fails with:
<pre>

pkcs15-init --generate-key rsa/1024 --auth-id 01 --split-key
</pre>
<pre>
[pkcs15-init] iso7816.c:102:iso7816_check_sw: Unknown SWs; SW1=9C, SW2=03
[pkcs15-init] muscle.c:557:msc_generate_keypair: returning with:
              Card command failed
[pkcs15-init] card.c:678:sc_card_ctl: returning with:
              Card command failed
[pkcs15-init] pkcs15-muscle.c:272:muscle_generate_key:
              Unable to generate key
[pkcs15-init] pkcs15-muscle.c:273:muscle_generate_key: returning with:
              Card command failed
Failed to generate key: Card command failed
</pre>
<p>I was able to fix this by re-downloading the applet onto the card. This also happens the other way round, when generating a 1024 bit key first and trying &#8212; after reinitializing the card with <code>pkcs15-init</code> &#8212; to generate a 2048 bit key.<br />
So I recommend to stick with 1024 bit keys with the current software versions (debian lenny).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/12/05/150/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

