config.go 162 KB

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