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>
This commit is contained in:
Jorijn van der Graaf 2026-11-19 16:09:48 +01:00
commit 2e3739ff7a
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
23 changed files with 488 additions and 209 deletions

View file

@ -31,8 +31,12 @@ using namespace Crafter;
namespace fs = std::filesystem;
// One user's worker. Every call is read and checked first (the account, the counterparty, what is to be paid), then
// polkit decides with a summary built from the worker's own data, and only then does the call run. The wire carries
// bunq's types, so the worker works with bunq's connector directly.
// polkit decides with a summary built from the worker's own data, and only then does the call run. On nostrod's own
// interface nothing of the user's is read, and the bank is asked nothing, for a caller polkit has not said yes to: a
// call that must look something up to word its question asks first whether the caller may see the accounts
// (HandleLookup). The checkout is the one that reads before it asks: an order it knows is answered from its record,
// and the account that pays a new one is chosen for the dialog to name (OnPay). The wire carries bunq's types, so the
// worker works with bunq's connector directly.
namespace {
using Work = std::function<void(sd_bus_message* reply)>;
@ -161,6 +165,13 @@ namespace {
} catch(const std::exception& e) {
message = e.what();
}
// The connector says which call went wrong, "bunq POST /user/…/monetary-account/…/payment: …", and that names
// the user and the account at the bank. An app at checkout never sees the account, so it is told what the bank
// said and whether the payment may have been made all the same, and not what was asked of the bank.
const std::size_t said = message.find(": ");
if(Interface(call) == Checkout::interfaceName && message.starts_with("bunq ") && said != std::string::npos) {
message.replace(0, said, "bunq");
}
return ErrorReply(call, name, message);
}
@ -168,16 +179,46 @@ namespace {
sd_bus_send(nullptr, answer.get(), nullptr);
}
// Text from a caller or a bank, made fit for a password dialog: no control, zero-width or direction-changing
// characters, nothing a dialog could take for markup or polkit for one of its $(…) fields, and at most 64
// characters, so a long name cannot push what matters out of sight.
std::string Shown(std::string_view text) {
std::string out;
std::size_t characters = 0;
// The most a password dialog shows of a name, a description or a reference, in characters; and of an address,
// which it shows whole: the longest an e-mail address gets.
constexpr std::size_t shownLimit = 64;
constexpr std::size_t addressLimit = 254;
using Range = std::pair<std::uint32_t, std::uint32_t>;
// What draws nothing, or tells the reader's own text where to go: control and format characters, the line and
// paragraph separators, what Unicode leaves out of a display by default (soft hyphens, joiners, fillers, variation
// selectors, tags), surrogates, private use, and what is no character at all.
constexpr std::array<Range, 31> unshown = {{
{0x0000, 0x001F}, {0x007F, 0x009F}, {0x00AD, 0x00AD}, {0x034F, 0x034F}, {0x0600, 0x0605}, {0x061C, 0x061C}, {0x06DD, 0x06DD}, {0x070F, 0x070F},
{0x0890, 0x0891}, {0x08E2, 0x08E2}, {0x115F, 0x1160}, {0x17B4, 0x17B5}, {0x180B, 0x180F}, {0x200B, 0x200F}, {0x2028, 0x202E}, {0x2060, 0x206F},
{0x3164, 0x3164}, {0xD800, 0xF8FF}, {0xFDD0, 0xFDEF}, {0xFE00, 0xFE0F}, {0xFEFF, 0xFEFF}, {0xFFA0, 0xFFA0}, {0xFFF0, 0xFFFC}, {0xFFFE, 0xFFFF},
{0x110BD, 0x110BD}, {0x110CD, 0x110CD}, {0x13430, 0x1343F}, {0x1BCA0, 0x1BCA3}, {0x1D173, 0x1D17A}, {0xE0000, 0xE0FFF}, {0xF0000, 0xFFFFFFFF},
}};
// A space of any width, and the Braille pattern without a dot, which is one to the eye.
constexpr std::array<Range, 8> blank = {{
{0x0020, 0x0020}, {0x00A0, 0x00A0}, {0x1680, 0x1680}, {0x2000, 0x200A}, {0x202F, 0x202F}, {0x205F, 0x205F}, {0x2800, 0x2800}, {0x3000, 0x3000},
}};
bool Among(std::span<const Range> ranges, std::uint32_t code) {
return std::ranges::any_of(ranges, [code](const Range& range) { return code >= range.first && code <= range.second; });
}
// Text from a caller or a bank, made fit for a password dialog, which is where the user reads what a password is
// for. Nothing of `unshown`, so no text hides, turns around or starts a line of its own; a space of any kind is one
// plain space, and none leads or trails, so none pushes what follows onto another line; nothing a dialog could take
// for markup, or polkit for one of its $(…) fields; and at most `limit` characters, so a long name cannot push what
// matters out of sight. An & goes with < and >: an agent that reads its message as Pango markup, as GNOME's older
// one and MATE's do, shows nothing at all of a message with a bare & in it, the amount included.
std::string Shown(std::string_view text, std::size_t limit = shownLimit) {
// Each character as it is shown, up to the first that does not fit, which is there to say that there is more.
std::vector<std::string_view> shown;
bool spaced = false;
std::size_t i = 0;
// The text is UTF-8: D-Bus carries nothing else, and nlohmann's parser takes nothing else from the bank. A
// sequence is still never read past the end.
while(i < text.size()) {
while(i < text.size() && shown.size() <= limit) {
const std::uint8_t lead = static_cast<std::uint8_t>(text[i]);
const std::size_t length = std::min<std::size_t>(lead < 0x80 ? 1 : lead < 0xE0 ? 2 : lead < 0xF0 ? 3 : 4, text.size() - i);
std::uint32_t code = length == 1 ? lead : lead & (0xFF >> (length + 1));
@ -186,25 +227,25 @@ namespace {
}
const std::string_view character = text.substr(i, length);
i += length;
const bool hidden = code < 0x20 || code == 0x7F || (code >= 0x80 && code < 0xA0) || (code >= 0x200B && code <= 0x200F) || (code >= 0x202A && code <= 0x202E) || (code >= 0x2060 && code <= 0x2069) || code == 0xFEFF;
if(hidden) {
if(Among(unshown, code)) {
continue;
}
if(characters == 64) {
out += "…";
break;
if(Among(blank, code)) {
spaced = !shown.empty();
continue;
}
characters++;
if(code == '<') {
out += "‹";
} else if(code == '>') {
out += "›";
} else {
if(code == '(' && out.ends_with('$')) {
out += ' ';
}
out += character;
// The one space that stands for however many there were; and one that keeps a $ and a ( apart.
if(std::exchange(spaced, false) || (code == '(' && !shown.empty() && shown.back() == "$")) {
shown.emplace_back(" ");
}
shown.push_back(code == '<' ? "‹" : code == '>' ? "›" : code == '&' ? "+" : character);
}
std::string out;
for(const std::string_view piece : shown | std::views::take(limit)) {
out += piece;
}
if(shown.size() > limit) {
out += "…";
}
return out;
}
@ -223,9 +264,21 @@ namespace {
throw std::invalid_argument(std::format("unknown environment '{}': production or sandbox", name));
}
// Who a caller wants paid or asked. The address is what decides where the money goes, so the dialog shows it whole
// and as it is, or the call is refused before anyone is asked: an address that would read otherwise there than it
// is (one with an & reads as one with a +, which is somebody else's) could have the user confirm a payment to
// someone they did not mean. A name is only made fit to show.
BunqCounterparty Counterparty(std::string_view value, std::string_view name) {
BunqCounterparty party = BunqCounterparty::Parse(value, name);
if(Shown(party.value, addressLimit) != party.value) {
throw std::invalid_argument(std::format("'{}' cannot be paid or asked through nostro: the password dialog would not show that address as it is, since it holds an &, a <, a > or a $(, something that draws nothing, or more than {} characters", Shown(party.value), addressLimit));
}
return party;
}
// Who is paid or asked, as a dialog shows it: the address first, so a long name cannot hide it.
std::string Party(const BunqCounterparty& party) {
return party.name.empty() ? Shown(party.value) : std::format("{} ({})", Shown(party.value), Shown(party.name));
return party.name.empty() ? Shown(party.value, addressLimit) : std::format("{} ({})", Shown(party.value, addressLimit), Shown(party.name));
}
std::string Party(const BunqLabel& label) {
@ -278,7 +331,7 @@ namespace {
return {
{"amount_minor", std::to_string(amount)},
{"currency", std::string(GetCurrencyCode(currency))},
{"counterparty", Shown(counterparty)},
{"counterparty", Shown(counterparty, addressLimit)},
{"account_iban", account.iban},
{"environment", std::string(EnvironmentName(account.connector->environment))},
};
@ -346,7 +399,8 @@ namespace {
throw std::invalid_argument(std::format("no account is called or has IBAN '{}'", key));
}
// The user's connectors, read on the first call: the first call also records whose directory this is.
// The user's connectors, read for the first call polkit says yes to, or the first new order at checkout: that call
// also records whose directory this is. Reading them refreshes each one's accounts, which asks the bank.
void Load(Worker& worker) {
if(worker.loaded) {
return;
@ -380,6 +434,8 @@ namespace {
MessagePtr call;
Work work;
After after;
// What a yes is followed by in place of an answer: the rest of a call that asked before it looked (HandleLookup).
std::function<void()> next;
std::string action;
bool interactive = false;
std::string cancellation;
@ -416,6 +472,13 @@ namespace {
Leave(reply);
Leave(reply);
if(authorized) {
// The connectors are read for a caller polkit said yes to, and for no other: reading them asks the bank.
Load(worker);
if(check->next) {
// The call goes on to its own question, and is answered through that one.
check->next();
return 0;
}
answer = Answer(call, check->work);
} else if(challenge && !check->interactive) {
answer = ErrorReply(call, SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED, std::format("{} needs your password, and the call did not let nostrod ask for it", check->action));
@ -435,10 +498,11 @@ namespace {
return 0;
}
// Asks polkit whether the caller may do what `prompt` says, then runs `work` and answers; or answers why not; and
// then runs `after` with the answer. The check does not block: other calls are served while a password dialog is
// open.
std::int32_t Gate(Worker& worker, sd_bus_message* call, const Prompt& prompt, Work work, After after = {}) {
// Asks polkit whether the caller may do what `prompt` says. On a yes it runs `next` when there is one, which
// answers the call itself, and else runs `work` and answers with what that appended; on anything else it answers
// why not. Then it runs `after` with the answer it gave. The check does not block: other calls are served while a
// password dialog is open.
std::int32_t Ask(Worker& worker, sd_bus_message* call, const Prompt& prompt, Work work, After after, std::function<void()> next) {
const bool interactive = sd_bus_message_get_allow_interactive_authorization(call) > 0;
sd_bus_message* raw = nullptr;
ThrowOnSdBus(sd_bus_message_new_method_call(worker.system.get(), &raw, "org.freedesktop.PolicyKit1", "/org/freedesktop/PolicyKit1/Authority", "org.freedesktop.PolicyKit1.Authority", "CheckAuthorization"), "ask polkit");
@ -472,7 +536,7 @@ namespace {
std::string cancellation = std::format("nostro-{}-{}", getpid(), ++worker.checks);
Append(raw, cancellation);
std::unique_ptr<Check> check = std::make_unique<Check>(&worker, MessagePtr(sd_bus_message_ref(call)), std::move(work), std::move(after), std::string(prompt.action), interactive, std::move(cancellation));
std::unique_ptr<Check> check = std::make_unique<Check>(&worker, MessagePtr(sd_bus_message_ref(call)), std::move(work), std::move(after), std::move(next), std::string(prompt.action), interactive, std::move(cancellation));
ThrowOnSdBus(sd_bus_call_async(worker.system.get(), nullptr, raw, OnChecked, check.get(), Microseconds(worker.options.promptTimeout)), "ask polkit");
// OnChecked owns it now.
check.release();
@ -480,7 +544,14 @@ namespace {
return 1;
}
// Runs `body` for `call`: it answers through Gate, or throws, and then the call is answered with the error.
// Asks polkit whether the caller may do what `prompt` says, then runs `work` and answers; or answers why not; and
// then runs `after` with the answer.
std::int32_t Gate(Worker& worker, sd_bus_message* call, const Prompt& prompt, Work work, After after = {}) {
return Ask(worker, call, prompt, std::move(work), std::move(after), {});
}
// Runs `body` for `call`: it answers through Gate, or throws, and then the call is answered with the error. Nothing
// of the user's is read here: a body reads its arguments and asks polkit, and what it then does runs after a yes.
template<typename Body>
std::int32_t Handle(sd_bus_message* call, void* userdata, Body&& body) {
Worker& worker = *static_cast<Worker*>(userdata);
@ -489,7 +560,6 @@ namespace {
if(worker.refusal) {
throw Refused(*worker.refusal);
}
Load(worker);
return body(worker);
} catch(...) {
Deliver(ErrorFor(call, std::current_exception()));
@ -497,6 +567,21 @@ namespace {
}
}
// Runs `body` for a call that names something of the user's (an account, a card, a request, a draft, a connector)
// and is not a call to see it. Such a call's own question to polkit is worded from what was found, so the body
// looks it up first; and whether it is there is the user's to know, and finding it can take a question to the
// bank. Both are for a caller who may see the user's accounts: polkit is asked that first, as `seen` words it,
// and `body` runs on its yes. An active session has that yes without a dialog, as shipped; where seeing takes a
// password, such a call asks for it twice, once to look and once to act.
template<typename Body>
std::int32_t HandleLookup(sd_bus_message* call, void* userdata, std::string_view seen, Body body) {
return Handle(call, userdata, [call, seen, &body](Worker& worker) {
return Ask(worker, call, Prompt{actionView, std::string(seen), {}}, {}, {}, [&worker, body = std::move(body)] {
body(worker);
});
});
}
std::int32_t OnConnectors(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return Gate(worker, call, Prompt{actionView, "see your bank connectors", {}}, [](sd_bus_message* reply) {
@ -551,7 +636,7 @@ namespace {
}
std::int32_t OnRemoveConnector(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your bank connectors", [call](Worker& worker) {
const std::string key = Read<std::string>(call);
// By name, or by the number Connectors() lists it under.
std::vector<BunqConnector*> matches;
@ -598,9 +683,10 @@ namespace {
return Handle(call, userdata, [call](Worker& worker) {
const std::string account = Read<std::string>(call);
const TransactionQuery query = ReadQuery(call);
const AccountKey key = KeyOf(FindAccount(account));
return Gate(worker, call, Prompt{actionView, "see your transactions", {}}, [key, query](sd_bus_message* reply) {
BunqAccount& found = AccountBy(key);
// The account is looked up once polkit has said yes: whether there is one of that name is for a caller who
// may see the accounts, and finding it can take a question to the bank.
return Gate(worker, call, Prompt{actionView, "see your transactions", {}}, [account, query](sd_bus_message* reply) {
BunqAccount& found = FindAccount(account);
// What is new at the bank first: a call to it, which takes its time and which it counts. Not for a
// question about what is stored alone, as a search in a list just given is: that is answered at once.
if(!query.stored) {
@ -631,11 +717,11 @@ namespace {
};
std::int32_t OnSend(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your accounts and balances", [call](Worker& worker) {
const Payment payment = Payment::Read(call);
const BunqAccount& account = FindAccount(payment.account);
RequirePositive(payment.amount);
const BunqCounterparty payee = BunqCounterparty::Parse(payment.counterparty, payment.name);
const BunqCounterparty payee = Counterparty(payment.counterparty, payment.name);
const Prompt prompt{actionPay, std::format("pay {} to {} from {}", FormatMoney(payment.amount, account.currency), Party(payee), Party(account)), PaymentDetails(account, payment.amount, account.currency, payee.value)};
return Gate(worker, call, prompt, [key = KeyOf(account), payment](sd_bus_message* reply) {
const BunqAccount& found = AccountBy(key);
@ -656,13 +742,13 @@ namespace {
}
std::int32_t OnSchedule(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your accounts and balances", [call](Worker& worker) {
const Payment payment = Payment::Read(call);
const BunqSchedule schedule = Read<BunqSchedule>(call);
const BunqAccount& account = FindAccount(payment.account);
RequirePositive(payment.amount);
schedule.Check();
const BunqCounterparty payee = BunqCounterparty::Parse(payment.counterparty, payment.name);
const BunqCounterparty payee = Counterparty(payment.counterparty, payment.name);
const Prompt prompt{actionPay, std::format("schedule {} to {} from {}, {}", FormatMoney(payment.amount, account.currency), Party(payee), Party(account), When(schedule)), PaymentDetails(account, payment.amount, account.currency, payee.value)};
return Gate(worker, call, prompt, [key = KeyOf(account), payment, schedule](sd_bus_message* reply) {
const BunqAccount& found = AccountBy(key);
@ -673,11 +759,11 @@ namespace {
}
std::int32_t OnRequest(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your accounts and balances", [call](Worker& worker) {
const Payment payment = Payment::Read(call);
const BunqAccount& account = FindAccount(payment.account);
RequirePositive(payment.amount);
const BunqCounterparty payer = BunqCounterparty::Parse(payment.counterparty, payment.name);
const BunqCounterparty payer = Counterparty(payment.counterparty, payment.name);
const Prompt prompt{actionChange, std::format("ask {} for {} into {}", Party(payer), FormatMoney(payment.amount, account.currency), Party(account)), PaymentDetails(account, payment.amount, account.currency, payer.value)};
return Gate(worker, call, prompt, [key = KeyOf(account), payment](sd_bus_message* reply) {
const BunqAccount& found = AccountBy(key);
@ -690,9 +776,10 @@ namespace {
template<typename List>
std::int32_t Listing(sd_bus_message* call, void* userdata, std::string_view what, List list) {
return Handle(call, userdata, [call, what, list](Worker& worker) {
const AccountKey key = KeyOf(FindAccount(Read<std::string>(call)));
return Gate(worker, call, Prompt{actionView, std::format("see your {}", what), {}}, [key, list](sd_bus_message* reply) {
Append(reply, list(AccountBy(key)));
const std::string account = Read<std::string>(call);
// Looked up once polkit has said yes, as in OnTransactions.
return Gate(worker, call, Prompt{actionView, std::format("see your {}", what), {}}, [account, list](sd_bus_message* reply) {
Append(reply, list(FindAccount(account)));
});
});
}
@ -716,7 +803,7 @@ namespace {
// Revoking a request or cancelling a schedule: a change to one object of one account.
template<typename Act>
std::int32_t Undo(sd_bus_message* call, void* userdata, std::string_view what, Act act) {
return Handle(call, userdata, [call, what, act](Worker& worker) {
return HandleLookup(call, userdata, "see your accounts and balances", [call, what, act](Worker& worker) {
const BunqAccount& account = FindAccount(Read<std::string>(call));
const std::uint64_t id = Read<std::uint64_t>(call);
const Prompt prompt{actionChange, std::format("{} {} of {}", what, id, Party(account)), {}};
@ -735,7 +822,7 @@ namespace {
}
std::int32_t OnRespondToRequest(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your incoming requests for money", [call](Worker& worker) {
const BunqAccount& account = FindAccount(Read<std::string>(call));
const std::uint64_t id = Read<std::uint64_t>(call);
const bool accept = Read<bool>(call);
@ -751,11 +838,11 @@ namespace {
}
std::int32_t OnDraft(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your accounts and balances", [call](Worker& worker) {
const Payment payment = Payment::Read(call);
const BunqAccount& account = FindAccount(payment.account);
RequirePositive(payment.amount);
const BunqCounterparty payee = BunqCounterparty::Parse(payment.counterparty, payment.name);
const BunqCounterparty payee = Counterparty(payment.counterparty, payment.name);
const Prompt prompt{actionChange, std::format("make a draft payment of {} to {} from {}, paid once someone accepts it", FormatMoney(payment.amount, account.currency), Party(payee), Party(account)), PaymentDetails(account, payment.amount, account.currency, payee.value)};
return Gate(worker, call, prompt, [key = KeyOf(account), payment](sd_bus_message* reply) {
const BunqAccount& found = AccountBy(key);
@ -766,7 +853,7 @@ namespace {
}
std::int32_t OnRespondToDraftPayment(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your draft payments", [call](Worker& worker) {
const BunqAccount& account = FindAccount(Read<std::string>(call));
const std::uint64_t id = Read<std::uint64_t>(call);
const bool accept = Read<bool>(call);
@ -805,7 +892,7 @@ namespace {
}
std::int32_t OnSetCardStatus(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your cards", [call](Worker& worker) {
const std::uint64_t card = Read<std::uint64_t>(call);
const std::string status = Read<std::string>(call);
// Unfreezing lets the card pay again; a card reported lost or stolen is blocked for good.
@ -872,7 +959,7 @@ namespace {
}
std::int32_t OnSetDefaultCheckoutAccount(sd_bus_message* call, void* userdata, sd_bus_error*) {
return Handle(call, userdata, [call](Worker& worker) {
return HandleLookup(call, userdata, "see your accounts and balances", [call](Worker& worker) {
const BunqAccount& account = FindAccount(Read<std::string>(call));
// bunq lets an OAuth connection pay the user's own accounts only, so through one no shop could be paid.
if(account.connector->IsOAuth()) {
@ -926,10 +1013,11 @@ namespace {
}
};
// One reference to one payee is one order, of one amount.
// One reference to one payee is one order, of one amount. Which amount the order has is not said: any app that
// knows the payee and the reference of an order another app had paid would learn from it what was paid for it.
void RequireSameOrder(std::int64_t amount, Currency currency, const Order& order) {
if(amount != order.amount || currency != order.currency) {
throw std::invalid_argument(std::format("reference {} to {} is an order of {}, not of {}: another order needs another reference", Shown(order.reference), order.payee.value, FormatMoney(amount, currency), FormatMoney(order.amount, order.currency)));
throw std::invalid_argument(std::format("reference {} to {} is an order of another amount than {}: another order needs another reference", Shown(order.reference), order.payee.value, FormatMoney(order.amount, order.currency)));
}
}
@ -1026,6 +1114,9 @@ namespace {
if(AnswerKnownOrder(worker, call, order)) {
return 1;
}
// The account that pays is chosen before the user is asked, since the dialog names it: an order not seen
// before has the connectors read for it, which no call of nostrod's own interface does before polkit's yes.
Load(worker);
// From here on, a call for the same order waits for this one, and Settle answers it.
worker.paying[order.Key()] = Paying{order.amount, order.currency, {}};
ChooseAccount(worker, call, order, [&worker, call, order](const Choice& choice) {