selenium_tor 1.6.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -5
  3. data/CHANGELOG.md +26 -0
  4. data/README.md +34 -41
  5. data/Rakefile +1 -2
  6. data/fonts/Arimo-Bold.ttf +0 -0
  7. data/fonts/Arimo-BoldItalic.ttf +0 -0
  8. data/fonts/Arimo-Italic.ttf +0 -0
  9. data/fonts/Arimo-Regular.ttf +0 -0
  10. data/fonts/Cousine-Bold.ttf +0 -0
  11. data/fonts/Cousine-BoldItalic.ttf +0 -0
  12. data/fonts/Cousine-Italic.ttf +0 -0
  13. data/fonts/Cousine-Regular.ttf +0 -0
  14. data/fonts/NotoNaskhArabic-Regular.ttf +0 -0
  15. data/fonts/NotoSansAdlam-Regular.ttf +0 -0
  16. data/fonts/NotoSansArmenian-Regular.ttf +0 -0
  17. data/fonts/NotoSansBalinese-Regular.ttf +0 -0
  18. data/fonts/NotoSansBamum-Regular.ttf +0 -0
  19. data/fonts/NotoSansBassaVah-Regular.ttf +0 -0
  20. data/fonts/NotoSansBatak-Regular.ttf +0 -0
  21. data/fonts/NotoSansBengali-Regular.ttf +0 -0
  22. data/fonts/NotoSansBuginese-Regular.ttf +0 -0
  23. data/fonts/NotoSansBuhid-Regular.ttf +0 -0
  24. data/fonts/NotoSansCanadianAboriginal-Regular.ttf +0 -0
  25. data/fonts/NotoSansChakma-Regular.ttf +0 -0
  26. data/fonts/NotoSansCham-Regular.ttf +0 -0
  27. data/fonts/NotoSansCherokee-Regular.ttf +0 -0
  28. data/fonts/NotoSansCoptic-Regular.ttf +0 -0
  29. data/fonts/NotoSansDeseret-Regular.ttf +0 -0
  30. data/fonts/NotoSansDevanagari-Regular.ttf +0 -0
  31. data/fonts/NotoSansElbasan-Regular.ttf +0 -0
  32. data/fonts/NotoSansEthiopic-Regular.ttf +0 -0
  33. data/fonts/NotoSansGeorgian-Regular.ttf +0 -0
  34. data/fonts/NotoSansGrantha-Regular.ttf +0 -0
  35. data/fonts/NotoSansGujarati-Regular.ttf +0 -0
  36. data/fonts/NotoSansGunjalaGondi-Regular.ttf +0 -0
  37. data/fonts/NotoSansGurmukhi-Regular.ttf +0 -0
  38. data/fonts/NotoSansHanifiRohingya-Regular.ttf +0 -0
  39. data/fonts/NotoSansHanunoo-Regular.ttf +0 -0
  40. data/fonts/NotoSansHebrew-Regular.ttf +0 -0
  41. data/fonts/NotoSansJP-Regular.otf +0 -0
  42. data/fonts/NotoSansJavanese-Regular.ttf +0 -0
  43. data/fonts/NotoSansKR-Regular.otf +0 -0
  44. data/fonts/NotoSansKannada-Regular.ttf +0 -0
  45. data/fonts/NotoSansKayahLi-Regular.ttf +0 -0
  46. data/fonts/NotoSansKhmer-Regular.ttf +0 -0
  47. data/fonts/NotoSansKhojki-Regular.ttf +0 -0
  48. data/fonts/NotoSansKhudawadi-Regular.ttf +0 -0
  49. data/fonts/NotoSansLao-Regular.ttf +0 -0
  50. data/fonts/NotoSansLepcha-Regular.ttf +0 -0
  51. data/fonts/NotoSansLimbu-Regular.ttf +0 -0
  52. data/fonts/NotoSansLisu-Regular.ttf +0 -0
  53. data/fonts/NotoSansMahajani-Regular.ttf +0 -0
  54. data/fonts/NotoSansMalayalam-Regular.ttf +0 -0
  55. data/fonts/NotoSansMandaic-Regular.ttf +0 -0
  56. data/fonts/NotoSansMasaramGondi-Regular.ttf +0 -0
  57. data/fonts/NotoSansMedefaidrin-Regular.ttf +0 -0
  58. data/fonts/NotoSansMeeteiMayek-Regular.ttf +0 -0
  59. data/fonts/NotoSansMendeKikakui-Regular.ttf +0 -0
  60. data/fonts/NotoSansMiao-Regular.ttf +0 -0
  61. data/fonts/NotoSansModi-Regular.ttf +0 -0
  62. data/fonts/NotoSansMongolian-Regular.ttf +0 -0
  63. data/fonts/NotoSansMro-Regular.ttf +0 -0
  64. data/fonts/NotoSansMultani-Regular.ttf +0 -0
  65. data/fonts/NotoSansNKo-Regular.ttf +0 -0
  66. data/fonts/NotoSansNewTaiLue-Regular.ttf +0 -0
  67. data/fonts/NotoSansNewa-Regular.ttf +0 -0
  68. data/fonts/NotoSansOlChiki-Regular.ttf +0 -0
  69. data/fonts/NotoSansOriya-Regular.ttf +0 -0
  70. data/fonts/NotoSansOsage-Regular.ttf +0 -0
  71. data/fonts/NotoSansOsmanya-Regular.ttf +0 -0
  72. data/fonts/NotoSansPahawhHmong-Regular.ttf +0 -0
  73. data/fonts/NotoSansPauCinHau-Regular.ttf +0 -0
  74. data/fonts/NotoSansRejang-Regular.ttf +0 -0
  75. data/fonts/NotoSansRunic-Regular.ttf +0 -0
  76. data/fonts/NotoSansSC-Regular.otf +0 -0
  77. data/fonts/NotoSansSamaritan-Regular.ttf +0 -0
  78. data/fonts/NotoSansSaurashtra-Regular.ttf +0 -0
  79. data/fonts/NotoSansSharada-Regular.ttf +0 -0
  80. data/fonts/NotoSansShavian-Regular.ttf +0 -0
  81. data/fonts/NotoSansSinhala-Regular.ttf +0 -0
  82. data/fonts/NotoSansSoraSompeng-Regular.ttf +0 -0
  83. data/fonts/NotoSansSoyombo-Regular.ttf +0 -0
  84. data/fonts/NotoSansSundanese-Regular.ttf +0 -0
  85. data/fonts/NotoSansSylotiNagri-Regular.ttf +0 -0
  86. data/fonts/NotoSansSymbols-Regular.ttf +0 -0
  87. data/fonts/NotoSansSymbols2-Regular.ttf +0 -0
  88. data/fonts/NotoSansSyriac-Regular.ttf +0 -0
  89. data/fonts/NotoSansTC-Regular.otf +0 -0
  90. data/fonts/NotoSansTagalog-Regular.ttf +0 -0
  91. data/fonts/NotoSansTagbanwa-Regular.ttf +0 -0
  92. data/fonts/NotoSansTaiLe-Regular.ttf +0 -0
  93. data/fonts/NotoSansTaiTham-Regular.ttf +0 -0
  94. data/fonts/NotoSansTaiViet-Regular.ttf +0 -0
  95. data/fonts/NotoSansTakri-Regular.ttf +0 -0
  96. data/fonts/NotoSansTamil-Regular.ttf +0 -0
  97. data/fonts/NotoSansTelugu-Regular.ttf +0 -0
  98. data/fonts/NotoSansThaana-Regular.ttf +0 -0
  99. data/fonts/NotoSansThai-Regular.ttf +0 -0
  100. data/fonts/NotoSansTifinagh-Regular.ttf +0 -0
  101. data/fonts/NotoSansTifinaghAPT-Regular.ttf +0 -0
  102. data/fonts/NotoSansTifinaghAdrar-Regular.ttf +0 -0
  103. data/fonts/NotoSansTifinaghAgrawImazighen-Regular.ttf +0 -0
  104. data/fonts/NotoSansTifinaghAhaggar-Regular.ttf +0 -0
  105. data/fonts/NotoSansTifinaghAir-Regular.ttf +0 -0
  106. data/fonts/NotoSansTifinaghAzawagh-Regular.ttf +0 -0
  107. data/fonts/NotoSansTifinaghGhat-Regular.ttf +0 -0
  108. data/fonts/NotoSansTifinaghHawad-Regular.ttf +0 -0
  109. data/fonts/NotoSansTifinaghRhissaIxa-Regular.ttf +0 -0
  110. data/fonts/NotoSansTifinaghSIL-Regular.ttf +0 -0
  111. data/fonts/NotoSansTifinaghTawellemmet-Regular.ttf +0 -0
  112. data/fonts/NotoSansTirhuta-Regular.ttf +0 -0
  113. data/fonts/NotoSansVai-Regular.ttf +0 -0
  114. data/fonts/NotoSansWancho-Regular.ttf +0 -0
  115. data/fonts/NotoSansWarangCiti-Regular.ttf +0 -0
  116. data/fonts/NotoSansYi-Regular.ttf +0 -0
  117. data/fonts/NotoSansZanabazarSquare-Regular.ttf +0 -0
  118. data/fonts/NotoSerifArmenian-Regular.ttf +0 -0
  119. data/fonts/NotoSerifBalinese-Regular.ttf +0 -0
  120. data/fonts/NotoSerifBengali-Regular.ttf +0 -0
  121. data/fonts/NotoSerifDevanagari-Regular.ttf +0 -0
  122. data/fonts/NotoSerifDogra-Regular.ttf +0 -0
  123. data/fonts/NotoSerifEthiopic-Regular.ttf +0 -0
  124. data/fonts/NotoSerifGeorgian-Regular.ttf +0 -0
  125. data/fonts/NotoSerifGrantha-Regular.ttf +0 -0
  126. data/fonts/NotoSerifGujarati-Regular.ttf +0 -0
  127. data/fonts/NotoSerifGurmukhi-Regular.ttf +0 -0
  128. data/fonts/NotoSerifHebrew-Regular.ttf +0 -0
  129. data/fonts/NotoSerifKannada-Regular.ttf +0 -0
  130. data/fonts/NotoSerifKhmer-Regular.ttf +0 -0
  131. data/fonts/NotoSerifKhojki-Regular.ttf +0 -0
  132. data/fonts/NotoSerifLao-Regular.ttf +0 -0
  133. data/fonts/NotoSerifMalayalam-Regular.ttf +0 -0
  134. data/fonts/NotoSerifMyanmar-Regular.ttf +0 -0
  135. data/fonts/NotoSerifNPHmong-Regular.ttf +0 -0
  136. data/fonts/NotoSerifSinhala-Regular.ttf +0 -0
  137. data/fonts/NotoSerifTamil-Regular.ttf +0 -0
  138. data/fonts/NotoSerifTelugu-Regular.ttf +0 -0
  139. data/fonts/NotoSerifThai-Regular.ttf +0 -0
  140. data/fonts/NotoSerifTibetan-Regular.ttf +0 -0
  141. data/fonts/NotoSerifYezidi-Regular.ttf +0 -0
  142. data/fonts/Pyidaungsu-2.5.3_Regular.ttf +0 -0
  143. data/fonts/STIXTwoMath-Regular.otf +0 -0
  144. data/fonts/Tinos-Bold.ttf +0 -0
  145. data/fonts/Tinos-BoldItalic.ttf +0 -0
  146. data/fonts/Tinos-Italic.ttf +0 -0
  147. data/fonts/Tinos-Regular.ttf +0 -0
  148. data/fonts/TwemojiMozilla.ttf +0 -0
  149. data/fonts/fonts.conf +183 -0
  150. data/lib/selenium_tor.rb +5 -1
  151. data/lib/tor/driver.rb +26 -12
  152. data/lib/tor/error.rb +18 -0
  153. data/lib/tor/libxul_checksums.yml +56 -0
  154. data/lib/tor/libxul_patchable.rb +13 -13
  155. data/lib/tor/options.rb +13 -29
  156. data/lib/tor/tor_prefs.rb +2 -2
  157. data/lib/tor/tor_process.rb +42 -13
  158. data/lib/tor/torrc.rb +14 -9
  159. data/lib/tor/version.rb +1 -1
  160. metadata +150 -6
  161. data/lib/tor/system_tor.rb +0 -17
