Commit graph

111 commits

Author SHA1 Message Date
Cecylia Bocovich
ead5a960d7
Bump snowflake library imports and go.mod to v2 2021-11-11 10:14:49 -05:00
Cecylia Bocovich
ace8df37ed Fix compile bug in client, caught by CI 2021-08-24 10:27:24 -04:00
Cecylia Bocovich
a39d6693e1 Call conn.Reject() if SOCKS arguments are invalid 2021-08-19 21:31:51 -04:00
Cecylia Bocovich
e762f58a31 Parse SOCKS arguments and prefer over command line options
Parsing the Snowflake client options from SOCKS allow us to specify
snowflake client settings in the bridge lines.
2021-08-19 21:20:34 -04:00
Cecylia Bocovich
4acc08cc60 Use a config struct for snowflake client options 2021-08-19 21:20:34 -04:00
David Fifield
c13810192d Skeleton of ampCacheRendezvous.
Currently the same as httpRendezvous, but activated using the -ampcache
command-line option.
2021-08-05 16:13:24 -06:00
Simone Basso
aefabe683f fix(client/snowflake.go): prevent wg.Add race condition
In VSCode, the staticcheck tool emits this warning:

> should call wg.Add(1) before starting the goroutine to
> avoid a race (SA2000)go-staticcheck

To avoid this warning, just move wg.Add outside.
2021-06-14 10:10:02 +02:00
David Fifield
01a96c7d95 Fix error handling around transport.Dial.
The code checked for and displayed an error, but would then go on to
call copyLoop on the nil Conn returned from transport.Dial. Add a return
in that case, and put the cleanup operations in defer. Also remove an
obsolete comment about an empty address. Obsolete because:
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/merge_requests/31#note_2733279
2021-05-24 14:40:50 -06:00
Cecylia Bocovich
e87b9175dd Implement snowflake client lib as PTv2.1 Go API
This implements a pluggable transports v2.1 compatible Go API in the
Snowflake client library, and refactors how the main Snowflake program
calls it. The Go API implements the two required client side functions:
a constructor that returns a Transport, and a Dial function for the
Transport that returns a net.Conn. See the PT specification for more
information:
https://github.com/Pluggable-Transports/Pluggable-Transports-spec/blob/master/releases/PTSpecV2.1/Pluggable%20Transport%20Specification%20v2.1%20-%20Go%20Transport%20API.pdf
2021-05-12 09:08:41 -04:00
Cecylia Bocovich
83c01565ef Update webrtc library to v3.0.0
This update required two main changes to how we use the library. First,
we had to make sure we created the datachannel on the offering peer side
before creating the offer. Second, we had to make sure we wait for the
gathering of all candidates to complete since trickle-ice is enabled by
default. See the release notes for more details:
https://github.com/pion/webrtc/wiki/Release-WebRTC@v3.0.0.
2021-01-12 10:37:26 -05:00
Cecylia Bocovich
8ec8a7cb63 Pass lock to socksAcceptLoop by reference
This fixes a bug where we were passing the lock by value to
socksAcceptLoop.
2020-12-16 10:52:19 -05:00
Cecylia Bocovich
effc667544 Wait until all goroutines finish before shutdown 2020-12-05 15:50:16 -05:00
Cecylia Bocovich
b9cc54b3b7 Send shutdown signal to shutdown open connections
Normally all dangling goroutines are terminated when the main function
exits. However, for projects that use a patched version of snowflake as
a library, these goroutines continued running as long as the main function
had not yet terminated. This commit has all open SOCKS connections close
after receiving a shutdown signal.
2020-12-05 15:50:16 -05:00
Cecylia Bocovich
cc55481faf Set max number of snowflakes in the Tongue 2020-08-27 16:44:07 -04:00
Cecylia Bocovich
1364d7d45b Move snowflake ConnectLoop inside SOCKS Handler
Bug #21314: maintains a separate snowflake connect loop per SOCKS
connection. This way, if Tor decides to stop using Snowflake, Snowflake
will stop using the client's network.
2020-08-27 16:43:55 -04:00
Cecylia Bocovich
82031289a3 Refactor subsetting of ice servers into main
This moves the subsetting of ice servers out of the parseIceServers
function and into main.
2020-07-24 14:08:09 -04:00
Cecylia Bocovich
92520f681d Choose a random subset from given STUN servers
Only chooses a subset as long as we have over 2 STUN servers to choose
from.
2020-07-23 11:30:36 -04:00
Cecylia Bocovich
bf924445e3 Implement NAT discovery (RFC 5780) at the client
Snowflake clients will now attempt NAT discovery using the provided STUN
servers and report their NAT type to the Snowflake broker for matching.
The three possibilities for NAT types are:
- unknown (the client was unable to determine their NAT type),
- restricted (the client has a restrictive NAT and can only be paired
with unrestricted NATs)
- unrestricted (the client can be paired with any other NAT).
2020-07-06 13:16:03 -04:00
David Fifield
2853fc9362 Make BytesSyncLogger's implementation details internal.
Provide NewBytesSyncLogger that returns an opaque data structure.
Automatically start up the logging loop goroutine in NewBytesSyncLogger.
2020-04-23 21:38:44 -06:00
David Fifield
ee2fb42d33 Immediately and unconditionally grant new SOCKS connections. 2020-04-23 14:00:03 -06:00
Arlo Breault
5fa7578655 Rename logToStateDir/keepLocalAddresses to kebab case
https://en.wikipedia.org/wiki/Letter_case#Special_case_styles
2020-03-25 11:53:24 -04:00
Arlo Breault
f58c865d82 Add unsafe logging 2020-03-25 11:53:24 -04:00
Cecylia Bocovich
920f6791f3 Add a go.mod and go.sum for snowflake 2020-03-05 09:21:17 -05:00
Arlo Breault
0fae4ee8ea Remove local LAN address ICE candidates
Unfortunately, the "public" RTCIceTransportPolicy was removed.

