<?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>Erik Tews</title>
	<atom:link href="http://www.datenzone.de/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.datenzone.de/blog</link>
	<description></description>
	<lastBuildDate>Sun, 29 Jan 2012 22:04:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Installing Stunnel on OpenWRT</title>
		<link>http://www.datenzone.de/blog/2012/01/installing-stunnel-on-openwrt/</link>
		<comments>http://www.datenzone.de/blog/2012/01/installing-stunnel-on-openwrt/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 22:04:20 +0000</pubDate>
		<dc:creator>erik</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.datenzone.de/blog/?p=41</guid>
		<description><![CDATA[Stunnel is a general purpose SSL/TLS proxy. I explained in my last posting how to use stunnel with Android, so that Android apps can communicate with a server through SSL/TLS with mutal authentication and encryption. For many people, running stunnel on &#8230;<p class="read-more"><a href="http://www.datenzone.de/blog/2012/01/installing-stunnel-on-openwrt/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.stunnel.org/">Stunnel</a> is a general purpose SSL/TLS proxy. I explained <a href="http://www.datenzone.de/blog/2012/01/using-ssltls-client-certificate-authentification-in-android-applications/">in my last posting</a> how to use <em>stunnel</em> with <a href="http://www.android.com/developers/">Android</a>, so that Android apps can communicate with a server through SSL/TLS with mutal authentication and encryption. For many people, running stunnel on their home router as a gatekeeper might a good option. <a href="https://openwrt.org/">OpenWRT</a> is an open source operating system, that can be flashed on many routers and wireless LAN access points an other device.</p>
<p>How to install OpenWRT is not covered by this posting. Instead I suggest reading the <a href="http://wiki.openwrt.org/doc/howto/generic.flashing">general documentation</a> on the OpenWRT website. After OpenWRT is running, there are two ways how to install stunnel.</p>
<h1>Install with opkg</h1>
<p>The easiest way to install stunnel on OpenWRT is opkg. Just execute:</p>
<pre>opkg update; opkg install stunnel</pre>
<p>However, the space on many routers is limited, and this might fail.</p>
<h1>Install with ImageBuilder</h1>
<p>For those, who don&#8217;t have enough space on their router, they can still try the <a href="http://wiki.openwrt.org/doc/howto/obtain.firmware.generate">ImageBuilder</a>. Here, a new firmware image is generated, that compresses stunnel much better. Here, we need to build an image like:</p>
<pre>make image <strong>PACKAGES="stunnel"</strong></pre>
<p>And possibly, other options need to be set, depending on your plattform. After the image has been generated, it can be flashed on the device.</p>
<h1>Configuring stunnel</h1>
<p>Because some paths are different, we need to adjust the stunnel.conf from the last posting.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cert = /etc/stunnel/cert-server.pem
key = /etc/stunnel/key-server.pem
CAfile = /etc/stunnel/cert-client.pem
sslVersion = SSLv3
chroot = /var
setuid = nobody
setgid = nogroup
pid = /stunnel.pid
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
[service]
accept  = ZZZZZ
connect = 192.168.XXX.YYY:80
verify = 2</pre></div></div>

<p>All certificate and key files are placed in <em>/etc/stunnel/</em>. How we can start it with <em>/etc/init.d/stunnel start</em>. Also, just doing a reboot on the device might be a good idea, to check if stunnel still works after a reboot.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenzone.de/blog/2012/01/installing-stunnel-on-openwrt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SSL/TLS Client Certificate Authentification in Android Applications</title>
		<link>http://www.datenzone.de/blog/2012/01/using-ssltls-client-certificate-authentification-in-android-applications/</link>
		<comments>http://www.datenzone.de/blog/2012/01/using-ssltls-client-certificate-authentification-in-android-applications/#comments</comments>
		<pubDate>Sat, 14 Jan 2012 03:27:47 +0000</pubDate>
		<dc:creator>erik</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Crypto]]></category>

		<guid isPermaLink="false">http://www.datenzone.de/blog/?p=33</guid>
		<description><![CDATA[Assume that you want to write an Android application, that needs to communicate with your server or your wireless router at home, for personal use. You might be interested in securing this communication against eavesdropping, so that nobody else sees, &#8230;<p class="read-more"><a href="http://www.datenzone.de/blog/2012/01/using-ssltls-client-certificate-authentification-in-android-applications/">Read more &#187;</a></p>]]></description>
			<content:encoded><![CDATA[<p>Assume that you want to write an Android application, that needs to communicate with your server or your wireless router at home, for personal use. You might be interested in securing this communication against eavesdropping, so that nobody else sees, what you application sends and receives. You also might be interested in authenticating you communication, so that you can be sure that only your application and your server or router communicate, and nobody else is able to modify the content transmitted, without being noticed. The SSL/TLS protocol is a perfect solution for this problem, so that you don&#8217;t need to invent a solution yourself.</p>
<h1>Certificates</h1>
<p>To ensure authenticity of both communication partners, X.509 certificates can be used. Most secure websites in the internet like paypal, ebay, or amazon only use X.509 certificates for the server, and the client is authenticated using a username and a password. For this example, X.509 certificates will be used for both communication partners.</p>
<p>To generate two self-signed X.509 certificates, the following script can be used. It will generate two new RSA 2048 bit keys, generate two self signed certificates, and bundle the client certificate with the corresponding private key, and the servers public certificate in a PKCS#12 container file.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">OPENSSL_OPTS</span>=<span style="color: #ff0000;">&quot;-new -newkey rsa:2048 -nodes -days 5475 -x509&quot;</span>
<span style="color: #007800;">CN_SERVER</span>=<span style="color: #ff0000;">&quot;/CN=server&quot;</span>
<span style="color: #007800;">CN_CLIENT</span>=<span style="color: #ff0000;">&quot;/CN=client&quot;</span>
<span style="color: #007800;">PASS</span>=<span style="color: #ff0000;">&quot;123456&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Generating keys&quot;</span>
openssl req <span style="color: #660033;">-keyout</span> key-server.pem <span style="color: #660033;">-subj</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CN_SERVER</span>&quot;</span> \
 <span style="color: #660033;">-out</span> cert-server.pem <span style="color: #007800;">$OPENSSL_OPTS</span>
openssl req <span style="color: #660033;">-keyout</span> key-client.pem <span style="color: #660033;">-subj</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$CN_CLIENT</span>&quot;</span>\
 <span style="color: #660033;">-out</span> cert-client.pem <span style="color: #007800;">$OPENSSL_OPTS</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Encrypting key for the client now&quot;</span>
openssl pkcs12 <span style="color: #660033;">-export</span> <span style="color: #660033;">-passout</span> <span style="color: #ff0000;">&quot;pass:<span style="color: #007800;">$PASS</span>&quot;</span> \
 <span style="color: #660033;">-in</span> cert-client.pem <span style="color: #660033;">-inkey</span> key-client.pem <span style="color: #660033;">-out</span> client.p12 \
 <span style="color: #660033;">-certfile</span> cert-server.pem <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;Client&quot;</span> <span style="color: #660033;">-caname</span> <span style="color: #ff0000;">&quot;Server&quot;</span></pre></div></div>

<h1>Stunnel</h1>
<p>We will use stunnel for the server. Stunnel is a lightweight general SSL/TLS wrapper and proxy. First, we copy cert-client.pem cert-server.pem and key-server.pem to the server to /etc/ssl/stunnel or another directory. Next is the stunnel configuration file:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">cert = /etc/ssl/stunnel/cert-server.pem
key = /etc/ssl/stunnel/key-server.pem
CAfile = /etc/ssl/stunnel/cert-client.pem
sslVersion = SSLv3
chroot = /var/lib/stunnel4/
setuid = stunnel4
setgid = stunnel4
pid = /stunnel4.pid
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
[service]
accept  = 1279
connect = target:1280
verify = 2</pre></div></div>

<p>This will set up a stunnel server, listening on port 1279, and forwarding the unencrypted communication to target port 1280. It will only allow connections from a client, presenting a valid certificate.</p>
<h1>Android</h1>
<p>Next, we can write the code for our Android application:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Adopt this in your application</span>
<span style="color: #003399;">String</span> PASSWORD_FOR_PKCS12 <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;123456&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">InputStream</span> pkcs12in <span style="color: #339933;">=</span> ......
<span style="color: #666666; font-style: italic;">// You only need to execute this code once</span>
SSLContext context <span style="color: #339933;">=</span> SSLContext.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TLS&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Local client certificate and key and server certificate</span>
<span style="color: #003399;">KeyStore</span> keyStore <span style="color: #339933;">=</span> <span style="color: #003399;">KeyStore</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;PKCS12&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
keyStore.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span>pkcs12in, PASSWORD_FOR_PKCS12.<span style="color: #006633;">toCharArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Build a TrustManager, that trusts only the server certificate</span>
TrustManagerFactory tmf <span style="color: #339933;">=</span> TrustManagerFactory.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;X509&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">KeyStore</span> keyStoreCA <span style="color: #339933;">=</span> <span style="color: #003399;">KeyStore</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BKS&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
keyStoreCA.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Certificate</span> c <span style="color: #339933;">=</span> keyStore.<span style="color: #006633;">getCertificate</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Server&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
keyStoreCA.<span style="color: #006633;">setCertificateEntry</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Server&quot;</span>, c<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
tmf.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>keyStoreCA<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Build a KeyManager for Client auth</span>
KeyManagerFactory kmf <span style="color: #339933;">=</span> KeyManagerFactory.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>
        KeyManagerFactory.<span style="color: #006633;">getDefaultAlgorithm</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
kmf.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>keyStore, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #006633;">init</span><span style="color: #009900;">&#40;</span>kmf.<span style="color: #006633;">getKeyManagers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, tmf.<span style="color: #006633;">getTrustManagers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Everytime you need your https connection, run this code</span>
<span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;https://my-router:1279/&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
HttpsURLConnection urlConnection <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>HttpsURLConnection<span style="color: #009900;">&#41;</span> url.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
urlConnection.<span style="color: #006633;">setSSLSocketFactory</span><span style="color: #009900;">&#40;</span>context.<span style="color: #006633;">getSocketFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
urlConnection.<span style="color: #006633;">setHostnameVerifier</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> AllowAllHostnameVerifier<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">InputStream</span> in <span style="color: #339933;">=</span> urlConnection.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.datenzone.de/blog/2012/01/using-ssltls-client-certificate-authentification-in-android-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A blog on cryptographie</title>
		<link>http://www.datenzone.de/blog/2012/01/a-blog-on-cryptographie/</link>
		<comments>http://www.datenzone.de/blog/2012/01/a-blog-on-cryptographie/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 00:57:13 +0000</pubDate>
		<dc:creator>erik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.datenzone.de/blog/?p=21</guid>
		<description><![CDATA[I have started to write about mostly applied aspects of cryptographie, cryptanalysis and security on http://cryptanalysis.eu/. Postings for these topics won&#8217;t appear here.]]></description>
			<content:encoded><![CDATA[<p>I have started to write about mostly applied aspects of cryptographie, cryptanalysis and security on <a href="http://cryptanalysis.eu/">http://cryptanalysis.eu/</a>. Postings for these topics won&#8217;t appear here.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenzone.de/blog/2012/01/a-blog-on-cryptographie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

