Thank you very much. :)<div>I&#39;ll post some results when I have them.<div><br></div><div>- Kyle<br><br><div class="gmail_quote">On Sun, Dec 28, 2008 at 3:55 PM, Adam Langley <span dir="ltr">&lt;<a href="mailto:agl@imperialviolet.org">agl@imperialviolet.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Looks like I should do a quick write up:<br>
<br>
One caveat, I&#39;m running Android 1.1 PLAT-RC16, which is an unreleased<br>
testing version. However, I don&#39;t believe that anything pertinent has<br>
changed.<br>
<br>
1) Setup your phone for debugging.<br>
<br>
Home -&gt; Settings -&gt; Applications -&gt; Development. Check both &quot;USB<br>
debugging&quot; and &quot;Stay Awake&quot;.<br>
<br>
2) Setup udev<br>
<br>
See <a href="http://code.google.com/android/intro/develop-and-debug.html" target="_blank">http://code.google.com/android/intro/develop-and-debug.html</a> and<br>
search the page for &quot;udev&quot;. This is to make sure that the USB device<br>
inodes get the correct permissions.<br>
<br>
3) Download the SDK<br>
<br>
<a href="http://code.google.com/android/intro/installing.html" target="_blank">http://code.google.com/android/intro/installing.html</a><br>
<br>
Put the tools/ directory from the SDK in your $PATH. You&#39;ll need the<br>
adb utility from there.<br>
<br>
4) Plug your phone into a USB port on your computer<br>
<br>
`adb devices` should list a single device.<br>
<br>
5) Grab a full source release and build it<br>
<br>
Follow <a href="http://source.android.com/download" target="_blank">http://source.android.com/download</a>. It&#39;s a lot of downloading,<br>
disk space and build time. If you aren&#39;t running an Intel x86 or<br>
x86-64 build platform you might have some issues. If you are running<br>
x86-64 you&#39;ll still have some issues. Many of them are covered on the<br>
above page but one which I had was that my distro (Ubuntu 8.10)<br>
doesn&#39;t seem to have 32-bit libreadline libraries.<br>
<br>
I built a 32-bit libreadline from source (this is from memory only):<br>
% export CC=&quot;gcc -m32&quot;<br>
% ./configure<br>
% make<br>
% sudo cp libreadline.so.5.2 libhistory.so.5.2 /usr/lib32<br>
% sudo chmod a+rx /usr/lib32/libreadline.so.5.2 /usr/lib32/libhistory.so.5.2<br>
% ldconfig (might setup the symlinks /usr/lib/libreadline.so for you,<br>
otherwise, do it manually)<br>
<br>
Hopefully you can do a successful `make` run with the android source.<br>
<br>
6) Setup agcc<br>
<br>
Once you have a source build, you should have an ARM cross-compiler in<br>
mydroid/prebuilt/linux-x86/toolchain/arm-eabi-4.3.1/bin. The agcc[1]<br>
script will give all the correct arguments to it to build binaries<br>
with bionic etc. Put both agcc and ..../arm-eabi-4.3.1 in your $PATH.<br>
<br>
[1] <a href="http://plausible.org/andy/agcc" target="_blank">http://plausible.org/andy/agcc</a><br>
<br>
7) Build a test binary<br>
<br>
% cat &gt; test.c &lt;&lt;EOF<br>
#include &lt;stdio.h&gt;<br>
<br>
int<br>
main() {<br>
 &nbsp;printf(&quot;hello android\n&quot;);<br>
 &nbsp;return 0;<br>
}<br>
EOF<br>
<br>
% agcc test.c<br>
% file ./a.out<br>
<br>
That should get you an ARM binary<br>
<br>
8) Try running it<br>
<br>
% adb push a.out /sqlite_stmt_journals<br>
% adb shell<br>
$ cd /sqlite_stmt_journals<br>
$ ./a.out<br>
<br>
/sqlite_stmt_journals is just a tmpfs filesystem that&#39;s easy to get to.<br>
<br>
9) Build libevent<br>
<br>
Download libevent<br>
<br>
% export CC=&quot;agcc&quot;<br>
% ./configure --host=arm-eabi<br>
<br>
I had to manually disable select support in config.h and remove<br>
select.c (and everything else to do with select) from the Makefile<br>
because bionic seems to be missing fd_mask structures. I also didn&#39;t<br>
bother building anything in /test.<br>
<br>
Hopefully you end up with libevent.a (probably in .libs). Copy it to<br>
mydroid/out/target/product/generic/obj/lib.<br>
<br>
10) Setup include paths<br>
<br>
I added these lines to the list of include paths in agcc:<br>
<br>
 &nbsp; &nbsp;&quot;-I$DROID/external/libevent-1.4.9-stable&quot;,<br>
 &nbsp; &nbsp;&quot;-I$DROID/external/openssl/include&quot;,<br>
 &nbsp; &nbsp;&quot;-I$DROID/external/zlib&quot;,<br>