Binary file
Binary file
data/fonts/fonts.conf ADDED
@@ -0,0 +1,183 @@
1
+ <?xml version="1.0"?>
2
+ <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
3
+ <!--
4
+ **DO NOT EDIT THIS FILE!**
5
+ This file sets Tor Browser's bundled fonts as the only available system fonts
6
+ and standardizes rendering settings.
7
+ Any changes might deanonymize you, or expose you to fingerprinting vectors.
8
+ -->
9
+ <!--
10
+ Derived from fonts.conf.in of Fontconfig.
11
+
12
+ Copyright © 2000,2001,2002,2003,2004,2006,2007 Keith Packard
13
+ Copyright © 2005 Patrick Lam
14
+ Copyright © 2009 Roozbeh Pournader
15
+ Copyright © 2008,2009 Red Hat, Inc.
16
+ Copyright © 2008 Danilo Šegan
17
+ Copyright © 2012 Google, Inc.
18
+
19
+
20
+ Permission to use, copy, modify, distribute, and sell this software and its
21
+ documentation for any purpose is hereby granted without fee, provided that
22
+ the above copyright notice appear in all copies and that both that
23
+ copyright notice and this permission notice appear in supporting
24
+ documentation, and that the name of the author(s) not be used in
25
+ advertising or publicity pertaining to distribution of the software without
26
+ specific, written prior permission. The authors make no
27
+ representations about the suitability of this software for any purpose. It
28
+ is provided "as is" without express or implied warranty.
29
+
30
+ THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
31
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
32
+ EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
33
+ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
34
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
35
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
36
+ PERFORMANCE OF THIS SOFTWARE.
37
+ -->
38
+ <fontconfig>
39
+
40
+ <!-- Font directory list -->
41
+
42
+ <dir prefix="cwd">fonts</dir>
43
+
44
+ <!--
45
+ Accept deprecated 'mono' alias, replacing it with 'monospace'
46
+ -->
47
+ <match target="pattern">
48
+ <test qual="any" name="family">
49
+ <string>mono</string>
50
+ </test>
51
+ <edit name="family" mode="assign" binding="same">
52
+ <string>monospace</string>
53
+ </edit>
54
+ </match>
55
+
56
+ <!--
57
+ Accept alternate 'sans serif' spelling, replacing it with 'sans-serif'
58
+ -->
59
+ <match target="pattern">
60
+ <test qual="any" name="family">
61
+ <string>sans serif</string>
62
+ </test>
63
+ <edit name="family" mode="assign" binding="same">
64
+ <string>sans-serif</string>
65
+ </edit>
66
+ </match>
67
+
68
+ <!--
69
+ Accept deprecated 'sans' alias, replacing it with 'sans-serif'
70
+ -->
71
+ <match target="pattern">
72
+ <test qual="any" name="family">
73
+ <string>sans</string>
74
+ </test>
75
+ <edit name="family" mode="assign" binding="same">
76
+ <string>sans-serif</string>
77
+ </edit>
78
+ </match>
79
+
80
+ <!--
81
+ Set our default generic families.
82
+ -->
83
+ <match target="pattern">
84
+ <test qual="any" name="family">
85
+ <string>sans-serif</string>
86
+ </test>
87
+ <edit name="family" mode="assign" binding="same">
88
+ <string>Arimo</string>
89
+ </edit>
90
+ </match>
91
+ <match target="pattern">
92
+ <test qual="any" name="family">
93
+ <string>serif</string>
94
+ </test>
95
+ <edit name="family" mode="assign" binding="same">
96
+ <string>Tinos</string>
97
+ </edit>
98
+ </match>
99
+ <match target="pattern">
100
+ <test qual="any" name="family">
101
+ <string>monospace</string>
102
+ </test>
103
+ <edit name="family" mode="assign" binding="same">
104
+ <string>Cousine</string>
105
+ </edit>
106
+ </match>
107
+
108
+ <!--
109
+ tor-browser#41799, tor-browser-build#41237: Add some aliases for
110
+ compatibility.
111
+ -->
112
+ <match target="pattern">
113
+ <test qual="any" name="family">
114
+ <string>Arial</string>
115
+ </test>
116
+ <edit name="family" mode="assign" binding="same">
117
+ <string>Arimo</string>
118
+ </edit>
119
+ </match>
120
+ <match target="pattern">
121
+ <test qual="any" name="family">
122
+ <string>Times New Roman</string>
123
+ </test>
124
+ <edit name="family" mode="assign" binding="same">
125
+ <string>Tinos</string>
126
+ </edit>
127
+ </match>
128
+ <match target="pattern">
129
+ <test qual="any" name="family">
130
+ <string>Courier New</string>
131
+ </test>
132
+ <edit name="family" mode="assign" binding="same">
133
+ <string>Cousine</string>
134
+ </edit>
135
+ </match>
136
+ <match target="pattern">
137
+ <test qual="any" name="family">
138
+ <string>Helvetica</string>
139
+ </test>
140
+ <edit name="family" mode="assign" binding="same">
141
+ <string>Arimo</string>
142
+ </edit>
143
+ </match>
144
+ <match target="pattern">
145
+ <test qual="any" name="family">
146
+ <string>Times</string>
147
+ </test>
148
+ <edit name="family" mode="assign" binding="same">
149
+ <string>Tinos</string>
150
+ </edit>
151
+ </match>
152
+ <match target="pattern">
153
+ <test qual="any" name="family">
154
+ <string>Courier</string>
155
+ </test>
156
+ <edit name="family" mode="assign" binding="same">
157
+ <string>Cousine</string>
158
+ </edit>
159
+ </match>
160
+
161
+ <!-- Font cache directory list -->
162
+
163
+ <cachedir prefix="xdg">fontconfig</cachedir>
164
+
165
+ <config>
166
+ <!--
167
+ Rescan configuration every 30 seconds when FcFontSetList is called
168
+ -->
169
+ <rescan>
170
+ <int>30</int>
171
+ </rescan>
172
+ </config>
173
+
174
+ <!-- Standardize rendering settings. -->
175
+ <match target="pattern">
176
+ <edit name="antialias" mode="assign"><bool>true</bool></edit>
177
+ <edit name="autohint" mode="assign"><bool>false</bool></edit>
178
+ <edit name="hinting" mode="assign"><bool>true</bool></edit>
179
+ <edit name="hintstyle" mode="assign"><const>hintfull</const></edit>
180
+ <edit name="lcdfilter" mode="assign"><const>lcddefault</const></edit>
181
+ <edit name="rgba" mode="assign"><const>none</const></edit>
182
+ </match>
183
+ </fontconfig>
data/lib/selenium_tor.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'selenium-webdriver'
3
+ ENV['SE_OFFLINE'] = 'true' # we don't want selenium-manager getting & using firefox in error
4
+ ENV['SE_AVOID_STATS'] = 'true' # no telemetry thanks!
5
+
6
+ load 'selenium-webdriver.rb' # force load to ensure env vars are applied
7
+
4
8
  require_relative 'driver'
