mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
lightningd: have makesecret take hex or string (just like datastore)
Changelog-Added: JSON-RPC: `makesecret` can take a string argument instead of hex. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -4,14 +4,15 @@ lightning-makesecret -- Command for deriving pseudorandom key from HSM
|
|||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
|
|
||||||
**makesecret** *hex*
|
**makesecret** [*hex*] [*string*]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
The **makesecret** RPC command derives a secret key from the HSM_secret.
|
The **makesecret** RPC command derives a secret key from the HSM_secret.
|
||||||
|
|
||||||
The *hex* can be any hex data.
|
One of *hex* or *string* must be specified: *hex* can be any hex data,
|
||||||
|
*string* is a UTF-8 string interpreted literally.
|
||||||
|
|
||||||
RETURN VALUE
|
RETURN VALUE
|
||||||
------------
|
------------
|
||||||
@@ -32,11 +33,6 @@ AUTHOR
|
|||||||
|
|
||||||
Aditya <<aditya.sharma20111@gmail.com>> is mainly responsible.
|
Aditya <<aditya.sharma20111@gmail.com>> is mainly responsible.
|
||||||
|
|
||||||
SEE ALSO
|
|
||||||
--------
|
|
||||||
|
|
||||||
lightning-getsharedsecret(7)
|
|
||||||
|
|
||||||
RESOURCES
|
RESOURCES
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": [
|
"required": [],
|
||||||
"hex"
|
|
||||||
],
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"hex": {
|
"hex": {
|
||||||
"type": "hex",
|
"type": "hex",
|
||||||
"description": "This will be used for deriving the secret"
|
"description": "This will be used for deriving the secret"
|
||||||
|
},
|
||||||
|
"string": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "This will be used for deriving the secret"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,16 +131,30 @@ static struct command_result *json_makesecret(struct command *cmd,
|
|||||||
const jsmntok_t *obj UNNEEDED,
|
const jsmntok_t *obj UNNEEDED,
|
||||||
const jsmntok_t *params)
|
const jsmntok_t *params)
|
||||||
{
|
{
|
||||||
u8 *info;
|
u8 *data;
|
||||||
|
const char *strdata;
|
||||||
struct json_stream *response;
|
struct json_stream *response;
|
||||||
struct secret secret;
|
struct secret secret;
|
||||||
|
|
||||||
if (!param(cmd, buffer, params,
|
if (!param(cmd, buffer, params,
|
||||||
p_req("hex", param_bin_from_hex, &info),
|
p_opt("hex", param_bin_from_hex, &data),
|
||||||
|
p_opt("string", param_string, &strdata),
|
||||||
NULL))
|
NULL))
|
||||||
return command_param_failed();
|
return command_param_failed();
|
||||||
|
|
||||||
u8 *msg = towire_hsmd_derive_secret(cmd, info);
|
if (strdata) {
|
||||||
|
if (data)
|
||||||
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
"Cannot have both hex and string");
|
||||||
|
data = tal_dup_arr(cmd, u8, (u8 *)strdata, strlen(strdata), 0);
|
||||||
|
} else {
|
||||||
|
if (!data)
|
||||||
|
return command_fail(cmd, JSONRPC2_INVALID_PARAMS,
|
||||||
|
"Must have either hex or string");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
u8 *msg = towire_hsmd_derive_secret(cmd, data);
|
||||||
if (!wire_sync_write(cmd->ld->hsm_fd, take(msg)))
|
if (!wire_sync_write(cmd->ld->hsm_fd, take(msg)))
|
||||||
return command_fail(cmd, LIGHTNINGD,
|
return command_fail(cmd, LIGHTNINGD,
|
||||||
"Could not write to HSM: %s", strerror(errno));
|
"Could not write to HSM: %s", strerror(errno));
|
||||||
|
|||||||
@@ -2281,6 +2281,10 @@ def test_makesecret(node_factory):
|
|||||||
assert l1.rpc.makesecret(hex="736362207365637265")["secret"] != secret
|
assert l1.rpc.makesecret(hex="736362207365637265")["secret"] != secret
|
||||||
assert l1.rpc.makesecret(hex="7363622073656372657401")["secret"] != secret
|
assert l1.rpc.makesecret(hex="7363622073656372657401")["secret"] != secret
|
||||||
|
|
||||||
|
# Using string works!
|
||||||
|
assert l1.rpc.makesecret(string="scb secret")["secret"] == secret
|
||||||
|
assert l1.rpc.makesecret(None, "scb secret")["secret"] == secret
|
||||||
|
|
||||||
|
|
||||||
def test_staticbackup(node_factory):
|
def test_staticbackup(node_factory):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user