• Communicating with HomePlugAV Devices using Python

    I've got a couple of pairs of ON Networks' PL 500 HomePlugAV Powerline Adapters and have been playing around with them to see how they compare to the Computrend 902 devices I played around with 5 years ago.

    I'm still playing around with the kit, but thought I'd document a very basic example of how to send commands to the devices using Python - the instructions should work for any kit based on Qualcomm's INT6x00 and AR7x00 chipsets (mine use the AR7420/QCA7420) - we'll be changing one of the encryption keys (the NMK) that the devices use

  • Python3 - TypeError: encoding without a string argument

    I thought I'd document this as although the cause/fix is fairly simple, searching for the error string encoding without a string argument gives a lot of hits for a similarly structured but different error - string argument without an encoding.

    An example backtrace might be:

    Traceback (most recent call last):
      File "./profiler.py", line 346, in 
        meta['config_files']['pdns'] = zip_and_compress(read_file_content('/etc/powerdns/pdns.conf'))
      File "./profiler.py", line 289, in zip_and_compress
        gz = gzip.compress(bytes(s,"utf-8"))
    TypeError: encoding without a string argument

    With the example code being fairly simple

    def read_file_content(path):
        ''' Read the entirety of a file into a variable
        file_content = None
        with open(path, 'rb') as content_file:
            file_content = content_file.read()
        return file_content
    def zip_and_compress(s):
        ''' Config files can get quite sizeable. To keep the size of our output DB down
        we gzip and then ascii armour them
        gz = gzip.compress(bytes(s,"utf-8"))
        return base64.b64encode(gz).decode("utf-8")
  • Sending commit notifications using Git post-receive hooks

    I make heavy use of Git, and have plugins that allow me to view my commits when viewing issues in JIRA. Unfortunately these plugins rely on Lucene indexes which has proven to be a bit of an issue when archiving projects (or maintaining a HTML fallback).

    There are various post-receive hooks out there for sending mail notifications out whenever someone runs 'git push', however they're generally tailored towards notifying a group of developers.

    I simply wanted the equivalent of 'git log' to appear within my JIRA activity flow on any issue which is mentioned in the commit message.

    This documentation provides a python based post-receive hook intended to do just that, and also documents exactly how to go about applying that hook to all existing and future repos on your server.

  • Writing (and backdooring) a ChaCha20 based CSPRNG

    Recently I've been playing around with the generation of random numbers.

    Although it's not quite ready yet, once of the things I've built is a source of (hopefully) random data. The writeup on that will come later.

    But, as an interesting distraction (and in some ways, the natural extension) is to then create a Psuedo Random Number Generator (PRNG) seeded by data from that random source.

    I wanted it to be (in principle) Cryptographically Secure (i.e. so we're creating a CSPRNG). In practice it isn't really (we'll explore why later in this post). I also wanted to implement what Bernstein calls "Fast Key Erasure" along with some techniques discussed by Amazon in relation to their S2N implementation.

    In this post I'll be detailing how my RNG works, as well as at looking at what each of those techniques do to the numbers being generated.

    I'm not a cryptographer, so I'm going to try and keep this relatively light-touch, if only to try and avoid highlighting my own ignorance too much. Although this post (as a whole) has turned out to be quite long, hopefully the individual sections are relatively easy to follow