Prepare Remote 0.1.0 test release and retain SSH-signed publishing
This commit is contained in:
1 parent
d7da6548e1
commit
346ec77c75
8 files changed
+450
-29
No files matched your search
@@ -4,9 +4,9 @@ A repository of experimental Tentacles for Cthulhu, maintained by Storm
|
|||||||
Dragon. It contains [Hello World](hello-world/README.md), the development
|
Dragon. It contains [Hello World](hello-world/README.md), the development
|
||||||
[Wormhole tentacle](wormhole/README.md), and
|
[Wormhole tentacle](wormhole/README.md), and
|
||||||
[Battery Status](battery-status/README.md).
|
[Battery Status](battery-status/README.md).
|
||||||
The [Remote implementation](remote/README.md) has a source-built command with
|
The experimental [Remote tentacle](remote/README.md) connects through an NVDA
|
||||||
reader-owned consent and experimental software speech; it is not yet installable
|
Remote compatible relay for speech, keyboard control, clipboard text and Braille,
|
||||||
or able to control a desktop.
|
with reader-owned consent for each session. Its first release is for live testing.
|
||||||
Repository material and these Tentacles are licensed under GPL-3.0-or-later; see
|
Repository material and these Tentacles are licensed under GPL-3.0-or-later; see
|
||||||
[LICENSE](LICENSE) and [CONTRIBUTING.md](CONTRIBUTING.md).
|
[LICENSE](LICENSE) and [CONTRIBUTING.md](CONTRIBUTING.md).
|
||||||
|
|
||||||
@@ -20,6 +20,10 @@ Native packages are available from the
|
|||||||
Battery Status 0.1.0 packages are available from the
|
Battery Status 0.1.0 packages are available from the
|
||||||
[Battery Status release page](https://git.stormux.org/storm/cthulhu-tentacles/releases/tag/battery-status-v0.1.0).
|
[Battery Status release page](https://git.stormux.org/storm/cthulhu-tentacles/releases/tag/battery-status-v0.1.0).
|
||||||
It uses Cthulhu+Shift+B and requires the UPower system service.
|
It uses Cthulhu+Shift+B and requires the UPower system service.
|
||||||
|
Remote 0.1.0 test packages are available from the
|
||||||
|
[Remote release page](https://git.stormux.org/storm/cthulhu-tentacles/releases/tag/remote-v0.1.0).
|
||||||
|
It uses Cthulhu+Ctrl+Shift+R and requires the matching experimental reader;
|
||||||
|
see [installation and live checks](remote/README.md#install-and-test-010).
|
||||||
Local build artifacts live in the ignored `dist/` directory.
|
Local build artifacts live in the ignored `dist/` directory.
|
||||||
The discovery source URL is
|
The discovery source URL is
|
||||||
`https://git.stormux.org/storm/cthulhu-tentacles`.
|
`https://git.stormux.org/storm/cthulhu-tentacles`.
|
||||||
@@ -47,10 +51,10 @@ make check
|
|||||||
|
|
||||||
The executables are `hello-world/bin/hello-world`,
|
The executables are `hello-world/bin/hello-world`,
|
||||||
`wormhole/bin/wormhole-tentacle`, `battery-status/bin/battery-status`, and
|
`wormhole/bin/wormhole-tentacle`, `battery-status/bin/battery-status`, and
|
||||||
the development command `remote/bin/remote`;
|
`remote/bin/remote`;
|
||||||
all are ignored by Git.
|
all are ignored by Git.
|
||||||
Checks validate the TOML metadata, registration and suggested bindings, and
|
Checks validate the TOML metadata, registration and suggested bindings, and
|
||||||
invoke the three catalog Tentacles through the actual Cthulhu host, plus private
|
invoke the existing catalog Tentacles through the actual Cthulhu host, plus private
|
||||||
Remote consent/relay and typed speech IPC tests. They produce no speech
|
Remote consent/relay and typed speech IPC tests. They produce no speech
|
||||||
or Braille and leave the running reader alone.
|
or Braille and leave the running reader alone.
|
||||||
|
|
||||||
@@ -64,6 +68,8 @@ and focused-item/clipboard access as well as speech/Braille. **Install** instead
|
|||||||
and saves the package disabled. The reader verifies the catalog's SHA-256 digest,
|
and saves the package disabled. The reader verifies the catalog's SHA-256 digest,
|
||||||
package identity and native architecture before saving a launch entry. Catalogs
|
package identity and native architecture before saving a launch entry. Catalogs
|
||||||
without a published compatible release show a clear message and remain unchecked.
|
without a published compatible release show a clear message and remain unchecked.
|
||||||
|
Remote can be selected in the same table; its installation grants and separate
|
||||||
|
per-session approval are described in its README.
|
||||||
No source builds or install scripts run during this workflow. Resource limits
|
No source builds or install scripts run during this workflow. Resource limits
|
||||||
do not make untrusted same-user programs safe.
|
do not make untrusted same-user programs safe.
|
||||||
|
|
||||||
@@ -122,6 +128,36 @@ explicit restart is needed when changing the reader itself. For source-only loca
|
|||||||
testing, the development launch procedure remains in
|
testing, the development launch procedure remains in
|
||||||
[Hello World](hello-world/README.md#local-launch).
|
[Hello World](hello-world/README.md#local-launch).
|
||||||
|
|
||||||
|
### SSH-agent release uploads
|
||||||
|
|
||||||
|
For this Gitea repository, `tools/publish.py` signs HTTPS API requests with an
|
||||||
|
RSA key already registered with Gitea and loaded in `ssh-agent`. It requires
|
||||||
|
Python's Paramiko package. No API token is needed or stored, and no private-key
|
||||||
|
file is read. With multiple loaded RSA keys, select one using
|
||||||
|
`--ssh-key SHA256:...` and its `ssh-add -l` fingerprint.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 -B tools/publish.py auth
|
||||||
|
python3 -B -m unittest discover -s tools -p test_publish.py
|
||||||
|
```
|
||||||
|
|
||||||
|
Prepare and review one Tentacle's archives, `dist/catalog.toml`, `SHA256SUMS`
|
||||||
|
and release notes. Commit the reviewed source and push its release tag. The
|
||||||
|
uploader requires a clean working tree and checks that the remote tag points to
|
||||||
|
the current source commit. For example, after tagging a new Remote version:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 -B tools/publish.py publish --tentacle remote --notes dist/remote-release-notes.md
|
||||||
|
python3 -B tools/publish.py verify --tentacle remote
|
||||||
|
```
|
||||||
|
|
||||||
|
The publisher refuses an existing release, creates a draft prerelease, uploads
|
||||||
|
the selected archives and checksums, publishes it, then downloads the public
|
||||||
|
assets again to verify their hashes. Upload failures retain the draft for
|
||||||
|
inspection; it never deletes or replaces assets. Push the matching catalog to
|
||||||
|
the default branch only after public verification passes. This tool does not
|
||||||
|
make commits, push Git refs, or modify the running reader.
|
||||||
|
|
||||||
## Create and release your own Tentacle
|
## Create and release your own Tentacle
|
||||||
|
|
||||||
This tutorial creates a native Go Tentacle named **Greeting**, then makes it
|
This tutorial creates a native Go Tentacle named **Greeting**, then makes it
|
||||||
@@ -335,6 +371,7 @@ and testing AI-assisted changes.
|
|||||||
The `make build`, `make check` and `tools/package.py` commands in **this**
|
The `make build`, `make check` and `tools/package.py` commands in **this**
|
||||||
repository build/check Hello World, Wormhole, and Battery Status. `tools/package.py --tentacle wormhole`
|
repository build/check Hello World, Wormhole, and Battery Status. `tools/package.py --tentacle wormhole`
|
||||||
packages Wormhole; `--tentacle battery-status` packages Battery Status.
|
packages Wormhole; `--tentacle battery-status` packages Battery Status.
|
||||||
|
Use `--tentacle remote` to package Remote for both architectures.
|
||||||
The default still packages Hello World. The checker pins the
|
The default still packages Hello World. The checker pins the
|
||||||
current versions and expected Tentacles. Adapt those tools and checks when
|
current versions and expected Tentacles. Adapt those tools and checks when
|
||||||
extending this repository, or use
|
extending this repository, or use
|
||||||
|
|||||||
@@ -47,3 +47,19 @@ platform = "linux"
|
|||||||
architecture = "arm64"
|
architecture = "arm64"
|
||||||
url = "https://git.stormux.org/storm/cthulhu-tentacles/releases/download/battery-status-v0.1.0/battery-status-0.1.0-linux-arm64.tar.gz"
|
url = "https://git.stormux.org/storm/cthulhu-tentacles/releases/download/battery-status-v0.1.0/battery-status-0.1.0-linux-arm64.tar.gz"
|
||||||
sha256 = "d75e40fd76280ecba228f3d3132d846f4e8f79a3e2bdd6dafd515c39a191cca0"
|
sha256 = "d75e40fd76280ecba228f3d3132d846f4e8f79a3e2bdd6dafd515c39a191cca0"
|
||||||
|
|
||||||
|
[[tentacles]]
|
||||||
|
id = "remote"
|
||||||
|
manifest = "remote/tentacle.toml"
|
||||||
|
|
||||||
|
[[tentacles.releases]]
|
||||||
|
platform = "linux"
|
||||||
|
architecture = "amd64"
|
||||||
|
url = "https://git.stormux.org/storm/cthulhu-tentacles/releases/download/remote-v0.1.0/remote-0.1.0-linux-amd64.tar.gz"
|
||||||
|
sha256 = "3c69a1437ab8f47943068f2deeaa5ebd531635cd315855bfb548e83b25bd815c"
|
||||||
|
|
||||||
|
[[tentacles.releases]]
|
||||||
|
platform = "linux"
|
||||||
|
architecture = "arm64"
|
||||||
|
url = "https://git.stormux.org/storm/cthulhu-tentacles/releases/download/remote-v0.1.0/remote-0.1.0-linux-arm64.tar.gz"
|
||||||
|
sha256 = "86f772c161e74492a741fdb5befcda7c31535ace1cf5b308dacd61b244dde58b"
|
||||||
@@ -5,7 +5,8 @@ keyboard control in both directions with a core F11 escape, explicit clipboard
|
|||||||
text, Braille output/routing in both directions and review packaging. Every
|
text, Braille output/routing in both directions and review packaging. Every
|
||||||
live acceptance gate below (physical keyboard, audible speech, physical Braille,
|
live acceptance gate below (physical keyboard, audible speech, physical Braille,
|
||||||
NVDA/Orca interoperability, installer/ARM64 release checks) remains open and is
|
NVDA/Orca interoperability, installer/ARM64 release checks) remains open and is
|
||||||
the next step; do not advertise the release until those results are recorded.
|
the next step. Version 0.1.0 is being packaged as an explicitly experimental
|
||||||
|
test release to collect those results, not as a live-accepted stable release.
|
||||||
Research date: 2026-11-03. Unchecked checklist items describe future work. API
|
Research date: 2026-11-03. Unchecked checklist items describe future work. API
|
||||||
names and limits below remain proposed contracts unless an implementation
|
names and limits below remain proposed contracts unless an implementation
|
||||||
increment explicitly records them as implemented and tested.
|
increment explicitly records them as implemented and tested.
|
||||||
|
|||||||
+41
-12
@@ -1,14 +1,43 @@
|
|||||||
# Remote — implementation in progress
|
# Remote 0.1.0 — experimental test release
|
||||||
|
|
||||||
Remote will connect Cthulhu to an NVDA Remote protocol-v2 relay, as either a
|
Remote connects Cthulhu to an NVDA Remote protocol-v2 relay, as either a
|
||||||
controller or a controlled computer. The first implementation increment is a
|
controller or a controlled computer, with relay/role selection, reader-owned
|
||||||
tested Go relay library in `src/`. A subsequent increment now provides a
|
consent, connection controls, speech, keyboard, clipboard text and Braille.
|
||||||
source-built command with relay/role selection, reader-owned consent and connection
|
Version 0.1.0 is the first packaged release for live testing. Physical keyboard
|
||||||
controls, speech, keyboard, clipboard text and Braille. A protocol 1.1 manifest
|
recovery, audible speech/masking, physical Braille and NVDA/Orca interoperability
|
||||||
now exists and `tools/package.py --tentacle remote` builds review archives, but
|
have not yet passed live acceptance. ARM64 is cross-built and has not been run
|
||||||
Remote is not in the published catalog: live acceptance and a verified release
|
on ARM64 hardware.
|
||||||
come first.
|
|
||||||
See [the source command and physical-input checks](command.md).
|
## Install and test 0.1.0
|
||||||
|
|
||||||
|
Use the matching experimental Cthulhu reader from `testing` revision
|
||||||
|
`952d3c82049a5521c506d7e30e6118361f2c7f4d` or a compatible later revision.
|
||||||
|
Keyboard control requires its `cthulhu-input-helper`; Braille requires
|
||||||
|
`cthulhu-braille`. Keyboard capture/injection requires Xorg. Installing this
|
||||||
|
Tentacle does not update the reader or its helpers.
|
||||||
|
|
||||||
|
In global Cthulhu Preferences → Tentacles, add or refresh
|
||||||
|
`https://git.stormux.org/storm/cthulhu-tentacles`, select **Remote**, review its
|
||||||
|
version and requested access, and choose **Install and enable**. Packages for
|
||||||
|
Linux amd64 and arm64 and their SHA-256 checksums are on the
|
||||||
|
[0.1.0 release page](https://git.stormux.org/storm/cthulhu-tentacles/releases/tag/remote-v0.1.0).
|
||||||
|
|
||||||
|
Press Cthulhu+Ctrl+Shift+R, select the role and relay, and choose the services
|
||||||
|
to test. Each connection also needs physical local approval in the reader's
|
||||||
|
dialog. Use a private test relay and harmless text on disposable test desktops.
|
||||||
|
Choose **Return to desktop and keep this connection** after connecting; the
|
||||||
|
same shortcut reopens status and Disconnect. Keyboard focus uses
|
||||||
|
Cthulhu+Ctrl+Shift+F; F11 returns to local control. Clipboard send/receive use
|
||||||
|
Cthulhu+Ctrl+Shift+C/V and never automatically overwrite the clipboard.
|
||||||
|
|
||||||
|
Follow [the physical keyboard, speech, clipboard and Braille checks](command.md)
|
||||||
|
on both desktops. Check disconnect/lock/handoff with modifiers held, local
|
||||||
|
typing after F11, password/key masking and ordinary reading. Recheck Hello
|
||||||
|
World, Wormhole and Battery Status because they share the host interaction path.
|
||||||
|
Record reader/peer versions, role, layout, actual speech/key/Braille results and
|
||||||
|
recovery behavior. Automated tests do not establish those results.
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
Implemented:
|
Implemented:
|
||||||
|
|
||||||
@@ -176,8 +205,8 @@ private fixtures do not establish them.
|
|||||||
Remaining release evidence includes captured NVDA protocol fixtures, actual
|
Remaining release evidence includes captured NVDA protocol fixtures, actual
|
||||||
NVDA/add-on/Orca interoperability, physical-source approval and keyboard recovery,
|
NVDA/add-on/Orca interoperability, physical-source approval and keyboard recovery,
|
||||||
audible speech and masking, physical Braille, installer checks and ARM64 package
|
audible speech and masking, physical Braille, installer checks and ARM64 package
|
||||||
validation. Review archives exist; catalog publication and release deployment
|
validation. The test release does not establish those live results. Unreviewed
|
||||||
are separate actions. Unreviewed speech producers remain deliberately local.
|
speech producers remain deliberately local.
|
||||||
See [the current plan status](../remote.md) for scope and release gates. Older
|
See [the current plan status](../remote.md) for scope and release gates. Older
|
||||||
increment documents describe the state at the time of each increment, not a
|
increment documents describe the state at the time of each increment, not a
|
||||||
current implementation backlog.
|
current implementation backlog.
|
||||||
|
|||||||
+8
-7
@@ -3,8 +3,9 @@
|
|||||||
The source-built Remote executable now registers a production command through
|
The source-built Remote executable now registers a production command through
|
||||||
the public Go SDK. This increment joins relay/role selection, reader-owned
|
the public Go SDK. This increment joins relay/role selection, reader-owned
|
||||||
consent and the existing connection workflow. It provides **experimental speech**
|
consent and the existing connection workflow. It provides **experimental speech**
|
||||||
with the matching reader. Keyboard forwarding/injection, clipboard transfer
|
with the matching reader. Subsequent increments added keyboard control,
|
||||||
and Braille services remain unavailable. There is still no installable manifest or catalog entry.
|
clipboard text and Braille; version 0.1.0 packages these for live testing.
|
||||||
|
See [installation and current requirements](README.md#install-and-test-010).
|
||||||
|
|
||||||
The subsequent [speech coordinator increment](speech.md) now connects typed
|
The subsequent [speech coordinator increment](speech.md) now connects typed
|
||||||
relay speech to presentation IPC and reader output events to relay writes.
|
relay speech to presentation IPC and reader output events to relay writes.
|
||||||
@@ -41,11 +42,11 @@ the endpoint drops the previous endpoint's pin. Review access returns a typed
|
|||||||
|
|
||||||
The host keeps its existing interaction slot and resolves the exact requesting
|
The host keeps its existing interaction slot and resolves the exact requesting
|
||||||
process session. Install grants limit the requested role/grants. The reader's
|
process session. Install grants limit the requested role/grants. The reader's
|
||||||
own local-only form starts on Cancel with every grant unchecked. This development
|
own local-only form starts on Cancel with every grant unchecked. The command
|
||||||
command requests only `remote-present` for controller or `output-observe` for
|
requests `remote-present` for controller or `output-observe` for controlled,
|
||||||
controlled. Limited ordinary-event speech observation and isolated incoming
|
plus the keyboard, clipboard and Braille services explicitly selected for that
|
||||||
software presentation now exist. Keyboard, clipboard and Braille
|
connection. Install grants and the separate reader approval constrain each
|
||||||
permissions are not requested. A shortcut, child request or fabricated command
|
service. A shortcut, child request or fabricated command
|
||||||
argument cannot approve access.
|
argument cannot approve access.
|
||||||
|
|
||||||
On explicit nonempty approval the reader issues `remote.action` through the SDK
|
On explicit nonempty approval the reader issues `remote.action` through the SDK
|
||||||
|
|||||||
+9
-4
@@ -31,8 +31,8 @@ def check_metadata(repoRoot):
|
|||||||
"Unsupported metadata format")
|
"Unsupported metadata format")
|
||||||
require(repository["id"] == "storm.cthulhu-tentacles" and repository["name"],
|
require(repository["id"] == "storm.cthulhu-tentacles" and repository["name"],
|
||||||
"Repository identity is missing")
|
"Repository identity is missing")
|
||||||
require([item["id"] for item in catalog["tentacles"]] == ["hello-world", "wormhole", "battery-status"],
|
require([item["id"] for item in catalog["tentacles"]] == ["hello-world", "wormhole", "battery-status", "remote"],
|
||||||
"Catalog must list Hello World, Wormhole, and Battery Status")
|
"Catalog must list Hello World, Wormhole, Battery Status, and Remote")
|
||||||
for item in catalog["tentacles"]:
|
for item in catalog["tentacles"]:
|
||||||
name = item["id"]
|
name = item["id"]
|
||||||
require(item["manifest"] == f"{name}/tentacle.toml", "Manifest path must match ID")
|
require(item["manifest"] == f"{name}/tentacle.toml", "Manifest path must match ID")
|
||||||
@@ -40,10 +40,15 @@ def check_metadata(repoRoot):
|
|||||||
require(manifest["format-version"] == 1 and manifest["id"] == name
|
require(manifest["format-version"] == 1 and manifest["id"] == name
|
||||||
and manifest["name"] and manifest["version"] == ("0.1.2" if name == "wormhole" else "0.1.0"), "Invalid Tentacle metadata")
|
and manifest["name"] and manifest["version"] == ("0.1.2" if name == "wormhole" else "0.1.0"), "Invalid Tentacle metadata")
|
||||||
expectedGrants = ["presentation"] + (["interaction"] if name in ("wormhole", "battery-status") else [])
|
expectedGrants = ["presentation"] + (["interaction"] if name in ("wormhole", "battery-status") else [])
|
||||||
|
if name == "remote":
|
||||||
|
expectedGrants = ["presentation", "interaction", "output-observe", "remote-present", "keyboard-capture",
|
||||||
|
"keyboard-inject", "braille-stream", "clipboard-exchange"]
|
||||||
|
expectedApis = (["commands", "session-events", "presentation", "interaction", "remote-access"]
|
||||||
|
if name == "remote" else ["commands"] + expectedGrants)
|
||||||
expectedProgram = "wormhole-tentacle" if name == "wormhole" else name
|
expectedProgram = "wormhole-tentacle" if name == "wormhole" else name
|
||||||
require(manifest["entry-point"] == [f"bin/{expectedProgram}"]
|
require(manifest["entry-point"] == [f"bin/{expectedProgram}"]
|
||||||
and manifest["capabilities"] == expectedGrants
|
and manifest["capabilities"] == expectedGrants
|
||||||
and manifest["apis"] == ["commands"] + expectedGrants,
|
and manifest["apis"] == expectedApis,
|
||||||
"Unexpected launch or grants")
|
"Unexpected launch or grants")
|
||||||
require((repoRoot / "LICENSE").is_file() and (repoRoot / name / "LICENSE").is_file()
|
require((repoRoot / "LICENSE").is_file() and (repoRoot / name / "LICENSE").is_file()
|
||||||
and (repoRoot / name / "README.md").is_file(), "License and help are required")
|
and (repoRoot / name / "README.md").is_file(), "License and help are required")
|
||||||
@@ -156,7 +161,7 @@ def check_host(repoRoot, programPath, name):
|
|||||||
|
|
||||||
|
|
||||||
def check_remote_manifest(repoRoot, readerRoot):
|
def check_remote_manifest(repoRoot, readerRoot):
|
||||||
"""Remote is not in the catalog until a release is published and verified."""
|
"""Check Remote's protocol and grants against the matching reader SDK."""
|
||||||
manifest = read_toml(repoRoot / "remote/tentacle.toml")
|
manifest = read_toml(repoRoot / "remote/tentacle.toml")
|
||||||
require(manifest["format-version"] == 1 and manifest["id"] == "remote" and manifest["name"] == "Remote"
|
require(manifest["format-version"] == 1 and manifest["id"] == "remote" and manifest["name"] == "Remote"
|
||||||
and manifest["runtime"] == "native" and manifest["platforms"] == ["linux"]
|
and manifest["runtime"] == "native" and manifest["platforms"] == ["linux"]
|
||||||
|
|||||||
@@ -0,0 +1,234 @@
|
|||||||
|
# Copyright (c) 2026 Storm Dragon
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
"""Publish this repository's prepared releases using SSH-agent HTTP signatures.
|
||||||
|
|
||||||
|
Requires Paramiko and an RSA key registered with Gitea, loaded in ssh-agent.
|
||||||
|
No API token or private-key file is read or stored.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import base64
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import tarfile
|
||||||
|
import time
|
||||||
|
import tomllib
|
||||||
|
import urllib.error
|
||||||
|
import urllib.parse
|
||||||
|
import urllib.request
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
import paramiko
|
||||||
|
|
||||||
|
|
||||||
|
ORIGIN = "https://git.stormux.org"
|
||||||
|
REPO_API = "/api/v1/repos/storm/cthulhu-tentacles"
|
||||||
|
|
||||||
|
|
||||||
|
class NoRedirect(urllib.request.HTTPRedirectHandler):
|
||||||
|
def redirect_request(self, request, source, code, message, headers, newURL):
|
||||||
|
raise RuntimeError("Refusing to redirect an authenticated request")
|
||||||
|
|
||||||
|
|
||||||
|
class HTTPSRedirect(urllib.request.HTTPRedirectHandler):
|
||||||
|
def redirect_request(self, request, source, code, message, headers, newURL):
|
||||||
|
parsed = urllib.parse.urlsplit(newURL)
|
||||||
|
if parsed.scheme != "https" or parsed.username or parsed.password:
|
||||||
|
raise RuntimeError("Release download redirect must use HTTPS without credentials")
|
||||||
|
return super().redirect_request(request, source, code, message, headers, newURL)
|
||||||
|
|
||||||
|
|
||||||
|
class Publisher:
|
||||||
|
def __init__(self, fingerprint=None):
|
||||||
|
self.agent = paramiko.Agent()
|
||||||
|
keys = [key for key in self.agent.get_keys() if key.get_name() == "ssh-rsa"]
|
||||||
|
if fingerprint:
|
||||||
|
keys = [key for key in keys if self.key_fingerprint(key) == fingerprint]
|
||||||
|
if len(keys) != 1:
|
||||||
|
self.agent.close()
|
||||||
|
raise RuntimeError("Load one registered RSA key in ssh-agent, or select it with --ssh-key SHA256:...")
|
||||||
|
self.key = keys[0]
|
||||||
|
self.fingerprint = self.key_fingerprint(self.key)
|
||||||
|
self.opener = urllib.request.build_opener(NoRedirect())
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def key_fingerprint(key):
|
||||||
|
return "SHA256:" + base64.b64encode(hashlib.sha256(key.asbytes()).digest()).decode().rstrip("=")
|
||||||
|
|
||||||
|
def request(self, method, route, body=None, contentType=None, allowMissing=False):
|
||||||
|
parsed = urllib.parse.urlsplit(route)
|
||||||
|
if (method not in ("GET", "POST", "PATCH") or parsed.scheme or parsed.netloc
|
||||||
|
or parsed.fragment or ".." in parsed.path.split("/")
|
||||||
|
or not (method == "GET" and route == "/api/v1/user"
|
||||||
|
or parsed.path == REPO_API or parsed.path.startswith(REPO_API + "/"))):
|
||||||
|
raise RuntimeError("Request is outside this repository's release API")
|
||||||
|
created = int(time.time())
|
||||||
|
expires = created + 30
|
||||||
|
names = ["(request-target)", "(created)", "(expires)"]
|
||||||
|
lines = [f"(request-target): {method.lower()} {route}",
|
||||||
|
f"(created): {created}", f"(expires): {expires}"]
|
||||||
|
headers = {"Accept": "application/json"}
|
||||||
|
if body is not None:
|
||||||
|
digest = "SHA-512=" + base64.b64encode(hashlib.sha512(body).digest()).decode()
|
||||||
|
headers["Digest"] = digest
|
||||||
|
headers["Content-Type"] = contentType or "application/json"
|
||||||
|
names.append("digest")
|
||||||
|
lines.append("digest: " + digest)
|
||||||
|
signed = self.key.sign_ssh_data("\n".join(lines).encode(), algorithm="rsa-sha2-256")
|
||||||
|
wire = paramiko.Message(signed if isinstance(signed, bytes) else signed.asbytes())
|
||||||
|
if wire.get_text() != "rsa-sha2-256":
|
||||||
|
raise RuntimeError("Unexpected SSH signature algorithm")
|
||||||
|
signature = base64.b64encode(wire.get_binary()).decode()
|
||||||
|
headerNames = " ".join(names)
|
||||||
|
headers["Signature"] = (f'keyId="{self.fingerprint}",algorithm="hs2019",'
|
||||||
|
f'created={created},expires={expires},'
|
||||||
|
f'headers="{headerNames}",signature="{signature}"')
|
||||||
|
request = urllib.request.Request(ORIGIN + route, data=body, headers=headers, method=method)
|
||||||
|
try:
|
||||||
|
with self.opener.open(request, timeout=45) as response:
|
||||||
|
data = response.read((2 << 20) + 1)
|
||||||
|
if len(data) > 2 << 20:
|
||||||
|
raise RuntimeError("Release API response is too large")
|
||||||
|
return json.loads(data) if data else None
|
||||||
|
except urllib.error.HTTPError as error:
|
||||||
|
if allowMissing and method == "GET" and error.code == 404:
|
||||||
|
return None
|
||||||
|
raise RuntimeError(f"Git server rejected {method} {route}: HTTP {error.code}") from None
|
||||||
|
|
||||||
|
def authenticate(self):
|
||||||
|
account = self.request("GET", "/api/v1/user")
|
||||||
|
repository = self.request("GET", REPO_API)
|
||||||
|
if not repository.get("permissions", {}).get("push"):
|
||||||
|
raise RuntimeError("The signing account lacks repository write access")
|
||||||
|
print(f"SSH-signed authentication and repository write access verified for {account['login']}.", flush=True)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
self.agent.close()
|
||||||
|
|
||||||
|
|
||||||
|
def release_artifacts(repoRoot, name):
|
||||||
|
catalog = tomllib.loads((repoRoot / "dist/catalog.toml").read_text())
|
||||||
|
matches = [entry for entry in catalog["tentacles"] if entry["id"] == name]
|
||||||
|
if len(matches) != 1:
|
||||||
|
raise RuntimeError("Select one Tentacle from the prepared catalog")
|
||||||
|
entry = matches[0]
|
||||||
|
if entry["manifest"] != f"{name}/tentacle.toml":
|
||||||
|
raise RuntimeError("Manifest path must match the Tentacle ID")
|
||||||
|
manifestBytes = (repoRoot / entry["manifest"]).read_bytes()
|
||||||
|
manifest = tomllib.loads(manifestBytes.decode())
|
||||||
|
version = manifest["version"]
|
||||||
|
tagName = f"{name}-v{version}"
|
||||||
|
prefix = f"{ORIGIN}/storm/cthulhu-tentacles/releases/download/{tagName}/"
|
||||||
|
artifacts = []
|
||||||
|
targets = set()
|
||||||
|
for release in entry.get("releases", []):
|
||||||
|
target = (release["platform"], release["architecture"])
|
||||||
|
filename = f"{name}-{version}-{target[0]}-{target[1]}.tar.gz"
|
||||||
|
if target in targets or target[0] != "linux" or target[1] not in ("amd64", "arm64"):
|
||||||
|
raise RuntimeError("Invalid or duplicate release architecture")
|
||||||
|
targets.add(target)
|
||||||
|
if release["url"] != prefix + filename:
|
||||||
|
raise RuntimeError("Prepared URL does not match this release")
|
||||||
|
artifactPath = repoRoot / "dist" / filename
|
||||||
|
digest = hashlib.sha256(artifactPath.read_bytes()).hexdigest()
|
||||||
|
if digest != release["sha256"]:
|
||||||
|
raise RuntimeError("Archive digest differs from the prepared catalog")
|
||||||
|
with tarfile.open(artifactPath) as archive:
|
||||||
|
if archive.extractfile("tentacle.toml").read() != manifestBytes:
|
||||||
|
raise RuntimeError("Archive manifest differs from the source")
|
||||||
|
for filename in ("README.md", "LICENSE"):
|
||||||
|
if archive.extractfile(filename).read() != (repoRoot / name / filename).read_bytes():
|
||||||
|
raise RuntimeError("Archive documentation differs from the source")
|
||||||
|
artifacts.append((artifactPath, release))
|
||||||
|
if not artifacts:
|
||||||
|
raise RuntimeError("No prepared release artifacts")
|
||||||
|
expectedSums = "".join(f"{release['sha256']} {path.name}\n" for path, release in artifacts)
|
||||||
|
if (repoRoot / "dist/SHA256SUMS").read_text() != expectedSums:
|
||||||
|
raise RuntimeError("SHA256SUMS must contain exactly the selected release artifacts")
|
||||||
|
return manifest, tagName, artifacts
|
||||||
|
|
||||||
|
|
||||||
|
def verify_downloads(repoRoot, artifacts, tagName):
|
||||||
|
opener = urllib.request.build_opener(HTTPSRedirect())
|
||||||
|
for artifactPath, release in artifacts:
|
||||||
|
with opener.open(release["url"], timeout=60) as response:
|
||||||
|
data = response.read((32 << 20) + 1)
|
||||||
|
if len(data) > 32 << 20 or hashlib.sha256(data).hexdigest() != release["sha256"]:
|
||||||
|
raise RuntimeError("Published download differs from the prepared archive")
|
||||||
|
print(f"Verified public download: {artifactPath.name}", flush=True)
|
||||||
|
url = f"{ORIGIN}/storm/cthulhu-tentacles/releases/download/{tagName}/SHA256SUMS"
|
||||||
|
with opener.open(url, timeout=45) as response:
|
||||||
|
if response.read(8193) != (repoRoot / "dist/SHA256SUMS").read_bytes():
|
||||||
|
raise RuntimeError("Published SHA256SUMS differs from the prepared file")
|
||||||
|
print("Public archives and SHA256SUMS verified.", flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
def publish(publisher, repoRoot, manifest, tagName, artifacts, notesPath):
|
||||||
|
notes = notesPath.read_text()
|
||||||
|
if not notes.strip():
|
||||||
|
raise RuntimeError("Release notes are empty")
|
||||||
|
if subprocess.check_output(["git", "status", "--porcelain"], cwd=repoRoot):
|
||||||
|
raise RuntimeError("Commit and review source changes before publication")
|
||||||
|
commit = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=repoRoot, text=True).strip()
|
||||||
|
refs = subprocess.check_output(["git", "ls-remote", "--tags", "origin", f"refs/tags/{tagName}",
|
||||||
|
f"refs/tags/{tagName}^{{}}"], cwd=repoRoot, text=True)
|
||||||
|
tagRefs = dict(line.split()[::-1] for line in refs.splitlines())
|
||||||
|
if tagRefs.get(f"refs/tags/{tagName}^{{}}", tagRefs.get(f"refs/tags/{tagName}")) != commit:
|
||||||
|
raise RuntimeError("Push the release tag at the reviewed source commit first")
|
||||||
|
existing = publisher.request("GET", REPO_API + f"/releases/tags/{tagName}", allowMissing=True)
|
||||||
|
if existing:
|
||||||
|
raise RuntimeError("Release already exists; inspect it before retrying")
|
||||||
|
release = publisher.request("POST", REPO_API + "/releases", json.dumps({
|
||||||
|
"tag_name": tagName, "target_commitish": commit,
|
||||||
|
"name": f"{manifest['name']} {manifest['version']} (experimental)",
|
||||||
|
"body": notes, "draft": True, "prerelease": True,
|
||||||
|
}).encode())
|
||||||
|
releaseID = release["id"]
|
||||||
|
print(f"Created draft release {releaseID}; upload failures leave it draft for inspection.", flush=True)
|
||||||
|
assetPaths = [path for path, _ in artifacts] + [repoRoot / "dist/SHA256SUMS"]
|
||||||
|
for artifactPath in assetPaths:
|
||||||
|
boundary = "TentacleUpload" + uuid.uuid4().hex
|
||||||
|
header = (f'--{boundary}\r\nContent-Disposition: form-data; name="attachment"; '
|
||||||
|
f'filename="{artifactPath.name}"\r\nContent-Type: application/octet-stream\r\n\r\n').encode()
|
||||||
|
body = header + artifactPath.read_bytes() + f"\r\n--{boundary}--\r\n".encode()
|
||||||
|
route = REPO_API + f"/releases/{releaseID}/assets?" + urllib.parse.urlencode({"name": artifactPath.name})
|
||||||
|
asset = publisher.request("POST", route, body, f"multipart/form-data; boundary={boundary}")
|
||||||
|
if asset["name"] != artifactPath.name or asset["size"] != artifactPath.stat().st_size:
|
||||||
|
raise RuntimeError("Uploaded asset identity or size differs")
|
||||||
|
print(f"Uploaded {artifactPath.name}", flush=True)
|
||||||
|
publisher.request("PATCH", REPO_API + f"/releases/{releaseID}", json.dumps({"draft": False}).encode())
|
||||||
|
verify_downloads(repoRoot, artifacts, tagName)
|
||||||
|
print(f"Published {ORIGIN}/storm/cthulhu-tentacles/releases/tag/{tagName}", flush=True)
|
||||||
|
print("Review and push the prepared catalog to the default branch after these download checks.")
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
parser.add_argument("action", choices=("auth", "publish", "verify"))
|
||||||
|
parser.add_argument("--tentacle", help="One prepared Tentacle ID")
|
||||||
|
parser.add_argument("--notes", type=Path, help="Reviewed release notes file")
|
||||||
|
parser.add_argument("--ssh-key", help="Select a loaded RSA key by its SHA256 fingerprint")
|
||||||
|
args = parser.parse_args()
|
||||||
|
if args.action != "auth" and (not args.tentacle or any(c not in "abcdefghijklmnopqrstuvwxyz0123456789.-" for c in args.tentacle)):
|
||||||
|
parser.error("Select a valid --tentacle ID")
|
||||||
|
if args.action == "publish" and not args.notes:
|
||||||
|
parser.error("Publication requires --notes")
|
||||||
|
repoRoot = Path(__file__).resolve().parents[1]
|
||||||
|
if args.action != "auth":
|
||||||
|
manifest, tagName, artifacts = release_artifacts(repoRoot, args.tentacle)
|
||||||
|
if args.action == "verify":
|
||||||
|
verify_downloads(repoRoot, artifacts, tagName)
|
||||||
|
return
|
||||||
|
publisher = Publisher(args.ssh_key)
|
||||||
|
try:
|
||||||
|
publisher.authenticate()
|
||||||
|
if args.action == "publish":
|
||||||
|
publish(publisher, repoRoot, manifest, tagName, artifacts, args.notes)
|
||||||
|
finally:
|
||||||
|
publisher.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
# Copyright (c) 2026 Storm Dragon
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
"""Offline checks for release authentication and publication guards."""
|
||||||
|
|
||||||
|
import base64
|
||||||
|
import hashlib
|
||||||
|
import io
|
||||||
|
import re
|
||||||
|
from types import SimpleNamespace
|
||||||
|
import unittest
|
||||||
|
from unittest.mock import Mock, patch
|
||||||
|
import urllib.error
|
||||||
|
|
||||||
|
import paramiko
|
||||||
|
|
||||||
|
import publish
|
||||||
|
|
||||||
|
|
||||||
|
class PublisherTests(unittest.TestCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
cls.signingKey = paramiko.RSAKey.generate(1024)
|
||||||
|
|
||||||
|
def make_publisher(self, response=b'{"id":1}'):
|
||||||
|
publisher = publish.Publisher.__new__(publish.Publisher)
|
||||||
|
publisher.key = self.signingKey
|
||||||
|
publisher.fingerprint = publisher.key_fingerprint(self.signingKey)
|
||||||
|
publisher.opener = SimpleNamespace(open=Mock(return_value=io.BytesIO(response)))
|
||||||
|
return publisher
|
||||||
|
|
||||||
|
def test_upload_signature_authenticates_body_and_query(self):
|
||||||
|
publisher = self.make_publisher()
|
||||||
|
route = publish.REPO_API + "/releases/1/assets?name=example.tar.gz"
|
||||||
|
body = b"example release content"
|
||||||
|
with patch.object(publish.time, "time", return_value=1000):
|
||||||
|
self.assertEqual(publisher.request("POST", route, body), {"id": 1})
|
||||||
|
request = publisher.opener.open.call_args.args[0]
|
||||||
|
fields = dict(re.findall(r'(\w+)="([^"]*)"', request.get_header("Signature")))
|
||||||
|
digest = "SHA-512=" + base64.b64encode(hashlib.sha512(body).digest()).decode()
|
||||||
|
expected = (f"(request-target): post {route}\n(created): 1000\n(expires): 1030\ndigest: {digest}").encode()
|
||||||
|
signature = paramiko.Message()
|
||||||
|
signature.add_string("rsa-sha2-256")
|
||||||
|
signature.add_string(base64.b64decode(fields["signature"]))
|
||||||
|
self.assertTrue(self.signingKey.verify_ssh_sig(expected, paramiko.Message(signature.asbytes())))
|
||||||
|
self.assertFalse(self.signingKey.verify_ssh_sig(expected + b"changed", paramiko.Message(signature.asbytes())))
|
||||||
|
self.assertEqual(request.data, body)
|
||||||
|
self.assertEqual(request.get_header("Digest"), digest)
|
||||||
|
self.assertEqual(fields["headers"], "(request-target) (created) (expires) digest")
|
||||||
|
|
||||||
|
def test_repository_boundary_rejects_requests_before_signing(self):
|
||||||
|
publisher = self.make_publisher()
|
||||||
|
for method, route in (("GET", "https://example.org/"), ("DELETE", publish.REPO_API),
|
||||||
|
("POST", "/api/v1/user"), ("GET", publish.REPO_API + "-other"),
|
||||||
|
("GET", publish.REPO_API + "/../other")):
|
||||||
|
with self.subTest(method=method, route=route), self.assertRaises(RuntimeError):
|
||||||
|
publisher.request(method, route)
|
||||||
|
publisher.opener.open.assert_not_called()
|
||||||
|
|
||||||
|
def test_signed_requests_never_follow_redirects(self):
|
||||||
|
with self.assertRaisesRegex(RuntimeError, "redirect"):
|
||||||
|
publish.NoRedirect().redirect_request(None, None, 302, None, None, "https://example.org/")
|
||||||
|
with self.assertRaisesRegex(RuntimeError, "HTTPS"):
|
||||||
|
publish.HTTPSRedirect().redirect_request(None, None, 302, None, None, "http://example.org/")
|
||||||
|
|
||||||
|
def test_missing_release_is_distinct_from_failed_authentication(self):
|
||||||
|
publisher = self.make_publisher()
|
||||||
|
route = publish.REPO_API + "/releases/tags/example-v0.1.0"
|
||||||
|
for status in (401, 403, 404):
|
||||||
|
publisher.opener.open.side_effect = urllib.error.HTTPError(publish.ORIGIN + route, status, "", {}, None)
|
||||||
|
if status == 404:
|
||||||
|
self.assertIsNone(publisher.request("GET", route, allowMissing=True))
|
||||||
|
else:
|
||||||
|
with self.assertRaisesRegex(RuntimeError, f"HTTP {status}"):
|
||||||
|
publisher.request("GET", route, allowMissing=True)
|
||||||
|
|
||||||
|
def test_ambiguous_agent_keys_require_explicit_selection(self):
|
||||||
|
agent = Mock()
|
||||||
|
agent.get_keys.return_value = [self.signingKey, self.signingKey]
|
||||||
|
with patch.object(publish.paramiko, "Agent", return_value=agent):
|
||||||
|
with self.assertRaisesRegex(RuntimeError, "select it"):
|
||||||
|
publish.Publisher()
|
||||||
|
agent.close.assert_called_once()
|
||||||
|
|
||||||
|
def test_existing_release_cannot_be_overwritten(self):
|
||||||
|
publisher = self.make_publisher()
|
||||||
|
publisher.request = Mock(return_value={"id": 1})
|
||||||
|
notesPath = Mock()
|
||||||
|
notesPath.read_text.return_value = "Example release notes"
|
||||||
|
responses = [b"", "a" * 40, "a" * 40 + "\trefs/tags/example-v0.1.0\n"]
|
||||||
|
with patch.object(publish.subprocess, "check_output", side_effect=responses):
|
||||||
|
with self.assertRaisesRegex(RuntimeError, "already exists"):
|
||||||
|
publish.publish(publisher, Mock(), {}, "example-v0.1.0", [], notesPath)
|
||||||
|
self.assertEqual(publisher.request.call_count, 1)
|
||||||
|
self.assertEqual(publisher.request.call_args.args[0], "GET")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user