From: rajarshimaitra Date: Sat, 8 Jan 2022 18:33:12 +0000 (+0530) Subject: Add cookie authentication option for rpc X-Git-Tag: v0.4.0~2^2~2 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/scripts/struct.Script.html?a=commitdiff_plain;h=180fe4748c85dde7668785abf8593c1a34c55238;p=bdk-cli Add cookie authentication option for rpc --- diff --git a/src/bdk_cli.rs b/src/bdk_cli.rs index baa12cf..10b3b17 100644 --- a/src/bdk_cli.rs +++ b/src/bdk_cli.rs @@ -191,9 +191,15 @@ where #[cfg(feature = "rpc")] let config: AnyBlockchainConfig = { - let auth = Auth::UserPass { - username: wallet_opts.rpc_opts.auth.0.clone(), - password: wallet_opts.rpc_opts.auth.1.clone(), + let auth = if let Some(cookie) = &wallet_opts.rpc_opts.cookie { + Auth::Cookie { + file: cookie.into(), + } + } else { + Auth::UserPass { + username: wallet_opts.rpc_opts.basic_auth.0.clone(), + password: wallet_opts.rpc_opts.basic_auth.1.clone(), + } }; // Use deterministic wallet name derived from descriptor diff --git a/src/lib.rs b/src/lib.rs index 9d08380..91ad841 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -229,8 +229,9 @@ use bdk_reserves::reserves::ProofOfReserves; /// #[cfg(feature = "rpc")] /// rpc_opts: RpcOpts{ /// address: "127.0.0.1:18443".to_string(), -/// auth: ("user".to_string(), "password".to_string()), +/// basic_auth: ("user".to_string(), "password".to_string()), /// skip_blocks: None, +/// cookie: None, /// }, /// #[cfg(feature = "compact_filters")] /// compactfilter_opts: CompactFilterOpts{ @@ -542,15 +543,19 @@ pub struct RpcOpts { )] pub address: String, - /// Sets the rpc authentication username:password + /// Sets the rpc basic authentication #[structopt( name = "USER:PASSWD", short = "a", - long = "auth", + long = "basic-auth", parse(try_from_str = parse_proxy_auth), default_value = "user:password", )] - pub auth: (String, String), + pub basic_auth: (String, String), + + /// Sets an optional cookie authentication + #[structopt(name = "COOKIE", long = "cookie")] + pub cookie: Option, /// Optionally skip initial `skip_blocks` blocks #[structopt(name = "SKIP_BLOCKS", short = "s", long = "skip-blocks")] @@ -1479,7 +1484,8 @@ mod test { #[cfg(feature = "rpc")] rpc_opts: RpcOpts { address: "127.0.0.1:18443".to_string(), - auth: ("user".to_string(), "password".to_string()), + basic_auth: ("user".to_string(), "password".to_string()), + cookie: None, skip_blocks: None, }, }, @@ -1616,7 +1622,8 @@ mod test { "--descriptor", "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)", "--change_descriptor", "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)", "--node", "125.67.89.101:56678", - "--auth", "user:password", + "--basic-auth", "user:password", + "--cookie", "/home/user/.bitcoin/regtest/.cookie", "--skip-blocks", "5", "get_new_address"]; @@ -1632,7 +1639,8 @@ mod test { change_descriptor: Some("wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)".to_string()), rpc_opts: RpcOpts { address: "125.67.89.101:56678".to_string(), - auth: ("user".to_string(), "password".to_string()), + basic_auth: ("user".to_string(), "password".to_string()), + cookie: Some("/home/user/.bitcoin/regtest/.cookie".to_string()), skip_blocks: Some(5), }, }, @@ -1734,7 +1742,8 @@ mod test { #[cfg(feature = "rpc")] rpc_opts: RpcOpts { address: "127.0.0.1:18443".to_string(), - auth: ("user".to_string(), "password".to_string()), + basic_auth: ("user".to_string(), "password".to_string()), + cookie: None, skip_blocks: None, }, }, @@ -1809,7 +1818,8 @@ mod test { #[cfg(feature = "rpc")] rpc_opts: RpcOpts { address: "127.0.0.1:18443".to_string(), - auth: ("user".to_string(), "password".to_string()), + basic_auth: ("user".to_string(), "password".to_string()), + cookie: None, skip_blocks: None, }, }, @@ -1871,7 +1881,8 @@ mod test { #[cfg(feature = "rpc")] rpc_opts: RpcOpts { address: "127.0.0.1:18443".to_string(), - auth: ("user".to_string(), "password".to_string()), + basic_auth: ("user".to_string(), "password".to_string()), + cookie: None, skip_blocks: None, }, #[cfg(any(feature="compact_filters", feature="electrum", feature="esplora"))] @@ -1946,7 +1957,8 @@ mod test { #[cfg(feature = "rpc")] rpc_opts: RpcOpts { address: "127.0.0.1:18443".to_string(), - auth: ("user".to_string(), "password".to_string()), + basic_auth: ("user".to_string(), "password".to_string()), + cookie: None, skip_blocks: None, }, },