config.go 23 KB

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