data/lib/tor/driver.rb CHANGED
@@ -18,12 +18,20 @@ module Selenium
18
18
  class Driver < DelegateClass(DriverDelegate)
19
19
  extend LibxulPatchable
20
20
 
21
- TORRC_PATH_PREF = 'extensions.torlauncher.torrc_path'
22
- TORRC = 'torrc'
23
- BROWSER_SECURITY_LEVEL_PREF = 'browser.security_level.security_slider'
24
- DOMAIN_ISOLATOR = 'TorDomainIsolator' # ES6 module
25
- NEW_CIRCUIT = 'newCircuitForDomain' # js function
26
- TB_SEC_LEVELS = { 'standard' => 4, 'safer' => 2, 'safest' => 1 }.freeze
21
+ TORRC = 'torrc'
22
+
23
+ PREF_BROWSER_SECURITY_LEVEL = 'browser.security_level.security_slider'
24
+ PREF_TORRC_PATH = 'extensions.torlauncher.torrc_path'
25
+ PREF_SOCKS_PORT = 'network.proxy.socks_port'
26
+
27
+ DOMAIN_ISOLATOR = 'TorDomainIsolator' # ES6 module
28
+ NEW_CIRCUIT = 'newCircuitForDomain' # js function
29
+
30
+ TB_SEC_LEVELS = { 'standard' => 4, 'safer' => 2, 'safest' => 1 }.freeze
31
+
32
+ LOCALHOST_PORT_REGEXP = /127\.0\.0\.1:(\d+)/
33
+
34
+ attr_reader :tor_process
27
35
 
