config.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. /*
  2. * Copyright (c) 2015, Psiphon Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package psiphon
  20. import (
  21. "encoding/json"
  22. "errors"
  23. "fmt"
  24. "net/http"
  25. "os"
  26. "strconv"
  27. "time"
  28. )
  29. // TODO: allow all params to be configured
  30. const (
  31. LEGACY_DATA_STORE_FILENAME = "psiphon.db"
  32. DATA_STORE_FILENAME = "psiphon.boltdb"
  33. CONNECTION_WORKER_POOL_SIZE = 10
  34. TUNNEL_POOL_SIZE = 1
  35. TUNNEL_CONNECT_TIMEOUT_SECONDS = 20
  36. TUNNEL_OPERATE_SHUTDOWN_TIMEOUT = 1 * time.Second
  37. TUNNEL_PORT_FORWARD_DIAL_TIMEOUT_SECONDS = 10
  38. TUNNEL_SSH_KEEP_ALIVE_PAYLOAD_MAX_BYTES = 256
  39. TUNNEL_SSH_KEEP_ALIVE_PERIOD_MIN = 60 * time.Second
  40. TUNNEL_SSH_KEEP_ALIVE_PERIOD_MAX = 120 * time.Second
  41. TUNNEL_SSH_KEEP_ALIVE_PERIODIC_TIMEOUT_SECONDS = 30
  42. TUNNEL_SSH_KEEP_ALIVE_PERIODIC_INACTIVE_PERIOD = 10 * time.Second
  43. TUNNEL_SSH_KEEP_ALIVE_PROBE_TIMEOUT_SECONDS = 5
  44. TUNNEL_SSH_KEEP_ALIVE_PROBE_INACTIVE_PERIOD = 10 * time.Second
  45. ESTABLISH_TUNNEL_TIMEOUT_SECONDS = 300
  46. ESTABLISH_TUNNEL_WORK_TIME = 60 * time.Second
  47. ESTABLISH_TUNNEL_PAUSE_PERIOD_SECONDS = 5
  48. ESTABLISH_TUNNEL_SERVER_AFFINITY_GRACE_PERIOD = 1 * time.Second
  49. HTTP_PROXY_ORIGIN_SERVER_TIMEOUT_SECONDS = 15
  50. HTTP_PROXY_MAX_IDLE_CONNECTIONS_PER_HOST = 50
  51. FETCH_REMOTE_SERVER_LIST_TIMEOUT_SECONDS = 30
  52. FETCH_REMOTE_SERVER_LIST_RETRY_PERIOD_SECONDS = 30
  53. FETCH_REMOTE_SERVER_LIST_STALE_PERIOD = 6 * time.Hour
  54. PSIPHON_API_CLIENT_SESSION_ID_LENGTH = 16
  55. PSIPHON_API_SERVER_TIMEOUT_SECONDS = 20
  56. PSIPHON_API_SHUTDOWN_SERVER_TIMEOUT = 1 * time.Second
  57. PSIPHON_API_STATUS_REQUEST_PERIOD_MIN = 5 * time.Minute
  58. PSIPHON_API_STATUS_REQUEST_PERIOD_MAX = 10 * time.Minute
  59. PSIPHON_API_STATUS_REQUEST_SHORT_PERIOD_MIN = 5 * time.Second
  60. PSIPHON_API_STATUS_REQUEST_SHORT_PERIOD_MAX = 10 * time.Second
  61. PSIPHON_API_STATUS_REQUEST_PADDING_MAX_BYTES = 256
  62. PSIPHON_API_CONNECTED_REQUEST_PERIOD = 24 * time.Hour
  63. PSIPHON_API_CONNECTED_REQUEST_RETRY_PERIOD = 5 * time.Second
  64. PSIPHON_API_TUNNEL_STATS_MAX_COUNT = 100
  65. PSIPHON_API_CLIENT_VERIFICATION_REQUEST_RETRY_PERIOD = 5 * time.Second
  66. FETCH_ROUTES_TIMEOUT_SECONDS = 60
  67. DOWNLOAD_UPGRADE_TIMEOUT = 15 * time.Minute
  68. DOWNLOAD_UPGRADE_RETRY_PERIOD_SECONDS = 30
  69. DOWNLOAD_UPGRADE_STALE_PERIOD = 6 * time.Hour
  70. IMPAIRED_PROTOCOL_CLASSIFICATION_DURATION = 2 * time.Minute
  71. IMPAIRED_PROTOCOL_CLASSIFICATION_THRESHOLD = 3
  72. TOTAL_BYTES_TRANSFERRED_NOTICE_PERIOD = 5 * time.Minute
  73. )
  74. // To distinguish omitted timeout params from explicit 0 value timeout
  75. // params, these params are int pointers. nil means no param was supplied
  76. // so use the default; a non-nil pointer to 0 means no timeout.
  77. // Config is the Psiphon configuration specified by the application. This
  78. // configuration controls the behavior of the core tunnel functionality.
  79. type Config struct {
  80. // LogFilename specifies a file to receive event notices (JSON format)
  81. // By default, notices are emitted to stdout.
  82. LogFilename string
  83. // DataStoreDirectory is the directory in which to store the persistent
  84. // database, which contains information such as server entries.
  85. // By default, current working directory.
  86. //
  87. // Warning: If the datastore file, DataStoreDirectory/DATA_STORE_FILENAME,
  88. // exists but fails to open for any reason (checksum error, unexpected file
  89. // format, etc.) it will be deleted in order to pave a new datastore and
  90. // continue running.
  91. DataStoreDirectory string
  92. // PropagationChannelId is a string identifier which indicates how the
  93. // Psiphon client was distributed. This parameter is required.
  94. // This value is supplied by and depends on the Psiphon Network, and is
  95. // typically embedded in the client binary.
  96. PropagationChannelId string
  97. // PropagationChannelId is a string identifier which indicates who
  98. // is sponsoring this Psiphon client. One purpose of this value is to
  99. // determine the home pages for display. This parameter is required.
  100. // This value is supplied by and depends on the Psiphon Network, and is
  101. // typically embedded in the client binary.
  102. SponsorId string
  103. // RemoteServerListUrl is a URL which specifies a location to fetch
  104. // out-of-band server entries. This facility is used when a tunnel cannot
  105. // be established to known servers.
  106. // This value is supplied by and depends on the Psiphon Network, and is
  107. // typically embedded in the client binary.
  108. RemoteServerListUrl string
  109. // RemoteServerListDownloadFilename specifies a target filename for
  110. // storing the remote server list download. Data is stored in co-located
  111. // files (RemoteServerListDownloadFilename.part*) to allow for resumable
  112. // downloading. If not specified, the default is to use the
  113. // remote object name as the filename, stored in the current working
  114. // directory.
  115. RemoteServerListDownloadFilename string
  116. // RemoteServerListSignaturePublicKey specifies a public key that's
  117. // used to authenticate the remote server list payload.
  118. // This value is supplied by and depends on the Psiphon Network, and is
  119. // typically embedded in the client binary.
  120. RemoteServerListSignaturePublicKey string
  121. // ClientVersion is the client version number that the client reports
  122. // to the server. The version number refers to the host client application,
  123. // not the core tunnel library. One purpose of this value is to enable
  124. // automatic updates.
  125. // This value is supplied by and depends on the Psiphon Network, and is
  126. // typically embedded in the client binary.
  127. // Note that sending a ClientPlatform string which includes "windows"
  128. // (case insensitive) and a ClientVersion of <= 44 will cause an
  129. // error in processing the response to DoConnectedRequest calls.
  130. ClientVersion string
  131. // ClientPlatform is the client platform ("Windows", "Android", etc.) that
  132. // the client reports to the server.
  133. ClientPlatform string
  134. // TunnelWholeDevice is a flag that is passed through to the handshake
  135. // request for stats purposes. Set to 1 when the host application is tunneling
  136. // the whole device, 0 otherwise.
  137. TunnelWholeDevice int
  138. // EgressRegion is a ISO 3166-1 alpha-2 country code which indicates which
  139. // country to egress from. For the default, "", the best performing server
  140. // in any country is selected.
  141. EgressRegion string
  142. // TunnelProtocol indicates which protocol to use. Valid values include:
  143. // "SSH", "OSSH", "UNFRONTED-MEEK-OSSH", "UNFRONTED-MEEK-HTTPS-OSSH",
  144. // "FRONTED-MEEK-OSSH", "FRONTED-MEEK-HTTP-OSSH". For the default, "",
  145. // the best performing protocol is used.
  146. TunnelProtocol string
  147. // EstablishTunnelTimeoutSeconds specifies a time limit after which to halt
  148. // the core tunnel controller if no tunnel has been established. The default
  149. // is ESTABLISH_TUNNEL_TIMEOUT_SECONDS.
  150. EstablishTunnelTimeoutSeconds *int
  151. // ListenInterface specifies which interface to listen on. If no interface
  152. // is provided then listen on 127.0.0.1.
  153. // If 'any' is provided then use 0.0.0.0.
  154. // If there are multiple IP addresses on an interface use the first IPv4 address.
  155. ListenInterface string
  156. // LocalSocksProxyPort specifies a port number for the local SOCKS proxy
  157. // running at 127.0.0.1. For the default value, 0, the system selects a free
  158. // port (a notice reporting the selected port is emitted).
  159. LocalSocksProxyPort int
  160. // LocalHttpProxyPort specifies a port number for the local HTTP proxy
  161. // running at 127.0.0.1. For the default value, 0, the system selects a free
  162. // port (a notice reporting the selected port is emitted).
  163. LocalHttpProxyPort int
  164. // ConnectionWorkerPoolSize specifies how many connection attempts to attempt
  165. // in parallel. The default, 0, uses CONNECTION_WORKER_POOL_SIZE which is
  166. // recommended.
  167. ConnectionWorkerPoolSize int
  168. // TunnelPoolSize specifies how many tunnels to run in parallel. Port forwards
  169. // are multiplexed over multiple tunnels. The default, 0, uses TUNNEL_POOL_SIZE
  170. // which is recommended.
  171. TunnelPoolSize int
  172. // UpstreamProxyUrl is a URL specifying an upstream proxy to use for all
  173. // outbound connections. The URL should include proxy type and authentication
  174. // information, as required. See example URLs here:
  175. // https://github.com/Psiphon-Labs/psiphon-tunnel-core/tree/master/psiphon/upstreamproxy
  176. UpstreamProxyUrl string
  177. // UpstreamProxyCustomHeaders is a set of additional arbitrary HTTP headers that are
  178. // added to all requests made through the upstream proxy specified by UpstreamProxyUrl
  179. // NOTE: Only HTTP(s) proxies use this if specified
  180. UpstreamProxyCustomHeaders http.Header
  181. // NetworkConnectivityChecker is an interface that enables the core tunnel to call
  182. // into the host application to check for network connectivity. This parameter is
  183. // only applicable to library deployments.
  184. NetworkConnectivityChecker NetworkConnectivityChecker
  185. // DeviceBinder is an interface that enables the core tunnel to call
  186. // into the host application to bind sockets to specific devices. This is used
  187. // for VPN routing exclusion. This parameter is only applicable to library
  188. // deployments.
  189. DeviceBinder DeviceBinder
  190. // DnsServerGetter is an interface that enables the core tunnel to call
  191. // into the host application to discover the native network DNS server settings.
  192. // This parameter is only applicable to library deployments.
  193. DnsServerGetter DnsServerGetter
  194. // HostNameTransformer is an interface that enables pluggable hostname
  195. // transformation circumvention strategies.
  196. HostNameTransformer HostNameTransformer
  197. // TargetServerEntry is an encoded server entry. When specified, this server entry
  198. // is used exclusively and all other known servers are ignored.
  199. TargetServerEntry string
  200. // DisableApi disables Psiphon server API calls including handshake, connected,
  201. // status, etc. This is used for special case temporary tunnels (Windows VPN mode).
  202. DisableApi bool
  203. // DisableRemoteServerListFetcher disables fetching remote server lists. This is
  204. // used for special case temporary tunnels.
  205. DisableRemoteServerListFetcher bool
  206. // SplitTunnelRoutesUrlFormat is an URL which specifies the location of a routes
  207. // file to use for split tunnel mode. The URL must include a placeholder for the
  208. // client region to be supplied. Split tunnel mode uses the routes file to classify
  209. // port forward destinations as foreign or domestic and does not tunnel domestic
  210. // destinations. Split tunnel mode is on when all the SplitTunnel parameters are
  211. // supplied.
  212. // This value is supplied by and depends on the Psiphon Network, and is
  213. // typically embedded in the client binary.
  214. SplitTunnelRoutesUrlFormat string
  215. // SplitTunnelRoutesSignaturePublicKey specifies a public key that's
  216. // used to authenticate the split tunnel routes payload.
  217. // This value is supplied by and depends on the Psiphon Network, and is
  218. // typically embedded in the client binary.
  219. SplitTunnelRoutesSignaturePublicKey string
  220. // SplitTunnelDnsServer specifies a DNS server to use when resolving port
  221. // forward target domain names to IP addresses for classification. The DNS
  222. // server must support TCP requests.
  223. SplitTunnelDnsServer string
  224. // UpgradeDownloadUrl specifies a URL from which to download a host client upgrade
  225. // file, when one is available. The core tunnel controller provides a resumable
  226. // download facility which downloads this resource and emits a notice when complete.
  227. // This value is supplied by and depends on the Psiphon Network, and is
  228. // typically embedded in the client binary.
  229. UpgradeDownloadUrl string
  230. // UpgradeDownloadClientVersionHeader specifies the HTTP header name for the
  231. // entity at UpgradeDownloadUrl which specifies the client version (an integer
  232. // value). A HEAD request may be made to check the version number available at
  233. // UpgradeDownloadUrl. UpgradeDownloadClientVersionHeader is required when
  234. // UpgradeDownloadUrl is specified.
  235. UpgradeDownloadClientVersionHeader string
  236. // UpgradeDownloadFilename is the local target filename for an upgrade download.
  237. // This parameter is required when UpgradeDownloadUrl is specified.
  238. // Data is stored in co-located files (UpgradeDownloadFilename.part*) to allow
  239. // for resumable downloading.
  240. UpgradeDownloadFilename string
  241. // EmitBytesTransferred indicates whether to emit periodic notices showing
  242. // bytes sent and received.
  243. EmitBytesTransferred bool
  244. // UseIndistinguishableTLS enables use of an alternative TLS stack with a less
  245. // distinct fingerprint (ClientHello content) than the stock Go TLS.
  246. // UseIndistinguishableTLS only applies to untunneled TLS connections. This
  247. // parameter is only supported on platforms built with OpenSSL.
  248. // Requires TrustedCACertificatesFilename to be set.
  249. UseIndistinguishableTLS bool
  250. // UseTrustedCACertificates toggles use of the trusted CA certs, specified
  251. // in TrustedCACertificatesFilename, for tunneled TLS connections that expect
  252. // server certificates signed with public certificate authorities (currently,
  253. // only upgrade downloads). This option is used with stock Go TLS in cases where
  254. // Go may fail to obtain a list of root CAs from the operating system.
  255. // Requires TrustedCACertificatesFilename to be set.
  256. UseTrustedCACertificatesForStockTLS bool
  257. // TrustedCACertificatesFilename specifies a file containing trusted CA certs.
  258. // The file contents should be compatible with OpenSSL's SSL_CTX_load_verify_locations.
  259. // When specified, this enables use of indistinguishable TLS for HTTPS requests
  260. // that require typical (system CA) server authentication.
  261. TrustedCACertificatesFilename string
  262. // DisablePeriodicSshKeepAlive indicates whether to send an SSH keepalive every
  263. // 1-2 minutes, when the tunnel is idle. If the SSH keepalive times out, the tunnel
  264. // is considered to have failed.
  265. DisablePeriodicSshKeepAlive bool
  266. // DeviceRegion is the optional, reported region the host device is running in.
  267. // This input value should be a ISO 3166-1 alpha-2 country code. The device region
  268. // is reported to the server in the connected request and recorded for Psiphon
  269. // stats.
  270. // When provided, this value may be used, pre-connection, to select performance
  271. // or circumvention optimization strategies for the given region.
  272. DeviceRegion string
  273. // EmitDiagnosticNotices indicates whether to output notices containing detailed
  274. // information about the Psiphon session. As these notices may contain sensitive
  275. // network information, they should not be insecurely distributed or displayed
  276. // to users. Default is off.
  277. EmitDiagnosticNotices bool
  278. // TunnelConnectTimeoutSeconds specifies a single tunnel connection sequence timeout.
  279. // Zero value means that connection process will not time out.
  280. // If omitted, the default value is TUNNEL_CONNECT_TIMEOUT_SECONDS.
  281. TunnelConnectTimeoutSeconds *int
  282. // TunnelPortForwardTimeoutSeconds specifies a timeout per SSH port forward.
  283. // Zero value means a port forward will not time out.
  284. // If omitted, the default value is TUNNEL_PORT_FORWARD_DIAL_TIMEOUT_SECONDS.
  285. TunnelPortForwardTimeoutSeconds *int
  286. // TunnelSshKeepAliveProbeTimeoutSeconds specifies a timeout value for "probe"
  287. // SSH keep-alive that is sent upon port forward failure.
  288. // Zero value means keep-alive request will not time out.
  289. // If omitted, the default value is TUNNEL_SSH_KEEP_ALIVE_PROBE_TIMEOUT_SECONDS.
  290. TunnelSshKeepAliveProbeTimeoutSeconds *int
  291. // TunnelSshKeepAlivePeriodicTimeoutSeconds specifies a timeout value for regular
  292. // SSH keep-alives that are sent periodically.
  293. // Zero value means keep-alive request will not time out.
  294. // If omitted, the default value is TUNNEL_SSH_KEEP_ALIVE_PERIODIC_TIMEOUT_SECONDS.
  295. TunnelSshKeepAlivePeriodicTimeoutSeconds *int
  296. // FetchRemoteServerListTimeoutSeconds specifies a timeout value for remote server list
  297. // HTTP request. Zero value means that request will not time out.
  298. // If omitted, the default value is FETCH_REMOTE_SERVER_LIST_TIMEOUT_SECONDS.
  299. FetchRemoteServerListTimeoutSeconds *int
  300. // PsiphonApiServerTimeoutSeconds specifies a timeout for periodic API HTTP
  301. // requests to Psiphon server such as stats, home pages, etc.
  302. // Zero value means that request will not time out.
  303. // If omitted, the default value is PSIPHON_API_SERVER_TIMEOUT_SECONDS.
  304. // Note that this value is overridden for final stats requests during shutdown
  305. // process in order to prevent hangs.
  306. PsiphonApiServerTimeoutSeconds *int
  307. // FetchRoutesTimeoutSeconds specifies a timeout value for split tunnel routes
  308. // HTTP request. Zero value means that request will not time out.
  309. // If omitted, the default value is FETCH_ROUTES_TIMEOUT_SECONDS.
  310. FetchRoutesTimeoutSeconds *int
  311. // HttpProxyOriginServerTimeoutSeconds specifies an HTTP response header timeout
  312. // value in various HTTP relays found in httpProxy.
  313. // Zero value means that request will not time out.
  314. // If omitted, the default value is HTTP_PROXY_ORIGIN_SERVER_TIMEOUT_SECONDS.
  315. HttpProxyOriginServerTimeoutSeconds *int
  316. // FetchRemoteServerListRetryPeriodSeconds specifies the delay before
  317. // resuming a remote server list download after a failure.
  318. // If omitted, the default value FETCH_REMOTE_SERVER_LIST_RETRY_PERIOD_SECONDS.
  319. FetchRemoteServerListRetryPeriodSeconds *int
  320. // DownloadUpgradestRetryPeriodSeconds specifies the delay before
  321. // resuming a client upgrade download after a failure.
  322. // If omitted, the default value DOWNLOAD_UPGRADE_RETRY_PERIOD_SECONDS.
  323. DownloadUpgradeRetryPeriodSeconds *int
  324. // EstablishTunnelPausePeriodSeconds specifies the delay between attempts
  325. // to establish tunnels. Briefly pausing allows for network conditions to improve
  326. // and for asynchronous operations such as fetch remote server list to complete.
  327. // If omitted, the default value is ESTABLISH_TUNNEL_PAUSE_PERIOD_SECONDS.
  328. EstablishTunnelPausePeriodSeconds *int
  329. }
  330. // LoadConfig parses and validates a JSON format Psiphon config JSON
  331. // string and returns a Config struct populated with config values.
  332. func LoadConfig(configJson []byte) (*Config, error) {
  333. var config Config
  334. err := json.Unmarshal(configJson, &config)
  335. if err != nil {
  336. return nil, ContextError(err)
  337. }
  338. // Do SetEmitDiagnosticNotices first, to ensure config file errors are emitted.
  339. if config.EmitDiagnosticNotices {
  340. SetEmitDiagnosticNotices(true)
  341. }
  342. // These fields are required; the rest are optional
  343. if config.PropagationChannelId == "" {
  344. return nil, ContextError(
  345. errors.New("propagation channel ID is missing from the configuration file"))
  346. }
  347. if config.SponsorId == "" {
  348. return nil, ContextError(
  349. errors.New("sponsor ID is missing from the configuration file"))
  350. }
  351. if config.DataStoreDirectory == "" {
  352. config.DataStoreDirectory, err = os.Getwd()
  353. if err != nil {
  354. return nil, ContextError(err)
  355. }
  356. }
  357. if config.ClientVersion == "" {
  358. config.ClientVersion = "0"
  359. }
  360. _, err = strconv.Atoi(config.ClientVersion)
  361. if err != nil {
  362. return nil, ContextError(
  363. fmt.Errorf("invalid client version: %s", err))
  364. }
  365. if config.TunnelProtocol != "" {
  366. if !Contains(SupportedTunnelProtocols, config.TunnelProtocol) {
  367. return nil, ContextError(
  368. errors.New("invalid tunnel protocol"))
  369. }
  370. }
  371. if config.EstablishTunnelTimeoutSeconds == nil {
  372. defaultEstablishTunnelTimeoutSeconds := ESTABLISH_TUNNEL_TIMEOUT_SECONDS
  373. config.EstablishTunnelTimeoutSeconds = &defaultEstablishTunnelTimeoutSeconds
  374. }
  375. if config.ConnectionWorkerPoolSize == 0 {
  376. config.ConnectionWorkerPoolSize = CONNECTION_WORKER_POOL_SIZE
  377. }
  378. if config.TunnelPoolSize == 0 {
  379. config.TunnelPoolSize = TUNNEL_POOL_SIZE
  380. }
  381. if config.NetworkConnectivityChecker != nil {
  382. return nil, ContextError(errors.New("NetworkConnectivityChecker interface must be set at runtime"))
  383. }
  384. if config.DeviceBinder != nil {
  385. return nil, ContextError(errors.New("DeviceBinder interface must be set at runtime"))
  386. }
  387. if config.DnsServerGetter != nil {
  388. return nil, ContextError(errors.New("DnsServerGetter interface must be set at runtime"))
  389. }
  390. if config.HostNameTransformer != nil {
  391. return nil, ContextError(errors.New("HostNameTransformer interface must be set at runtime"))
  392. }
  393. if config.UpgradeDownloadUrl != "" &&
  394. (config.UpgradeDownloadClientVersionHeader == "" || config.UpgradeDownloadFilename == "") {
  395. return nil, ContextError(errors.New(
  396. "UpgradeDownloadUrl requires UpgradeDownloadClientVersionHeader and UpgradeDownloadFilename"))
  397. }
  398. if config.TunnelConnectTimeoutSeconds == nil {
  399. defaultTunnelConnectTimeoutSeconds := TUNNEL_CONNECT_TIMEOUT_SECONDS
  400. config.TunnelConnectTimeoutSeconds = &defaultTunnelConnectTimeoutSeconds
  401. }
  402. if config.TunnelPortForwardTimeoutSeconds == nil {
  403. defaultTunnelPortForwardTimeoutSeconds := TUNNEL_PORT_FORWARD_DIAL_TIMEOUT_SECONDS
  404. config.TunnelPortForwardTimeoutSeconds = &defaultTunnelPortForwardTimeoutSeconds
  405. }
  406. if config.TunnelSshKeepAliveProbeTimeoutSeconds == nil {
  407. defaultTunnelSshKeepAliveProbeTimeoutSeconds := TUNNEL_SSH_KEEP_ALIVE_PROBE_TIMEOUT_SECONDS
  408. config.TunnelSshKeepAliveProbeTimeoutSeconds = &defaultTunnelSshKeepAliveProbeTimeoutSeconds
  409. }
  410. if config.TunnelSshKeepAlivePeriodicTimeoutSeconds == nil {
  411. defaultTunnelSshKeepAlivePeriodicTimeoutSeconds := TUNNEL_SSH_KEEP_ALIVE_PERIODIC_TIMEOUT_SECONDS
  412. config.TunnelSshKeepAlivePeriodicTimeoutSeconds = &defaultTunnelSshKeepAlivePeriodicTimeoutSeconds
  413. }
  414. if config.FetchRemoteServerListTimeoutSeconds == nil {
  415. defaultFetchRemoteServerListTimeoutSeconds := FETCH_REMOTE_SERVER_LIST_TIMEOUT_SECONDS
  416. config.FetchRemoteServerListTimeoutSeconds = &defaultFetchRemoteServerListTimeoutSeconds
  417. }
  418. if config.PsiphonApiServerTimeoutSeconds == nil {
  419. defaultPsiphonApiServerTimeoutSeconds := PSIPHON_API_SERVER_TIMEOUT_SECONDS
  420. config.PsiphonApiServerTimeoutSeconds = &defaultPsiphonApiServerTimeoutSeconds
  421. }
  422. if config.FetchRoutesTimeoutSeconds == nil {
  423. defaultFetchRoutesTimeoutSeconds := FETCH_ROUTES_TIMEOUT_SECONDS
  424. config.FetchRoutesTimeoutSeconds = &defaultFetchRoutesTimeoutSeconds
  425. }
  426. if config.HttpProxyOriginServerTimeoutSeconds == nil {
  427. defaultHttpProxyOriginServerTimeoutSeconds := HTTP_PROXY_ORIGIN_SERVER_TIMEOUT_SECONDS
  428. config.HttpProxyOriginServerTimeoutSeconds = &defaultHttpProxyOriginServerTimeoutSeconds
  429. }
  430. if config.FetchRemoteServerListRetryPeriodSeconds == nil {
  431. defaultFetchRemoteServerListRetryPeriodSeconds := FETCH_REMOTE_SERVER_LIST_RETRY_PERIOD_SECONDS
  432. config.FetchRemoteServerListRetryPeriodSeconds = &defaultFetchRemoteServerListRetryPeriodSeconds
  433. }
  434. if config.DownloadUpgradeRetryPeriodSeconds == nil {
  435. defaultDownloadUpgradeRetryPeriodSeconds := DOWNLOAD_UPGRADE_RETRY_PERIOD_SECONDS
  436. config.DownloadUpgradeRetryPeriodSeconds = &defaultDownloadUpgradeRetryPeriodSeconds
  437. }
  438. if config.EstablishTunnelPausePeriodSeconds == nil {
  439. defaultEstablishTunnelPausePeriodSeconds := ESTABLISH_TUNNEL_PAUSE_PERIOD_SECONDS
  440. config.EstablishTunnelPausePeriodSeconds = &defaultEstablishTunnelPausePeriodSeconds
  441. }
  442. return &config, nil
  443. }