https://developer.mozilla.org/en-US/docs/Web/API/RTCConfiguration#RTCIceTransportPolicy_enum

Trac: 19026
2020-02-08 10:13:40 -05:00
David Fifield
a2292ce35b Make timeout constants into time.Duration values.
This slightly changes some log messages.
2020-01-31 00:08:50 -07:00
David Fifield
dfb83c6606 Allow handling multiple SOCKS connections simultaneously.
Close the SOCKS connection in the same function that opens it.
2020-01-30 10:18:23 -07:00
David Fifield
2fb52c8639 Check for an invalid broker URL at a higher level.
Instead of returning nil from NewBrokerChannel and having
WebRTCDialer.Catch check for nil, let NewBrokerChannel return an error
and bail out before calling WebRTCDialer.Catch.

Suggested by cohosh.
https://bugs.torproject.org/33040#comment:3
2020-01-27 20:50:26 -07:00
David Fifield
febb4936f6 Refactor SOCKS-related logging. 2020-01-23 11:24:00 -07:00
David Fifield
aa3999857f Move ICE server logging out of parseIceServers. 2020-01-23 11:24:00 -07:00
David Fifield
509f634506 NewWebRTCDialer cannot return an error. 2020-01-23 11:24:00 -07:00
David Fifield
d6467ff585 Formatting improvements. 2020-01-23 10:43:31 -07:00
David Fifield
e27709080a Update a comment: we no longer keep track of handlers. 2020-01-23 10:42:35 -07:00
David Fifield
5ff75e1034 Remove erroneous logging around pt.*Error calls.
These functions are called for their side effect of sending a PT error
message on stdout; they also return a representation of the error
message as an error object for the caller to use if it wishes. These
functions *always* return a non-nil error object; it is not something to
be logged, any more than the return value of errors.New is.

