<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Hacking on William Floyd (low-quality images)</title>
    <link>https://w-floyd.com/categories/hacking/</link>
    <description>Recent content in Hacking on William Floyd</description>
    <generator>Hugo</generator><language>en</language><managingEditor>William Floyd</managingEditor><webMaster>William Floyd</webMaster><lastBuildDate>Fri, 08 Jan 2021 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://w-floyd.com/categories/hacking/index.low.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Analysis of a 2005 Nissan Altima Remote Keyfob</title>
      <link>https://w-floyd.com/2021/01/nissan-keyfob/</link>
      <pubDate>Fri, 08 Jan 2021 00:00:00 +0000</pubDate><author>William Floyd</author>
      <guid>https://w-floyd.com/2021/01/nissan-keyfob/</guid><description>&lt;p&gt;I got my first car a few months ago - a decidedly beat up North American 2005 Nissan Altima.&#xA;It came with a remote keyfob, but something was shorting internally, and the battery would drain within a matter of hours.&#xA;I ordered a two-pack of aftermarket fobs from Amazon, paired them no problem, and that was that.&lt;/p&gt;&#xA;&lt;p&gt;After a while though, I got to thinking, how might I connect my car to my Home Assistant system?&#xA;I am reluctant to tap into the CAN bus directly, so instead I am going to investigate utilizing the same method as my remote fob. Specifically, I want to program my own &amp;ldquo;fob&amp;rdquo; using an Arduino and a RF transmitter (spoiler: I cannot, at least for now).&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;h1 id=&#34;the-hardware&#34;&gt;&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#the-hardware&#34;&gt;The Hardware&lt;/a&gt;&#xA;&lt;/h1&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/fob/opened-4032.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/fob/opened-400.avif&#34; alt=&#34;Opened remote&#34; title=&#34;Opened remote&#34; width=&#34;4032&#34; height=&#34;3024&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;p&gt;While I may analyze the original fob at some point, for the time being I shall work from the aftermarket fob.&#xA;Opening the casing reveals a rather simple circuit (&lt;a href=&#34;media/fob/pcb_front-4032.avif&#34; &gt;front&lt;/a&gt;, &lt;a href=&#34;media/fob/pcb_back-4032.avif&#34; &gt;back&lt;/a&gt;) - battery contacts, four buttons, a smattering of passives, an oscillator, the main control chip, 8 test points, and an antenna trace running around the perimeter of the PCB.&lt;/p&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/fob/closeup-4032.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/fob/closeup-400.avif&#34; alt=&#34;Closeup&#34; title=&#34;Closeup&#34; width=&#34;4032&#34; height=&#34;3024&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;p&gt;Rather unhelpfully, the control IC is unmarked, so either I&amp;rsquo;ll need to wait until I can look at the original fob to find any clues, or try to find what I need online.&lt;/p&gt;&#xA;&lt;p&gt;As a note, it should be easy enough for me to replace the buttons with an electrical solution controlled by an ESP8266 or similar - I may end up doing this some day.&#xA;For the time being, however, I have nothing to glean from the hardware in my fob.&lt;/p&gt;&#xA;&lt;h1 id=&#34;research&#34;&gt;&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#research&#34;&gt;Research&lt;/a&gt;&#xA;&lt;/h1&gt;&#xA;&lt;p&gt;A quick look at the Amazon listing for my fob already tells me what models of fobs it replaces: KBRASTU15, CWTWB1U758, and CWTWB1U821.&#xA;Matching other listings, my specific model is the KBRASTU15.&#xA;This is actually an FCC ID, so that&amp;rsquo;s my next lead.&lt;/p&gt;&#xA;&lt;p&gt;This &lt;a href=&#34;https://fccid.io/KBRASTU15&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;fccid.io&lt;/a&gt; listing is rather useful, providing original FCC images and documents.&#xA;Unfortunately, the &lt;a href=&#34;https://fccid.io/KBRASTU15/Internal-Photos/Internal-Photos-140601.pdf&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;internal images&lt;/a&gt; are low enough resolution to prevent reading the IC silkscreen.&#xA;Interestingly, the aftermarket fob has a small fraction of the part count of the original fob, while still functioning perfectly.&#xA;The most useful available document is the &lt;a href=&#34;https://fccid.io/KBRASTU15/Operational-Description/Technical-Description-139545.pdf&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Technical Description&lt;/a&gt;.&#xA;This is where we start to get somewhere.&lt;/p&gt;&#xA;&lt;p&gt;In essence, the fob emits a wakeup sequence &amp;lsquo;A&amp;rsquo;, followed by sequence &amp;lsquo;B&amp;rsquo; repeated as long as the button is pressed.&#xA;The structure of these sequences is also described - sufficient to say, it uses a rolling code system.&#xA;Importantly for my analysis, the encoding method of the signal is given (though interestingly their diagram annotations seem to be incorrect).&lt;/p&gt;&#xA;&lt;p&gt;With this information in hand, I ordered a cheap RTL-SDR (a Nooelec NESDR Mini 2+).&lt;/p&gt;&#xA;&lt;h1 id=&#34;sdr-analysis&#34;&gt;&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#sdr-analysis&#34;&gt;SDR Analysis&lt;/a&gt;&#xA;&lt;/h1&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/4_locks.webp&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/4_locks.webp&#34; alt=&#34;4 Presses of the Locking Key&#34; title=&#34;4 Presses of the Locking Key&#34; width=&#34;1210&#34; height=&#34;240&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;p&gt;The radio, being a North American model, operates at 315MHz.&#xA;Using Universal &lt;a href=&#34;https://github.com/jopohl/urh&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Radio Hacker&lt;/a&gt;, I began capturing examples of locking and unlocking signals.&#xA;Using the software is outside the scope of this post, but I found some YouTube videos by the software author that proved to be useful - it&amp;rsquo;s not hard to learn to use.&lt;/p&gt;&#xA;&lt;p&gt;Ultimately, I ended up trimming down 4 &amp;lsquo;B&amp;rsquo; sequences each of locking and unlocking (that is, different presses, not repeats during the same press).&#xA;I also opted not to include the preamble and header of these &amp;lsquo;B&amp;rsquo; sequences, as these are the same for any fob and include no actual information.&lt;/p&gt;&#xA;&lt;p&gt;The resulting signals varied in length and followed no apparent repeating format - this is where the encoding scheme described in the FCC documents comes in.&#xA;Fortunately, URH allows specifying and chaining encoding schemes, as well as calling external software to decode the data.&#xA;As I am not dealing with a large amount of data, I wrote a quick bash script to decode the data:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;#!/bin/bash&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;lc&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;while&lt;/span&gt; IFS&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; read -r -n1 c; &lt;span style=&#34;color:#66d9ef&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;c&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                break&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;c&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; !&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;lc&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;lc&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; !&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                echo -n &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;lc&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#75715e&#34;&gt;# Deal with the last character&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                lc&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;c&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;elif&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;lc&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;c&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;c&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;0&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        echo -n &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;1&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        echo -n &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;0&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                lc&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;elif&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;lc&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;==&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;; &lt;span style=&#34;color:#66d9ef&#34;&gt;then&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                lc&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;c&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;fi&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;done&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;1&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;exit&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This does the trick, and all the data has a uniform length of 67 bits.&#xA;While the document specifies 66 bits, perhaps the aftermarket keyfob adds an extra bit.&#xA;In any case, this extra trailing bit is always 0.&lt;/p&gt;&#xA;&lt;p&gt;Finally we have something like this:&lt;/p&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/decoded.webp&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/decoded.webp&#34; alt=&#34;Decoded data&#34; title=&#34;Decoded data&#34; width=&#34;1831&#34; height=&#34;271&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;p&gt;The top four entries are when locking, the bottom four when unlocking.&#xA;The highlighted segments from left to right, as per the technical document, are:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;encrypt&lt;/li&gt;&#xA;&lt;li&gt;serial number&lt;/li&gt;&#xA;&lt;li&gt;function code&lt;/li&gt;&#xA;&lt;li&gt;verify code&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;It can easily be seen how the intent of the button press is not encrypted, but is part of the function code near the end.&#xA;Also, the serial is correctly defined, as it does not change at any point.&#xA;I am not sure what the verify bits are present for - perhaps if an error occurs the encoding scheme would result in a non 0 result (though this is purely speculation).&lt;/p&gt;&#xA;&lt;p&gt;What we know now is that the keyfob does indeed use a rolling code algorithm, though not which one (web searches do not seem to specify).&lt;/p&gt;&#xA;&lt;h1 id=&#34;more-research&#34;&gt;&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#more-research&#34;&gt;More Research&lt;/a&gt;&#xA;&lt;/h1&gt;&#xA;&lt;p&gt;I do not have access to the original keyfob at this time, so some image searching may be in order.&#xA;Several leads appeared, but the main one was this:&lt;/p&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/research/alt_2-1044.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2021/01/nissan-keyfob/media/research/alt_2-400.avif&#34; alt=&#34;Pre-owned OEM fob&#34; title=&#34;Pre-owned OEM fob&#34; width=&#34;1044&#34; height=&#34;806&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;p&gt;None of the text appears especially legible, so the first thing I can do is compare the logo on the OEM fob to existing rolling code chip manufacturers.&#xA;As it happens, Microchip is the company in question, producing the widely documented KeeLoq product line (&lt;a href=&#34;http://keeloq.narod.ru/decryption.pdf&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;leaked spec sheet&lt;/a&gt;).&#xA;Looking at their product lines, it becomes clear that the original fob uses the HCS361 chip.&#xA;My aftermarket chips must be using a knockoff or unmarked version of this.&lt;/p&gt;&#xA;&lt;p&gt;Hurray, we know what chip we&amp;rsquo;re up against, what algorithm it uses, and how to get the information of an existing fob.&#xA;What we do not know is how to program our own chip (or software equivalent).&#xA;This is where things get a lot more involved than I have the expertise to do.&lt;/p&gt;&#xA;&lt;p&gt;What would be required would be the Nissan manufacturer code for this series of fobs.&#xA;Try as I might, these do not seem to have leaked online, nor have any other manufacturers as far as I can tell.&#xA;Speculating, perhaps those that have access to these codes either keep them to themselves for ethical reasons, or because there is financial incentive to keeping this information private.&#xA;Clearly there are Chinese manufacturers who know what this key is, because it would have been required in order to program this fob.&lt;/p&gt;&#xA;&lt;h1 id=&#34;key-problem&#34;&gt;&#xA;  &lt;a class=&#34;heading-link&#34; href=&#34;#key-problem&#34;&gt;Key Problem&lt;/a&gt;&#xA;&lt;/h1&gt;&#xA;&lt;p&gt;So how might I find this manufacturer key?&#xA;Curiously, I cannot even find reference to Nissan ever using KeeLoq, so that does not bode well.&#xA;Trawling the recent NA Nissan git leak doesn&amp;rsquo;t reveal anything related to such a key.&#xA;The consensus seems to be that a &lt;a href=&#34;https://link.springer.com/chapter/10.1007/978-3-642-02384-2_25&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;power analysis&lt;/a&gt; of the receiver is required to determine the manufacturer key.&#xA;While apparently not difficult for the researchers, it is beyond my means at this stage.&#xA;I am certainly &lt;a href=&#34;https://crypto.stackexchange.com/questions/61297/getting-a-keeloq-manufacturer-key&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;not&lt;/a&gt; &lt;a href=&#34;https://reverseengineering.stackexchange.com/questions/11988/question-about-keeloq-a-car-remote-control-standard&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;the&lt;/a&gt; &lt;a href=&#34;https://www.eevblog.com/forum/microcontrollers/microchip-keeloq-classic-new-firmware-for-garage-door-receiver-new-fobs/&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;first&lt;/a&gt; &lt;a href=&#34;https://forum.newae.com/t/finding-the-samples-with-leaking-bits/1919&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;one&lt;/a&gt; &lt;a href=&#34;https://web.archive.org/web/20210419001256/https://advancedpersistentjest.com/2020/06/13/side-channel-analysis-of-keeloq/&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;to&lt;/a&gt; &lt;a href=&#34;https://github.com/marc-invalid/chipwhisperer-marc/blob/master/doc/marc/keeloq/examples_hcs301/examples_hcs301.md&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;try&lt;/a&gt; &lt;a href=&#34;https://lerner98.medium.com/car-key-hacking-not-really-b60873cd18a&#34;  class=&#34;external-link&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;The way forward would seem to buy a spare ECU for my vehicle and to use a ChipWhisperer and attempt to learn how to do power analysis.&#xA;I don&amp;rsquo;t have the time or resources (or frankly the need) to do that for now, so I think this is where my journey ends.&#xA;I&amp;rsquo;ll update this if ever I can get my hands on the manufacturer key and do anything more with this.&lt;/p&gt;&#xA;</description>
    </item>
    <item>
      <title>DIY &#39;Smart&#39; Coffee Maker</title>
      <link>https://w-floyd.com/2020/07/coffee/</link>
      <pubDate>Sun, 05 Jul 2020 00:00:00 +0000</pubDate><author>William Floyd</author>
      <guid>https://w-floyd.com/2020/07/coffee/</guid><description>&lt;p&gt;I have recently (last couple months) been getting into home automation, specifically using Home Assistant.&#xA;I also wanted to get a coffee maker that used K-Cups.&#xA;Thus the goal was born - to get a coffee maker working with Home Assistant, such that I could automate it to fit my morning routine.&lt;/p&gt;&#xA;&lt;p&gt;I first searched for new coffee makers, looking to see what the easiest ones would be to hack into and automate.&#xA;I got so far as adding a sleek new brand name model to my Amazon cart, but thankfully reason and frugality prevailed!&#xA;Instead, I opted to swing by the local Goodwill the next day, to see what secondhand options might be available.&#xA;As luck would have it, I found a no-frills, single button coffee maker for the princely sum of $4, and I was on my merry way.&lt;/p&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2020/07/coffee/media/20200610_204856-3024.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2020/07/coffee/media/20200610_204856-400.avif&#34; alt=&#34;The Spoils of Goodwill&#34; title=&#34;The Spoils of Goodwill&#34; width=&#34;3024&#34; height=&#34;4032&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;Later that evening, opening the black box up (thankfully I had the correct triangular screwdriver head), I found very easily hackable innards.&lt;/p&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2020/07/coffee/media/20200610_205351-4032.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2020/07/coffee/media/20200610_205351-400.avif&#34; alt=&#34;Poor lighting is the worst...&#34; title=&#34;Poor lighting is the worst...&#34; width=&#34;4032&#34; height=&#34;3024&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;p&gt;The control board (&lt;a href=&#34;media/20200610_205847-3024.avif&#34; &gt;front&lt;/a&gt;, &lt;a href=&#34;media/20200610_205841-3024.avif&#34; &gt;back&lt;/a&gt;) is very simple - two buttons in parallel, an LED, and a couple resistors.&#xA;I&amp;rsquo;m not quite sure what the logic is upstream (it un/latches on each press), but the buttons short to ground, and this is something I can work with.&#xA;The control board has wires for ground, signal, and 5V, in that order.&lt;/p&gt;&#xA;&lt;p&gt;The ordeal of hacking into the thing, and my missteps trying to do so, is rather boring really, but it produced this:&lt;/p&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2020/07/coffee/media/20200702_120309-3024.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2020/07/coffee/media/20200702_120309-400.avif&#34; alt=&#34;Interception!&#34; title=&#34;Interception!&#34; width=&#34;3024&#34; height=&#34;4032&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2020/07/coffee/media/20200702_120302-3024.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2020/07/coffee/media/20200702_120302-400.avif&#34; alt=&#34;Perfboard&#34; title=&#34;Perfboard&#34; width=&#34;3024&#34; height=&#34;4032&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2020/07/coffee/media/20200702_120328-3024.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2020/07/coffee/media/20200702_120328-400.avif&#34; alt=&#34;D1 Mini&#34; title=&#34;D1 Mini&#34; width=&#34;3024&#34; height=&#34;4032&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;p&gt;The brains I added was a Wemos D1 Mini (thanks, Aliexpress!), with a 3.3V&amp;lt;-&amp;gt;5V converter between to sense when the coffee maker is on, and also turn on a mosfet to short the button to ground.&#xA;I initially had issues with the coffee maker turning on whenever I plugged the D1 Mini in, but a pulldown resistor solved this.&lt;/p&gt;&#xA;&lt;a href=&#34;https://w-floyd.com/2020/07/coffee/media/20200702_120334-3024.avif&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34; class=&#34;image-full&#34;&gt;&lt;img data-rimg src=&#34;https://w-floyd.com/2020/07/coffee/media/20200702_120334-400.avif&#34; alt=&#34;External USB Plug&#34; title=&#34;External USB Plug&#34; width=&#34;3024&#34; height=&#34;4032&#34; loading=&#34;lazy&#34; decoding=&#34;async&#34; /&gt;&lt;/a&gt;&#xA;&lt;p&gt;I also opted for an external USB plug - this allows me to possibly reflash this without opening the enclosure, and also meant I did not need to splice into the mains line inside, which I was reluctant to do.&lt;/p&gt;&#xA;&lt;p&gt;I initially flashed and programmed the coffee maker with Tasmota, but almost immediately opted to use ESPHome instead.&#xA;I like Tasmota and ESPHome, I was just able to get more fine control of the setup using ESPHome in this instance, especially concerning the button logic.&lt;/p&gt;&#xA;&lt;p&gt;The (important) code is as follows:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;binary_sensor&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  - &lt;span style=&#34;color:#f92672&#34;&gt;platform&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;gpio&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;device_class&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;power&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;internal&lt;/span&gt;: &lt;span style=&#34;color:#66d9ef&#34;&gt;true&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;id&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;power_on&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;pin&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;D2&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;switch&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  - &lt;span style=&#34;color:#f92672&#34;&gt;platform&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;gpio&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;pin&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;D1&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;id&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;relay&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;restore_mode&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;ALWAYS_OFF&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  - &lt;span style=&#34;color:#f92672&#34;&gt;platform&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;template&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;name&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Coffee Maker&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;icon&lt;/span&gt;: &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;mdi:coffee-maker&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;lambda&lt;/span&gt;: |-&lt;span style=&#34;color:#e6db74&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;      if (id(power_on).state) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        return true;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;      } else {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;        return false;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;      }&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;turn_on_action&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - &lt;span style=&#34;color:#f92672&#34;&gt;switch.turn_on&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;relay&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - &lt;span style=&#34;color:#f92672&#34;&gt;delay&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;50ms&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - &lt;span style=&#34;color:#f92672&#34;&gt;switch.turn_off&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;relay&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;turn_off_action&lt;/span&gt;:&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - &lt;span style=&#34;color:#f92672&#34;&gt;switch.turn_on&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;relay&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - &lt;span style=&#34;color:#f92672&#34;&gt;delay&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;50ms&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    - &lt;span style=&#34;color:#f92672&#34;&gt;switch.turn_off&lt;/span&gt;: &lt;span style=&#34;color:#ae81ff&#34;&gt;relay&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The beauty of the way in which I can detect signals and simulate a button press is that ESPHome senses when I use the physical button, and updates accordingly.&#xA;I can use the coffee maker absolutely as normal, the &amp;lsquo;Smart&amp;rsquo; part of it is optional.&lt;/p&gt;&#xA;&lt;hr&gt;&#xA;&lt;p&gt;The rest of my setup using this coffee maker is somewhat outside the scope of this post, but it includes using Tasker on my phone to run a &amp;lsquo;Wakeup&amp;rsquo; automation on Home Assistant, which will - along with turning on my bed-head lamp, and switching my monitor on before putting it to sleep - check if I turned on a &amp;lsquo;Morning Coffee&amp;rsquo; user input.&#xA;If I remembered to prep my coffee the night before, and turned on the switch, I will wake up to a hot cup of coffee (or, the sound of a coffee-in-progress).&#xA;I can also command Alexa and Google Assistant to do my bidding and make me a coffee.&#xA;At least someone does what I want&amp;hellip;&lt;/p&gt;&#xA;&lt;p&gt;Truly, we are living in the future.&lt;/p&gt;&#xA;</description>
    </item>
  </channel>
</rss>
