add keypairs
authorAJ ONeal <aj@therootcompany.com>
Wed, 21 Oct 2020 10:05:04 +0000 (10:05 +0000)
committerAJ ONeal <aj@therootcompany.com>
Wed, 21 Oct 2020 10:05:04 +0000 (10:05 +0000)
keypairs/README.md [new file with mode: 0644]
keypairs/install.ps1 [new file with mode: 0644]
keypairs/install.sh [new file with mode: 0644]
keypairs/releases.js [new file with mode: 0644]

diff --git a/keypairs/README.md b/keypairs/README.md
new file mode 100644 (file)
index 0000000..260222f
--- /dev/null
@@ -0,0 +1,55 @@
+---
+title: keypairs
+homepage: https://github.com/therootcompany/keypairs
+tagline: |
+  keypairs: a cross-platform tool for RSA, ECDSA, JWT, JOSE, and general asymmetric encryption
+---
+
+To update or switch versions, run `webi keypairs@stable`.
+
+## Cheat Sheet
+
+> keypairs is like JWT.io, at your fingertips.
+
+- Generates NIST standard RSA and ECDSA keys
+- Signatures output as JWT and JWS (JSONE)
+- Verifies signatures
+
+### How to generate JSON Web Keys (JWKs)
+
+```bash
+# keypairs gen -key <key.format> -pub <pub.format>
+keypairs gen -key key.jwk.json -pub pub.jwk.json
+```
+
+JWK is the default format, for which you can use stdout (key) and stderr (pub)
+
+```bash
+keypairs gen > key.jwk.json 2> pub.jwk.json
+```
+
+### How to generate PEM (PKCS) keys
+
+```bash
+keypairs gen -key key.pem -pub pub.pem
+```
+
+Or DER
+
+```bash
+keypairs gen -key key.der -pub pub.der
+```
+
+### How to sign a payload
+
+```bash
+# keypairs sign --exp 1h <priv key> <data or file> > token.jwt 2> sig.jws
+keypairs sign --exp 1h key.jwk.json '{ "sub": "me@example.com" }' > token.jwt 2> sig.jws
+```
+
+### How to verify a signature
+
+```bash
+# keypairs sign --exp 1h <pub key> <signed file or data>
+keypairs sign --exp 1h pub.jwk.json token.jwt
+```
diff --git a/keypairs/install.ps1 b/keypairs/install.ps1
new file mode 100644 (file)
index 0000000..0a5f9cf
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/env pwsh
+
+####################
+# Install keypairs #
+####################
+
+# Every package should define these variables
+$pkg_cmd_name = "keypairs"
+
+$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\keypairs.exe"
+$pkg_dst = "$pkg_dst_cmd"
+
+$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\keypairs-v$Env:WEBI_VERSION\bin\keypairs.exe"
+$pkg_src_bin = "$Env:USERPROFILE\.local\opt\keypairs-v$Env:WEBI_VERSION\bin"
+$pkg_src_dir = "$Env:USERPROFILE\.local\opt\keypairs-v$Env:WEBI_VERSION"
+$pkg_src = "$pkg_src_cmd"
+
+$pkg_download = "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"
+
+# Fetch archive
+IF (!(Test-Path -Path "$Env:USERPROFILE\Downloads\$Env:WEBI_PKG_FILE"))
+{
+    # TODO: arch detection
+    echo "Downloading keypairs from $Env:WEBI_PKG_URL to $pkg_download"
+    & curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
+    & move "$pkg_download.part" "$pkg_download"
+}
+
+IF (!(Test-Path -Path "$pkg_src_cmd"))
+{
+    echo "Installing keypairs"
+
+    # TODO: create package-specific temp directory
+    # Enter tmp
+    pushd .local\tmp
+
+        # Remove any leftover tmp cruft
+        Remove-Item -Path ".\keypairs-v*" -Recurse -ErrorAction Ignore
+        Remove-Item -Path ".\keypairs.exe" -Recurse -ErrorAction Ignore
+
+        # Unpack archive file into this temporary directory
+        # Windows BSD-tar handles zip. Imagine that.
+        echo "Unpacking $pkg_download"
+        & tar xf "$pkg_download"
+
+        # Settle unpacked archive into place
+        echo "Install Location: $pkg_src_cmd"
+        New-Item "$pkg_src_bin" -ItemType Directory
+        Move-Item -Path ".\keypairs.exe" -Destination "$pkg_src_bin"
+
+    # Exit tmp
+    popd
+}
+
+echo "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
+Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore
+Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
diff --git a/keypairs/install.sh b/keypairs/install.sh
new file mode 100644 (file)
index 0000000..48c96aa
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+function __init_keypairs() {
+    set -e
+    set -u
+
+    ####################
+    # Install keypairs #
+    ####################
+
+    # Every package should define these 6 variables
+    pkg_cmd_name="keypairs"
+
+    pkg_dst_cmd="$HOME/.local/bin/keypairs"
+    pkg_dst="$pkg_dst_cmd"
+
+    pkg_src_cmd="$HOME/.local/opt/keypairs-v$WEBI_VERSION/bin/keypairs"
+    pkg_src_dir="$HOME/.local/opt/keypairs-v$WEBI_VERSION"
+    pkg_src="$pkg_src_cmd"
+
+    pkg_install() {
+        # $HOME/.local/opt/keypairs-v0.6.5/bin
+        mkdir -p "$pkg_src_bin"
+
+        # mv ./keypairs* "$HOME/.local/opt/keypairs-v0.6.5/bin/keypairs"
+        mv ./"$pkg_cmd_name"* "$pkg_src_cmd"
+
+        # chmod a+x "$HOME/.local/opt/keypairs-v0.6.5/bin/keypairs"
+        chmod a+x "$pkg_src_cmd"
+    }
+
+    pkg_get_current_version() {
+        # 'keypairs version' has output in this format:
+        #       keypairs v0.6.5 (7e6fd17) 2020-10-21T06:26:46Z
+        # This trims it down to just the version number:
+        #       0.6.5
+        echo "$(keypairs --version 2>/dev/null | head -n 1 | cut -d' ' -f2 | sed 's:^v::')"
+    }
+
+}
+
+__init_keypairs
diff --git a/keypairs/releases.js b/keypairs/releases.js
new file mode 100644 (file)
index 0000000..5204dbc
--- /dev/null
@@ -0,0 +1,18 @@
+'use strict';
+
+var github = require('../_common/github.js');
+var owner = 'therootcompany';
+var repo = 'keypairs';
+
+module.exports = function (request) {
+  return github(request, owner, repo).then(function (all) {
+    return all;
+  });
+};
+
+if (module === require.main) {
+  module.exports(require('@root/request')).then(function (all) {
+    all = require('../_webi/normalize.js')(all);
+    console.info(JSON.stringify(all));
+  });
+}