From b73053b3892ac337e864b0fe2fa7a3f7e996d3e8 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Fri, 27 Jul 2018 16:54:48 +0900 Subject: [PATCH] Support proper cookie authentication --- rpcclient/infrastructure.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rpcclient/infrastructure.go b/rpcclient/infrastructure.go index bfd9194d4c..9787448b16 100644 --- a/rpcclient/infrastructure.go +++ b/rpcclient/infrastructure.go @@ -820,7 +820,17 @@ func (c *Client) sendPost(jReq *jsonRequest) { httpReq.Header.Set("Content-Type", "application/json") // Configure basic access authorization. - httpReq.SetBasicAuth(c.config.User, c.config.Pass) + if c.config.CookieFilePath == "" { + httpReq.SetBasicAuth(c.config.User, c.config.Pass) + } else { + cookie, err := ioutil.ReadFile(c.config.CookieFilePath) + if err == nil { + splitCookie := strings.Split(string(cookie), ":") + if len(splitCookie) == 2 { + httpReq.SetBasicAuth(splitCookie[0], splitCookie[1]) + } + } + } log.Tracef("Sending command [%s] with id %d", jReq.method, jReq.id) c.sendPostRequest(httpReq, jReq) @@ -1065,6 +1075,9 @@ type ConnConfig struct { // Pass is the passphrase to use to authenticate to the RPC server. Pass string + // Alternative to User/Pass authentication, this file get read for each request + CookieFilePath string + // DisableTLS specifies whether transport layer security should be // disabled. It is recommended to always use TLS if the RPC server // supports it as otherwise your username and password is sent across