config.go 148 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717
  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. "crypto/md5"
  22. "encoding/base64"
  23. "encoding/binary"
  24. "encoding/json"
  25. "fmt"
  26. "io/ioutil"
  27. "net/http"
  28. "os"
  29. "path/filepath"
  30. "reflect"
  31. "regexp"
  32. "strconv"
  33. "strings"
  34. "sync"
  35. "sync/atomic"
  36. "unicode"
  37. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common"
  38. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/errors"
  39. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/parameters"
  40. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
  41. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/resolver"
  42. "github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/transforms"
  43. "golang.org/x/crypto/nacl/secretbox"
  44. )
  45. const (
  46. TUNNEL_POOL_SIZE = 1
  47. MAX_TUNNEL_POOL_SIZE = 32
  48. // Psiphon data directory name, relative to config.DataRootDirectory.
  49. // See config.GetPsiphonDataDirectory().
  50. PsiphonDataDirectoryName = "ca.psiphon.PsiphonTunnel.tunnel-core"
  51. // Filename constants, all relative to config.GetPsiphonDataDirectory().
  52. HomepageFilename = "homepage"
  53. NoticesFilename = "notices"
  54. OldNoticesFilename = "notices.1"
  55. UpgradeDownloadFilename = "upgrade"
  56. )
  57. // Config is the Psiphon configuration specified by the application. This
  58. // configuration controls the behavior of the core tunnel functionality.
  59. //
  60. // To distinguish omitted timeout params from explicit 0 value timeout params,
  61. // corresponding fields are int pointers. nil means no value was supplied and
  62. // to use the default; a non-nil pointer to 0 means no timeout.
  63. type Config struct {
  64. // DataRootDirectory is the directory in which to store persistent files,
  65. // which contain information such as server entries. By default, current
  66. // working directory.
  67. //
  68. // Psiphon will assume full control of files under this directory. They may
  69. // be deleted, moved or overwritten.
  70. DataRootDirectory string
  71. // UseNoticeFiles configures notice files for writing. If set, homepages
  72. // will be written to a file created at config.GetHomePageFilename()
  73. // and notices will be written to a file created at
  74. // config.GetNoticesFilename().
  75. //
  76. // The homepage file may be read after the Tunnels notice with count of 1.
  77. //
  78. // The value of UseNoticeFiles sets the size and frequency at which the
  79. // notices file, config.GetNoticesFilename(), will be rotated. See the
  80. // comment for UseNoticeFiles for more details. One rotated older file,
  81. // config.GetOldNoticesFilename(), is retained.
  82. //
  83. // The notice files may be may be read at any time; and should be opened
  84. // read-only for reading. Diagnostic notices are omitted from the notice
  85. // files.
  86. //
  87. // See comment for setNoticeFiles in notice.go for further details.
  88. UseNoticeFiles *UseNoticeFiles
  89. // PropagationChannelId is a string identifier which indicates how the
  90. // Psiphon client was distributed. This parameter is required. This value
  91. // is supplied by and depends on the Psiphon Network, and is typically
  92. // embedded in the client binary.
  93. PropagationChannelId string
  94. // SponsorId is a string identifier which indicates who is sponsoring this
  95. // Psiphon client. One purpose of this value is to determine the home
  96. // pages for display. This parameter is required. This value is supplied
  97. // by and depends on the Psiphon Network, and is typically embedded in the
  98. // client binary.
  99. SponsorId string
  100. // ClientVersion is the client version number that the client reports to
  101. // the server. The version number refers to the host client application,
  102. // not the core tunnel library. One purpose of this value is to enable
  103. // automatic updates. This value is supplied by and depends on the Psiphon
  104. // Network, and is typically embedded in the client binary.
  105. //
  106. // Note that sending a ClientPlatform string which includes "windows"
  107. // (case insensitive) and a ClientVersion of <= 44 will cause an error in
  108. // processing the response to DoConnectedRequest calls.
  109. ClientVersion string
  110. // ClientPlatform is the client platform ("Windows", "Android", etc.) that
  111. // the client reports to the server.
  112. ClientPlatform string
  113. // ClientFeatures is a list of feature names denoting enabled application
  114. // features. Clients report enabled features to the server for stats
  115. // purposes.
  116. ClientFeatures []string
  117. // EgressRegion is a ISO 3166-1 alpha-2 country code which indicates which
  118. // country to egress from. For the default, "", the best performing server
  119. // in any country is selected.
  120. EgressRegion string
  121. // SplitTunnelOwnRegion enables split tunnel mode for the client's own
  122. // country. When enabled, TCP port forward destinations that resolve to
  123. // the same GeoIP country as the client are connected to directly,
  124. // untunneled.
  125. SplitTunnelOwnRegion bool
  126. // SplitTunnelRegions enables selected split tunnel mode in which the
  127. // client specifies a list of ISO 3166-1 alpha-2 country codes for which
  128. // traffic should be untunneled. TCP port forwards destined to any
  129. // country specified in SplitTunnelRegions will be untunneled, regardless
  130. // of whether SplitTunnelOwnRegion is on or off.
  131. SplitTunnelRegions []string
  132. // ListenInterface specifies which interface to listen on. If no
  133. // interface is provided then listen on 127.0.0.1. If 'any' is provided
  134. // then use 0.0.0.0. If there are multiple IP addresses on an interface
  135. // use the first IPv4 address.
  136. ListenInterface string
  137. // DisableLocalSocksProxy disables running the local SOCKS proxy.
  138. DisableLocalSocksProxy bool
  139. // LocalSocksProxyPort specifies a port number for the local SOCKS proxy
  140. // running at 127.0.0.1. For the default value, 0, the system selects a
  141. // free port (a notice reporting the selected port is emitted).
  142. LocalSocksProxyPort int
  143. // LocalHttpProxyPort specifies a port number for the local HTTP proxy
  144. // running at 127.0.0.1. For the default value, 0, the system selects a
  145. // free port (a notice reporting the selected port is emitted).
  146. LocalHttpProxyPort int
  147. // DisableLocalHTTPProxy disables running the local HTTP proxy.
  148. DisableLocalHTTPProxy bool
  149. // NetworkLatencyMultiplier is a multiplier that is to be applied to
  150. // default network event timeouts. Set this to tune performance for
  151. // slow networks.
  152. // When set, must be >= 1.0.
  153. NetworkLatencyMultiplier float64
  154. // LimitTunnelProtocols indicates which protocols to use. Valid values
  155. // include: "SSH", "OSSH", "TLS-OSSH", "UNFRONTED-MEEK-OSSH",
  156. // "UNFRONTED-MEEK-HTTPS-OSSH", "UNFRONTED-MEEK-SESSION-TICKET-OSSH",
  157. // "FRONTED-MEEK-OSSH", "FRONTED-MEEK-HTTP-OSSH", "QUIC-OSSH",
  158. // "FRONTED-MEEK-QUIC-OSSH", "TAPDANCE-OSSH", and "CONJURE-OSSH".
  159. // For the default, an empty list, all protocols are used.
  160. LimitTunnelProtocols []string
  161. // InitialLimitTunnelProtocols is an optional initial phase of limited
  162. // protocols for the first InitialLimitTunnelProtocolsCandidateCount
  163. // candidates; after these candidates, LimitTunnelProtocols applies.
  164. //
  165. // For the default, an empty list, InitialLimitTunnelProtocols is off.
  166. InitialLimitTunnelProtocols []string
  167. // InitialLimitTunnelProtocolsCandidateCount is the number of candidates
  168. // to which InitialLimitTunnelProtocols is applied instead of
  169. // LimitTunnelProtocols.
  170. //
  171. // For the default, 0, InitialLimitTunnelProtocols is off.
  172. InitialLimitTunnelProtocolsCandidateCount int
  173. // LimitTLSProfiles indicates which TLS profiles to select from. Valid
  174. // values are listed in protocols.SupportedTLSProfiles.
  175. // For the default, an empty list, all profiles are candidates for
  176. // selection.
  177. LimitTLSProfiles []string
  178. // LimitQUICVersions indicates which QUIC versions to select from. Valid
  179. // values are listed in protocols.SupportedQUICVersions.
  180. // For the default, an empty list, all versions are candidates for
  181. // selection.
  182. LimitQUICVersions []string
  183. // EstablishTunnelTimeoutSeconds specifies a time limit after which to
  184. // halt the core tunnel controller if no tunnel has been established. The
  185. // default is parameters.EstablishTunnelTimeout.
  186. EstablishTunnelTimeoutSeconds *int
  187. // EstablishTunnelPausePeriodSeconds specifies the delay between attempts
  188. // to establish tunnels. Briefly pausing allows for network conditions to
  189. // improve and for asynchronous operations such as fetch remote server
  190. // list to complete. If omitted, a default value is used. This value is
  191. // typical overridden for testing.
  192. EstablishTunnelPausePeriodSeconds *int
  193. // EstablishTunnelPausePeriodSeconds specifies the grace period, or head
  194. // start, provided to the affinity server candidate when establishing. The
  195. // affinity server is the server used for the last established tunnel.
  196. EstablishTunnelServerAffinityGracePeriodMilliseconds *int
  197. // ConnectionWorkerPoolSize specifies how many connection attempts to
  198. // attempt in parallel. If omitted or when 0, a default is used; this is
  199. // recommended.
  200. ConnectionWorkerPoolSize int
  201. // TunnelPoolSize specifies how many tunnels to run in parallel. Port
  202. // forwards are multiplexed over multiple tunnels. If omitted or when 0,
  203. // the default is TUNNEL_POOL_SIZE, which is recommended. Any value over
  204. // MAX_TUNNEL_POOL_SIZE is treated as MAX_TUNNEL_POOL_SIZE.
  205. TunnelPoolSize int
  206. // StaggerConnectionWorkersMilliseconds adds a specified delay before
  207. // making each server candidate available to connection workers. This
  208. // option is enabled when StaggerConnectionWorkersMilliseconds > 0.
  209. StaggerConnectionWorkersMilliseconds int
  210. // LimitIntensiveConnectionWorkers limits the number of concurrent
  211. // connection workers attempting connections with resource intensive
  212. // protocols. This option is enabled when LimitIntensiveConnectionWorkers
  213. // > 0.
  214. LimitIntensiveConnectionWorkers int
  215. // LimitMeekBufferSizes selects smaller buffers for meek protocols.
  216. LimitMeekBufferSizes bool
  217. // LimitCPUThreads minimizes the number of CPU threads -- and associated
  218. // overhead -- the are used.
  219. LimitCPUThreads bool
  220. // LimitRelayBufferSizes selects smaller buffers for port forward relaying.
  221. LimitRelayBufferSizes bool
  222. // IgnoreHandshakeStatsRegexps skips compiling and using stats regexes.
  223. IgnoreHandshakeStatsRegexps bool
  224. // UpstreamProxyURL is a URL specifying an upstream proxy to use for all
  225. // outbound connections. The URL should include proxy type and
  226. // authentication information, as required. See example URLs here:
  227. // https://github.com/Psiphon-Labs/psiphon-tunnel-core/tree/master/psiphon/upstreamproxy
  228. UpstreamProxyURL string
  229. // CustomHeaders is a set of additional arbitrary HTTP headers that are
  230. // added to all plaintext HTTP requests and requests made through an HTTP
  231. // upstream proxy when specified by UpstreamProxyURL.
  232. CustomHeaders http.Header
  233. // MeekAdditionalHeaders is a set of additional arbitrary HTTP headers
  234. // that are added to all meek HTTP requests. An additional header is
  235. // ignored when the header name is already present in a meek request.
  236. MeekAdditionalHeaders http.Header
  237. // NetworkConnectivityChecker is an interface that enables tunnel-core to
  238. // call into the host application to check for network connectivity. See:
  239. // NetworkConnectivityChecker doc.
  240. NetworkConnectivityChecker NetworkConnectivityChecker
  241. // DeviceBinder is an interface that enables tunnel-core to call into the
  242. // host application to bind sockets to specific devices. See: DeviceBinder
  243. // doc.
  244. //
  245. // When DeviceBinder is set, the "VPN" feature name is automatically added
  246. // when reporting ClientFeatures.
  247. DeviceBinder DeviceBinder
  248. // AllowDefaultDNSResolverWithBindToDevice indicates that it's safe to use
  249. // the default resolver when DeviceBinder is configured, as the host OS
  250. // will automatically exclude DNS requests from the VPN.
  251. AllowDefaultDNSResolverWithBindToDevice bool
  252. // IPv6Synthesizer is an interface that allows tunnel-core to call into
  253. // the host application to synthesize IPv6 addresses. See: IPv6Synthesizer
  254. // doc.
  255. IPv6Synthesizer IPv6Synthesizer
  256. // HasIPv6RouteGetter is an interface that allows tunnel-core to call into
  257. // the host application to determine if the host has an IPv6 route. See:
  258. // HasIPv6RouteGetter doc.
  259. HasIPv6RouteGetter HasIPv6RouteGetter
  260. // DNSServerGetter is an interface that enables tunnel-core to call into
  261. // the host application to discover the native network DNS server
  262. // settings. See: DNSServerGetter doc.
  263. DNSServerGetter DNSServerGetter
  264. // NetworkIDGetter in an interface that enables tunnel-core to call into
  265. // the host application to get an identifier for the host's current active
  266. // network. See: NetworkIDGetter doc.
  267. NetworkIDGetter NetworkIDGetter
  268. // NetworkID, when not blank, is used as the identifier for the host's
  269. // current active network.
  270. // NetworkID is ignored when NetworkIDGetter is set.
  271. NetworkID string
  272. // DisableTactics disables tactics operations including requests, payload
  273. // handling, and application of parameters.
  274. DisableTactics bool
  275. // DisableReplay causes any persisted dial parameters to be ignored when
  276. // they would otherwise be used for replay.
  277. DisableReplay bool
  278. // TargetServerEntry is an encoded server entry. When specified, this
  279. // server entry is used exclusively and all other known servers are
  280. // ignored; also, when set, ConnectionWorkerPoolSize is ignored and
  281. // the pool size is 1.
  282. TargetServerEntry string
  283. // DisableApi disables Psiphon server API calls including handshake,
  284. // connected, status, etc. This is used for special case temporary tunnels
  285. // (Windows VPN mode).
  286. DisableApi bool
  287. // TargetAPIProtocol specifies whether to force use of "ssh" or "web" API
  288. // protocol. When blank, the default, the optimal API protocol is used.
  289. // Note that this capability check is not applied before the
  290. // "CandidateServers" count is emitted.
  291. //
  292. // This parameter is intended for testing and debugging only. Not all
  293. // parameters are supported in the legacy "web" API protocol, including
  294. // speed test samples.
  295. TargetAPIProtocol string
  296. // TargetAPIProtocol specifies whether to use "json" or "cbor" API
  297. // protocol parameter encodings. When blank, the default is to use "cbor"
  298. // where supported.
  299. TargetAPIEncoding string
  300. // RemoteServerListURLs is list of URLs which specify locations to fetch
  301. // out-of-band server entries. This facility is used when a tunnel cannot
  302. // be established to known servers. This value is supplied by and depends
  303. // on the Psiphon Network, and is typically embedded in the client binary.
  304. // All URLs must point to the same entity with the same ETag. At least one
  305. // TransferURL must have OnlyAfterAttempts = 0.
  306. RemoteServerListURLs parameters.TransferURLs
  307. // RemoteServerListSignaturePublicKey specifies a public key that's used
  308. // to authenticate the remote server list payload. This value is supplied
  309. // by and depends on the Psiphon Network, and is typically embedded in the
  310. // client binary.
  311. RemoteServerListSignaturePublicKey string
  312. // DisableRemoteServerListFetcher disables fetching remote server lists.
  313. // This is used for special case temporary tunnels.
  314. DisableRemoteServerListFetcher bool
  315. // FetchRemoteServerListRetryPeriodMilliseconds specifies the delay before
  316. // resuming a remote server list download after a failure. If omitted, a
  317. // default value is used. This value is typical overridden for testing.
  318. FetchRemoteServerListRetryPeriodMilliseconds *int
  319. // ObfuscatedServerListRootURLs is a list of URLs which specify root
  320. // locations from which to fetch obfuscated server list files. This value
  321. // is supplied by and depends on the Psiphon Network, and is typically
  322. // embedded in the client binary. All URLs must point to the same entity
  323. // with the same ETag. At least one DownloadURL must have
  324. // OnlyAfterAttempts = 0.
  325. ObfuscatedServerListRootURLs parameters.TransferURLs
  326. // EnableUpgradeDownload indicates whether to check for and download
  327. // upgrades. When set, UpgradeDownloadURLs and
  328. // UpgradeDownloadClientVersionHeader must also be set. ClientPlatform
  329. // and ClientVersion should also be set.
  330. EnableUpgradeDownload bool
  331. // UpgradeDownloadURLs is list of URLs which specify locations from which
  332. // to download a host client upgrade file, when one is available. The core
  333. // tunnel controller provides a resumable download facility which
  334. // downloads this resource and emits a notice when complete. This value is
  335. // supplied by and depends on the Psiphon Network, and is typically
  336. // embedded in the client binary. All URLs must point to the same entity
  337. // with the same ETag. At least one DownloadURL must have
  338. // OnlyAfterAttempts = 0.
  339. UpgradeDownloadURLs parameters.TransferURLs
  340. // UpgradeDownloadClientVersionHeader specifies the HTTP header name for
  341. // the entity at UpgradeDownloadURLs which specifies the client version
  342. // (an integer value). A HEAD request may be made to check the version
  343. // number available at UpgradeDownloadURLs.
  344. // UpgradeDownloadClientVersionHeader is required when UpgradeDownloadURLs
  345. // is specified.
  346. UpgradeDownloadClientVersionHeader string
  347. // FetchUpgradeRetryPeriodMilliseconds specifies the delay before resuming
  348. // a client upgrade download after a failure. If omitted, a default value
  349. // is used. This value is typical overridden for testing.
  350. FetchUpgradeRetryPeriodMilliseconds *int
  351. // EnableFeedbackUpload indicates whether to enable uploading feedback
  352. // data. When set, FeedbackUploadURLs and FeedbackEncryptionPublicKey
  353. // must also be set.
  354. EnableFeedbackUpload bool
  355. // FeedbackUploadURLs is a list of SecureTransferURLs which specify
  356. // locations where feedback data can be uploaded, pairing with each
  357. // location a public key with which to encrypt the feedback data. This
  358. // value is supplied by and depends on the Psiphon Network, and is
  359. // typically embedded in the client binary. At least one TransferURL must
  360. // have OnlyAfterAttempts = 0.
  361. FeedbackUploadURLs parameters.TransferURLs
  362. // FeedbackEncryptionPublicKey is a default base64-encoded, RSA public key
  363. // value used to encrypt feedback data. Used when uploading feedback with a
  364. // TransferURL which has no public key value configured, i.e.
  365. // B64EncodedPublicKey = "".
  366. FeedbackEncryptionPublicKey string
  367. // TrustedCACertificatesFilename specifies a file containing trusted CA
  368. // certs. When set, this toggles use of the trusted CA certs, specified in
  369. // TrustedCACertificatesFilename, for tunneled TLS connections that expect
  370. // server certificates signed with public certificate authorities
  371. // (currently, only upgrade downloads). This option is used with stock Go
  372. // TLS in cases where Go may fail to obtain a list of root CAs from the
  373. // operating system.
  374. TrustedCACertificatesFilename string
  375. // DisableSystemRootCAs, when true, disables loading system root CAs when
  376. // verifying TLS certificates for all remote server list downloads, upgrade
  377. // downloads, and feedback uploads. Each of these transfers has additional
  378. // security at the payload level. Verifying TLS certificates is preferred,
  379. // as an additional security and circumvention layer; set
  380. // DisableSystemRootCAs only in cases where system root CAs cannot be
  381. // loaded; for example, if unsupported (iOS < 12) or insufficient memory
  382. // (VPN extension on iOS < 15).
  383. DisableSystemRootCAs bool
  384. // DisablePeriodicSshKeepAlive indicates whether to send an SSH keepalive
  385. // every 1-2 minutes, when the tunnel is idle. If the SSH keepalive times
  386. // out, the tunnel is considered to have failed.
  387. DisablePeriodicSshKeepAlive bool
  388. // DeviceLocation is the optional, reported location the host device is
  389. // running in. This input value should be a string representing location
  390. // geohash. The device location is reported to the server in the connected
  391. // request and recorded for Psiphon stats.
  392. DeviceLocation string
  393. // DeviceRegion is the optional, reported region the host device is
  394. // running in. This input value should be a ISO 3166-1 alpha-2 country
  395. // code. The device region is reported to the server in the connected
  396. // request and recorded for Psiphon stats.
  397. //
  398. // When provided, this value may be used, pre-connection, to select
  399. // performance or circumvention optimization strategies for the given
  400. // region.
  401. DeviceRegion string
  402. // EmitDiagnosticNotices indicates whether to output notices containing
  403. // detailed information about the Psiphon session. As these notices may
  404. // contain sensitive information, they should not be insecurely distributed
  405. // or displayed to users. Default is off.
  406. EmitDiagnosticNotices bool
  407. // EmitDiagnosticNetworkParameters indicates whether to include network
  408. // parameters in diagnostic notices. As these parameters are sensitive
  409. // circumvention network information, they should not be insecurely
  410. // distributed or displayed to users. Default is off.
  411. EmitDiagnosticNetworkParameters bool
  412. // EmitBytesTransferred indicates whether to emit frequent notices showing
  413. // bytes sent and received.
  414. EmitBytesTransferred bool
  415. // EmitSLOKs indicates whether to emit notices for each seeded SLOK. As
  416. // this could reveal user browsing activity, it's intended for debugging
  417. // and testing only.
  418. EmitSLOKs bool
  419. // EmitRefractionNetworkingLogs indicates whether to emit gotapdance log
  420. // messages to stdout. Note that gotapdance log messages do not conform to
  421. // the Notice format standard. Default is off.
  422. EmitRefractionNetworkingLogs bool
  423. // EmitServerAlerts indicates whether to emit notices for server alerts.
  424. EmitServerAlerts bool
  425. // EmitClientAddress indicates whether to emit the client's public network
  426. // address, IP and port, as seen by the server.
  427. EmitClientAddress bool
  428. // RateLimits specify throttling configuration for the tunnel.
  429. RateLimits common.RateLimits
  430. // PacketTunnelTunDeviceFileDescriptor specifies a tun device file
  431. // descriptor to use for running a packet tunnel. When this value is > 0,
  432. // a packet tunnel is established through the server and packets are
  433. // relayed via the tun device file descriptor. The file descriptor is
  434. // duped in NewController. When PacketTunnelTunDeviceFileDescriptor is
  435. // set, TunnelPoolSize must be 1.
  436. PacketTunnelTunFileDescriptor int
  437. // PacketTunnelTransparentDNSIPv4Address is the IPv4 address of the DNS
  438. // server configured by a VPN using a packet tunnel. All DNS packets
  439. // destined to this DNS server are transparently redirected to the
  440. // Psiphon server DNS.
  441. PacketTunnelTransparentDNSIPv4Address string
  442. // PacketTunnelTransparentDNSIPv6Address is the IPv6 address of the DNS
  443. // server configured by a VPN using a packet tunnel. All DNS packets
  444. // destined to this DNS server are transparently redirected to the
  445. // Psiphon server DNS.
  446. PacketTunnelTransparentDNSIPv6Address string
  447. // SessionID specifies a client session ID to use in the Psiphon API. The
  448. // session ID should be a randomly generated value that is used only for a
  449. // single session, which is defined as the period between a user starting
  450. // a Psiphon client and stopping the client.
  451. //
  452. // A session ID must be 32 hex digits (lower case). When blank, a random
  453. // session ID is automatically generated. Supply a session ID when a
  454. // single client session will cross multiple Controller instances.
  455. SessionID string
  456. // Authorizations is a list of encoded, signed access control
  457. // authorizations that the client has obtained and will present to the
  458. // server.
  459. Authorizations []string
  460. // ServerEntrySignaturePublicKey is a base64-encoded, ed25519 public
  461. // key value used to verify individual server entry signatures. This value
  462. // is supplied by and depends on the Psiphon Network, and is typically
  463. // embedded in the client binary.
  464. ServerEntrySignaturePublicKey string
  465. // ExchangeObfuscationKey is a base64-encoded, NaCl secretbox key used to
  466. // obfuscate server info exchanges between clients.
  467. // Required for the exchange functionality.
  468. ExchangeObfuscationKey string
  469. // MigrateHomepageNoticesFilename migrates a homepage file from the path
  470. // previously configured with setNoticeFiles to the new path for homepage
  471. // files under the data root directory. The file specified by this config
  472. // value will be moved to config.GetHomePageFilename().
  473. //
  474. // Note: see comment for config.Commit() for a description of how file
  475. // migrations are performed.
  476. //
  477. // If not set, no migration operation will be performed.
  478. MigrateHomepageNoticesFilename string
  479. // MigrateRotatingNoticesFilename migrates notice files from the path
  480. // previously configured with setNoticeFiles to the new path for notice
  481. // files under the data root directory.
  482. //
  483. // MigrateRotatingNoticesFilename will be moved to
  484. // config.GetNoticesFilename().
  485. //
  486. // MigrateRotatingNoticesFilename.1 will be moved to
  487. // config.GetOldNoticesFilename().
  488. //
  489. // Note: see comment for config.Commit() for a description of how file
  490. // migrations are performed.
  491. //
  492. // If not set, no migration operation will be performed.
  493. MigrateRotatingNoticesFilename string
  494. // MigrateDataStoreDirectory indicates the location of the datastore
  495. // directory, as previously configured with the deprecated
  496. // DataStoreDirectory config field. Datastore files found in the specified
  497. // directory will be moved under the data root directory.
  498. //
  499. // Note: see comment for config.Commit() for a description of how file
  500. // migrations are performed.
  501. MigrateDataStoreDirectory string
  502. // MigrateRemoteServerListDownloadFilename indicates the location of
  503. // remote server list download files. The remote server list files found at
  504. // the specified path will be moved under the data root directory.
  505. //
  506. // Note: see comment for config.Commit() for a description of how file
  507. // migrations are performed.
  508. MigrateRemoteServerListDownloadFilename string
  509. // MigrateObfuscatedServerListDownloadDirectory indicates the location of
  510. // the obfuscated server list downloads directory, as previously configured
  511. // with ObfuscatedServerListDownloadDirectory. Obfuscated server list
  512. // download files found in the specified directory will be moved under the
  513. // data root directory.
  514. //
  515. // Warning: if the directory is empty after obfuscated server
  516. // list files are moved, then it will be deleted.
  517. //
  518. // Note: see comment for config.Commit() for a description of how file
  519. // migrations are performed.
  520. MigrateObfuscatedServerListDownloadDirectory string
  521. // MigrateUpgradeDownloadFilename indicates the location of downloaded
  522. // application upgrade files. Downloaded upgrade files found at the
  523. // specified path will be moved under the data root directory.
  524. //
  525. // Note: see comment for config.Commit() for a description of how file
  526. // migrations are performed.
  527. MigrateUpgradeDownloadFilename string
  528. // DisableTunnels disables establishing a client tunnel. Set
  529. // DisableTunnels when running a stand-alone in-proxy proxy.
  530. DisableTunnels bool
  531. // InproxyEnableProxy enables running an in-proxy proxy.
  532. InproxyEnableProxy bool
  533. // InproxyProxySessionPrivateKey specifies a long-term in-proxy proxy
  534. // private key and corresponding, derived proxy ID to use. If blank, an
  535. // ephemeral key will be generated.
  536. InproxyProxySessionPrivateKey string
  537. // InproxyMaxClients specifies the maximum number of in-proxy clients to
  538. // be proxied concurrently. Must be > 0 when InproxyEnableProxy is set.
  539. InproxyMaxClients int
  540. // InproxyLimitUpstreamBytesPerSecond specifies the upstream byte transfer
  541. // rate limit for each proxied client. When 0, there is no limit.
  542. InproxyLimitUpstreamBytesPerSecond int
  543. // InproxyLimitDownstreamBytesPerSecond specifies the downstream byte
  544. // transfer rate limit for each proxied client. When 0, there is no limit.
  545. InproxyLimitDownstreamBytesPerSecond int
  546. // InproxyProxyPersonalCompartmentIDs specifies the personal compartment
  547. // IDs used by an in-proxy proxy. Personal compartment IDs are
  548. // distributed from proxy operators to client users out-of-band and
  549. // provide a mechanism to allow only certain clients to use a proxy.
  550. //
  551. // Limitation: currently, at most 1 personal compartment may be specified.
  552. // See InproxyClientPersonalCompartmentIDs comment for additional
  553. // personal pairing limitations.
  554. InproxyProxyPersonalCompartmentIDs []string
  555. // InproxyClientPersonalCompartmentIDs specifies the personal compartment
  556. // IDs used by an in-proxy client. Personal compartment IDs are
  557. // distributed from proxy operators to client users out-of-band and
  558. // provide a mechanism to ensure a client uses only a certain proxy for
  559. // all tunnels connections.
  560. //
  561. // When InproxyClientPersonalCompartmentIDs is set, the client will use
  562. // only in-proxy protocols, ensuring that all connections go through the
  563. // proxy or proxies with the same personal compartment IDs.
  564. //
  565. // Limitations:
  566. //
  567. // While fully functional, the personal pairing mode has a number of
  568. // limitations that make the current implementation less suitable for
  569. // large scale deployment.
  570. //
  571. // Since the mode requires an in-proxy connection to a proxy, announcing
  572. // with the corresponding personal compartment ID, not only must that
  573. // proxy be available, but also a broker, and both the client and proxy
  574. // must rendezvous at the same broker.
  575. //
  576. // In personal mode, clients and proxies use a simplistic approach to
  577. // rendezvous: always select the first broker spec. This works, but is
  578. // not robust in terms of load balancing, and fails if the first broker
  579. // is unreachable or overloaded. Non-personal in-proxy dials can simply
  580. // use any available broker.
  581. //
  582. InproxyClientPersonalCompartmentIDs []string
  583. // InproxyPersonalPairingConnectionWorkerPoolSize specifies the value for
  584. // ConnectionWorkerPoolSize in personal pairing mode. If omitted or when
  585. // 0, a default is used; this is recommended.
  586. InproxyPersonalPairingConnectionWorkerPoolSize int
  587. // EmitInproxyProxyActivity indicates whether to emit frequent notices
  588. // showing proxy connection information and bytes transferred.
  589. EmitInproxyProxyActivity bool
  590. //
  591. // The following parameters are deprecated.
  592. //
  593. // DataStoreDirectory is the directory in which to store the persistent
  594. // database, which contains information such as server entries. By
  595. // default, current working directory.
  596. //
  597. // Deprecated:
  598. // Use MigrateDataStoreDirectory. When MigrateDataStoreDirectory
  599. // is set, this parameter is ignored.
  600. //
  601. // DataStoreDirectory has been subsumed by the new data root directory,
  602. // which is configured with DataRootDirectory. If set, datastore files
  603. // found in the specified directory will be moved under the data root
  604. // directory.
  605. DataStoreDirectory string
  606. // RemoteServerListDownloadFilename specifies a target filename for
  607. // storing the remote server list download. Data is stored in co-located
  608. // files (RemoteServerListDownloadFilename.part*) to allow for resumable
  609. // downloading.
  610. //
  611. // Deprecated:
  612. // Use MigrateRemoteServerListDownloadFilename. When
  613. // MigrateRemoteServerListDownloadFilename is set, this parameter is
  614. // ignored.
  615. //
  616. // If set, remote server list download files found at the specified path
  617. // will be moved under the data root directory.
  618. RemoteServerListDownloadFilename string
  619. // ObfuscatedServerListDownloadDirectory specifies a target directory for
  620. // storing the obfuscated remote server list downloads. Data is stored in
  621. // co-located files (<OSL filename>.part*) to allow for resumable
  622. // downloading.
  623. //
  624. // Deprecated:
  625. // Use MigrateObfuscatedServerListDownloadDirectory. When
  626. // MigrateObfuscatedServerListDownloadDirectory is set, this parameter is
  627. // ignored.
  628. //
  629. // If set, obfuscated server list download files found at the specified path
  630. // will be moved under the data root directory.
  631. ObfuscatedServerListDownloadDirectory string
  632. // UpgradeDownloadFilename is the local target filename for an upgrade
  633. // download. This parameter is required when UpgradeDownloadURLs (or
  634. // UpgradeDownloadUrl) is specified. Data is stored in co-located files
  635. // (UpgradeDownloadFilename.part*) to allow for resumable downloading.
  636. //
  637. // Deprecated:
  638. // Use MigrateUpgradeDownloadFilename. When MigrateUpgradeDownloadFilename
  639. // is set, this parameter is ignored.
  640. //
  641. // If set, upgrade download files found at the specified path will be moved
  642. // under the data root directory.
  643. UpgradeDownloadFilename string
  644. // TunnelProtocol indicates which protocol to use. For the default, "",
  645. // all protocols are used.
  646. //
  647. // Deprecated: Use LimitTunnelProtocols. When LimitTunnelProtocols is not
  648. // nil, this parameter is ignored.
  649. TunnelProtocol string
  650. // Deprecated: Use CustomHeaders. When CustomHeaders is not nil, this
  651. // parameter is ignored.
  652. UpstreamProxyCustomHeaders http.Header
  653. // RemoteServerListUrl is a URL which specifies a location to fetch out-
  654. // of-band server entries. This facility is used when a tunnel cannot be
  655. // established to known servers. This value is supplied by and depends on
  656. // the Psiphon Network, and is typically embedded in the client binary.
  657. //
  658. // Deprecated: Use RemoteServerListURLs. When RemoteServerListURLs is not
  659. // nil, this parameter is ignored.
  660. RemoteServerListUrl string
  661. // ObfuscatedServerListRootURL is a URL which specifies the root location
  662. // from which to fetch obfuscated server list files. This value is
  663. // supplied by and depends on the Psiphon Network, and is typically
  664. // embedded in the client binary.
  665. //
  666. // Deprecated: Use ObfuscatedServerListRootURLs. When
  667. // ObfuscatedServerListRootURLs is not nil, this parameter is ignored.
  668. ObfuscatedServerListRootURL string
  669. // UpgradeDownloadUrl specifies a URL from which to download a host client
  670. // upgrade file, when one is available. The core tunnel controller
  671. // provides a resumable download facility which downloads this resource
  672. // and emits a notice when complete. This value is supplied by and depends
  673. // on the Psiphon Network, and is typically embedded in the client binary.
  674. //
  675. // Deprecated: Use UpgradeDownloadURLs. When UpgradeDownloadURLs is not
  676. // nil, this parameter is ignored.
  677. UpgradeDownloadUrl string
  678. //
  679. // The following parameters are for testing purposes.
  680. //
  681. // TransformHostNameProbability is for testing purposes.
  682. TransformHostNameProbability *float64
  683. // FragmentorProbability and associated Fragmentor fields are for testing
  684. // purposes.
  685. FragmentorProbability *float64
  686. FragmentorLimitProtocols []string
  687. FragmentorMinTotalBytes *int
  688. FragmentorMaxTotalBytes *int
  689. FragmentorMinWriteBytes *int
  690. FragmentorMaxWriteBytes *int
  691. FragmentorMinDelayMicroseconds *int
  692. FragmentorMaxDelayMicroseconds *int
  693. // MeekTrafficShapingProbability and associated fields are for testing
  694. // purposes.
  695. MeekTrafficShapingProbability *float64
  696. MeekTrafficShapingLimitProtocols []string
  697. MeekMinTLSPadding *int
  698. MeekMaxTLSPadding *int
  699. MeekMinLimitRequestPayloadLength *int
  700. MeekMaxLimitRequestPayloadLength *int
  701. MeekRedialTLSProbability *float64
  702. MeekAlternateCookieNameProbability *float64
  703. MeekAlternateContentTypeProbability *float64
  704. // ObfuscatedSSHAlgorithms and associated ObfuscatedSSH fields are for
  705. // testing purposes. If specified, ObfuscatedSSHAlgorithms must have 4 SSH
  706. // KEX elements in order: the kex algorithm, cipher, MAC, and server host
  707. // key algorithm.
  708. ObfuscatedSSHAlgorithms []string
  709. ObfuscatedSSHMinPadding *int
  710. ObfuscatedSSHMaxPadding *int
  711. // LivenessTestMinUpstreamBytes and other LivenessTest fields are for
  712. // testing purposes.
  713. LivenessTestMinUpstreamBytes *int
  714. LivenessTestMaxUpstreamBytes *int
  715. LivenessTestMinDownstreamBytes *int
  716. LivenessTestMaxDownstreamBytes *int
  717. // ReplayCandidateCount and other Replay fields are for testing purposes.
  718. ReplayCandidateCount *int
  719. ReplayDialParametersTTLSeconds *int
  720. ReplayTargetUpstreamBytes *int
  721. ReplayTargetDownstreamBytes *int
  722. ReplayTargetTunnelDurationSeconds *int
  723. ReplayLaterRoundMoveToFrontProbability *float64
  724. ReplayRetainFailedProbability *float64
  725. ReplayIgnoreChangedConfigState *bool
  726. // NetworkLatencyMultiplierMin and other NetworkLatencyMultiplier fields are
  727. // for testing purposes.
  728. NetworkLatencyMultiplierMin float64
  729. NetworkLatencyMultiplierMax float64
  730. NetworkLatencyMultiplierLambda float64
  731. // UseOnlyCustomTLSProfiles and other TLS configuration fields are for
  732. // testing purposes.
  733. UseOnlyCustomTLSProfiles *bool
  734. CustomTLSProfiles protocol.CustomTLSProfiles
  735. SelectRandomizedTLSProfileProbability *float64
  736. NoDefaultTLSSessionIDProbability *float64
  737. DisableFrontingProviderTLSProfiles protocol.LabeledTLSProfiles
  738. // ClientBurstUpstreamTargetBytes and other burst metric fields are for
  739. // testing purposes.
  740. ClientBurstUpstreamTargetBytes *int
  741. ClientBurstUpstreamDeadlineMilliseconds *int
  742. ClientBurstDownstreamTargetBytes *int
  743. ClientBurstDownstreamDeadlineMilliseconds *int
  744. // ApplicationParameters is for testing purposes.
  745. ApplicationParameters parameters.KeyValues
  746. // CustomHostNameRegexes and other custom host name fields are for testing
  747. // purposes.
  748. CustomHostNameRegexes []string
  749. CustomHostNameProbability *float64
  750. CustomHostNameLimitProtocols []string
  751. // ConjureCachedRegistrationTTLSeconds and other Conjure fields are for
  752. // testing purposes.
  753. ConjureCachedRegistrationTTLSeconds *int
  754. ConjureAPIRegistrarBidirectionalURL string
  755. ConjureAPIRegistrarFrontingSpecs parameters.FrontingSpecs
  756. ConjureAPIRegistrarMinDelayMilliseconds *int
  757. ConjureAPIRegistrarMaxDelayMilliseconds *int
  758. ConjureDecoyRegistrarProbability *float64
  759. ConjureDecoyRegistrarWidth *int
  760. ConjureDecoyRegistrarMinDelayMilliseconds *int
  761. ConjureDecoyRegistrarMaxDelayMilliseconds *int
  762. ConjureEnableIPv6Dials *bool
  763. ConjureEnablePortRandomization *bool
  764. ConjureEnableRegistrationOverrides *bool
  765. ConjureLimitTransports protocol.ConjureTransports
  766. ConjureSTUNServerAddresses []string
  767. ConjureDTLSEmptyInitialPacketProbability *float64
  768. // HoldOffTunnelMinDurationMilliseconds and other HoldOffTunnel fields are
  769. // for testing purposes.
  770. HoldOffTunnelMinDurationMilliseconds *int
  771. HoldOffTunnelMaxDurationMilliseconds *int
  772. HoldOffTunnelProtocols []string
  773. HoldOffTunnelFrontingProviderIDs []string
  774. HoldOffTunnelProbability *float64
  775. // RestrictFrontingProviderIDs and other RestrictFrontingProviderIDs fields
  776. // are for testing purposes.
  777. RestrictFrontingProviderIDs []string
  778. RestrictFrontingProviderIDsClientProbability *float64
  779. // HoldOffDirectTunnelMinDurationMilliseconds and other HoldOffDirect
  780. // fields are for testing purposes.
  781. HoldOffDirectTunnelMinDurationMilliseconds *int
  782. HoldOffDirectTunnelMaxDurationMilliseconds *int
  783. HoldOffDirectTunnelProviderRegions map[string][]string
  784. HoldOffDirectTunnelProbability *float64
  785. // RestrictDirectProviderRegions and other RestrictDirect fields are for
  786. // testing purposes.
  787. RestrictDirectProviderRegions map[string][]string
  788. RestrictDirectProviderIDsClientProbability *float64
  789. // UpstreamProxyAllowAllServerEntrySources is for testing purposes.
  790. UpstreamProxyAllowAllServerEntrySources *bool
  791. // LimitTunnelDialPortNumbers is for testing purposes.
  792. LimitTunnelDialPortNumbers parameters.TunnelProtocolPortLists
  793. // QUICDisablePathMTUDiscoveryProbability is for testing purposes.
  794. QUICDisablePathMTUDiscoveryProbability *float64
  795. // DNSResolverAttemptsPerServer and other DNSResolver fields are for
  796. // testing purposes.
  797. DNSResolverAttemptsPerServer *int
  798. DNSResolverAttemptsPerPreferredServer *int
  799. DNSResolverRequestTimeoutMilliseconds *int
  800. DNSResolverAwaitTimeoutMilliseconds *int
  801. DNSResolverPreresolvedIPAddressCIDRs parameters.LabeledCIDRs
  802. DNSResolverPreresolvedIPAddressProbability *float64
  803. DNSResolverAlternateServers []string
  804. DNSResolverPreferredAlternateServers []string
  805. DNSResolverPreferAlternateServerProbability *float64
  806. DNSResolverProtocolTransformSpecs transforms.Specs
  807. DNSResolverProtocolTransformScopedSpecNames transforms.ScopedSpecNames
  808. DNSResolverProtocolTransformProbability *float64
  809. DNSResolverIncludeEDNS0Probability *float64
  810. DNSResolverCacheExtensionInitialTTLMilliseconds *int
  811. DNSResolverCacheExtensionVerifiedTTLMilliseconds *int
  812. DirectHTTPProtocolTransformSpecs transforms.Specs
  813. DirectHTTPProtocolTransformScopedSpecNames transforms.ScopedSpecNames
  814. DirectHTTPProtocolTransformProbability *float64
  815. FrontedHTTPProtocolTransformSpecs transforms.Specs
  816. FrontedHTTPProtocolTransformScopedSpecNames transforms.ScopedSpecNames
  817. FrontedHTTPProtocolTransformProbability *float64
  818. OSSHObfuscatorSeedTransformSpecs transforms.Specs
  819. OSSHObfuscatorSeedTransformScopedSpecNames transforms.ScopedSpecNames
  820. OSSHObfuscatorSeedTransformProbability *float64
  821. ObfuscatedQUICNonceTransformSpecs transforms.Specs
  822. ObfuscatedQUICNonceTransformScopedSpecNames transforms.ScopedSpecNames
  823. ObfuscatedQUICNonceTransformProbability *float64
  824. // OSSHPrefix parameters are for testing purposes only.
  825. OSSHPrefixSpecs transforms.Specs
  826. OSSHPrefixScopedSpecNames transforms.ScopedSpecNames
  827. OSSHPrefixProbability *float64
  828. OSSHPrefixSplitMinDelayMilliseconds *int
  829. OSSHPrefixSplitMaxDelayMilliseconds *int
  830. OSSHPrefixEnableFragmentor *bool
  831. // TLSTunnelTrafficShapingProbability and associated fields are for testing.
  832. TLSTunnelTrafficShapingProbability *float64
  833. TLSTunnelMinTLSPadding *int
  834. TLSTunnelMaxTLSPadding *int
  835. // TLSFragmentClientHello fields are for testing purposes only.
  836. TLSFragmentClientHelloProbability *float64
  837. TLSFragmentClientHelloLimitProtocols []string
  838. // AdditionalParameters is used for testing.
  839. AdditionalParameters string
  840. // SteeringIP fields are for testing purposes only.
  841. SteeringIPCacheTTLSeconds *int
  842. SteeringIPCacheMaxEntries *int
  843. SteeringIPProbability *float64
  844. // The following in-proxy fields are for testing purposes only.
  845. InproxyAllowProxy *bool
  846. InproxyAllowClient *bool
  847. InproxyTunnelProtocolSelectionProbability *float64
  848. InproxyBrokerSpecs parameters.InproxyBrokerSpecsValue
  849. InproxyPersonalPairingBrokerSpecs parameters.InproxyBrokerSpecsValue
  850. InproxyProxyBrokerSpecs parameters.InproxyBrokerSpecsValue
  851. InproxyProxyPersonalPairingBrokerSpecs parameters.InproxyBrokerSpecsValue
  852. InproxyClientBrokerSpecs parameters.InproxyBrokerSpecsValue
  853. InproxyClientPersonalPairingBrokerSpecs parameters.InproxyBrokerSpecsValue
  854. InproxyReplayBrokerDialParametersTTLSeconds *int
  855. InproxyReplayBrokerUpdateFrequencySeconds *int
  856. InproxyReplayBrokerDialParametersProbability *float64
  857. InproxyReplayBrokerRetainFailedProbability *float64
  858. InproxyCommonCompartmentIDs parameters.InproxyCompartmentIDsValue
  859. InproxyMaxCompartmentIDListLength *int
  860. InproxyProxyAnnounceRequestTimeoutMilliseconds *int
  861. InproxyProxyAnnounceDelayMilliseconds *int
  862. InproxyProxyAnnounceDelayJitter *float64
  863. InproxyProxyAnswerRequestTimeoutMilliseconds *int
  864. InproxyClientOfferRequestTimeoutMilliseconds *int
  865. InproxyClientOfferRetryDelayMilliseconds *int
  866. InproxyClientOfferRetryJitter *float64
  867. InproxyClientRelayedPacketRequestTimeoutMilliseconds *int
  868. InproxyDTLSRandomizationProbability *float64
  869. InproxyDataChannelTrafficShapingProbability *float64
  870. InproxyDataChannelTrafficShapingParameters *parameters.InproxyDataChannelTrafficShapingParametersValue
  871. InproxySTUNServerAddresses []string
  872. InproxySTUNServerAddressesRFC5780 []string
  873. InproxyProxySTUNServerAddresses []string
  874. InproxyProxySTUNServerAddressesRFC5780 []string
  875. InproxyClientSTUNServerAddresses []string
  876. InproxyClientSTUNServerAddressesRFC5780 []string
  877. InproxyClientDiscoverNATProbability *float64
  878. InproxyDisableSTUN *bool
  879. InproxyDisablePortMapping *bool
  880. InproxyDisableInboundForMobileNetworks *bool
  881. InproxyDisableIPv6ICECandidates *bool
  882. InproxyProxyDisableSTUN *bool
  883. InproxyProxyDisablePortMapping *bool
  884. InproxyProxyDisableInboundForMobileNetworks *bool
  885. InproxyProxyDisableIPv6ICECandidates *bool
  886. InproxyClientDisableSTUN *bool
  887. InproxyClientDisablePortMapping *bool
  888. InproxyClientDisableInboundForMobileNetworks *bool
  889. InproxyClientDisableIPv6ICECandidates *bool
  890. InproxyProxyDiscoverNATTimeoutMilliseconds *int
  891. InproxyClientDiscoverNATTimeoutMilliseconds *int
  892. InproxyWebRTCAnswerTimeoutMilliseconds *int
  893. InproxyProxyWebRTCAwaitDataChannelTimeoutMilliseconds *int
  894. InproxyClientWebRTCAwaitDataChannelTimeoutMilliseconds *int
  895. InproxyProxyDestinationDialTimeoutMilliseconds *int
  896. InproxyPsiphonAPIRequestTimeoutMilliseconds *int
  897. InproxyProxyTotalActivityNoticePeriodMilliseconds *int
  898. InproxyClientDialRateLimitQuantity *int
  899. InproxyClientDialRateLimitIntervalMilliseconds *int
  900. InproxySkipAwaitFullyConnected bool
  901. InproxyEnableWebRTCDebugLogging bool
  902. // params is the active parameters.Parameters with defaults, config values,
  903. // and, optionally, tactics applied.
  904. //
  905. // New tactics must be applied by calling Config.SetParameters; calling
  906. // params.Set directly will fail to add config values.
  907. paramsMutex sync.Mutex
  908. params *parameters.Parameters
  909. dialParametersHash []byte
  910. dynamicConfigMutex sync.Mutex
  911. sponsorID string
  912. authorizations []string
  913. deviceBinder DeviceBinder
  914. networkIDGetter NetworkIDGetter
  915. clientFeatures []string
  916. resolverMutex sync.Mutex
  917. resolver *resolver.Resolver
  918. committed bool
  919. loadTimestamp string
  920. tacticsAppliedReceiversMutex sync.Mutex
  921. tacticsAppliedReceivers []TacticsAppliedReceiver
  922. signalComponentFailure atomic.Value
  923. inproxyMustUpgradePosted int32
  924. }
  925. // TacticsAppliedReceiver specifies the interface for a component that is
  926. // signaled when tactics are applied. TacticsApplied is invoked when any
  927. // tactics are applied after initial start up, and then whenever new tactics
  928. // are received and applied while running.
  929. type TacticsAppliedReceiver interface {
  930. TacticsApplied() error
  931. }
  932. // Config field which specifies if notice files should be used and at which
  933. // frequency and size they should be rotated.
  934. //
  935. // If either RotatingFileSize or RotatingSyncFrequency are <= 0, default values
  936. // are used.
  937. //
  938. // See comment for setNoticeFiles in notice.go for further details.
  939. type UseNoticeFiles struct {
  940. RotatingFileSize int
  941. RotatingSyncFrequency int
  942. }
  943. // LoadConfig parses a JSON format Psiphon config JSON string and returns a
  944. // Config struct populated with config values.
  945. //
  946. // The Config struct may then be programmatically populated with additional
  947. // values, including callbacks such as DeviceBinder.
  948. //
  949. // Before using the Config, Commit must be called, which will perform further
  950. // validation and initialize internal data structures.
  951. func LoadConfig(configJson []byte) (*Config, error) {
  952. var config Config
  953. err := json.Unmarshal(configJson, &config)
  954. if err != nil {
  955. return nil, errors.Trace(err)
  956. }
  957. config.loadTimestamp = common.TruncateTimestampToHour(
  958. common.GetCurrentTimestamp())
  959. config.signalComponentFailure.Store(func() {})
  960. return &config, nil
  961. }
  962. // IsCommitted checks if Commit was called.
  963. func (config *Config) IsCommitted() bool {
  964. return config.committed
  965. }
  966. // Commit validates Config fields finalizes initialization.
  967. //
  968. // Config fields should not be set after calling Config, as any changes may
  969. // not be reflected in internal data structures.
  970. //
  971. // If migrateFromLegacyFields is set to true, then an attempt to migrate from
  972. // legacy fields is made.
  973. //
  974. // Migration from legacy fields:
  975. // Config fields of the naming Migrate* (e.g. MigrateDataStoreDirectory) specify
  976. // a file migration operation which should be performed. These fields correspond
  977. // to deprecated fields, which previously could be used to specify where Psiphon
  978. // stored different sets of persistent files (e.g. MigrateDataStoreDirectory
  979. // corresponds to the deprecated field DataStoreDirectory).
  980. //
  981. // Psiphon now stores all persistent data under the configurable
  982. // DataRootDirectory (see Config.DataRootDirectory). The deprecated fields, and
  983. // corresponding Migrate* fields, are now used to specify the file or directory
  984. // path where, or under which, persistent files and directories created by
  985. // previous versions of Psiphon exist, so they can be moved under the
  986. // DataRootDirectory.
  987. //
  988. // For each migration operation:
  989. // - In the case of directories that could have defaulted to the current working
  990. // directory, persistent files and directories created by Psiphon are
  991. // precisely targeted to avoid moving files which were not created by Psiphon.
  992. // - If no file is found at the specified path, or an error is encountered while
  993. // migrating the file, then an error is logged and execution continues
  994. // normally.
  995. //
  996. // A sentinel file which signals that file migration has been completed, and
  997. // should not be attempted again, is created under DataRootDirectory after one
  998. // full pass through Commit(), regardless of whether file migration succeeds or
  999. // fails. It is better to not endlessly retry file migrations on each Commit()
  1000. // because file system errors are expected to be rare and persistent files will
  1001. // be re-populated over time.
  1002. func (config *Config) Commit(migrateFromLegacyFields bool) error {
  1003. // Apply any additional parameters first
  1004. additionalParametersInfoMsgs, err := config.applyAdditionalParameters()
  1005. if err != nil {
  1006. return errors.TraceMsg(err, "failed to apply additional parameters")
  1007. }
  1008. // Do SetEmitDiagnosticNotices first, to ensure config file errors are
  1009. // emitted.
  1010. if config.EmitDiagnosticNotices {
  1011. SetEmitDiagnosticNotices(
  1012. true, config.EmitDiagnosticNetworkParameters)
  1013. }
  1014. // Migrate and set notice files before any operations that may emit an
  1015. // error. This is to ensure config file errors are written to file when
  1016. // notice files are configured with config.UseNoticeFiles.
  1017. //
  1018. // Note:
  1019. // Errors encountered while configuring the data directory cannot be written
  1020. // to notice files. This is because notices files are created within the
  1021. // data directory.
  1022. if config.DataRootDirectory == "" {
  1023. wd, err := os.Getwd()
  1024. if err != nil {
  1025. return errors.Trace(common.RedactFilePathsError(err))
  1026. }
  1027. config.DataRootDirectory = wd
  1028. }
  1029. // Create root directory
  1030. dataDirectoryPath := config.GetPsiphonDataDirectory()
  1031. if !common.FileExists(dataDirectoryPath) {
  1032. err := os.Mkdir(dataDirectoryPath, os.ModePerm)
  1033. if err != nil {
  1034. return errors.Tracef(
  1035. "failed to create datastore directory with error: %s",
  1036. common.RedactFilePathsError(err, dataDirectoryPath))
  1037. }
  1038. }
  1039. // Check if the migration from legacy config fields has already been
  1040. // completed. See the Migrate* config fields for more details.
  1041. migrationCompleteFilePath := filepath.Join(config.GetPsiphonDataDirectory(), "migration_complete")
  1042. needMigration := !common.FileExists(migrationCompleteFilePath)
  1043. // Collect notices to emit them after notice files are set
  1044. var noticeMigrationAlertMsgs []string
  1045. var noticeMigrationInfoMsgs []string
  1046. // Migrate notices first to ensure notice files are used for notices if
  1047. // UseNoticeFiles is set.
  1048. homepageFilePath := config.GetHomePageFilename()
  1049. noticesFilePath := config.GetNoticesFilename()
  1050. if migrateFromLegacyFields {
  1051. if needMigration {
  1052. // Move notice files that exist at legacy file paths under the data root
  1053. // directory.
  1054. noticeMigrationInfoMsgs = append(noticeMigrationInfoMsgs, "Config migration: need migration")
  1055. noticeMigrations := migrationsFromLegacyNoticeFilePaths(config)
  1056. successfulMigrations := 0
  1057. for _, migration := range noticeMigrations {
  1058. err := DoFileMigration(migration)
  1059. if err != nil {
  1060. alertMsg := fmt.Sprintf("Config migration: %s", errors.Trace(err))
  1061. noticeMigrationAlertMsgs = append(noticeMigrationAlertMsgs, alertMsg)
  1062. } else {
  1063. successfulMigrations += 1
  1064. }
  1065. }
  1066. infoMsg := fmt.Sprintf("Config migration: %d/%d notice files successfully migrated", successfulMigrations, len(noticeMigrations))
  1067. noticeMigrationInfoMsgs = append(noticeMigrationInfoMsgs, infoMsg)
  1068. } else {
  1069. noticeMigrationInfoMsgs = append(noticeMigrationInfoMsgs, "Config migration: migration already completed")
  1070. }
  1071. }
  1072. if config.UseNoticeFiles != nil {
  1073. setNoticeFiles(
  1074. homepageFilePath,
  1075. noticesFilePath,
  1076. config.UseNoticeFiles.RotatingFileSize,
  1077. config.UseNoticeFiles.RotatingSyncFrequency)
  1078. }
  1079. // Emit notices now that notice files are set if configured
  1080. for _, msg := range additionalParametersInfoMsgs {
  1081. NoticeInfo(msg)
  1082. }
  1083. for _, msg := range noticeMigrationAlertMsgs {
  1084. NoticeWarning(msg)
  1085. }
  1086. for _, msg := range noticeMigrationInfoMsgs {
  1087. NoticeInfo(msg)
  1088. }
  1089. // Promote legacy fields.
  1090. if config.CustomHeaders == nil {
  1091. config.CustomHeaders = config.UpstreamProxyCustomHeaders
  1092. config.UpstreamProxyCustomHeaders = nil
  1093. }
  1094. if config.RemoteServerListUrl != "" && config.RemoteServerListURLs == nil {
  1095. config.RemoteServerListURLs = promoteLegacyTransferURL(config.RemoteServerListUrl)
  1096. }
  1097. if config.ObfuscatedServerListRootURL != "" && config.ObfuscatedServerListRootURLs == nil {
  1098. config.ObfuscatedServerListRootURLs = promoteLegacyTransferURL(config.ObfuscatedServerListRootURL)
  1099. }
  1100. if config.UpgradeDownloadUrl != "" && config.UpgradeDownloadURLs == nil {
  1101. config.UpgradeDownloadURLs = promoteLegacyTransferURL(config.UpgradeDownloadUrl)
  1102. }
  1103. if config.TunnelProtocol != "" && len(config.LimitTunnelProtocols) == 0 {
  1104. config.LimitTunnelProtocols = []string{config.TunnelProtocol}
  1105. }
  1106. if config.DataStoreDirectory != "" && config.MigrateDataStoreDirectory == "" {
  1107. config.MigrateDataStoreDirectory = config.DataStoreDirectory
  1108. }
  1109. if config.RemoteServerListDownloadFilename != "" && config.MigrateRemoteServerListDownloadFilename == "" {
  1110. config.MigrateRemoteServerListDownloadFilename = config.RemoteServerListDownloadFilename
  1111. }
  1112. if config.ObfuscatedServerListDownloadDirectory != "" && config.MigrateObfuscatedServerListDownloadDirectory == "" {
  1113. config.MigrateObfuscatedServerListDownloadDirectory = config.ObfuscatedServerListDownloadDirectory
  1114. }
  1115. if config.UpgradeDownloadFilename != "" && config.MigrateUpgradeDownloadFilename == "" {
  1116. config.MigrateUpgradeDownloadFilename = config.UpgradeDownloadFilename
  1117. }
  1118. // Supply default values.
  1119. // Create datastore directory.
  1120. dataStoreDirectoryPath := config.GetDataStoreDirectory()
  1121. if !common.FileExists(dataStoreDirectoryPath) {
  1122. err := os.Mkdir(dataStoreDirectoryPath, os.ModePerm)
  1123. if err != nil {
  1124. return errors.Tracef(
  1125. "failed to create datastore directory with error: %s",
  1126. common.RedactFilePathsError(err, dataStoreDirectoryPath))
  1127. }
  1128. }
  1129. // Create OSL directory.
  1130. oslDirectoryPath := config.GetObfuscatedServerListDownloadDirectory()
  1131. if !common.FileExists(oslDirectoryPath) {
  1132. err := os.Mkdir(oslDirectoryPath, os.ModePerm)
  1133. if err != nil {
  1134. return errors.Tracef(
  1135. "failed to create osl directory with error: %s",
  1136. common.RedactFilePathsError(err, oslDirectoryPath))
  1137. }
  1138. }
  1139. if config.ClientVersion == "" {
  1140. config.ClientVersion = "0"
  1141. }
  1142. if config.TunnelPoolSize == 0 {
  1143. config.TunnelPoolSize = TUNNEL_POOL_SIZE
  1144. }
  1145. // Validate config fields.
  1146. if !common.FileExists(config.DataRootDirectory) {
  1147. return errors.TraceNew("DataRootDirectory does not exist")
  1148. }
  1149. if config.PropagationChannelId == "" {
  1150. return errors.TraceNew("propagation channel ID is missing from the configuration file")
  1151. }
  1152. if config.SponsorId == "" {
  1153. return errors.TraceNew("sponsor ID is missing from the configuration file")
  1154. }
  1155. _, err = strconv.Atoi(config.ClientVersion)
  1156. if err != nil {
  1157. return errors.Tracef("invalid client version: %s", err)
  1158. }
  1159. if config.TargetAPIProtocol != "" &&
  1160. !protocol.PsiphonAPIProtocolIsValid(config.TargetAPIProtocol) {
  1161. return errors.TraceNew("invalid TargetAPIProtocol")
  1162. }
  1163. if config.TargetAPIEncoding != "" &&
  1164. !protocol.PsiphonAPIEncodingIsValid(config.TargetAPIEncoding) {
  1165. return errors.TraceNew("invalid TargetAPIEncoding")
  1166. }
  1167. if !config.DisableRemoteServerListFetcher {
  1168. if config.RemoteServerListURLs != nil {
  1169. if config.RemoteServerListSignaturePublicKey == "" {
  1170. return errors.TraceNew("missing RemoteServerListSignaturePublicKey")
  1171. }
  1172. }
  1173. if config.ObfuscatedServerListRootURLs != nil {
  1174. if config.RemoteServerListSignaturePublicKey == "" {
  1175. return errors.TraceNew("missing RemoteServerListSignaturePublicKey")
  1176. }
  1177. }
  1178. }
  1179. if config.EnableUpgradeDownload {
  1180. if len(config.UpgradeDownloadURLs) == 0 {
  1181. return errors.TraceNew("missing UpgradeDownloadURLs")
  1182. }
  1183. if config.UpgradeDownloadClientVersionHeader == "" {
  1184. return errors.TraceNew("missing UpgradeDownloadClientVersionHeader")
  1185. }
  1186. }
  1187. if config.EnableFeedbackUpload {
  1188. if len(config.FeedbackUploadURLs) == 0 {
  1189. return errors.TraceNew("missing FeedbackUploadURLs")
  1190. }
  1191. if config.FeedbackEncryptionPublicKey == "" {
  1192. return errors.TraceNew("missing FeedbackEncryptionPublicKey")
  1193. }
  1194. }
  1195. if config.ObfuscatedSSHAlgorithms != nil &&
  1196. len(config.ObfuscatedSSHAlgorithms) != 4 {
  1197. // TODO: validate each algorithm?
  1198. return errors.TraceNew("invalid ObfuscatedSSHAlgorithms")
  1199. }
  1200. if config.InproxyEnableProxy && config.InproxyMaxClients <= 0 {
  1201. return errors.TraceNew("invalid InproxyMaxClients")
  1202. }
  1203. if !config.DisableTunnels &&
  1204. config.InproxyEnableProxy &&
  1205. !GetAllowOverlappingPersonalCompartmentIDs() &&
  1206. common.ContainsAny(
  1207. config.InproxyProxyPersonalCompartmentIDs,
  1208. config.InproxyClientPersonalCompartmentIDs) {
  1209. // Don't allow an in-proxy client and proxy run in the same app to match.
  1210. return errors.TraceNew("invalid overlapping personal compartment IDs")
  1211. }
  1212. if len(config.InproxyProxyPersonalCompartmentIDs) > 1 {
  1213. return errors.TraceNew("invalid proxy personal compartment ID count")
  1214. }
  1215. // This constraint is expected by logic in Controller.runTunnels().
  1216. if config.PacketTunnelTunFileDescriptor > 0 && config.TunnelPoolSize != 1 {
  1217. return errors.TraceNew("packet tunnel mode requires TunnelPoolSize to be 1")
  1218. }
  1219. // SessionID must be PSIPHON_API_CLIENT_SESSION_ID_LENGTH lowercase hex-encoded bytes.
  1220. if config.SessionID == "" {
  1221. sessionID, err := MakeSessionId()
  1222. if err != nil {
  1223. return errors.Trace(err)
  1224. }
  1225. config.SessionID = sessionID
  1226. }
  1227. if len(config.SessionID) != 2*protocol.PSIPHON_API_CLIENT_SESSION_ID_LENGTH ||
  1228. -1 != strings.IndexFunc(config.SessionID, func(c rune) bool {
  1229. return !unicode.Is(unicode.ASCII_Hex_Digit, c) || unicode.IsUpper(c)
  1230. }) {
  1231. return errors.TraceNew("invalid SessionID")
  1232. }
  1233. config.paramsMutex.Lock()
  1234. config.params, err = parameters.NewParameters(
  1235. func(err error) {
  1236. NoticeWarning("Parameters getValue failed: %s", err)
  1237. })
  1238. config.paramsMutex.Unlock()
  1239. if err != nil {
  1240. return errors.Trace(err)
  1241. }
  1242. // parametersParameters.Set will validate the config fields applied to
  1243. // parametersParameters.
  1244. err = config.SetParameters("", false, nil)
  1245. if err != nil {
  1246. return errors.Trace(err)
  1247. }
  1248. // Calculate and set the dial parameters hash. After this point, related
  1249. // config fields must not change.
  1250. config.setDialParametersHash()
  1251. // Set defaults for dynamic config fields.
  1252. config.SetDynamicConfig(config.SponsorId, config.Authorizations)
  1253. // Initialize config.deviceBinder and config.config.networkIDGetter. These
  1254. // wrap config.DeviceBinder and config.NetworkIDGetter/NetworkID with
  1255. // loggers.
  1256. //
  1257. // New variables are set to avoid mutating input config fields.
  1258. // Internally, code must use config.deviceBinder and
  1259. // config.networkIDGetter and not the input/exported fields.
  1260. if config.DeviceBinder != nil {
  1261. config.deviceBinder = newLoggingDeviceBinder(config.DeviceBinder)
  1262. }
  1263. networkIDGetter := config.NetworkIDGetter
  1264. if networkIDGetter == nil {
  1265. // Limitation: unlike NetworkIDGetter, which calls back to platform APIs
  1266. // this method of network identification is not dynamic and will not reflect
  1267. // network changes that occur while running.
  1268. if config.NetworkID != "" {
  1269. networkIDGetter = newStaticNetworkGetter(config.NetworkID)
  1270. } else {
  1271. networkIDGetter = newStaticNetworkGetter("UNKNOWN")
  1272. }
  1273. }
  1274. config.networkIDGetter = newLoggingNetworkIDGetter(networkIDGetter)
  1275. // Initialize config.clientFeatures, which adds feature names on top of
  1276. // those specified by the host application in config.ClientFeatures.
  1277. config.clientFeatures = config.ClientFeatures
  1278. feature := "VPN"
  1279. if config.DeviceBinder != nil && !common.Contains(config.clientFeatures, feature) {
  1280. config.clientFeatures = append(config.clientFeatures, feature)
  1281. }
  1282. // Migrate from old config fields. This results in files being moved under
  1283. // a config specified data root directory.
  1284. if migrateFromLegacyFields && needMigration {
  1285. // If unset, set MigrateDataStoreDirectory to the previous default value for
  1286. // DataStoreDirectory to ensure that datastore files are migrated.
  1287. if config.MigrateDataStoreDirectory == "" {
  1288. wd, err := os.Getwd()
  1289. if err != nil {
  1290. return errors.Trace(err)
  1291. }
  1292. NoticeInfo("MigrateDataStoreDirectory unset, using working directory")
  1293. config.MigrateDataStoreDirectory = wd
  1294. }
  1295. // Move files that exist at legacy file paths under the data root
  1296. // directory.
  1297. migrations, err := migrationsFromLegacyFilePaths(config)
  1298. if err != nil {
  1299. return errors.Trace(err)
  1300. }
  1301. // Do migrations
  1302. successfulMigrations := 0
  1303. for _, migration := range migrations {
  1304. err := DoFileMigration(migration)
  1305. if err != nil {
  1306. NoticeWarning("Config migration: %s", errors.Trace(err))
  1307. } else {
  1308. successfulMigrations += 1
  1309. }
  1310. }
  1311. NoticeInfo(fmt.Sprintf(
  1312. "Config migration: %d/%d legacy files successfully migrated",
  1313. successfulMigrations, len(migrations)))
  1314. // Remove OSL directory if empty
  1315. if config.MigrateObfuscatedServerListDownloadDirectory != "" {
  1316. files, err := ioutil.ReadDir(config.MigrateObfuscatedServerListDownloadDirectory)
  1317. if err != nil {
  1318. NoticeWarning(
  1319. "Error reading OSL directory: %s",
  1320. errors.Trace(common.RedactFilePathsError(err, config.MigrateObfuscatedServerListDownloadDirectory)))
  1321. } else if len(files) == 0 {
  1322. err := os.Remove(config.MigrateObfuscatedServerListDownloadDirectory)
  1323. if err != nil {
  1324. NoticeWarning(
  1325. "Error deleting empty OSL directory: %s",
  1326. errors.Trace(common.RedactFilePathsError(err, config.MigrateObfuscatedServerListDownloadDirectory)))
  1327. }
  1328. }
  1329. }
  1330. f, err := os.Create(migrationCompleteFilePath)
  1331. if err != nil {
  1332. NoticeWarning(
  1333. "Config migration: failed to create migration completed file with error %s",
  1334. errors.Trace(common.RedactFilePathsError(err, migrationCompleteFilePath)))
  1335. } else {
  1336. NoticeInfo("Config migration: completed")
  1337. f.Close()
  1338. }
  1339. }
  1340. config.committed = true
  1341. return nil
  1342. }
  1343. // GetParameters returns the current parameters.Parameters.
  1344. func (config *Config) GetParameters() *parameters.Parameters {
  1345. config.paramsMutex.Lock()
  1346. defer config.paramsMutex.Unlock()
  1347. return config.params
  1348. }
  1349. // SetParameters resets the parameters.Parameters to the default values,
  1350. // applies any config file values, and then applies the input parameters (from
  1351. // tactics, etc.)
  1352. //
  1353. // Set skipOnError to false when initially applying only config values, as
  1354. // this will validate the values and should fail. Set skipOnError to true when
  1355. // applying tactics to ignore invalid or unknown parameter values from tactics.
  1356. //
  1357. // In the case of applying tactics, do not call Config.parameters.Set
  1358. // directly as this will not first apply config values.
  1359. //
  1360. // If there is an error, the existing Config.parameters are left
  1361. // entirely unmodified.
  1362. func (config *Config) SetParameters(tag string, skipOnError bool, applyParameters map[string]interface{}) error {
  1363. setParameters := []map[string]interface{}{config.makeConfigParameters()}
  1364. if applyParameters != nil {
  1365. setParameters = append(setParameters, applyParameters)
  1366. }
  1367. // Don't hold the lock on config.paramsMutex when signalling
  1368. // GetTacticsAppliedReceivers, or else GetParameters will deadlock.
  1369. // Releasing the lock early here also ensures we don't hold the lock when
  1370. // posting notices.
  1371. config.paramsMutex.Lock()
  1372. validationFlags := 0
  1373. if skipOnError {
  1374. validationFlags |= parameters.ValidationSkipOnError
  1375. }
  1376. counts, err := config.params.Set(tag, validationFlags, setParameters...)
  1377. if err != nil {
  1378. config.paramsMutex.Unlock()
  1379. return errors.Trace(err)
  1380. }
  1381. p := config.params.Get()
  1382. config.paramsMutex.Unlock()
  1383. NoticeInfo("applied %v parameters with tag '%s'", counts, tag)
  1384. // Emit certain individual parameter values for quick reference in diagnostics.
  1385. NoticeInfo(
  1386. "NetworkLatencyMultiplier Min/Max/Lambda: %f/%f/%f",
  1387. p.Float(parameters.NetworkLatencyMultiplierMin),
  1388. p.Float(parameters.NetworkLatencyMultiplierMax),
  1389. p.Float(parameters.NetworkLatencyMultiplierLambda))
  1390. // Application Parameters are feature flags/config info, delivered as Client
  1391. // Parameters via tactics/etc., to be communicated to the outer application.
  1392. // Emit these now, as notices.
  1393. if p.WeightedCoinFlip(parameters.ApplicationParametersProbability) {
  1394. NoticeApplicationParameters(p.KeyValues(parameters.ApplicationParameters))
  1395. } else {
  1396. // The front end may persist Application Parameters, so clear any previously
  1397. // persisted values.
  1398. NoticeApplicationParameters(parameters.KeyValues{})
  1399. }
  1400. // Signal all registered TacticsAppliedReceivers that new tactics have
  1401. // been applied. Each receiver is responsible for checking if its
  1402. // individual tactics parameters have actually changed.
  1403. for _, receiver := range config.GetTacticsAppliedReceivers() {
  1404. err := receiver.TacticsApplied()
  1405. if err != nil {
  1406. NoticeError("TacticsApplied failed: %v", err)
  1407. // Log and continue running.
  1408. }
  1409. }
  1410. return nil
  1411. }
  1412. // SetResolver sets the current resolver.
  1413. func (config *Config) SetResolver(resolver *resolver.Resolver) {
  1414. config.resolverMutex.Lock()
  1415. defer config.resolverMutex.Unlock()
  1416. config.resolver = resolver
  1417. }
  1418. // GetResolver returns the current resolver. May return nil.
  1419. func (config *Config) GetResolver() *resolver.Resolver {
  1420. config.resolverMutex.Lock()
  1421. defer config.resolverMutex.Unlock()
  1422. return config.resolver
  1423. }
  1424. // SetTacticsAppliedReceivers registers the list of TacticsAppliedReceivers.
  1425. func (config *Config) SetTacticsAppliedReceivers(receivers []TacticsAppliedReceiver) {
  1426. config.tacticsAppliedReceiversMutex.Lock()
  1427. defer config.tacticsAppliedReceiversMutex.Unlock()
  1428. config.tacticsAppliedReceivers = receivers
  1429. }
  1430. // GetTacticsAppliedReceivers gets the list of registered
  1431. // TacticsAppliedReceivers.
  1432. func (config *Config) GetTacticsAppliedReceivers() []TacticsAppliedReceiver {
  1433. config.tacticsAppliedReceiversMutex.Lock()
  1434. defer config.tacticsAppliedReceiversMutex.Unlock()
  1435. return config.tacticsAppliedReceivers
  1436. }
  1437. // SetDynamicConfig sets the current client sponsor ID and authorizations.
  1438. // Invalid values for sponsor ID are ignored. The caller must not modify the
  1439. // input authorizations slice.
  1440. func (config *Config) SetDynamicConfig(sponsorID string, authorizations []string) {
  1441. config.dynamicConfigMutex.Lock()
  1442. defer config.dynamicConfigMutex.Unlock()
  1443. if sponsorID != "" {
  1444. config.sponsorID = sponsorID
  1445. }
  1446. config.authorizations = authorizations
  1447. }
  1448. // GetSponsorID returns the current client sponsor ID.
  1449. func (config *Config) GetSponsorID() string {
  1450. config.dynamicConfigMutex.Lock()
  1451. defer config.dynamicConfigMutex.Unlock()
  1452. return config.sponsorID
  1453. }
  1454. // IsSplitTunnelEnabled indicates if split tunnel mode is enabled, either for
  1455. // the client's own country, a specified list of countries, or both.
  1456. func (config *Config) IsSplitTunnelEnabled() bool {
  1457. return config.SplitTunnelOwnRegion || len(config.SplitTunnelRegions) > 0
  1458. }
  1459. // GetAuthorizations returns the current client authorizations.
  1460. // The caller must not modify the returned slice.
  1461. func (config *Config) GetAuthorizations() []string {
  1462. config.dynamicConfigMutex.Lock()
  1463. defer config.dynamicConfigMutex.Unlock()
  1464. return config.authorizations
  1465. }
  1466. // GetPsiphonDataDirectory returns the directory under which all persistent
  1467. // files should be stored. This directory is created under
  1468. // config.DataRootDirectory. The motivation for an additional directory is that
  1469. // config.DataRootDirectory defaults to the current working directory, which may
  1470. // include non-tunnel-core files that should be excluded from directory-spanning
  1471. // operations (e.g. excluding all tunnel-core files from backup).
  1472. func (config *Config) GetPsiphonDataDirectory() string {
  1473. return filepath.Join(config.DataRootDirectory, PsiphonDataDirectoryName)
  1474. }
  1475. // GetHomePageFilename the path where the homepage notices file will be created.
  1476. func (config *Config) GetHomePageFilename() string {
  1477. return filepath.Join(config.GetPsiphonDataDirectory(), HomepageFilename)
  1478. }
  1479. // GetNoticesFilename returns the path where the notices file will be created.
  1480. // When the file is rotated it will be moved to config.GetOldNoticesFilename().
  1481. func (config *Config) GetNoticesFilename() string {
  1482. return filepath.Join(config.GetPsiphonDataDirectory(), NoticesFilename)
  1483. }
  1484. // GetOldNoticeFilename returns the path where the rotated notices file will be
  1485. // created.
  1486. func (config *Config) GetOldNoticesFilename() string {
  1487. return filepath.Join(config.GetPsiphonDataDirectory(), OldNoticesFilename)
  1488. }
  1489. // GetDataStoreDirectory returns the directory in which the persistent database
  1490. // will be stored. Created in Config.Commit(). The persistent database contains
  1491. // information such as server entries.
  1492. func (config *Config) GetDataStoreDirectory() string {
  1493. return filepath.Join(config.GetPsiphonDataDirectory(), "datastore")
  1494. }
  1495. // GetObfuscatedServerListDownloadDirectory returns the directory in which
  1496. // obfuscated remote server list downloads will be stored. Created in
  1497. // Config.Commit().
  1498. func (config *Config) GetObfuscatedServerListDownloadDirectory() string {
  1499. return filepath.Join(config.GetPsiphonDataDirectory(), "osl")
  1500. }
  1501. // GetRemoteServerListDownloadFilename returns the filename where the remote
  1502. // server list download will be stored. Data is stored in co-located files
  1503. // (RemoteServerListDownloadFilename.part*) to allow for resumable downloading.
  1504. func (config *Config) GetRemoteServerListDownloadFilename() string {
  1505. return filepath.Join(config.GetPsiphonDataDirectory(), "remote_server_list")
  1506. }
  1507. // GetUpgradeDownloadFilename specifies the filename where upgrade downloads
  1508. // will be stored. This filename is valid when UpgradeDownloadURLs
  1509. // (or UpgradeDownloadUrl) is specified. Data is stored in co-located files
  1510. // (UpgradeDownloadFilename.part*) to allow for resumable downloading.
  1511. func (config *Config) GetUpgradeDownloadFilename() string {
  1512. return filepath.Join(config.GetPsiphonDataDirectory(), UpgradeDownloadFilename)
  1513. }
  1514. // UseUpstreamProxy indicates if an upstream proxy has been
  1515. // configured.
  1516. func (config *Config) UseUpstreamProxy() bool {
  1517. return config.UpstreamProxyURL != ""
  1518. }
  1519. // GetNetworkID returns the current network ID. When NetworkIDGetter
  1520. // is set, this calls into the host application; otherwise, a default
  1521. // value is returned.
  1522. func (config *Config) GetNetworkID() string {
  1523. return config.networkIDGetter.GetNetworkID()
  1524. }
  1525. func (config *Config) SetSignalComponentFailure(signalComponentFailure func()) {
  1526. config.signalComponentFailure.Store(signalComponentFailure)
  1527. }
  1528. // IsInproxyPersonalPairingMode indicates that the client is in in-proxy
  1529. // personal pairing mode, where connections are made only through in-proxy
  1530. // proxies with corresponding personal compartment IDs.
  1531. func (config *Config) IsInproxyPersonalPairingMode() bool {
  1532. return len(config.InproxyClientPersonalCompartmentIDs) > 0
  1533. }
  1534. // OnInproxyMustUpgrade is invoked when the in-proxy broker returns the
  1535. // MustUpgrade response. When either running a proxy, or when running a
  1536. // client in personal-pairing mode -- two states that require in-proxy
  1537. // functionality -- onInproxyMustUpgrade initiates a shutdown after emitting
  1538. // the InproxyMustUpgrade notice.
  1539. func (config *Config) OnInproxyMustUpgrade() {
  1540. // TODO: check if LimitTunnelProtocols is set to allow only INPROXY tunnel
  1541. // protocols; this is another case where in-proxy functionality is
  1542. // required.
  1543. if config.InproxyEnableProxy || config.IsInproxyPersonalPairingMode() {
  1544. if atomic.CompareAndSwapInt32(&config.inproxyMustUpgradePosted, 0, 1) {
  1545. NoticeInproxyMustUpgrade()
  1546. }
  1547. config.signalComponentFailure.Load().(func())()
  1548. }
  1549. }
  1550. func (config *Config) makeConfigParameters() map[string]interface{} {
  1551. // Build set of config values to apply to parameters.
  1552. //
  1553. // Note: names of some config fields such as
  1554. // StaggerConnectionWorkersMilliseconds and LimitMeekBufferSizes have
  1555. // changed in the parameters. The existing config fields are retained for
  1556. // backwards compatibility.
  1557. applyParameters := make(map[string]interface{})
  1558. // To support platform clients that configure NetworkLatencyMultiplier, set
  1559. // the NetworkLatencyMultiplierMin/NetworkLatencyMultiplierMax range to the
  1560. // specified value. Also set the older NetworkLatencyMultiplier tactic, since
  1561. // that will be used in the case of replaying with dial parameters persisted
  1562. // by an older client version.
  1563. if config.NetworkLatencyMultiplier > 0.0 {
  1564. applyParameters[parameters.NetworkLatencyMultiplier] = config.NetworkLatencyMultiplier
  1565. applyParameters[parameters.NetworkLatencyMultiplierMin] = config.NetworkLatencyMultiplier
  1566. applyParameters[parameters.NetworkLatencyMultiplierMax] = config.NetworkLatencyMultiplier
  1567. }
  1568. if config.NetworkLatencyMultiplierMin > 0.0 {
  1569. applyParameters[parameters.NetworkLatencyMultiplierMin] = config.NetworkLatencyMultiplierMin
  1570. }
  1571. if config.NetworkLatencyMultiplierMax > 0.0 {
  1572. applyParameters[parameters.NetworkLatencyMultiplierMax] = config.NetworkLatencyMultiplierMax
  1573. }
  1574. if config.NetworkLatencyMultiplierLambda > 0.0 {
  1575. applyParameters[parameters.NetworkLatencyMultiplierLambda] = config.NetworkLatencyMultiplierLambda
  1576. }
  1577. if len(config.LimitTunnelProtocols) > 0 {
  1578. applyParameters[parameters.LimitTunnelProtocols] = protocol.TunnelProtocols(config.LimitTunnelProtocols)
  1579. }
  1580. if len(config.InitialLimitTunnelProtocols) > 0 && config.InitialLimitTunnelProtocolsCandidateCount > 0 {
  1581. applyParameters[parameters.InitialLimitTunnelProtocols] = protocol.TunnelProtocols(config.InitialLimitTunnelProtocols)
  1582. applyParameters[parameters.InitialLimitTunnelProtocolsCandidateCount] = config.InitialLimitTunnelProtocolsCandidateCount
  1583. }
  1584. if len(config.LimitTLSProfiles) > 0 {
  1585. applyParameters[parameters.LimitTLSProfiles] = protocol.TunnelProtocols(config.LimitTLSProfiles)
  1586. }
  1587. if len(config.LimitQUICVersions) > 0 {
  1588. applyParameters[parameters.LimitQUICVersions] = protocol.QUICVersions(config.LimitQUICVersions)
  1589. }
  1590. if config.EstablishTunnelTimeoutSeconds != nil {
  1591. applyParameters[parameters.EstablishTunnelTimeout] = fmt.Sprintf("%ds", *config.EstablishTunnelTimeoutSeconds)
  1592. }
  1593. if config.EstablishTunnelServerAffinityGracePeriodMilliseconds != nil {
  1594. applyParameters[parameters.EstablishTunnelServerAffinityGracePeriod] = fmt.Sprintf("%dms", *config.EstablishTunnelServerAffinityGracePeriodMilliseconds)
  1595. }
  1596. if config.EstablishTunnelPausePeriodSeconds != nil {
  1597. applyParameters[parameters.EstablishTunnelPausePeriod] = fmt.Sprintf("%ds", *config.EstablishTunnelPausePeriodSeconds)
  1598. }
  1599. if config.ConnectionWorkerPoolSize != 0 {
  1600. applyParameters[parameters.ConnectionWorkerPoolSize] = config.ConnectionWorkerPoolSize
  1601. }
  1602. if config.TunnelPoolSize != 0 {
  1603. applyParameters[parameters.TunnelPoolSize] = config.TunnelPoolSize
  1604. }
  1605. if config.StaggerConnectionWorkersMilliseconds > 0 {
  1606. applyParameters[parameters.StaggerConnectionWorkersPeriod] = fmt.Sprintf("%dms", config.StaggerConnectionWorkersMilliseconds)
  1607. }
  1608. if config.LimitIntensiveConnectionWorkers > 0 {
  1609. applyParameters[parameters.LimitIntensiveConnectionWorkers] = config.LimitIntensiveConnectionWorkers
  1610. }
  1611. applyParameters[parameters.MeekLimitBufferSizes] = config.LimitMeekBufferSizes
  1612. applyParameters[parameters.IgnoreHandshakeStatsRegexps] = config.IgnoreHandshakeStatsRegexps
  1613. if config.EstablishTunnelTimeoutSeconds != nil {
  1614. applyParameters[parameters.EstablishTunnelTimeout] = fmt.Sprintf("%ds", *config.EstablishTunnelTimeoutSeconds)
  1615. }
  1616. if config.FetchRemoteServerListRetryPeriodMilliseconds != nil {
  1617. applyParameters[parameters.FetchRemoteServerListRetryPeriod] = fmt.Sprintf("%dms", *config.FetchRemoteServerListRetryPeriodMilliseconds)
  1618. }
  1619. if config.FetchUpgradeRetryPeriodMilliseconds != nil {
  1620. applyParameters[parameters.FetchUpgradeRetryPeriod] = fmt.Sprintf("%dms", *config.FetchUpgradeRetryPeriodMilliseconds)
  1621. }
  1622. if !config.DisableRemoteServerListFetcher {
  1623. if config.RemoteServerListURLs != nil {
  1624. applyParameters[parameters.RemoteServerListSignaturePublicKey] = config.RemoteServerListSignaturePublicKey
  1625. applyParameters[parameters.RemoteServerListURLs] = config.RemoteServerListURLs
  1626. }
  1627. if config.ObfuscatedServerListRootURLs != nil {
  1628. applyParameters[parameters.RemoteServerListSignaturePublicKey] = config.RemoteServerListSignaturePublicKey
  1629. applyParameters[parameters.ObfuscatedServerListRootURLs] = config.ObfuscatedServerListRootURLs
  1630. }
  1631. }
  1632. if config.EnableUpgradeDownload {
  1633. applyParameters[parameters.UpgradeDownloadURLs] = config.UpgradeDownloadURLs
  1634. applyParameters[parameters.UpgradeDownloadClientVersionHeader] = config.UpgradeDownloadClientVersionHeader
  1635. }
  1636. if config.EnableFeedbackUpload {
  1637. applyParameters[parameters.FeedbackUploadURLs] = config.FeedbackUploadURLs
  1638. applyParameters[parameters.FeedbackEncryptionPublicKey] = config.FeedbackEncryptionPublicKey
  1639. }
  1640. applyParameters[parameters.TunnelRateLimits] = config.RateLimits
  1641. if config.TransformHostNameProbability != nil {
  1642. applyParameters[parameters.TransformHostNameProbability] = *config.TransformHostNameProbability
  1643. }
  1644. if config.FragmentorProbability != nil {
  1645. applyParameters[parameters.FragmentorProbability] = *config.FragmentorProbability
  1646. }
  1647. if len(config.FragmentorLimitProtocols) > 0 {
  1648. applyParameters[parameters.FragmentorLimitProtocols] = protocol.TunnelProtocols(config.FragmentorLimitProtocols)
  1649. }
  1650. if config.FragmentorMinTotalBytes != nil {
  1651. applyParameters[parameters.FragmentorMinTotalBytes] = *config.FragmentorMinTotalBytes
  1652. }
  1653. if config.FragmentorMaxTotalBytes != nil {
  1654. applyParameters[parameters.FragmentorMaxTotalBytes] = *config.FragmentorMaxTotalBytes
  1655. }
  1656. if config.FragmentorMinWriteBytes != nil {
  1657. applyParameters[parameters.FragmentorMinWriteBytes] = *config.FragmentorMinWriteBytes
  1658. }
  1659. if config.FragmentorMaxWriteBytes != nil {
  1660. applyParameters[parameters.FragmentorMaxWriteBytes] = *config.FragmentorMaxWriteBytes
  1661. }
  1662. if config.FragmentorMinDelayMicroseconds != nil {
  1663. applyParameters[parameters.FragmentorMinDelay] = fmt.Sprintf("%dus", *config.FragmentorMinDelayMicroseconds)
  1664. }
  1665. if config.FragmentorMaxDelayMicroseconds != nil {
  1666. applyParameters[parameters.FragmentorMaxDelay] = fmt.Sprintf("%dus", *config.FragmentorMaxDelayMicroseconds)
  1667. }
  1668. if config.MeekTrafficShapingProbability != nil {
  1669. applyParameters[parameters.MeekTrafficShapingProbability] = *config.MeekTrafficShapingProbability
  1670. }
  1671. if len(config.MeekTrafficShapingLimitProtocols) > 0 {
  1672. applyParameters[parameters.MeekTrafficShapingLimitProtocols] = protocol.TunnelProtocols(config.MeekTrafficShapingLimitProtocols)
  1673. }
  1674. if config.MeekMinTLSPadding != nil {
  1675. applyParameters[parameters.MeekMinTLSPadding] = *config.MeekMinTLSPadding
  1676. }
  1677. if config.MeekMaxTLSPadding != nil {
  1678. applyParameters[parameters.MeekMaxTLSPadding] = *config.MeekMaxTLSPadding
  1679. }
  1680. if config.MeekMinLimitRequestPayloadLength != nil {
  1681. applyParameters[parameters.MeekMinLimitRequestPayloadLength] = *config.MeekMinLimitRequestPayloadLength
  1682. }
  1683. if config.MeekMaxLimitRequestPayloadLength != nil {
  1684. applyParameters[parameters.MeekMaxLimitRequestPayloadLength] = *config.MeekMaxLimitRequestPayloadLength
  1685. }
  1686. if config.MeekRedialTLSProbability != nil {
  1687. applyParameters[parameters.MeekRedialTLSProbability] = *config.MeekRedialTLSProbability
  1688. }
  1689. if config.MeekAlternateCookieNameProbability != nil {
  1690. applyParameters[parameters.MeekAlternateCookieNameProbability] = *config.MeekAlternateCookieNameProbability
  1691. }
  1692. if config.MeekAlternateContentTypeProbability != nil {
  1693. applyParameters[parameters.MeekAlternateContentTypeProbability] = *config.MeekAlternateContentTypeProbability
  1694. }
  1695. if config.ObfuscatedSSHMinPadding != nil {
  1696. applyParameters[parameters.ObfuscatedSSHMinPadding] = *config.ObfuscatedSSHMinPadding
  1697. }
  1698. if config.ObfuscatedSSHMaxPadding != nil {
  1699. applyParameters[parameters.ObfuscatedSSHMaxPadding] = *config.ObfuscatedSSHMaxPadding
  1700. }
  1701. if config.LivenessTestMinUpstreamBytes != nil {
  1702. applyParameters[parameters.LivenessTestMinUpstreamBytes] = *config.LivenessTestMinUpstreamBytes
  1703. }
  1704. if config.LivenessTestMaxUpstreamBytes != nil {
  1705. applyParameters[parameters.LivenessTestMaxUpstreamBytes] = *config.LivenessTestMaxUpstreamBytes
  1706. }
  1707. if config.LivenessTestMinDownstreamBytes != nil {
  1708. applyParameters[parameters.LivenessTestMinDownstreamBytes] = *config.LivenessTestMinDownstreamBytes
  1709. }
  1710. if config.LivenessTestMaxDownstreamBytes != nil {
  1711. applyParameters[parameters.LivenessTestMaxDownstreamBytes] = *config.LivenessTestMaxDownstreamBytes
  1712. }
  1713. if config.ReplayCandidateCount != nil {
  1714. applyParameters[parameters.ReplayCandidateCount] = *config.ReplayCandidateCount
  1715. }
  1716. if config.ReplayDialParametersTTLSeconds != nil {
  1717. applyParameters[parameters.ReplayDialParametersTTL] = fmt.Sprintf("%ds", *config.ReplayDialParametersTTLSeconds)
  1718. }
  1719. if config.ReplayTargetUpstreamBytes != nil {
  1720. applyParameters[parameters.ReplayTargetUpstreamBytes] = *config.ReplayTargetUpstreamBytes
  1721. }
  1722. if config.ReplayTargetDownstreamBytes != nil {
  1723. applyParameters[parameters.ReplayTargetDownstreamBytes] = *config.ReplayTargetDownstreamBytes
  1724. }
  1725. if config.ReplayTargetTunnelDurationSeconds != nil {
  1726. applyParameters[parameters.ReplayTargetTunnelDuration] = fmt.Sprintf("%ds", *config.ReplayTargetTunnelDurationSeconds)
  1727. }
  1728. if config.ReplayLaterRoundMoveToFrontProbability != nil {
  1729. applyParameters[parameters.ReplayLaterRoundMoveToFrontProbability] = *config.ReplayLaterRoundMoveToFrontProbability
  1730. }
  1731. if config.ReplayRetainFailedProbability != nil {
  1732. applyParameters[parameters.ReplayRetainFailedProbability] = *config.ReplayRetainFailedProbability
  1733. }
  1734. if config.ReplayIgnoreChangedConfigState != nil {
  1735. applyParameters[parameters.ReplayIgnoreChangedConfigState] = *config.ReplayIgnoreChangedConfigState
  1736. }
  1737. if config.UseOnlyCustomTLSProfiles != nil {
  1738. applyParameters[parameters.UseOnlyCustomTLSProfiles] = *config.UseOnlyCustomTLSProfiles
  1739. }
  1740. if len(config.CustomTLSProfiles) > 0 {
  1741. applyParameters[parameters.CustomTLSProfiles] = config.CustomTLSProfiles
  1742. }
  1743. if config.SelectRandomizedTLSProfileProbability != nil {
  1744. applyParameters[parameters.SelectRandomizedTLSProfileProbability] = *config.SelectRandomizedTLSProfileProbability
  1745. }
  1746. if config.NoDefaultTLSSessionIDProbability != nil {
  1747. applyParameters[parameters.NoDefaultTLSSessionIDProbability] = *config.NoDefaultTLSSessionIDProbability
  1748. }
  1749. if len(config.DisableFrontingProviderTLSProfiles) > 0 {
  1750. applyParameters[parameters.DisableFrontingProviderTLSProfiles] = config.DisableFrontingProviderTLSProfiles
  1751. }
  1752. if config.ClientBurstUpstreamTargetBytes != nil {
  1753. applyParameters[parameters.ClientBurstUpstreamTargetBytes] = *config.ClientBurstUpstreamTargetBytes
  1754. }
  1755. if config.ClientBurstUpstreamDeadlineMilliseconds != nil {
  1756. applyParameters[parameters.ClientBurstUpstreamDeadline] = fmt.Sprintf("%dms", *config.ClientBurstUpstreamDeadlineMilliseconds)
  1757. }
  1758. if config.ClientBurstDownstreamTargetBytes != nil {
  1759. applyParameters[parameters.ClientBurstDownstreamTargetBytes] = *config.ClientBurstDownstreamTargetBytes
  1760. }
  1761. if config.ClientBurstDownstreamDeadlineMilliseconds != nil {
  1762. applyParameters[parameters.ClientBurstDownstreamDeadline] = fmt.Sprintf("%dms", *config.ClientBurstDownstreamDeadlineMilliseconds)
  1763. }
  1764. if config.ApplicationParameters != nil {
  1765. applyParameters[parameters.ApplicationParameters] = config.ApplicationParameters
  1766. }
  1767. if config.CustomHostNameRegexes != nil {
  1768. applyParameters[parameters.CustomHostNameRegexes] = parameters.RegexStrings(config.CustomHostNameRegexes)
  1769. }
  1770. if config.CustomHostNameProbability != nil {
  1771. applyParameters[parameters.CustomHostNameProbability] = *config.CustomHostNameProbability
  1772. }
  1773. if config.CustomHostNameLimitProtocols != nil {
  1774. applyParameters[parameters.CustomHostNameLimitProtocols] = protocol.TunnelProtocols(config.CustomHostNameLimitProtocols)
  1775. }
  1776. if config.ConjureCachedRegistrationTTLSeconds != nil {
  1777. applyParameters[parameters.ConjureCachedRegistrationTTL] = fmt.Sprintf("%ds", *config.ConjureCachedRegistrationTTLSeconds)
  1778. }
  1779. if config.ConjureAPIRegistrarBidirectionalURL != "" {
  1780. applyParameters[parameters.ConjureAPIRegistrarBidirectionalURL] = config.ConjureAPIRegistrarBidirectionalURL
  1781. }
  1782. if len(config.ConjureAPIRegistrarFrontingSpecs) > 0 {
  1783. applyParameters[parameters.ConjureAPIRegistrarFrontingSpecs] = config.ConjureAPIRegistrarFrontingSpecs
  1784. }
  1785. if config.ConjureAPIRegistrarMinDelayMilliseconds != nil {
  1786. applyParameters[parameters.ConjureAPIRegistrarMinDelay] = fmt.Sprintf("%dms", *config.ConjureAPIRegistrarMinDelayMilliseconds)
  1787. }
  1788. if config.ConjureAPIRegistrarMaxDelayMilliseconds != nil {
  1789. applyParameters[parameters.ConjureAPIRegistrarMaxDelay] = fmt.Sprintf("%dms", *config.ConjureAPIRegistrarMaxDelayMilliseconds)
  1790. }
  1791. if config.ConjureDecoyRegistrarProbability != nil {
  1792. applyParameters[parameters.ConjureDecoyRegistrarProbability] = *config.ConjureDecoyRegistrarProbability
  1793. }
  1794. if config.ConjureDecoyRegistrarWidth != nil {
  1795. applyParameters[parameters.ConjureDecoyRegistrarWidth] = *config.ConjureDecoyRegistrarWidth
  1796. }
  1797. if config.ConjureDecoyRegistrarMinDelayMilliseconds != nil {
  1798. applyParameters[parameters.ConjureDecoyRegistrarMinDelay] = fmt.Sprintf("%dms", *config.ConjureDecoyRegistrarMinDelayMilliseconds)
  1799. }
  1800. if config.ConjureDecoyRegistrarMaxDelayMilliseconds != nil {
  1801. applyParameters[parameters.ConjureDecoyRegistrarMaxDelay] = fmt.Sprintf("%dms", *config.ConjureDecoyRegistrarMaxDelayMilliseconds)
  1802. }
  1803. if config.ConjureEnableIPv6Dials != nil {
  1804. applyParameters[parameters.ConjureEnableIPv6Dials] = *config.ConjureEnableIPv6Dials
  1805. }
  1806. if config.ConjureEnablePortRandomization != nil {
  1807. applyParameters[parameters.ConjureEnablePortRandomization] = *config.ConjureEnablePortRandomization
  1808. }
  1809. if config.ConjureEnableRegistrationOverrides != nil {
  1810. applyParameters[parameters.ConjureEnableRegistrationOverrides] = *config.ConjureEnableRegistrationOverrides
  1811. }
  1812. if config.ConjureLimitTransports != nil {
  1813. applyParameters[parameters.ConjureLimitTransports] = config.ConjureLimitTransports
  1814. }
  1815. if config.ConjureSTUNServerAddresses != nil {
  1816. applyParameters[parameters.ConjureSTUNServerAddresses] = config.ConjureSTUNServerAddresses
  1817. }
  1818. if config.ConjureDTLSEmptyInitialPacketProbability != nil {
  1819. applyParameters[parameters.ConjureDTLSEmptyInitialPacketProbability] = *config.ConjureDTLSEmptyInitialPacketProbability
  1820. }
  1821. if config.HoldOffTunnelMinDurationMilliseconds != nil {
  1822. applyParameters[parameters.HoldOffTunnelMinDuration] = fmt.Sprintf("%dms", *config.HoldOffTunnelMinDurationMilliseconds)
  1823. }
  1824. if config.HoldOffTunnelMaxDurationMilliseconds != nil {
  1825. applyParameters[parameters.HoldOffTunnelMaxDuration] = fmt.Sprintf("%dms", *config.HoldOffTunnelMaxDurationMilliseconds)
  1826. }
  1827. if len(config.HoldOffTunnelProtocols) > 0 {
  1828. applyParameters[parameters.HoldOffTunnelProtocols] = protocol.TunnelProtocols(config.HoldOffTunnelProtocols)
  1829. }
  1830. if len(config.HoldOffTunnelFrontingProviderIDs) > 0 {
  1831. applyParameters[parameters.HoldOffTunnelFrontingProviderIDs] = config.HoldOffTunnelFrontingProviderIDs
  1832. }
  1833. if config.HoldOffTunnelProbability != nil {
  1834. applyParameters[parameters.HoldOffTunnelProbability] = *config.HoldOffTunnelProbability
  1835. }
  1836. if config.HoldOffDirectTunnelMinDurationMilliseconds != nil {
  1837. applyParameters[parameters.HoldOffDirectTunnelMinDuration] = fmt.Sprintf("%dms", *config.HoldOffDirectTunnelMinDurationMilliseconds)
  1838. }
  1839. if config.HoldOffDirectTunnelMaxDurationMilliseconds != nil {
  1840. applyParameters[parameters.HoldOffDirectTunnelMaxDuration] = fmt.Sprintf("%dms", *config.HoldOffDirectTunnelMaxDurationMilliseconds)
  1841. }
  1842. if len(config.HoldOffDirectTunnelProviderRegions) > 0 {
  1843. applyParameters[parameters.HoldOffDirectTunnelProviderRegions] = parameters.KeyStrings(config.HoldOffDirectTunnelProviderRegions)
  1844. }
  1845. if config.HoldOffDirectTunnelProbability != nil {
  1846. applyParameters[parameters.HoldOffDirectTunnelProbability] = *config.HoldOffDirectTunnelProbability
  1847. }
  1848. if len(config.RestrictDirectProviderRegions) > 0 {
  1849. applyParameters[parameters.RestrictDirectProviderRegions] = parameters.KeyStrings(config.RestrictDirectProviderRegions)
  1850. }
  1851. if config.RestrictDirectProviderIDsClientProbability != nil {
  1852. applyParameters[parameters.RestrictDirectProviderIDsClientProbability] = *config.RestrictDirectProviderIDsClientProbability
  1853. }
  1854. if len(config.RestrictFrontingProviderIDs) > 0 {
  1855. applyParameters[parameters.RestrictFrontingProviderIDs] = config.RestrictFrontingProviderIDs
  1856. }
  1857. if config.RestrictFrontingProviderIDsClientProbability != nil {
  1858. applyParameters[parameters.RestrictFrontingProviderIDsClientProbability] = *config.RestrictFrontingProviderIDsClientProbability
  1859. }
  1860. if config.UpstreamProxyAllowAllServerEntrySources != nil {
  1861. applyParameters[parameters.UpstreamProxyAllowAllServerEntrySources] = *config.UpstreamProxyAllowAllServerEntrySources
  1862. }
  1863. if len(config.LimitTunnelDialPortNumbers) > 0 {
  1864. applyParameters[parameters.LimitTunnelDialPortNumbers] = config.LimitTunnelDialPortNumbers
  1865. }
  1866. if config.QUICDisablePathMTUDiscoveryProbability != nil {
  1867. applyParameters[parameters.QUICDisableClientPathMTUDiscoveryProbability] = *config.QUICDisablePathMTUDiscoveryProbability
  1868. }
  1869. if config.DNSResolverAttemptsPerServer != nil {
  1870. applyParameters[parameters.DNSResolverAttemptsPerServer] = *config.DNSResolverAttemptsPerServer
  1871. }
  1872. if config.DNSResolverAttemptsPerPreferredServer != nil {
  1873. applyParameters[parameters.DNSResolverAttemptsPerPreferredServer] = *config.DNSResolverAttemptsPerPreferredServer
  1874. }
  1875. if config.DNSResolverRequestTimeoutMilliseconds != nil {
  1876. applyParameters[parameters.DNSResolverRequestTimeout] = fmt.Sprintf("%dms", *config.DNSResolverRequestTimeoutMilliseconds)
  1877. }
  1878. if config.DNSResolverAwaitTimeoutMilliseconds != nil {
  1879. applyParameters[parameters.DNSResolverAwaitTimeout] = fmt.Sprintf("%dms", *config.DNSResolverAwaitTimeoutMilliseconds)
  1880. }
  1881. if config.DNSResolverPreresolvedIPAddressProbability != nil {
  1882. applyParameters[parameters.DNSResolverPreresolvedIPAddressProbability] = *config.DNSResolverPreresolvedIPAddressProbability
  1883. }
  1884. if config.DNSResolverPreresolvedIPAddressCIDRs != nil {
  1885. applyParameters[parameters.DNSResolverPreresolvedIPAddressCIDRs] = config.DNSResolverPreresolvedIPAddressCIDRs
  1886. }
  1887. if config.DNSResolverAlternateServers != nil {
  1888. applyParameters[parameters.DNSResolverAlternateServers] = config.DNSResolverAlternateServers
  1889. }
  1890. if config.DNSResolverPreferredAlternateServers != nil {
  1891. applyParameters[parameters.DNSResolverPreferredAlternateServers] = config.DNSResolverPreferredAlternateServers
  1892. }
  1893. if config.DNSResolverPreferAlternateServerProbability != nil {
  1894. applyParameters[parameters.DNSResolverPreferAlternateServerProbability] = *config.DNSResolverPreferAlternateServerProbability
  1895. }
  1896. if config.DNSResolverProtocolTransformSpecs != nil {
  1897. applyParameters[parameters.DNSResolverProtocolTransformSpecs] = config.DNSResolverProtocolTransformSpecs
  1898. }
  1899. if config.DNSResolverProtocolTransformScopedSpecNames != nil {
  1900. applyParameters[parameters.DNSResolverProtocolTransformScopedSpecNames] = config.DNSResolverProtocolTransformScopedSpecNames
  1901. }
  1902. if config.DNSResolverProtocolTransformProbability != nil {
  1903. applyParameters[parameters.DNSResolverProtocolTransformProbability] = *config.DNSResolverProtocolTransformProbability
  1904. }
  1905. if config.DNSResolverIncludeEDNS0Probability != nil {
  1906. applyParameters[parameters.DNSResolverIncludeEDNS0Probability] = *config.DNSResolverIncludeEDNS0Probability
  1907. }
  1908. if config.DNSResolverCacheExtensionInitialTTLMilliseconds != nil {
  1909. applyParameters[parameters.DNSResolverCacheExtensionInitialTTL] = fmt.Sprintf("%dms", *config.DNSResolverCacheExtensionInitialTTLMilliseconds)
  1910. }
  1911. if config.DNSResolverCacheExtensionVerifiedTTLMilliseconds != nil {
  1912. applyParameters[parameters.DNSResolverCacheExtensionVerifiedTTL] = fmt.Sprintf("%dms", *config.DNSResolverCacheExtensionVerifiedTTLMilliseconds)
  1913. }
  1914. if config.DirectHTTPProtocolTransformSpecs != nil {
  1915. applyParameters[parameters.DirectHTTPProtocolTransformSpecs] = config.DirectHTTPProtocolTransformSpecs
  1916. }
  1917. if config.DirectHTTPProtocolTransformScopedSpecNames != nil {
  1918. applyParameters[parameters.DirectHTTPProtocolTransformScopedSpecNames] = config.DirectHTTPProtocolTransformScopedSpecNames
  1919. }
  1920. if config.DirectHTTPProtocolTransformProbability != nil {
  1921. applyParameters[parameters.DirectHTTPProtocolTransformProbability] = *config.DirectHTTPProtocolTransformProbability
  1922. }
  1923. if config.FrontedHTTPProtocolTransformSpecs != nil {
  1924. applyParameters[parameters.FrontedHTTPProtocolTransformSpecs] = config.FrontedHTTPProtocolTransformSpecs
  1925. }
  1926. if config.FrontedHTTPProtocolTransformScopedSpecNames != nil {
  1927. applyParameters[parameters.FrontedHTTPProtocolTransformScopedSpecNames] = config.FrontedHTTPProtocolTransformScopedSpecNames
  1928. }
  1929. if config.FrontedHTTPProtocolTransformProbability != nil {
  1930. applyParameters[parameters.FrontedHTTPProtocolTransformProbability] = *config.FrontedHTTPProtocolTransformProbability
  1931. }
  1932. if config.OSSHObfuscatorSeedTransformSpecs != nil {
  1933. applyParameters[parameters.OSSHObfuscatorSeedTransformSpecs] = config.OSSHObfuscatorSeedTransformSpecs
  1934. }
  1935. if config.OSSHObfuscatorSeedTransformScopedSpecNames != nil {
  1936. applyParameters[parameters.OSSHObfuscatorSeedTransformScopedSpecNames] = config.OSSHObfuscatorSeedTransformScopedSpecNames
  1937. }
  1938. if config.OSSHObfuscatorSeedTransformProbability != nil {
  1939. applyParameters[parameters.OSSHObfuscatorSeedTransformProbability] = *config.OSSHObfuscatorSeedTransformProbability
  1940. }
  1941. if config.ObfuscatedQUICNonceTransformSpecs != nil {
  1942. applyParameters[parameters.ObfuscatedQUICNonceTransformSpecs] = config.ObfuscatedQUICNonceTransformSpecs
  1943. }
  1944. if config.ObfuscatedQUICNonceTransformScopedSpecNames != nil {
  1945. applyParameters[parameters.ObfuscatedQUICNonceTransformScopedSpecNames] = config.ObfuscatedQUICNonceTransformScopedSpecNames
  1946. }
  1947. if config.ObfuscatedQUICNonceTransformProbability != nil {
  1948. applyParameters[parameters.ObfuscatedQUICNonceTransformProbability] = *config.ObfuscatedQUICNonceTransformProbability
  1949. }
  1950. if config.OSSHPrefixSpecs != nil {
  1951. applyParameters[parameters.OSSHPrefixSpecs] = config.OSSHPrefixSpecs
  1952. }
  1953. if config.OSSHPrefixScopedSpecNames != nil {
  1954. applyParameters[parameters.OSSHPrefixScopedSpecNames] = config.OSSHPrefixScopedSpecNames
  1955. }
  1956. if config.OSSHPrefixProbability != nil {
  1957. applyParameters[parameters.OSSHPrefixProbability] = *config.OSSHPrefixProbability
  1958. }
  1959. if config.OSSHPrefixSplitMinDelayMilliseconds != nil {
  1960. applyParameters[parameters.OSSHPrefixSplitMinDelay] = fmt.Sprintf("%dms", *config.OSSHPrefixSplitMinDelayMilliseconds)
  1961. }
  1962. if config.OSSHPrefixSplitMaxDelayMilliseconds != nil {
  1963. applyParameters[parameters.OSSHPrefixSplitMaxDelay] = fmt.Sprintf("%dms", *config.OSSHPrefixSplitMaxDelayMilliseconds)
  1964. }
  1965. if config.OSSHPrefixEnableFragmentor != nil {
  1966. applyParameters[parameters.OSSHPrefixEnableFragmentor] = *config.OSSHPrefixEnableFragmentor
  1967. }
  1968. if config.TLSTunnelTrafficShapingProbability != nil {
  1969. applyParameters[parameters.TLSTunnelTrafficShapingProbability] = *config.TLSTunnelTrafficShapingProbability
  1970. }
  1971. if config.TLSTunnelMinTLSPadding != nil {
  1972. applyParameters[parameters.TLSTunnelMinTLSPadding] = *config.TLSTunnelMinTLSPadding
  1973. }
  1974. if config.TLSTunnelMaxTLSPadding != nil {
  1975. applyParameters[parameters.TLSTunnelMaxTLSPadding] = *config.TLSTunnelMaxTLSPadding
  1976. }
  1977. if config.TLSFragmentClientHelloProbability != nil {
  1978. applyParameters[parameters.TLSFragmentClientHelloProbability] = *config.TLSFragmentClientHelloProbability
  1979. }
  1980. if len(config.TLSFragmentClientHelloLimitProtocols) > 0 {
  1981. applyParameters[parameters.TLSFragmentClientHelloLimitProtocols] = protocol.TunnelProtocols(config.TLSFragmentClientHelloLimitProtocols)
  1982. }
  1983. if config.SteeringIPCacheTTLSeconds != nil {
  1984. applyParameters[parameters.SteeringIPCacheTTL] = fmt.Sprintf("%ds", *config.SteeringIPCacheTTLSeconds)
  1985. }
  1986. if config.SteeringIPCacheMaxEntries != nil {
  1987. applyParameters[parameters.SteeringIPCacheMaxEntries] = *config.SteeringIPCacheMaxEntries
  1988. }
  1989. if config.SteeringIPProbability != nil {
  1990. applyParameters[parameters.SteeringIPProbability] = *config.SteeringIPProbability
  1991. }
  1992. if config.InproxyPersonalPairingConnectionWorkerPoolSize != 0 {
  1993. applyParameters[parameters.InproxyPersonalPairingConnectionWorkerPoolSize] = config.InproxyPersonalPairingConnectionWorkerPoolSize
  1994. }
  1995. if config.InproxyAllowProxy != nil {
  1996. applyParameters[parameters.InproxyAllowProxy] = *config.InproxyAllowProxy
  1997. }
  1998. if config.InproxyAllowClient != nil {
  1999. applyParameters[parameters.InproxyAllowClient] = *config.InproxyAllowClient
  2000. }
  2001. if config.InproxyTunnelProtocolSelectionProbability != nil {
  2002. applyParameters[parameters.InproxyTunnelProtocolSelectionProbability] = *config.InproxyTunnelProtocolSelectionProbability
  2003. }
  2004. if len(config.InproxyBrokerSpecs) > 0 {
  2005. applyParameters[parameters.InproxyBrokerSpecs] = config.InproxyBrokerSpecs
  2006. }
  2007. if len(config.InproxyPersonalPairingBrokerSpecs) > 0 {
  2008. applyParameters[parameters.InproxyPersonalPairingBrokerSpecs] = config.InproxyPersonalPairingBrokerSpecs
  2009. }
  2010. if len(config.InproxyProxyBrokerSpecs) > 0 {
  2011. applyParameters[parameters.InproxyProxyBrokerSpecs] = config.InproxyProxyBrokerSpecs
  2012. }
  2013. if len(config.InproxyProxyPersonalPairingBrokerSpecs) > 0 {
  2014. applyParameters[parameters.InproxyProxyPersonalPairingBrokerSpecs] = config.InproxyProxyPersonalPairingBrokerSpecs
  2015. }
  2016. if len(config.InproxyClientBrokerSpecs) > 0 {
  2017. applyParameters[parameters.InproxyClientBrokerSpecs] = config.InproxyClientBrokerSpecs
  2018. }
  2019. if len(config.InproxyClientPersonalPairingBrokerSpecs) > 0 {
  2020. applyParameters[parameters.InproxyClientPersonalPairingBrokerSpecs] = config.InproxyClientPersonalPairingBrokerSpecs
  2021. }
  2022. if config.InproxyReplayBrokerDialParametersTTLSeconds != nil {
  2023. applyParameters[parameters.InproxyReplayBrokerDialParametersTTL] = fmt.Sprintf("%ds", *config.InproxyReplayBrokerDialParametersTTLSeconds)
  2024. }
  2025. if config.InproxyReplayBrokerUpdateFrequencySeconds != nil {
  2026. applyParameters[parameters.InproxyReplayBrokerUpdateFrequency] = fmt.Sprintf("%ds", *config.InproxyReplayBrokerUpdateFrequencySeconds)
  2027. }
  2028. if config.InproxyReplayBrokerDialParametersProbability != nil {
  2029. applyParameters[parameters.InproxyReplayBrokerDialParametersProbability] = *config.InproxyReplayBrokerDialParametersProbability
  2030. }
  2031. if config.InproxyReplayBrokerRetainFailedProbability != nil {
  2032. applyParameters[parameters.InproxyReplayBrokerRetainFailedProbability] = *config.InproxyReplayBrokerRetainFailedProbability
  2033. }
  2034. if len(config.InproxyCommonCompartmentIDs) > 0 {
  2035. applyParameters[parameters.InproxyCommonCompartmentIDs] = config.InproxyCommonCompartmentIDs
  2036. }
  2037. if config.InproxyMaxCompartmentIDListLength != nil {
  2038. applyParameters[parameters.InproxyMaxCompartmentIDListLength] = *config.InproxyMaxCompartmentIDListLength
  2039. }
  2040. if config.InproxyProxyAnnounceRequestTimeoutMilliseconds != nil {
  2041. applyParameters[parameters.InproxyProxyAnnounceRequestTimeout] = fmt.Sprintf("%dms", *config.InproxyProxyAnnounceRequestTimeoutMilliseconds)
  2042. }
  2043. if config.InproxyProxyAnnounceDelayMilliseconds != nil {
  2044. applyParameters[parameters.InproxyProxyAnnounceDelay] = fmt.Sprintf("%dms", *config.InproxyProxyAnnounceDelayMilliseconds)
  2045. }
  2046. if config.InproxyProxyAnnounceDelayJitter != nil {
  2047. applyParameters[parameters.InproxyProxyAnnounceDelayJitter] = *config.InproxyProxyAnnounceDelayJitter
  2048. }
  2049. if config.InproxyProxyAnswerRequestTimeoutMilliseconds != nil {
  2050. applyParameters[parameters.InproxyProxyAnswerRequestTimeout] = fmt.Sprintf("%dms", *config.InproxyProxyAnswerRequestTimeoutMilliseconds)
  2051. }
  2052. if config.InproxyClientOfferRequestTimeoutMilliseconds != nil {
  2053. applyParameters[parameters.InproxyClientOfferRequestTimeout] = fmt.Sprintf("%dms", *config.InproxyClientOfferRequestTimeoutMilliseconds)
  2054. }
  2055. if config.InproxyClientOfferRetryDelayMilliseconds != nil {
  2056. applyParameters[parameters.InproxyClientOfferRetryDelay] = fmt.Sprintf("%dms", *config.InproxyClientOfferRetryDelayMilliseconds)
  2057. }
  2058. if config.InproxyClientOfferRetryJitter != nil {
  2059. applyParameters[parameters.InproxyClientOfferRetryJitter] = *config.InproxyClientOfferRetryJitter
  2060. }
  2061. if config.InproxyClientRelayedPacketRequestTimeoutMilliseconds != nil {
  2062. applyParameters[parameters.InproxyClientRelayedPacketRequestTimeout] = fmt.Sprintf("%dms", *config.InproxyClientRelayedPacketRequestTimeoutMilliseconds)
  2063. }
  2064. if config.InproxyDTLSRandomizationProbability != nil {
  2065. applyParameters[parameters.InproxyDTLSRandomizationProbability] = *config.InproxyDTLSRandomizationProbability
  2066. }
  2067. if config.InproxyDataChannelTrafficShapingProbability != nil {
  2068. applyParameters[parameters.InproxyDataChannelTrafficShapingProbability] = *config.InproxyDataChannelTrafficShapingProbability
  2069. }
  2070. if config.InproxyDataChannelTrafficShapingParameters != nil {
  2071. applyParameters[parameters.InproxyDataChannelTrafficShapingParameters] = *config.InproxyDataChannelTrafficShapingParameters
  2072. }
  2073. if len(config.InproxySTUNServerAddresses) > 0 {
  2074. applyParameters[parameters.InproxySTUNServerAddresses] = config.InproxySTUNServerAddresses
  2075. }
  2076. if len(config.InproxySTUNServerAddressesRFC5780) > 0 {
  2077. applyParameters[parameters.InproxySTUNServerAddressesRFC5780] = config.InproxySTUNServerAddressesRFC5780
  2078. }
  2079. if len(config.InproxyProxySTUNServerAddresses) > 0 {
  2080. applyParameters[parameters.InproxyProxySTUNServerAddresses] = config.InproxyProxySTUNServerAddresses
  2081. }
  2082. if len(config.InproxyProxySTUNServerAddressesRFC5780) > 0 {
  2083. applyParameters[parameters.InproxyProxySTUNServerAddressesRFC5780] = config.InproxyProxySTUNServerAddressesRFC5780
  2084. }
  2085. if len(config.InproxyClientSTUNServerAddresses) > 0 {
  2086. applyParameters[parameters.InproxyClientSTUNServerAddresses] = config.InproxyClientSTUNServerAddresses
  2087. }
  2088. if len(config.InproxyClientSTUNServerAddressesRFC5780) > 0 {
  2089. applyParameters[parameters.InproxyClientSTUNServerAddressesRFC5780] = config.InproxyClientSTUNServerAddressesRFC5780
  2090. }
  2091. if config.InproxyClientDiscoverNATProbability != nil {
  2092. applyParameters[parameters.InproxyClientDiscoverNATProbability] = *config.InproxyClientDiscoverNATProbability
  2093. }
  2094. if config.InproxyDisableSTUN != nil {
  2095. applyParameters[parameters.InproxyDisableSTUN] = *config.InproxyDisableSTUN
  2096. }
  2097. if config.InproxyDisablePortMapping != nil {
  2098. applyParameters[parameters.InproxyDisablePortMapping] = *config.InproxyDisablePortMapping
  2099. }
  2100. if config.InproxyDisableInboundForMobileNetworks != nil {
  2101. applyParameters[parameters.InproxyDisableInboundForMobileNetworks] = *config.InproxyDisableInboundForMobileNetworks
  2102. }
  2103. if config.InproxyDisableIPv6ICECandidates != nil {
  2104. applyParameters[parameters.InproxyDisableIPv6ICECandidates] = *config.InproxyDisableIPv6ICECandidates
  2105. }
  2106. if config.InproxyProxyDisableSTUN != nil {
  2107. applyParameters[parameters.InproxyProxyDisableSTUN] = *config.InproxyProxyDisableSTUN
  2108. }
  2109. if config.InproxyProxyDisablePortMapping != nil {
  2110. applyParameters[parameters.InproxyProxyDisablePortMapping] = *config.InproxyProxyDisablePortMapping
  2111. }
  2112. if config.InproxyProxyDisableInboundForMobileNetworks != nil {
  2113. applyParameters[parameters.InproxyProxyDisableInboundForMobileNetworks] = *config.InproxyProxyDisableInboundForMobileNetworks
  2114. }
  2115. if config.InproxyProxyDisableIPv6ICECandidates != nil {
  2116. applyParameters[parameters.InproxyProxyDisableIPv6ICECandidates] = *config.InproxyProxyDisableIPv6ICECandidates
  2117. }
  2118. if config.InproxyClientDisableSTUN != nil {
  2119. applyParameters[parameters.InproxyClientDisableSTUN] = *config.InproxyClientDisableSTUN
  2120. }
  2121. if config.InproxyClientDisablePortMapping != nil {
  2122. applyParameters[parameters.InproxyClientDisablePortMapping] = *config.InproxyClientDisablePortMapping
  2123. }
  2124. if config.InproxyClientDisableInboundForMobileNetworks != nil {
  2125. applyParameters[parameters.InproxyClientDisableInboundForMobileNetworks] = *config.InproxyClientDisableInboundForMobileNetworks
  2126. }
  2127. if config.InproxyClientDisableIPv6ICECandidates != nil {
  2128. applyParameters[parameters.InproxyClientDisableIPv6ICECandidates] = *config.InproxyClientDisableIPv6ICECandidates
  2129. }
  2130. if config.InproxyProxyDiscoverNATTimeoutMilliseconds != nil {
  2131. applyParameters[parameters.InproxyProxyDiscoverNATTimeout] = fmt.Sprintf("%dms", *config.InproxyProxyDiscoverNATTimeoutMilliseconds)
  2132. }
  2133. if config.InproxyClientDiscoverNATTimeoutMilliseconds != nil {
  2134. applyParameters[parameters.InproxyClientDiscoverNATTimeout] = fmt.Sprintf("%dms", *config.InproxyClientDiscoverNATTimeoutMilliseconds)
  2135. }
  2136. if config.InproxyWebRTCAnswerTimeoutMilliseconds != nil {
  2137. applyParameters[parameters.InproxyWebRTCAnswerTimeout] = fmt.Sprintf("%dms", *config.InproxyWebRTCAnswerTimeoutMilliseconds)
  2138. }
  2139. if config.InproxyProxyWebRTCAwaitDataChannelTimeoutMilliseconds != nil {
  2140. applyParameters[parameters.InproxyProxyWebRTCAwaitDataChannelTimeout] = fmt.Sprintf("%dms", *config.InproxyProxyWebRTCAwaitDataChannelTimeoutMilliseconds)
  2141. }
  2142. if config.InproxyClientWebRTCAwaitDataChannelTimeoutMilliseconds != nil {
  2143. applyParameters[parameters.InproxyClientWebRTCAwaitDataChannelTimeout] = fmt.Sprintf("%dms", *config.InproxyClientWebRTCAwaitDataChannelTimeoutMilliseconds)
  2144. }
  2145. if config.InproxyProxyDestinationDialTimeoutMilliseconds != nil {
  2146. applyParameters[parameters.InproxyProxyDestinationDialTimeout] = fmt.Sprintf("%dms", *config.InproxyProxyDestinationDialTimeoutMilliseconds)
  2147. }
  2148. if config.InproxyPsiphonAPIRequestTimeoutMilliseconds != nil {
  2149. applyParameters[parameters.InproxyPsiphonAPIRequestTimeout] = fmt.Sprintf("%dms", *config.InproxyPsiphonAPIRequestTimeoutMilliseconds)
  2150. }
  2151. if config.InproxyProxyTotalActivityNoticePeriodMilliseconds != nil {
  2152. applyParameters[parameters.InproxyProxyTotalActivityNoticePeriod] = fmt.Sprintf("%dms", *config.InproxyProxyTotalActivityNoticePeriodMilliseconds)
  2153. }
  2154. if config.InproxyClientDialRateLimitQuantity != nil {
  2155. applyParameters[parameters.InproxyClientDialRateLimitQuantity] = *config.InproxyClientDialRateLimitQuantity
  2156. }
  2157. if config.InproxyClientDialRateLimitIntervalMilliseconds != nil {
  2158. applyParameters[parameters.InproxyClientDialRateLimitInterval] = fmt.Sprintf("%dms", *config.InproxyClientDialRateLimitIntervalMilliseconds)
  2159. }
  2160. // When adding new config dial parameters that may override tactics, also
  2161. // update setDialParametersHash.
  2162. return applyParameters
  2163. }
  2164. func (config *Config) setDialParametersHash() {
  2165. // Calculate and store a hash of the config values that may impact
  2166. // dial parameters. This hash is used as part of the dial parameters
  2167. // replay mechanism to detect when persisted dial parameters should
  2168. // be discarded due to conflicting config changes.
  2169. //
  2170. // With a couple of minor exceptions, configuring dial parameters via the
  2171. // config is intended for testing only, and so these parameters are expected
  2172. // to be present in test runs only. It remains an important case to discard
  2173. // replay dial parameters when test config parameters are varied.
  2174. //
  2175. // Hashing the parameter names detects some ambiguous hash cases, such as two
  2176. // consecutive int64 parameters, one omitted and one not, that are flipped.
  2177. // The serialization is not completely unambiguous, and the format is
  2178. // currently limited by legacy cases (not invalidating replay dial parameters
  2179. // for production clients is more important than invalidating for test runs).
  2180. // We cannot hash the entire config JSON as it contains non-dial parameter
  2181. // fields which may frequently change across runs.
  2182. //
  2183. // MD5 hash is used solely as a data checksum and not for any security
  2184. // purpose.
  2185. hash := md5.New()
  2186. if len(config.LimitTunnelProtocols) > 0 {
  2187. hash.Write([]byte("LimitTunnelProtocols"))
  2188. for _, protocol := range config.LimitTunnelProtocols {
  2189. hash.Write([]byte(protocol))
  2190. }
  2191. }
  2192. if len(config.InitialLimitTunnelProtocols) > 0 && config.InitialLimitTunnelProtocolsCandidateCount > 0 {
  2193. hash.Write([]byte("InitialLimitTunnelProtocols"))
  2194. for _, protocol := range config.InitialLimitTunnelProtocols {
  2195. hash.Write([]byte(protocol))
  2196. }
  2197. binary.Write(hash, binary.LittleEndian, int64(config.InitialLimitTunnelProtocolsCandidateCount))
  2198. }
  2199. if len(config.LimitTLSProfiles) > 0 {
  2200. hash.Write([]byte("LimitTLSProfiles"))
  2201. for _, profile := range config.LimitTLSProfiles {
  2202. hash.Write([]byte(profile))
  2203. }
  2204. }
  2205. if len(config.LimitQUICVersions) > 0 {
  2206. hash.Write([]byte("LimitQUICVersions"))
  2207. for _, version := range config.LimitQUICVersions {
  2208. hash.Write([]byte(version))
  2209. }
  2210. }
  2211. // Whether a custom User-Agent is specified is a binary flag: when not set,
  2212. // the replay dial parameters value applies. When set, external
  2213. // considerations apply.
  2214. if _, ok := config.CustomHeaders["User-Agent"]; ok {
  2215. hash.Write([]byte("CustomHeaders User-Agent"))
  2216. hash.Write([]byte{1})
  2217. }
  2218. if config.UpstreamProxyURL != "" {
  2219. hash.Write([]byte("UpstreamProxyURL"))
  2220. hash.Write([]byte(config.UpstreamProxyURL))
  2221. }
  2222. if config.TransformHostNameProbability != nil {
  2223. hash.Write([]byte("TransformHostNameProbability"))
  2224. binary.Write(hash, binary.LittleEndian, *config.TransformHostNameProbability)
  2225. }
  2226. if config.FragmentorProbability != nil {
  2227. hash.Write([]byte("FragmentorProbability"))
  2228. binary.Write(hash, binary.LittleEndian, *config.FragmentorProbability)
  2229. }
  2230. if len(config.FragmentorLimitProtocols) > 0 {
  2231. hash.Write([]byte("FragmentorLimitProtocols"))
  2232. for _, protocol := range config.FragmentorLimitProtocols {
  2233. hash.Write([]byte(protocol))
  2234. }
  2235. }
  2236. if config.FragmentorMinTotalBytes != nil {
  2237. hash.Write([]byte("FragmentorMinTotalBytes"))
  2238. binary.Write(hash, binary.LittleEndian, int64(*config.FragmentorMinTotalBytes))
  2239. }
  2240. if config.FragmentorMaxTotalBytes != nil {
  2241. hash.Write([]byte("FragmentorMaxTotalBytes"))
  2242. binary.Write(hash, binary.LittleEndian, int64(*config.FragmentorMaxTotalBytes))
  2243. }
  2244. if config.FragmentorMinWriteBytes != nil {
  2245. hash.Write([]byte("FragmentorMinWriteBytes"))
  2246. binary.Write(hash, binary.LittleEndian, int64(*config.FragmentorMinWriteBytes))
  2247. }
  2248. if config.FragmentorMaxWriteBytes != nil {
  2249. hash.Write([]byte("FragmentorMaxWriteBytes"))
  2250. binary.Write(hash, binary.LittleEndian, int64(*config.FragmentorMaxWriteBytes))
  2251. }
  2252. if config.FragmentorMinDelayMicroseconds != nil {
  2253. hash.Write([]byte("FragmentorMinDelayMicroseconds"))
  2254. binary.Write(hash, binary.LittleEndian, int64(*config.FragmentorMinDelayMicroseconds))
  2255. }
  2256. if config.FragmentorMaxDelayMicroseconds != nil {
  2257. hash.Write([]byte("FragmentorMaxDelayMicroseconds"))
  2258. binary.Write(hash, binary.LittleEndian, int64(*config.FragmentorMaxDelayMicroseconds))
  2259. }
  2260. if config.MeekTrafficShapingProbability != nil {
  2261. hash.Write([]byte("MeekTrafficShapingProbability"))
  2262. binary.Write(hash, binary.LittleEndian, *config.MeekTrafficShapingProbability)
  2263. }
  2264. if len(config.MeekTrafficShapingLimitProtocols) > 0 {
  2265. hash.Write([]byte("MeekTrafficShapingLimitProtocols"))
  2266. for _, protocol := range config.MeekTrafficShapingLimitProtocols {
  2267. hash.Write([]byte(protocol))
  2268. }
  2269. }
  2270. if config.MeekMinLimitRequestPayloadLength != nil {
  2271. hash.Write([]byte("MeekMinLimitRequestPayloadLength"))
  2272. binary.Write(hash, binary.LittleEndian, int64(*config.MeekMinLimitRequestPayloadLength))
  2273. }
  2274. if config.MeekMaxLimitRequestPayloadLength != nil {
  2275. hash.Write([]byte("MeekMaxLimitRequestPayloadLength"))
  2276. binary.Write(hash, binary.LittleEndian, int64(*config.MeekMaxLimitRequestPayloadLength))
  2277. }
  2278. if config.MeekRedialTLSProbability != nil {
  2279. hash.Write([]byte("MeekRedialTLSProbability"))
  2280. binary.Write(hash, binary.LittleEndian, *config.MeekRedialTLSProbability)
  2281. }
  2282. if config.ObfuscatedSSHMinPadding != nil {
  2283. hash.Write([]byte("ObfuscatedSSHMinPadding"))
  2284. binary.Write(hash, binary.LittleEndian, int64(*config.ObfuscatedSSHMinPadding))
  2285. }
  2286. if config.ObfuscatedSSHMaxPadding != nil {
  2287. hash.Write([]byte("ObfuscatedSSHMaxPadding"))
  2288. binary.Write(hash, binary.LittleEndian, int64(*config.ObfuscatedSSHMaxPadding))
  2289. }
  2290. if config.LivenessTestMinUpstreamBytes != nil {
  2291. hash.Write([]byte("LivenessTestMinUpstreamBytes"))
  2292. binary.Write(hash, binary.LittleEndian, int64(*config.LivenessTestMinUpstreamBytes))
  2293. }
  2294. if config.LivenessTestMaxUpstreamBytes != nil {
  2295. hash.Write([]byte("LivenessTestMaxUpstreamBytes"))
  2296. binary.Write(hash, binary.LittleEndian, int64(*config.LivenessTestMaxUpstreamBytes))
  2297. }
  2298. if config.LivenessTestMinDownstreamBytes != nil {
  2299. hash.Write([]byte("LivenessTestMinDownstreamBytes"))
  2300. binary.Write(hash, binary.LittleEndian, int64(*config.LivenessTestMinDownstreamBytes))
  2301. }
  2302. if config.LivenessTestMaxDownstreamBytes != nil {
  2303. hash.Write([]byte("LivenessTestMaxDownstreamBytes"))
  2304. binary.Write(hash, binary.LittleEndian, int64(*config.LivenessTestMaxDownstreamBytes))
  2305. }
  2306. // Legacy case: these parameters are included in the hash unconditionally,
  2307. // and so will impact almost all production clients. These parameter names
  2308. // are not hashed since that would invalidate all replay dial parameters for
  2309. // existing clients whose hashes predate the inclusion of parameter names.
  2310. binary.Write(hash, binary.LittleEndian, config.NetworkLatencyMultiplierMin)
  2311. binary.Write(hash, binary.LittleEndian, config.NetworkLatencyMultiplierMax)
  2312. binary.Write(hash, binary.LittleEndian, config.NetworkLatencyMultiplierLambda)
  2313. if config.UseOnlyCustomTLSProfiles != nil {
  2314. hash.Write([]byte("UseOnlyCustomTLSProfiles"))
  2315. binary.Write(hash, binary.LittleEndian, *config.UseOnlyCustomTLSProfiles)
  2316. }
  2317. if len(config.CustomTLSProfiles) > 0 {
  2318. hash.Write([]byte("CustomTLSProfiles"))
  2319. for _, customTLSProfile := range config.CustomTLSProfiles {
  2320. encodedCustomTLSProofile, _ := json.Marshal(customTLSProfile)
  2321. hash.Write(encodedCustomTLSProofile)
  2322. }
  2323. }
  2324. if config.SelectRandomizedTLSProfileProbability != nil {
  2325. hash.Write([]byte("SelectRandomizedTLSProfileProbability"))
  2326. binary.Write(hash, binary.LittleEndian, *config.SelectRandomizedTLSProfileProbability)
  2327. }
  2328. if config.NoDefaultTLSSessionIDProbability != nil {
  2329. hash.Write([]byte("NoDefaultTLSSessionIDProbability"))
  2330. binary.Write(hash, binary.LittleEndian, *config.NoDefaultTLSSessionIDProbability)
  2331. }
  2332. if len(config.DisableFrontingProviderTLSProfiles) > 0 {
  2333. hash.Write([]byte("DisableFrontingProviderTLSProfiles"))
  2334. encodedDisableFrontingProviderTLSProfiles, _ :=
  2335. json.Marshal(config.DisableFrontingProviderTLSProfiles)
  2336. hash.Write(encodedDisableFrontingProviderTLSProfiles)
  2337. }
  2338. if len(config.CustomHostNameRegexes) > 0 {
  2339. hash.Write([]byte("CustomHostNameRegexes"))
  2340. for _, customHostNameRegex := range config.CustomHostNameRegexes {
  2341. hash.Write([]byte(customHostNameRegex))
  2342. }
  2343. }
  2344. if config.CustomHostNameProbability != nil {
  2345. hash.Write([]byte("CustomHostNameProbability"))
  2346. binary.Write(hash, binary.LittleEndian, *config.CustomHostNameProbability)
  2347. }
  2348. if len(config.CustomHostNameLimitProtocols) > 0 {
  2349. hash.Write([]byte("CustomHostNameLimitProtocols"))
  2350. for _, protocol := range config.CustomHostNameLimitProtocols {
  2351. hash.Write([]byte(protocol))
  2352. }
  2353. }
  2354. if config.ConjureCachedRegistrationTTLSeconds != nil {
  2355. hash.Write([]byte("ConjureCachedRegistrationTTLSeconds"))
  2356. binary.Write(hash, binary.LittleEndian, int64(*config.ConjureCachedRegistrationTTLSeconds))
  2357. }
  2358. if config.ConjureAPIRegistrarBidirectionalURL != "" {
  2359. hash.Write([]byte("ConjureAPIRegistrarBidirectionalURL"))
  2360. hash.Write([]byte(config.ConjureAPIRegistrarBidirectionalURL))
  2361. }
  2362. if len(config.ConjureAPIRegistrarFrontingSpecs) > 0 {
  2363. hash.Write([]byte("ConjureAPIRegistrarFrontingSpecs"))
  2364. for _, frontingSpec := range config.ConjureAPIRegistrarFrontingSpecs {
  2365. encodedFrontSpec, _ := json.Marshal(frontingSpec)
  2366. hash.Write(encodedFrontSpec)
  2367. }
  2368. }
  2369. if config.ConjureAPIRegistrarMinDelayMilliseconds != nil {
  2370. hash.Write([]byte("ConjureAPIRegistrarMinDelayMilliseconds"))
  2371. binary.Write(hash, binary.LittleEndian, int64(*config.ConjureAPIRegistrarMinDelayMilliseconds))
  2372. }
  2373. if config.ConjureAPIRegistrarMaxDelayMilliseconds != nil {
  2374. hash.Write([]byte("ConjureAPIRegistrarMaxDelayMilliseconds"))
  2375. binary.Write(hash, binary.LittleEndian, int64(*config.ConjureAPIRegistrarMaxDelayMilliseconds))
  2376. }
  2377. if config.ConjureDecoyRegistrarWidth != nil {
  2378. hash.Write([]byte("ConjureDecoyRegistrarWidth"))
  2379. binary.Write(hash, binary.LittleEndian, int64(*config.ConjureDecoyRegistrarWidth))
  2380. }
  2381. if config.ConjureDecoyRegistrarMinDelayMilliseconds != nil {
  2382. hash.Write([]byte("ConjureDecoyRegistrarMinDelayMilliseconds"))
  2383. binary.Write(hash, binary.LittleEndian, int64(*config.ConjureDecoyRegistrarMinDelayMilliseconds))
  2384. }
  2385. if config.ConjureDecoyRegistrarMaxDelayMilliseconds != nil {
  2386. hash.Write([]byte("ConjureDecoyRegistrarMaxDelayMilliseconds"))
  2387. binary.Write(hash, binary.LittleEndian, int64(*config.ConjureDecoyRegistrarMaxDelayMilliseconds))
  2388. }
  2389. if config.ConjureLimitTransports != nil {
  2390. hash.Write([]byte("ConjureLimitTransports"))
  2391. for _, transport := range config.ConjureLimitTransports {
  2392. hash.Write([]byte(transport))
  2393. }
  2394. }
  2395. if config.ConjureSTUNServerAddresses != nil {
  2396. hash.Write([]byte("ConjureSTUNServerAddresses"))
  2397. for _, address := range config.ConjureSTUNServerAddresses {
  2398. hash.Write([]byte(address))
  2399. }
  2400. }
  2401. if config.HoldOffTunnelMinDurationMilliseconds != nil {
  2402. hash.Write([]byte("HoldOffTunnelMinDurationMilliseconds"))
  2403. binary.Write(hash, binary.LittleEndian, int64(*config.HoldOffTunnelMinDurationMilliseconds))
  2404. }
  2405. if config.HoldOffTunnelMaxDurationMilliseconds != nil {
  2406. hash.Write([]byte("HoldOffTunnelMaxDurationMilliseconds"))
  2407. binary.Write(hash, binary.LittleEndian, int64(*config.HoldOffTunnelMaxDurationMilliseconds))
  2408. }
  2409. if len(config.HoldOffTunnelProtocols) > 0 {
  2410. hash.Write([]byte("HoldOffTunnelProtocols"))
  2411. for _, protocol := range config.HoldOffTunnelProtocols {
  2412. hash.Write([]byte(protocol))
  2413. }
  2414. }
  2415. if len(config.HoldOffTunnelFrontingProviderIDs) > 0 {
  2416. hash.Write([]byte("HoldOffTunnelFrontingProviderIDs"))
  2417. for _, providerID := range config.HoldOffTunnelFrontingProviderIDs {
  2418. hash.Write([]byte(providerID))
  2419. }
  2420. }
  2421. if config.HoldOffDirectTunnelProbability != nil {
  2422. hash.Write([]byte("HoldOffDirectTunnelProbability"))
  2423. binary.Write(hash, binary.LittleEndian, *config.HoldOffDirectTunnelProbability)
  2424. }
  2425. if config.HoldOffDirectTunnelMinDurationMilliseconds != nil {
  2426. hash.Write([]byte("HoldOffDirectTunnelMinDurationMilliseconds"))
  2427. binary.Write(hash, binary.LittleEndian, int64(*config.HoldOffDirectTunnelMinDurationMilliseconds))
  2428. }
  2429. if config.HoldOffDirectTunnelMaxDurationMilliseconds != nil {
  2430. hash.Write([]byte("HoldOffDirectTunnelMaxDurationMilliseconds"))
  2431. binary.Write(hash, binary.LittleEndian, int64(*config.HoldOffDirectTunnelMaxDurationMilliseconds))
  2432. }
  2433. if len(config.HoldOffDirectTunnelProviderRegions) > 0 {
  2434. hash.Write([]byte("HoldOffDirectTunnelProviderRegions"))
  2435. for providerID, regions := range config.HoldOffDirectTunnelProviderRegions {
  2436. hash.Write([]byte(providerID))
  2437. for _, region := range regions {
  2438. hash.Write([]byte(region))
  2439. }
  2440. }
  2441. }
  2442. if config.HoldOffTunnelProbability != nil {
  2443. hash.Write([]byte("HoldOffTunnelProbability"))
  2444. binary.Write(hash, binary.LittleEndian, *config.HoldOffTunnelProbability)
  2445. }
  2446. if len(config.RestrictDirectProviderRegions) > 0 {
  2447. hash.Write([]byte("RestrictDirectProviderRegions"))
  2448. for providerID, regions := range config.RestrictDirectProviderRegions {
  2449. hash.Write([]byte(providerID))
  2450. for _, region := range regions {
  2451. hash.Write([]byte(region))
  2452. }
  2453. }
  2454. }
  2455. if config.RestrictDirectProviderIDsClientProbability != nil {
  2456. hash.Write([]byte("RestrictDirectProviderIDsClientProbability"))
  2457. binary.Write(hash, binary.LittleEndian, *config.RestrictDirectProviderIDsClientProbability)
  2458. }
  2459. if len(config.RestrictFrontingProviderIDs) > 0 {
  2460. hash.Write([]byte("RestrictFrontingProviderIDs"))
  2461. for _, providerID := range config.RestrictFrontingProviderIDs {
  2462. hash.Write([]byte(providerID))
  2463. }
  2464. }
  2465. if config.RestrictFrontingProviderIDsClientProbability != nil {
  2466. hash.Write([]byte("RestrictFrontingProviderIDsClientProbability"))
  2467. binary.Write(hash, binary.LittleEndian, *config.RestrictFrontingProviderIDsClientProbability)
  2468. }
  2469. if config.UpstreamProxyAllowAllServerEntrySources != nil {
  2470. hash.Write([]byte("UpstreamProxyAllowAllServerEntrySources"))
  2471. binary.Write(hash, binary.LittleEndian, *config.UpstreamProxyAllowAllServerEntrySources)
  2472. }
  2473. if len(config.LimitTunnelDialPortNumbers) > 0 {
  2474. hash.Write([]byte("LimitTunnelDialPortNumbers"))
  2475. encodedLimitTunnelDialPortNumbers, _ :=
  2476. json.Marshal(config.LimitTunnelDialPortNumbers)
  2477. hash.Write(encodedLimitTunnelDialPortNumbers)
  2478. }
  2479. if config.QUICDisablePathMTUDiscoveryProbability != nil {
  2480. hash.Write([]byte("QUICDisablePathMTUDiscoveryProbability"))
  2481. binary.Write(hash, binary.LittleEndian, *config.QUICDisablePathMTUDiscoveryProbability)
  2482. }
  2483. if config.DNSResolverAttemptsPerServer != nil {
  2484. hash.Write([]byte("DNSResolverAttemptsPerServer"))
  2485. binary.Write(hash, binary.LittleEndian, int64(*config.DNSResolverAttemptsPerServer))
  2486. }
  2487. if config.DNSResolverRequestTimeoutMilliseconds != nil {
  2488. hash.Write([]byte("DNSResolverRequestTimeoutMilliseconds"))
  2489. binary.Write(hash, binary.LittleEndian, int64(*config.DNSResolverRequestTimeoutMilliseconds))
  2490. }
  2491. if config.DNSResolverAwaitTimeoutMilliseconds != nil {
  2492. hash.Write([]byte("DNSResolverAwaitTimeoutMilliseconds"))
  2493. binary.Write(hash, binary.LittleEndian, int64(*config.DNSResolverAwaitTimeoutMilliseconds))
  2494. }
  2495. if config.DNSResolverPreresolvedIPAddressCIDRs != nil {
  2496. hash.Write([]byte("DNSResolverPreresolvedIPAddressCIDRs"))
  2497. encodedDNSResolverPreresolvedIPAddressCIDRs, _ :=
  2498. json.Marshal(config.DNSResolverPreresolvedIPAddressCIDRs)
  2499. hash.Write(encodedDNSResolverPreresolvedIPAddressCIDRs)
  2500. }
  2501. if config.DNSResolverPreresolvedIPAddressProbability != nil {
  2502. hash.Write([]byte("DNSResolverPreresolvedIPAddressProbability"))
  2503. binary.Write(hash, binary.LittleEndian, *config.DNSResolverPreresolvedIPAddressProbability)
  2504. }
  2505. if config.DNSResolverAlternateServers != nil {
  2506. hash.Write([]byte("DNSResolverAlternateServers"))
  2507. for _, server := range config.DNSResolverAlternateServers {
  2508. hash.Write([]byte(server))
  2509. }
  2510. }
  2511. if config.DNSResolverPreferAlternateServerProbability != nil {
  2512. hash.Write([]byte("DNSResolverPreferAlternateServerProbability"))
  2513. binary.Write(hash, binary.LittleEndian, *config.DNSResolverPreferAlternateServerProbability)
  2514. }
  2515. if config.DNSResolverProtocolTransformSpecs != nil {
  2516. hash.Write([]byte("DNSResolverProtocolTransformSpecs"))
  2517. encodedDNSResolverProtocolTransformSpecs, _ :=
  2518. json.Marshal(config.DNSResolverProtocolTransformSpecs)
  2519. hash.Write(encodedDNSResolverProtocolTransformSpecs)
  2520. }
  2521. if config.DNSResolverProtocolTransformScopedSpecNames != nil {
  2522. hash.Write([]byte("DNSResolverProtocolTransformScopedSpecNames"))
  2523. encodedDNSResolverProtocolTransformScopedSpecNames, _ :=
  2524. json.Marshal(config.DNSResolverProtocolTransformScopedSpecNames)
  2525. hash.Write(encodedDNSResolverProtocolTransformScopedSpecNames)
  2526. }
  2527. if config.DNSResolverProtocolTransformProbability != nil {
  2528. hash.Write([]byte("DNSResolverProtocolTransformProbability"))
  2529. binary.Write(hash, binary.LittleEndian, *config.DNSResolverProtocolTransformProbability)
  2530. }
  2531. if config.DNSResolverIncludeEDNS0Probability != nil {
  2532. hash.Write([]byte("DNSResolverIncludeEDNS0Probability"))
  2533. binary.Write(hash, binary.LittleEndian, *config.DNSResolverIncludeEDNS0Probability)
  2534. }
  2535. if config.DNSResolverCacheExtensionInitialTTLMilliseconds != nil {
  2536. hash.Write([]byte("DNSResolverCacheExtensionInitialTTLMilliseconds"))
  2537. binary.Write(hash, binary.LittleEndian, int64(*config.DNSResolverCacheExtensionInitialTTLMilliseconds))
  2538. }
  2539. if config.DNSResolverCacheExtensionVerifiedTTLMilliseconds != nil {
  2540. hash.Write([]byte("DNSResolverCacheExtensionVerifiedTTLMilliseconds"))
  2541. binary.Write(hash, binary.LittleEndian, int64(*config.DNSResolverCacheExtensionVerifiedTTLMilliseconds))
  2542. }
  2543. if config.DirectHTTPProtocolTransformSpecs != nil {
  2544. hash.Write([]byte("DirectHTTPProtocolTransformSpecs"))
  2545. encodedDirectHTTPProtocolTransformSpecs, _ :=
  2546. json.Marshal(config.DirectHTTPProtocolTransformSpecs)
  2547. hash.Write(encodedDirectHTTPProtocolTransformSpecs)
  2548. }
  2549. if config.DirectHTTPProtocolTransformScopedSpecNames != nil {
  2550. hash.Write([]byte("DirectHTTPProtocolTransformScopedSpecNames"))
  2551. encodedDirectHTTPProtocolTransformScopedSpecNames, _ :=
  2552. json.Marshal(config.DirectHTTPProtocolTransformScopedSpecNames)
  2553. hash.Write(encodedDirectHTTPProtocolTransformScopedSpecNames)
  2554. }
  2555. if config.DirectHTTPProtocolTransformProbability != nil {
  2556. hash.Write([]byte("DirectHTTPProtocolTransformProbability"))
  2557. binary.Write(hash, binary.LittleEndian, *config.DirectHTTPProtocolTransformProbability)
  2558. }
  2559. if config.FrontedHTTPProtocolTransformSpecs != nil {
  2560. hash.Write([]byte("FrontedHTTPProtocolTransformSpecs"))
  2561. encodedFrontedHTTPProtocolTransformSpecs, _ :=
  2562. json.Marshal(config.FrontedHTTPProtocolTransformSpecs)
  2563. hash.Write(encodedFrontedHTTPProtocolTransformSpecs)
  2564. }
  2565. if config.FrontedHTTPProtocolTransformScopedSpecNames != nil {
  2566. hash.Write([]byte("FrontedHTTPProtocolTransformScopedSpecNames"))
  2567. encodedFrontedHTTPProtocolTransformScopedSpecNames, _ :=
  2568. json.Marshal(config.FrontedHTTPProtocolTransformScopedSpecNames)
  2569. hash.Write(encodedFrontedHTTPProtocolTransformScopedSpecNames)
  2570. }
  2571. if config.FrontedHTTPProtocolTransformProbability != nil {
  2572. hash.Write([]byte("FrontedHTTPProtocolTransformProbability"))
  2573. binary.Write(hash, binary.LittleEndian, *config.FrontedHTTPProtocolTransformProbability)
  2574. }
  2575. if config.OSSHObfuscatorSeedTransformSpecs != nil {
  2576. hash.Write([]byte("OSSHObfuscatorSeedTransformSpecs"))
  2577. encodedOSSHObfuscatorSeedTransformSpecs, _ :=
  2578. json.Marshal(config.OSSHObfuscatorSeedTransformSpecs)
  2579. hash.Write(encodedOSSHObfuscatorSeedTransformSpecs)
  2580. }
  2581. if config.OSSHObfuscatorSeedTransformScopedSpecNames != nil {
  2582. hash.Write([]byte("OSSHObfuscatorSeedTransformScopedSpecNames"))
  2583. encodedOSSHObfuscatorSeedTransformScopedSpecNames, _ :=
  2584. json.Marshal(config.OSSHObfuscatorSeedTransformScopedSpecNames)
  2585. hash.Write(encodedOSSHObfuscatorSeedTransformScopedSpecNames)
  2586. }
  2587. if config.OSSHObfuscatorSeedTransformProbability != nil {
  2588. hash.Write([]byte("OSSHObfuscatorSeedTransformProbability"))
  2589. binary.Write(hash, binary.LittleEndian, *config.OSSHObfuscatorSeedTransformProbability)
  2590. }
  2591. if config.ObfuscatedQUICNonceTransformSpecs != nil {
  2592. hash.Write([]byte("ObfuscatedQUICNonceTransformSpecs"))
  2593. encodedObfuscatedQUICNonceTransformSpecs, _ :=
  2594. json.Marshal(config.ObfuscatedQUICNonceTransformSpecs)
  2595. hash.Write(encodedObfuscatedQUICNonceTransformSpecs)
  2596. }
  2597. if config.ObfuscatedQUICNonceTransformScopedSpecNames != nil {
  2598. hash.Write([]byte("ObfuscatedQUICNonceTransformScopedSpecNames"))
  2599. encodedObfuscatedQUICNonceTransformScopedSpecNames, _ :=
  2600. json.Marshal(config.ObfuscatedQUICNonceTransformScopedSpecNames)
  2601. hash.Write(encodedObfuscatedQUICNonceTransformScopedSpecNames)
  2602. }
  2603. if config.ObfuscatedQUICNonceTransformProbability != nil {
  2604. hash.Write([]byte("ObfuscatedQUICNonceTransformProbability"))
  2605. binary.Write(hash, binary.LittleEndian, *config.ObfuscatedQUICNonceTransformProbability)
  2606. }
  2607. if config.OSSHPrefixSpecs != nil {
  2608. hash.Write([]byte("OSSHPrefixSpecs"))
  2609. encodedOSSHPrefixSpecs, _ := json.Marshal(config.OSSHPrefixSpecs)
  2610. hash.Write(encodedOSSHPrefixSpecs)
  2611. }
  2612. if config.OSSHPrefixScopedSpecNames != nil {
  2613. hash.Write([]byte("OSSHPrefixScopedSpecNames"))
  2614. encodedOSSHPrefixScopedSpecNames, _ := json.Marshal(config.OSSHPrefixScopedSpecNames)
  2615. hash.Write(encodedOSSHPrefixScopedSpecNames)
  2616. }
  2617. if config.OSSHPrefixProbability != nil {
  2618. hash.Write([]byte("OSSHPrefixProbability"))
  2619. binary.Write(hash, binary.LittleEndian, *config.OSSHPrefixProbability)
  2620. }
  2621. if config.OSSHPrefixSplitMinDelayMilliseconds != nil {
  2622. hash.Write([]byte("OSSHPrefixSplitMinDelayMilliseconds"))
  2623. binary.Write(hash, binary.LittleEndian, int64(*config.OSSHPrefixSplitMinDelayMilliseconds))
  2624. }
  2625. if config.OSSHPrefixSplitMaxDelayMilliseconds != nil {
  2626. hash.Write([]byte("OSSHPrefixSplitMaxDelayMilliseconds"))
  2627. binary.Write(hash, binary.LittleEndian, int64(*config.OSSHPrefixSplitMaxDelayMilliseconds))
  2628. }
  2629. if config.OSSHPrefixEnableFragmentor != nil {
  2630. hash.Write([]byte("OSSHPrefixEnableFragmentor"))
  2631. binary.Write(hash, binary.LittleEndian, *config.OSSHPrefixEnableFragmentor)
  2632. }
  2633. if config.TLSTunnelTrafficShapingProbability != nil {
  2634. hash.Write([]byte("TLSTunnelTrafficShapingProbability"))
  2635. binary.Write(hash, binary.LittleEndian, *config.TLSTunnelTrafficShapingProbability)
  2636. }
  2637. if config.TLSTunnelMinTLSPadding != nil {
  2638. hash.Write([]byte("TLSTunnelMinTLSPadding"))
  2639. binary.Write(hash, binary.LittleEndian, int64(*config.TLSTunnelMinTLSPadding))
  2640. }
  2641. if config.TLSTunnelMaxTLSPadding != nil {
  2642. hash.Write([]byte("TLSTunnelMaxTLSPadding"))
  2643. binary.Write(hash, binary.LittleEndian, int64(*config.TLSTunnelMaxTLSPadding))
  2644. }
  2645. if config.TLSFragmentClientHelloProbability != nil {
  2646. hash.Write([]byte("TLSFragmentClientHelloProbability"))
  2647. binary.Write(hash, binary.LittleEndian, *config.TLSFragmentClientHelloProbability)
  2648. }
  2649. if len(config.TLSFragmentClientHelloLimitProtocols) > 0 {
  2650. hash.Write([]byte("TLSFragmentClientHelloLimitProtocols"))
  2651. for _, protocol := range config.TLSFragmentClientHelloLimitProtocols {
  2652. hash.Write([]byte(protocol))
  2653. }
  2654. }
  2655. // Steering IPs are ephemeral and not replayed, so steering IP parameters
  2656. // are excluded here.
  2657. if config.InproxyTunnelProtocolSelectionProbability != nil {
  2658. hash.Write([]byte("InproxyTunnelProtocolSelectionProbability"))
  2659. binary.Write(hash, binary.LittleEndian, *config.InproxyTunnelProtocolSelectionProbability)
  2660. }
  2661. if len(config.InproxyBrokerSpecs) > 0 {
  2662. hash.Write([]byte("InproxyBrokerSpecs"))
  2663. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyBrokerSpecs)))
  2664. }
  2665. if len(config.InproxyPersonalPairingBrokerSpecs) > 0 {
  2666. hash.Write([]byte("InproxyPersonalPairingBrokerSpecs"))
  2667. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyPersonalPairingBrokerSpecs)))
  2668. }
  2669. if len(config.InproxyProxyBrokerSpecs) > 0 {
  2670. hash.Write([]byte("InproxyProxyBrokerSpecs"))
  2671. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyProxyBrokerSpecs)))
  2672. }
  2673. if len(config.InproxyProxyPersonalPairingBrokerSpecs) > 0 {
  2674. hash.Write([]byte("InproxyProxyPersonalPairingBrokerSpecs"))
  2675. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyProxyPersonalPairingBrokerSpecs)))
  2676. }
  2677. if len(config.InproxyClientBrokerSpecs) > 0 {
  2678. hash.Write([]byte("InproxyClientBrokerSpecs"))
  2679. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyClientBrokerSpecs)))
  2680. }
  2681. if len(config.InproxyClientPersonalPairingBrokerSpecs) > 0 {
  2682. hash.Write([]byte("InproxyClientPersonalPairingBrokerSpecs"))
  2683. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyClientPersonalPairingBrokerSpecs)))
  2684. }
  2685. if config.InproxyReplayBrokerDialParametersTTLSeconds != nil {
  2686. hash.Write([]byte("InproxyReplayBrokerDialParametersTTLSeconds"))
  2687. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyReplayBrokerDialParametersTTLSeconds))
  2688. }
  2689. if config.InproxyReplayBrokerUpdateFrequencySeconds != nil {
  2690. hash.Write([]byte("InproxyReplayBrokerUpdateFrequencySeconds"))
  2691. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyReplayBrokerUpdateFrequencySeconds))
  2692. }
  2693. if config.InproxyReplayBrokerDialParametersProbability != nil {
  2694. hash.Write([]byte("InproxyReplayBrokerDialParametersProbability"))
  2695. binary.Write(hash, binary.LittleEndian, *config.InproxyReplayBrokerDialParametersProbability)
  2696. }
  2697. if config.InproxyReplayBrokerRetainFailedProbability != nil {
  2698. hash.Write([]byte("InproxyReplayBrokerRetainFailedProbability"))
  2699. binary.Write(hash, binary.LittleEndian, *config.InproxyReplayBrokerRetainFailedProbability)
  2700. }
  2701. if len(config.InproxyCommonCompartmentIDs) > 0 {
  2702. hash.Write([]byte("InproxyCommonCompartmentIDs"))
  2703. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyCommonCompartmentIDs)))
  2704. }
  2705. if config.InproxyMaxCompartmentIDListLength != nil {
  2706. hash.Write([]byte("InproxyMaxCompartmentIDListLength"))
  2707. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyMaxCompartmentIDListLength))
  2708. }
  2709. if config.InproxyProxyAnnounceRequestTimeoutMilliseconds != nil {
  2710. hash.Write([]byte("InproxyProxyAnnounceRequestTimeoutMilliseconds"))
  2711. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyProxyAnnounceRequestTimeoutMilliseconds))
  2712. }
  2713. if config.InproxyProxyAnnounceDelayMilliseconds != nil {
  2714. hash.Write([]byte("InproxyProxyAnnounceDelayMilliseconds"))
  2715. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyProxyAnnounceDelayMilliseconds))
  2716. }
  2717. if config.InproxyProxyAnnounceDelayJitter != nil {
  2718. hash.Write([]byte("InproxyProxyAnnounceDelayJitter"))
  2719. binary.Write(hash, binary.LittleEndian, *config.InproxyProxyAnnounceDelayJitter)
  2720. }
  2721. if config.InproxyProxyAnswerRequestTimeoutMilliseconds != nil {
  2722. hash.Write([]byte("InproxyProxyAnswerRequestTimeoutMilliseconds"))
  2723. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyProxyAnswerRequestTimeoutMilliseconds))
  2724. }
  2725. if config.InproxyClientOfferRequestTimeoutMilliseconds != nil {
  2726. hash.Write([]byte("InproxyClientOfferRequestTimeoutMilliseconds"))
  2727. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyClientOfferRequestTimeoutMilliseconds))
  2728. }
  2729. if config.InproxyClientOfferRetryDelayMilliseconds != nil {
  2730. hash.Write([]byte("InproxyClientOfferRetryDelayMilliseconds"))
  2731. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyClientOfferRetryDelayMilliseconds))
  2732. }
  2733. if config.InproxyClientOfferRetryJitter != nil {
  2734. hash.Write([]byte("InproxyClientOfferRetryJitter"))
  2735. binary.Write(hash, binary.LittleEndian, *config.InproxyClientOfferRetryJitter)
  2736. }
  2737. if config.InproxyClientRelayedPacketRequestTimeoutMilliseconds != nil {
  2738. hash.Write([]byte("InproxyClientRelayedPacketRequestTimeoutMilliseconds"))
  2739. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyClientRelayedPacketRequestTimeoutMilliseconds))
  2740. }
  2741. if config.InproxyDTLSRandomizationProbability != nil {
  2742. hash.Write([]byte("InproxyDTLSRandomizationProbability"))
  2743. binary.Write(hash, binary.LittleEndian, *config.InproxyDTLSRandomizationProbability)
  2744. }
  2745. if config.InproxyDataChannelTrafficShapingProbability != nil {
  2746. hash.Write([]byte("InproxyDataChannelTrafficShapingProbability"))
  2747. binary.Write(hash, binary.LittleEndian, *config.InproxyDataChannelTrafficShapingProbability)
  2748. }
  2749. if config.InproxyDataChannelTrafficShapingParameters != nil {
  2750. hash.Write([]byte("InproxyDataChannelTrafficShapingParameters"))
  2751. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyDataChannelTrafficShapingParameters)))
  2752. }
  2753. if config.InproxySTUNServerAddresses != nil {
  2754. hash.Write([]byte("InproxySTUNServerAddresses"))
  2755. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyProxySTUNServerAddresses)))
  2756. }
  2757. if config.InproxySTUNServerAddressesRFC5780 != nil {
  2758. hash.Write([]byte("InproxySTUNServerAddressesRFC5780"))
  2759. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyProxySTUNServerAddressesRFC5780)))
  2760. }
  2761. if config.InproxyProxySTUNServerAddresses != nil {
  2762. hash.Write([]byte("InproxyProxySTUNServerAddresses"))
  2763. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyProxySTUNServerAddresses)))
  2764. }
  2765. if config.InproxyProxySTUNServerAddressesRFC5780 != nil {
  2766. hash.Write([]byte("InproxyProxySTUNServerAddressesRFC5780"))
  2767. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyProxySTUNServerAddressesRFC5780)))
  2768. }
  2769. if config.InproxyClientSTUNServerAddresses != nil {
  2770. hash.Write([]byte("InproxyClientSTUNServerAddresses"))
  2771. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyClientSTUNServerAddresses)))
  2772. }
  2773. if config.InproxyClientSTUNServerAddressesRFC5780 != nil {
  2774. hash.Write([]byte("InproxyClientSTUNServerAddressesRFC5780"))
  2775. hash.Write([]byte(fmt.Sprintf("%+v", config.InproxyClientSTUNServerAddressesRFC5780)))
  2776. }
  2777. if config.InproxyClientDiscoverNATProbability != nil {
  2778. hash.Write([]byte("InproxyClientDiscoverNATProbability"))
  2779. binary.Write(hash, binary.LittleEndian, *config.InproxyClientDiscoverNATProbability)
  2780. }
  2781. if config.InproxyDisableSTUN != nil {
  2782. hash.Write([]byte("InproxyDisableSTUN"))
  2783. binary.Write(hash, binary.LittleEndian, *config.InproxyDisableSTUN)
  2784. }
  2785. if config.InproxyDisablePortMapping != nil {
  2786. hash.Write([]byte("InproxyDisablePortMapping"))
  2787. binary.Write(hash, binary.LittleEndian, *config.InproxyDisablePortMapping)
  2788. }
  2789. if config.InproxyDisableInboundForMobileNetworks != nil {
  2790. hash.Write([]byte("InproxyDisableInboundForMobileNetworks"))
  2791. binary.Write(hash, binary.LittleEndian, *config.InproxyDisableInboundForMobileNetworks)
  2792. }
  2793. if config.InproxyDisableIPv6ICECandidates != nil {
  2794. hash.Write([]byte("InproxyDisableIPv6ICECandidates"))
  2795. binary.Write(hash, binary.LittleEndian, *config.InproxyDisableIPv6ICECandidates)
  2796. }
  2797. if config.InproxyProxyDisableSTUN != nil {
  2798. hash.Write([]byte("InproxyProxyDisableSTUN"))
  2799. binary.Write(hash, binary.LittleEndian, *config.InproxyProxyDisableSTUN)
  2800. }
  2801. if config.InproxyProxyDisablePortMapping != nil {
  2802. hash.Write([]byte("InproxyProxyDisablePortMapping"))
  2803. binary.Write(hash, binary.LittleEndian, *config.InproxyProxyDisablePortMapping)
  2804. }
  2805. if config.InproxyProxyDisableInboundForMobileNetworks != nil {
  2806. hash.Write([]byte("InproxyProxyDisableInboundForMobileNetworks"))
  2807. binary.Write(hash, binary.LittleEndian, *config.InproxyProxyDisableInboundForMobileNetworks)
  2808. }
  2809. if config.InproxyProxyDisableIPv6ICECandidates != nil {
  2810. hash.Write([]byte("InproxyProxyDisableIPv6ICECandidates"))
  2811. binary.Write(hash, binary.LittleEndian, *config.InproxyProxyDisableIPv6ICECandidates)
  2812. }
  2813. if config.InproxyClientDisableSTUN != nil {
  2814. hash.Write([]byte("InproxyClientDisableSTUN"))
  2815. binary.Write(hash, binary.LittleEndian, *config.InproxyClientDisableSTUN)
  2816. }
  2817. if config.InproxyClientDisablePortMapping != nil {
  2818. hash.Write([]byte("InproxyClientDisablePortMapping"))
  2819. binary.Write(hash, binary.LittleEndian, *config.InproxyClientDisablePortMapping)
  2820. }
  2821. if config.InproxyClientDisableInboundForMobileNetworks != nil {
  2822. hash.Write([]byte("InproxyClientDisableInboundForMobileNetworks"))
  2823. binary.Write(hash, binary.LittleEndian, *config.InproxyClientDisableInboundForMobileNetworks)
  2824. }
  2825. if config.InproxyClientDisableIPv6ICECandidates != nil {
  2826. hash.Write([]byte("InproxyClientDisableIPv6ICECandidates"))
  2827. binary.Write(hash, binary.LittleEndian, *config.InproxyClientDisableIPv6ICECandidates)
  2828. }
  2829. if config.InproxyProxyDiscoverNATTimeoutMilliseconds != nil {
  2830. hash.Write([]byte("InproxyProxyDiscoverNATTimeoutMilliseconds"))
  2831. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyProxyDiscoverNATTimeoutMilliseconds))
  2832. }
  2833. if config.InproxyClientDiscoverNATTimeoutMilliseconds != nil {
  2834. hash.Write([]byte("InproxyClientDiscoverNATTimeoutMilliseconds"))
  2835. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyClientDiscoverNATTimeoutMilliseconds))
  2836. }
  2837. if config.InproxyWebRTCAnswerTimeoutMilliseconds != nil {
  2838. hash.Write([]byte("InproxyWebRTCAnswerTimeoutMilliseconds"))
  2839. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyWebRTCAnswerTimeoutMilliseconds))
  2840. }
  2841. if config.InproxyProxyWebRTCAwaitDataChannelTimeoutMilliseconds != nil {
  2842. hash.Write([]byte("InproxyProxyWebRTCAwaitDataChannelTimeoutMilliseconds"))
  2843. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyProxyWebRTCAwaitDataChannelTimeoutMilliseconds))
  2844. }
  2845. if config.InproxyClientWebRTCAwaitDataChannelTimeoutMilliseconds != nil {
  2846. hash.Write([]byte("InproxyClientWebRTCAwaitDataChannelTimeoutMilliseconds"))
  2847. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyClientWebRTCAwaitDataChannelTimeoutMilliseconds))
  2848. }
  2849. if config.InproxyProxyDestinationDialTimeoutMilliseconds != nil {
  2850. hash.Write([]byte("InproxyProxyDestinationDialTimeoutMilliseconds"))
  2851. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyProxyDestinationDialTimeoutMilliseconds))
  2852. }
  2853. if config.InproxyPsiphonAPIRequestTimeoutMilliseconds != nil {
  2854. hash.Write([]byte("InproxyPsiphonAPIRequestTimeoutMilliseconds"))
  2855. binary.Write(hash, binary.LittleEndian, int64(*config.InproxyPsiphonAPIRequestTimeoutMilliseconds))
  2856. }
  2857. config.dialParametersHash = hash.Sum(nil)
  2858. }
  2859. // applyAdditionalParameters decodes and applies any additional parameters
  2860. // stored in config.AdditionalParameter to the Config and returns an array
  2861. // of notices which should be logged at the info level. If there is no error,
  2862. // then config.AdditionalParameter is set to "" to conserve memory and further
  2863. // calls will do nothing. This function should only be called once.
  2864. //
  2865. // If there is an error, the existing Config is left entirely unmodified.
  2866. func (config *Config) applyAdditionalParameters() ([]string, error) {
  2867. if config.AdditionalParameters == "" {
  2868. return nil, nil
  2869. }
  2870. b, err := base64.StdEncoding.DecodeString(config.AdditionalParameters)
  2871. if err != nil {
  2872. return nil, errors.Trace(err)
  2873. }
  2874. if len(b) < 32 {
  2875. return nil, errors.Tracef("invalid length, len(b) == %d", len(b))
  2876. }
  2877. var key [32]byte
  2878. copy(key[:], b[:32])
  2879. decrypted, ok := secretbox.Open(nil, b[32:], &[24]byte{}, &key)
  2880. if !ok {
  2881. return nil, errors.TraceNew("secretbox.Open failed")
  2882. }
  2883. var additionalParameters Config
  2884. err = json.Unmarshal(decrypted, &additionalParameters)
  2885. if err != nil {
  2886. return nil, errors.Trace(err)
  2887. }
  2888. src := reflect.ValueOf(&additionalParameters).Elem()
  2889. dest := reflect.ValueOf(config).Elem()
  2890. var infoNotices []string
  2891. for i := 0; i < src.NumField(); i++ {
  2892. if !src.Field(i).IsZero() {
  2893. dest.Field(i).Set(src.Field(i))
  2894. infoNotice := fmt.Sprintf("%s overridden by AdditionalParameters", dest.Type().Field(i).Name)
  2895. infoNotices = append(infoNotices, infoNotice)
  2896. }
  2897. }
  2898. // Reset field to conserve memory since this is a one-time operation.
  2899. config.AdditionalParameters = ""
  2900. return infoNotices, nil
  2901. }
  2902. func promoteLegacyTransferURL(URL string) parameters.TransferURLs {
  2903. transferURLs := make(parameters.TransferURLs, 1)
  2904. transferURLs[0] = &parameters.TransferURL{
  2905. URL: base64.StdEncoding.EncodeToString([]byte(URL)),
  2906. SkipVerify: false,
  2907. OnlyAfterAttempts: 0,
  2908. }
  2909. return transferURLs
  2910. }
  2911. type loggingDeviceBinder struct {
  2912. d DeviceBinder
  2913. }
  2914. func newLoggingDeviceBinder(d DeviceBinder) *loggingDeviceBinder {
  2915. return &loggingDeviceBinder{d: d}
  2916. }
  2917. func (d *loggingDeviceBinder) BindToDevice(fileDescriptor int) (string, error) {
  2918. deviceInfo, err := d.d.BindToDevice(fileDescriptor)
  2919. if err == nil && deviceInfo != "" {
  2920. NoticeBindToDevice(deviceInfo)
  2921. }
  2922. return deviceInfo, err
  2923. }
  2924. type staticNetworkGetter struct {
  2925. networkID string
  2926. }
  2927. func newStaticNetworkGetter(networkID string) *staticNetworkGetter {
  2928. return &staticNetworkGetter{networkID: networkID}
  2929. }
  2930. func (n *staticNetworkGetter) GetNetworkID() string {
  2931. return n.networkID
  2932. }
  2933. type loggingNetworkIDGetter struct {
  2934. n NetworkIDGetter
  2935. }
  2936. func newLoggingNetworkIDGetter(n NetworkIDGetter) *loggingNetworkIDGetter {
  2937. return &loggingNetworkIDGetter{n: n}
  2938. }
  2939. func (n *loggingNetworkIDGetter) GetNetworkID() string {
  2940. networkID := n.n.GetNetworkID()
  2941. // All PII must appear after the initial "-"
  2942. // See: https://godoc.org/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon#NetworkIDGetter
  2943. logNetworkID := networkID
  2944. index := strings.Index(logNetworkID, "-")
  2945. if index != -1 {
  2946. logNetworkID = logNetworkID[:index]
  2947. }
  2948. if len(logNetworkID)+1 < len(networkID) {
  2949. // Indicate when additional network info was present after the first "-".
  2950. logNetworkID += "+[redacted]"
  2951. }
  2952. NoticeNetworkID(logNetworkID)
  2953. return networkID
  2954. }
  2955. // migrationsFromLegacyNoticeFilePaths returns the file migrations which must be
  2956. // performed to move notice files from legacy file paths, which were configured
  2957. // with the legacy config fields HomepageNoticesFilename and
  2958. // RotatingNoticesFilename, to the new file paths used by Psiphon which exist
  2959. // under the data root directory.
  2960. func migrationsFromLegacyNoticeFilePaths(config *Config) []FileMigration {
  2961. var noticeMigrations []FileMigration
  2962. if config.MigrateHomepageNoticesFilename != "" {
  2963. noticeMigrations = append(noticeMigrations, FileMigration{
  2964. Name: "hompage",
  2965. OldPath: config.MigrateHomepageNoticesFilename,
  2966. NewPath: config.GetHomePageFilename(),
  2967. })
  2968. }
  2969. if config.MigrateRotatingNoticesFilename != "" {
  2970. migrations := []FileMigration{
  2971. {
  2972. Name: "notices",
  2973. OldPath: config.MigrateRotatingNoticesFilename,
  2974. NewPath: config.GetNoticesFilename(),
  2975. IsDir: false,
  2976. },
  2977. {
  2978. Name: "notices.1",
  2979. OldPath: config.MigrateRotatingNoticesFilename + ".1",
  2980. NewPath: config.GetNoticesFilename() + ".1",
  2981. },
  2982. }
  2983. noticeMigrations = append(noticeMigrations, migrations...)
  2984. }
  2985. return noticeMigrations
  2986. }
  2987. // migrationsFromLegacyFilePaths returns the file migrations which must be
  2988. // performed to move files from legacy file paths, which were configured with
  2989. // legacy config fields, to the new file paths used by Psiphon which exist
  2990. // under the data root directory.
  2991. // Note: an attempt is made to redact any file paths from the returned error.
  2992. func migrationsFromLegacyFilePaths(config *Config) ([]FileMigration, error) {
  2993. migrations := []FileMigration{
  2994. {
  2995. Name: "psiphon.boltdb",
  2996. OldPath: filepath.Join(config.MigrateDataStoreDirectory, "psiphon.boltdb"),
  2997. NewPath: filepath.Join(config.GetDataStoreDirectory(), "psiphon.boltdb"),
  2998. },
  2999. {
  3000. Name: "psiphon.boltdb.lock",
  3001. OldPath: filepath.Join(config.MigrateDataStoreDirectory, "psiphon.boltdb.lock"),
  3002. NewPath: filepath.Join(config.GetDataStoreDirectory(), "psiphon.boltdb.lock"),
  3003. },
  3004. }
  3005. if config.MigrateRemoteServerListDownloadFilename != "" {
  3006. // Migrate remote server list files
  3007. rslMigrations := []FileMigration{
  3008. {
  3009. Name: "remote_server_list",
  3010. OldPath: config.MigrateRemoteServerListDownloadFilename,
  3011. NewPath: config.GetRemoteServerListDownloadFilename(),
  3012. },
  3013. {
  3014. Name: "remote_server_list.part",
  3015. OldPath: config.MigrateRemoteServerListDownloadFilename + ".part",
  3016. NewPath: config.GetRemoteServerListDownloadFilename() + ".part",
  3017. },
  3018. {
  3019. Name: "remote_server_list.part.etag",
  3020. OldPath: config.MigrateRemoteServerListDownloadFilename + ".part.etag",
  3021. NewPath: config.GetRemoteServerListDownloadFilename() + ".part.etag",
  3022. },
  3023. }
  3024. migrations = append(migrations, rslMigrations...)
  3025. }
  3026. if config.MigrateObfuscatedServerListDownloadDirectory != "" {
  3027. // Migrate OSL registry file and downloads
  3028. oslFileRegex, err := regexp.Compile(`^osl-.+$`)
  3029. if err != nil {
  3030. return nil, errors.TraceMsg(err, "failed to compile regex for osl files")
  3031. }
  3032. files, err := ioutil.ReadDir(config.MigrateObfuscatedServerListDownloadDirectory)
  3033. if err != nil {
  3034. NoticeWarning(
  3035. "Migration: failed to read OSL download directory with error %s",
  3036. common.RedactFilePathsError(err, config.MigrateObfuscatedServerListDownloadDirectory))
  3037. } else {
  3038. for _, file := range files {
  3039. if oslFileRegex.MatchString(file.Name()) {
  3040. fileMigration := FileMigration{
  3041. Name: "osl",
  3042. OldPath: filepath.Join(config.MigrateObfuscatedServerListDownloadDirectory, file.Name()),
  3043. NewPath: filepath.Join(config.GetObfuscatedServerListDownloadDirectory(), file.Name()),
  3044. }
  3045. migrations = append(migrations, fileMigration)
  3046. }
  3047. }
  3048. }
  3049. }
  3050. if config.MigrateUpgradeDownloadFilename != "" {
  3051. // Migrate downloaded upgrade files
  3052. oldUpgradeDownloadFilename := filepath.Base(config.MigrateUpgradeDownloadFilename)
  3053. // Create regex for:
  3054. // <old_upgrade_download_filename>
  3055. // <old_upgrade_download_filename>.<client_version_number>
  3056. // <old_upgrade_download_filename>.<client_version_number>.part
  3057. // <old_upgrade_download_filename>.<client_version_number>.part.etag
  3058. upgradeDownloadFileRegex, err := regexp.Compile(`^` + oldUpgradeDownloadFilename + `(\.\d+(\.part(\.etag)?)?)?$`)
  3059. if err != nil {
  3060. return nil, errors.TraceMsg(err, "failed to compile regex for upgrade files")
  3061. }
  3062. upgradeDownloadDir := filepath.Dir(config.MigrateUpgradeDownloadFilename)
  3063. files, err := ioutil.ReadDir(upgradeDownloadDir)
  3064. if err != nil {
  3065. NoticeWarning(
  3066. "Migration: failed to read upgrade download directory with error %s",
  3067. common.RedactFilePathsError(err, upgradeDownloadDir))
  3068. } else {
  3069. for _, file := range files {
  3070. if upgradeDownloadFileRegex.MatchString(file.Name()) {
  3071. oldFileSuffix := strings.TrimPrefix(file.Name(), oldUpgradeDownloadFilename)
  3072. fileMigration := FileMigration{
  3073. Name: "upgrade",
  3074. OldPath: filepath.Join(upgradeDownloadDir, file.Name()),
  3075. NewPath: config.GetUpgradeDownloadFilename() + oldFileSuffix,
  3076. }
  3077. migrations = append(migrations, fileMigration)
  3078. }
  3079. }
  3080. }
  3081. }
  3082. return migrations, nil
  3083. }