<br>
The first is where I happened to build libevent. Your location may<br>
vary. The other two are path of the standard source distribution.<br>
<br>
11) Build tor<br>
<br>
I used 0.2.0.32<br>
<br>
Firstly, Android doesn&#39;t include deprecated OpenSSL functions, so add<br>
a wrapper to src/common/crypto.c:<br>
<br>
+++ tor-0.2.0.32-agl/src/common/crypto.c &nbsp;2008-12-28 12:24:25.000000000 -0800<br>
@@ -387,6 +387,37 @@<br>
 &nbsp; tor_free(env);<br>
&nbsp;}<br>
<br>
+RSA *RSA_generate_key(int bits, unsigned long e_value,<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; void (*callback)(int,int,void *), void *cb_arg)<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;{<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;BN_GENCB cb;<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;int i;<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;RSA *rsa = RSA_new();<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;BIGNUM *e = BN_new();<br>
+<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;if(!rsa || !e) goto err;<br>
+<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;/* The problem is when building with 8, 16, or 32 BN_ULONG,<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; * unsigned long can be larger */<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;for (i=0; i&lt;(int)sizeof(unsigned long)*8; i++)<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (e_value &amp; (1UL&lt;&lt;i))<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (BN_set_bit(e,i) == 0)<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto err;<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
+<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;BN_GENCB_set_old(&amp;cb, callback, cb_arg);<br>
+<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;if(RSA_generate_key_ex(rsa, bits, e, &amp;cb)) {<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BN_free(e);<br>
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return rsa;<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;}<br>
+err:<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;if(e) BN_free(e);<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;if(rsa) RSA_free(rsa);<br>
+ &nbsp; &nbsp; &nbsp; &nbsp;return 0;<br>
+}<br>
+<br>
<br>
Then, the only other issues I had were with some odd namespace<br>
collision with log.h. I&#39;ll include the diffs, although I didn&#39;t bother<br>
pinning down the problem, I just worked around where it popped up:<br>
<br>
--- tor-0.2.0.32/src/common/log.h &nbsp; 2008-02-26 11:56:29.000000000 -0800<br>
+++ tor-0.2.0.32-agl/src/common/log.h &nbsp;2008-12-28 12:02:17.000000000 -0800<br>
@@ -11,7 +11,7 @@<br>
 &nbsp;* \brief Headers for log.c<br>
 &nbsp;**/<br>
<br>
-#ifndef __LOG_H<br>
+#ifndef __TOR_LOG_H<br>
&nbsp;#define LOG_H_ID &quot;$Id: log.h 13412 2008-02-07 05:31:47Z nickm $&quot;<br>
<br>
&nbsp;#include &quot;compat.h&quot;<br>
@@ -180,6 +180,6 @@<br>
<br>
&nbsp;#endif /* !GNUC */<br>
<br>
-# define __LOG_H<br>
+# define __TOR_LOG_H<br>
&nbsp;#endif<br>
--- tor-0.2.0.32/src/or/buffers.c &nbsp; 2008-11-20 14:14:26.000000000 -0800<br>
+++ tor-0.2.0.32-agl/src/or/buffers.c &nbsp;2008-12-28 12:03:08.000000000 -0800<br>
@@ -14,6 +14,7 @@<br>
 &nbsp;* memory, file descriptors, or TLS connections.<br>
 &nbsp;**/<br>
&nbsp;#define BUFFERS_PRIVATE<br>
+#include &quot;src/common/log.h&quot;<br>
&nbsp;#include &quot;or.h&quot;<br>
<br>
&nbsp;//#define PARANOIA<br>
diff -ur tor-0.2.0.32/src/or/circuitbuild.c<br>
tor-0.2.0.32-agl/src/or/circuitbuild.c<br>
--- tor-0.2.0.32/src/or/circuitbuild.c 2008-09-23 14:00:43.000000000 -0700<br>
+++ tor-0.2.0.32-agl/src/or/circuitbuild.c &nbsp; 2008-12-28 12:03:30.000000000 -0800<br>
@@ -12,6 +12,7 @@<br>
 &nbsp;* \brief The actual details of building circuits.<br>
 &nbsp;**/<br>
