lightningd: new runes infrastructure.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
c4e84bcbe2
commit
9177084505
|
@ -37,6 +37,7 @@ LIGHTNINGD_SRC := \
|
||||||
lightningd/plugin_control.c \
|
lightningd/plugin_control.c \
|
||||||
lightningd/plugin_hook.c \
|
lightningd/plugin_hook.c \
|
||||||
lightningd/routehint.c \
|
lightningd/routehint.c \
|
||||||
|
lightningd/runes.c \
|
||||||
lightningd/subd.c \
|
lightningd/subd.c \
|
||||||
lightningd/watch.c
|
lightningd/watch.c
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
#include <lightningd/lightningd.h>
|
#include <lightningd/lightningd.h>
|
||||||
#include <lightningd/onchain_control.h>
|
#include <lightningd/onchain_control.h>
|
||||||
#include <lightningd/plugin.h>
|
#include <lightningd/plugin.h>
|
||||||
|
#include <lightningd/runes.h>
|
||||||
#include <lightningd/subd.h>
|
#include <lightningd/subd.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
#include <wallet/txfilter.h>
|
#include <wallet/txfilter.h>
|
||||||
|
@ -1118,6 +1119,11 @@ int main(int argc, char *argv[])
|
||||||
else if (max_blockheight != UINT32_MAX)
|
else if (max_blockheight != UINT32_MAX)
|
||||||
max_blockheight -= ld->config.rescan;
|
max_blockheight -= ld->config.rescan;
|
||||||
|
|
||||||
|
/*~ We have bearer tokens called `runes` you can use to control access. They have
|
||||||
|
* a fascinating history which I shall not go into now, but they're derived from
|
||||||
|
* Macaroons which was a over-engineered Googlism. */
|
||||||
|
ld->runes = runes_init(ld);
|
||||||
|
|
||||||
/*~ That's all of the wallet db operations for now. */
|
/*~ That's all of the wallet db operations for now. */
|
||||||
db_commit_transaction(ld->wallet->db);
|
db_commit_transaction(ld->wallet->db);
|
||||||
|
|
||||||
|
|
|
@ -371,6 +371,9 @@ struct lightningd {
|
||||||
|
|
||||||
/* For anchors: how much do we keep for spending close txs? */
|
/* For anchors: how much do we keep for spending close txs? */
|
||||||
struct amount_sat emergency_sat;
|
struct amount_sat emergency_sat;
|
||||||
|
|
||||||
|
/* runes! */
|
||||||
|
struct runes *runes;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Turning this on allows a tal allocation to return NULL, rather than aborting.
|
/* Turning this on allows a tal allocation to return NULL, rather than aborting.
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
#include "config.h"
|
||||||
|
#include <ccan/array_size/array_size.h>
|
||||||
|
#include <ccan/rune/rune.h>
|
||||||
|
#include <ccan/tal/str/str.h>
|
||||||
|
#include <common/json_command.h>
|
||||||
|
#include <common/json_param.h>
|
||||||
|
#include <common/json_stream.h>
|
||||||
|
#include <common/type_to_string.h>
|
||||||
|
#include <db/exec.h>
|
||||||
|
#include <hsmd/hsmd_wiregen.h>
|
||||||
|
#include <lightningd/hsm_control.h>
|
||||||
|
#include <lightningd/jsonrpc.h>
|
||||||
|
#include <lightningd/lightningd.h>
|
||||||
|
#include <lightningd/runes.h>
|
||||||
|
#include <wallet/wallet.h>
|
||||||
|
|
||||||
|
/* This is lightningd->runes */
|
||||||
|
struct runes {
|
||||||
|
struct rune *master;
|
||||||
|
u64 next_unique_id;
|
||||||
|
struct rune_blacklist *blacklist;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct runes *runes_init(struct lightningd *ld)
|
||||||
|
{
|
||||||
|
const u8 *msg;
|
||||||
|
struct runes *runes = tal(ld, struct runes);
|
||||||
|
const u8 *data;
|
||||||
|
struct secret secret;
|
||||||
|
|
||||||
|
runes->next_unique_id = db_get_intvar(ld->wallet->db, "runes_uniqueid", 0);
|
||||||
|
runes->blacklist = wallet_get_runes_blacklist(runes, ld->wallet);
|
||||||
|
|
||||||
|
/* Runes came out of commando, hence the derivation key is 'commando' */
|
||||||
|
data = tal_dup_arr(tmpctx, u8, (u8 *)"commando", strlen("commando"), 0);
|
||||||
|
msg = hsm_sync_req(tmpctx, ld, towire_hsmd_derive_secret(tmpctx, data));
|
||||||
|
if (!fromwire_hsmd_derive_secret_reply(msg, &secret))
|
||||||
|
fatal("Bad reply from HSM: %s", tal_hex(tmpctx, msg));
|
||||||
|
|
||||||
|
runes->master = rune_new(runes, secret.data, ARRAY_SIZE(secret.data), NULL);
|
||||||
|
|
||||||
|
return runes;
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef LIGHTNING_LIGHTNINGD_RUNES_H
|
||||||
|
#define LIGHTNING_LIGHTNINGD_RUNES_H
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
struct runes *runes_init(struct lightningd *ld);
|
||||||
|
|
||||||
|
#endif /* LIGHTNING_LIGHTNINGD_RUNES_H */
|
|
@ -187,6 +187,9 @@ void plugins_set_builtin_plugins_dir(struct plugins *plugins UNNEEDED,
|
||||||
/* Generated stub for resend_closing_transactions */
|
/* Generated stub for resend_closing_transactions */
|
||||||
void resend_closing_transactions(struct lightningd *ld UNNEEDED)
|
void resend_closing_transactions(struct lightningd *ld UNNEEDED)
|
||||||
{ fprintf(stderr, "resend_closing_transactions called!\n"); abort(); }
|
{ fprintf(stderr, "resend_closing_transactions called!\n"); abort(); }
|
||||||
|
/* Generated stub for runes_init */
|
||||||
|
struct runes *runes_init(struct lightningd *ld UNNEEDED)
|
||||||
|
{ fprintf(stderr, "runes_init called!\n"); abort(); }
|
||||||
/* Generated stub for setup_color_and_alias */
|
/* Generated stub for setup_color_and_alias */
|
||||||
void setup_color_and_alias(struct lightningd *ld UNNEEDED)
|
void setup_color_and_alias(struct lightningd *ld UNNEEDED)
|
||||||
{ fprintf(stderr, "setup_color_and_alias called!\n"); abort(); }
|
{ fprintf(stderr, "setup_color_and_alias called!\n"); abort(); }
|
||||||
|
|
Loading…
Reference in New Issue