<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Chris Chandler on Medium]]></title>
        <description><![CDATA[Stories by Chris Chandler on Medium]]></description>
        <link>https://medium.com/@squanderingtime?source=rss-9d9be4a4b20d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7DgnqGpI4oUnjyIDzsbvLg.jpeg</url>
            <title>Stories by Chris Chandler on Medium</title>
            <link>https://medium.com/@squanderingtime?source=rss-9d9be4a4b20d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 23:47:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@squanderingtime/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[You Too Can Build A Kernel/Hypervisor Part 1 — Preliminaries]]></title>
            <link>https://medium.com/@squanderingtime/you-too-can-build-a-kernel-hypervisor-part-1-preliminaries-de451a55708f?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/de451a55708f</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[operating-systems]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Wed, 10 Jul 2019 19:45:07 GMT</pubDate>
            <atom:updated>2019-07-10T19:45:07.213Z</atom:updated>
            <content:encoded><![CDATA[<h3>You Too Can Build A Kernel/Hypervisor Part 1 — Preliminaries</h3><p>About a week or two ago I started following some how-tos on the internet for building kernels and/or hypervisors in Rust. It’s been a fun adventure and I thought I would compile my notes together in case someone wants to follow along or see how an OS starts up. Most of the examples out (probably to keep things simpler…) are based on x86_64 hardware. To spice things up a bit I decided that I’d be targeting aarch64 (ARMv8) instead using QEMU’s virt board.</p><p>The intended audience here is someone with a background in programming, but not necessarily kernel programming or C. A familiarity with assembly syntax is helpful, but certainly not required. The same can be said for a working knowledge of Rust. This is mostly a vehicle to talk about all the exciting concepts in lower-level programming as opposed to a “Here’s how to write Rust.”</p><p>Some of this work was inspired by Philipp Oppermann’s excellent Writing an OS In Rust (Second Edition ) <a href="https://os.phil-opp.com/">https://os.phil-opp.com/</a> . If you would rather see and write a kernel for x86_64 you should go read his instead.</p><p>Ash Wilding has an excellent tour of hypervisor concepts on his blog at <a href="https://ashw.io/blog/arm64-hypervisor-tutorial/1">https://ashw.io/blog/arm64-hypervisor-tutorial/1</a>. He also includes examples of the assembly needed to setup some core functionality on an Arm system.</p><h3>Preliminaries on OSX (10.14.5)</h3><ul><li>homebrew</li><li>crosstoolng (1.24.0) via homebrew</li><li>Rustup if you’re following along with my code (not needed per se)</li><li>rustup nightly (because we need compiler features hidden behind nightly)</li></ul><h3>Aside about cross compiling</h3><p>What’s the deal with a cross compiler?! I already have a compiler.</p><p>That’s true, but…</p><p>Compilers target a “triple” on their output. The format is machine-vendor-OS. In my case, the default “triple” is x86_64-apple-darwin. That is to say it will use the x86_64 instruction set, on hardware provided by Apple, with the Darwin/XNU <a href="https://en.wikipedia.org/wiki/Application_binary_interface">ABI</a> (application binary interface).</p><p>If I want to do operating system development I have to make a radically different set of assumptions, especially if I’m targeting a different instruction set like aarch64/ARMv8. What we really need is a compiler that can target aarch64-unknown-elf. That is, it will use the aarch64 (ARMv8) instruction set, without caring about hardware, and that the output need only conform to the ELF spec.</p><h3>Install crosstool-ng &amp; Cross-compiling Toolchain</h3><p>This has an easy part and a tricky part. The easy part is installing it via homebrew. The tricky part is that crosstool-ng is a toolchain that compiles other toolchains so you have to meet all the requirements of those toolchains too.</p><p>You’re probably going to need to create a new volume with Disk Utility for storing the cross compiler toolchain. Most of the compiler toolchains assume a case sensitive filesystem and crosstool-ng won’t even attempt to build (for good reasons) until that’s true.</p><p>You’re going to need an APFS volume w/ case sensitivity and probably about 10GB. The final required size will be considerably less, but we need to make sure to have enough space to store all the compilation intermediates.</p><p>I followed the instructions at <a href="https://medium.com/coinmonks/setup-gcc-8-1-cross-compiler-toolchain-for-raspberry-pi-3-on-macos-high-sierra-cb3fc8b6443e">https://medium.com/coinmonks/setup-gcc-8-1-cross-compiler-toolchain-for-raspberry-pi-3-on-macos-high-sierra-cb3fc8b6443e</a></p><p>Luckily for OSX 10.14.5 (as of this writing) I didn’t need <em>most</em> of the instructions (for crosstool-ng 1.24.0). I started with creating the volume, skipped to menuconfig, and then went right to build and it all worked.</p><p>Once you have the mount point /Volumes/xtool-build-env/<em> </em>you can skip to configuring crosstool-ng<em>.</em></p><p>The key things that need to be set via ct-ng menuconfig:</p><ul><li>Paths and misc options -&gt; Working directory -&gt; /Volumes/xtool-build-env/.build</li><li>Paths and misc options -&gt; Prefix directory -&gt; /Volumes/xtool-build-env/${CT_TARGET}</li><li>Target options -&gt; Target architecture -&gt; ARM</li><li>Target options -&gt; Endianness -&gt; Little endian</li><li>Target options -&gt; Bitness -&gt; 64</li><li>Operating System -&gt; Target OS -&gt; Bare-metal</li><li>Binary utilities -&gt; binary format -&gt; ELF</li><li>Debug facilities -&gt; gdb (Not strictly required, but you <strong>will</strong> regret not having it if you decide to experiment)</li></ul><p>Here’s <a href="https://gist.github.com/cchandler/e15a54ac5ac93b63ed1831383e957f85">a gist of my local config</a> just in case you decide to dig around the config file and want a reference point.</p><p>You should be able to make the toolchain now with ct-ng build. Don’t be like me and do this step at home, or at least with a power cable. It took my relatively recent laptop about 20 minutes of work and 25% of my battery to finish this step.</p><p>When it’s done you should have a directory /Volumes/xtool-build-env/aarch64-unknown-elf/bin with a bunch of tools prefixed aarch64-unknown-elf.</p><h3>Installing Rust</h3><p>I did this project in Rust, so if you want to build along, you’ll need it. That being said, if you just want the details of how the pieces fit together, feel free to ignore it. <a href="https://rustup.rs/">Get the Rust toolchain installer</a> and follow the instructions.</p><p>The only additional instructions you’ll need are to enable + set nightly, and add the aarch64-unknown-linux-gnu target.</p><pre>rustup default nightly<br>rustup target add aarch64-unknown-linux-gnu</pre><h3>Additional Rust tools</h3><p>We need a few additional Cargo command line tools that aren’t strictly needed to compile our OS crate, but do need to be on the command line</p><pre>rustup component add llvm-tools-preview<br>cargo install xargo<br>cargo install cargo-binutils</pre><h3>Installing QEMU</h3><p>Super simple: brew install qemu.</p><h3>Sanity Checks Before Continuing</h3><p>If you’re trying to get <em>everything</em> working then you should now have (on $PATH):</p><ul><li>aarch64-unknown-elf-gdb</li><li>qemu-system-aarch64</li><li>cargo-size (from cargo-binutils)</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de451a55708f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Hugo SciFi Reader (1953–1963)]]></title>
            <link>https://medium.com/@squanderingtime/my-hugo-scifi-reader-1953-1963-3fcbacb8e5e3?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3fcbacb8e5e3</guid>
            <category><![CDATA[science-fiction]]></category>
            <category><![CDATA[hugo-awards]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Wed, 03 Jul 2019 19:39:16 GMT</pubDate>
            <atom:updated>2019-07-03T19:39:16.934Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*i5MkSglyPMZNyTdm.JPG" /><figcaption>Amazing Stories!</figcaption></figure><p>Sometime ago I made a personal project out of reading the list of Hugo award winning science fiction novels. I don’t remember exactly when it started, but as I write this I’m working my way through the 1990s. I offered to put together a reading list for friends based on the entries I’ve read so far with some light commentary on which ones I’d recommend and which ones I’d skip.</p><h3>Me as a reader &amp; Who this is for</h3><p>I’m going to qualify this entire list with the kind of reader I am. First off, I tend to read short fiction and novellas. Shorter is better and I am immediately skeptical of any book over 250 pages. I also distrust books that are meant to be a series. Concise is good. I do not, however, have any particular preferences on hard science fiction versus “softer” science fiction. If you’re not familiar with the distinction then don’t even worry about it.</p><p>If you are willing to tell a stranger that you enjoy Gravity’s Rainbow, Finnegans Wake, or Foucault’s Pendulum then you’re almost certainly going to disagree with me a lot (I would gladly throw all three in the trash). No amount of flowery prose, structural innovation, or avant garde storytelling can make up for a lack of compelling plot or a point.</p><h3>The award itself</h3><p>Named for Hugo Gernsbeck the founder of the first Science Fiction magazine <em>Amazing Stories</em> in 1926. The award itself is handed out annually at Worldcon, the World Science Fiction Convention, and is overseen by the World Science Fiction Society. Any dues paying member can make a nomination, and after nominations, vote. There’s no additional criteria like a book must be at least <em>this sciency</em> to win an award.</p><p>This is to say that the award, in many ways, is a popularity contest among the World Science Fiction Society members. As such, the award shouldn’t be construed as the “best” available, but rather the most popular. The social mores of the time and the makeup of the society itself are unavoidable. For example, science fiction had women writers for decades and was even started by Mary Shelly… but the first winner in 1953, The Demolished Man, is profoundly sexist.</p><p>So take any given work, <em>especially</em> the earlier works with a healthy grain of salt.</p><h3>The List (1953–1963)</h3><h4>1953- The Demolished Man by Alfred Bester</h4><p>The Demolished Man is a super fun inverted detective story told from the perspective of the guy doing the crime. The catch is that by the time of the book some humans have developed ESP. Not everyone, but enough that they’ve formed a world-wide guild and the police have mind readers available. So how do you commit a murder when the state can read your thoughts?</p><p>It’s a fun adventure but unless you like the almost cartoony-ness of the old pulp science fiction magazines this one might be rough. One critical summary included that the characters and their motivations only make sense in terms of Freudian psychology. And on the overt sexism, to borrow Jo Walton’s quote: “The words girl and pretty always come as a pair.”</p><p>As far as I know this is also the first appearance of the term “esper” from “ESP-er.” It also makes a <em>number</em> of jokes that literally only make sense in print. So that’s fun.</p><p>Recommendation: Read, but only if you like pulpy storytelling.</p><h4>1954 (Retro Hugo)- Fahrenheit 451 by Ray Bradbury</h4><p>There was no Worldcon held in 1954 so this one was awarded in 2004 retroactively. The thing about retroactive awards like this is they go to the most popular book from the year that people remember, and given that many high schools teach this book, it’s no wonder it won.</p><p>Recommendation: Read because it’s a staple.</p><h4>1955- They’d Rather Be Right (Also known as The Forever Machine) by Mark Clifton and Frank Riley</h4><p>Scientists develop a machine that they can feed facts into, and based on those facts, make “correct” deductions. This machine, named Bossy, is eventually able to be hooked up to human brains to “optimize” away false notions and bad information. This includes the fundamentals of how we age (aging is just a misconception of the body?) and thus confers immortality. The catch, is that it works like therapy. It can only “optimize” away this bad information if you’re willing to accept a better, rational understanding of <em>everything in your head</em>. Faced with the choice of immortality or acknowledging a lifetime built on potential falsehoods… most people would rather be right.</p><p>Many analyses of the award winners conclude that this is one of the <em>worst</em> works to ever actually win the award. It has very little in the way of development, and when it actually reaches the point where the point goes, it doesn’t actually make one. It has a handful of interesting questions, but none of them are explored in the work itself. It’s a massive setup with no delivery. On the other hand, it’s so short that it’s usually collected in anthologies, so you’re likely to get other, better stories along with it.</p><p>I will say, one of the things I do like about this book is their portrayal of scientists and academics as being human and developing religious-like attachment to their theories and works. It shows that science isn’t an infallible process, but rather a human one.</p><p>Recommendation: Skip, unless it comes in a good anthology.</p><h4>1956- Double Star by Robert Heinlein</h4><p>A down-on-his-luck actor going by the name The Great Lorenzo gets sucked into a massive political plot spanning Earth and Mars when he’s hired to be a body double for an unspecified individual. He winds up in a massive political plot that could lead to war. Hijinks ensue. This is a book strongly propelled by tension and to talk any more plot would ruin it.</p><p>I <strong>thoroughly</strong> enjoyed this book and would strongly recommend it. Especially if you’ve read other of Heinlein’s books. Also, this is one of the best first-person perspective books I’ve ever read, period. Heinlein does an amazing job of getting you into Lorenzo’s head. At 170 pages, the pacing is superb.</p><p>Recommendation: Definite read.</p><h4>1957- No Worldcon Held</h4><h4>1958- The Big Time by Fritz Leiber</h4><p>There’s a war called the Change War. It’s a war fought in the timeline, constantly rewriting events and modifying history. Outside of this timeline is The Big Time, which has a recuperation station for warriors coming back from battle where the story takes place. In contrast, there’s the Little Time where all the changes happen. The story is told from the perspective of a worker at the recuperation station talking to people engaged in the battles.</p><p>This book… is. so. boring. It suffers from the problem of existing in a world far more interesting than anything covered in the book. It’s the science fiction version of My Dinner With Andre. But dryer. It’s people sitting around talking about what happens in the world. On the positive side, it deals with more postmodern ideas like the mutability of history. On the other hand, so many <em>better</em> works have come along since this one I can’t recommend it. It’s only 130 pages… but it feels <strong><em>so</em></strong> much longer.</p><p>Update: Actually, feel free to skip anything by Fritz Leiber. I have yet to read anything of his I haven’t wanted to throw across the room.</p><p>Recommendation: Hard pass.</p><h4>1959- A Case of Conscience by James Blish</h4><p>A Peruvian Jesuit priest, Father Ramon Ruiz-Sanchez, is part of a survey team to the planet Lithia to investigate whether it should be brought into trade agreements. The Lithians, a lizard like people, have developed a perfect, innate, and infallible sense of morality without any notion of God or religion. Father Ruiz-Sanchez experiences something along a crisis of faith and the book explores religion’s impact on society.</p><p>It’s a surprisingly good example of hard science fiction told with a spiritual side. Regarding the science for instance, the name Lithia comes from the lithium content in the high concentration of pegmatite on the planet’s surface. Also be prepared to have a solid explanation of The Manichean Heresy.</p><p>Recommendation: Read.</p><h4>1960- Starship Troopers by Robert A. Heinlein</h4><p>The story of the space marine Juan “Johnny” Rico and his deployments first against “The skinnies” and then his subsequent deployment in The Bug War. This was the last of Heinlein’s “juvenile” novels and spends a healthy amount of time discussing civics, the military, voting, and the like. It’s also the origin of the term “space marine.”</p><p>If you’ve seen the 1997 movie of the same name you should know that the movie is a <em>satirization</em> of the book. The stories are essentially the same but where the movie is portraying a silly, comically pro-military propaganda machine, the book is quite serious in its treatment of the same ethics and ideology. Heinlein spent the rest of his career being accused of militarism and fascism for this book. That being said, I did enjoy it.</p><p>Recommendation: Read. Especially for the origins of the Space Marine trope.</p><h4>1961- A Canticle for Leibowitz by Walter M. Miller, Jr.</h4><p>The world is annihilated in a nuclear war called The Flame Deluge. One thousand years later humanity is finally starting to rebuild after a period referred to as The Simplification. Latin is once again common and the Catholic church reigns supreme. On a mission in the desert, a young novitiate of the church named Brother Francis Gerard discovers a bomb shelter owned by the same man credited with founding his order, Leibowitz. This sets off a 1500 year chain of events told in three beautiful vignettes. Themes include the cyclical nature of history, science, power, and religion.</p><p>This book is absolutely <em>superb</em> and I strongly recommend it.</p><p>Recommendation: Must Read.</p><h4>1962- Stranger in a Strange Land by Robert A. Heinlein</h4><p>The tale of the first human, Valentine Michael Smith, to grow up among Heinlein’s famous Martian aliens. Smith returns to Earth as a young adult having been raised by the Martians. He’s never experienced human cultures, television, politics, or the opposite sex. He makes his way through human society (and religion) as one of the most famous humans in history with an almost unfathomable claim to Mars itself (because of legal quirks in this universe).</p><p>Here’s a book where I openly acknowledge that I diverge from popular opinion. Despite its extreme popularity, I found this book almost unreadably boring. I’ve met numerous people that described it as “life changing” but I just don’t get it. Some of the “edgiest” content is about open relationships and polyamory, so if you’re already familiar with those subjects, this book isn’t going to come across as transgressive or edgy. It’s actually made the top of numerous “Best of the Banned Books” list for this reason.</p><p>Recommendation: Read, but only if you’re out of alternatives and want to see what the fuss is about.</p><h4>1963- The Man in the High Castle by Phillip K. Dick</h4><p>An alternate history set in 1962 presupposing that both Nazi Germany and Imperial Japan won World War II. Adventure in the carved up United States starting in San Francisco with a sprinkling of the I Ching. I would write more about it, but honestly, I really can’t stand Phillip K. Dick’s novels. I find his short stories superb, but most of his novel length works I just can’t get behind. Especially works like this that take on a 4th-wall-breaking meta-narrative. I also find his longer writing style <em>incredibly</em> boring.</p><p>Recommendation: Hard pass unless you know you like Phillip K. Dick novels.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3fcbacb8e5e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Certificates: A Primer]]></title>
            <link>https://medium.com/@squanderingtime/certificates-a-primer-bcece76cd682?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcece76cd682</guid>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[certificate-authority]]></category>
            <category><![CDATA[openssl]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Wed, 03 Jul 2019 18:05:00 GMT</pubDate>
            <atom:updated>2019-07-03T18:05:00.632Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been meaning to write a primer on certificates for about a decade now. Certificates are a ubiquitous piece of modern engineering infrastructure that we collectively spend very little time discussing. Hopefully I can demystify some of the inner-workings so the next time you get a goofy certificate error you’ll at least have something to refer back to.</p><p>This might become “Part 1” of a larger set if you find it helpful :-). So feel free to offer suggestions + feedback.</p><h3>The Certificate File</h3><p>Certificates essentially come in two flavors: DER and PEM. Telling them apart is very easy. DER is a binary encoding format</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MdI9ERDMAatg3-L9EKZdqA.png" /><figcaption>DER encoded certificate</figcaption></figure><p>PEM encoding starts with the much prettier, well-known header:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*osjRn-wfBBcCQY4iY3xA2Q.png" /><figcaption>PEM encoded certificate</figcaption></figure><p>If you wanted to inspect the contents of a PEM certificate you would use:</p><pre>openssl x509 -in root.pem -text</pre><p>and if you wanted to read a DER certificate you would add the -inform der flag.</p><pre>openssl x509 -in root.der -inform der -text</pre><h3>The Body Elements</h3><p>Just about everything you need to know about certificates can be understood locally by looking at certificate files. There’s really nothing special happening in them.</p><p>We’re going to go section by section explaining the pieces. I’ll present them in the same order that openssl’s x509 text presents them.</p><h4>Data</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bLqiNhE32c7-86CVs4TpzQ.png" /><figcaption>Certificate Data &amp; Serial Number</figcaption></figure><p>Every certificate you are likely to ever see is version 3. I have never seen a non-v3 in the wild.</p><p>Serial numbers though are interesting. These are unique and tracked by certificate authorities to track issued certificates. If you were to go looking through a Certificate Revocation List (CRL) you would be searching by serial number.</p><h4>Signature, Issuer, and Subject</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bVLqikIeXI0poe71AiYLzQ.png" /><figcaption>Algorithm, Issuer, and Subject</figcaption></figure><p>The signature algorithm explains how this particular certificate is to be validated. In this case we’re saying that if you want to validate this certificate you’ll need to calculate a SHA-512 of the certificate body and use the public key of the issuer certificate to make sure the signature matches. In this case, because the issuer matches the subject, this is a self-signed certificate (and later when we talk about extensions it will be identified as a CA). All root certificates are self-signed like this.</p><p>Both the issuer and the subject field are made of a “Distinguished Name.” A distinguished name is technically an X.500 Name so if you thought this looked… <em>ldap-y</em> that’s why. The distinguished name may include:</p><pre>CN=commonName<br>OU=organizationUnit<br>O=organizationName<br>L=localityName<br>S=stateName<br>C=country</pre><p>For the purposes of the internet, the common name is what’s used for matching a hostname. So my certificate above would name match for <a href="https://squanderingti.me./">https://squanderingti.me</a> because it’s the common name (cn) of the subject.</p><h3>Subject Key Info</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FmcUtXqePpVvDBNocBc7sA.png" /><figcaption>Public Key Information</figcaption></figure><p>The juicy crypto bits. If you don’t care about the innards of RSA you can safely ignore these fields. This is an RSA key that’s 2048 bits in length. Then it’s the bytes of the modulus and exponent. The value 65,537 is the commonly selected exponent for a <a href="https://en.wikipedia.org/wiki/65,537">variety of reasons</a>.</p><h3>X.509v3 Extensions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t-4BmZLpzv7ebpABxaDdfQ.png" /><figcaption>X.509 V3 Extensions</figcaption></figure><p>The V3 extensions are the real meat &amp; potatoes of the certificate body. These define some niceties and how the certificate may be used.</p><h4>Subject Key Identifier</h4><p>The subject key identifier is a hash of the public key body. It’s used for making additional cert lookups fast.</p><h4>Key Usage</h4><p>The Key Usage says what this certificate’s key is authorized (by the certificate authority) to perform. From the standard, RFC 3280, this field may contain:</p><pre>KeyUsage ::= BIT STRING {<br>           digitalSignature        (0),<br>           nonRepudiation          (1),<br>           keyEncipherment         (2),<br>           dataEncipherment        (3),<br>           keyAgreement            (4),<br>           keyCertSign             (5),<br>           cRLSign                 (6),<br>           encipherOnly            (7),<br>           decipherOnly            (8) }</pre><p>OpenSSL displays keyCertSign as “Certificate Sign.” That means this public key is usable for signing other certs. That makes sense since it’s a root. However, if you tried using this certificate on a local http server for playing around you would notice some clients would reject it outright because it lacks the key usage of dataEncipherment, and keyEncipherment. It’s sort of an additional protection to make sure a CA certificate isn’t used for non-approved uses… but relies on the checker to verify usage bits. In my experience few libraries check usage flags.</p><h4>Criticality</h4><p>Also of note is that ‘critical’ flag. Any extension marked as critical means “Dear SSL/TLS library: If you do not know how to interpret this extension then you must reject me immediately.”</p><h4>Extended Key Usage</h4><p>Extended key usage came later and is sometimes used for clarifying intent. I included it in my root in this example but it’s usually used on end certificates. The values outlined in the spec are:</p><pre>id-kp-serverAuth             OBJECT IDENTIFIER ::= { id-kp 1 }<br>id-kp-clientAuth             OBJECT IDENTIFIER ::= { id-kp 2 }<br>id-kp-codeSigning             OBJECT IDENTIFIER ::= { id-kp 3 }<br>id-kp-emailProtection         OBJECT IDENTIFIER ::= { id-kp 4 }<br>id-kp-timeStamping            OBJECT IDENTIFIER ::= { id-kp 8 }<br>id-kp-OCSPSigning            OBJECT IDENTIFIER ::= { id-kp 9 }</pre><p>but if you were feeling industrious you could put any OID in this field.</p><h4>Basic Constraints</h4><p>Basic Constraints only contains two possible values: “is this a CA?” and “maximum path length.” If you sign a certificate (let’s say ‘A’) by another certificate (‘B’) and the issuing certificate(‘B’) doesn’t have this flag set your new certificate (‘A’) will be rejected. Path length says the maximum number of signing certificates that can exist between this certificate and the end certificate being verified (this prevents an intermediate certificate being lost).</p><h4>Authority Key Identifier</h4><p>The Authority Key Identifier is a hash of the issuing entity’s public key. This makes it fast to search the local trust store/certificate list. In this case you can see the Subject Key Identifier and the Authority Key Identifier match.</p><h4>Subject Alternative Name</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*aB2XTVqNZj7P2McAebnBPA.png" /><figcaption>Google’s SAN on 5/15/19</figcaption></figure><p>This has become a <em>very</em> common extension. This is used when the subject of the certificate may have multiple names. If you request a wildcard cert that should work on multiple domains like ‘*.squanderingti.me’ then the wildcard will be placed inside the Subject Alternative Name field. As you can see in the example, it’s possible to cram quite a few DNS names into this field.</p><h4>Certificate Policies</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*131hSO6Jqdkdx9Caj8Y_mA.png" /></figure><p>The policies are essentially where certificate issuance and contract law meet. An issuer may include policy identifiers saying under what terms the certificate was issued and what would be required for revocation or some such. If you wish to read <a href="https://pki.goog/GTS-CP-1.3.pdf">Google’s PKI policies</a> you can search that first OID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wag9vFBxaipgOmLxKIwjcA.png" /></figure><h4>CRL Distribution Points</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*2dEGTbzq3mWEYlD2UZcE3Q.png" /></figure><p>The CRL distribution point is where you would go to find the entire list of certificates that this certificate’s issuer has revoked. CRLs are special signed lists containing all the serial numbers of certificates that should be considered bad.</p><h4>Certificate Authority Information Access</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*N1z_emxa1hT6N2HP1QsMSw.png" /></figure><p>For long-lived issuing authorities, they might have revoked <em>a lot</em> of certificates over the years. For instance, if a customer requests a re-issuance of a cert, which happens through the normal course of business, then the old one has to be revoked. So instead of having to download a potentially massive CRL you can use the Online Certificate Status Protocol (OCSP) to quickly check a serial number.</p><p>The CA issuers is a link to locate the certificate body of the issuer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcece76cd682" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Have A Binary, But Where Is Main?]]></title>
            <link>https://medium.com/@squanderingtime/i-have-a-binary-but-where-is-main-721a7086dd2f?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/721a7086dd2f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Tue, 14 May 2019 18:03:23 GMT</pubDate>
            <atom:updated>2019-05-14T18:03:23.716Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately I’ve been working on a project to explore the x86–64 instruction set. Part of this exploration requires using a disassembler to get the actual instructions that comprise a piece of software. That leads to the question “Where <em>exactly</em> are the instructions that make up my program?”</p><p>Let’s say you have a program written in C like the following</p><pre>#include&lt;stdio.h&gt;</pre><pre>int main() {<br> printf(&quot;Hello World!\n&quot;);<br> return 0;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEjg1PBctY2Us7j9oaSeFQ.png" /><figcaption>Print the program, compile it, run it.</figcaption></figure><p>The first leading question is: what exactly <em>is</em> a.out anyway? In most circles you’ll hear it called a binary but that’s not the whole picture. Specifically, it’s an Executable &amp; Linkable Format file also called an elf file. Amazing write-ups exist on the structure of this file so if you want to learn all the nitty gritty details I’d highly suggest the wiki page.</p><p><a href="https://en.wikipedia.org/wiki/Executable_and_Linkable_Format">Executable and Linkable Format - Wikipedia</a></p><p>For our purposes the important thing to know is that the file contains a very informative program header with all the physical offsets to physically locate the bits we care about. The main part of our program lives within a section called .text.</p><p>There’s a few different ways to find the physical offset and size of the text section. One way is to use the readelfutil.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qb03jxCNDA7AmDayAFQjlg.png" /><figcaption>readelf output of the sections in a.out</figcaption></figure><p>Here we can see that offset for .text is 0x530 with a size of 0x1a2. This, however, includes all the instructions that the compiler designated as our program. It includes a lot of additional boilerplate to setup the environment and stack that executes before main. If we wanted the opcodes for just main we would need to look inside the symbol table to find the specific symbol’s offset and size. One way to get that information is to use objdump.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ADFXAYeRIPogEGyWUKVRtQ.png" /><figcaption>objdump output of the symbol main</figcaption></figure><p>Here we can see that main is defined in the .text section with offset 0x63a and with size 0x17.</p><p>We can use a different trick with gdb to confirm these offsets and lengths are correct. Here’s an example using gdb to disassemble a particular symbol so we can see the individual instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kavjigy3S_Whdb4kKP6KPQ.png" /><figcaption>gdb confirming the offsets</figcaption></figure><p>As an interesting side note we can look at the 3rd instruction lea (which is ‘load effective address’ if you aren’t used to reading assembly). This is going to load the effective address of 0x9f+%rip (%rip is a register) which gdb says is 0x6e4 via the comment on the right. If we return to the same utility objdump we used above we can get the data section of the file we can confirm that’s the address of “Hello World!”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AMR6yt6oix9EcFqAnTZ8Og.png" /><figcaption>objdump output of the .rodata section</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=721a7086dd2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Manually linking Rust binaries to support out-of-tree LLVM passes]]></title>
            <link>https://medium.com/@squanderingtime/manually-linking-rust-binaries-to-support-out-of-tree-llvm-passes-8776b1d037a4?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8776b1d037a4</guid>
            <category><![CDATA[rustlang]]></category>
            <category><![CDATA[llvm]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Sat, 13 Apr 2019 19:44:16 GMT</pubDate>
            <atom:updated>2019-04-13T19:44:16.309Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*z_0DvYlL84trz8DS7PITVw.png" /><figcaption>Checking some results in Ghidra</figcaption></figure><p>Recently I had a project develop that had some fairly unique requirements. First off, it’s a solid candidate for Rust. Second, because of some, erm, strange deployment situations… we needed a toolchain that supported arbitrary out-of-tree LLVM passes. So this work grew out of a viability test. Suffice it to say, I am <em>not</em> a rust expert by any means and there might even be a better way of doing this. That being said, it’s also a fun tour through LLVM internals and other systems concepts. I tried to write this in a way that captures the exploratory process so if you aren’t familiar with some of these lower-level concepts that you can come along for a fun ride and hopefully get something out of it anyway.</p><p>If you’re not familiar with it, LLVM is a massive project that’s been around for 20 years for building modular compiler infrastructure. It does <em>a lot</em> so I’m going to refer to the wiki + project page if you want to know more. What you need to know for this article is that LLVM is split into frontends and backends. Frontends (like rustc) generate LLVM-IR (intermediate representation) so that a backend can generate machine code. Along the way you’ll also see LLVM bitcode and object code. Passes are functional units that can read IR and potentially mutate it. Think code transformation and optimization. In fact, most of the compiler’s heavy lifting occurs in the form of passes transforming and optimizing IR before writing out the results.</p><p>So how do we add a custom pass to run on a Rust binary when cargo and rustc do all the magic for us?</p><h3>Bill of Materials</h3><p>This article was written with the following versions in-mind</p><ul><li>Rust stable-x86_64-apple-darwin<br>rustc 1.33.0 (2aa4c46cf 2019–02–28) (Installed via rustup)</li><li>llvm: stable 8.0.0 ( installed via homebrew)</li></ul><h3>A simple binary</h3><p>Let’s take the following Rust program (in main.rs)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cec564ed2c9b7e668b4f99bcf8d95ca9/href">https://medium.com/media/cec564ed2c9b7e668b4f99bcf8d95ca9/href</a></iframe><p>It does nothing fancy- literally just says hello.</p><p>Normally we would compile this with:</p><pre>rustc main.rs</pre><p>But since we’re using the standard Rustup toolchain, it doesn’t know about our out-of-tree LLVM passes held in a shared object file elsewhere. So instead of completing the program, we’re going to compile it with some extra flags to get LLVM-IR instead of a binary:</p><pre>rustc --emit=llvm-ir main.rs</pre><p>Now we’ve got a new file named main.ll (the IR format) of main. If you aren’t used to seeing IR you can look through this file and see that it’s sort of like fancy assembly. For now, let’s take it the rest of the way to being a complete program:</p><pre>LLVM_HOME=/usr/local/Cellar/llvm/8.0.0/</pre><pre># Run the IR through the LLVM assembler to generate bitcode<br>$LLVM_HOME/bin/llvm-as main.ll</pre><pre># opt is the key addition. It takes in IR or BC and runs it through a pass, returning the mutated BC.<br>$LLVM_HOME/bin/opt -load ~/PATH_TO_PASS.dylib -o main.bc main.bc</pre><pre># Use LLVM&#39;s static compiler to transform the bitcode into object code. Generates main.o<br>$LLVM_HOME/bin/llc -filetype=obj main.bc</pre><pre># Lastly, run the object code through clang so we can complete the linking phase and have a complete binary. (Except this won&#39;t work yet...)<br>$LLVM_HOME/bin/clang -m64 main.o</pre><h4>Linking?!</h4><p>If we try and run that last command as-is we get</p><pre>+ /usr/local/Cellar/llvm/8.0.0//bin/clang -m64 main.o<br>Undefined symbols for architecture x86_64:<br>  &quot;<strong>std::io::stdio::_print::hdec9324a4622df1e</strong>&quot;, referenced from:<br>      main::main::hfe98083a4c87500f in main.o<br>  &quot;std::rt::lang_start_internal::h3dc68cf5532522d7&quot;, referenced from:<br>      std::rt::lang_start::h149f34af029e1c5f in main.o<br>  &quot;<strong>_rust_eh_personality</strong>&quot;, referenced from:<br>      Dwarf Exception Unwind Info (__eh_frame) in main.o<br>ld: symbol(s) not found for architecture x86_64<br>clang-8: error: linker command failed with exit code 1 (use -v to see invocation)</pre><p>Which makes sense. LLVM has no idea where to locate those symbols because we haven’t told it. I’m not going to go too far into the weeds on this, but you can use nm to print the symbol table of various object files. Here’s the output of main.o.The capital U in the output means ‘undefined’ and linking won’t complete until that symbol is found.</p><pre>$ nm main.o | grep _rust<br>                 U _rust_eh_personality<br>$ nm main.o | grep _print<br>                 U __ZN3std2io5stdio6_print17hdec9324a4622df1eE</pre><p>Let’s try one answer that <em>sort</em> of relies on cheating…</p><h4>Locating our missing symbols</h4><p>So where are these symbols? They’re sitting inside a file /Users/chris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/libstd-d4fbe66ddea5f3ce.dylib.</p><pre>$ nm ~/.rustup/toolchains/stable-x86_64-apple-darwin/lib/libstd-d4fbe66ddea5f3ce.dylib | grep _rust_eh_personality</pre><pre>0000000000033960 T _rust_eh_personality</pre><p>This time, unlike an undefined ‘U’, we have a ‘T’- meaning it’s concretely defined in the TEXT segment of this object. So let’s go back to the build directory and link against that file.</p><pre>clang -m64 main.o -L /Users/chris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/ -lstd-d4fbe66ddea5f3ce</pre><p>If you aren’t familiar with clang’s arguments:</p><ul><li>-L Is telling LLVM to look in a particular directory for shared libraries. On OSX these files aredylib, on Linux- so, and on Windows they’re dll.</li><li>-l is the actual name of the library we’re asking to be linked.</li><li>-m is just saying we’d like this compiled as 64 bit output</li></ul><p>Indeed, this will link! But, womp womp, it doesn’t run as-is</p><pre>$ ./a.out<br>dyld: Library not loaded: <a href="http://twitter.com/rpath/libstd-d4fbe66ddea5f3ce">@rpath/libstd-d4fbe66ddea5f3ce</a>.dylib<br>  Referenced from: /Users/chris/Development/rust_play/simple/./a.out<br>  Reason: image not found<br>Abort trap: 6</pre><p>That’s because we told the linker to <em>dynamically</em> link it. That path isn’t on the system’s normal shared library search path, so when it goes to start it, it can’t locate rust’s libstd. We can help it out by using the LD_LIBRARY_PATH trick, but that’s cumbersome and, had we just built it with rustc, it wouldn’t be needed.</p><pre>$ LD_LIBRARY_PATH=/Users/chris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/ ./a.out<br>Hello!</pre><p>So what’s happening?</p><h4>Reverse engineering what rustc is doing</h4><p>Let’s take a different tac. How do Rust’s static libraries work? They’re actually just archive (ar) files called rlibs. If we look in that same directory we found the dylib for libstd we can find files with the same name but the rlib extension instead. Theoretically, if we provide all these rlibs (because I’m lazy and not optimizing imports) maybe the compiler can resolve all these symbols statically and we can end up with a binary that works the way we expect.</p><pre>$LLVM_HOME/bin/clang -m64 *.o $(find /Users/chris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib -name &#39;*rlib&#39;)</pre><p>Essentially the spray-and-pray approach. On my system this is currently another 84 rlib libraries. <em>Note: that these entries to clang don’t have a prefix (no </em><em>-l)</em>. Here’s the shortened linking output this time around:</p><pre>&quot;___rust_alloc&quot;, referenced from:<br>      (omitted)<br>      ...<br>  &quot;___rust_alloc_zeroed&quot;, referenced from:<br>      (omitted) <br>      ...    <br>  &quot;___rust_dealloc&quot;, referenced from:<br>      (omitted)<br>      ...<br>  &quot;___rust_realloc&quot;, referenced from:<br>      (omitted)<br>      ...</pre><p>If we try and compile the program this way we <em>do</em> find all the symbols the linker complained about in the first time around, but now we have <em>new</em> symbols it can’t find. This also makes sense, given the way linking works, we have to be able to resolve transitive dependencies too. So it’s possible we found the symbols our program needs… but now we need the symbols those symbols need…</p><p>Luckily though, we’re down to just a few and they all sound like memory handling functions. Where are the memory handling functions? If we use nm on all the rlibs in the directory it’s undefined everywhere. If we look in the dylib files though it’s there!</p><pre>$ nm /Users/chris/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-d4fbe66ddea5f3ce.dylib | grep __rust_alloc<br>00000000000334e0 T ___rust_alloc<br>0000000000033510 T ___rust_alloc_zeroed</pre><p>So rustc must be doing something special. I had to do some spelunking around rustc’s code… and it turns out the magic is hidden inside librustc_codegen_llvm and librustc_codegen_ssa. They use LLVM’s code generation capability to create an allocator shim that handles the situation where you want a standalone binary. So let’s find a way to get rustc to generate the allocator shim and we can borrow it :-).</p><p>The magic turns out to be:</p><pre>rustc -C save-temps --emit=llvm-ir main.rs</pre><p>Turns out that normally rustc wants to be a good citizen and cleanup temp files, except that we really need the temp files because that includes the allocator shim! This incantation will generate an extra bitcode file in the working directory that indeed has all the allocator symbols(names will vary and you’ll also note that there isn’t a concrete offset yet because this isn’t object code)</p><pre>$ nm main.4s37gsrti678ik8u.rcgu.bc<br>                 U ___rdl_alloc<br>                 U ___rdl_alloc_zeroed<br>                 U ___rdl_dealloc<br>                 U ___rdl_realloc<br>---------------- T ___rust_alloc<br>---------------- T ___rust_alloc_zeroed<br>---------------- T ___rust_dealloc<br>---------------- T ___rust_realloc</pre><p>Here’s the full build script</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c732ffd27558aa09e57841da39b05577/href">https://medium.com/media/c732ffd27558aa09e57841da39b05577/href</a></iframe><p>This indeed will work as expected!</p><pre>$ ./a.out<br>Hello!</pre><p>Phew.</p><h3>A more complex binary</h3><p>For the sake of completeness let’s add a slightly more complicated case where we use cargo and have multiple rust level dependencies.</p><p>Here’s a program with some dependencies on logging and periodic tasks.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/30a7d69ef8a79c2ade84546b37e6191d/href">https://medium.com/media/30a7d69ef8a79c2ade84546b37e6191d/href</a></iframe><p>Instead of calling rustc directly we add some extra arguments to cargo to make sure it passes flags along to rustc.</p><pre>cargo rustc --verbose -- -v -C save-temps --emit=llvm-ir</pre><p>Cargo puts everything of interest in target/debug/deps including the allocator shim we discovered above. This directory will also include rlib copies of all the dependency crates which makes linking a snap.</p><p>Here’s the slightly modified build script that will let you build a more complicated binary:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f55183169d4857b7161b179ca598453a/href">https://medium.com/media/f55183169d4857b7161b179ca598453a/href</a></iframe><p>With final output:</p><pre>$ ./complicated_app<br>2019-04-13 15:25:14 INFO  [complicated] Starting Agent!<br>2019-04-13 15:25:15 INFO  [complicated] Periodic task</pre><p>And with that you should be able to build just about any Rust binary with custom LLVM passes without having to rebuild them directly into rust’s LLVM toolchain!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8776b1d037a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Translation Workbench]]></title>
            <link>https://medium.com/@squanderingtime/translation-workbench-d7f162d95b5c?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7f162d95b5c</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[manga]]></category>
            <category><![CDATA[translation]]></category>
            <category><![CDATA[new-product-development]]></category>
            <category><![CDATA[japanese-language]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Mon, 27 Aug 2018 18:45:06 GMT</pubDate>
            <atom:updated>2018-08-27T18:45:06.391Z</atom:updated>
            <content:encoded><![CDATA[<p>About a year and a half ago I built myself a tool I call “translation workbench” to make reading manga (in its original Japanese) easier. Going from textbook Japanese to colloquial Japanese is a hell of a jump and there’s really nothing quite like manga for absorbing common speech.</p><p>The core problem though is, unless you can read all 2,136 常用漢字, you’re going to spending 90% of your time in the dictionary. That is assuming you have no problem with the grammar.</p><p>So I did what I do. I built a tool! Take a picture of a page, upload it into translation workbench, splash some ML+computer vision on it to detect the page + apply keystone correction, run it through a preliminary translation engine, ENHANCE, select regions of interest + apply layout. Voila, you now have all the extracted kanji in a place where in-browser tools like <a href="https://github.com/melink14/rikaikun">rikaikun</a> can drastically speed up reading time.</p><p>Anyway, this tool has been running on AWS and I even did the basics of productizing it so other people could use it… but then I basically got pulled in another direction. Is this something you’d like to use? Or even work on? The market of English-speaking Japanese learners that get far enough to attempt manga is relatively small, but I keep thinking about it anyway. I mean, I built all this, so maybe it’s worth something to someone other than me.</p><h3>Who doesn’t love screenshots?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0O1F4AqvovzbPMcnti-H_g.png" /><figcaption>Pages of a book so you can see where they are in the workflow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ho2hHRBlwtNdRa75GdykWw.png" /><figcaption>Corner detection + the raw image. The red square shows where it thinks the upper left corner of the page is.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sknPD8oNCFG6xl0IFB2Sxg.png" /><figcaption>Regions of interest. Green is what the OCR system found, blue is what I want extracted.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nN1H9NUtuiOf8qJANgbJsQ.png" /><figcaption>Final stage of workflow where you can hover for single word translation.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7f162d95b5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Shippable Datacenter Part 2: Security Discussion and a Survey of Secure Boot Options]]></title>
            <link>https://medium.com/@squanderingtime/shippable-datacenter-part-2-security-discussion-and-a-survey-of-secure-boot-options-3dfb171aedb3?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dfb171aedb3</guid>
            <category><![CDATA[embedded-systems]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Mon, 16 Jul 2018 18:37:00 GMT</pubDate>
            <atom:updated>2018-07-16T18:50:04.605Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s talk about security. One of the criteria I wanted to bake into this project early on was security. I’ve worked in security off and on again all over my career. Which I say only to add emphasis that writing about embedded security is extremely obtuse. It exists in a state somewhere between “non-existent” and “imagine Ikea instructions for a car engine.” I struggled for days on how to layout most of this information and I’m still not thrilled with it… so there’s likely going to be a lot of additional writing and probably a revision coming. Anyway, moving right along.</p><h4>Recap</h4><p>I started with the Raspberry Pi because I knew it would be a good launchpad to do something more interesting and pursue this idea. I got a basic version working as expected. <a href="https://medium.com/@squanderingtime/shippable-mini-datacenter-of-raspberry-pis-part-1-192f9877df3">I could manage a Raspberry Pi from a central management machine, up to and including replacing the OS on the unit entirely via the networ</a>k. Though not exactly how it would work in something like a managed datacenter, the process was remarkably similar.</p><p>If you didn’t read the entire previous article, the bootstrapping process goes something like this:</p><ul><li>new machine ARPs for address, DHCP offers a new address along with a ‘next-server’ to begin netbooting over TFTP (maybe PXE)</li><li>PXE, or something behaving like PXE, starts looking for configuration files over TFTP.</li><li>Machine finds a boot configuration and starts booting</li><li>Some sort of inventory + imaging process kicks off and lays down a new OS on the disk</li><li>Maybe some initial configuration is done for “first boot” into the new OS</li><li>Machine is integrated into the fleet</li></ul><p>The first thing I should mention is that any compromise of the management network is a total catastrophe. All of these services assume a secure network and provide little-to-no risk mitigation. For instance, if an attacker’s rogue server is simply <strong>faster</strong> than the management machine you can offer DHCP first and direct all machines to boot whatever you’d like. Or, if you have physical access to the SD card in the Raspberry Pi, it doesn’t matter what’s on that SD card because it can just be replaced and the network skipped entirely.</p><h3>So why do we care &amp; what’s the difference?</h3><p>The fundamental difference between a shippable datacenter and a traditional one is physical tamper exposure. A traditional datacenter is a fortress. For example, a provider I worked with recently had five biometric checkpoints between the parking lot and the cage with servers. There was a Mantrap door between the parking lot and the lobby you had to enter just to provide your ID so you could authenticate <em>further</em>. If you were unannounced you never even made it to the lobby. Like the scene from Sneakers: <a href="https://www.youtube.com/watch?v=pGUldQs65LQ">“The whole building says ‘Go Away.’”</a></p><p>Physical attacks against this kind of infrastructure usually involve going for the supply chain. Finding a way to tamper with a device bound for the cage that’s going to ship from a manufacturer directly to the datacenter without crossing the office. While definitely possible, relatively speaking, it’s a very expensive &amp; complicated attack.</p><p>This shippable datacenter on the other hand has no fortress. It’s everything moving as a unit over some sort of logistics freighting system. Additionally, the precept was that it’s installed in the field without typical solid infrastructure. The possibility someone would have physical access is <em>significantly</em> higher.</p><h3>The Requirements</h3><p>With this framing, let’s talk about how we can build a more secure architecture to meet our needs. Is there a way we can ensure that these machines only run the system that we want them to run? We have three major concerns right now:</p><ul><li>Attacker replaces SD card</li><li>Attacker places TFTP-capable server on the network and begins offering boot info, system image, etc</li><li>Remote verification/attestation</li></ul><p>Phrased differently: Is the boot media in the machine the media I expect? Is the replacement content for that boot media served by the network the content I expect? Can I verify the state of that content at arbitrary points?</p><p>The rest of this particular article, and indeed the start of the next several articles, is going to concern a survey of the major secure boot options available.</p><h4>What is secure boot?</h4><p>I’m going to be slightly reductive and say secure boot is the process where a trusted piece of firmware verifies cryptographic signatures on every successive stage of booting. The firmware verifies the bootloader, and the bootloader verifies the OS.</p><h4>Raspberry Pi (In)Security</h4><p>While the Raspberry Pi is a <strong>superb</strong> educational tool and a great prototype platform, it provides absolutely no security. None. If there’s even a chance that a system compromise would have negative consequences with real-world fallout, it would be unethical to deploy the Raspberry Pi. Key takeaways, assorted notes, and what I mean by no security:</p><ul><li>The Raspberry Pi bootloader has no notion of authentication. If it finds bootcode.bin and start.elf on the SD card it’s going to boot from it. Similarly, if the unit has been programmed for USB boot it will try the network. If a TFTP server offers bootcode.bin and start.elf it will load those.</li><li>bootcode.bin and start.elf are, themselves, not authenticated. If someone reverse engineers these (currently closed source) they can control the boot process. Since Raspberry Pi technically boots the CPU from the GPU the CPU will start in a potentially unknown state.</li><li>There’s no way to specify the boot order. First thing found offering bootcode.bin and start.elf gets to dictate the rest of the process. SD card is always checked first.</li><li>The SoC (System on a chip) is the Broadcom BCM2837B0. All the security features that exist in the underlying ARM Cortex-A53 cores have been disabled in silicon. <a href="https://github.com/christinaa/rpi-open-firmware/issues/37#issuecomment-388551489">https://github.com/christinaa/rpi-open-firmware/issues/37#issuecomment-388551489</a></li><li>No TPM (trusted platform module) for key storage. Encrypting SD card is useless since it would have to contain the key in plain text for booting. Requiring a password 1) defeats the purpose of remote deployment and 2) lack of something like SOL (Serial over LAN) makes inputting it remotely difficult.</li></ul><p>What are the alternatives in the space? Does any single-board computer offer a compelling security story? As of this writing there are a few different competing specifications for implementing secure boot on ARM, or even x86, based architectures.</p><h3>The Options (Sort of Specification-wise)</h3><p>This list, while not exhaustive, covers the major options for securely booting a single board computer (SBC).</p><ul><li>ARM Trusted Firmware / Trusted Board Boot</li><li>High Assurance Boot (Freescale iMX SoCs only)</li><li>U-Boot (Sort of…)</li><li>UEFI Secure Boot</li></ul><h4>ARM Trusted Board Boot (TBB)</h4><p>Technically this is a thing, but in practice, it’s mostly just a document. ARM’s ecosystem, much like the Android ecosystem, is severely fragmented. ARM manufactures the Cortex series cores that are used in nearly every mainstream SoC available today. Despite those cores implementing the features required to support things like ARM TrustZone and TBB, they require cooperation from both the SoC manufacturer and the SBC manufacturer. The SoC manufacturer has to wire them in and integrate them correctly. The SBC manufacturer has to work with the SoC manufacturer to make sure their bootloader can initialize everything correctly and securely. As you’ll recall, above, I said the Broadcom SoC in the Raspberry Pi has mostly disabled the required security features.</p><p>Additionally, before you can have TBB, you must meet TBBR (Trusted Board Boot Requirements)… Which is another onerous specification. So assuming the manufacturer has done everything for TBBR, they can begin cloning+modifying ARM’s TrustedFirmware reference starting point <a href="https://github.com/ARM-software/arm-trusted-firmware">https://github.com/ARM-software/arm-trusted-firmware</a> . This reference spec is itself a living breathing thing, so unless a manufacturer is keeping their proprietary fork up to date, as pieces become available in the formal spec, the specific manufacturers firmware releases won’t support them.</p><p>A handful of manufacturers exist claiming to offer various levels of implementation of TBB like Xilinx, but finding out if a specific SBC has support is a documentation nightmare. The spec has been around for years, but unless people start clamoring for it, adoption looks like it will remain low. Matteo Carlini has a good presentation at Linaro Connect talking about the spec <a href="http://connect.linaro.org/resource/sfo17/sfo17-201/">http://connect.linaro.org/resource/sfo17/sfo17-201/</a> that also includes mentioning how UEFI (below) can co-exist with it.</p><p>Theoretically this specification allows for remote attestation provided that the ARM Trusted Firmware implementation sufficiently implements TrustZone. Unfortunately, given that it’s up to every individual manufacturer, this has to be evaluated on a case-by-case basis.</p><h4>High Assurance Boot</h4><p>First off, it’s a proprietary option made by Freescale (which merged with NXP and then purchased by Qualcomm, so maybe we’ll see it elsewhere?) and thus only works on boards using the i.MX SoC. Under the hood it works like most of the options out there- whatever you want to boot requires a signature that we validate before execution. What makes HAB nice is that the keys are write-protected behind one-time programmable (OTP) fuses and we can permanently fuse the keys to the board. Others might disagree, but I like this no-take-backsies approach.</p><p>Things I’m less fond of:</p><ul><li>the best reference site out there is actually a blog post from BoundaryDevices <a href="https://boundarydevices.com/high-assurance-boot-hab-dummies/">https://boundarydevices.com/high-assurance-boot-hab-dummies/</a> related to their Nitrogen series SBCs.</li><li>Proprietary toolchain for signing binaries.</li><li>No mention of a TPM so no clear strategy yet on remote attestation.</li></ul><h4>U-Boot (Sort of)</h4><p>I’m including this, despite it not being a specification, because there’s a handful of devices out there that basically make the pitch “you always have the option of compiling u-boot for your particular board and using that for secure boot.” Unless there’s a way to:</p><ul><li>permanently fuse your compiled version of u-boot with keys into something like onboard SPI flash</li><li>guarantee it’s the only boot option</li><li>make sure it always executes no matter what</li></ul><p>… then it’s not much better than the Raspberry Pi option. Secure boot is only viable if the attacker can’t replace the bootloader. This is why Apple pays a <a href="https://www.wired.com/2016/09/top-shelf-iphone-hack-now-goes-1-5-million/">$200K bug bounty on bootloader</a> vulnerabilities.</p><p>While it <em>can</em> use a TPM it doesn’t require it, so remote attestation remains tenuous.</p><h4>UEFI Secure Boot</h4><p>In my opinion this is the best option available today. It also has the added benefits of being the de-facto standard on servers for years as well as being the standard advocated for by several industry juggernauts (Microsoft, Intel, HP, etc). UEFI in general has been around for nearly 20 years and has a full ecosystem around it. I’m not sure when secure boot showed up specifically but it was common enough that in 2011 Microsoft was comfortable <em>mandating</em> it as a requirement for installing Windows 8.</p><p>Unfortunately, as far as SBCs go, it’s only implemented on a few very select boards, most of which are manufactured by Intel. This is because <a href="https://github.com/tianocore/tianocore.github.io/wiki/EDK-II">Tiano</a>, the reference UEFI implementation, is also made by Intel. One major thing to keep in mind: UEFI secure boot requires a TPM to verify the bootloader. So boards like BeagleBoard supporting EDK2/Tiano are available, but actually implementing all of secure boot requires some sort of a DIY TPM add-on.</p><h3>The Best Option So Far</h3><p>Is there a board out there that actually implements a reasonable security story? The best one I’ve managed to locate yet is the <a href="https://minnowboard.org/">Minnowboard Turbot</a>.</p><p>It’s manufactured by Intel and uses the reference Tiano/EDK2 UEFI firmware. Additionally, it supports the newer firmware TPM (fTPM) 2 specification so actually includes a proper chain for both making sure the board only boots what we want <em>and</em> verifying the firmware remotely afterward. Surprise surprise, an interesting side note on this one, it’s one of the few SBCs that actually <em>doesn’t</em> use ARM and uses <a href="http://ark.intel.com/products/78477/Intel-Atom-Processor-E3826-1M-Cache-1_46-GHz">Intel Atom E3826</a> or <a href="http://ark.intel.com/products/78475/Intel-Atom-Processor-E3845-2M-Cache-1_91-GHz">Intel Atom E3845</a> depending on version.</p><p>I’ve gone ahead and setup the dual-core <a href="https://minnowboard.org/minnowboard-turbot/technical-specs">Turbot</a> board. After working with the Raspberry Pi (which I still think is great!), the Turbot feels absolutely luxurious. It more or less boots and behaves like a rack mounted server thanks to the full UEFI implementation. Further, it doesn’t require any special steps in constructing boot media, so using the Ubuntu base server image on USB was seamless. Additionally, getting secure boot working with the fTPM, while not trivial, was at least straightforward.</p><h3>Next up!</h3><p>Next in the sequence I’ll talk about getting the Minnowboard’s UEFI secure boot process setup along with TPM basics so we can start building a closed chain of trust.</p><h3>Appendix &amp; Related Materials</h3><p>If you liked the above and want to see more examples and how they interrelate then this section is for you.</p><p><a href="http://connect.linaro.org.s3.amazonaws.com/sfo17/Presentations/SFO17-201%20Secure%20Boot%20on%20Arm%20systems.pdf">The raw slides from the Linaro Connect presentation</a></p><p>^^ Worth reading to get a grasp of how gnarly these specifications can be on the inside.</p><p><a href="https://source.android.com/security/verifiedboot/verified-boot">Android verified boot</a></p><p>^^ Though it mostly applies to handsets, the underlying tech is very similar. General purpose computers/servers are lagging behind what Android is doing in embedded security.</p><p><a href="https://community.arm.com/iot/embedded/f/discussions/7016/uefi-on-arm-v8-based-linux-embedded-system">UEFI and ARM living together discussion</a></p><p>^^ Solid discussion of how they live together and can support one another.</p><p><a href="https://conference.hitb.org/hitbsecconf2013kul/materials/D2T3%20-%20Job%20de%20Haas%20-%2020%20Ways%20Past%20Secure%20Boot.pdf">20 ways past secure boot</a></p><p>^^ Fun presentation by Job de Haas on how many ways you can do secure boot incorrectly and render it useless. Great survey of attacks.</p><p><a href="https://www.tianocore.org/getting-started.html">Tiano Core, getting started</a></p><p>^^ Provides a great starting place with TianoCore. Particularly interesting if you want to see how the sausage is made regarding UEFI.</p><p><a href="https://www.linuxjournal.com/content/take-control-your-pc-uefi-secure-boot">Take Control of Your PC with UEFI Secure Boot, Linux journal</a></p><p>^^ Provides an excellent discussion on the individual administrative steps of UEFI and how to do them with OpenSSL.</p><p><a href="https://www.slideshare.net/linaroorg/las16111-easing-access-to-arm-trustzone-optee-and-raspberry-pi-3">Easing access to ARM TrustZone OP-TEE and Rpi3</a></p><p>^^ Great presentation on the basics of ARM TrustZone and <a href="https://www.op-tee.org/">OP-TEE</a>. It’s a great set of educational slides but makes the usual caveats on slide 7 that because of implementation details, none of this is <em>actually</em> secure on RPi3.</p><p><a href="https://www.youtube.com/watch?v=lkFKtCh2SaU">Verified Boot: From ROM to Userspace</a></p><p>^^ Another excellent presentation. Marc Kleine-Budde discusses verified boot using HAB on a RioTBoard.</p><p><a href="https://www.youtube.com/watch?v=cyHGN72VMSc">Trusted Boot on the Olimex OLinuXino LIME2</a></p><p>^^ Getting trusted boot working with a DIY TPM by Merlijn Wajer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dfb171aedb3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Network Managed Raspberry Pis for a Shippable Datacenter]]></title>
            <link>https://medium.com/@squanderingtime/shippable-mini-datacenter-of-raspberry-pis-part-1-192f9877df3?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/192f9877df3</guid>
            <category><![CDATA[edge-computing]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Fri, 29 Jun 2018 16:58:27 GMT</pubDate>
            <atom:updated>2018-06-29T17:01:56.058Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<p>In a former life I spent a lot of time thinking about how to turn an empty room with chillers, some dark fiber, and a pallet of blank servers into a functioning production datacenter. Though I just tell people to use The Cloud anymore, applications that can’t use the cloud still exist. In particular, what about deploying temporary infrastructure into the world where either power or connectivity are disrupted or entirely unavailable? I made a small project of trying to find a way to create a small, shippable mini datacenter made from Raspberry Pi units that would be remotely manageable without having hands-on access. At $35 a unit this represents a landmark way to get a significant amount of server compute into a small physical footprint for temporary applications in remote locations.</p><h4>Technical Problem Statement</h4><p>The core problem in getting this idea to work is finding a way to install an operating system on a Raspberry Pi’s SD card without physically being able to touch the SD card, at least beyond initial prep work. Once the system is deployed, that’s it. Everything else needs to be done remotely including potentially upgrading the OS. I get around this by using a combination of Raspberry Pi’s relatively new net booting and introducing an intermediate stage bootloader (u-boot).</p><p>To power this we’re going to use a Netgear switch, simulate a management machine with my laptop, and a Raspberry Pi 3.</p><p>From here on out I’m going to switch focus to the nitty-gritty details. I’m going to call this how-to “intermediate to advanced” in difficulty. I try to be as explicit as possible, but it touches several fairly complicated Linux systems that each would be worthy of an explanatory article on their own. Additionally, if something is wrong, the symptom is “a thing without an OS isn’t starting up right.” And that’s a nightmare to debug. Further, it’s unlikely you’ll have the <em>exact</em> materials I use so you’ll have to reinterpret some of the sections to make it appropriate. Good luck, I believe in you!</p><h3>Outline</h3><p>The general flow is:</p><ul><li>We’re going to get a bootstrapping machine image setup for most required services.</li><li>Prep a Raspberry Pi for netbooting and installing raspbian lite so we can extract a first-attempt root filesystem off it.</li><li>Once netbooting is working, compile u-boot and introduce a new bootloader that gives us network control.</li></ul><h3>Bill of Materials</h3><p>Here’s a list of everything I’m using with versions as appropriate:</p><ul><li>VirtualBox 5.2.0 r118431</li><li>Ubuntu 18.04 “Bionic Beaver” minimal install ISO</li><li>Raspbian Stretch Lite 2018–06–27</li><li>Macbook Pro</li><li>Raspberry Pi 3</li><li>32GB SD Card <a href="https://www.amazon.com/gp/product/B0749KG1JK/ref=oh_aui_detailpage_o01_s00?ie=UTF8&amp;psc=1">https://www.amazon.com/gp/product/B0749KG1JK/ref=oh_aui_detailpage_o01_s00?ie=UTF8&amp;psc=1</a></li><li>Anker USB-C Gigabit ethernet adapter <a href="https://www.amazon.com/gp/product/B00ZZ6NW5E/ref=oh_aui_detailpage_o01_s00?ie=UTF8&amp;psc=1">https://www.amazon.com/gp/product/B00ZZ6NW5E/ref=oh_aui_detailpage_o01_s00?ie=UTF8&amp;psc=1</a></li><li>NETGEAR 5-Port Gigabit Smart Managed Plus Switch <a href="https://www.amazon.com/gp/product/B00HGLVZLY/ref=oh_aui_detailpage_o00_s00?ie=UTF8&amp;psc=1">https://www.amazon.com/gp/product/B00HGLVZLY/ref=oh_aui_detailpage_o00_s00?ie=UTF8&amp;psc=1</a></li></ul><h3>Bootstrapping Part 1: Creating a Management (Virtual) Machine</h3><p>We need a place to begin the operations. An image on a laptop or something that we can cart into a remote location and begin jumping additional machines.</p><h4>Setting up VirtualBox</h4><p>Create a new virtual machine for the project. I create one with:</p><ul><li>64 bit Linux</li><li>2GB of memory</li><li>1 processor</li><li>20GB dynamically expanding disk image</li><li>Bridged network adapter to my WiFi</li><li>USB 3.0 xHCI Controller</li><li>Fully capture the Realtek USB device (The Anker USB-C ethernet)</li></ul><p>Here are screenshots of the settings you’re less-likely to have ever modified if you use VirtualBox. None of this relies on special VirtualBox behavior so if you use a different virtualization system it should still work fine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zQyAbWRdljYlwoRSyiEAMw.png" /><figcaption>Network settings</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n270zDekncmHAbKhXtmPAA.png" /><figcaption>USB port settings</figcaption></figure><p>Attach the Ubuntu minimal install image to the virtual machine, power it up, and install the server basics. The specifics aren’t super important because I try to include all the specific packages needed. Just keep an eye on space. I named mine bootstrapper and the default user is chris.</p><h3>Bootstrapping Part 1a: (Optional) Renaming the network interface</h3><p>For completeness I’m going to include that I changed my USB-C ethernet adapter name. This is entirely optional. However, it’s a pain to refer to the USB interface as (in my case) enx00e04c011f13 instead of usbnet.</p><p>The easiest way to do this is get the MAC address of the USB adapter with ifconfig.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6JSEfWuZO1SDb9UPHtSGTw.png" /><figcaption>ifconfig output to get the physical MAC address</figcaption></figure><p>Create a custom rule for udev in /etc/udev/rules.d/ called 10-usb-nic.rules with:</p><pre>ATTR{address}==”00:e0:4c:01:1f:13&quot;, SUBSYSTEM==”net”, ACTION==”add”, NAME=”usbnet”</pre><p>Except replace my example ethernet address with the one from your system. Also of note, ATTR, SUBSYSTEM, and ACTION all have <strong>two</strong> equal signs to signal conditions, and the last one is a single one to signal an action (setting the name). It’s an easy thing to miss. Also, yes, the file must end in .rules. To apply the changes you need to trigger a change in udev with sudo udevadm trigger or just restart the VM.</p><h3>Bootstrapping Part 2: Creating our cleanroom network</h3><p>We’re going to create a brand new network that’s plugged into that USB-C ethernet adapter. Everything else will be hung off of that. My laptop is already on a 10.0.1.0/24 thanks to my wifi, so I’m going to create a new network as 10.10.10.0/24 so it’s easily distinguished. Edit the config in /etc/netplan/01-netcfg.yaml</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dNckE1OxoW13062KywfA8A.png" /><figcaption>Netplan config</figcaption></figure><p>I want the enp0s3 interface to dhcp against my wifi normally, but I want the usbnet interface to have a static address. It’s going to act as the router/gateway for this network as well. Make sure to not specify a gateway on this IP address or every time it comes up Linux will assign an ip default route through it and make most of your traffic mysteriously vanish.</p><p>Apply the configuration with sudo netplan apply. ifconfig should now look like the one from above in the interface renaming section.</p><p>Because this machine is acting as a router/gateway we’re also going to need to enable IP forwarding, otherwise Linux will not route packets from usbnet to enp0s3 and our internal network won’t be able to communicate out. Secondly, because 10.* is <a href="https://tools.ietf.org/html/rfc1918">normally non-routable</a> we need to enable iptables’s ip masquerade.</p><p>To see if IP forwarding is enabled: cat /proc/sys/net/ipv4/ip_forward. If it returns 0 it’s disabled, 1 if enabled. To enable it for this current session sudo sysctl -w net.ipv4.ip_forward=1 and to make it permanent edit /etc/sysctl.conf and add net.ipv4.ip_forward=1.</p><p>To enable IP Masquerade:</p><p>sudo iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE</p><p>The easy way to make this permanent is to install iptables-persistent and when it asks you to save the current rules, say yes.</p><h3>Bootstrapping Part 3: DHCP, TFTP, DNS services</h3><p>Next up! The Netgear switch could be configured to handle DHCP, but in order for us to participate in network bootloading we need to be able to control DHCP optional messages and provide tftp data services. Luckily, and maybe somewhat surprisingly given the name, dnsmasq combines both of these into a single package. Run sudo apt-get install dnsmasq.</p><p>You can replace the config at /etc/dnsmasq.conf with this example config:</p><pre>dhcp-range=10.10.10.2,10.10.10.254,255.255.255.0<br>log-dhcp<br>enable-tftp<br>tftp-root=/var/ftpd<br>pxe-service=0,&quot;Raspberry Pi Boot&quot;</pre><ul><li>dhcp-range controls what addresses our server will hand out. Since we’re using 1, and 255 is the broadcast, that leaves everything between 2 and 254.</li><li>log-dhcp will put verbose logging into /var/log/syslog so it’s easier to diagnose if something goes wrong</li><li>enable-tftp because we want to serve files via tftp on port 69.</li><li>pxe-service because we want to return all the optional DHCP headers to enable PXE booting.</li></ul><p>The server will fail to start if the ftpd directory does not exist. It’s possible you’ll need to create it: sudo mkdir -p /var/ftpd and make sure dnsmasq owns it sudo chown -R dnsmasq /var/ftpd</p><p>After updating the config restart dnsmasq via sudo service dnsmasq restart.</p><p>DNS services where this machine will act as a non-authoritative relay are already included in dnsmasq, so nothing additional to do there. Requests will be made according to the management machine’s default DNS.</p><h3>Intermission</h3><p>At this point you have a virtual machine that has all the services in place to bootstrap a new machine via PXE (or at least something PXE-like). The next several steps are going to switch gears and work on the pi. First we need to enable its netbooting features and then we need to extract all the boot pieces from the SD card and move them to the bootstrapping server.</p><h3>Raspberry Pi Prep Part 1: Installing Raspbian Lite</h3><p>I’m not going to cover the Raspberry Pi installation at great depth since they’ve put a significant amount of time in to documenting it well. The NOOBS installer is pretty great <a href="https://www.raspberrypi.org/downloads/noobs/">https://www.raspberrypi.org/downloads/noobs/</a> and only takes a few minutes.</p><p>At the end of this step you should have a working + bootable SD card that gets you to a shell. Enable OpenSSH server and make any other tweaks you normally would. Theoretically, when the pi is plugged into our lab network it should be able to DHCP just fine and connect out to the internet.</p><h3>Raspberry Pi Prep Part 2: Enable network boot mode</h3><p>Next up, we have to reconfigure the Pi to boot via the network. In order to do this we need to enable usb boot mode on the device. The official instructions are here, but it’s as simple as adding one line to a config file and rebooting.</p><p><a href="https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/msd.md">How to boot from a USB mass storage device on a Raspberry Pi - Raspberry Pi Documentation</a></p><h3>Raspberry Pi Prep Part 3: Extracting the boot pieces and mirroring root volume</h3><p>It’s time to get all the boot data from the pi and copy it to the bootsrapping machine. My Raspberry Pi is running on 10.10.10.126 for these examples. Assuming ssh is working from the management side this is pretty straightforward:</p><pre>scp -r pi@10.10.10.126:/boot ~<br>sudo cp ~/boot/* /var/ftpd</pre><p>On the Raspberry Pi we’re going to tar up the root volume and copy it over to the management machine. Quick install of rsync and make an nfs directory directly under root.</p><pre>sudo apt-get install rsync<br>sudo mkdir -p /nfs/client1<br>sudo rsync -xa --progress --exclude /nfs / /nfs/client1<br>cd /<br>sudo tar cf backup.tar nfs/</pre><p>I don’t bother compressing this backup because it takes a <em>long</em> time on pi. scp the backup.tar to the bootstrapping machine, move it to / and then sudo tar xf backup.tar. Make sure to do it as root to preserve the permissions of the original filesystem otherwise you’ll get some really funky behavior.</p><p>Once the files are extracted we need to edit /nfs/client1/etc/fstab and remove the references to /dev/mmcblk0p6 references or it won’t boot.</p><p>Aside: Because I’m sort of mixing+matching distributions of Linux without some sort of config management system, UIDs are not consistent across machines. Any file that’s owned by ‘pi’ on the Raspberry Pi is going to retain it’s UID on the management machine and suddenly appear owned as ‘chris’ my default user. This is “correct” in the technical sense but might look funny if you aren’t expecting it.</p><h3>Bootstrapping Part 4: Enable NFS</h3><p>Still more work to do on the management machine! Now that we have a mirrored copy of the pi’s root filesystem sitting at /nfs/client1 we need to enable NFS so it can be remotely mounted + booted.</p><p>Add the following line to /etc/exports</p><pre>/nfs/client1 *(rw,sync,no_subtree_check,no_root_squash)</pre><p>And enable the appropriate services</p><pre>sudo systemctl enable rpcbind<br>sudo systemctl restart rpcbind<br>sudo systemctl enable nfs-kernel-server<br>sudo systemctl restart nfs-kernel-server</pre><h3>Bootstrapping Part 5: Update /var/ftpd/cmdline.txt</h3><p>Everything is nearly in place to have rudimentary netbooting. We need to update /var/ftpd/cmdline.txt to refer to our new NFS root volume. The file should contain on a single line:</p><pre>dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=10.10.10.1:/nfs/client1,vers=3 rw ip=dhcp rootwait elevator=deadline</pre><h3>Intermission Again</h3><p>Whew. At this point, if you remove the SD card from the Raspberry Pi and plug it in, it <em>should</em> be able to boot from the network and get to a shell! If dnsmasq’s verbose logging was enabled you can check out /var/log/syslog and you should see DHCP activity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0r-ShD8tKPAmE-cpUYA1tA.png" /><figcaption>Example of DHCP next server, bootcode.bin and start.elf being served over tftp</figcaption></figure><p>You’ve earned a coffee. Go take a break. This is a long how-to.</p><h3>Dynamic Boot Choices Part 1: We need u-boot</h3><p>So as I said above, the real problem with remotely managing Raspberry Pis is how to dynamically update them <em>without</em> having your hands on them. We can’t pop the SD card in and out in this scenario. We’re going to need an intermediate bootloader that we’re going to be able to access a network with and make additional choices before bootstrapping the OS.</p><p>Back to the management machine.</p><p>First, because the management machine is x86_64 and our target machine is ARM, we’re going to need a cross compiler. Thankfully, Ubuntu packages one we can install:</p><pre>sudo apt-get install gcc-arm-linux-gnueabi build-essentials flex bison</pre><pre><br>git clone --depth 1 git://git.denx.de/u-boot.git u-boot/<br>cd u-boot</pre><p>We’re going to need to cross-compile a 32-bit version of u-boot specifically targeted toward a Raspberry Pi.</p><pre>export CROSS_COMPILE=arm-linux-gnueabi-<br>make rpi_3_32b_defconfig<br>make</pre><p>Now to do some re-arranging. Within /var/ftpd we’re going to:</p><ul><li>Rename kernel7.img to kernel7_32.img</li><li>Copy u-boot.bin from the build directory to kernel7.img</li><li>Make a new directory in here called pxelinux.cfg</li><li>chown everything so dnsmasq can read it</li></ul><p>Now, when the Raspberry Pi network boots it will load kernel7.img as usual, but instead of being a complete Linux kernel, it’s going to load u-boot instead. U-boot is going to know it got loaded via the network and will then magically begin to emulate PXELINUX giving us a much easier to control bootloader.</p><h3>Dynamic Boot Choices Part 2: PXE Linux config</h3><p>PXE Linux figures out what to do by searching the tftp directory for certain key files. The first file it’s going to look for starts with 01 (for the first physical network interface it could locate) and then the entire MAC address in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VZFsXaZwW5L1HMFwsWaVeQ.png" /></figure><p>My configuration is:</p><pre>menu title Working U-Boot Menu</pre><pre>#default NFSNetwork<br>default Local<br>timeout 3</pre><pre>label NFSNetwork<br> menu label Use NFS mount<br> kernel kernel7_32.img<br> append dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=10.10.10.1:/nfs/client1,vers=3 rw ip=dhcp rootwait elevator=deadline</pre><pre>label Local<br> menu label Use Local mount<br> kernel kernel7_32.img<br> append dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait</pre><p>What this says is wait for 3 seconds (in case a keyboard is plugged in and you want to override the choice) and then, depending on which label is specified under default, go ahead and try to boot that. Now our server is in charge of which path it’s going to take. If we want to make sure the machine boots via NFS, we can change the default and power cycle the device. You can also see the renamed original Raspbian kernel kernel7_32.img in the configuration.</p><p>Before we try booting this way though we have to tamper with both the boot and the recover volume on the SD card that’s sitting in the pi. If the boot firmware locates bootcode.bin and start.elf it’s going to try and perform a local boot. So I plugged the card into my laptop and renamed them to bootcode.disabled and start.disabled on both partitions. We want the boot partition to fail, but leave the EXT4 root file system intact for this to work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ui4-u_MxkMkTJhwWnvINiQ.png" /><figcaption>Example serving the PXELinux config and the renamed original kernel</figcaption></figure><h3>Moment of Truth: Installing an OS onto the SD Card</h3><p>All the pieces are finally in place. Set the pxelinux.cfg for the raspberry pi to netboot. We can run lsblk to confirm that none of the partitions are mounted or being used as a root FS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gx4ccFX6RclCHVxjXjVL0A.png" /><figcaption>lsblk output showing / is not local</figcaption></figure><p>In this example it auto-mounted /boot because it was present, but on my particular card it’s empty. Go ahead and unmount it so we have unrestricted access to /dev/mmcblk0.</p><p>I’ve also placed the Raspbian lite install image into the pi user’s home directory directly on the management machine (which is made easy because this is all NFS).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zmBaZCdbi_tHIuyjL55_Sg.png" /><figcaption>Raspberry Pi dd-ing the image into place on its own SD card</figcaption></figure><p>For convenience I’m going to mkfs over the fat partition just to make sure that whatever boot info was placed into that partition won’t be used so it has to netboot on startup.</p><pre>sudo mkfs -t vfat /dev/mmcblk0p1</pre><p>Go back to the management machine and set it to boot locally. At this point we also need to make one minor tweak. Because I used NOOBs to install the first time, and a raw image the second, the partition specified in the pxelinux.cfg directory needs to be updated. The local boot before was root=/dev/mmcblk0p7 and now needs to be root=/dev/mmcblk0p2. Restart the Raspberry Pi.</p><p>And voila! It correctly booted into its new OS which we installed on its own SD card via the network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yZjkVfxmyeZGFpq5gHtlRg.png" /><figcaption>Raspberry Pi booting locally w/ first-time boot tasks running</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DWreh2Q_0q6gm6nqvZ-xaA.png" /><figcaption>I didn’t enable SSH server before restarting…</figcaption></figure><h3>Future Direction</h3><p>I’m going to continue exploring this idea. At this point, because it really looks like any traditional management platform, we could do any number of things. Next up would be adding in a system like ansible or chef so we could write a basic image to the SD card and when it boots it begins secondary configuration tasks. A good example would be participating in something like a Kubernetes cluster.</p><p>Another interesting direction would be to try and create a management machine from an Intel NUC. Since the ideal deployment scenario is likely to be untrusted, there’s a ton of interesting work around SGX and platform trust to see if we could really lock down the management machine for security. Or for redundancy, create a pair of secure mirrored NUCs for fault tolerance.</p><h3>Bibliography &amp; Additional Reading</h3><ul><li><a href="http://www.raspibo.org/wiki/index.php?title=Raspberry_PI:_network_boot_explained">Raspberry PI: network boot explained - raspibo</a></li><li><a href="https://www.makeuseof.com/tag/network-boot-raspberry-pi-without-microsd/">How to Network Boot a Raspberry Pi Without a MicroSD Card</a></li><li><a href="https://netplan.io/examples">Examples | netplan.io</a></li><li><a href="https://blogging.dragon.org.uk/howto-setup-dnsmasq-as-dns-dhcp/">HOWTO: Setup dnsmasq as DNS DHCP - Beware Here Be Musings</a></li><li><a href="https://elinux.org/RPi_U-Boot">RPi U-Boot - eLinux.org</a></li><li><a href="http://www.tal.org/tutorials/raspberry-pi3-build-64-bit-kernel">Build 64-bit kernel for Raspberry Pi 3, using native tools</a></li><li><a href="https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/net_tutorial.md">Network boot your Raspberry Pi</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=192f9877df3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Toward a better technical interview]]></title>
            <link>https://medium.com/@squanderingtime/toward-a-better-technical-interview-d5bcdfb0351?source=rss-9d9be4a4b20d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5bcdfb0351</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[technical-interview]]></category>
            <dc:creator><![CDATA[Chris Chandler]]></dc:creator>
            <pubDate>Fri, 06 Apr 2018 19:32:35 GMT</pubDate>
            <atom:updated>2018-04-06T19:32:35.435Z</atom:updated>
            <content:encoded><![CDATA[<p>Technical interviewing is profoundly broken. The problem isn’t constrained to either the job seeking or the job hiring side. For those looking for a job it frequently boils down to little more than an algorithm lottery on how quickly you’ll spot the “ah ha” moment. On the hiring side it amounts to a mountain of weak signals and going through interview wrap ups with a lot of “I’m just not sure.” Luck is a considerable factor on both sides. The result is a tremendous amount of energy on all sides being wasted. Why is this the case though? Largely it’s a combination of ossified bad practices, lack of defining the skills we actually need, and a misunderstanding of what problem solving really is. This is about the concrete steps of interviewing, but that being said, we must take a large detour through the realm of problem solving to make it sufficiently coherent and relevant. Also, this is not about weeding out negative candidates faster- it’s about reducing false-negatives (people you should have hired but didn’t) and false-positives (people you did hire but shouldn’t have) through improved signaling and reduced guessing. Lastly, behavioral interviewing is also very important, but not the focus here.</p><h3>tl;dr — Abstract</h3><p>Ditch the whiteboard unless the candidate is drawing a block diagram to further a discussion. Clearly delineate the skills someone would need to succeed in the role. If candidates are leaving the interview and you feel like you’ve got weak signals, you’re asking useless questions or don’t understand the role. If the role involves coding and problem solving: laptop + dynamic problem solving is the only way to go.</p><h3>So you need to hire someone — Distilling need</h3><p>Let’s start at the top. I believe it is a fair statement to say we hire because there’s work to be done and not enough people to do it. Great. Since you have at least some rudimentary backlog of work and a future direction, you <em>should</em> have an understanding of what knowledge, skills, and competencies a person should have to achieve success in the role. Without this guiding light you have nothing to measure a candidate against.</p><p>If you’re hiring a developer, what kind of developer do you need? What degree of seniority? All too often companies implement a one-size-fits-all technical interview that applies the same rubric to a new college graduate, a self-taught individual, or someone with 15+ years of experience. This is a nonsense- the level of experience of the candidate will change the interview considerably. In order to calibrate these changes, we need to solidly know what it is we expect at different levels.</p><p>I chose my earlier words very carefully: knowledge, skills, and competencies. These are the paraphrased definitions from the Centre for European Research on Employment and Human Resources</p><ol><li>Knowledge is the information we acquired in the world. The combination of our capacity to learn and the opportunity to learn. It’s the background base level of information we need to perform a job. This is knowing a programming language, Photoshop is an image editor, or that DNS runs on port 53.</li><li>Skills are the specializations we acquire from experience when our knowledge intersects the opportunity to apply our knowledge. Applying programming to build systems, being able to paint in Photoshop, being able to diagnose DNS problems are all skills.</li><li>Competence is a more thorny one. The literature offers a less concise definition but offers a context-dependent: ‘characteristic of an individual that has been shown to drive superior job performance’ (Hartle 1995). It also frequently includes the different combinations of skills and their necessary level, alongside with the personality characteristics to achieve success. These are principally sussed out in behavioral interviews and thus not a key focus here.</li></ol><p>The key advantage of having a framework of capabilities and requirements is that we can now go step-by-step through an interview process and verify we are measuring the things we need clearly. At any given step we should clearly be able to articulate the knowledge or skill being scrutinized and why it’s being measured.</p><p>With actual job requirements in hand, let’s talk about the big three of bad signaling: whiteboard problem solving, whiteboard coding, and architectural medley.</p><h3>Whiteboard Problem Solving and Why It’s Worthless</h3><p>The most odious first. I don’t know anyone that feels this particular whiteboard segment of a technical interview is worth anyone’s time. Yet they are ubiquitous. For the interviewer it’s usually boring and routine, and for the interviewee it’s usually little more than a game of chance. If you’re not familiar it usually goes like this:</p><blockquote>“Ok. This is going to be the problem solving part of the interview. I’m going to give you a problem and I want you to think about it, come up with a solution, and then write some code to actually do it. Here’s the first step: consider a list of integers. They might be positive or negative. How can you most efficiently determine that any three of them sum to zero?”</blockquote><p>Assuming you get the first one right (they’re almost always broken into an ‘easy’ step and ‘hard’ step).</p><blockquote>“Ok, great. How about this: given the same list of integers, can you determine the greatest monotonic subsequence? So if you have 1, 10, 2, 3, 6, 4, 5. You would pick 1, 2, 3, 4, 5.”</blockquote><p>Take a look at your list of knowledge, skills, and competencies. Which of the three is this <em>actually</em> measuring? This segment will almost certainly be said to assess one’s “problem solving ability” or “CS fundamentals.” In practice, this is largely inaccurate and amounts to little more than guessing. Real world problem solving is an order of magnitude more difficult, and as far as CS fundamentals go it’s just seeing if you dusted off your algorithm book from your college program. I will more rigorously demonstrate why this is not useful problem solving, but I’m going to let this quote from Lazlo Block, SVP of People at Google, from a 2013 New York Times interview say it first:</p><blockquote>“On the hiring side, we found that brainteasers are a complete waste of time. How many golf balls can you fit into an airplane? How many gas stations in Manhattan? A complete waste of time. They don’t predict anything. They serve primarily to make the interviewer feel smart.”</blockquote><p>I argue that the previous two problems <em>also</em> solidly fall in this category. How many times have I needed a way to check if three integers sum to zero? None. How many times in my career have I needed a monotonic subsequence of integers? None. How many times have I needed a combinatoric solution to <em>anything</em>? Very, very few. Surely though Google finds these useful since they’ve done a solid job of popularizing the algorithms/problem-solving approach? Surely in all their interviews they found something diagnostic?Lazlo Block again:</p><blockquote>“We looked at tens of thousands of interviews, and everyone who had done the interviews and what they scored the candidate, and how that person ultimately performed in their job. We found zero relationship. It’s a complete random mess, except for one guy who was highly predictive because he only interviewed people for a very specialized area, where he happened to be the world’s leading expert.”</blockquote><p>How is it possible that with tens of thousands of interviews they were unable to establish a relationship between the interview and on the job performance? I argue it’s because this interview technique has no bearing on any actual problem solving in the field. We require a brief analysis on actual problem solving to drive this home.</p><h4>Actual Problem Solving?</h4><p>Whiteboard problem solving has two critical shortcomings: it’s purely static, and they have no gradations of success. They don’t change over time and the problem is either solved or it isn’t. Problem solving, especially as far as the literature is concerned, is broken down into two major varieties: static and dynamic. If all the information necessary to solve the problem is available from the outset, and you’re only applying previous knowledge, then by definition it’s a static problem. In fact, even the experts writing the measurement and assessment tools have stated that (1) both pencil and paper are insufficient for dynamic problem solving analysis, and (2) that domain-specific knowledge can actually harm results (different pre-existing mental models)[die-bonn]. A serious impedance mismatch is in play- what nearly every employer is actively seeking is dynamic problem solving capability. The distinction is explained here in “The Assessment of Problem-Solving Competencies”:</p><blockquote>In the first case [static], all problem-related information is available upfront, and the problem situation does not change over time. In the case of dynamic problems, the problem state changes and develops with time and through the respondents’ actions. So actually, dynamic problems are much closer to typical everyday-like problem situations — in a dynamic problem situation some aspects of the problem may aggravate over time whereas others may simply disappear. Static problems are suitable for measuring analytical problem-solving skills; dynamic problems tap a mixture of analytical, complex and dynamic problem-solving abilities.</blockquote><p>That latter half sounds much, much closer to how a software engineer actually spends the day.</p><p>Onward to the flaw of its black and white nature. The candidate either does, or does not solve the problem. In wrap-ups and feedback sessions it’s quite common to see comments extrapolating the <em>speed</em> at which an individual solves a problem as an indicator of their overall problem solving capability. This relationship is both unfounded and unreplicable. Secondarily, static problem solving recognizes at least four distinct levels of capability [Reeff et al., 2005, p. 202]:</p><ol><li><strong>Content-related reasoning</strong>: Achieving limited tasks based on practical reasoning.</li><li><strong>Evaluating</strong>: Rudimentary systematic reasoning. “Problems at this level are characterized by well-defined, one-dimensional goals; they ask for the evaluation of certain alternatives with regard to transparent, explicitly stated constraints. At this level, people use concrete logical operations.”[die-bonn]</li><li><strong>Ordering/integrating</strong>: “…people will be able to use formal operations (e.g. ordering) to integrate multidimensional or ill-defined goals, and to cope with non-transparent or multiple dependent constraints”[die-bonn]</li><li><strong>Critical Thinking</strong>: “At the final and highest level of competency, people are capable of grasping a system of problem states and possible solutions as a whole. Thus, the consistency of certain criteria, the dependency among multiple sequences of actions and other “meta-features” of a problem situation may be considered systematically. Also, at this stage people are able to explain how and why they arrived at a certain solution. This level of problem-solving competency requires a kind of critical thinking and a certain amount of meta-cognition.”[die-bonn]</li></ol><p>Take special notice of the wording in levels 3 and 4: multidimensional, ill-defined, non-transparent, multiple dependent constraints, multiple sequences, meta-cognition. At best these problems analyze a combination of early computer science classes with static capabilities at no higher level than ‘evaluating’ competency. The skill ceiling is simply too constrained to be diagnostic. It’s not indicative of real world problems, and it’s not even capable of fully measuring the thing it ostensibly is supposed to. Dynamic problem solving as an alternative will be demonstrated in the better options below, but first, let’s finish wrapping up the bad options.</p><h3>Whiteboard coding</h3><p>This is as ubiquitous as “problem solving” but doesn’t require anywhere near the level of analysis. Nobody codes this way. No one. At best it’s a “because we’ve always done at this way,” and at worst it’s an intimidation tactic.</p><p>A programming language is a directly measurable piece of knowledge. Actual programming is a directly observable skill.</p><p>There’s no reason to have someone write code by hand on a whiteboard. Expecting syntactic and lexical correctness in this circumstance is veiled hostility. Tens of thousands of hours have been poured into the tooling surrounding software development to make the process less error-prone, easier, and more efficient. If someone is a career Java developer and used to having IntelliJ, then let that person use IntelliJ . The skill of programming is inescapably connected to its ecosystem of tooling.</p><h3>Architectural Surprise</h3><p>I should start this with I actually like architectural interviews. These usually involve drawing numerous block diagrams on a board and explaining how pieces of a more complex system fit together. What I don’t like are architectural interviews where the system being architected is previously <em>unknown</em> to the candidate. “Build a thing you’ve never built at a ridiculously high level in front of strangers with only a cursory technical feedback loop.”</p><p>Theoretically this is because the interviewer wants to see how the interviewee approaches something novel and apply architectural skills in a vacuum. The problem is it just doesn’t work this way in reality. If you were building something new it would be done over months to years and involve tremendous amount of research and input from the business, other engineers, planners, etc. It’s a very convoluted feedback loop. In fact, nearly every large, complicated system I’ve ever worked on has been massively influenced by “soft” factors like how much slack was available on other teams, legal &amp; regulatory frameworks, hardware constraints, etc.</p><h3>Toward A Better Technical Interview</h3><p>So what does a <em>good</em> interview look like? A good interview should allow the candidate to showcase their knowledge, skills, and experience in the best light possible (which will also expose competencies) and allow you to compare it to your actual needs. No one should leave the interview with an ambiguous feeling. It <em>absolutely</em> requires a degree of tailoring to the experience level of the candidate. Calibrate success criteria around knowledge and skills accordingly (see section on bias), make sure the interviewers know it, and especially, make sure the candidate knows it. Nobody likes walking in blind.</p><h4>Assessing Knowledge and Skills</h4><p>Knowledge assessment is made fantastically more difficult than it needs to be. Literally talk to the candidate. There’s no need to game the information, hit them with a surprise, or suss it out by proxy. Well-established rubrics of understanding exist. Apply them as consistently as possible. If you need a starting place, albeit a pedantic one, I’d recommend <a href="https://en.wikipedia.org/wiki/Bloom%27s_taxonomy#The_cognitive_domain_(knowledge-based)">Bloom’s Taxonomy</a>. Here’s an example of the six levels of understanding for a job that requires some degree of Linux package management knowledge:</p><ol><li><strong>Remembering</strong>: Being able to remember elementary facts in a category. “Name a Linux package manager.”</li><li><strong>Comprehending</strong>: Compare two elements at a high level. “Compare CentOS’s to Ubuntu’s.”</li><li><strong>Applying</strong>: Applying previous knowledge to a new piece of external information. “Would CentOS’s package management make sense given this rollout strategy?”</li><li><strong>Analyzing</strong>: Break information into component parts and determine interior relationships. “Compare and contrast modern Linux package management. Provide specifics.”</li><li><strong>Synthesizing</strong>: Building a structure from diverse patterns and putting parts together to form a whole. “How would you propose managing a package release system for a diverse fleet of Linux systems?”</li><li><strong>Evaluating</strong>: Defending opinions by making a judgement of internal evidence combined with external criteria. “What package management + release system would you recommend based on our needs.”</li></ol><p>An example interview that I find particularly useful is asking a candidate to draw the architecture of a system they worked on or built (This double-dips as a skill question!). With that drawing in place, and focusing on your particular hiring needs, begin going through this sort of taxonomy approach about how much detail the candidate can provide about any specific piece.</p><blockquote>What factors lead to this choice? You used JSON, can you think of other alternatives that would have also worked? Given those alternatives do you believe this one was the best? Knowing what you know now, would you make that same choice again?</blockquote><p>The more senior the candidate, the more nuanced and specific the information should be, as well as being cognizant of external softer factors. A junior candidate knows of things and can discuss them, a senior candidate contextualizes, compares, and evaluates under changing criteria. Wash, rinse, repeat for all the skills you need.</p><p>Be sure to focus on the interconnectedness of capabilities: it’s possible to bullshit successfully about a single skill, it’s much harder to bullshit about a constellation of related skills. If you aren’t seeing evidence of a particular skill, then ask the candidate directly. Don’t leave the interview believing that if it didn’t come up that they don’t know about it.</p><h4>Assessing skills + Actual Problem Solving</h4><p>Seat your candidate in front of a computer and have them use it. All the technical skills we need day-to-day are directly observable. Softer skills can be more difficult to assess, but I find forcing the candidate to engage in communication will surface most of the behavioral problems over the course of a day. There’s no need to come up with some tricky scenario. If git is a required skill, make the candidate use git. It might take more than one problem to cover your bases, but that’s OK too. If you require a burdensome number of skills, maybe reevaluate the role. Stay away from algorithm problems for all the previously stated problems with static, low-ceiling, domain-specific problem solving. I like to think of this guideline this way : you want the complexity to be within the problem, not the solution. The sweet spot for exploring skills, in particular problem solving, is to come up with a fairly generic <em>dynamic</em> problem that incorporates as many other requirements as possible. So what makes a good dynamic problem? Let’s circle back to the promised discussion of dynamic problems.</p><h4>Dynamic Problem Solving and My New Favorite Questions</h4><p>Dynamic problem solving has two phases [die-bonn]:</p><ul><li>Knowledge acquisition</li><li>Knowledge application</li></ul><p>The problem should begin with a phase of learning how a system works, and then based upon that understanding, manipulate a set of exogenous variables the user can control to get a set of endogenous variables to a goal state. It’s couched in fancy language, but this is about the most perfect academic explanation of debugging I’ve ever heard. Consider this frequent refrain:</p><blockquote>Huh. That’s weird. We deployed my code to staging but it’s behaving differently than on my laptop. Now I’m going to spend the afternoon figuring out what’s different. I know the framework makes some environmental choices, but I thought those were accounted for. Is the problem in my code, the library code, my configuration, or something in the environment?</blockquote><p>This combines knowledge acquisition (what’s going on?), with exogenous variables (my code + configuration), endogenous variables (the environment + framework), and the potentially extraordinarily complicated hidden relationships between them.</p><p>The best example of how to simulate this without any computer domain knowledge at all in the literature is actually so brilliant I’m going to suggest its usage here:</p><blockquote>Set the temperature and humidity of a pretend room based on three unlabeled sliders. Every time you make a change the graphs for temperature and humidity will be updated for a given time t. Make the room comfortable and explain the relationship between each slider and the room.</blockquote><p>The language is very straightforward, a problem we’ve all dealt with, and relies on no special information. It’s essentially debugging the room temperature. Behind the scenes though this is a highly tunable and randomly generable problem. Consider this less-showy incarnation of a similar example from the DYNAMIS computer-based assessment [Blech].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*jiTveo2WpBaN6NLZXpcTmA.png" /></figure><p>The user is in control of A and B, and the user can see the output of Y and Z. None of the edges connecting the variables or their values are known. In order to get Y and Z into a goal state the user would have to uncover the following relationship types:</p><ol><li>Direct simple effect: B has a direct impact on Z.</li><li>Multiple effect: A influences Y and Z.</li><li>Multiple dependency: Z can be influenced by both A and B.</li><li>Eigendynamics: Z can modify itself.</li><li>Side effects: Y can modify Z.</li></ol><p>Here’s why I love this problem: even if you’ve solved one instance of this, it won’t help you with another. The complexity is embedded within the problem, not the answer. This is much more like a game that you and a candidate can pair on which also helps prevent interviewer fatigue. Move it behind an API server, and build a client to interact with it. Build more tools if you think it will help. If you solve an easy instance, generate a new one and do that one. The problem is essentially the same as a generic differential equation solver, so the expectation definitely isn’t on finding a working strategy, but rather by making it usable for a human and assessing needs. If the candidate is fully prepped on the problem, then great, turn up the difficulty! If they display expert level ability to tease apart variables, can code a client + assistive tooling, and have all the requisite knowledge from above then you should have <strong>very</strong> <strong>strong</strong> positive signals.</p><p>Additionally, numerous options exist to make this easier or harder:</p><ol><li>Number of variables</li><li>Number of relations</li><li>Random components: Hidden variables influencing endogenous variables in non-systemic ways. (Have you ever had a system experiencing heat related failure? It’s a <em>nightmare</em> the first time you encounter it.)</li><li>Delayed effect: Think propagation delay in relationships.</li><li>Time windowing + no reset: Limit the number of steps the user has or don’t allow the system to be reset.</li><li>Transparency: How much of the system do you reveal at the beginning.</li></ol><h4>Known Architecture</h4><p>I’m only going to modify this slightly from the version I dislike. I prefer having candidates draw the architecture of a system they <em>know well</em>. I believe this is significantly more instructive than a surprise choice.</p><ol><li>It uncovers the extend to which they can explain something they worked on daily for an extended period of time.</li><li>You can ask “what was the hardest part of this for you?” You can explore whether it was a based on technical difficulty or <em>organizational</em> difficulty. Organizational difficulty is a fantastic springboard for a lot of behavioral questions. This also makes it easy to lead into “What would you do differently without that constraint?”</li><li>People fall back on what they know in rough situations or under duress. This is particularly important if your organization hasn’t quite dialed in its mentorship and the candidate will be flying solo. If you can find out a large system someone is proud of, you can get a window into what they will likely build again given free reign and tight deadlines. But like I said above, just ask too: “Would you use these patterns again if given the opportunity?”</li></ol><h3>Conclusions</h3><p>There are no panaceas for technical interviewing. There isn’t a perfect solution and nothing will work for 100% of all companies all the time. That being said, I believe we can definitely do far better. The key takeaways</p><ul><li>Understand the role you’re hiring for by making sure the knowledge and skills are both enumerable and measurable.</li><li>Unless you’re in the middle of an architectural discussion or the candidate needs a diagram to clarify, no whiteboards.</li><li>Nothing beats having the candidate use a real computer.</li><li>Minimize the surprises and let the candidate play to their strengths- you would want this if they were an employee anyway.</li><li>Simple problems with complex solutions will bore your interviewers and they aren’t indicative anyway.</li><li>Favor dynamic over static problems.</li></ul><h3>Footnote A: On Bias</h3><p>I would be remiss to write this much on hiring without offering a note on bias. Much has been written elsewhere and I absolutely believe that marginalized groups are treated unfairly in the hiring process. My minor contribution to this discussion is to treat knowledge and skills as things a person has, and not the place where they came from. I believe that the industry engages in classist, ageist, college-centric hiring practices to the detriment of us all. Hire people that know what they’re doing and stop worrying about Big-O notation.</p><p>Secondly, much of the literature clearly states that both knowledge (requires opportunity to learn) and skills requires (opportunity to apply knowledge). The result is that both of these are social constructs. You will always have the inherent biases of the interviewers and your corporate culture to contend with which is why fair grading and honesty are critical.</p><p>This is honestly worthy of its own field of study and I welcome additional notes.</p><h3>Footnote B: On “CS Fundamentals”</h3><p>Can we <em>please</em> just stop using this phrase? I graduated from an accredited CS program and the coursework included: discrete math, calculus, linear algebra, programming, theory of language, theory of computation, algorithms 1, algorithms 2, advanced algorithms, digital signal processing, operating systems, computer architecture, networks, software engineering, and the list goes on for a while. When we say “CS fundamentals” we almost always end up targeting about a week’s worth of lectures somewhere in a freshman/sophomore year program. Especially on algorithms you shouldn’t be implementing. Calling this tiny amount of information “CS fundamentals” is phenomenally disingenuous.</p><h3>Bibliography</h3><p>Hartle, F. (1995) How to Re-engineer your Performance Management Process, London: Kogan Page.</p><p>Blech, Christine &amp; Funke, Joachim. (2005). Dynamis review: An overview about applications of the Dynamis approach in cognitive psychology <a href="https://www.researchgate.net/publication/228353257_Dynamis_review_An_overview_about_applications_of_the_Dynamis_approach_in_cognitive_psychology">https://www.researchgate.net/publication/228353257_Dynamis_review_An_overview_about_applications_of_the_Dynamis_approach_in_cognitive_psychology</a></p><p><a href="https://www.die-bonn.de/esprid/dokumente/doc-2006/reeff06_01.pdf">https://www.die-bonn.de/esprid/dokumente/doc-2006/reeff06_01.pdf</a> The Assessment of Problem-Solving Competencies</p><p><a href="https://www.nytimes.com/2013/06/20/business/in-head-hunting-big-data-may-not-be-such-a-big-deal.html">In Head-Hunting, Big Data May Not Be Such a Big Deal</a></p><p>Reeff, J.-P./Zabal, A./Klieme, E. (2005): ALL Problem Solving Framework. In: Murray, T. S./Clermont, Y./Binkley, M. (2005): International Adult Literacy Survey. Measuring Adult Literacy and Life Skills: New Frameworks for Assessment. Ottawa</p><p>Bloom’s Taxonomy on Wikipedia <a href="https://en.wikipedia.org/wiki/Bloom%27s_taxonomy#The_cognitive_domain_(knowledge-based)">https://en.wikipedia.org/wiki/Bloom%27s_taxonomy#The_cognitive_domain_(knowledge-based)</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5bcdfb0351" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>