<br>
+#include &quot;src/common/log.h&quot;<br>
&nbsp;#include &quot;or.h&quot;<br>
<br>
&nbsp;/********* START VARIABLES **********/<br>
Only in tor-0.2.0.32-agl/src/or: .deps<br>
diff -ur tor-0.2.0.32/src/or/eventdns.c tor-0.2.0.32-agl/src/or/eventdns.c<br>
--- tor-0.2.0.32/src/or/eventdns.c &nbsp;2008-02-26 11:56:28.000000000 -0800<br>
+++ tor-0.2.0.32-agl/src/or/eventdns.c 2008-12-28 12:18:22.000000000 -0800<br>
@@ -121,6 +121,7 @@<br>
&nbsp;#endif<br>
<br>
&nbsp;/* for debugging possible memory leaks. */<br>
+#include &quot;src/common/util.h&quot;<br>
&nbsp;#define malloc(x) tor_malloc(x)<br>
&nbsp;#define realloc(x,y) tor_realloc((x),(y))<br>
&nbsp;#define free(x) tor_free(x)<br>
Only in tor-0.2.0.32-agl/src/or: Makefile<br>
diff -ur tor-0.2.0.32/src/or/or.h tor-0.2.0.32-agl/src/or/or.h<br>
--- tor-0.2.0.32/src/or/or.h &nbsp;2008-11-20 14:14:26.000000000 -0800<br>
+++ tor-0.2.0.32-agl/src/or/or.h 2008-12-28 12:03:48.000000000 -0800<br>
@@ -75,7 +75,7 @@<br>
<br>
&nbsp;#include &quot;crypto.h&quot;<br>
&nbsp;#include &quot;tortls.h&quot;<br>
-#include &quot;log.h&quot;<br>
+#include &quot;src/common/log.h&quot;<br>
&nbsp;#include &quot;compat.h&quot;<br>
&nbsp;#include &quot;container.h&quot;<br>
&nbsp;#include &quot;util.h&quot;<br>
<br>
12) Finish up<br>
<br>
I didn&#39;t bother building any of the Tor utilities once I had the Tor<br>
binary. You can copy it to the phone with adb push again and run it<br>
via the shell.<br>
<br>
First you should `export HOME=/sdcard` because the tmpfs is very small.<br>
<br>
<br>
<br>
That gets Tor running, however it&#39;s hardly very neat.<br>
<br>
The rest of Android is designed around Activies, as documented in the<br>
SDK documentation. I suspect that the way to go would be to build Tor<br>
as a .so, renaming the main function. You can use JNI[1] from a Java<br>
thread to start running Tor by calling the new alternative main. If<br>
you do this, you&#39;ll want to read [2] otherwise the system will<br>
randomly kill the process.<br>
<br>
I believe that there&#39;s a way to get Android to use an HTTP proxy.<br>
Certainly there&#39;s an http_proxy field in<br>
frameworks/base/core/java/android/provider/Settings.java. You might<br>
find details online about poking a value in a SQLite table. The<br>
sqlite3 binary that they reference isn&#39;t shipped on the phones, but<br>
you find it in mydroid/out/target/product/generic/system/xbin.<br>
However, I don&#39;t believe that the sqlite file lives in the same place<br>
anymore and I don&#39;t know where it moved to.<br>
<br>
<br>
<br>
AGL<br>
<br>
[1] <a href="http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-methods-bridging-cc-and-java/" target="_blank">http://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-methods-bridging-cc-and-java/</a><br>

[2] <a href="http://code.google.com/android/reference/android/app/Service.html" target="_blank">http://code.google.com/android/reference/android/app/Service.html</a><br>
<div><div></div><div class="Wj3C7c"><br>
--<br>
Adam Langley <a href="mailto:agl@imperialviolet.org">agl@imperialviolet.org</a> <a href="http://www.imperialviolet.org" target="_blank">http://www.imperialviolet.org</a><br>
</div></div></blockquote></div><br></div></div>