28
36
  def initialize(options: nil, **)
29
37
  @data_dir = Dir.mktmpdir
@@ -31,7 +39,8 @@ module Selenium
31
39
  add_torrc_path_to_options
32
40
  @instance = DriverDelegate.new(options: @options, **)
33
41
  install_extensions @instance
34
- create_tor_process_and_start_tor @options.tor_opts
42
+ pid = create_tor_process_and_start_tor(@options.tor_opts)
43
+ @instance.pref[PREF_SOCKS_PORT] = socks_port(pid)
35
44
  super(@instance)
36
45
  end
37
46
 
@@ -46,13 +55,13 @@ module Selenium
46
55
  end
47
56
 
48
57
  def security_level
49
- pref[BROWSER_SECURITY_LEVEL_PREF]
58
+ pref[PREF_BROWSER_SECURITY_LEVEL]
50
59
  end
51
60
 
52
61
  def security_level=(int)
53
62
  raise(ArgumentError, "Valid security levels are: #{TB_SEC_LEVELS.values}") unless TB_SEC_LEVELS.value?(int)
54
63
 
55
- pref[BROWSER_SECURITY_LEVEL_PREF] = int
64
+ pref[PREF_BROWSER_SECURITY_LEVEL] = int
56
65
  end
57
66
 
58
67
  def new_circuit_for_site
@@ -64,7 +73,7 @@ module Selenium
64
73
  private
65
74
 
66
75
  def add_torrc_path_to_options
67
- @options.prefs[TORRC_PATH_PREF] = File.join(@data_dir, TORRC)
76
+ @options.prefs[PREF_TORRC_PATH] = File.join(@data_dir, TORRC)
68
77
  end
69
78
 
70
79
  def install_extensions(instance)
@@ -73,20 +82,25 @@ module Selenium
73
82
 
74
83
  def create_tor_process_and_start_tor(opts)
75
84
  timeout = opts.delete :timeout
76
- @tor_process = tor_process(opts)
85
+ @tor_process = create_tor_process(opts)
77
86
  @tor_process.start_tor(timeout: timeout)
78
87
  rescue Tor::TorProcess::TorProcessError => e
79
88
  instance_variable_get(:@instance)&.quit # avoids hanging firefox.real process
80
89
  raise Error::WebDriverError, e
81
90
  end
82
91
 
83
- def tor_process(opts)
92
+ def create_tor_process(opts)
84
93
  TorProcess.new(@data_dir, opts || {})
85
94
  end
86
95
 
87
96
  def domain
88
97
  URI(current_url).host&.match(/[^\.]+\.\w+$/)
89
98
  end
