<?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; documentation</title>
	<atom:link href="http://blog.runtux.com/category/documentation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.runtux.com</link>
	<description>Neues, Interessantes, Skurriles</description>
	<lastBuildDate>Mon, 19 Apr 2010 15:21:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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>
		<item>
		<title>Media Ecologies Conference</title>
		<link>http://blog.runtux.com/2009/11/03/148/</link>
		<comments>http://blog.runtux.com/2009/11/03/148/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 12:05:08 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[licensing]]></category>
		<category><![CDATA[neu]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=148</guid>
		<description><![CDATA[I&#8217;m currently at the media ecologies conference in manchester, UK. I was just talking about what tools and interfaces we need for collaboration tools (on the web). This also rehashes some of the ideas in my blog entry on cloud computing and the problems with (lack of) openness of cloud applications. The slides of my [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently at the <a href="http://www.espach.salford.ac.uk/sssi/p2p/">media ecologies conference</a> in manchester, UK. I was just talking about what tools and interfaces we need for collaboration tools (on the web). This also rehashes some of the ideas in my <a href="http://blog.runtux.com/2009/08/04/106/">blog entry on cloud computing</a> and the problems with (lack of) openness of cloud applications. The slides of my talk can be downloaded from <a href="http://runtux.com/files/download/manchester.4.pdf">my website</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/11/03/148/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Did Ronja Fail?</title>
		<link>http://blog.runtux.com/2009/10/27/142/</link>
		<comments>http://blog.runtux.com/2009/10/27/142/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 17:30:32 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[licensing]]></category>
		<category><![CDATA[open hardware]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=142</guid>
		<description><![CDATA[Ronja, the optical data link device, is often cited as a failed open source hardware project &#8212; the last one mentioning it I just read is Lawrence Kincheloe&#8217;s excellent essay Musings Upon the Nature of Open Source Hardware as a Business at the end of his project visit summary at Factor e Farm.
Roja did fail [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://ronja.twibright.com/">Ronja</a>, the optical data link device, is often cited as a failed open source hardware project &#8212; the last one mentioning it I just read is Lawrence Kincheloe&#8217;s <em>excellent</em> essay <a href="http://openfarmtech.org/weblog/?p=1187">Musings Upon the Nature of Open Source Hardware as a Business</a> at the end of his project visit summary at <a href="http://openfarmtech.org/index.php?title=Factor_e_Farm">Factor e Farm</a>.<br />
Roja <em>did</em> fail (in the sense that it isn&#8217;t very widespread today not in the sense of being a cool open source project). One of the research studies I know of is the presentation &#8220;<a href="http://www.oekonux-conference.org/program/events/22.en.html">Ronja &#8212; Darknet of Lights</a>&#8221; by Johan <a href="http://www.oekonux-conference.org/program/speakers/33.en.html">S&#246;derberg</a> at the <a href="http://www.oekonux-conference.org/">4th Oekonux conference</a> for which <a href="http://www.oekonux-conference.org/documentation/croome/Soederberg.mp3">Audio</a> is available. The study is very interesting although I don&#8217;t agree with the conclusions. So why did Ronja &#8220;fail&#8221;?<br />
Ronja&#8217;s main application was cheap internet access. At the time of its design in 2001 <a href="http://en.wikipedia.org/wiki/Wireless_LAN">wireless LAN</a> (Wifi) wasn&#8217;t yet available cheaply. And in the Czech Republic <a href="http://en.wikipedia.org/wiki/Digital_subscriber_line">DSL</a> wasn&#8217;t available at the time.<br />
Now consider the technical characteristics of Ronja:
<ul class="simple">
<li>Up to 10MBit/s</li>
<li>Up to 1.4 km range</li>
<li>Light: Doesn&#8217;t work in fog, or other bad weather (snow)</li>
<li>Light: Hard to get the beam to the destination (direction)</li>
<li>Light: Interference with daylight</li>
<li>For full-duplex communication we need two (receiver + transmitter) devices</li>
<li>sold for around 700$ at the time (the LED alone cost 120$ you get these for .75$ now)</li>
<li>needed &#8220;a hell of a lot of time to build one&#8221; according to <a href="http://www.oekonux-conference.org/program/speakers/33.en.html">S&#246;derberg</a></li>
</ul>
<p>And compare these with WLAN:
<ul class="simple">
<li>Up to 54MBit/s</li>
<li>With good antennas several km range (I&#8217;ve built a link with 5.5km)</li>
<li>Antennas are cheap and can even be built at home, e.g., a <a href="http://en.wikipedia.org/wiki/Cantenna">Cantenna</a> &#8212; you can build a cantenna in an evening</li>
<li>Works in fog and bad weather</li>
<li>we need only one antenna at sender and one at receiver</li>
<li>WLAN is <em>very</em> cheap nowadays, it became available (with new frequencies) in 2005 in cz.</li>
</ul>
<p>So I think that Ronja &#8220;failed&#8221; because it was replaced by something better and cheaper that was readily available. It isn&#8217;t an example of a failed open source business model for hardware and shouldn&#8217;t be used as an example. This doesn&#8217;t mean that we already know how a business model for open source hardware should look like, though.<br />
The idea behind Ronja &#8212; according to the <a href="http://en.wikipedia.org/wiki/RONJA">Wikipedia article on Ronja</a> &#8220;User Controlled Technology&#8221; is (mostly) achieved with WLAN technology today: We can use cheap devices and modify them (using open source firmware and homegrown antennas) to suit our needs. And there are large wireless communities now like <a href="http://funkfeuer.at/">Funkfeuer</a> in Vienna who do their own Internet communication.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/10/27/142/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
<enclosure url="http://www.oekonux-conference.org/documentation/croome/Soederberg.mp3" length="65504681" type="audio/mpeg" />
		</item>
		<item>
		<title>PGAPy: Genetische Algorithmen mit Python</title>
		<link>http://blog.runtux.com/2009/10/25/138/</link>
		<comments>http://blog.runtux.com/2009/10/25/138/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 07:57:22 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[deutsch]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=138</guid>
		<description><![CDATA[[Dies ist der Abstract meines Vortrags am Linuxwochenende im Metalab, die alte Version des Abstracts ist inzwischen von der Linuxwochen Homepage verschwunden...]
PGAPy ist ein Python-Wrapper f&#252;r PGAPack, eine der vollst&#228;ndigsten Bibliotheken f&#252;r genetischen Algorithmen. Die Python-Bibliothek eignet sich f&#252;r eigene Experimente mit genetischen Algorithmen, aber auch f&#252;r die Implementierung von kompletten Anwendungen.
Der Vortrag gibt eine [...]]]></description>
			<content:encoded><![CDATA[<p>[Dies ist der Abstract meines Vortrags am Linuxwochenende im Metalab, die alte Version des Abstracts ist inzwischen von der Linuxwochen Homepage verschwunden...]</p>
<p><a href="http://pgapy.sourceforge.net/">PGAPy</a> ist ein Python-Wrapper f&#252;r <a href="ftp://info.mcs.anl.gov/pub/pgapack/README">PGAPack</a>, eine der vollst&#228;ndigsten Bibliotheken f&#252;r genetischen Algorithmen. Die Python-Bibliothek eignet sich f&#252;r eigene Experimente mit genetischen Algorithmen, aber auch f&#252;r die Implementierung von kompletten Anwendungen.</p>
<p>Der Vortrag gibt eine kurze Einf&#252;hrung in genetischen Algorithmen mit Beispielen in Python. Vorgestellt wird u.a. ein Programm zum automatischen Erzeugen der bekannten Sudoku Zahlenr&#228;tsel. Dabei wird schrittweise die Bewertungsfunktion f&#252;r ein Sudoku entwickelt.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/10/25/138/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linuxwochenende 2009</title>
		<link>http://blog.runtux.com/2009/10/23/134/</link>
		<comments>http://blog.runtux.com/2009/10/23/134/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 13:39:42 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[deutsch]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[money]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=134</guid>
		<description><![CDATA[Dieses Wochenende ist wieder Linuxwochenende im metalab, ich werde wieder einen Vortrag zu Open Money halten, ausserdem einen Lightning-Talk zu Generierung von Morse-Code als MIDI-Datei (was für einige Anwärter auf die Amateurfunklizenz vielleicht interessant ist, auch wenn das Code-Requirement inzischen gefallen ist.)
]]></description>
			<content:encoded><![CDATA[<p>Dieses Wochenende ist wieder <a href="http://linuxwochenende2009.luga.at/">Linuxwochenende</a> im <a href="http://metalab.at">metalab</a>, ich werde wieder einen <a href="http://linuxwochenende2009.luga.at/paper15.html">Vortrag zu Open Money</a> halten, ausserdem einen Lightning-Talk zu Generierung von <a href="http://linuxwochenende2009.luga.at/paper16.html">Morse-Code als MIDI-Datei</a> (was für einige Anwärter auf die <a href="http://metalab.at/wiki/MetaFunk">Amateurfunklizenz</a> vielleicht interessant ist, auch wenn das Code-Requirement inzischen gefallen ist.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/10/23/134/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cloud computing, Vendor Lock-In and the Future</title>
		<link>http://blog.runtux.com/2009/08/04/106/</link>
		<comments>http://blog.runtux.com/2009/08/04/106/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 22:20:35 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[licensing]]></category>
		<category><![CDATA[money]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=106</guid>
		<description><![CDATA[Cloud Computing is becoming increasingly popular &#8212; and it is a danger to your freedom. But we can do something about it.
First, when the term Cloud Computing was introduced, it meant a set of low-level services like virtual machines, databases and file storage. Examples of these are Amazon Elastic Computing Cloud and related services. Since [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Cloud_computing">Cloud Computing</a> is becoming increasingly popular &#8212; and it is a danger to your freedom. But we can do something about it.<br />
First, when the term Cloud Computing was introduced, it meant a set of low-level services like virtual machines, databases and file storage. Examples of these are <a href="http://aws.amazon.com/ec2/">Amazon Elastic Computing Cloud</a> and related services. Since these services are quite low-level, they can be replicated by others, an example is the <a href="http://open.eucalyptus.com/">Eucalyptus</a> project.<br />
This means if you aren&#8217;t satisfied with the service one cloud computing provider offers, you either can change the provider or &#8212; e.g., using <a href="http://open.eucalyptus.com/">Eucalyptus</a> &#8212; roll your own.<br />
But increasingly cloud-computing is a relaunch of the old <a href="http://en.wikipedia.org/wiki/Software_as_a_service">Software as a Service</a> paradigm under a new name. This means that <em>applications</em> like Textprocessing, Spreadsheets, Wiki, Blog, Voice and Video over IP, collaboration software in general is made available as so-called &#8220;Web 2.0&#8243; applications &#8212; now called &#8220;Cloud Applications&#8221; on the web.<br />
When using these services, there is a severe risk of <a href="http://en.wikipedia.org/wiki/Vendor_lock-in">Vendor Lock-In</a> &#8212; since the applications may not be available elsewhere, you cannot easily switch the provider. Worse: From some of the Web 2.0 Services like social networks (e.g., Xing, LinkedIn, Facebook) you can&#8217;t retrieve your own data. Xing for example has a &#8220;mobile export&#8221; for data, but this works only for paying customers and only exports address data.<br />
And people have started to realize &#8212; e.g., in this <a href="http://www.facebook.com/group.php?gid=5145637860">facebook group</a> &#8212; that multiple incompatible applications &#8212; escpecially in the social network sector &#8212; puts a large burdon on customers to update multiple personal profiles on multiple sites.<br />
But although it has been noted by the Free Software and Open Source community (e.g., in an <a href="http://broadcast.oreilly.com/2009/04/stallman-discusses-free-softwa.html">interview with Richard Stallman</a> and by <a href="http://esr.ibiblio.org/?p=932">Eric S. Raymond in his blog</a>) it has not been widely recognized that cloud computing or software as a service &#8212; in particular in the form called &#8220;Web 2.0&#8243; &#8212; creates a vendor lock-in worse than for proprietary software.<br />
For your social networks this may mean that when you retrieve your data (remember, <em>you</em> helped them build that data!), the social network may throw you out as it happened <a href="http://blogs.sun.com/bblfish/entry/scoble_gets_thrown_off_facebook">in that case mentioned by Henry Story</a> and <a href="http://blogs.sun.com/bblfish/entry/data_portability_scoble_explains">later updated here</a>.<br />
The solution to this problem? Don&#8217;t get trapped in a data silo. This may still mean that there can be software as a service offerings. But the software needs to be free (as in free speech). So we can still switch to another provider or decide to host our own service.<br />
But companies won&#8217;t do it for us. As Doc Searls notes in <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 />
So this can only change if customers make and demand the change. A good rule-of-thumb for software as a service is on the page of the Open Cloud Initiative in the article <a href="http://www.opencloudinitiative.org/node/27">The four degrees of cloud computing openness</a>. While being a customer of a closed/proprietary cloud with &#8220;no access&#8221; is clearly a bad idea, open <a href="http://en.wikipedia.org/wiki/Application_programming_interface">APIs</a> and formats don&#8217;t work too well &#8212; you don&#8217;t have the software to work with your data. So the only valid options that remain are Open <a href="http://en.wikipedia.org/wiki/Application_programming_interface">APIs</a>, Open Formats <em>and</em> Open Source, and in some cases Open Data.<br />
Still most web applications &#8212; like most social network software &#8212; are of the completely closed type. There are no open formats and no open <a href="http://en.wikipedia.org/wiki/Application_programming_interface">APIs</a>. So check your dependencies: What web-applications are you depending on and what is their degree of cloud computing openness?<br />
A word on the license to guarantee openness in cloud-computing. As mentioned in the above-cited <a href="http://broadcast.oreilly.com/2009/04/stallman-discusses-free-softwa.html">interview with Richard Stallman</a>, the <a href="http://www.gnu.org/copyleft/gpl.html">GNU General Public License</a> is <em>not</em> enough to keep software in a cloud open. The cloud provider could take the software, make own modifications (which you will depend upon) and <em>not</em> release the modified software to you as a customer. Again you have a vendor lock-in. To prevent this, the <a href="http://www.gnu.org/licenses/agpl.html">GNU Affero General Public License</a> has been designed that prevents closed-source modifications to hosted applications.<br />
Finally, for all sorts of social software &#8212; not just social network software but everything that creates more value for more people, usually by linking information &#8212; should follow a distributed peer-to-peer approach. We don&#8217;t want this data to be a siloed application hosted by a single company. And if there are multiple companies hosting the data we already see the problem with multiple social network providers.<br />
So we need standards and distributed protocols. And the implementation should follow a peer-to-peer approach &#8212; like seen in filesharing applications today &#8212; to make it resilient to failure and/or take-down orders of hostile bodies (like, e.g., some governments). Lets call this &#8220;Web 3.0&#8243;.<br />
Examples of such social software are of course the social network sector. We already have a distributed protocol for social networking based on the <a href="http://en.wikipedia.org/wiki/FOAF_(software)">Friend of a Friend</a> <a href="http://en.wikipedia.org/wiki/Semantic_Web">Semantic Web</a> <a href="http://en.wikipedia.org/wiki/Ontology_(computer_science)">Ontology</a>. With this approach everyone can publish his social networking data and still be in control of who can see what. And the data is under user-control, so it&#8217;s possible to remove something.<br />
Another example of social software is probably Money (in the sense of micro- or macro payments in the net). Thomas Greco in the book <a href="http://beyondmoney.net/the-end-of-money-and-the-future-of-civilization/">The End of Money and the Future of Civilization</a> asks for separation of money and the state. A future implementation of money may well be based on a peer-to-peer social software implementation.<br />
These social software needs security solutions. We want to model trust-relationships. Parts of the puzzle are probably <a href="http://en.wikipedia.org/wiki/OpenID">OpenID</a> and a newly-proposed scheme by Henry Story called <a href="http://blogs.sun.com/bblfish/entry/more_on_authorization_in_foaf">FOAF+SSL</a> mainly used for social networking 3.0 but probably very useful for other social software solutions.<br />
So lets work on solutions for the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/08/04/106/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Verletzung der Netzneutralität durch Inode/UPC</title>
		<link>http://blog.runtux.com/2009/06/15/103/</link>
		<comments>http://blog.runtux.com/2009/06/15/103/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 09:17:03 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[deutsch]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[skurril]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=103</guid>
		<description><![CDATA[Seit einiger Zeit bekommt man von Inode/UPC einen automatischen Nameserver (DNS) zugeteilt der bei offensichtlichen Tippfehlern (wenn ein Benutzer sich beim Namen einer Webseite verschreibt) eine Werbe- und Suchmaschine von UPC zurückliefert &#8212; statt dem Benutzer mitzuteilen, dass es diese Domain nicht gibt.
Diese Verhalten eines der wichtigsten Services im Internet &#8212; der Namensauflösung &#8212; verletzt [...]]]></description>
			<content:encoded><![CDATA[<p>Seit einiger Zeit bekommt man von Inode/UPC einen automatischen Nameserver (DNS) zugeteilt der bei offensichtlichen Tippfehlern (wenn ein Benutzer sich beim Namen einer Webseite verschreibt) eine Werbe- und Suchmaschine von UPC zurückliefert &#8212; statt dem Benutzer mitzuteilen, dass es diese Domain nicht gibt.</p>
<p>Diese Verhalten eines der wichtigsten Services im Internet &#8212; der Namensauflösung &#8212; verletzt klar die <a href="http://de.wikipedia.org/wiki/Netzneutralit%C3%A4t">Netzneutralität</a> wie auch schon im Jahr 2007 von Ed Felten in seinem <a href="http://www.freedom-to-tinker.com/blog/felten/verizon-violates-net-neutrality-dns-deviations">Blog im Falle Verizon</a> festgestellt wurde. Verizon hat wohl seither auf diese Praxis &#8212; nach vielen Protesten &#8212; wieder verzichtet. Berechtigterweise wurde UPC für diese Praxis für den <a href="http://bigbrotherawards.at/2008/Nominierungen#UPC_-_Aus_.C3.B6sterreichischen_Tippfehlern_werden_US-Werbeprofile">Big Brother Award</a> nominiert &#8212; die gesammelten Daten gehen offensichtlich an einen ausländischen Werbeunternehmer. Zumindest in einem Fall kommt es bei diesem Verhalten zu Probleme bei Telefonie im Internet wie einem <a href="http://www.ip-phone-forum.de/showthread.php?t=191607">Forum Posting</a> zu entnehmen ist.</p>
<p>Schlimmer noch: UPC liefert falschen Information auch für Domains die ganz klar von jemand anderem reserviert sind. Wenn ich also nonexistent.source-forge.org ansurfe komme ich auch auf die Werbeseite von UPC &#8212; obwohl source-forge.org (ja mit Bindestrich) von dem grossen Open Source Projekthoster sourceforge reserviert ist. Hoffentlich lässt es da mal jemand auf ein Gerichtsverfahren wegen unlauterem Wettbewerb ankommen. Wäre vermutlich recht lukrativ, jedenfalls bei anderen Firmen als Sourceforge.</p>
<p>Mir war das bisher nicht aufgefallen, aber offensichtlich wurden ehemalige Inode-Kunden erst vor kurzem umgestellt, UPC-Telekabel Kunden offensichtlich schon früher.</p>
<p>Heute habe ich mich bei der UPC-Hotline beschwert. Man werde an dem Fall arbeiten und &#8220;den Fehler&#8221; beheben. Leider könne man mir keine Ticket-Nummer geben unter welcher ich meine Beschwerde nochmal urgieren kann &#8212; aber ich könne ja &#8220;in einigen Tagen&#8221; wieder anrufen. Ein Rückruf wurde mir versprochen, mal sehen ob da was kommt. Ich habe den Hotline-Bearbeiter freundlich darauf hingewiesen, dass es sich ja nicht um einen unbekannten Fehler handeln kann, wenn UPC dafür bereits für den Big Brother Award nominiert wurde.</p>
<p>Inzwischen habe ich einen Workaround gefunden: UPC hat die alten, funktionierenden Nameserver nicht abgeschaltet, in obigem Link des ip-phone-forums findet man funktionierende DNS-Server: 195.34.133.25 und 195.34.133.26 die man fix einstellen kann. Weitere Tips finden sich als Antwort auf mein <a href="http://www.luga.at/mailing-lists/luga/2009/06/msg00026.html">Posting an die LUGA-Mailingliste</a>. Die alternative ist, gleich einen eigenen Nameserver zu betreiben (unter Linux sehr einfach möglich) oder auf alternative Namenshierarchien umzusatteln wie z.B. <a href="http://www.opennicproject.org/">opennicproject</a> &#8212; auch wenn man bei Verwendung von Alternativen von einer <a href="http://www.golem.de/0904/66730.html">deutschen Ministerin gleich als pädophil</a> eingestuft wird. Es ist kaum zu glauben, was manche Politiker für einen Schwachsinn von sich geben.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/06/15/103/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>grml to the rescue</title>
		<link>http://blog.runtux.com/2009/06/05/101/</link>
		<comments>http://blog.runtux.com/2009/06/05/101/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 12:18:19 +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=101</guid>
		<description><![CDATA[I recently needed to recover data from a &#8220;dead&#8221; notebook. The only hardware I had available that had a connector for an ATA notebook harddisk was my Soekris net4801. This device doesn&#8217;t have VGA on board, so we need to boot GRML with a serial console. First I was unable to get GRML to correctly [...]]]></description>
			<content:encoded><![CDATA[<p>I recently needed to recover data from a &#8220;dead&#8221; notebook. The only hardware I had available that had a connector for an ATA notebook harddisk was my <a href="http://soekris.com/net4801.htm">Soekris net4801</a>. This device doesn&#8217;t have VGA on board, so we need to boot <a href="http://grml.org/">GRML</a> with a serial console. First I was unable to get GRML to correctly start a getty process. Meanwhile I&#8217;ve found out that the recipe in <a href="http://bts.grml.org/grml/issue485">issue485</a> of the GRML-Bugtracker does the trick (I&#8217;ve modified the console speed to the speed I&#8217;m using in the Soekris bootloader):</p>
<p><code>grml console=tty 1console=ttyS1,38400n8</code></p>
<p>I had tried <code>console=ttyS1,38400n8</code> before which doesn&#8217;t work. So I added the ssh= boot-options found out via the <a href="http://wiki.grml.org/doku.php?id=cheatcodes">grml cheatsheet</a>. I could ping the machine but no SSH. Turns out it takes a loooong time until grml starts up the ssh-daemon for two reasons</p>
<ul>
<li>The net4801 is really slow</li>
<li>GRML creates new SSH Host-keys before starting up SSH. Thats good. But a newly-started box without a Keyboard has a really small random-number pool, so the box sits there waiting for randomness to happen for generating the keys. So it helps to run several parallel pings to the machine to create some network traffic the timing of which slowly fills the randomness pool &#8230;</li>
</ul>
<p>Turns out that process took several minutes on the Soekris net4801. After waiting I was finally able to log into grml and rescue the data using ddrescue. Thanks GRML!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/06/05/101/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Good support from Beronet</title>
		<link>http://blog.runtux.com/2009/04/27/92/</link>
		<comments>http://blog.runtux.com/2009/04/27/92/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 08:35:30 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[neu]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=92</guid>
		<description><![CDATA[On April 9 I blogged here some firmware bugs of the Beronet bero*fos failover switch. They now have a new firmware 1.3.5 &#8212; a little over two weeks after reporting the bug with easter holidays in between. I&#8217;ve not had time yet to test this but wanted to blog this as an example of good [...]]]></description>
			<content:encoded><![CDATA[<p>On April 9 I <a href="http://blog.runtux.com/2009/04/09/81/">blogged here</a> some firmware bugs of the <a href="http://beronet.com/">Beronet</a> <a href="https://shop.beronet.com/product_info.php/cPath/56/products_id/159">bero*fos</a> failover switch. They now have a new <a href="http://www.beronet.com/component/option,com_remository/Itemid,38/func,selectcat/cat,5">firmware 1.3.5</a> &#8212; a little over two weeks after reporting the bug with easter holidays in between. I&#8217;ve not had time yet to test this but wanted to blog this as an example of good support. I&#8217;ll blog the test results when I&#8217;ve had time to test the device with the new firmware.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/04/27/92/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Beronet bero*fos failover switch</title>
		<link>http://blog.runtux.com/2009/04/09/81/</link>
		<comments>http://blog.runtux.com/2009/04/09/81/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 15:36:26 +0000</pubDate>
		<dc:creator>Ralf Schlatterbeck</dc:creator>
				<category><![CDATA[asterisk]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[skurril]]></category>

		<guid isPermaLink="false">http://blog.runtux.com/?p=81</guid>
		<description><![CDATA[Update 2009-04-27: There is a new firmware: good support from beronet
Update 2009-04-10: I&#8217;ve written a config-utility for the device, available in my rsclib on sourceforge (in python)
I&#8217;m now experimenting with the Beronet bero*fos failover switch. I need this for a project where two redundant asterisks should be switched by the bero*fos.
To get the following into [...]]]></description>
			<content:encoded><![CDATA[<p>Update 2009-04-27: There is a new firmware: <a href="http://blog.runtux.com/2009/04/27/92/">good support from beronet</a><br />
Update 2009-04-10: I&#8217;ve written a config-utility for the device, available in my <a href="http://rsclib.sourceforge.net">rsclib</a> on sourceforge (in python)</p>
<p>I&#8217;m now experimenting with the <a href="http://beronet.com/">Beronet</a> <a href="https://shop.beronet.com/product_info.php/cPath/56/products_id/159">bero*fos</a> failover switch. I need this for a project where two redundant asterisks should be switched by the <a href="https://shop.beronet.com/product_info.php/cPath/56/products_id/159">bero*fos</a>.<br />
To get the following into proportion: I&#8217;m a customer of Beronet and usually like their products. But selling a device for around 700.- Euro we should expect working firmware and working configuration software. Especially since the device sits at a crucial point from a safety point of view: it&#8217;s used in scenarios where we want failover capabilities for telephone equipment.<br />
The config-software is open source, so we can work around it&#8217;s shortcomings. But there is a firmware bug, setting some configuration variables via web interface has side-effects on other configuration variables. (we can work around that by writing our own config program). So I&#8217;d really like a more open design here: I&#8217;m voting for open firmware and a hardware documentation. But that might lead to others building the device for less money&#8230;<br />
I would also prefer a documentation of the parameter interface in addition to (or instead of) a configuration program. Integrating the device into other infrastructures where we don&#8217;t want a binary configuration program requires reverse-engineering. I&#8217;ve done that in the following.<br />
In the following I&#8217;m referring to berofos Firmware 1.3.3 which is the latest on Beronets webpage and in my device. The berofos tools for Linux on the webpage were apparently last updated in December 2007 and don&#8217;t have a version number.<br />
The device has four groups of 4 ports each, A, B, C, D. These can be switched in two scenarios, a <em>fallback</em> scenario, which can connect A-B or A-D and a <em>bypass</em> scenario which can connect A-B and C-D or A-D. The first scenario is useful if there are redundant devices where one device can replace another (e.g. as in our scenario with two asterisk boxes), the second scenario is useful when you have an asterisk connected in between the telephone network and an old PBX. In case the asterisk fails, the PBX can be directly connected to the telephone network.<br />
I won&#8217;t rehash the features and documentation of the device here, the <a href="http://www.beronet.com/component/option,com_remository/Itemid,38/func,selectcat/cat,5/">berofos docs and tools</a> page has a link to the manual (and to the command-line tool for both, Linux and Windows).<br />
The device has a web-interface and a command-line interface written in C under the <a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html">GPL version 2</a> license without a version-upgrade clause. The individual source files refer to a LICENSE file which isn&#8217;t included in the distribution.<br />
The web interface has several bugs, some changes of config variables will change variables in other configuration pages. A notable example is the <em>defaults</em> page. In this page the default state of the relais can be set. When changing anything on that page, the device will also change the scenario to <em>bypass</em>.<br />
Worse, when changing the mailserver page (the device is able to notify you via email if something bad happens) the dhcp setting is reset. This means on next powerup the device probably won&#8217;t try to get it&#8217;s ip via dhcp but use whatever happens to be the currently configured IP address. I didn&#8217;t try to reboot the device in this state because I noticed (and was looking for) this side-effect because I was already searching for a pattern in the failures.<br />
Getting the config is easy, it&#8217;s under the url <code>http://fos/config.txt</code> where fos is the device. The following text file is retrieved:</p>
<pre>
bnfos_confmap_magic=0.1
1_sz=0
4_mode=0
1_rm=checked
5_p0=0
1_p0=
5_p1=0
1_p1=
3_dn=
3_ip=10.23.5.100
3_nm=255.255.255.0
3_gw=10.23.5.254
3_dns=10.23.5.254
3_dhcp=checked
3_port=80
3_pwd=
2_mhost=0.0.0.0
2_mfrom=
2_mto=
3_log=
3_loghost=0.0.0.0
6_wen=0
2_wen=
6_wstate=0
2_wintv=60
2_as=checked
2_men=
0_wretv=0
</pre>
<p>Apparently all configuration variables that influence other variables are in the same group: They have the same number in front.<br />
The bugs of the web interface are not browser-specific. In fact the command-line tools also use the http-interface of the device to set and get options:
<pre>
% bnfos/bnfos --get scenario -h 10.23.5.100
scenario = 0
zsh: exit 167   bnfos/bnfos --get scenario -h 10.23.5.100
% bnfos/bnfos --set modedef=0 -h 10.23.5.100
Setting modedef succeeded!
% bnfos/bnfos --get scenario -h 10.23.5.100
scenario = 1
zsh: exit 167   bnfos/bnfos --get scenario -h 10.23.5.100
</pre>
<p>Exit-code of the bnfos tool when querying a variable is always 167. It also doesn&#8217;t follow the UNIX mantra for command-line tools: Be silent on success, noisy on error. But we also see here that the bug appears with the command-line tool too: changing the default relais mode also changed the scenario.<br />
When looking with wireshark we see that for setting the variable with the command-line tool it just retrieved the URL <code>/?cmd=1&amp;rm=0</code> with a HTTP Get-request.<br />
When using the <code>--show</code> switch, output is on <code>stderr</code> so piping the result needs special shell commands ( <code>|&amp;</code> is a zsh shortcut for piping both, <code>stdout</code> and <code>stderr</code>):</p>
<pre>
% bnfos/bnfos --show -h 10.23.5.100 |&amp; grep dhcp
 dhcp      = 1
zsh: exit 167   bnfos/bnfos --show -h 10.23.5.100 2&gt;&amp;1 |
</pre>
<p>Setting the mail parameters <code>smtpserv</code>, <code>smtpfrom</code> and <code>smtpto</code> is impossible via the command-line interface. We always the the cryptic error message:</p>
<pre>
% bnfos/bnfos --set smtpto='10.23.5.5' -h 10.23.5.100
Setting smtpto failed: Could not parse!
zsh: exit 1     bnfos/bnfos --set smtpto='10.23.5.5' -h 10.23.5.100
</pre>
<p>Studying the code of the config-tool reveals that there are two configuration tables, one in <code>src/beronet/confmap_fos.h</code> named <code>bnfos_confmap</code> which includes all info about the low-level device parameters:</p>
<pre>
static const struct {
  char *key;
  char type;
  int cmd;
  char *parm;
  char *macro;
} bnfos_confmap[BNFOS_MAX_KEYS] = {
  { "sz"     , 'b', 1, "sz=%s"    , "szenario(0)"},
  { "mode"   , 'b', 4, "mode=%s"  , "mode(0)"},
  { "rm"     , 'b', 1, "rm=%s"    , "config(1,1)"},

  { "p0"     , 'b', 5, "p=0&amp;s=%s" , "pwrport(0,0)"},
  { "p0"     , 'b', 1, "p0=%s"    , "config(2,1)"},
  { "p1"     , 'b', 5, "p=1&amp;s=%s" , "pwrport(0,1)"},
  { "p1"     , 'b', 1, "p1=%s"    , "config(3,1)"},

  { "dn"     , 'h', 3, "dn=%s"    , "hostname(1)"},
  { "ip"     , 'a', 3, "ip=%s"    , "netconf(0)"},
  { "nm"     , 'a', 3, "nm=%s"    , "netconf(1)"},
  { "gw"     , 'a', 3, "gw=%s"    , "netconf(2)"},
  { "dns"    , 'a', 3, "dns=%s"   , "netconf(3)"},
  { "dhcp"   , 'b', 3, "dhcp=%s"  , "config(4,1)"},
  { "port"   , 'p', 3, "port=%s"  , "netconf(6)"},
  { "pwd"    , 'b', 3, "pwd=%s"   , "config(5,1)"},
  { "apwd"   , 'd', 3, "apwd=%s"  , NULL},

  { "mhost"  , 's', 2, "mhost=%s" , "netconf(5)"},
  { "mfrom"  , 's', 2, "mfrom=%s" , "netconf(7)"},
  { "mto"    , 's', 2, "mto=%s"   , "netconf(8)"},
  { "XXXXX"  , 'n', 7, ""         , NULL},

  { "log"    , 'b', 3, "syslog=%s", "config(10,1)"},
  { "loghost", 'a', 3, "slgip=%s" , "netconf(9)"},
  { "logport", 'p', 3, "slgpt=%s" , "netconf(10)"},

  { "wen"    , 'b', 6, "wen=%s"   , "wdog(0)"},
  { "wen"    , 'b', 2, "wen=%s"   , "config(6,1)"},
  { "wstate" ,   0, 6, "wstate=%s", "wdog(0)"},
  { "wintv"  , 'p', 2, "wintv=%s" , "config(8,?)"},
  { "as"     , 'b', 2, "as=%s"    , "config(9,1)"},
  { "men"    , 'b', 2, "men=%s"   , "config(7,1)"},
  { "wretv"  ,   0, 0, NULL       , "wdog(2)"},
};
</pre>
<p>and one in <code>bnfos/main.c</code> that maps the high-level command-line paramters to the low-level http requests:</p>
<pre>
/* keyword description for --set / --get */
static struct {
  char *keyword;
  char *descr;
} keys[BNFOS_MAX_KEYS] = {
  {"scenario", "scenario (0=fallback; 1=bypass)"},

  {"mode", "relais mode (0=A--D; 1=A--B or A--B,C--D)"},
  {"modedef", "default relais mode (0=A--D; 1=A--B or A--B,C--D)"},

  {"power1", "state of powerport 1 (0=off; 1=on)"},
  {"power1def", "default state of powerport 1 (0=off; 1=on)"},
  {"power2", "state of powerport 2 (0=off; 1=on)"},
  {"power2def", "default state of powerport 2 (0=off; 1=on)"},

  {"hostname", "device hostname"},

  {"address", "ip address"},
  {"netmask", "netmask address"},
  {"gateway", "gateway address"},
  {"dns", "dns server address"},
  {"dhcp", "query dhcp server (0=off; 1=on)"},
  {"port", "http listen port"},
  {"pwd", "http password protection (0=off; 1=on)"},
  {"apwd", "admin password"},

  {"smtpserv", "smtp server"},
  {"smtpfrom", "smtp sender address"},
  {"smtpto", "smtp destination address"},
  {"smtptest", "trigger testmail"},

  {"syslog", "syslog logging (0=off; 1=on)"},
  {"slgip", "syslog server ip"},
  {"slgpt", "syslog server port"},
  {"wdog", "watchdog enable (0=off; 1=on)"},
  {"wdogdef", "default watchdog enable (0=off; 1=on)"},
  {"wdogstate", "watchdog state (0=off; 1=on; 2=failure)"},
  {"wdogitime", "watchdog intervall time"},
  {"wdogaudio", "watchdog audio alarm (0=off; 1=on)"},
  {"wdogmail", "watchdog alarm mails (0=off; 1=on)"},
  {"wdogrtime", "watchdog remaining time to failure"},
};
</pre>
<p>I haven&#8217;t found a mechanism that keeps these two tables in different source files in sync (they currently seem to be), looks like both tables need to have the matching options in the same place in both tables. The code for matching options to low-level commands just uses the same index to navigate in both tables.<br />
The <code>bnfos_confmap</code> table has a <code>s</code> for the type of the smtp parameters. This type isn&#8217;t handled in the config-tool and leads to the cryptic error message above. Patching the table to specify the type <code>h</code> (there is a comment <code>XXX check hostname for validy</code> for that type this checking apparently isn&#8217;t done yet, so we can use the code there to parse normal strings) would work. After applying a patch to <code>src/beronet/confmap_fos.h</code>, the sources aren&#8217;t recompiled, seems that the Makefile is broken, too. So after a <code>make clean ; make</code> I&#8217;m finally able to set the smtp parameters via the command-line interface:</p>
<pre>
% bnfos/bnfos --set smtpserv='10.23.5.5' -h 10.23.5.100
Setting smtpserv succeeded!
</pre>
<p>Looking over this again, I prefer to do the following patch that adds support for the &#8217;s&#8217; type:</p>
<pre>
--- bntools/src/bnfos.c 2007-08-28 09:27:46.000000000 +0200
+++ bntools.hacked/src/bnfos.c  2009-04-09 12:10:46.000000000 +0200
@@ -379,6 +379,14 @@
     set-&gt;val = strdup(val);
     return BNFOS_RET_OK;

+  case 's':
+    /* Allow empty strings */
+    if (!val) {
+        val = "";
+    }
+    set-&gt;val = strdup(val);
+    return BNFOS_RET_OK;
+
   case 'p':
     {
       int v;
</pre>
<p>This is a cleaner way to make configuring the smtp parameters work. Turns out that setting the mail gw does <em>not</em> influence the dhcp setting. But in the web-interface, the mail gateway and the syslog server are combined in one page. so trying that:</p>
<pre>
% bnfos/bnfos --show -h 10.23.5.100 |&amp; grep dhcp
 dhcp      = 1
zsh: exit 167   bnfos/bnfos --show -h 10.23.5.100 2&gt;&amp;1 |
zsh: done       grep dhcp
% bnfos/bnfos --set slgip='10.23.5.5' -h 10.23.5.100
Setting slgip succeeded!
% bnfos/bnfos --show -h 10.23.5.100 |&amp; grep dhcp
 dhcp      = 0
zsh: exit 167   bnfos/bnfos --show -h 10.23.5.100 2&gt;&amp;1 |
zsh: done       grep dhcp
</pre>
<p>we see that changing the syslog server also changes the dhcp setting like in the web-interface. When looking more closely, we see that the dhcp and the syslog IP are in the same <code>cmd</code> group. Thats the number in column 3 of the <code>bnfos_confmap</code> and the number in from of each line in <code>config.txt</code> retrieved via the web interface.<br />
So the workaround for the bug in the firmware is to write a config program that retrieves all variables in the same <code>cmd</code> group and, when setting one of the variables in that group, also send all the other current settings in the same get-request.<br />
Fortunately the <code>bnfos_confmap</code> table has the command pattern for generating the get-request for each of the variables in column 4 (<code>parm</code>). So it shouldn&#8217;t be too hard to write a new config utility (and of course I won&#8217;t do that i C either) that works around the firmware bugs.<br />
I already said that I would have preferred an open firmware to fix the bugs at the source, did I?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.runtux.com/2009/04/09/81/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
