Nostro/implementations/Nostro.App-Errors.cpp
Jorijn van der Graaf 2e3739ff7a
fix: close what the security review before the first release found
A review of the tree and its history before they are published found no
key and no bank data in them. It did find these, each closed here.

The password dialog could be emptied (daemon). Shown(), which makes a
payee's name fit for polkit's dialog, let an & through. GNOME's older
agent (polkit-gnome) and MATE's put the message into Pango markup
unescaped, where a bare & fails to parse and leaves the dialog without
a message: paying "Tom & Jerry", or an order an app names so at
checkout, asked for the password and showed no amount and no payee.
Line and paragraph separators passed too. Shown() now shows & as +,
leaves out what draws nothing or places text (control and format
characters, the separators, what Unicode ignores by default, private
use) and makes any run of spaces one space. An address is held to it
instead of made fit: an e-mail address the dialog could not show
unchanged is refused before anyone is asked, since "a&b@..." shown as
"a+b@..." is somebody else's address.

A refused caller could look (daemon). A call that names an account, a
card, a request, a draft or a connector had it looked up, at the bank
where that takes it, before polkit was asked. So a caller polkit
refused was told whether it was there ("no account is called ..."),
and had the bank asked. Such a call now asks for View first
(HandleLookup), a call that only sees looks its account up after its
yes, and the connectors are read, which refreshes the accounts at the
bank, on the first yes instead of on the first call.

An app at checkout was told too much (checkout). The refusal of an
order's reference with another amount named the amount on record, and
a refusal by the bank carried the call it answered, whose path has the
user's and the account's ids at bunq. Neither does now.

A key typed by hand could be read off the screen (app). The line under
a key field showed how the key begins and its last four characters,
which is every character of it as it is typed. It shows how the key
begins and how long it is.

Every change asks for the password (packaging, app). Change, the
action for what changes something and pays nobody, passed without a
password in an active session, so any program of the user's could
cancel a scheduled payment, ask for money in their name or freeze a
card. It asks now (auth_self), a draft saved and a card frozen
included: only View passes as shipped, and loosening is an
administrator's rule, of which the README has an example. The app says
of every change where it is confirmed (AsksPassword is gone), and the
request form sends on its button as the pay form does: its review
sheet would be a second confirmation of what the dialog confirms.

What is built is what was tested (build). Crafter.Network, Crafter.DB
and Crafter.LintRules are named at the commits the tests ran against.
Crafter.Thread still follows its branch, which Crafter.Network's own
project file names, and so does Crafter.Network in the app's debug
build, where Crafter.Debug names it too and crafter-build refuses a
module built twice. lib/json.hpp was nlohmann/json's develop branch at
95e9a593 less its last newline, and called 3.12.0: it is that file
byte for byte now, and called what it is.

The published contract changes with this, before any release (design
rule 10): an e-mail address the dialog cannot show as it is is
refused, a call that looks something up needs View as well as its own
action, the checkout's errors say less, and the policy asks for the
password for Change. The XML, the policy and ShouldServeEveryUser,
which now holds the policy to its defaults, change together.

Reproduced and verified on the fake bus and the fake bunq. The new
checks of ShouldServeEveryUser fail on the worker of before (50 of
them: the & shown, the lookups answered, the bank asked) and pass now.
crafter-build test (17 tests), lint for the library, the app and the
fake system, and tests/coverage.sh (every line, function and region)
pass. Looked at on the made-up system, 360x760 dp at scale 2, dark, on
KDE Wayland: the key form with a key typed, the request form with its
wait and its result, a card frozen, and About. No picture in the
README shows a screen that changed.

Not tried: bunq's sandbox, a real polkit agent, the Flatpak builds.
The README's example rule ran against a stand-in for polkit's rule
engine only.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-19 16:09:48 +01:00

94 lines
5.3 KiB
C++

