#!/bin/sh # This file is part of Haketilo # # Copyright (C) 2021, Wojtek Kosior # # This program is free software: you can redistribute it and/or modify # it under the terms of the CC0 1.0 Universal License as published by # the Creative Commons Corporation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # CC0 1.0 Universal License for more details. set -e . ./shell_utils.sh _PROG_NAME="$0" OPERATION="$1" API_KEY="$2" SECRET="$3" XPI_PATH="$4" base64url() { ech "$1" | base64 -w 0 | tr '/+' '_-' | tr -d '=' } sha256hmac() { base64url "$(ech "$2" | openssl dgst -sha256 -hmac "$1" -binary -)" } get_manifest_key() { get_json_key "$1" "$(unzip -p "$2" manifest.json)" } generate_jwt() { local JWT_HEAD='{"alg":"HS256", "typ":"JWT"}' local JWT_ID=$(dd if=/dev/random bs=21 count=1 2>/dev/null | base64) local ISSUED_AT_TIME=$(date -u +%s) local EXPIRATION_TIME=$((ISSUED_AT_TIME + 300)) local JWT_PAYLOAD="$(cat <