Skip to content

Commit

Permalink
rpc: checkmessage return an error if pubkey is not found
Browse files Browse the repository at this point in the history
Returning an warning message when the pub key is not specified and there is no node in the graph.

We try to help people that use core lightning as a signer and nothings else.

Changelog-Deprecated: rpc: checkmessage return an error when the pubkey is not specified and it is unknown in the network graph.
  • Loading branch information
vincenzopalazzo authored and cdecker committed Jul 19, 2022
1 parent 5abed48 commit 1d671a2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions common/jsonrpc_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ static const errcode_t DATASTORE_UPDATE_WRONG_GENERATION = 1204;
static const errcode_t DATASTORE_UPDATE_HAS_CHILDREN = 1205;
static const errcode_t DATASTORE_UPDATE_NO_CHILDREN = 1206;

/* Errors from signmessage command */
static const errcode_t SIGNMESSAGE_PUBKEY_NOT_FOUND = 1301;

/* Errors from wait* commands */
static const errcode_t WAIT_TIMEOUT = 2000;

Expand Down
4 changes: 4 additions & 0 deletions doc/lightning-checkmessage.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ known node key (as per *listnodes*), and verification succeeds if it
matches for any one of them. Note: this is implemented far more
efficiently than trying each one, so performance is not a concern.

On failure, an error is returned and core lightning exit with the following error code:
- -32602: Parameter missed or malformed;
- 1301: *pubkey* not found in the graph.

RETURN VALUE
------------

Expand Down
7 changes: 7 additions & 0 deletions lightningd/signmessage.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "config.h"
#include <common/bech32.h>
#include <common/configdir.h>
#include <common/json_command.h>
#include <common/json_param.h>
#include <errno.h>
Expand Down Expand Up @@ -133,6 +134,12 @@ static void listnodes_done(const char *buffer,
if (t)
t = json_get_member(buffer, t, "nodes");

if (!deprecated_apis && (!t || t->size == 0)) {
was_pending(command_fail(can->cmd, SIGNMESSAGE_PUBKEY_NOT_FOUND,
"pub key not found in the graph, expected pubkey is %s",
node_id_to_hexstr(tmpctx, &can->id)));
return;
}
response = json_stream_success(can->cmd);
json_add_node_id(response, "pubkey", &can->id);
json_add_bool(response, "verified", t && t->size == 1);
Expand Down
18 changes: 17 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,8 @@ def test_relative_config_dir(node_factory):


def test_signmessage(node_factory):
l1, l2 = node_factory.line_graph(2, wait_for_announce=True)
l1, l2 = node_factory.line_graph(2, wait_for_announce=True,
opts={'allow-deprecated-apis': True})

corpus = [[None,
"this is a test!",
Expand Down Expand Up @@ -2712,3 +2713,18 @@ def test_torv2_in_db(node_factory):
l1.stop()
l1.db_manip("UPDATE peers SET address='3fyb44wdhnd2ghhl.onion:1234';")
l1.start()


def test_checkmessage_pubkey_not_found(node_factory):
l1 = node_factory.get_node()

msg = "testcase to check new rpc error"
pubkey = "03be3b0e9992153b1d5a6e1623670b6c3663f72ce6cf2e0dd39c0a373a7de5a3b7"
zbase = "d66bqz3qsku5fxtqsi37j11pci47ydxa95iusphutggz9ezaxt56neh77kxe5hyr41kwgkncgiu94p9ecxiexgpgsz8daoq4tw8kj8yx"

with pytest.raises(RpcError, match="not found in the graph, expected pubkey is {}".format(pubkey)):
l1.rpc.checkmessage(msg, zbase)

check_result = l1.rpc.checkmessage(msg, zbase, pubkey=pubkey)
assert check_result["pubkey"] == pubkey
assert check_result["verified"] is True

0 comments on commit 1d671a2

Please sign in to comment.