// SPDX-License-Identifier: GPL-3.0-only
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
module Nostro.App:Errors_impl;
import std;
import Nostro;
import :Errors;
using namespace Nostro;
using namespace Nostro::App;
std::string_view App::ActionOf(Operation operation) noexcept {
switch(operation) {
case Operation::Send:
case Operation::Schedule:
case Operation::PayRequest:
case Operation::AcceptDraft: return Bus::actionPay;
case Operation::Draft:
case Operation::Request:
case Operation::RevokeRequest:
case Operation::RejectRequest:
case Operation::CancelSchedule:
case Operation::RejectDraft:
case Operation::FreezeCard: return Bus::actionChange;
case Operation::UnfreezeCard: return Bus::actionUnfreezeCard;
case Operation::BlockCard: return Bus::actionBlockCard;
case Operation::AddConnection:
case Operation::RemoveConnection:
case Operation::SetCheckoutAccount: return Bus::actionConnectors;
default: return Bus::actionView;
}
}
bool App::MovesMoney(Operation operation) noexcept {
return ActionOf(operation) == Bus::actionPay;
}
Guidance App::Explain(const std::exception_ptr& error, Operation operation) {
const bool reading = operation == Operation::Load;
const std::string where = MovesMoney(operation) ? "Look at the account's activity before trying again." : "Look at what is there before trying again.";
const auto unknown = [&where, operation](std::string_view said) {
return Guidance{Problem::Unknown, MovesMoney(operation) ? "It may have been paid" : "It may have been done", std::format("No clear answer came back: {}. {}", said, where), true, false};
};
const auto missing = [](std::string_view said) {
return Guidance{Problem::NoService, "Nostro's service is not running", std::format("Nostro keeps your bank connections in a service of its own, nostrod, which is not running and which the system could not start. Install nostrod and its system files as Nostro's README says, then try again. ({})", said), false, true};
};
try {
std::rethrow_exception(error);
} catch(const DaemonMissing& e) {
return missing(e.what());
} catch(const NoSystemBus& e) {
return {Problem::NoService, "The system bus cannot be reached", std::format("Nostro talks to its service, nostrod, over the system bus, and cannot connect to it: {}. Nothing can be shown or done without it.", e.what()), false, true};
} catch(const OutcomeUnknown& e) {
return unknown(e.what());
} catch(const std::invalid_argument& e) {
return {Problem::Input, "That cannot be done", std::format("{}. Nothing was sent.", e.what()), false, false};
} catch(const DaemonError& e) {
if(e.name == Bus::errorCancelled) {
return {Problem::NotConfirmed, "Not confirmed", "Nothing was done. If no password dialog appeared, nothing in this session can ask for your password: the desktop's authentication agent is not running.", false, false};
}
if(e.name == "org.freedesktop.DBus.Error.AccessDenied") {
return {Problem::NotAllowed, "Not allowed", std::format("{}. Nothing was done. Try again, or ask whoever manages this computer.", e.what()), false, reading};
}
if(e.name == "org.freedesktop.DBus.Error.InteractiveAuthorizationRequired") {
return {Problem::CannotAsk, "Could not ask for your password", "nostrod was not allowed to have the system ask for your password, so nothing was done. Nostro's README says how the service is set up.", false, false};
}
if(e.name == Bus::errorOAuthCannotPay) {
// What a bank answers a connection that it lets pay between the user's own accounts only.
return {Problem::OwnAccountsOnly, "This connection cannot pay others", "Your bank lets it pay between your own accounts only. Save the payment as a draft instead, and approve it in your bank's app.", false, false};
}
if(e.name == Bus::errorBank) {
return {Problem::Bank, "The bank refused", e.what(), false, reading};
}
if(e.name.starts_with("org.freedesktop.systemd1.") || e.name.starts_with("org.freedesktop.DBus.Error.Spawn.") || e.name == "org.freedesktop.DBus.Error.NameHasNoOwner") {
return missing(e.what());
}
if(e.name == "org.freedesktop.DBus.Error.NoReply" || e.name == "org.freedesktop.DBus.Error.Timeout") {
return {Problem::Late, "No answer yet", "nostrod took too long to answer, which the bank's own limits can cause. Try again in a moment.", false, true};
}
// nostrod's own word for a payment that ended without a clear answer, such as one its worker died under.
if(e.name == Bus::errorFailed && MovesMoney(operation)) {
return unknown(e.what());
}
return {Problem::Failed, "That did not work", e.what(), false, reading};
} catch(const std::system_error& e) {
// An answer that could not be read, or a connection that broke under the call.
if(!reading) {
return unknown(e.what());
}
return {Problem::Failed, "That did not work", e.what(), false, true};
} catch(const std::exception& e) {
return {Problem::Failed, "That did not work", e.what(), false, reading};
}
}