<?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>Daniel Witte &#187; Uncategorized</title>
	<atom:link href="http://blog.mozilla.com/dwitte/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mozilla.com/dwitte</link>
	<description>Real life ftw.</description>
	<lastBuildDate>Thu, 09 Sep 2010 19:07:38 +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>User Agent string changes coming in Firefox 4</title>
		<link>http://blog.mozilla.com/dwitte/2010/08/24/user-agent-string-changes-coming-in-firefox-4/</link>
		<comments>http://blog.mozilla.com/dwitte/2010/08/24/user-agent-string-changes-coming-in-firefox-4/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 21:23:51 +0000</pubDate>
		<dc:creator>dwitte</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/dwitte/?p=30</guid>
		<description><![CDATA[Edit 9/9/2010: This information has been superseded by an updated post here. Please refer there for final information on the changes for Firefox 4. With a title like that, you just know this is going to be fun. (No, seriously.) The user agent string is one of those wonderfully eclectic things, a balance of modernity [...]]]></description>
			<content:encoded><![CDATA[<p><i><b>Edit 9/9/2010:</b> This information has been superseded by an updated post </i><a href="http://hacks.mozilla.org/2010/09/final-user-agent-string-for-firefox-4/">here</a><i>. Please refer there for final information on the changes for Firefox 4.</i></p>
<p>With a title like that, you just know this is going to be fun. (No, seriously.)</p>
<p>The user agent string is one of those wonderfully eclectic things, a balance of modernity and antiquity. Except mostly skewed toward antiquity. It&#8217;s grown, piece by piece, over the years; because everyone has their own special way of parsing it, it&#8217;s a notoriously sensitive beast. Adding to it is relatively simple, but removing or rearranging bits is not.</p>
<p>If you&#8217;re a web developer and you rely on bits in the UA string, this post is definitely for you. As it so happens, the UA string for <a href="http://blogs.msdn.com/b/ie/archive/2010/03/23/introducing-ie9-s-user-agent-string.aspx">Internet Explorer 9</a> has undergone some revision, and Microsoft has recently announced the string for <a href="http://blogs.msdn.com/b/iemobile/archive/2010/03/25/ladies-and-gentlemen-please-welcome-the-ie-mobile-user-agent-string.aspx">IE Mobile</a>. This makes the time ripe for a revision so that web developers can make the necessary changes to sniffer code all at once.</p>
<p>Here are the changes we&#8217;ve made so far for Firefox 4, on the Big Three platforms (for a complete reference, see <a href="https://developer.mozilla.org/En/Firefox_User_Agent_String_Reference">https://developer.mozilla.org/En/Firefox_User_Agent_String_Reference</a>):</p>
<h3 style="padding-left: 30px;"><code><strong>Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/<em>yyyymmdd</em> Firefox/4.0.1</strong></code><br />
<code><strong>Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/<em>yyyymmdd</em> Firefox/4.0.1</strong></code><br />
<code><strong>Mozilla/5.0 (X11; Linux i686; rv:2.0.1) Gecko/<em>yyyymmdd</em> Firefox/4.0.1</strong></code></h3>
<p>What&#8217;s changed, you say? Here&#8217;s what:</p>
<p>1) The <code><strong>"Windows; "</strong></code> prefix is gone from the (surprise!) Windows-specific string.</p>
<p>2) The locale (e.g. <code><strong>"en-US; "</strong></code>) is gone. The locale of the browser is not always the same as the locale the user prefers to view content in &#8212; the HTTP Accept header is the recommended source of this information.</p>
<p>3) The <code><strong>"U; "</strong></code> is gone. Back in the day, this was used to denote browsers with strong encryption from those without. Nowadays, no browser ships with weak encryption. This means that if you&#8217;re sniffing for <code><strong>"U; "</strong></code>, you should stop doing so, or sniff for the lack of weak encryption (<code><strong>"I; "</strong></code> or <code><strong>"N; "</strong></code>).</p>
<p>4) Testing builds of Firefox (Minefield nightlies and prerelease builds) will now identify themselves as <code><strong>"Firefox/<em>x.y.z</em>"</strong></code>, just like release builds.</p>
<p>We may also remove the <code><strong>"Macintosh; "</strong></code> from the Mac UA string, and the way a Linux x86 32-bit browser build running on an x86_64 processor is identified; if we do, you&#8217;ll hear about it here.</p>
<p>It&#8217;s also worth noting why we <em>didn&#8217;t</em> change some things. The <code><strong>"X11"</strong></code> part of the Linux string may appear redundant, but it&#8217;s actually not: desktop machines are almost exclusively running X11, but Android phones are not. For reasons like this, the various platform-specific parts of the string are important to know. For instance, there are different tokens for Windows 64 on x64 or IA64, or WoW64 (a 32-bit browser on a 64-bit Windows); PPC or Intel on Mac OS X; and the various environments and architectures for Linux. A list of the common variations can be found at the <a href="https://developer.mozilla.org/En/Firefox_User_Agent_String_Reference">link above</a>. There&#8217;s also a text file <a href="http://people.mozilla.com/~dwitte/ua.txt">here</a> for your testing convenience.</p>
<p>There are some other important changes relating to how the UA string can be modified by external programs, Firefox addons, and users themselves. I&#8217;ll detail these changes in an upcoming post, but suffice to say: the days of horrendously long and arcane strings are over.</p>
<p>Now, if you&#8217;re a web developer, take note! These changes will be in Firefox 4 Beta 5 (soon to be released), so if you want to be ahead of the game, you&#8217;re welcome to test against it. As noted above, for a complete list of UA strings to test against in all their glorious variations, see the <a href="https://developer.mozilla.org/En/Firefox_User_Agent_String_Reference">link above</a> or the <a href="http://people.mozilla.com/~dwitte/ua.txt">text file</a>. Happy sniffing!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/dwitte/2010/08/24/user-agent-string-changes-coming-in-firefox-4/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Extension authors, browser hackers, meet js-ctypes</title>
		<link>http://blog.mozilla.com/dwitte/2010/03/12/extension-authors-browser-hackers-meet-js-ctypes/</link>
		<comments>http://blog.mozilla.com/dwitte/2010/03/12/extension-authors-browser-hackers-meet-js-ctypes/#comments</comments>
		<pubDate>Sat, 13 Mar 2010 02:10:15 +0000</pubDate>
		<dc:creator>dwitte</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/dwitte/?p=12</guid>
		<description><![CDATA[What, you may ask, is js-ctypes? Let&#8217;s say you&#8217;re writing a Firefox extension in JavaScript that needs to call into native code. (For example, weave-crypto, which needs to call into the NSS library. Or your extension here, which, say, wants to call into NSPR, libc, or Win32 functions directly.) Currently, you&#8217;re limited to either a) [...]]]></description>
			<content:encoded><![CDATA[<p>What, you may ask, is js-ctypes? Let&#8217;s say you&#8217;re writing a Firefox extension in JavaScript that needs to call into native code. (For example, weave-crypto, which needs to call into the NSS library. Or your extension here, which, say, wants to call into NSPR, libc, or Win32 functions directly.) Currently, you&#8217;re limited to either a) using the scriptable XPCOM interfaces provided by libxul, or b) writing and implementing your own XPCOM interfaces and shipping binary code with your extension. If a) is inadequate, you&#8217;re stuck with b), which makes shipping an extension much harder &#8212; binary code must be built for each supported platform, and rolled up together into your cross-platform xpi.</p>
<p>Thusly, the answer is js-ctypes: it allows JavaScript to call into native C code and manipulate data types, without using XPCOM and without compiling a line of code. This means you don&#8217;t need to define XPCOM interfaces, and can use shared libraries like libc directly. As a side benefit, much of the type conversion overhead of XPConnect is avoided, so that execution can be faster. (I&#8217;ll be benchmarking in a later post.) This will ship with Gecko 1.9.3, which will be underpinning Firefox 4.</p>
<p>But how, you say? To the examples (tested on 32-bit x86 Linux; sans cross-platform safety):</p>
<p>1. Opening a library.</p>
<pre><code><span style="color: #333399;"><span style="color: #808080;">// First, import the ctypes module.</span>
Components.utils.import("resource://gre/modules/ctypes.jsm");

<span style="color: #808080;">// Open libc.</span>
let library = ctypes.open("libc.so.6");

<span style="color: #808080;">// Declare the 'fopen' function, which has a C prototype of:
//   FILE* fopen(const char* name, const char* mode);</span>
let fopen = library.declare("fopen",                        <span style="color: #808080;">// symbol name</span>
                            ctypes.default_abi,             <span style="color: #808080;">// cdecl calling convention</span>
                            ctypes.StructType("FILE").ptr,  <span style="color: #808080;">// return type (FILE*)</span>
                            ctypes.char.ptr,                <span style="color: #808080;">// first arg (const char*)</span>
                            ctypes.char.ptr);               <span style="color: #808080;">// second arg (const char*)</span>

<span style="color: #808080;">// Call the function, and get a FILE* pointer object back.</span>
let file = fopen("hello world.txt", "w");

<span style="color: #808080;">// What is 'file'?</span>
file.toString();
  <span style="color: #ff0000;">===&gt; "ctypes.StructType("FILE").ptr(ctypes.UInt64("0x9781b38"))"</span>  <span style="color: #808080;">// pointer value</span>

// ... write data to file here ...</span></code></pre>
<p>2. Declaring and using structs and arrays.</p>
<pre><code><span style="color: #333399;"><span style="color: #808080;">// Declare the 'hostent' struct, which contains five fields, each with their own
// types. This corresponds to the C declaration:
//   struct hostent {
//     char* h_name;       // name of host
//     char** h_aliases;   // array of strings representing aliases of the host
//     int h_addrtype;     // whether the IP address is IPv4 or IPv6
//     int h_length;       // length, in bytes, of the IP address
//     char** h_addr_list; // array of IP addresses from name server
//   };</span>
let hostent = ctypes.StructType("hostent",
                                [{ h_name      : ctypes.char.ptr                 },
                                 { h_aliases   : ctypes.char.ptr.ptr             },
                                 { h_addrtype  : ctypes.int                      },
                                 { h_length    : ctypes.int                      },
                                 { h_addr_list : ctypes.uint8_t.array(4).ptr.ptr }]);

<span style="color: #808080;">// Declare the 'gethostbyname' function, which has a C prototype of:
//   struct hostent* gethostbyname(const char* name);</span>
let gethostbyname = library.declare("gethostbyname",
                                    ctypes.default_abi,
                                    hostent.ptr,         <span style="color: #808080;">// use our 'hostent' type</span>
                                    ctypes.char.ptr);

<span style="color: #808080;">// Ask our function to resolve a hostname.</span>
let google = gethostbyname("mail.google.com");

<span style="color: #808080;">// Dereference the pointer to 'hostent' struct, access the 'h_name' field, and
// convert it to a JS string. This is roughly equivalent to the C expression:
//   printf("%s", google-&gt;h_name);</span>
google.contents.h_name.readString();
  <span style="color: #ff0000;">===&gt; "googlemail.l.google.com"</span>

<span style="color: #808080;">// Dereference the 'h_addr_list' field twice to get the first element in the
// array, which is an array of 4 bytes representing the IPv4 address of the host.
// Roughly equivalent C:
//   printf("%u.%u.%u.%u", (int) h_addr_list[0][0], (int) h_addr_list[0][1],
//          (int) h_addr_list[0][2], (int) h_addr_list[0][3]);</span>
google.contents.h_addr_list.contents.contents.toString();
  <span style="color: #ff0000;">===&gt; "ctypes.uint8_t.array(4)([74, 125, 19, 17])"</span>  <span style="color: #808080;">// 74.125.19.17</span></span></code></pre>
<p>3. Creating C function pointers for JS functions.</p>
<pre><code><span style="color: #333399;"><span style="color: #808080;">// Declare the type of a comparator function that takes two pointers to elements,
// and returns:
//   -1 if i &lt; j;
//    0 if i == j;
//    1 if i &gt; j.
// Equivalent C:
//   typedef int (comparator_t*)(const int8_t* i, const int8_t* j);</span>
let comparator_t = ctypes.FunctionType(ctypes.default_abi, ctypes.int,
                                       ctypes.int8_t.ptr, ctypes.int8_t.ptr).ptr;

<span style="color: #808080;">// What's the C type of 'comparator_t'?</span>
comparator_t.name;
  <span style="color: #ff0000;">===&gt; "int (*)(int8_t*,int8_t*)"</span>

<span style="color: #808080;">// Declare the 'qsort' function which takes an array of elements and a comparator
// function, and sorts the array.
//   void qsort(void* array, size_t length, size_t elemsize, comparator_t comp);</span>
let qsort = library.declare("qsort", ctypes.default_abi, ctypes.void_t,
              ctypes.voidptr_t, ctypes.size_t, ctypes.size_t, comparator_t);

<span style="color: #808080;">// Implement a JS function that looks just like 'comparator_t' above.</span>
function reverse(i, j) { return j.contents - i.contents; }

<span style="color: #808080;">// Construct a C function pointer from our JS function.</span>
let reverse_ptr = comparator_t(reverse);

<span style="color: #808080;">// What's 'reverse_ptr'?</span>
reverse_ptr.toString();
  <span style="color: #ff0000;">===&gt; "ctypes.FunctionType(ctypes.default_abi, ctypes.int, ctypes.int8_t.ptr,
                            ctypes.int8_t.ptr).ptr(ctypes.UInt64("0x81a430cb"))"</span>

<span style="color: #808080;">// Construct an array of values and call 'qsort'.</span>
let array_t = ctypes.int8_t.array();
let ints = array_t([3, 1, 5, 6, 4, 2]);
qsort(ints.address(), ints.length, array_t.elementType.size, reverse_ptr);

<span style="color: #808080;">// Voilà!</span>
ints.toString();
  <span style="color: #ff0000;">===&gt; "ctypes.int8_t.array(6)([6, 5, 4, 3, 2, 1])"</span></span></code></pre>
<p>So, if you&#8217;re an extension author, or writing code for the browser, keep js-ctypes in mind &#8212; and let us know how it goes!</p>
<p><i>Edit 8/7/10: updated syntax for API changes.</i></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/dwitte/2010/03/12/extension-authors-browser-hackers-meet-js-ctypes/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>On the state (and future) of cookies</title>
		<link>http://blog.mozilla.com/dwitte/2010/03/03/on-the-state-and-future-of-cookies/</link>
		<comments>http://blog.mozilla.com/dwitte/2010/03/03/on-the-state-and-future-of-cookies/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 20:31:59 +0000</pubDate>
		<dc:creator>dwitte</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/dwitte/?p=6</guid>
		<description><![CDATA[Back in 1994, at a fledgling company called Netscape Communications, a specification was proposed that would fundamentally change the Web: the ability for a web server and a browser to maintain state. Web pages being viewed in a browser could send login information to websites using the standard form controls that we know today, but [...]]]></description>
			<content:encoded><![CDATA[<p>Back in 1994, at a fledgling company called Netscape Communications, a <a href="http://web.archive.org/web/20070805052634/http://wp.netscape.com/newsref/std/cookie_spec.html">specification</a> was proposed that would fundamentally change the Web: the ability for a web server and a browser to maintain state. Web pages being viewed in a browser could send login information to websites using the standard form controls that we know today, but there was no way for that login state to be associated with an individual browser. Things like shopping carts, online forums, and online banking weren&#8217;t possible. The cookie specification changed that. By allowing the web server to store small pieces of information in the browser, this information could then be sent back with every http request, and stateful transactions were born.</p>
<p>Of course, the web back then was far different from the web today, and the cookie standard really hasn&#8217;t changed much. The simple protocol that was implemented more than a decade ago was just that &#8211; simple, minimal, enough to get the job done. But along came https, and JavaScript, and advertisers that want to track you, and host sites with many unrelated subdomains like GeoCities and Blogspot &#8212; and with them came cross-site scripting attacks and severe privacy and security issues. Underneath a login session at your favorite online bank is just a handful of cookies, and if that bank makes a mistake or two in their implementation, those cookies could be sent in the clear &#8212; you can guess what happens next.</p>
<p>There have been attempts to improve the protocol. <a href="http://tools.ietf.org/html/rfc2109">RFC2109</a> was the first, and somewhat reflects the situation today. But this spec didn&#8217;t succeed a vacuum &#8211; cookies were already in use, and browsers didn&#8217;t wholly adopt the new standard for fear of breaking existing, working sites. The spec became more of an ideology, and servers were instead designed around how browsers actually behaved. Realizing that changing the standard &#8212; or rather, having browsers and servers implement the standard &#8212; was a losing battle, <a href="http://tools.ietf.org/html/rfc2965">RFC2965</a> was produced. This introduced new headers, Set-Cookie2 and Cookie2, that had different semantics and solved some (then new) problems &#8211; it added more trust to cookies, so that servers could have more confidence that what they received from a browser actually originated from them and not an attacker. This is achieved by sending back metadata with each cookie, detailing how the cookie was set. Unfortunately, interest in the new standard wasn&#8217;t great, and most browsers today don&#8217;t implement it. (Among the big five, Opera is the sole exception.) But the problem of cookie trust and integrity remains.</p>
<p>Thus was formed the <a href="http://tools.ietf.org/wg/httpstate/charters">http-state</a> working group in 2009, under the auspices of the IETF. The charter of the group is, firstly, to produce a specification that accurately reflects how cookies are implemented today. This is necessarily a big task, because such a specification must account for the subtle differences between browser implementations. This will result in two separate documents &#8212; one describing how clients should behave in order to match other clients (concensus behavior), and one describing how servers should behave in order to interoperate with those clients (conservative behavior). The former will be much more detailed &#8212; due to the presence of numerous edge cases &#8212; than the latter. Work towards producing a <a href="http://tools.ietf.org/wg/httpstate/draft-ietf-httpstate-cookie/">draft</a> is pretty far along. As an added benefit, the extensive testing of the big five browsers required to produce this spec has resulted in several fixes to Firefox, in order to bring it in line with the consensus behavior. <a href="http://www.adambarth.com/">Adam Barth</a> deserves a big callout for the awesome effort and energy he&#8217;s put into this project &#8212; without him this spec wouldn&#8217;t exist.</p>
<p>The http-state working group will be congregating at the <a href="http://www.ietf.org/meeting/77/index.html">77th IETF meeting</a> in Anaheim, California, March 21-26. Representatives from at least some of the major browser vendors &#8212; and of course other server and client implementors &#8212; will be there. I&#8217;ll be going along in my capacity as the Firefox cookie module owner. Which brings me to the second (perhaps informal) purpose of the group, or at least of many of its members &#8212; to bounce around ideas for a modern cookie standard; something that does not inherit the integrity problems and lack of scaling that current implementations do. While there are new web standards that provide state management mechanisms (such as <a href="http://en.wikipedia.org/wiki/DOM_storage">DOM storage</a>), nothing beats the simplicity, ubiquity, and public awareness of cookies. Thus it is a noble goal to make things right, and something that http-state holds promise to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/dwitte/2010/03/03/on-the-state-and-future-of-cookies/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Joining Mozilla</title>
		<link>http://blog.mozilla.com/dwitte/2009/07/06/joining-mozilla/</link>
		<comments>http://blog.mozilla.com/dwitte/2009/07/06/joining-mozilla/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 04:07:17 +0000</pubDate>
		<dc:creator>dwitte</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mozilla.com/dwitte/?p=3</guid>
		<description><![CDATA[&#8230; and my first post!! After a good long while in school (essentially my entire life to date, in fact), I complete a Ph.D at Stanford University and join Mozilla Corporation. I&#8217;ve enjoyed contributing to Mozilla for many years, in which time I&#8217;ve helped improve performance, clean up code, add features, improve privacy, and (probably [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; and my first post!!</p>
<p>After a good long while in school (essentially my entire life to date, in fact), I complete a Ph.D at Stanford University and join Mozilla Corporation. I&#8217;ve enjoyed contributing to Mozilla for many years, in which time I&#8217;ve helped improve performance, clean up code, add features, improve privacy, and (probably most significantly) become owner of the <a href="http://www.mozilla.org/owners.html#cookies-and-permissions">cookie module</a>. I hope to continue these activities, with one notable addition: my primary focus at Mozilla will now be static analysis, working to improve code quality and performance for the entire Mozilla platform. I will be working mostly with <a href="http://blog.mozilla.com/tglek/">Taras Glek</a>, <a href="http://benjamin.smedbergs.us/blog/">Benjamin Smedberg</a>, and <a href="http://blog.mozilla.com/dmandelin/">David Mandelin</a> among others, and I&#8217;ll be blogging soon about some of the problems we hope to solve.</p>
<p>There&#8217;s a lot to be done, and I&#8217;m excited to finally be able to devote some serious time to it!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mozilla.com/dwitte/2009/07/06/joining-mozilla/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

