config.go 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026
  1. /*
  2. * Copyright (c) 2016, 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 server
  20. import (
  21. "crypto/rand"
  22. "crypto/rsa"
  23. "crypto/x509"
  24. "encoding/base64"
  25. "encoding/hex"
  26. "encoding/json"
  27. "encoding/pem"
  28. "fmt"
  29. "net"
  30. "os"
  31. "strconv"
  32. "strings"
  33. "sync/atomic"
  34. "time"
  35. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
  36. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/accesscontrol"
  37. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/crypto/ssh"
  38. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
  39. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/osl"
  40. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
  41. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/tactics"
  42. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/values"
  43. "golang.org/x/crypto/nacl/box"
  44. )
  45. const (
  46. SERVER_CONFIG_FILENAME = "psiphond.config"
  47. SERVER_TRAFFIC_RULES_CONFIG_FILENAME = "psiphond-traffic-rules.config"
  48. SERVER_OSL_CONFIG_FILENAME = "psiphond-osl.config"
  49. SERVER_TACTICS_CONFIG_FILENAME = "psiphond-tactics.config"
  50. SERVER_ENTRY_FILENAME = "server-entry.dat"
  51. DEFAULT_SERVER_IP_ADDRESS = "127.0.0.1"
  52. WEB_SERVER_SECRET_BYTE_LENGTH = 32
  53. DISCOVERY_VALUE_KEY_BYTE_LENGTH = 32
  54. SSH_USERNAME_SUFFIX_BYTE_LENGTH = 8
  55. SSH_PASSWORD_BYTE_LENGTH = 32
  56. SSH_RSA_HOST_KEY_BITS = 2048
  57. SSH_OBFUSCATED_KEY_BYTE_LENGTH = 32
  58. PERIODIC_GARBAGE_COLLECTION = 120 * time.Second
  59. STOP_ESTABLISH_TUNNELS_ESTABLISHED_CLIENT_THRESHOLD = 20
  60. DEFAULT_LOG_FILE_REOPEN_RETRIES = 10
  61. )
  62. // Config specifies the configuration and behavior of a Psiphon
  63. // server.
  64. type Config struct {
  65. // LogLevel specifies the log level. Valid values are:
  66. // panic, fatal, error, warn, info, debug
  67. LogLevel string
  68. // LogFilename specifies the path of the file to log
  69. // to. When blank, logs are written to stderr.
  70. LogFilename string
  71. // LogFileReopenRetries specifies how many retries, each with a 1ms delay,
  72. // will be attempted after reopening a rotated log file fails. Retries
  73. // mitigate any race conditions between writes/reopens and file operations
  74. // performed by external log managers, such as logrotate.
  75. //
  76. // When omitted, DEFAULT_LOG_FILE_REOPEN_RETRIES is used.
  77. LogFileReopenRetries *int
  78. // LogFileCreateMode specifies that the Psiphon server should create a new
  79. // log file when one is not found, such as after rotation with logrotate
  80. // configured with nocreate. The value is the os.FileMode value to use when
  81. // creating the file.
  82. //
  83. // When omitted, the Psiphon server does not create log files.
  84. LogFileCreateMode *int
  85. // SkipPanickingLogWriter disables panicking when
  86. // unable to write any logs.
  87. SkipPanickingLogWriter bool
  88. // DiscoveryValueHMACKey is the network-wide secret value
  89. // used to determine a unique discovery strategy.
  90. DiscoveryValueHMACKey string
  91. // GeoIPDatabaseFilenames are paths of GeoIP2/GeoLite2
  92. // MaxMind database files. When empty, no GeoIP lookups are
  93. // performed. Each file is queried, in order, for the
  94. // logged fields: country code, city, and ISP. Multiple
  95. // file support accommodates the MaxMind distribution where
  96. // ISP data in a separate file.
  97. GeoIPDatabaseFilenames []string
  98. // PsinetDatabaseFilename is the path of the file containing
  99. // psinet.Database data.
  100. PsinetDatabaseFilename string
  101. // HostID is the ID of the server host; this is used for API
  102. // event logging.
  103. HostID string
  104. // ServerIPAddress is the public IP address of the server.
  105. ServerIPAddress string
  106. // WebServerPort is the listening port of the web server.
  107. // When <= 0, no web server component is run.
  108. WebServerPort int
  109. // WebServerSecret is the unique secret value that the client
  110. // must supply to make requests to the web server.
  111. WebServerSecret string
  112. // WebServerCertificate is the certificate the client uses to
  113. // authenticate the web server.
  114. WebServerCertificate string
  115. // WebServerPrivateKey is the private key the web server uses to
  116. // authenticate itself to clients.
  117. WebServerPrivateKey string
  118. // WebServerPortForwardAddress specifies the expected network
  119. // address ("<host>:<port>") specified in a client's port forward
  120. // HostToConnect and PortToConnect when the client is making a
  121. // tunneled connection to the web server. This address is always
  122. // exempted from validation against SSH_DISALLOWED_PORT_FORWARD_HOSTS
  123. // and AllowTCPPorts.
  124. WebServerPortForwardAddress string
  125. // WebServerPortForwardRedirectAddress specifies an alternate
  126. // destination address to be substituted and dialed instead of
  127. // the original destination when the port forward destination is
  128. // WebServerPortForwardAddress.
  129. WebServerPortForwardRedirectAddress string
  130. // TunnelProtocolPorts specifies which tunnel protocols to run
  131. // and which ports to listen on for each protocol. Valid tunnel
  132. // protocols include:
  133. // "SSH", "OSSH", "UNFRONTED-MEEK-OSSH", "UNFRONTED-MEEK-HTTPS-OSSH",
  134. // "UNFRONTED-MEEK-SESSION-TICKET-OSSH", "FRONTED-MEEK-OSSH",
  135. // ""FRONTED-MEEK-QUIC-OSSH" FRONTED-MEEK-HTTP-OSSH", "QUIC-OSSH",
  136. // ""MARIONETTE-OSSH", and TAPDANCE-OSSH".
  137. //
  138. // In the case of "MARIONETTE-OSSH" the port value is ignored and must be
  139. // set to 0. The port value specified in the Marionette format is used.
  140. TunnelProtocolPorts map[string]int
  141. // TunnelProtocolPassthroughAddresses specifies passthrough addresses to be
  142. // used for tunnel protocols configured in TunnelProtocolPorts. Passthrough
  143. // is a probing defense which relays all network traffic between a client and
  144. // the passthrough target when the client fails anti-probing tests.
  145. //
  146. // TunnelProtocolPassthroughAddresses is supported for:
  147. // "UNFRONTED-MEEK-HTTPS-OSSH", "UNFRONTED-MEEK-SESSION-TICKET-OSSH".
  148. TunnelProtocolPassthroughAddresses map[string]string
  149. // SSHPrivateKey is the SSH host key. The same key is used for
  150. // all protocols, run by this server instance, which use SSH.
  151. SSHPrivateKey string
  152. // SSHServerVersion is the server version presented in the
  153. // identification string. The same value is used for all
  154. // protocols, run by this server instance, which use SSH.
  155. SSHServerVersion string
  156. // SSHUserName is the SSH user name to be presented by the
  157. // the tunnel-core client. The same value is used for all
  158. // protocols, run by this server instance, which use SSH.
  159. SSHUserName string
  160. // SSHPassword is the SSH password to be presented by the
  161. // the tunnel-core client. The same value is used for all
  162. // protocols, run by this server instance, which use SSH.
  163. SSHPassword string
  164. // SSHBeginHandshakeTimeoutMilliseconds specifies the timeout
  165. // for clients queueing to begin an SSH handshake. The default
  166. // is SSH_BEGIN_HANDSHAKE_TIMEOUT.
  167. SSHBeginHandshakeTimeoutMilliseconds *int
  168. // SSHHandshakeTimeoutMilliseconds specifies the timeout
  169. // before which a client must complete its handshake. The default
  170. // is SSH_HANDSHAKE_TIMEOUT.
  171. SSHHandshakeTimeoutMilliseconds *int
  172. // ObfuscatedSSHKey is the secret key for use in the Obfuscated
  173. // SSH protocol. The same secret key is used for all protocols,
  174. // run by this server instance, which use Obfuscated SSH.
  175. ObfuscatedSSHKey string
  176. // MeekCookieEncryptionPrivateKey is the NaCl private key used
  177. // to decrypt meek cookie payload sent from clients. The same
  178. // key is used for all meek protocols run by this server instance.
  179. MeekCookieEncryptionPrivateKey string
  180. // MeekObfuscatedKey is the secret key used for obfuscating
  181. // meek cookies sent from clients. The same key is used for all
  182. // meek protocols run by this server instance.
  183. MeekObfuscatedKey string
  184. // MeekProhibitedHeaders is a list of HTTP headers to check for
  185. // in client requests. If one of these headers is found, the
  186. // request fails. This is used to defend against abuse.
  187. MeekProhibitedHeaders []string
  188. // MeekProxyForwardedForHeaders is a list of HTTP headers which
  189. // may be added by downstream HTTP proxies or CDNs in front
  190. // of clients. These headers supply the original client IP
  191. // address, which is geolocated for stats purposes. Headers
  192. // include, for example, X-Forwarded-For. The header's value
  193. // is assumed to be a comma delimted list of IP addresses where
  194. // the client IP is the first IP address in the list. Meek protocols
  195. // look for these headers and use the client IP address from
  196. // the header if any one is present and the value is a valid
  197. // IP address; otherwise the direct connection remote address is
  198. // used as the client IP.
  199. MeekProxyForwardedForHeaders []string
  200. // MeekTurnAroundTimeoutMilliseconds specifies the amount of time meek will
  201. // wait for downstream bytes before responding to a request. The default is
  202. // MEEK_DEFAULT_TURN_AROUND_TIMEOUT.
  203. MeekTurnAroundTimeoutMilliseconds *int
  204. // MeekExtendedTurnAroundTimeoutMilliseconds specifies the extended amount of
  205. // time meek will wait for downstream bytes, as long as bytes arrive every
  206. // MeekTurnAroundTimeoutMilliseconds, before responding to a request. The
  207. // default is MEEK_DEFAULT_EXTENDED_TURN_AROUND_TIMEOUT.
  208. MeekExtendedTurnAroundTimeoutMilliseconds *int
  209. // MeekMaxSessionStalenessMilliseconds specifies the TTL for meek sessions.
  210. // The default is MEEK_DEFAULT_MAX_SESSION_STALENESS.
  211. MeekMaxSessionStalenessMilliseconds *int
  212. // MeekHTTPClientIOTimeoutMilliseconds specifies meek HTTP server I/O
  213. // timeouts. The default is MEEK_DEFAULT_HTTP_CLIENT_IO_TIMEOUT.
  214. MeekHTTPClientIOTimeoutMilliseconds *int
  215. // MeekCachedResponseBufferSize is the size of a private,
  216. // fixed-size buffer allocated for every meek client. The buffer
  217. // is used to cache response payload, allowing the client to retry
  218. // fetching when a network connection is interrupted. This retry
  219. // makes the OSSH tunnel within meek resilient to interruptions
  220. // at the HTTP TCP layer.
  221. // Larger buffers increase resiliency to interruption, but consume
  222. // more memory as buffers as never freed. The maximum size of a
  223. // response payload is a function of client activity, network
  224. // throughput and throttling.
  225. // A default of 64K is used when MeekCachedResponseBufferSize is 0.
  226. MeekCachedResponseBufferSize int
  227. // MeekCachedResponsePoolBufferSize is the size of a fixed-size,
  228. // shared buffer used to temporarily extend a private buffer when
  229. // MeekCachedResponseBufferSize is insufficient. Shared buffers
  230. // allow some clients to successfully retry longer response payloads
  231. // without allocating large buffers for all clients.
  232. // A default of 64K is used when MeekCachedResponsePoolBufferSize
  233. // is 0.
  234. MeekCachedResponsePoolBufferSize int
  235. // MeekCachedResponsePoolBufferCount is the number of shared
  236. // buffers. Shared buffers are allocated on first use and remain
  237. // allocated, so shared buffer count * size is roughly the memory
  238. // overhead of this facility.
  239. // A default of 2048 is used when MeekCachedResponsePoolBufferCount
  240. // is 0.
  241. MeekCachedResponsePoolBufferCount int
  242. // UDPInterceptUdpgwServerAddress specifies the network address of
  243. // a udpgw server which clients may be port forwarding to. When
  244. // specified, these TCP port forwards are intercepted and handled
  245. // directly by this server, which parses the SSH channel using the
  246. // udpgw protocol. Handling includes udpgw transparent DNS: tunneled
  247. // UDP DNS packets are rerouted to the host's DNS server.
  248. //
  249. // The intercept is applied before the port forward destination is
  250. // validated against SSH_DISALLOWED_PORT_FORWARD_HOSTS and
  251. // AllowTCPPorts. So the intercept address may be any otherwise
  252. // prohibited destination.
  253. UDPInterceptUdpgwServerAddress string
  254. // DNSResolverIPAddress specifies the IP address of a DNS server
  255. // to be used when "/etc/resolv.conf" doesn't exist or fails to
  256. // parse. When blank, "/etc/resolv.conf" must contain a usable
  257. // "nameserver" entry.
  258. DNSResolverIPAddress string
  259. // LoadMonitorPeriodSeconds indicates how frequently to log server
  260. // load information (number of connected clients per tunnel protocol,
  261. // number of running goroutines, amount of memory allocated, etc.)
  262. // The default, 0, disables load logging.
  263. LoadMonitorPeriodSeconds int
  264. // ProcessProfileOutputDirectory is the path of a directory to which
  265. // process profiles will be written when signaled with SIGUSR2. The
  266. // files are overwritten on each invocation. When set to the default
  267. // value, blank, no profiles are written on SIGUSR2. Profiles include
  268. // the default profiles here: https://golang.org/pkg/runtime/pprof/#Profile.
  269. ProcessProfileOutputDirectory string
  270. // ProcessBlockProfileDurationSeconds specifies the sample duration for
  271. // "block" profiling. For the default, 0, no "block" profile is taken.
  272. ProcessBlockProfileDurationSeconds int
  273. // ProcessCPUProfileDurationSeconds specifies the sample duration for
  274. // CPU profiling. For the default, 0, no CPU profile is taken.
  275. ProcessCPUProfileDurationSeconds int
  276. // TrafficRulesFilename is the path of a file containing a JSON-encoded
  277. // TrafficRulesSet, the traffic rules to apply to Psiphon client tunnels.
  278. TrafficRulesFilename string
  279. // OSLConfigFilename is the path of a file containing a JSON-encoded
  280. // OSL Config, the OSL schemes to apply to Psiphon client tunnels.
  281. OSLConfigFilename string
  282. // RunPacketTunnel specifies whether to run a packet tunnel.
  283. RunPacketTunnel bool
  284. // PacketTunnelEgressInterface specifies tun.ServerConfig.EgressInterface.
  285. PacketTunnelEgressInterface string
  286. // PacketTunnelDownstreamPacketQueueSize specifies
  287. // tun.ServerConfig.DownStreamPacketQueueSize.
  288. PacketTunnelDownstreamPacketQueueSize int
  289. // PacketTunnelSessionIdleExpirySeconds specifies
  290. // tun.ServerConfig.SessionIdleExpirySeconds.
  291. PacketTunnelSessionIdleExpirySeconds int
  292. // PacketTunnelSudoNetworkConfigCommands sets
  293. // tun.ServerConfig.SudoNetworkConfigCommands.
  294. PacketTunnelSudoNetworkConfigCommands bool
  295. // RunPacketManipulator specifies whether to run a packet manipulator.
  296. RunPacketManipulator bool
  297. // MaxConcurrentSSHHandshakes specifies a limit on the number of concurrent
  298. // SSH handshake negotiations. This is set to mitigate spikes in memory
  299. // allocations and CPU usage associated with SSH handshakes when many clients
  300. // attempt to connect concurrently. When a maximum limit is specified and
  301. // reached, additional clients that establish TCP or meek connections will
  302. // be disconnected after a short wait for the number of concurrent handshakes
  303. // to drop below the limit.
  304. // The default, 0 is no limit.
  305. MaxConcurrentSSHHandshakes int
  306. // PeriodicGarbageCollectionSeconds turns on periodic calls to
  307. // debug.FreeOSMemory, every specified number of seconds, to force garbage
  308. // collection and memory scavenging. Specify 0 to disable. The default is
  309. // PERIODIC_GARBAGE_COLLECTION.
  310. PeriodicGarbageCollectionSeconds *int
  311. // StopEstablishTunnelsEstablishedClientThreshold sets the established client
  312. // threshold for dumping profiles when SIGTSTP is signaled. When there are
  313. // less than or equal to the threshold number of established clients,
  314. // profiles are dumped to aid investigating unusual load limited states that
  315. // occur when few clients are connected and load should be relatively low. A
  316. // profile dump is attempted at most once per process lifetime, the first
  317. // time the threshold is met. Disabled when < 0.
  318. StopEstablishTunnelsEstablishedClientThreshold *int
  319. // AccessControlVerificationKeyRing is the access control authorization
  320. // verification key ring used to verify signed authorizations presented
  321. // by clients. Verified, active (unexpired) access control types will be
  322. // available for matching in the TrafficRulesFilter for the client via
  323. // AuthorizedAccessTypes. All other authorizations are ignored.
  324. AccessControlVerificationKeyRing accesscontrol.VerificationKeyRing
  325. // TacticsConfigFilename is the path of a file containing a JSON-encoded
  326. // tactics server configuration.
  327. TacticsConfigFilename string
  328. // MarionetteFormat specifies a Marionette format to use with the
  329. // MARIONETTE-OSSH tunnel protocol. The format specifies the network
  330. // protocol port to listen on.
  331. MarionetteFormat string
  332. // BlocklistFilename is the path of a file containing a CSV-encoded
  333. // blocklist configuration. See NewBlocklist for more file format
  334. // documentation.
  335. BlocklistFilename string
  336. // BlocklistActive indicates whether to actively prevent blocklist hits in
  337. // addition to logging events.
  338. BlocklistActive bool
  339. // AllowBogons disables port forward bogon checks. This should be used only
  340. // for testing.
  341. AllowBogons bool
  342. // OwnEncodedServerEntries is a list of the server's own encoded server
  343. // entries, idenfified by server entry tag. These values are used in the
  344. // handshake API to update clients that don't yet have a signed copy of these
  345. // server entries.
  346. //
  347. // For purposes of compartmentalization, each server receives only its own
  348. // server entries here; and, besides the discovery server entries, in
  349. // psinet.Database, necessary for the discovery feature, no other server
  350. // entries are stored on a Psiphon server.
  351. OwnEncodedServerEntries map[string]string
  352. sshBeginHandshakeTimeout time.Duration
  353. sshHandshakeTimeout time.Duration
  354. periodicGarbageCollection time.Duration
  355. stopEstablishTunnelsEstablishedClientThreshold int
  356. dumpProfilesOnStopEstablishTunnelsDone int32
  357. }
  358. // GetLogFileReopenConfig gets the reopen retries, and create/mode inputs for
  359. // rotate.NewRotatableFileWriter, which is used when writing to log files.
  360. //
  361. // By default, we expect the log files to be managed by logrotate, with
  362. // logrotate configured to re-create the next log file after rotation. As
  363. // described in the documentation for rotate.NewRotatableFileWriter, and as
  364. // observed in production, we occasionally need retries when attempting to
  365. // reopen the log file post-rotation; and we avoid conflicts, and spurious
  366. // re-rotations, by disabling file create in rotate.NewRotatableFileWriter. In
  367. // large scale production, incidents requiring retry are very rare, so the
  368. // retry delay is not expected to have a significant impact on performance.
  369. //
  370. // The defaults may be overriden in the Config.
  371. func (config *Config) GetLogFileReopenConfig() (int, bool, os.FileMode) {
  372. retries := DEFAULT_LOG_FILE_REOPEN_RETRIES
  373. if config.LogFileReopenRetries != nil {
  374. retries = *config.LogFileReopenRetries
  375. }
  376. create := false
  377. mode := os.FileMode(0)
  378. if config.LogFileCreateMode != nil {
  379. create = true
  380. mode = os.FileMode(*config.LogFileCreateMode)
  381. }
  382. return retries, create, mode
  383. }
  384. // RunWebServer indicates whether to run a web server component.
  385. func (config *Config) RunWebServer() bool {
  386. return config.WebServerPort > 0
  387. }
  388. // RunLoadMonitor indicates whether to monitor and log server load.
  389. func (config *Config) RunLoadMonitor() bool {
  390. return config.LoadMonitorPeriodSeconds > 0
  391. }
  392. // RunPeriodicGarbageCollection indicates whether to run periodic garbage collection.
  393. func (config *Config) RunPeriodicGarbageCollection() bool {
  394. return config.periodicGarbageCollection > 0
  395. }
  396. // DumpProfilesOnStopEstablishTunnels indicates whether dump profiles due to
  397. // an unexpectedly low number of established clients during high load.
  398. func (config *Config) DumpProfilesOnStopEstablishTunnels(establishedClientsCount int) bool {
  399. if config.stopEstablishTunnelsEstablishedClientThreshold < 0 {
  400. return false
  401. }
  402. if atomic.LoadInt32(&config.dumpProfilesOnStopEstablishTunnelsDone) != 0 {
  403. return false
  404. }
  405. dump := (establishedClientsCount <= config.stopEstablishTunnelsEstablishedClientThreshold)
  406. atomic.StoreInt32(&config.dumpProfilesOnStopEstablishTunnelsDone, 1)
  407. return dump
  408. }
  409. // GetOwnEncodedServerEntry returns one of the server's own server entries, as
  410. // identified by the server entry tag.
  411. func (config *Config) GetOwnEncodedServerEntry(serverEntryTag string) (string, bool) {
  412. serverEntry, ok := config.OwnEncodedServerEntries[serverEntryTag]
  413. return serverEntry, ok
  414. }
  415. // LoadConfig loads and validates a JSON encoded server config.
  416. func LoadConfig(configJSON []byte) (*Config, error) {
  417. var config Config
  418. err := json.Unmarshal(configJSON, &config)
  419. if err != nil {
  420. return nil, errors.Trace(err)
  421. }
  422. if config.ServerIPAddress == "" {
  423. return nil, errors.TraceNew("ServerIPAddress is required")
  424. }
  425. if config.WebServerPort > 0 && (config.WebServerSecret == "" || config.WebServerCertificate == "" ||
  426. config.WebServerPrivateKey == "") {
  427. return nil, errors.TraceNew(
  428. "Web server requires WebServerSecret, WebServerCertificate, WebServerPrivateKey")
  429. }
  430. if config.WebServerPortForwardAddress != "" {
  431. if err := validateNetworkAddress(config.WebServerPortForwardAddress, false); err != nil {
  432. return nil, errors.TraceNew("WebServerPortForwardAddress is invalid")
  433. }
  434. }
  435. if config.WebServerPortForwardRedirectAddress != "" {
  436. if config.WebServerPortForwardAddress == "" {
  437. return nil, errors.TraceNew(
  438. "WebServerPortForwardRedirectAddress requires WebServerPortForwardAddress")
  439. }
  440. if err := validateNetworkAddress(config.WebServerPortForwardRedirectAddress, false); err != nil {
  441. return nil, errors.TraceNew("WebServerPortForwardRedirectAddress is invalid")
  442. }
  443. }
  444. for tunnelProtocol, port := range config.TunnelProtocolPorts {
  445. if !common.Contains(protocol.SupportedTunnelProtocols, tunnelProtocol) {
  446. return nil, errors.Tracef("Unsupported tunnel protocol: %s", tunnelProtocol)
  447. }
  448. if protocol.TunnelProtocolUsesSSH(tunnelProtocol) ||
  449. protocol.TunnelProtocolUsesObfuscatedSSH(tunnelProtocol) {
  450. if config.SSHPrivateKey == "" || config.SSHServerVersion == "" ||
  451. config.SSHUserName == "" || config.SSHPassword == "" {
  452. return nil, errors.Tracef(
  453. "Tunnel protocol %s requires SSHPrivateKey, SSHServerVersion, SSHUserName, SSHPassword",
  454. tunnelProtocol)
  455. }
  456. }
  457. if protocol.TunnelProtocolUsesObfuscatedSSH(tunnelProtocol) {
  458. if config.ObfuscatedSSHKey == "" {
  459. return nil, errors.Tracef(
  460. "Tunnel protocol %s requires ObfuscatedSSHKey",
  461. tunnelProtocol)
  462. }
  463. }
  464. if protocol.TunnelProtocolUsesMeekHTTP(tunnelProtocol) ||
  465. protocol.TunnelProtocolUsesMeekHTTPS(tunnelProtocol) {
  466. if config.MeekCookieEncryptionPrivateKey == "" || config.MeekObfuscatedKey == "" {
  467. return nil, errors.Tracef(
  468. "Tunnel protocol %s requires MeekCookieEncryptionPrivateKey, MeekObfuscatedKey",
  469. tunnelProtocol)
  470. }
  471. }
  472. if protocol.TunnelProtocolUsesMarionette(tunnelProtocol) {
  473. if port != 0 {
  474. return nil, errors.Tracef(
  475. "Tunnel protocol %s port is specified in format, not TunnelProtocolPorts",
  476. tunnelProtocol)
  477. }
  478. }
  479. }
  480. for tunnelProtocol, address := range config.TunnelProtocolPassthroughAddresses {
  481. if !protocol.TunnelProtocolSupportsPassthrough(tunnelProtocol) {
  482. return nil, errors.Tracef("Passthrough unsupported tunnel protocol: %s", tunnelProtocol)
  483. }
  484. if _, _, err := net.SplitHostPort(address); err != nil {
  485. if err != nil {
  486. return nil, errors.Tracef(
  487. "Tunnel protocol %s passthrough address %s invalid: %s",
  488. tunnelProtocol, address, err)
  489. }
  490. }
  491. }
  492. config.sshBeginHandshakeTimeout = SSH_BEGIN_HANDSHAKE_TIMEOUT
  493. if config.SSHBeginHandshakeTimeoutMilliseconds != nil {
  494. config.sshBeginHandshakeTimeout = time.Duration(*config.SSHBeginHandshakeTimeoutMilliseconds) * time.Millisecond
  495. }
  496. config.sshHandshakeTimeout = SSH_HANDSHAKE_TIMEOUT
  497. if config.SSHHandshakeTimeoutMilliseconds != nil {
  498. config.sshHandshakeTimeout = time.Duration(*config.SSHHandshakeTimeoutMilliseconds) * time.Millisecond
  499. }
  500. if config.ObfuscatedSSHKey != "" {
  501. seed, err := protocol.DeriveSSHServerVersionPRNGSeed(config.ObfuscatedSSHKey)
  502. if err != nil {
  503. return nil, errors.Tracef(
  504. "DeriveSSHServerVersionPRNGSeed failed: %s", err)
  505. }
  506. serverVersion := values.GetSSHServerVersion(seed)
  507. if serverVersion != "" {
  508. config.SSHServerVersion = serverVersion
  509. }
  510. }
  511. if config.UDPInterceptUdpgwServerAddress != "" {
  512. if err := validateNetworkAddress(config.UDPInterceptUdpgwServerAddress, true); err != nil {
  513. return nil, errors.Tracef("UDPInterceptUdpgwServerAddress is invalid: %s", err)
  514. }
  515. }
  516. if config.DNSResolverIPAddress != "" {
  517. if net.ParseIP(config.DNSResolverIPAddress) == nil {
  518. return nil, errors.Tracef("DNSResolverIPAddress is invalid")
  519. }
  520. }
  521. config.periodicGarbageCollection = PERIODIC_GARBAGE_COLLECTION
  522. if config.PeriodicGarbageCollectionSeconds != nil {
  523. config.periodicGarbageCollection = time.Duration(*config.PeriodicGarbageCollectionSeconds) * time.Second
  524. }
  525. config.stopEstablishTunnelsEstablishedClientThreshold = STOP_ESTABLISH_TUNNELS_ESTABLISHED_CLIENT_THRESHOLD
  526. if config.StopEstablishTunnelsEstablishedClientThreshold != nil {
  527. config.stopEstablishTunnelsEstablishedClientThreshold = *config.StopEstablishTunnelsEstablishedClientThreshold
  528. }
  529. err = accesscontrol.ValidateVerificationKeyRing(&config.AccessControlVerificationKeyRing)
  530. if err != nil {
  531. return nil, errors.Tracef(
  532. "AccessControlVerificationKeyRing is invalid: %s", err)
  533. }
  534. return &config, nil
  535. }
  536. func validateNetworkAddress(address string, requireIPaddress bool) error {
  537. host, portStr, err := net.SplitHostPort(address)
  538. if err != nil {
  539. return err
  540. }
  541. if requireIPaddress && net.ParseIP(host) == nil {
  542. return errors.TraceNew("host must be an IP address")
  543. }
  544. port, err := strconv.Atoi(portStr)
  545. if err != nil {
  546. return err
  547. }
  548. if port < 0 || port > 65535 {
  549. return errors.TraceNew("invalid port")
  550. }
  551. return nil
  552. }
  553. // GenerateConfigParams specifies customizations to be applied to
  554. // a generated server config.
  555. type GenerateConfigParams struct {
  556. LogFilename string
  557. SkipPanickingLogWriter bool
  558. LogLevel string
  559. ServerIPAddress string
  560. WebServerPort int
  561. EnableSSHAPIRequests bool
  562. TunnelProtocolPorts map[string]int
  563. MarionetteFormat string
  564. TrafficRulesConfigFilename string
  565. OSLConfigFilename string
  566. TacticsConfigFilename string
  567. TacticsRequestPublicKey string
  568. TacticsRequestObfuscatedKey string
  569. }
  570. // GenerateConfig creates a new Psiphon server config. It returns JSON encoded
  571. // configs and a client-compatible "server entry" for the server. It generates
  572. // all necessary secrets and key material, which are emitted in the config
  573. // file and server entry as necessary.
  574. //
  575. // GenerateConfig uses sample values for many fields. The intention is for
  576. // generated configs to be used for testing or as examples for production
  577. // setup, not to generate production-ready configurations.
  578. //
  579. // When tactics key material is provided in GenerateConfigParams, tactics
  580. // capabilities are added for all meek protocols in TunnelProtocolPorts.
  581. func GenerateConfig(params *GenerateConfigParams) ([]byte, []byte, []byte, []byte, []byte, error) {
  582. // Input validation
  583. if net.ParseIP(params.ServerIPAddress) == nil {
  584. return nil, nil, nil, nil, nil, errors.TraceNew("invalid IP address")
  585. }
  586. if len(params.TunnelProtocolPorts) == 0 {
  587. return nil, nil, nil, nil, nil, errors.TraceNew("no tunnel protocols")
  588. }
  589. usedPort := make(map[int]bool)
  590. if params.WebServerPort != 0 {
  591. usedPort[params.WebServerPort] = true
  592. }
  593. usingMeek := false
  594. for tunnelProtocol, port := range params.TunnelProtocolPorts {
  595. if !common.Contains(protocol.SupportedTunnelProtocols, tunnelProtocol) {
  596. return nil, nil, nil, nil, nil, errors.TraceNew("invalid tunnel protocol")
  597. }
  598. if usedPort[port] {
  599. return nil, nil, nil, nil, nil, errors.TraceNew("duplicate listening port")
  600. }
  601. usedPort[port] = true
  602. if protocol.TunnelProtocolUsesMeekHTTP(tunnelProtocol) ||
  603. protocol.TunnelProtocolUsesMeekHTTPS(tunnelProtocol) {
  604. usingMeek = true
  605. }
  606. }
  607. // One test mode populates the tactics config file; this will generate
  608. // keys. Another test mode passes in existing keys to be used in the
  609. // server entry. Both the filename and existing keys cannot be passed in.
  610. if (params.TacticsConfigFilename != "") &&
  611. (params.TacticsRequestPublicKey != "" || params.TacticsRequestObfuscatedKey != "") {
  612. return nil, nil, nil, nil, nil, errors.TraceNew("invalid tactics parameters")
  613. }
  614. // Web server config
  615. var webServerSecret, webServerCertificate,
  616. webServerPrivateKey, webServerPortForwardAddress string
  617. if params.WebServerPort != 0 {
  618. webServerSecretBytes, err := common.MakeSecureRandomBytes(WEB_SERVER_SECRET_BYTE_LENGTH)
  619. if err != nil {
  620. return nil, nil, nil, nil, nil, errors.Trace(err)
  621. }
  622. webServerSecret = hex.EncodeToString(webServerSecretBytes)
  623. webServerCertificate, webServerPrivateKey, err = common.GenerateWebServerCertificate("")
  624. if err != nil {
  625. return nil, nil, nil, nil, nil, errors.Trace(err)
  626. }
  627. webServerPortForwardAddress = net.JoinHostPort(
  628. params.ServerIPAddress, strconv.Itoa(params.WebServerPort))
  629. }
  630. // SSH config
  631. rsaKey, err := rsa.GenerateKey(rand.Reader, SSH_RSA_HOST_KEY_BITS)
  632. if err != nil {
  633. return nil, nil, nil, nil, nil, errors.Trace(err)
  634. }
  635. sshPrivateKey := pem.EncodeToMemory(
  636. &pem.Block{
  637. Type: "RSA PRIVATE KEY",
  638. Bytes: x509.MarshalPKCS1PrivateKey(rsaKey),
  639. },
  640. )
  641. signer, err := ssh.NewSignerFromKey(rsaKey)
  642. if err != nil {
  643. return nil, nil, nil, nil, nil, errors.Trace(err)
  644. }
  645. sshPublicKey := signer.PublicKey()
  646. sshUserNameSuffixBytes, err := common.MakeSecureRandomBytes(SSH_USERNAME_SUFFIX_BYTE_LENGTH)
  647. if err != nil {
  648. return nil, nil, nil, nil, nil, errors.Trace(err)
  649. }
  650. sshUserNameSuffix := hex.EncodeToString(sshUserNameSuffixBytes)
  651. sshUserName := "psiphon_" + sshUserNameSuffix
  652. sshPasswordBytes, err := common.MakeSecureRandomBytes(SSH_PASSWORD_BYTE_LENGTH)
  653. if err != nil {
  654. return nil, nil, nil, nil, nil, errors.Trace(err)
  655. }
  656. sshPassword := hex.EncodeToString(sshPasswordBytes)
  657. sshServerVersion := "SSH-2.0-Psiphon"
  658. // Obfuscated SSH config
  659. obfuscatedSSHKeyBytes, err := common.MakeSecureRandomBytes(SSH_OBFUSCATED_KEY_BYTE_LENGTH)
  660. if err != nil {
  661. return nil, nil, nil, nil, nil, errors.Trace(err)
  662. }
  663. obfuscatedSSHKey := hex.EncodeToString(obfuscatedSSHKeyBytes)
  664. // Meek config
  665. var meekCookieEncryptionPublicKey, meekCookieEncryptionPrivateKey, meekObfuscatedKey string
  666. if usingMeek {
  667. rawMeekCookieEncryptionPublicKey, rawMeekCookieEncryptionPrivateKey, err :=
  668. box.GenerateKey(rand.Reader)
  669. if err != nil {
  670. return nil, nil, nil, nil, nil, errors.Trace(err)
  671. }
  672. meekCookieEncryptionPublicKey = base64.StdEncoding.EncodeToString(rawMeekCookieEncryptionPublicKey[:])
  673. meekCookieEncryptionPrivateKey = base64.StdEncoding.EncodeToString(rawMeekCookieEncryptionPrivateKey[:])
  674. meekObfuscatedKeyBytes, err := common.MakeSecureRandomBytes(SSH_OBFUSCATED_KEY_BYTE_LENGTH)
  675. if err != nil {
  676. return nil, nil, nil, nil, nil, errors.Trace(err)
  677. }
  678. meekObfuscatedKey = hex.EncodeToString(meekObfuscatedKeyBytes)
  679. }
  680. // Other config
  681. discoveryValueHMACKeyBytes, err := common.MakeSecureRandomBytes(DISCOVERY_VALUE_KEY_BYTE_LENGTH)
  682. if err != nil {
  683. return nil, nil, nil, nil, nil, errors.Trace(err)
  684. }
  685. discoveryValueHMACKey := base64.StdEncoding.EncodeToString(discoveryValueHMACKeyBytes)
  686. // Assemble configs and server entry
  687. // Note: this config is intended for either testing or as an illustrative
  688. // example or template and is not intended for production deployment.
  689. logLevel := params.LogLevel
  690. if logLevel == "" {
  691. logLevel = "info"
  692. }
  693. // For testing, set the Psiphon server to create its log files; we do not
  694. // expect tests to necessarily run under log managers, such as logrotate.
  695. createMode := 0666
  696. config := &Config{
  697. LogLevel: logLevel,
  698. LogFilename: params.LogFilename,
  699. LogFileCreateMode: &createMode,
  700. SkipPanickingLogWriter: params.SkipPanickingLogWriter,
  701. GeoIPDatabaseFilenames: nil,
  702. HostID: "example-host-id",
  703. ServerIPAddress: params.ServerIPAddress,
  704. DiscoveryValueHMACKey: discoveryValueHMACKey,
  705. WebServerPort: params.WebServerPort,
  706. WebServerSecret: webServerSecret,
  707. WebServerCertificate: webServerCertificate,
  708. WebServerPrivateKey: webServerPrivateKey,
  709. WebServerPortForwardAddress: webServerPortForwardAddress,
  710. SSHPrivateKey: string(sshPrivateKey),
  711. SSHServerVersion: sshServerVersion,
  712. SSHUserName: sshUserName,
  713. SSHPassword: sshPassword,
  714. ObfuscatedSSHKey: obfuscatedSSHKey,
  715. TunnelProtocolPorts: params.TunnelProtocolPorts,
  716. DNSResolverIPAddress: "8.8.8.8",
  717. UDPInterceptUdpgwServerAddress: "127.0.0.1:7300",
  718. MeekCookieEncryptionPrivateKey: meekCookieEncryptionPrivateKey,
  719. MeekObfuscatedKey: meekObfuscatedKey,
  720. MeekProhibitedHeaders: nil,
  721. MeekProxyForwardedForHeaders: []string{"X-Forwarded-For"},
  722. LoadMonitorPeriodSeconds: 300,
  723. TrafficRulesFilename: params.TrafficRulesConfigFilename,
  724. OSLConfigFilename: params.OSLConfigFilename,
  725. TacticsConfigFilename: params.TacticsConfigFilename,
  726. MarionetteFormat: params.MarionetteFormat,
  727. }
  728. encodedConfig, err := json.MarshalIndent(config, "\n", " ")
  729. if err != nil {
  730. return nil, nil, nil, nil, nil, errors.Trace(err)
  731. }
  732. intPtr := func(i int) *int {
  733. return &i
  734. }
  735. trafficRulesSet := &TrafficRulesSet{
  736. DefaultRules: TrafficRules{
  737. RateLimits: RateLimits{
  738. ReadUnthrottledBytes: new(int64),
  739. ReadBytesPerSecond: new(int64),
  740. WriteUnthrottledBytes: new(int64),
  741. WriteBytesPerSecond: new(int64),
  742. },
  743. IdleTCPPortForwardTimeoutMilliseconds: intPtr(DEFAULT_IDLE_TCP_PORT_FORWARD_TIMEOUT_MILLISECONDS),
  744. IdleUDPPortForwardTimeoutMilliseconds: intPtr(DEFAULT_IDLE_UDP_PORT_FORWARD_TIMEOUT_MILLISECONDS),
  745. MaxTCPPortForwardCount: intPtr(DEFAULT_MAX_TCP_PORT_FORWARD_COUNT),
  746. MaxUDPPortForwardCount: intPtr(DEFAULT_MAX_UDP_PORT_FORWARD_COUNT),
  747. AllowTCPPorts: nil,
  748. AllowUDPPorts: nil,
  749. },
  750. }
  751. encodedTrafficRulesSet, err := json.MarshalIndent(trafficRulesSet, "\n", " ")
  752. if err != nil {
  753. return nil, nil, nil, nil, nil, errors.Trace(err)
  754. }
  755. encodedOSLConfig, err := json.MarshalIndent(&osl.Config{}, "\n", " ")
  756. if err != nil {
  757. return nil, nil, nil, nil, nil, errors.Trace(err)
  758. }
  759. tacticsRequestPublicKey := params.TacticsRequestPublicKey
  760. tacticsRequestObfuscatedKey := params.TacticsRequestObfuscatedKey
  761. var tacticsRequestPrivateKey string
  762. var encodedTacticsConfig []byte
  763. if params.TacticsConfigFilename != "" {
  764. tacticsRequestPublicKey, tacticsRequestPrivateKey, tacticsRequestObfuscatedKey, err =
  765. tactics.GenerateKeys()
  766. if err != nil {
  767. return nil, nil, nil, nil, nil, errors.Trace(err)
  768. }
  769. decodedTacticsRequestPublicKey, err := base64.StdEncoding.DecodeString(tacticsRequestPublicKey)
  770. if err != nil {
  771. return nil, nil, nil, nil, nil, errors.Trace(err)
  772. }
  773. decodedTacticsRequestPrivateKey, err := base64.StdEncoding.DecodeString(tacticsRequestPrivateKey)
  774. if err != nil {
  775. return nil, nil, nil, nil, nil, errors.Trace(err)
  776. }
  777. decodedTacticsRequestObfuscatedKey, err := base64.StdEncoding.DecodeString(tacticsRequestObfuscatedKey)
  778. if err != nil {
  779. return nil, nil, nil, nil, nil, errors.Trace(err)
  780. }
  781. tacticsConfig := &tactics.Server{
  782. RequestPublicKey: decodedTacticsRequestPublicKey,
  783. RequestPrivateKey: decodedTacticsRequestPrivateKey,
  784. RequestObfuscatedKey: decodedTacticsRequestObfuscatedKey,
  785. DefaultTactics: tactics.Tactics{
  786. TTL: "1m",
  787. Probability: 1.0,
  788. },
  789. }
  790. encodedTacticsConfig, err = json.MarshalIndent(tacticsConfig, "\n", " ")
  791. if err != nil {
  792. return nil, nil, nil, nil, nil, errors.Trace(err)
  793. }
  794. }
  795. capabilities := []string{}
  796. if params.EnableSSHAPIRequests {
  797. capabilities = append(capabilities, protocol.CAPABILITY_SSH_API_REQUESTS)
  798. }
  799. if params.WebServerPort != 0 {
  800. capabilities = append(capabilities, protocol.CAPABILITY_UNTUNNELED_WEB_API_REQUESTS)
  801. }
  802. for tunnelProtocol := range params.TunnelProtocolPorts {
  803. capabilities = append(capabilities, protocol.GetCapability(tunnelProtocol))
  804. if params.TacticsRequestPublicKey != "" && params.TacticsRequestObfuscatedKey != "" &&
  805. protocol.TunnelProtocolUsesMeek(tunnelProtocol) {
  806. capabilities = append(capabilities, protocol.GetTacticsCapability(tunnelProtocol))
  807. }
  808. }
  809. sshPort := params.TunnelProtocolPorts["SSH"]
  810. obfuscatedSSHPort := params.TunnelProtocolPorts["OSSH"]
  811. obfuscatedSSHQUICPort := params.TunnelProtocolPorts["QUIC-OSSH"]
  812. // Meek port limitations
  813. // - fronted meek protocols are hard-wired in the client to be port 443 or 80.
  814. // - only one other meek port may be specified.
  815. meekPort := params.TunnelProtocolPorts["UNFRONTED-MEEK-OSSH"]
  816. if meekPort == 0 {
  817. meekPort = params.TunnelProtocolPorts["UNFRONTED-MEEK-HTTPS-OSSH"]
  818. }
  819. if meekPort == 0 {
  820. meekPort = params.TunnelProtocolPorts["UNFRONTED-MEEK-SESSION-TICKET-OSSH"]
  821. }
  822. // Note: fronting params are a stub; this server entry will exercise
  823. // client and server fronting code paths, but not actually traverse
  824. // a fronting hop.
  825. serverEntryWebServerPort := ""
  826. strippedWebServerCertificate := ""
  827. if params.WebServerPort != 0 {
  828. serverEntryWebServerPort = fmt.Sprintf("%d", params.WebServerPort)
  829. // Server entry format omits the BEGIN/END lines and newlines
  830. lines := strings.Split(webServerCertificate, "\n")
  831. strippedWebServerCertificate = strings.Join(lines[1:len(lines)-2], "")
  832. }
  833. serverEntry := &protocol.ServerEntry{
  834. IpAddress: params.ServerIPAddress,
  835. WebServerPort: serverEntryWebServerPort,
  836. WebServerSecret: webServerSecret,
  837. WebServerCertificate: strippedWebServerCertificate,
  838. SshPort: sshPort,
  839. SshUsername: sshUserName,
  840. SshPassword: sshPassword,
  841. SshHostKey: base64.RawStdEncoding.EncodeToString(sshPublicKey.Marshal()),
  842. SshObfuscatedPort: obfuscatedSSHPort,
  843. SshObfuscatedQUICPort: obfuscatedSSHQUICPort,
  844. SshObfuscatedKey: obfuscatedSSHKey,
  845. Capabilities: capabilities,
  846. Region: "US",
  847. MeekServerPort: meekPort,
  848. MeekCookieEncryptionPublicKey: meekCookieEncryptionPublicKey,
  849. MeekObfuscatedKey: meekObfuscatedKey,
  850. MeekFrontingHosts: []string{params.ServerIPAddress},
  851. MeekFrontingAddresses: []string{params.ServerIPAddress},
  852. MeekFrontingDisableSNI: false,
  853. TacticsRequestPublicKey: tacticsRequestPublicKey,
  854. TacticsRequestObfuscatedKey: tacticsRequestObfuscatedKey,
  855. MarionetteFormat: params.MarionetteFormat,
  856. ConfigurationVersion: 1,
  857. }
  858. encodedServerEntry, err := protocol.EncodeServerEntry(serverEntry)
  859. if err != nil {
  860. return nil, nil, nil, nil, nil, errors.Trace(err)
  861. }
  862. return encodedConfig, encodedTrafficRulesSet, encodedOSLConfig, encodedTacticsConfig, []byte(encodedServerEntry), nil
  863. }