config.go 172 KB

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