Commit graph

104 commits

Author SHA1 Message Date
David Fifield
19b317e781 Use ListenAndServe{TLS} rather than separate Listen and Serve.
This is a port of commit cea86c937dc278ba6b2100c238b1d5206bbae2f0 from
meek. Its purpose is to remove the need to copy-paste parts of
net/http.Server.ListenAndServeTLS. Here is a copy of the commit message
from meek:

    The net/http package provides ListenAndServe and ListenAndServeTLS
    functions, but it doesn't provide a way to set up a listener without
    also entering an infinite serve loop. This matters for
    ListenAndServeTLS, which sets up a lot of magic behind the scenes for
    TLS and HTTP/2 support. Formerly, we had copy-pasted code from
    ListenAndServeTLS, but that code has only gotten more complicated in
    upstream net/http.

    The price we pay for this is that it's no longer possible for a server
    bindaddr to ask to listen on port 0 (i.e., a random ephemeral port).
    That's because we never get a change to find out what the listening
    address is, before entering the serve loop.

    What we gain is HTTP/2 support; formerly our copy-pasted code had the
    side effect of disabling HTTP/2, because it was copied from an older
    version and did things like
            config.NextProtos = []string{"http/1.1"}

    The new code calls http2.ConfigureServer first, but that's not what's
    providing HTTP/2 support. HTTP/2 support happens by default. The reason
    we call http2.ConfigureServer is because we need to set
    TLSConfig.GetCertificate, and http2.ConfigureServer is a convenient way
    to initialize TLSConfig in a way that is guaranteed to work with HTTP/2.
2018-03-13 19:18:52 -07:00
David Fifield
d0686b1c8d Use Manager.HTTPHandler for automatic TLS support in the server.
As with commit fcc274ac68 for the broker,
we need to start using the HTTP-01 challenge type in the Snowflake
websocket server transport plugin.
https://bugs.torproject.org/25346
2018-03-05 21:16:51 -08:00
David Fifield
ee4e0aa160 Trivial doc update: we do report the USERADDR now. 2018-03-05 15:27:27 -08:00
David Fifield
9ab8ea3df4 Use %.f not %.g to format stats interval.
fmt.Sprintf("%.g", 86400.4) → "9e+04"
fmt.Sprintf("%.f", 86400.4) → "86400"
2017-10-20 12:26:44 -07:00
David Fifield
085f253757 Fix periodic stats reporting.
The time interval was being reset every time a new connection came in.
2017-10-19 00:00:26 -07:00
David Fifield
58556dc07b Keep track of clientAddr in statsChannel. 2017-10-17 22:19:43 -07:00
David Fifield
4697746120 Actually call clientAddr. 2017-10-17 22:19:23 -07:00
David Fifield
1ef6211c6c Rough tests for the clientAddr function. 2017-10-17 22:13:56 -07:00
David Fifield
d9e8f8f647 Log once a day how many connections had client_ip.
This is a sanity check against any catastrophic failure of our parsing
code.
2017-10-17 22:12:21 -07:00
David Fifield
c84e1a2e03 Add a dummy port number to USERADDR.
Current versions of tor accept USERADDR with or without a port number,
but future versions may become more strict and require the port number.
https://bugs.torproject.org/23080
2017-10-17 22:12:21 -07:00
David Fifield
83f8712078 Factor out a function to extract the client IP address. 2017-10-17 22:12:21 -07:00
David Fifield
9e5eb7f5ee Pass the incoming client_ip into the ExtORPort. 2017-10-14 15:06:36 -04:00
David Fifield
db2251345d Close the log file in server. 2017-07-16 15:03:56 -07:00
David Fifield
a936fc7e9b README and documentation for server. 2017-01-21 14:53:51 -08:00
David Fifield
1f8be86a01 Add a DirCache for certificates under TOR_PT_STATE_LOCATION.
This way, we don't lose state of certificates every time the process is
restarted. There's a possibility, otherwise, that if you have to restart
the server rapidly, you might run into Let's Encrypt rate limits and be
unable to create a cert for a while.
https://godoc.org/rsc.io/letsencrypt#hdr-Persistent_Storage
2017-01-21 14:23:15 -08:00
David Fifield
b0826304a4 Make certManager a pointer and only set it when !disableTLS. 2017-01-21 14:01:43 -08:00
David Fifield
1b1fb37afe Add "hostname" args to the bridge descriptor as well. 2017-01-20 19:17:08 -08:00
David Fifield
80acfbd8d8 Explain more in usage. 2017-01-20 19:17:08 -08:00
David Fifield
b86bbd748d Add --acme-email option. 2017-01-20 19:17:08 -08:00
David Fifield
61310600c3 Automatically fetch certificates from Let's Encrypt.
This removes the --tls-cert and --tls-keys options and replaces them
with --acme-hostname and (optional) --acme-email. It uses
https://godoc.org/golang.org/x/crypto/acme/autocert, which is kind of a
successor to https://godoc.org/rsc.io/letsencrypt.

