<?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>CINAQ ~xiwen &#187; Linux</title>
	<atom:link href="http://www.cinaq.com/wordpress/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cinaq.com/wordpress</link>
	<description>Whistles and bells</description>
	<lastBuildDate>Mon, 12 Dec 2011 22:51:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>setup an encrypted directory on the sdcard in Android</title>
		<link>http://www.cinaq.com/wordpress/2011/10/setup-an-encrypted-directory-on-the-sdcard-in-android/</link>
		<comments>http://www.cinaq.com/wordpress/2011/10/setup-an-encrypted-directory-on-the-sdcard-in-android/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 09:41:16 +0000</pubDate>
		<dc:creator>xiwen</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[cryptsetup]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[htc hd2]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[sdcard]]></category>

		<guid isPermaLink="false">http://www.cinaq.com/wordpress/?p=88</guid>
		<description><![CDATA[Introduction Recently I acquired an HTC HD2 smartphone. It is running Android from NAND. To be specific, the HD2_NDT_MIUI_GINGER_STABLE_V2.2_MAGLDR rom found at XDA. It is known Android isn&#8217;t quite secure in terms of physical access. It is inevitable to loose ones mobile device. When that happens we should rest assured the information on that device [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<h4>Introduction</h4>
<p>Recently I acquired an HTC HD2 smartphone. It is running Android from NAND. To be specific, the HD2_NDT_MIUI_GINGER_STABLE_V2.2_MAGLDR rom found at XDA. It is known Android isn&#8217;t quite secure in terms of physical access. It is inevitable to loose ones mobile device. When that happens we should rest assured the information on that device is not accessible by others.</p>
<p><span id="more-88"></span></p>
<h4>Approach</h4>
<p>There are several ways to solve this problem. But I opted to use cryptsetup because 1) I&#8217;m familiar with it 2) transparency: an encrypted container accessible by normal apps 3) portability: the raw container can be opened on other Linux systems.</p>
<p>The first problem is <b>cryptsetup</b> is absent on a standard Android system. Thanks to <a href="http://androidvoid.wordpress.com/2009/09/30/android-encryption-using-cryptsetup-and-luks/">this post</a> I could get a hold of a binary(ideally one should compile their own). <b>cryptsetup</b> must be pushed to the Rooted device with e.g. <i>adb push</i><br />
I put mine in <i>/sd-ext/bin</i> which is an <b>ext2</b> partition the sdcard together with <b>crypt.sh</b> (found lower in this post, <a href="http://forum.xda-developers.com/showpost.php?p=14897706&#038;postcount=10">inspired by this</a>). The script by default creates a ~1.8GB container on the sdcard called <b>crypt.raw</b> and the mount point at <b>/sdcard/crypt</b>. </p>
<h4>Usage</h4>
<p>First the container must be initialized. This can be done within <b>adb shell</b>:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sh /sd-ext/bin/crypt.sh setup</div></div>
<p>It will take a while depending on the container size.</p>
<p>After it&#8217;s done you can mount the container:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sh /sd-ext/bin/crypt.sh mount</div></div>
<p>and unmount:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sh /sd-ext/bin/crypt.sh umount</div></div>
<p>What if we&#8217;re away from a computer without access to <b>adb</b>? Simply use <b>connectbot</b> to open a local connection then escalate privileges using</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">su</div></div>
<p>From here on, we can unlock the container whenever we please and it is compatible with all other apps. </p>
<h4>Conclusions</h4>
<p>The approach described above uses cryptsetup, a widely deployed solution in the Linux world. It enables the user to store data securely and transparently. The container size limit (2GB) can be overcome by using ext2/3/4 instead of the default vfat on the &#8220;host&#8221; filesystem. Or use a dedicated partition for it.</p>
<p>While this article doesn&#8217;t dive deep into realizing a water tight system it illustrates one can take measures themselves to increase security. A pit fall of this solution is that one can forget to lock the container. A device without pattern or pin lock (I don&#8217;t trust it myself. Hell, at least it is something) cannot protect your data. It is also wise to turn off debugging mode otherwise an attacker can just hook up your phone on USB and then fire up <b>adb</b> which grants them root access to an unlocked container. <i>Maybe I should write an article on securing Android</i></p>
<p>Several improvements can be made in the future:<br />
- a GUI frontend to crypt.sh<br />
- tight integration with the system: encrypt complete /sdcard and /data for instance<br />
- use pin/pattern to unlock container</p>
<h4>script: crypt.sh</h4>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/system/bin/sh</span><br />
<br />
<span style="color: #666666; font-style: italic;"># in kilobytes; vfat limits to 2G</span><br />
<span style="color: #007800;">SIZE</span>=<span style="color: #000000;">1900000</span><br />
<span style="color: #007800;">VOLNAME</span>=crypt<br />
<span style="color: #007800;">CRYPTSETUP</span>=<span style="color: #000000; font-weight: bold;">/</span>sd-ext<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>cryptsetup<br />
<br />
SETUP<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>zero <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>sdcard<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span>.raw <span style="color: #007800;">bs</span>=<span style="color: #000000;">1024</span> <span style="color: #007800;">count</span>=<span style="color: #800000;">${SIZE}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mknod</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21 b <span style="color: #000000;">7</span> <span style="color: #000000;">21</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; losetup <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21 <span style="color: #000000; font-weight: bold;">/</span>sdcard<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span>.raw<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800000;">${CRYPTSETUP}</span> <span style="color: #660033;">--cipher</span> aes-cbc-essiv:md5 <span style="color: #660033;">--key-size</span> <span style="color: #000000;">256</span> luksFormat <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800000;">${CRYPTSETUP}</span> luksOpen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21 <span style="color: #800000;">${VOLNAME}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mkfs.ext2 <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800000;">${CRYPTSETUP}</span> luksClose <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; losetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>sdcard<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
MOUNT<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mknod</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21 b <span style="color: #000000;">7</span> <span style="color: #000000;">21</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; losetup <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21 <span style="color: #000000; font-weight: bold;">/</span>sdcard<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span>.raw<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800000;">${CRYPTSETUP}</span> luksOpen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21 <span style="color: #800000;">${VOLNAME}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span> <span style="color: #000000; font-weight: bold;">/</span>sdcard<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
UMOUNT<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>sdcard<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800000;">${CRYPTSETUP}</span> luksClose <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>mapper<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${VOLNAME}</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; losetup <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>loop21<br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; setup<span style="color: #7a0874; font-weight: bold;">&#41;</span> SETUP <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">umount</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> UMOUNT <span style="color: #000000; font-weight: bold;">;;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> MOUNT <span style="color: #000000; font-weight: bold;">;;</span><br />
<span style="color: #000000; font-weight: bold;">esac</span></div></div>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.cinaq.com/wordpress/2011/10/setup-an-encrypted-directory-on-the-sdcard-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>weather: simple command line weather script</title>
		<link>http://www.cinaq.com/wordpress/2011/01/weather-simple-command-line-weather-script/</link>
		<comments>http://www.cinaq.com/wordpress/2011/01/weather-simple-command-line-weather-script/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 13:55:54 +0000</pubDate>
		<dc:creator>xiwen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[weather]]></category>

		<guid isPermaLink="false">http://www.cinaq.com/wordpress/?p=80</guid>
		<description><![CDATA[In my quest to make my systems more useful I created a command line weather script. There are similar programs made already like weathercli, weather-util. But the first didn&#8217;t work at all. The second only supports USA states/cities. Not quite useful in my situation where I want weather conditions of The Hague in The Netherlands. [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>In my quest to make my systems more useful I created a command line weather script. There are similar programs made already like weathercli, weather-util. But the first didn&#8217;t work at all. The second only supports USA states/cities. Not quite useful in my situation where I want weather conditions of The Hague in The Netherlands.</p>
<p>The result is a simple bash script that fetches xml data from <i>Google Weather AP</i>I using <i>curl</i>. This data is then parsed using <i>xmlscarlet</i> and <i>awk</i>.</p>
<p><img src="http://www.cinaq.com/wordpress/wp-content/uploads/2011/01/weather.png" alt="" title="weather" width="230" height="123" class="alignnone size-full wp-image-81" /></p>
<p><a href="https://i.cinaq.com/redmine/projects/awesome/repository/entry/bin/weather">View the final script</a></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.cinaq.com/wordpress/2011/01/weather-simple-command-line-weather-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add support for unix socket in gnu-netcat</title>
		<link>http://www.cinaq.com/wordpress/2009/08/add-support-for-unix-socket-in-gnu-netcat/</link>
		<comments>http://www.cinaq.com/wordpress/2009/08/add-support-for-unix-socket-in-gnu-netcat/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 21:50:34 +0000</pubDate>
		<dc:creator>xiwen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[arch linux]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[libvirt]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nc]]></category>
		<category><![CDATA[netcat]]></category>
		<category><![CDATA[qemu]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[virt-manager]]></category>
		<category><![CDATA[wrapper]]></category>

		<guid isPermaLink="false">http://www.cinaq.com/wordpress/?p=56</guid>
		<description><![CDATA[virsh from the libvirt package uses netcat to communicate with a remote server (in fact the command is executed locally on the remote server): command -p port [-l username] hostname netcat -U socket from: libvirt&#62; Remote support&#62; Extra parameters However, the server I&#8217;m testing with runs Arch Linux; virt-manager, libvirt and its dependencies were installed [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p><strong>virsh</strong> from the <strong>libvirt</strong> package uses netcat to communicate with a remote server (in fact the command is executed locally on the remote server):<br />
<em>command</em> -p <em>port</em> [-l <em>username</em>] <em>hostname</em> <em>netcat</em> -U <em>socket</em><br />
from: <a href="http://libvirt.org/remote.html" target="_blank">libvirt&gt; Remote support&gt; Extra parameters</a></p>
<p><span id="more-56"></span></p>
<p>However, the server I&#8217;m testing with runs Arch Linux; virt-manager, libvirt and its dependencies were installed through AUR; In the list of dependencies the OpenBSD implementation of netcat wasn&#8217;t listed. I&#8217;m aware Debian has ported it. The special feature in this netcat re-write is support for UNIX socket. As libvirt uses UNIX socket to communicate, the gnu-netcat cannot be used; it doesn&#8217;t understand the <strong>-U</strong> flag. The error happens when you try to connect to a remote server through a SSH tunnel:<br />
<em>virsh -d 5 -c qemu+ssh://somehost/system list</em></p>
<p>If the netcat binary on the remote host doesn&#8217;t understand -U, it will fail.</p>
<p>A quick dirty fix, more like a workaround, is to use a wrapper. <strong>socat</strong>&#8216;s speciality is socket. We can use it like this:</p>
<ul>
<li>rename original netcat: mv /usr/bin/netcat /usr/bin/netcat.orig</li>
<li>create the wrapper /usr/bin/netcat with as content:</li>
<pre>	#!/bin/sh
	if [ "$1" == "-U" ]; then socat - unix-client:$2
	else netcat.orig $@
	fi</pre>
<li>chmod 755 /usr/bin/netcat</li>
</ul>
<p>And you&#8217;re ready to rock <img src='http://www.cinaq.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><em>On the long run libvirt shouldn&#8217;t rely on the OpenBSD implementation of netcat. As there&#8217;s only a few Linux distributions out there that adopted this rewrite. Perhaps give the user the freedom to choose which socket-tool to use in the configuration file?</em></p>
<p><em><br />
</em></p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.cinaq.com/wordpress/2009/08/add-support-for-unix-socket-in-gnu-netcat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

