Skip to content

Commit 43211ba

Browse files
authored
Add a GUI to control the configured proxy (keybase#17879)
* Add support for socks proxies * Make proxy type case insensitive * Add some docs and clean the code slightly. Now tested and working with basic auth for socks and http_connect * Create disable-ssl-pinning config option to switch the server uri to keybase.io * Add docs on disabling cert pinning (now tested and working) * A little refactoring and some basic tests * Added unit tests Note that this does not fully test the proxy support since it does not set up a test environment with a proxy or actually run HTTP requests through a real proxy. This means this is definitely a limited and imperfect set of tests but it is still definitely better than nothing. As long as go's http.ProxyFromEnvironment continues to function the same way and we don't switch away from it, things should be reliable. * Add comment warning not to change the transport in order to preserve proxy support * Fix golint and go vet errors * Addressed first round of feedback * Refactored NewClient to return an error to get rid of a panic * Refactored GetServerURI to return an error in order to get rid of a panic * Fixed lint errors * In progress on adding proxy everywhere * Winded the globals through in order to proxy giphy calls * Route s3 through the proxy * Enabled proxy support and fixed a test * Linting * Fix go vet * Switched to passing in a globalcontext instead of an env * Switch if err to require * Fix circle build * Fix go vet errors * Set up pre-commit hook and ran against all the files in this PR * Refactor to get rid of extraneous arguments and updated gofmt version * Fixed gofmt * Refactored to use Contextified * Fixed failing tests * Fix failing CI that was caused by clearing the env * WIP * Initial version of GUI without plumbing or cert pinning * Add proxy.avdl and generated files * Add proxy.avdl and generated files * Enable the two new rpc calls as promises in js * Moved the proxy protocol to config.avdl * Working rpc to get data into react * Working saving proxies * Working proxy gui * Fix rebase * Make the keybase service use an updated proxy without restarting * Add confirmation modal before disabling cert pinning * Delete duplicate warning * Linting * Fix a bad refactor * Fix the order of buttons to not depend on object key ordering * Migrated retrieving proxy data to redux and saga * Migrated saving data to use redux and saga * Fix some of the small feedback * temp * Working migration of the pop up to a modal route * Fix Chris's feedback * Switch from componentWillReceiveProps to componentDidUpdate * Redid design per Cecile's feedback * Add margin above title * Removed dead code * Fixed Chris's feedback * Fixed Chris's feedback * Respond to feedback on PR * workaround react-native-push-notification subdep migrating to androidX * add gms * version overrides * no comment after version num * Fix CSS so the proxy settings don't overlap the developer settings on a small screen * Working on android * Fix http proxy behavior When configuring proxies via env variables, go automatically defaulted to the http protocol. When configured via the Proxy function, it does not. This defaults to the http protocol if a protocol was not specified. * Fixed cecile's feedback * More design tweaks * Fix basic auth parsing * Fixed failing test
1 parent 818cc6b commit 43211ba

26 files changed

Lines changed: 634 additions & 78 deletions

File tree

‎go/chat/giphy/search.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func httpClient(mctx libkb.MetaContext, host string) *http.Client {
112112
xprt.TLSClientConfig = tlsConfig
113113

114114
env := mctx.G().Env
115-
xprt.Proxy = libkb.MakeProxy(env.GetProxyType(), env.GetProxy())
115+
xprt.Proxy = libkb.MakeProxy(env)
116116

117117
return &http.Client{
118118
Transport: &xprt,

‎go/chat/s3/s3.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ func (s3 *S3) run(ctx context.Context, req *request, resp interface{}) (*http.Re
977977
}
978978
return
979979
},
980-
Proxy: libkb.MakeProxy(s3.G().Env.GetProxyType(), s3.G().Env.GetProxy()),
980+
Proxy: libkb.MakeProxy(s3.G().Env),
981981
},
982982
}
983983
}