99
+
100
+ def socks_port(pid)
101
+ str = `netstat -tnlp 2>/dev/null|grep #{pid}/tor` # net-tools dep
102
+ str.match(LOCALHOST_PORT_REGEXP)[1].to_i
103
+ end
90
104
  end
91
105
  end
92
106
  end
data/lib/tor/error.rb ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal:true
2
+
3
+ require 'selenium-webdriver'
4
+
5
+ # errors
6
+ module Selenium
7
+ module WebDriver
8
+ module Tor
9
+ class Error < WebDriver::Error::WebDriverError; end
10
+
11
+ class TorrcError < Error; end
12
+
13
+ class TorProcessError < Error; end
14
+
15
+ class LibxulPatchableError < Error; end
16
+ end
17
+ end
18
+ end
@@ -1,8 +1,64 @@
1
1
  ---
2
+ 14.5.3:
3
+ unpatched_libxul: 88c9aef61ca0df4c617a8c7c589194bd8ff31d1d7a6360512e1ab1cfc81390a8
4
+ patched_libxul: 18e6f350a2a8983395ffac984aac1a7a431d2acb0c97faa69d6f965199b67e2c
5
+ patch_checksum: b216ba4ad661e79e9cbf648837e1f18282490ee504f5970a2cb1ae7f847dd271
6
+ 14.5.2:
7
+ unpatched_libxul: 0e4d960cb427df67a25ab50aa934272e7ac7ee3487c709e48d97e2611e2ae930
8
+ patched_libxul: 20579db140991d77db1a3ffa3e248752dd689bf4156056402cbe1fd6287430c1
9
+ patch_checksum: d6db59104c809ee3c9232e093e85b34abc02069ccf63beb2102f371492fcd42d
10
+ 14.5.1:
11
+ unpatched_libxul: d3fb74cad36cb0b944b6db87d9377e81b54b0ba1dc9ffecef3ffbf95ab5f6c56
12
+ patched_libxul: 0092fe0b27e0bc4be47b1f925509064494effea370023bc91e39f254dc52d341
13
+ patch_checksum: 3746698dfe5ed5d0f56d28fa9655aff2c908252bed51f584e4822d8581e6a24f
14
+ !!str 14.5:
15
+ unpatched_libxul: 8518f1b2b6b76b2d17fd32189b16e25898a4ae3bf6981613feecdec290363232
16
+ patched_libxul: f58a11c36cc91fefab1cf92de822d70b0f3d17e38b32c4fa37ba8287529b40c3
17
+ patch_checksum: 852b152872338a3d0c097607f7f2aa0b41729136bfe661bcc8427dc61789c630
18
+ 14.5a6:
19
+ unpatched_libxul: 7cdfdf7fa84ea5a31607595114d33d77d27eb1fea814835735c0bc0f6484a5b7
20
+ patched_libxul: 622f8635cf4cc82cc8c4c2db03bae44123d79c50ee910795b1f1dbe4351c9ca3
21
+ patch_checksum: 44682be0e6b8d885f769fc30daa4f2fdbe64367935f5f88ef6ded29a397101c5
22
+ 14.5a5:
23
+ unpatched_libxul: d96ab04398a1d2636be475ecc3cca747a496213c78d778304d2953b48342af3e
24
+ patched_libxul: 5c3e72fc6d477735013d7079828aa99cc47c662c58a7ab48fec600f159987c38
25
+ patch_checksum: 31aeb887eadaff88c19bcd989f6e2530f2ac931a4169e314853116ff568e0250
26
+ 14.5a4:
27
+ unpatched_libxul: 86b62b1794005a400fd204d130ae0dbd7e69db67e66d0db9cc374aee5a0eafdb
28
+ patched_libxul: 38a7ffff8cb094b7987b413ed5406699b2b137cee5d260f0da7d9b9289a36818
29
+ patch_checksum: e018a62d07829f4bdfc8ebf6ff2555b6705ea938c5cfdb3667b05fd118e25efe
30
+ 14.5a3:
31
+ unpatched_libxul: 2c865e239e20aeb785c830a922aa197cbd87337669b05ea0c0d43dc4b101efe7
32
+ patched_libxul: c9a0a33e747268269e269e2a01618e3f8db0c11d080a3867014e11b08b5d2be5
33
+ patch_checksum: 7977048cde11319a9e5a337ace40abc30e63e7be7808b438105cd90b2397beaf
34
+ 14.5a2:
35
+ unpatched_libxul: 764f91909cac9c90208aaa70001a52cba43ec02d8b0dab69809e542f39a3c0a2
36
+ patched_libxul: 3fc4c32bde0bd9f1e1ac2d22a936d9912db0cf5f5510227906dca8abb3d4648b
37
+ patch_checksum: 24cdd9a7755093222faff66fa79bc9c7580503c760d2fae6e0835e3c33b0dade
2
38
  14.5a1:
3
39
  unpatched_libxul: 4586056dfd6584effa61f974e802b5b2103965326716423c2f76043e68571149
4
40
  patched_libxul: b4463dffe43a112e509764c5e32b100bc2749112dc852244ed8817b72e631642
5
41
  patch_checksum: a0397d3e9a86339c497bcedf3b8c4bed767284e9299e791e54266d42c2872b7d
