Commit graph

35 commits

Author SHA1 Message Date
David Fifield
ea7b9c0223 Wait briefly after calling ListenAndServe{TLS} to see if it errors.
This is a port of commit e3f3054f8b74caa639a6d9be09702693af9a70e7 from
meek.

In the previous commit, we changed from separate Listen and Serve steps
to always calling ListenAndServe. However, we would really like to
immediately get feedback if any errors happen in the Listen step inside
the call, because it's much better for debugging if those errors get
reported to tor through SMETHOD-ERROR--rather than reporting success to
tor and actually logging an error only in the snowflake log. So we wait
100 ms for an error to occur before deciding that the Listen succeeded.

We don't need to apply this hack to the ACME HTTP-01 listener, because
it's a plaintext listener. Unlike in the TLS case, there isn't any
internal magic that the net library does that we have to rely on. We
just call net.ListenTCP and check for an error.
2018-03-13 19:18:52 -07:00
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
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
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