The mistaken logging was added in
https://bugs.torproject.org/31794
b26c7a7a73
3ec9dd19fa
ed3d42e1ec
2020-01-20 23:57:31 -07:00
Cecylia Bocovich
0f99c5ab12 Touched up snowflake client tests
There were a few tests that needed refreshing since the introduction of
the pion library. Also added a few tests for the ICE server parsing
function in the client.
2019-12-06 11:30:34 -05:00
David Fifield
b4f4b29a03 Stop counting handlers before terminating.
The requirement to do so is obsolete and has already been removed from
other pluggable transports.

https://bugs.torproject.org/32046
2019-10-11 16:50:25 -06:00
Shane Howearth
8bbdb3b51a Bring code into line with Golangci-lint linters
- Error strings are no longer capitalized nor end with punctuation
- Alias import
- Remove extraneous initilisation code (No need to provide zero value
	for variables, because the compiler does that anyway)
2019-10-08 10:25:44 -04:00
Shane Howearth
b26c7a7a73 Handle generated errors in client 2019-10-08 10:25:44 -04:00
Cecylia Bocovich
b5c50b69d0 Ported snowflake client to work with pion/webrtc
Modified the snowflake client to use pion/webrtc as the webrtc library.
This involved a few small changes to match function signatures as well
as several larger ones:
- OnNegotiationNeeded is no longer supported, so CreateOffer and
SetLocalDescription have been moved to a go routine called after the
other peer connection callbacks are set
- We need our own deserialize/serialize functions
- We need to use a SettingEngine in order to access the
OnICEGatheringStateChange callback
2019-10-08 09:27:52 -04:00
Arlo Breault
622005c79e Remove copy/paste signalling 2019-05-08 11:21:56 -04:00
Cecylia Bocovich
b4a4a256db Ported log sanitization to client 2019-04-12 09:52:23 -04:00
David Fifield
a554439370 Link to #26360 for why we blackhole logs without -log.
Maybe we'll able to remove this in the far future.
2018-12-18 21:24:32 -07:00
Arlo Breault
cce7ee64a7 Start refactoring out a client and library 2018-11-20 22:38:02 -05:00
David Fifield
6077141f4a Log to io.Discard if no log file is set.
https://bugs.torproject.org/25600#comment:14

Snowflake in Tor Browser has been hanging after surfing for a while.
(Tor reports "no running bridges".) It only began happening after commit
12922a232b, which caused snowflake-client not to log to a file by
default (leaving it to log to its default stderr). What seems to be
happening is that tor doesn't read from its PT clients' stderr, leaving
a buffer to fill up that eventually causes a hang.
2018-06-10 16:41:32 -07:00
David Fifield
bdc1798adb Exit immediately after SIGTERM is there are no signals running.
Cf. https://bugs.torproject.org/24875
2018-03-21 00:51:04 -07:00
David Fifield
6a9c2bf951 Don't log "SOCKS accepted" if there was an Accept error.
This actually caused a nil pointer dereference panic when Accept
returned an error, because conn was nil.
2018-03-21 00:43:17 -07:00
Arlo Breault
8a31312ca1 Provide a flag to Log to state dir 2018-03-13 15:00:58 -04:00
Arlo Breault
bbb5a6aca2 webrtc.NewIceServer already does this split / validation
It also expects to be called with a non-empty string, which isn't
the case with this Split which always envokes the loop at least
once.  If -ice was omitted, an error was logged.
2017-10-18 11:15:53 -04:00
David Fifield
0c02af35d0 Move handling of -ice option into main.
Rather than having it happen as a side effect of flag parsing.

Having it happen as a side effect of flag parsing caused log messages
related to handling the option (e.g. "IceServerList:") to always go to
stderr, despite the presence of a -log option. This is because the
requested log file had not been opened yet.
2017-08-14 12:33:28 -07:00
David Fifield
86a244c39e Make client and server-webrtc log in UTC. 2017-07-16 14:58:34 -07:00
David Fifield
12922a232b Make logging optional and controlled by a -log option. 2017-06-29 15:46:57 -07:00