42
+ 14.0.9:
43
+ unpatched_libxul: b52659cb3a202ef69acd8ba37360467daf17d7b90afdf1419f7dbefb872979cc
44
+ patched_libxul: af9c6c3822664f2084b404d9fd34d2e6a2d3f7d2d71f25cf9dde9e97018302fa
45
+ patch_checksum: 88188dfbd38bd84fa5bd5f82634fc009543ea3e16ba756ea02ffb11dd7875de6
46
+ 14.0.7:
47
+ unpatched_libxul: 649f05fd66e6e84fbde94907571d5bc34b59f06974cb2ebb60d1847c3c0eb1cc
48
+ patched_libxul: 15d8aaf658bc08b0990525ca4b45539a43e8249541f102bb19cb9050420b6047
49
+ patch_checksum: b30c3a09eb0a77c23f3c691c8c1a369ca8b1fefd209391e93a077779e60298a1
50
+ 14.0.6:
51
+ unpatched_libxul: a421a0cd73815c323ab6c2c5c676e5177425ae65830290a147ec6efbd5e25388
52
+ patched_libxul: e7a21cef56b25bc4b1364f953505cf8f74147fc5b48c73d204c17ab10696dae0
53
+ patch_checksum: 2a9d08a8d21f7ab07df7d2d4ba24c0cbde9b05cebb3f38bfa5953e22c06482c9
54
+ 14.0.5:
55
+ unpatched_libxul: 77d68b6ab27058addd192ba1cb23afb16eccc6bee3d96e1f2f72e1f80c6a09e6
56
+ patched_libxul: a5786dc865dc673f3290d55d3da324e0209f427678544f5c37e667755b2437ec
57
+ patch_checksum: be36849ddf1fe51922a3c192d2e97232d93ad62e1bfb2f00e98e2dcbc26a06e3
58
+ 14.0.4:
59
+ unpatched_libxul: 994b21b5417e704be58107cc6308de6e1c922f0cf60b9df2aac0e4f0090f373f
60
+ patched_libxul: ae03c3e7217b85c0f28b4d971b695f0d042723447c84a8676a372f32e7b76252
61
+ patch_checksum: d9f32d00ff1050774f1a90d3055f69ebac113261c082fab621244547c6ef41f5
6
62
  14.0.3:
7
63
  unpatched_libxul: 2ddc3df2e8feb52c3bcd638249aac7d584d9c65888d67e18ad5fecceb4d5010a
8
64
  patched_libxul: 9864cdfd750e504f06bd9eeca427f0a20d83d0bb5cd8e8232ae4a3ee4b2812b1
@@ -5,6 +5,8 @@ require 'digest'
5
5
  require 'json'
6
6
  require 'open-uri'
7
7
  require 'yaml'
8
+
9
+ require_relative 'error'
8
10
  require_relative 'options' # module needs access to consts therein defined
9
11
 
10
12
  module Selenium
@@ -12,19 +14,17 @@ module Selenium
12
14
  module Tor
13
15
  # methods to patch/unpatch libxul.so
14
16
  module LibxulPatchable