‎go/libkb/client.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func NewClient(g *GlobalContext, config *ClientConfig, needCookie bool) (*Client
199199
xprt.TLSClientConfig = &tls.Config{RootCAs: config.RootCAs}
200200
}
201201

202-
xprt.Proxy = MakeProxy(env.GetProxyType(), env.GetProxy())
202+
xprt.Proxy = MakeProxy(env)
203203

204204
if !env.GetTorMode().Enabled() && env.GetRunMode() == DevelRunMode {
205205
xprt.Proxy = func(req *http.Request) (*url.URL, error) {

‎go/libkb/env.go‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,19 +1068,23 @@ func (e *Env) GetSkipLogoutIfRevokedCheck() bool {
10681068
func (e *Env) GetProxyType() ProxyType {
10691069
if e.GetTorMode() != TorNone {
10701070
// Tor mode is enabled. Tor mode is implemented via a socks proxy
1071-
return socks
1071+
return Socks
10721072
}
10731073
var proxyTypeStr = e.GetString(
10741074
func() string { return e.cmd.GetProxyType() },
10751075
func() string { return os.Getenv("PROXY_TYPE") },
10761076
func() string { return e.GetConfig().GetProxyType() },
10771077
)
1078+
return ProxyTypeStrToEnumFunc(proxyTypeStr)
1079+
}
1080+
1081+
func ProxyTypeStrToEnumFunc(proxyTypeStr string) ProxyType {
10781082
proxyType, ok := ProxyTypeStrToEnum[strings.ToLower(proxyTypeStr)]
10791083
if ok {
10801084
return proxyType
10811085
}
10821086
// If they give us a bogus proxy type we just don't enable a proxy
1083-
return noProxy
1087+
return NoProxy
10841088
}
10851089

10861090
// Get the address (optionally including a port) of the currently configured proxy. Returns an empty string if no proxy

‎go/libkb/env_test.go‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,58 +65,58 @@ func TestTorMode(t *testing.T) {
6565

6666
mockedEnv := NewEnv(MockedConfigReader{}, MockedConfigReader{}, makeLogGetter(t))
6767

68-
// Test that when tor mode is enabled, a socks proxy is properly configured
69-
require.Equal(t, noProxy, mockedEnv.GetProxyType())
68+
// Test that when tor mode is enabled, a Socks proxy is properly configured
69+
require.Equal(t, NoProxy, mockedEnv.GetProxyType())
7070
require.Equal(t, "", mockedEnv.GetProxy())
7171

7272
globalTorMode = TorLeaky
73-
require.Equal(t, socks, mockedEnv.GetProxyType())
73+
require.Equal(t, Socks, mockedEnv.GetProxyType())
7474
require.Equal(t, "localhost:9050", mockedEnv.GetProxy())
7575

7676
globalTorMode = TorStrict
77-
require.Equal(t, socks, mockedEnv.GetProxyType())
77+
require.Equal(t, Socks, mockedEnv.GetProxyType())
7878
require.Equal(t, "localhost:9050", mockedEnv.GetProxy())
7979

8080
// Test that tor mode overrides proxy settings
8181
globalProxyType = "http"
8282
globalProxyAddress = "localhost:8080"
83-
require.Equal(t, socks, mockedEnv.GetProxyType())
83+
require.Equal(t, Socks, mockedEnv.GetProxyType())
8484
require.Equal(t, "localhost:9050", mockedEnv.GetProxy())
8585
}
8686

8787
func TestGetProxyType(t *testing.T) {
8888
resetGlobals()
8989

9090
defaultEnv := NewEnv(nil, nil, makeLogGetter(t))
91-
require.Equal(t, noProxy, defaultEnv.GetProxyType())
91+
require.Equal(t, NoProxy, defaultEnv.GetProxyType())
9292

9393
mockedEnv := NewEnv(MockedConfigReader{}, MockedConfigReader{}, makeLogGetter(t))
94-
require.Equal(t, noProxy, mockedEnv.GetProxyType())
94+
require.Equal(t, NoProxy, mockedEnv.GetProxyType())
9595

96-
globalProxyType = "socks"
97-
require.Equal(t, socks, mockedEnv.GetProxyType())
96+
globalProxyType = "Socks"
97+
require.Equal(t, Socks, mockedEnv.GetProxyType())
9898
globalProxyType = "SOCKS"
99-
require.Equal(t, socks, mockedEnv.GetProxyType())
99+
require.Equal(t, Socks, mockedEnv.GetProxyType())
100100
globalProxyType = "SoCkS"
101-
require.Equal(t, socks, mockedEnv.GetProxyType())
101+
require.Equal(t, Socks, mockedEnv.GetProxyType())
102102

103103
globalProxyType = "http_connect"
104-
require.Equal(t, httpConnect, mockedEnv.GetProxyType())
104+
require.Equal(t, HTTPConnect, mockedEnv.GetProxyType())
105105
globalProxyType = "HTTP_CONNECT"
106-
require.Equal(t, httpConnect, mockedEnv.GetProxyType())
106+
require.Equal(t, HTTPConnect, mockedEnv.GetProxyType())
107107

108108
globalProxyType = "BOGUS"
109-
require.Equal(t, noProxy, mockedEnv.GetProxyType())
109+
require.Equal(t, NoProxy, mockedEnv.GetProxyType())
110110

111111
resetGlobals()
112-
require.Equal(t, noProxy, mockedEnv.GetProxyType())
112+
require.Equal(t, NoProxy, mockedEnv.GetProxyType())
113113

114114
orig := os.Getenv("PROXY_TYPE")
115115

116116
os.Setenv("PROXY_TYPE", "socks")
117-
require.Equal(t, socks, mockedEnv.GetProxyType())
117+
require.Equal(t, Socks, mockedEnv.GetProxyType())
118118
os.Setenv("PROXY_TYPE", "http_connect")
119-
require.Equal(t, httpConnect, mockedEnv.GetProxyType())
119+
require.Equal(t, HTTPConnect, mockedEnv.GetProxyType())
120120

121121
os.Setenv("PROXY_TYPE", orig)
122122
}

‎go/libkb/proxy.go‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ export PROXY_TYPE=<"socks" or "http_connect">
1616
export PROXY=<"localhost:8080" or "username:password@localhost:8080">
1717
```
1818
19-
Internally, we support proxies by setting the HTTP_PROXY and HTTPS_PROXY environment variables which
20-
http.ProxyFromEnvironment automatically reads from. Note that http.ProxyFromEnvironment does support
21-
socks5 proxies and basic auth.
19+
Internally, we support proxies by setting the Proxy field of http.Transport in order to use http's
20+
built in support for proxies. Note that http.Transport.Proxy does support socks5 proxies and basic auth.
2221
2322
By default, the client reaches out to api-0.core.keybaseapi.com which has a self-signed certificate. This
2423
is actually more secure than relying on the standard CA system since we pin the client to only accept this
@@ -52,14 +51,15 @@ import (
5251
type ProxyType int
5352

5453
const (
55-
noProxy ProxyType = iota
56-
socks
57-
httpConnect
54+
NoProxy ProxyType = iota
55+
Socks
56+
HTTPConnect
5857
)
5958

6059
// Maps a string to an enum. Used to list the different types of supported proxies and to convert
6160
// config options into the enum
62-
var ProxyTypeStrToEnum = map[string]ProxyType{"socks": socks, "http_connect": httpConnect}
61+
var ProxyTypeStrToEnum = map[string]ProxyType{"socks": Socks, "http_connect": HTTPConnect}
62+
var ProxyTypeEnumToStr = map[ProxyType]string{Socks: "socks", HTTPConnect: "http_connect", NoProxy: "no_proxy"}
6363

6464
func GetCommaSeparatedListOfProxyTypes() string {
6565
var proxyTypes []string
@@ -69,18 +69,22 @@ func GetCommaSeparatedListOfProxyTypes() string {
6969
return strings.Join(proxyTypes, ",")
7070
}
7171

72-
// Enable the proxy configured by this environment by setting the HTTP_PROXY and HTTPS_PROXY environment variables
73-
func MakeProxy(proxyType ProxyType, proxyAddress string) func(r *http.Request) (*url.URL, error) {
72+
// Return a function that can be passed to the http library in order to configure a proxy
73+
func MakeProxy(e *Env) func(r *http.Request) (*url.URL, error) {
7474
return func(r *http.Request) (*url.URL, error) {
75-
if proxyType == noProxy {
75+
proxyType := e.GetProxyType()
76+
proxyAddress := e.GetProxy()
77+
78+
if proxyType == NoProxy {
7679
// No proxy so returning nil tells it not to use a proxy
7780
return nil, nil
7881
}
79-
realProxyAddress := ""
80-
if proxyType == socks {
82+
realProxyAddress := proxyAddress
83+
if proxyType == Socks {
8184
realProxyAddress = "socks5://" + proxyAddress
82-
} else {
83-
realProxyAddress = proxyAddress
85+
} else if proxyType == HTTPConnect && !strings.Contains(proxyAddress, "http://") && !strings.Contains(proxyAddress, "https://") {
86+
// If they don't specify a protocol, default to http:// since it is the most common
87+
realProxyAddress = "http://" + proxyAddress
8488
}
8589

8690
realProxyURL, err := url.Parse(realProxyAddress)

‎go/libkb/proxy_test.go‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,43 @@ import (
99

1010
func TestProxyTypeStrToEnum(t *testing.T) {
1111
proxyType, ok := ProxyTypeStrToEnum["socks"]
12-
require.Equal(t, socks, proxyType)
12+
require.Equal(t, Socks, proxyType)
1313
require.Equal(t, true, ok)
1414

1515
proxyType, ok = ProxyTypeStrToEnum["http_connect"]
16-
require.Equal(t, httpConnect, proxyType)
16+
require.Equal(t, HTTPConnect, proxyType)
1717
require.Equal(t, true, ok)
1818

1919
proxyType, ok = ProxyTypeStrToEnum["bogus"]
2020
require.Equal(t, false, ok)
2121
}
2222

2323
func TestMakeProxy(t *testing.T) {
24-
f := MakeProxy(noProxy, "localhost:8090")
24+
resetGlobals()
25+
mockedEnv := NewEnv(MockedConfigReader{}, MockedConfigReader{}, makeLogGetter(t))
26+
27+
require.Equal(t, NoProxy, mockedEnv.GetProxyType())
28+
require.Equal(t, "", mockedEnv.GetProxy())
29+
f := MakeProxy(mockedEnv)
2530
retURL, err := f(nil)
2631

2732
// A nil retURL means no proxy
2833
require.Equal(t, (*url.URL)(nil), retURL)
2934
require.Equal(t, nil, err)
3035

31-
f = MakeProxy(socks, "localhost:8090")
36+
globalProxyType = "Socks"
37+
require.Equal(t, Socks, mockedEnv.GetProxyType())
38+
globalProxyAddress = "localhost:8090"
39+
require.Equal(t, "localhost:8090", mockedEnv.GetProxy())
40+
f = MakeProxy(mockedEnv)
3241
retURL, err = f(nil)
3342
require.Equal(t, nil, err)
3443
require.Equal(t, "socks5://localhost:8090", retURL.String())
3544

36-
f = MakeProxy(httpConnect, "localhost:8090")
45+
globalProxyType = "http_connect"
46+
require.Equal(t, HTTPConnect, mockedEnv.GetProxyType())
47+
f = MakeProxy(mockedEnv)
3748
retURL, err = f(nil)
3849
require.Equal(t, nil, err)
39-
require.Equal(t, "localhost:8090", retURL.String())
50+
require.Equal(t, "http://localhost:8090", retURL.String())
4051
}

‎go/protocol/keybase1/config.go‎

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)