chore: fix the clippy gate, guard the vault version, add CI (I3)
This commit is contained in:
14 files changed
+205
-47
No files matched your search
@@ -0,0 +1,53 @@
|
||||
# Continuous integration for Regent (Gitea Actions).
|
||||
#
|
||||
# The build needs the GTK 4 / libadwaita development headers (cargo compiles the
|
||||
# crate, it does not run the Meson UI build). The Rust toolchain is pinned: the
|
||||
# `clippy -- -D warnings` gate is calibrated to a specific compiler, so a moving
|
||||
# `stable` would reintroduce lint drift. `cargo-deny` fetches the RustSec advisory
|
||||
# database at run time, so the job needs network.
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install the GTK/libadwaita build dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends \
|
||||
build-essential pkg-config libgtk-4-dev libadwaita-1-dev
|
||||
|
||||
- name: Install Rust (pinned)
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: 1.99.1
|
||||
components: clippy
|
||||
|
||||
- name: Cache cargo
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
target
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
|
||||
|
||||
- name: Test
|
||||
run: cargo test --locked
|
||||
|
||||
- name: Clippy
|
||||
run: cargo clippy --all-targets --locked -- -D warnings
|
||||
|
||||
- name: Install cargo-deny
|
||||
uses: taiki-e/install-action@v2
|
||||
with:
|
||||
tool: cargo-deny
|
||||
|
||||
- name: cargo-deny
|
||||
run: cargo deny check
|
||||
@@ -704,7 +704,9 @@ data/ desktop, metainfo, gschema (all `.in` templates), icons, re
|
||||
`result` is the client's secret, p-tagged to the client and signed by the
|
||||
device key. Running `--pair` is the consent; permissions are never
|
||||
auto-granted, and the URI/secret are never printed or logged. `--pair -` reads
|
||||
the URI from **stdin** (I1), so it need not appear in `argv` or history. Client-supplied
|
||||
the URI from **stdin** (I1), so it need not appear in `argv` or history. The
|
||||
`bunker://` query is percent-encoded with `url::form_urlencoded` (I3), so a
|
||||
relay URL cannot smuggle a second query parameter. Client-supplied
|
||||
relays are **`wss://` only and at most `MAX_CLIENT_RELAYS` (5)**, and a literal
|
||||
IP that is not globally routable is refused — a `ws://` or `169.254.x`/loopback
|
||||
relay would otherwise turn a hostile URI into a local-network probe. The
|
||||
@@ -805,7 +807,10 @@ data/ desktop, metainfo, gschema (all `.in` templates), icons, re
|
||||
and renamed over the target, a corrupt file moved to a timestamped
|
||||
`keys.json.corrupt.<secs>.<nanos>` so a second corruption does not erase the
|
||||
first). It holds `version`, an optional plaintext `device` nsec,
|
||||
and `keys: [{pubkey, name, ncryptsec}]`. There is **no Secret Service and no
|
||||
and `keys: [{pubkey, name, ncryptsec}]`. A `version` **above 1** is refused
|
||||
**in place** (left on disk, not quarantined — a newer vault is intact, not
|
||||
corrupt), so an older Regent never silently downgrades it. There is **no
|
||||
Secret Service and no
|
||||
`oo7`** dependency: the login keyring was never at-rest protection (unlocked at
|
||||
login for the whole session, keyed off the login password). The data, config
|
||||
and cache directories — and the lock file's directory — are created **0700**
|
||||
@@ -1291,6 +1296,11 @@ the UI is tested. `build-aux/deploy-dev.sh` runs on the build host,
|
||||
|
||||
## Testing
|
||||
|
||||
- **CI** (`.gitea/workflows/ci.yaml`, Gitea Actions) runs `cargo test --locked`,
|
||||
`cargo clippy --all-targets --locked -- -D warnings` and `cargo deny check`
|
||||
(`deny.toml`); the toolchain is pinned because the `-D warnings` gate is
|
||||
calibrated to a compiler, and `cargo-deny` fetches the advisory database at run
|
||||
time. Clippy is **clean** at the pinned version — keep it that way.
|
||||
- Against a real relay — the path that actually matters, and the only one that
|
||||
exposes the two subscription traps above:
|
||||
```sh
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<key name="load-app-icons" type="b">
|
||||
<default>true</default>
|
||||
<summary>Load application icons</summary>
|
||||
<description>Fetch and show the icon an application declares in its pairing metadata, from the application's own server, after you approve it. Turning this off stops all icon fetches and leaves the initials in place.</description>
|
||||
<description>Fetch and show the icon an application declares in its pairing metadata, from the application's own server. While this is on, the icon is also fetched during pairing, before you approve the application, so the dialog can show it. Turning this off stops all icon fetches and leaves the initials in place.</description>
|
||||
</key>
|
||||
<key name="close-action" type="s">
|
||||
<default>'ask'</default>
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
[graph]
|
||||
# Check the dependency graph as the release build sees it.
|
||||
all-features = false
|
||||
|
||||
[advisories]
|
||||
version = 2
|
||||
# Add an id here only with a comment explaining why it cannot be fixed.
|
||||
ignore = []
|
||||
|
||||
[licenses]
|
||||
version = 2
|
||||
# Our own crate is `publish = false` (Unlicense); the allow-list gates the
|
||||
# dependency tree, so keep it to permissive licenses that cover it.
|
||||
allow = [
|
||||
"0BSD",
|
||||
"Apache-2.0",
|
||||
"Apache-2.0 WITH LLVM-exception",
|
||||
"BSD-2-Clause",
|
||||
"BSD-3-Clause",
|
||||
"BSL-1.0",
|
||||
"CC0-1.0",
|
||||
"CDLA-Permissive-2.0",
|
||||
"ISC",
|
||||
"MIT",
|
||||
"MIT-0",
|
||||
"MPL-2.0",
|
||||
"OpenSSL",
|
||||
"Unicode-3.0",
|
||||
"Unicode-DFS-2016",
|
||||
"Unlicense",
|
||||
"Zlib",
|
||||
]
|
||||
confidence-threshold = 0.9
|
||||
|
||||
[bans]
|
||||
multiple-versions = "warn"
|
||||
|
||||
[sources]
|
||||
unknown-registry = "deny"
|
||||
unknown-git = "deny"
|
||||
+1
-1
@@ -58,7 +58,7 @@ fn request(autostart: bool, commandline: Vec<String>) -> Result<(), String> {
|
||||
)
|
||||
.map_err(|error| error.to_string())?;
|
||||
|
||||
let _: (String,) = reply
|
||||
let _: (glib::variant::ObjectPath,) = reply
|
||||
.get()
|
||||
.ok_or("the portal returned an unexpected reply")?;
|
||||
Ok(())
|
||||
|
||||
+4
-1
@@ -32,6 +32,9 @@ pub enum Status {
|
||||
|
||||
type Listener = Rc<dyn Fn()>;
|
||||
|
||||
/// The callback `start` runs once the signer is up (or failed to start).
|
||||
type StartedCallback = Box<dyn FnOnce(Result<Arc<Signer>, String>)>;
|
||||
|
||||
pub struct SignerRunner {
|
||||
state: Rc<AppState>,
|
||||
/// The main window: the drain presents it for a prompt and hides it again
|
||||
@@ -158,7 +161,7 @@ impl SignerRunner {
|
||||
pub fn start(
|
||||
self: &Rc<Self>,
|
||||
extra: Vec<String>,
|
||||
after: Option<Box<dyn FnOnce(Result<Arc<Signer>, String>)>>,
|
||||
after: Option<StartedCallback>,
|
||||
) {
|
||||
// No key, no responder: starting one would leave the approval drain
|
||||
// parented to a hidden window. The key listener and the toggle both
|
||||
|
||||
+30
-13
@@ -782,15 +782,12 @@ pub fn bunker_uri(device: &PublicKey, relays: &[String], secret: &str) -> String
|
||||
format!("bunker://{}?{}&secret={}", device.to_hex(), relays, secret)
|
||||
}
|
||||
|
||||
/// Percent-encode one component of the `bunker://` query.
|
||||
///
|
||||
/// `form_urlencoded` encodes `&`, `=`, `%` and every non-unreserved byte, so a
|
||||
/// relay URL cannot smuggle a second query parameter or break the value.
|
||||
fn percent_encode(value: &str) -> String {
|
||||
value
|
||||
.chars()
|
||||
.map(|c| match c {
|
||||
':' => "%3A".to_string(),
|
||||
'/' => "%2F".to_string(),
|
||||
_ => c.to_string(),
|
||||
})
|
||||
.collect()
|
||||
url::form_urlencoded::byte_serialize(value.as_bytes()).collect()
|
||||
}
|
||||
|
||||
fn random_secret() -> String {
|
||||
@@ -3156,6 +3153,25 @@ mod tests {
|
||||
assert!(parse_client_uri("https://example.com").is_err());
|
||||
}
|
||||
|
||||
/// The `bunker://` query percent-encodes each relay component, so a relay
|
||||
/// URL with `&`/`=`/`?` cannot smuggle a second parameter or break the value
|
||||
/// (I3).
|
||||
#[test]
|
||||
fn a_bunker_uri_encodes_its_relays() {
|
||||
let device = Keys::generate().public_key();
|
||||
let uri = bunker_uri(
|
||||
&device,
|
||||
&["wss://relay.example.com/path?a=1&b=2".to_string()],
|
||||
"s3cret",
|
||||
);
|
||||
assert!(uri.starts_with(&format!("bunker://{}?relay=", device.to_hex())));
|
||||
assert!(
|
||||
uri.contains("relay=wss%3A%2F%2Frelay.example.com%2Fpath%3Fa%3D1%26b%3D2"),
|
||||
"{uri}"
|
||||
);
|
||||
assert!(uri.ends_with("&secret=s3cret"), "{uri}");
|
||||
}
|
||||
|
||||
/// A client-supplied relay is refused when it is plaintext or points at a
|
||||
/// non-public literal address — unless the test override is active. This is
|
||||
/// the pure policy behind `parse_client_uri` (M3).
|
||||
@@ -3537,7 +3553,7 @@ mod tests {
|
||||
|
||||
let added = RelayUrl::parse(&relay_b.relay).expect("relay url");
|
||||
signer
|
||||
.add_client_relays(&[added.clone()])
|
||||
.add_client_relays(std::slice::from_ref(&added))
|
||||
.await
|
||||
.expect("add the client relay");
|
||||
|
||||
@@ -3570,10 +3586,11 @@ mod tests {
|
||||
|
||||
let response = tokio::time::timeout(Duration::from_secs(10), async {
|
||||
while let Some(notification) = notifications.next().await {
|
||||
if let ClientNotification::Event { event, .. } = notification {
|
||||
if event.kind == Kind::NostrConnect && event.pubkey == device {
|
||||
return Some(event);
|
||||
}
|
||||
if let ClientNotification::Event { event, .. } = notification
|
||||
&& event.kind == Kind::NostrConnect
|
||||
&& event.pubkey == device
|
||||
{
|
||||
return Some(event);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
||||
+8
-8
@@ -488,14 +488,14 @@ impl AppState {
|
||||
async move { crate::store::icons::fetch(&fetch_url).await },
|
||||
move |result| {
|
||||
icons.end_preview(&key, &url);
|
||||
if let Ok(bytes) = result {
|
||||
if let Ok(texture) = crate::store::icons::decode(&bytes) {
|
||||
// Deliberately **not** cached: this is a pre-consent
|
||||
// fetch for an unapproved client, so a denial must leave
|
||||
// no texture behind (and repeated prompts must not leak
|
||||
// memory). The texture lives only as long as the dialog.
|
||||
apply(texture);
|
||||
}
|
||||
if let Ok(bytes) = result
|
||||
&& let Ok(texture) = crate::store::icons::decode(&bytes)
|
||||
{
|
||||
// Deliberately **not** cached: this is a pre-consent
|
||||
// fetch for an unapproved client, so a denial must leave
|
||||
// no texture behind (and repeated prompts must not leak
|
||||
// memory). The texture lives only as long as the dialog.
|
||||
apply(texture);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
+3
-4
@@ -149,10 +149,9 @@ pub async fn fetch_https(url: &str, expect: Content) -> Result<Vec<u8>> {
|
||||
.headers()
|
||||
.get(reqwest::header::CONTENT_TYPE)
|
||||
.and_then(|value| value.to_str().ok())
|
||||
&& !content_type.starts_with("image/")
|
||||
{
|
||||
if !content_type.starts_with("image/") {
|
||||
return Err("the server did not send an image".to_string());
|
||||
}
|
||||
return Err("the server did not send an image".to_string());
|
||||
}
|
||||
|
||||
return read_capped(response).await;
|
||||
@@ -912,7 +911,7 @@ mod tests {
|
||||
store.store(&live, url, b"x");
|
||||
store.store(&dead, url, b"x");
|
||||
|
||||
store.gc(&[live.clone()]);
|
||||
store.gc(std::slice::from_ref(&live));
|
||||
assert!(
|
||||
dir.join(format!("{live}.img")).exists(),
|
||||
"the live key is kept"
|
||||
|
||||
@@ -148,6 +148,19 @@ impl KeyStore {
|
||||
}
|
||||
};
|
||||
|
||||
// A future vault version is intact, not corrupt: refuse to run rather
|
||||
// than silently downgrade it — and do **not** move it to
|
||||
// `keys.json.corrupt.*` (that is for an unreadable file). A missing or
|
||||
// older version (0, the serde default) still loads.
|
||||
if vault.version > 1 {
|
||||
return Err(format!(
|
||||
"{} was written by a newer Regent (version {}); refusing to downgrade it",
|
||||
path.display(),
|
||||
vault.version
|
||||
)
|
||||
.into());
|
||||
}
|
||||
|
||||
let device = vault
|
||||
.device
|
||||
.as_deref()
|
||||
@@ -888,6 +901,30 @@ mod tests {
|
||||
let _ = std::fs::remove_dir_all(path.parent().unwrap());
|
||||
}
|
||||
|
||||
/// A vault written by a newer Regent is refused **in place** — not
|
||||
/// quarantined (it is intact) and not downgraded (I3).
|
||||
#[tokio::test]
|
||||
async fn a_future_vault_version_is_refused_without_quarantine() {
|
||||
let (path, store) = scratch();
|
||||
store.generate_user_key("Work", "hunter2").await.expect("generate");
|
||||
|
||||
let mut vault: serde_json::Value =
|
||||
serde_json::from_str(&std::fs::read_to_string(&path).expect("read")).expect("parse");
|
||||
vault["version"] = serde_json::Value::from(2u64);
|
||||
std::fs::write(&path, serde_json::to_string(&vault).expect("serialize")).expect("write");
|
||||
|
||||
let error = KeyStore::at(path.clone())
|
||||
.err()
|
||||
.expect("must refuse a newer version");
|
||||
assert!(error.to_string().contains("newer Regent"), "got: {error}");
|
||||
assert!(path.exists(), "the vault is left in place");
|
||||
assert!(
|
||||
corrupt_backups(&path).is_empty(),
|
||||
"a newer vault is not quarantined as corrupt"
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(path.parent().unwrap());
|
||||
}
|
||||
|
||||
/// The auto-lock timeout is measured from the unlock: under it, no lock; at
|
||||
/// it, lock. Zero means never, and a clock anomaly does not lock.
|
||||
#[test]
|
||||
|
||||
+8
-8
@@ -290,7 +290,7 @@ fn name_entry(question: &Question) -> Option<adw::EntryRow> {
|
||||
.name
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.map_or(true, str::is_empty);
|
||||
.is_none_or(str::is_empty);
|
||||
(paired && unnamed).then(|| adw::EntryRow::builder().title("Name").build())
|
||||
}
|
||||
|
||||
@@ -739,13 +739,13 @@ fn application_field(state: &Rc<AppState>, client: &ClientInfo) -> gtk::Box {
|
||||
.build();
|
||||
let texture = state.icons().texture(&public_key);
|
||||
let avatar = plain::avatar(32, name, texture.as_ref());
|
||||
if texture.is_none() {
|
||||
if let Some(image) = client.image.as_deref() {
|
||||
let avatar = avatar.clone();
|
||||
state.preview_icon(&public_key, image, move |texture| {
|
||||
avatar.set_custom_image(Some(&texture));
|
||||
});
|
||||
}
|
||||
if texture.is_none()
|
||||
&& let Some(image) = client.image.as_deref()
|
||||
{
|
||||
let avatar = avatar.clone();
|
||||
state.preview_icon(&public_key, image, move |texture| {
|
||||
avatar.set_custom_image(Some(&texture));
|
||||
});
|
||||
}
|
||||
|
||||
let label = match name {
|
||||
|
||||
+3
-4
@@ -313,10 +313,9 @@ impl Ui {
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|name| !name.is_empty()),
|
||||
) {
|
||||
if label != declared {
|
||||
row.add_row(&plain::row("Declared name", declared));
|
||||
}
|
||||
) && label != declared
|
||||
{
|
||||
row.add_row(&plain::row("Declared name", declared));
|
||||
}
|
||||
|
||||
// Which identity this app signs as. This is the binding the responder
|
||||
|
||||
+4
-4
@@ -220,10 +220,10 @@ impl ConnectDialog {
|
||||
{
|
||||
let listener = Rc::clone(&connect);
|
||||
copy.connect_clicked(move |_| {
|
||||
if let Some(uri) = listener.runner.bunker_uri() {
|
||||
if let Some(window) = listener.window() {
|
||||
plain::copy_secret(&window.clipboard(), &uri);
|
||||
}
|
||||
if let Some(uri) = listener.runner.bunker_uri()
|
||||
&& let Some(window) = listener.window()
|
||||
{
|
||||
plain::copy_secret(&window.clipboard(), &uri);
|
||||
}
|
||||
listener
|
||||
.overlay
|
||||
|
||||
@@ -521,7 +521,7 @@ impl Preferences {
|
||||
if passphrase.chars().count() < 8 {
|
||||
return preferences.error("Use a passphrase of at least 8 characters.");
|
||||
}
|
||||
if confirm.text().to_string() != passphrase {
|
||||
if confirm.text() != passphrase {
|
||||
return preferences.error("The two passphrases do not match.");
|
||||
}
|
||||
// Wipe the fields; the new passphrase must not linger in a widget.
|
||||
|
||||
Reference in new issue
Block a user