15
- class LibxulPatchableError < StandardError; end
16
-
17
- PATCH_REPO = 'https://gitlab.com/matzfan/keymaster/-/raw/master/patches/tor-browser'
18
- ISSUES_URL = 'https://gitlab.com/matzfan/keymaster/-/issues'
19
- NO_PATCH_MSG = "No patch for #{Tor::TBB_VERSION}, please raise an issue at #{ISSUES_URL}".freeze
20
- UNDEF_REGEXP = /undefined method (`|')\[\]' for nil/
17
+ PATCH_REPO_URL = 'https://gitlab.com/matzfan/keymaster/-/raw/master/patches/tor-browser'
18
+ ISSUES_URL = 'https://gitlab.com/matzfan/keymaster/-/issues'
19
+ NO_PATCH_MSG = "No patch for #{Tor::TBB_VERSION}, please raise an issue at #{ISSUES_URL}".freeze
20
+ UNDEF_REGEXP = /undefined method (`|')\[\]' for nil/
21
21
 
22
22
  def libxul_patched?
23
23
  libxul_checksum = checksum_for Tor::TBB_LIBXUL
24
24
  return true if patched_libxul_checksum_for_version == libxul_checksum
25
25
  return false if unpatched_libxul_checksum_for_version == libxul_checksum
26
26
 
27
- raise LibxulPatchableError, 'Unrecognized libxul.so'
27
+ raise Tor::LibxulPatchableError, 'Unrecognized libxul.so'
28
28
  end
29
29
 
30
30
  def patch_libxul
@@ -36,7 +36,7 @@ module Selenium
36
36
  execute_patch patchfile
37
37
  FileUtils.cp libxul_patched, Tor::TBB_LIBXUL
38
38
  rescue OpenURI::HTTPError
39
- raise LibxulPatchableError, NO_PATCH_MSG
39
+ raise Tor::LibxulPatchableError, NO_PATCH_MSG
40
40
  end
41
41
 
42
42
  def unpatch_libxul
@@ -57,7 +57,7 @@ module Selenium
57
57
 
58
58
  def valid?(patchfile)
59
59
  msg = "Invalid patch for #{Tor::TBB_VERSION}, please raise an issue at #{ISSUES_URL}"
60
- raise LibxulPatchableError, msg unless patch_checksum_for_version == checksum_for(patchfile)
60
+ raise Tor::LibxulPatchableError, msg unless patch_checksum_for_version == checksum_for(patchfile)
61
61
  end
62
62
 
63
63
  def execute_patch(patchfile)
@@ -71,7 +71,7 @@ module Selenium
71
71
  def unpatched_libxul_checksum_for_version
72
72
  libxul_checksums['unpatched_libxul']
73
73
  rescue NoMethodError => e
74
- raise LibxulPatchableError, NO_PATCH_MSG if e.message.match UNDEF_REGEXP
74
+ raise Tor::LibxulPatchableError, NO_PATCH_MSG if e.message.match UNDEF_REGEXP
75
75
 
76
76
  raise e
77
77
  end
@@ -79,7 +79,7 @@ module Selenium
79
79
  def patched_libxul_checksum_for_version
80
80
  libxul_checksums['patched_libxul']
81
81
  rescue NoMethodError => e
82
- raise LibxulPatchableError, NO_PATCH_MSG if e.message.match UNDEF_REGEXP
82
+ raise Tor::LibxulPatchableError, NO_PATCH_MSG if e.message.match UNDEF_REGEXP
83
83
 
84
84
  raise e
85
85
  end
@@ -87,7 +87,7 @@ module Selenium
87
87
  def patch_checksum_for_version
88
88
  libxul_checksums['patch_checksum']
89
89
  rescue NoMethodError => e
90
- raise LibxulPatchableError, NO_PATCH_MSG if e.message.match UNDEF_REGEXP
90
+ raise Tor::LibxulPatchableError, NO_PATCH_MSG if e.message.match UNDEF_REGEXP
91
91
 
92
92
  raise e
93
93
  end
@@ -106,7 +106,7 @@ module Selenium
106
106
  end
107
107
 
108
108
  def patch_url
109
- File.join PATCH_REPO, "#{Tor::TBB_VERSION}.patch"
109
+ File.join PATCH_REPO_URL, "#{Tor::TBB_VERSION}.patch"
110
110
  end
111
111
  end
112
112
  end
data/lib/tor/options.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'tor_prefs'
4
- require_relative 'system_tor'
5
4
  require 'selenium-webdriver'
6
5
 
7
6
  module Selenium
@@ -9,27 +8,24 @@ module Selenium
9
8
  module Tor
10
9
  # tor options
11
10
  class Options < Firefox::Options
12
- CAPABILITIES = CAPABILITIES.merge(tor_opts: 'tor_opts')
13
- CAPABILITIES[:system_tor] = 'system_tor' # DEPRECATED 2.0
11
+ CAPABILITIES = CAPABILITIES.merge(tor_opts: 'tor_opts')
14
12
  DEFAULT_TBB_DIR = File.join Dir.home, 'tor-browser'
15
13
 
16
- Tor::TBB_DIR = ENV.fetch('TOR_BROWSER_ROOT_DIR', nil) || DEFAULT_TBB_DIR
17
- Tor::TBB_BROWSER_DIR = File.join Tor::TBB_DIR, 'Browser'
18
- Tor::TBB_LIBXUL = File.join Tor::TBB_BROWSER_DIR, 'libxul.so'
19
- Tor::TBB_BINARY_PATH = File.join Tor::TBB_BROWSER_DIR, 'firefox'
14
+ Tor::TBB_DIR = ENV.fetch('TOR_BROWSER_ROOT_DIR', nil) || DEFAULT_TBB_DIR
15
+ Tor::TBB_BROWSER_DIR = File.join Tor::TBB_DIR, 'Browser'
16
+ Tor::TBB_LIBXUL = File.join Tor::TBB_BROWSER_DIR, 'libxul.so'
17
+ Tor::TBB_BINARY_PATH = File.join Tor::TBB_BROWSER_DIR, 'firefox'
20
18
  Tor::TBB_TOR_BINARY_PATH = File.join Tor::TBB_BROWSER_DIR, *%w[TorBrowser Tor tor]
21
- Tor::TBB_TOR_DATA_DIR = File.join Tor::TBB_BROWSER_DIR, *%w[TorBrowser Data Tor]
22
- Tor::TBB_PROFILE_DIR = File.join Tor::TBB_BROWSER_DIR, *%w[TorBrowser Data Browser profile.default]
23
- Tor::TBB_EXTENSIONS_DIR = File.join Tor::TBB_PROFILE_DIR, 'extensions'
24
- Tor::TBB_VERSION = JSON.parse(File.read(File.join(Tor::TBB_BROWSER_DIR, 'tbb_version.json')))['version']
19
+ Tor::TBB_TOR_DATA_DIR = File.join Tor::TBB_BROWSER_DIR, *%w[TorBrowser Data Tor]
20
+ Tor::TBB_PROFILE_DIR = File.join Tor::TBB_BROWSER_DIR, *%w[TorBrowser Data Browser profile.default]
21
+ Tor::TBB_EXTENSIONS_DIR = File.join Tor::TBB_PROFILE_DIR, 'extensions'
22
+ Tor::TBB_VERSION = JSON.parse(File.read(File.join(Tor::TBB_BROWSER_DIR, 'tbb_version.json')))['version']
25
23
 
26
24
  attr_reader :tor_opts
27
25
 
28
26
  def initialize(log_level: nil, **opts)
29
- opts[:tor_opts] = opts.delete(:system_tor).opts if opts[:system_tor] # DEPRECATED 2.0
30
- @tor_opts = opts[:tor_opts] ? opts.delete(:tor_opts) : {} # must be deleted before call to super
27
+ @tor_opts = opts[:tor_opts] ? opts.delete(:tor_opts) : {}
31
28
  do_start_tor_browser_script_stuff # stuff the start-tor-browser script in TBB does
32
- copy_fonts # so we don't have to change dir before executing TB binary - issues #2 and #9
33
29
  super(log_level: log_level, **tor_options(opts.delete(:prefs)).merge(opts))
34
30
  end
35
31
 
@@ -40,22 +36,10 @@ module Selenium
40
36
  end
41
37
 
42
38
  def do_start_tor_browser_script_stuff
43
- ENV['SESSION_MANAGER'] = nil
44
- ENV['XAUTHORITY'] = File.join(Dir.home, '.Xauthority') unless ENV.fetch('XAUTHORITY', nil)
45
- FileUtils.rm_rf File.join(Tor::TBB_BROWSER_DIR, *%w[TorBrowser Data fontconfig])
39
+ ENV['SESSION_MANAGER'] = nil
46
40
  ENV['GSETTINGS_BACKEND'] = 'memory'
47
- setup_font_vars if Tor::TBB_VERSION.to_f < 14.5 # DEPRECATE when 14.5 stable drops
48
- end
49
-
50
- def copy_fonts
51
- FileUtils.rm_rf File.join(File.expand_path('fonts'), '.')
52
- FileUtils.cp(Dir[File.join(Tor::TBB_BROWSER_DIR, 'fonts', '*')], File.expand_path('fonts'))
53
- end
54
-
55
- # DEPRECATE when 14.5 stable drops
56
- def setup_font_vars
57
- ENV['FONTCONFIG_PATH'] = File.join TBB_BROWSER_DIR, 'fontconfig'
58
- ENV['FONTCONFIG_FILE'] = 'fonts.conf'
41
+ ENV['XAUTHORITY'] = File.join(Dir.home, '.Xauthority') unless ENV.fetch('XAUTHORITY', nil)
42
+ FileUtils.rm_rf File.join(Tor::TBB_BROWSER_DIR, *%w[TorBrowser Data fontconfig])
59
43
  end
60
44
  end
61
45
  end
data/lib/tor/tor_prefs.rb CHANGED
@@ -17,8 +17,8 @@ module Selenium
17
17
 
18
18
  OTHER_PREFS = {
19
19
  'intl.language_notification.shown' => true, # affects font fingerprint (viewport size)
20
- 'remote.active-protocols' => 3, # CDP & BiDi future support
21
- 'extensions.torlauncher.start_tor' => false
20
+ 'remote.active-protocols' => 1, # BiDi only >= 4.32 https://github.com/SeleniumHQ/selenium/pull/15224/files
21
+ 'extensions.torlauncher.start_tor' => false # no settings Connection pane
22
22
  }.freeze
23
23
 
24
24
  TOR_PREFS = FIRST_CONNECTION_PREFS.merge OTHER_PREFS
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'timeout'
4
+ require_relative 'error'
4
5
  require_relative 'torrc'
5
6
 
6
7
  module Selenium
@@ -8,18 +9,22 @@ module Selenium
8
9
  module Tor
9
10
  # Respresentation of a tor process
10
11
  class TorProcess
11
- class TorProcessError < StandardError; end
12
-
13
12
  BOOTSTRAP_SUCCESS_REGEX = /Bootstrapped 100% \(done\): Done$/
14
- BOOTSTRAP_FAIL_REGEX = /^[A-Z][a-z]{2} \d{2} \d{2}:\d{2}:\d{2}\.\d{3} \[err\] .*/
13
+ BOOTSTRAP_FAIL_REGEX = /^[A-Z][a-z]{2} \d{2} \d{2}:\d{2}:\d{2}\.\d{3} \[err\] .*/
14
+
15
+ DIR_MSG = 'data_dir must exist and be a dir'
16
+ DATA_FILES = %w[cached-certs cached-microdesc-consensus cached-microdescs.new].freeze
17
+
18
+ class << self
19
+ attr_accessor :cached_certs, :cached_microdesc_consensus, :cached_microdescs # set when tor first started
20
+ end
15
21
 
16
22
  attr_reader :pid, :config
17
23
 
18
24
  def initialize(data_dir, opts = {})
19
- valid_data_dir?(data_dir)
25
+ setup_data_dir data_dir
20
26
  raise ArgumentError, 'TorProcess.new takes an options hash' unless opts.is_a? Hash
21
27
 
22
- @data_dir = data_dir # each tor process needs a separate data directory
23
28
  @opts = map_opts_to_torrc_keys opts
24
29
  @torrc = Torrc.new(@data_dir)
25
30
  @config ||= setup_config # Hash to store torrc config
@@ -29,11 +34,12 @@ module Selenium
29
34
  r, io = IO.pipe
30
35
  pid = Process.spawn tor_command, out: io, err: :out
31
36
  io.close
32
- errors = parse_tor_bootstrap_errors_with_timeout(r, timeout: timeout)
33
- errors.empty? ? @pid = pid : raise(TorProcessError, "Tor failed to start with errors:\n\n#{errors}")
37
+ parse_tor_bootstrap_errors_with_timeout(r, timeout: timeout)
38
+ # tor process now bootstrapped
39
+ read_from_data_files
40
+ @pid = pid
34
41
  rescue Timeout::Error
35
- Process.kill 'KILL', pid if pid
36
- raise Error::TimeoutError, "Tor not bootstrapped after #{timeout} seconds"
42
+ timeout_with pid, timeout
37
43
  ensure
38
44
  r.close
39
45
  end
@@ -46,9 +52,18 @@ module Selenium
46
52
 
47
53
  private
48
54
 
49
- def valid_data_dir?(dir)
50
- msg = 'data_dir must exist and be a dir'
51
- raise ArgumentError, msg unless Pathname.new(dir.to_s).directory? && Pathname.new(dir.to_s).empty?
55
+ def setup_data_dir(dir)
56
+ raise ArgumentError, DIR_MSG unless Pathname.new(dir.to_s).directory? && Pathname.new(dir.to_s).empty?
57
+
58
+ @data_dir = dir # each tor process needs a separate data directory
59
+ write_data_files_to dir
60
+ end
61
+
62
+ def write_data_files_to(dir)
63
+ DATA_FILES.each do |f|
64
+ var = self.class.instance_variable_get(var_from_file(f))
65
+ File.write(File.join(dir, f), var) if var
66
+ end
52
67
  end
53
68
 
54
69
  def map_opts_to_torrc_keys(opts)
@@ -66,13 +81,27 @@ module Selenium
66
81
 
67
82
  def parse_tor_bootstrap_errors_with_timeout(io, timeout:)
68
83
  lines = []
69
- Timeout.timeout timeout do
84
+ errors = Timeout.timeout timeout do
70
85
  io.each_line do |line|
71
86
  lines << line
72
87
  break lines.join if line.match BOOTSTRAP_FAIL_REGEX
73
88
  break '' if line.match BOOTSTRAP_SUCCESS_REGEX
74
89
  end
75
90
  end
91
+ raise(Tor::TorProcessError, "Tor failed to start with errors:\n\n#{errors}") unless errors.empty?
92
+ end
93
+
94
+ def read_from_data_files
95
+ DATA_FILES.each { |f| self.class.instance_variable_set var_from_file(f), File.read(File.join(@data_dir, f)) }
96
+ end
97
+
98
+ def var_from_file(name)
99
+ :"@#{name.tr('-', '_').sub('.new', '')}"
100
+ end
101
+
102
+ def timeout_with(pid, timeout)
103
+ Process.kill 'KILL', pid if pid
104
+ raise WebDriver::Error::TimeoutError, "Tor not bootstrapped after #{timeout} seconds" # regular s-w error
76
105
  end
77
106
  end
78
107
  end