The autocert package only works when the listener runs on port 443. For
that reason, if TOR_PT_SERVER_BINDADDR asks for a port other than 443,
the program will open an *additional* listening port on 443. If there is
an error opening the listener, it is reported through an SMETHOD-ERROR
for the requested address.

The inspiration for this code came from George Tankersley's patch for
meek-server:
https://bugs.torproject.org/18655#comment:8
https://github.com/gtank/meek/tree/letsencrypt
2017-01-20 19:17:08 -08:00
David Fifield
af70d49e96 Add a log messages when failing to open a listener. 2017-01-20 17:56:52 -08:00
David Fifield
42cdd53077 continue, not break, after SmethodError.
This was a bug added in 8378f85952 when
this code was moved out of a switch.
2017-01-20 15:22:11 -08:00
David Fifield
8378f85952 Remove a level of indentation in server. 2017-01-20 10:19:25 -08:00
David Fifield
d8411816c4 Include "tls=no" or "tls=yes" in the bridge descriptor.
Might make this controlled by ServerTransportOptions instead of the
--disable-tls command line option.
2017-01-20 10:13:39 -08:00
David Fifield
aa204af6b1 Make log messages more uniform. 2017-01-20 09:43:33 -08:00
David Fifield
21e27d3b3c Use log.Fatalf instead of log.Printf + os.Exit in server. 2017-01-20 09:39:53 -08:00
David Fifield
11f3bbe3c2 go fmt in server. 2017-01-19 16:42:29 -08:00
David Fifield
15963688c2 Remove support for the base64 WebSocket subprotocol.
This was only needed for very very old Firefox before WebSockets were
properly standardized.
2017-01-18 20:00:59 -08:00
David Fifield
3e78251715 Remove the --port option from WebSocket server.
Recommend ServerTransportListenAddr in torrc instead.
2017-01-18 19:33:07 -08:00
David Fifield
2a9126a158 Simplify signal handling in WebSocket server.
pt-spec no longer talks about SIGINT.
2017-01-18 19:24:02 -08:00
David Fifield
57f72ab4ff Remove unused logFile variable. 2017-01-18 19:20:30 -08:00
Arlo Breault
5cd2a226aa Enable tls websockets on the server
* Code lifted from meek-server
2016-12-19 16:07:02 -08:00
David Fifield
57c0724491 Use 192.81.135.242:9902 as the default relay.
This is the relay that reports using the transport name "snowflake".
https://bugs.torproject.org/18627
2016-03-27 12:49:20 -07:00
David Fifield
346f316038 Use "ExtORPort auto" in documentation. 2016-03-26 15:34:27 -07:00
David Fifield
a269053ac2 Make Snowflake-specific changes to the websocket server.
Change the transport name to "snowflake" and don't report the remote
client address to the ExtORPort.
2016-03-26 15:25:06 -07:00
David Fifield
cfca47674e Build the websocket-server.
Patch server.go to refer to out-of-tree websocket library.
2016-03-26 15:24:56 -07:00
David Fifield
e53705519e Add a copy of websocket-server in the server directory.
From commit ea3ee6b5cf035a9465c02b4a2b38882c9c6a7050 in
https://git.torproject.org/pluggable-transports/websocket.git
2016-03-26 15:24:56 -07:00
David Fifield
c4cfc7f8ba Move server to server-webrtc.
To make room for the WebSocket server we're actually going to use as a
primary server. Move server-webrtc docs to server-webrtc/README.md.
2016-03-26 15:24:44 -07:00
Arlo Breault
9fd471b4c4 Update to go-webrtc HEAD 2016-02-15 12:37:52 -08:00
Arlo Breault
5c166f5015 s/facilitator/broker/ 2016-01-19 21:52:03 -08:00
Arlo Breault
dcb901e408 Use chan struct{} instead
* Similar to a77ae6b771.
2016-01-19 13:41:19 -08:00
David Fifield
5279e32e3e Remove the default -http option from server/torrc.
We'll ask people to insert it manually if they want to test that way.
2016-01-18 23:03:42 -08:00
David Fifield
ff7cc926f7 Add an HTTP signaling receiver in the server.
This is a stand-in for some kind of faciliator that is separate from the
server transport plugin.
2016-01-18 21:30:31 -08:00
David Fifield
ac8669b38f Refactor signal receiving in server.
There's one FIFO reader goroutine instead of one per bindaddr.
makePeerConnectionFromOffer gives you a PeerConnection with an answer
and also sets up callbacks to pass a webRTCConn to datachannelHandler
when ready.
2016-01-18 21:13:08 -08:00
David Fifield
48db4ac132 Log errors from main. 2016-01-17 23:22:23 -08:00
David Fifield
726ad2bfb9 Make logging in server match client (no payloads). 2016-01-16 09:37:27 -08:00
David Fifield
bf2a825fce Log write on the server side. 2016-01-09 19:24:57 -08:00
David Fifield
c519813cf7 Keep quoted log messages ASCII. 2016-01-09 19:24:05 -08:00
Arlo Breault
0711b3e1b9 Bootstrapped 100%: Done 2016-01-09 10:42:02 -08:00
Arlo Breault
10c9685a33 Unblock the data channel 2016-01-09 10:08:22 -08:00