config.go 178 KB

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