Create ECDSA Keypair from Seed Phrase (BASH)

I was recently asked to provide the public component of a keypair for access to something. For reasons known only to myself, I decided it would amuse me to have the key derived from something else they'd said, so I knocked together a script to take a seed sentence and derive an ECDSA pair from that.

The script outputs the keypair in a few forms - the private key as a SHA256 hash, long SHA256 public key hash, RIPEMD public key hash (as used by many crypto currencies), and PEM versions of both (for use with OpenSSL et al).

Read more…

Running a remote instance of Firefox over an SSH tunnel (BASH)

Just occasionally I need to briefly run Firefox over an SSH connection, normally because I need something that's stored in Firefox on another machine (like a password that went into FF's manager by accident, or a bookmark - though those are easier dealt with another way)

This isn't something you want to do routinely, unless the remote end has very good upload speeds (even then, the repaints will be painful) and is only really viable as a means of last resort.

Simply creating a tunnel and running firefox won't work though, as by default Firefox will check for and connect to any existing instances, so you'll effectively just get a new firefox window on your local machine with no access to the data you're trying to access.

To avoid this, you need to use Firefox's no-remote argument.

Read more…

Converting disk back to Ready state from Non-Raid or Foreign on a Dell RAID controller (BASH)

If you're unable to create a new vdisk on Dell raid, and are getting something like the following

omconfig storage controller action=createvdisk controller=0 raid=r0 pdisks=0:1:25 size=max
The virtual disk cannot be created on the physical disks you selected. 
Possible reasons include: Insufficient disk space, available disks are not initialized, incorrect number of 
disks selected, unsupported RAID level selection, unsupported mix of SAS and SATA type disks, 
unsupported mix of SSD and HDD type disks, unsupported mix of 512Bytes a 4KBytes sector size disks, 
unsupported mix of PI capable and incapable type disks, controller restrictions or 
unsupported configuration

Then one possibility is that your replacement disk isn't in the "Online" state, and instead is showing as either "Foreign" or "Non-Raid"

omreport storage pdisk controller=0 |grep -E '^ID|State' | grep -A1 "0:1:25"
ID : 0:1:25
State : Non-RAID

omreport storage pdisk controller=0 |grep -E '^ID|State' | grep -A1 "0:1:24"
ID : 0:1:24
State : Foreign

These states have the following meanings

  • Non-Raid - The disk has previously been configured to be a non-RAID disk by a dell controller
  • Foreign - The disk has previously been part of a RAID array, but not one recognised by the controller (likely a disk repurposed from some other machine)

This documentation details how to revert both statuses back to "Ready" so the disk can be added to an array

Read more…

Urldecode string (LUA)

Sometimes, particularly when using LUA OpenResty, in may be necessary to url unencode/unescape a string, so that reserved characters are converted back to their literal representations. This is particularly useful as the value if ngx.var.arg_ variables are not automatically url unencoded

This snippet creates a function to do hex decode each character of a string

Read more…

FFMPEG Convert YUV444p to YUV420p (BASH)

Recently I've been using Kazam to create screencasts.

Although it's simple and convenient to use, it does have one drawback, in it's recordings it uses YUV444 as the colour encoding. That's almost fine for videos that are going to be played back on a desktop (depending on player support etc), but means that the majority of mobile devices will not play the content back.

It's therefore essential to convert to YUV420 before publishing. This snippet details how to do that using FFMPEG

Read more…

Forcing FFMPEG to honour segment length in HLS Stream Creator (BASH)

HLS Stream Creator uses FFmpeg under the hood in order to create HLS compatible video segments. However, FFmpeg will try to be smart about where it splits segments, so the interval specified on the command line may not always be honoured (depending on where keyframes are located and scenecut believes there's been a scene change).

This can occasionally lead to an annoying situation where segment lengths are significantly longer than expected, which may impact upon delivery

By exporting a couple of flags, however, it's possible to force FFmpeg to segment far closer to (and usually on) the expected interval. Be aware that this can severely impact video quality (which is why it's not forced by default)

Read more…

Force CURL to place request to a specific IP (BASH)

Back when everything was plain HTTP, to place a request via a specific machine you'd just pass curl that machine in the URL and then set a Host header for whatever domain you wanted that machine to try and serve. With HTTPs, though, you may need the SNI name to also be correct (not just to avoid certificate errors, but because the server may change behaviour based on the SNI name)

This snippet details how to force curl to resolve a domain+port pair to a specific IP

Read more…

Set a variable only if it is undefined (Javascript)

When relying on variables within a global scope, it's often wise to set a sane default within your script. However, it's important to ensure that that only occurs if the variable isn't already set (so that values set within the page itself are not overwritten, and nor are values propogated to that value if the script is called a second time for some reason).

Read more…

Ignore query string with Nginx caching proxy (NGinx)

Query strings in URLs give incredible flexibility, but are also an easy way for users to bypass your cache by appending random arguments (known as a cachebuster).

This documentation details how to adjust the cache key on a Nginx cachine reverse proxy, either to completely ignore the query string, or to only honour specific ones. If you're only serving static files then you'll likely want to ignore query strings entirely.

Read more…