Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clients: add rpcclient basic auth #664

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions brclient/appstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3798,6 +3798,9 @@ func newAppState(sendMsg func(tea.Msg), lndLogLines *sloglinesbuffer.Buffer,
rpcServer = rpcserver.New(rpcserver.Config{
JSONRPCListeners: jsonListeners,
Log: rpcsLog,
RPCUser: args.RPCUser,
RPCPass: args.RPCPass,
AuthMode: args.RPCAuthMode,
})
rpcServer.InitVersionService(appName, version.Version)
chatRPCServerCfg := rpcserver.ChatServerCfg{
Expand Down Expand Up @@ -3839,9 +3842,20 @@ func newAppState(sendMsg func(tea.Msg), lndLogLines *sloglinesbuffer.Buffer,
}

payRPCServerCfg := rpcserver.PaymentsServerCfg{
Log: logBknd.logger("RPCS"),
Client: c,
RootReplayMsgLogs: filepath.Join(args.DBRoot, "replaymsglog"),
Log: logBknd.logger("RPCS"),
Client: c,
RootReplayMsgLogs: filepath.Join(args.DBRoot, "replaymsglog"),
RPCAllowRemoteSendTip: args.RPCAllowRemoteSendTip,
RPCMaxRemoteSendTipAmt: args.RPCMaxRemoteSendTipAmt,
OnTipUser: func(uid clientintf.UserID, dcrAmount float64) error {
if !args.RPCAllowRemoteSendTip {
return fmt.Errorf("remote tip sending not allowed")
}
if args.RPCMaxRemoteSendTipAmt > 0 && dcrAmount > args.RPCMaxRemoteSendTipAmt {
return fmt.Errorf("tip exceeds max limit: %v", args.RPCMaxRemoteSendTipAmt)
}
return nil
},
}
err = rpcServer.InitPaymentsService(payRPCServerCfg)
if err != nil {
Expand Down
109 changes: 63 additions & 46 deletions brclient/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,15 @@ type config struct {
RPCCertPath string
RPCKeyPath string
RPCClientCAPath string
RPCUser string
RPCPass string
RPCAuthMode string
RPCIssueClientCert bool

// rpc configurable params
RPCAllowRemoteSendTip bool
RPCMaxRemoteSendTipAmt float64

ExternalEditorForComments bool

ResourcesUpstream string
Expand Down Expand Up @@ -330,6 +337,11 @@ func loadConfig() (*config, error) {
flagRPCKeyPath := fs.String("clientrpc.rpckeypath", defaultRPCKeyPath, "")
flagRPCClientCAPath := fs.String("clientrpc.rpcclientcapath", defaultRPCClientCA, "")
flagRPCIssueClientCert := fs.Bool("clientrpc.rpcissueclientcert", true, "")
flagRPCUser := fs.String("clientrpc.rpcuser", "", "")
flagRPCPass := fs.String("clientrpc.rpcpass", "", "")
flagRPCAuthMode := fs.String("clientrpc.rpcauthmode", "", "")
flagRPCAllowRemoteSendTip := fs.Bool("clientrpc.rpcallowremotesendtip", true, "allow remote send tip")
flagRPCMaxRemoteSendTipAmt := fs.Float64("clientrpc.rpcmaxremotesendtipamt", -1, "max remote send tip amount")

// resources
flagResourcesUpstream := fs.String("resources.upstream", "", "Upstream processor of resource requests")
Expand Down Expand Up @@ -488,52 +500,57 @@ func loadConfig() (*config, error) {

// Return the final cfg object.
return &config{
ServerAddr: *flagServerAddr,
Root: *flagRootDir,
DBRoot: filepath.Join(*flagRootDir, "db"),
DownloadsRoot: filepath.Join(*flagRootDir, "downloads"),
EmbedsRoot: filepath.Join(*flagRootDir, "embeds"),
WalletType: *flagWalletType,
MsgRoot: *flagMsgRoot,
LNRPCHost: *flagLNHost,
LNTLSCertPath: *flagLNTLSCert,
LNMacaroonPath: *flagLNMacaroonPath,
LNDebugLevel: *flagLNDebugLevel,
LNMaxLogFiles: *flagLNMaxLogFiles,
LNRPCListen: lnRPCListen,
LogFile: *flagLogFile,
MaxLogFiles: *flagMaxLogFiles,
DebugLevel: *flagDebugLevel,
CompressLevel: *flagCompressLevel,
CmdHistoryPath: cmdHistoryPath,
NickColor: *flagNickColor,
GCOtherColor: *flagGCOtherColor,
PMOtherColor: *flagPMOtherColor,
BlinkCursor: *flagBlinkCursor,
BellCmd: strings.TrimSpace(*flagBellCmd),
Network: *flagNetwork,
CPUProfile: *flagCPUProfile,
CPUProfileHz: *flagCPUProfileHz,
MemProfile: *flagMemProfile,
LogPings: *flagLogPings,
SendRecvReceipts: *flagSendRecvReceipts,
NoLoadChatHistory: *flagNoLoadChatHistory,
ProxyAddr: *flagProxyAddr,
ProxyUser: *flagProxyUser,
ProxyPass: *flagProxyPass,
TorIsolation: *flagTorIsolation,
MinWalletBal: minWalletBal,
MinRecvBal: minRecvBal,
MinSendBal: minSendBal,
WinPin: winpin,
MimeMap: mimeMap,
JSONRPCListen: jrpcListen,
RPCCertPath: *flagRPCCertPath,
RPCKeyPath: *flagRPCKeyPath,
RPCClientCAPath: *flagRPCClientCAPath,
RPCIssueClientCert: *flagRPCIssueClientCert,
InviteFundsAccount: *flagInviteFundsAccount,
ResourcesUpstream: *flagResourcesUpstream,
ServerAddr: *flagServerAddr,
Root: *flagRootDir,
DBRoot: filepath.Join(*flagRootDir, "db"),
DownloadsRoot: filepath.Join(*flagRootDir, "downloads"),
EmbedsRoot: filepath.Join(*flagRootDir, "embeds"),
WalletType: *flagWalletType,
MsgRoot: *flagMsgRoot,
LNRPCHost: *flagLNHost,
LNTLSCertPath: *flagLNTLSCert,
LNMacaroonPath: *flagLNMacaroonPath,
LNDebugLevel: *flagLNDebugLevel,
LNMaxLogFiles: *flagLNMaxLogFiles,
LNRPCListen: lnRPCListen,
LogFile: *flagLogFile,
MaxLogFiles: *flagMaxLogFiles,
DebugLevel: *flagDebugLevel,
CompressLevel: *flagCompressLevel,
CmdHistoryPath: cmdHistoryPath,
NickColor: *flagNickColor,
GCOtherColor: *flagGCOtherColor,
PMOtherColor: *flagPMOtherColor,
BlinkCursor: *flagBlinkCursor,
BellCmd: strings.TrimSpace(*flagBellCmd),
Network: *flagNetwork,
CPUProfile: *flagCPUProfile,
CPUProfileHz: *flagCPUProfileHz,
MemProfile: *flagMemProfile,
LogPings: *flagLogPings,
SendRecvReceipts: *flagSendRecvReceipts,
NoLoadChatHistory: *flagNoLoadChatHistory,
ProxyAddr: *flagProxyAddr,
ProxyUser: *flagProxyUser,
ProxyPass: *flagProxyPass,
TorIsolation: *flagTorIsolation,
MinWalletBal: minWalletBal,
MinRecvBal: minRecvBal,
MinSendBal: minSendBal,
WinPin: winpin,
MimeMap: mimeMap,
JSONRPCListen: jrpcListen,
RPCCertPath: *flagRPCCertPath,
RPCKeyPath: *flagRPCKeyPath,
RPCClientCAPath: *flagRPCClientCAPath,
RPCIssueClientCert: *flagRPCIssueClientCert,
RPCUser: *flagRPCUser,
RPCPass: *flagRPCPass,
RPCAuthMode: *flagRPCAuthMode,
InviteFundsAccount: *flagInviteFundsAccount,
ResourcesUpstream: *flagResourcesUpstream,
RPCAllowRemoteSendTip: *flagRPCAllowRemoteSendTip,
RPCMaxRemoteSendTipAmt: *flagRPCMaxRemoteSendTipAmt,

AutoHandshakeInterval: autoHandshakeInterval,
AutoRemoveIdleUsersInterval: autoRemoveInterval,
Expand Down
73 changes: 71 additions & 2 deletions bruig/flutterui/bruig/lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ class Config {
late final bool sendRecvReceipts;
late final bool autoSubPosts;
late final bool logPings;
late final List<String> jsonRPCListen;
late final String rpcCertPath;
late final String rpcKeyPath;
late final bool rpcIssueClientCert;
late final String rpcClientCApath;
late final String rpcUser;
late final String rpcPass;
late final String rpcAuthMode;
late final bool rpcAllowRemoteSendTip;
late final double rpcMaxRemoteSendTipAmt;

Config();
Config.filled(
Expand Down Expand Up @@ -135,7 +145,17 @@ class Config {
this.autoRemoveIgnoreList = defaultAutoRemoveIgnoreList,
this.sendRecvReceipts = true,
this.autoSubPosts = true,
this.logPings = false});
this.logPings = false,
this.jsonRPCListen = const [],
this.rpcCertPath = "",
this.rpcKeyPath = "",
this.rpcIssueClientCert = false,
this.rpcClientCApath = "",
this.rpcUser = "",
this.rpcPass = "",
this.rpcAuthMode = "",
this.rpcAllowRemoteSendTip = false,
this.rpcMaxRemoteSendTipAmt = 0});
factory Config.newWithRPCHost(
Config cfg, String rpcHost, String tlsCert, String macaroonPath) =>
Config.filled(
Expand Down Expand Up @@ -173,6 +193,16 @@ class Config {
sendRecvReceipts: cfg.sendRecvReceipts,
autoSubPosts: cfg.autoSubPosts,
logPings: cfg.logPings,
jsonRPCListen: cfg.jsonRPCListen,
rpcCertPath: cfg.rpcCertPath,
rpcKeyPath: cfg.rpcKeyPath,
rpcIssueClientCert: cfg.rpcIssueClientCert,
rpcClientCApath: cfg.rpcClientCApath,
rpcUser: cfg.rpcUser,
rpcPass: cfg.rpcPass,
rpcAuthMode: cfg.rpcAuthMode,
rpcAllowRemoteSendTip: cfg.rpcAllowRemoteSendTip,
rpcMaxRemoteSendTipAmt: cfg.rpcMaxRemoteSendTipAmt,
);

// Save a new config from scratch.
Expand Down Expand Up @@ -209,7 +239,7 @@ class Config {
}

// replaceConfig replaces the settings that can be modified by the GUI, while
// preserving manual chages made to the config file.
// preserving manual changes made to the config file.
Future<void> replaceConfig(
String filepath, {
String? debugLevel,
Expand All @@ -220,6 +250,16 @@ Future<void> replaceConfig(
String? proxyPassword,
int? torCircuitLimit,
bool? torIsolation,
String? jsonRPCListen,
String? rpcCertPath,
String? rpcKeyPath,
String? rpcClientCApath,
String? rpcUser,
String? rpcPass,
String? rpcAuthMode,
bool? rpcIssueClientCert,
bool? rpcAllowRemoteSendTip,
double? rpcMaxRemoteSendTipAmt,
}) async {
var f = ini.Config.fromStrings(File(filepath).readAsLinesSync());

Expand All @@ -241,6 +281,11 @@ Future<void> replaceConfig(
set(section, opt, "$val");
}

void setDouble(String section, String opt, double? val) {
if (val == null) return;
set(section, opt, "$val");
}

set("log", "debuglevel", debugLevel);
setBool("log", "pings", logPings);
set("payment", "lndebuglevel", lnDebugLevel);
Expand All @@ -251,6 +296,18 @@ Future<void> replaceConfig(
setInt("default", "circuitlimit", torCircuitLimit);
setBool("default", "torisolation", torIsolation);

// RPC settings
set("clientrpc", "jsonrpclisten", jsonRPCListen);
set("clientrpc", "rpccertpath", rpcCertPath);
set("clientrpc", "rpckeypath", rpcKeyPath);
set("clientrpc", "rpcclientcapath", rpcClientCApath);
set("clientrpc", "rpcuser", rpcUser);
set("clientrpc", "rpcpass", rpcPass);
set("clientrpc", "rpcauthmode", rpcAuthMode);
setBool("clientrpc", "rpcissueclientcert", rpcIssueClientCert);
setBool("clientrpc", "rpcallowremotesendtip", rpcAllowRemoteSendTip);
setDouble("clientrpc", "rpcmaxremotesendtipamt", rpcMaxRemoteSendTipAmt);

await File(filepath).writeAsString(f.toString());
}

Expand Down Expand Up @@ -394,6 +451,18 @@ Future<Config> loadConfig(String filepath) async {
c.simpleStoreShipCharge =
double.tryParse(f.get("resources", "shipcharge") ?? "0") ?? 0;

c.jsonRPCListen = getCommaList("clientrpc", "jsonrpclisten") ?? [];
c.rpcCertPath = f.get("clientrpc", "rpccertpath") ?? "";
c.rpcKeyPath = f.get("clientrpc", "rpckeypath") ?? "";
c.rpcIssueClientCert = getBool("clientrpc", "rpcissueclientcert");
c.rpcClientCApath = f.get("clientrpc", "rpcclientcapath") ?? "";
c.rpcUser = f.get("clientrpc", "rpcuser") ?? "";
c.rpcPass = f.get("clientrpc", "rpcpass") ?? "";
c.rpcAuthMode = f.get("clientrpc", "rpcauthmode") ?? "";
c.rpcAllowRemoteSendTip = getBool("clientrpc", "rpcallowremotesendtip");
c.rpcMaxRemoteSendTipAmt =
double.tryParse(f.get("clientrpc", "rpcmaxremotesendtipamt") ?? "0") ?? 0;

return c;
}

Expand Down
11 changes: 10 additions & 1 deletion bruig/flutterui/bruig/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,16 @@ class _AppState extends State<App> with WindowListener {
Platform.isAndroid || Platform.isIOS // Use longer interval on mobile
? 210 * 1000 // 210 = 3m30s
: 0, // Use whatever is default
);
cfg.jsonRPCListen,
cfg.rpcCertPath,
cfg.rpcKeyPath,
cfg.rpcIssueClientCert,
cfg.rpcClientCApath,
cfg.rpcUser,
cfg.rpcPass,
cfg.rpcAuthMode,
cfg.rpcAllowRemoteSendTip,
cfg.rpcMaxRemoteSendTipAmt);
await Golib.initClient(initArgs);
} catch (exception) {
if ("$exception".contains("client already initialized")) {
Expand Down
36 changes: 32 additions & 4 deletions bruig/flutterui/bruig/lib/models/newconfig.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,38 @@ class NewConfigModel extends ChangeNotifier {
LNNodeType nodeType = LNNodeType.internal;
NetworkType netType = NetworkType.mainnet;

String rpcHost = "";
String tlsCertPath = "";
String macaroonPath = "";
// default properties
String serverAddr = "";
String newWalletSeed = "";
bool advancedSetup = false;

// LN configuration properties
String rpcHost = "";
String tlsCertPath = "";
String macaroonPath = "";
List<String> seedToRestore = [];
Uint8List? multichanBackupRestore;
List<ConfirmSeedWords> confirmSeedWords = [];

// Network configuration properties
String proxyAddr = "";
String proxyUser = "";
String proxyPassword = "";
int torCircuitLimit = 32;
bool torIsolation = false;

// RPC configuration properties
List<String> jsonRPCListen = [""];
String rpcCertPath = "";
String rpcKeyPath = "";
String rpcClientCApath = "";
String rpcUser = "";
String rpcPass = "";
String rpcAuthMode = "";
bool rpcIssueClientCert = false;
bool rpcAllowRemoteSendTip = false;
double rpcMaxRemoteSendTipAmt = 0.0;

Future<LNInfo> tryExternalDcrlnd(
String host, String tlsPath, String macaroonPath) async {
var res = await Golib.lnTryExternalDcrlnd(host, tlsPath, macaroonPath);
Expand All @@ -90,6 +106,18 @@ class NewConfigModel extends ChangeNotifier {
proxyPassword: proxyPassword,
circuitLimit: torCircuitLimit,
torIsolation: torIsolation,

// RPC configuration settings
jsonRPCListen: jsonRPCListen,
rpcCertPath: rpcCertPath,
rpcKeyPath: rpcKeyPath,
rpcClientCApath: rpcClientCApath,
rpcUser: rpcUser,
rpcPass: rpcPass,
rpcAuthMode: rpcAuthMode,
rpcIssueClientCert: rpcIssueClientCert,
rpcAllowRemoteSendTip: rpcAllowRemoteSendTip,
rpcMaxRemoteSendTipAmt: rpcMaxRemoteSendTipAmt,
);
await cfg.saveNewConfig(await configFileName(appArgs));
cfg = await configFromArgs(appArgs); // Reload to fill defaults.
Expand All @@ -107,7 +135,7 @@ class NewConfigModel extends ChangeNotifier {
return cfg;
}

List<ConfirmSeedWords> createConfirmSeedWords(String seed) {
List<ConfirmSeedWords> createConfirmSeedWords(String seed) {
List<ConfirmSeedWords> confirmSeedWords = [];
var seedWords = seed.trim().split(' ');
var numWords = 5;
Expand Down
Loading
Loading