Allow alternative btcd RPC server auth.
This change adds the new btcdusername and btcdpassword options which, if set, are used instead of the username and password when authenticating to a btcd RPC server. If these new options are unset, the btcd user and password settings are shared with the client auth settings.
This commit is contained in:
parent
c4a0b70835
commit
461111cadf
3 changed files with 21 additions and 3 deletions
17
config.go
17
config.go
|
@ -55,8 +55,10 @@ type config struct {
|
|||
ConfigFile string `short:"C" long:"configfile" description:"Path to configuration file"`
|
||||
SvrListeners []string `long:"rpclisten" description:"Listen for RPC/websocket connections on this interface/port (default port: 18332, mainnet: 8332)"`
|
||||
DataDir string `short:"D" long:"datadir" description:"Directory to store wallets and transactions"`
|
||||
Username string `short:"u" long:"username" description:"Username for btcd authorization"`
|
||||
Password string `short:"P" long:"password" default-mask:"-" description:"Password for btcd authorization"`
|
||||
Username string `short:"u" long:"username" description:"Username for client and btcd authorization"`
|
||||
Password string `short:"P" long:"password" default-mask:"-" description:"Password for client and btcd authorization"`
|
||||
BtcdUsername string `long:"btcdusername" description:"Alternative username for btcd authorization"`
|
||||
BtcdPassword string `long:"btcdpassword" default-mask:"-" description:"Alternative password for btcd authorization"`
|
||||
RPCCert string `long:"rpccert" description:"File containing the certificate file"`
|
||||
RPCKey string `long:"rpckey" description:"File containing the certificate key"`
|
||||
MainNet bool `long:"mainnet" description:"Use the main Bitcoin network (default testnet3)"`
|
||||
|
@ -272,6 +274,17 @@ func loadConfig() (*config, []string, error) {
|
|||
// Expand environment variable and leading ~ for filepaths.
|
||||
cfg.CAFile = cleanAndExpandPath(cfg.CAFile)
|
||||
|
||||
// If the btcd username or password are unset, use the same auth as for
|
||||
// the client. The two settings were previously shared for btcd and
|
||||
// client auth, so this avoids breaking backwards compatibility while
|
||||
// allowing users to use different auth settings for btcd and wallet.
|
||||
if cfg.BtcdUsername == "" {
|
||||
cfg.BtcdUsername = cfg.Username
|
||||
}
|
||||
if cfg.BtcdPassword == "" {
|
||||
cfg.BtcdPassword = cfg.Password
|
||||
}
|
||||
|
||||
return &cfg, remainingArgs, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,11 @@
|
|||
; username=
|
||||
; password=
|
||||
|
||||
; Alternative username and password for btcd. If set, these will be used
|
||||
; instead of the username and password set above for authentication to a
|
||||
; btcd RPC server.
|
||||
; btcdusername=
|
||||
; btcdpassword=
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------------
|
||||
|
|
|
@ -642,7 +642,7 @@ func BtcdWS(certificates []byte) (*websocket.Conn, error) {
|
|||
}
|
||||
|
||||
// btcd requires basic authorization, so set the Authorization header.
|
||||
login := cfg.Username + ":" + cfg.Password
|
||||
login := cfg.BtcdUsername + ":" + cfg.BtcdPassword
|
||||
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login))
|
||||
config.Header.Add("Authorization", auth)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue