170 else: |
166 else: |
171 if "largefiles" in self.__config["extensions"]: |
167 if "largefiles" in self.__config["extensions"]: |
172 del self.__config["extensions"]["largefiles"] |
168 del self.__config["extensions"]["largefiles"] |
173 self.__config["extensions"]["#largefiles"] = "" |
169 self.__config["extensions"]["#largefiles"] = "" |
174 |
170 |
175 if self.closeheadCheckBox.isChecked() and self.__version >= (4, 8, 0): |
171 if self.closeheadCheckBox.isChecked(): |
176 self.__config["extensions"]["closehead"] = "" |
172 self.__config["extensions"]["closehead"] = "" |
177 else: |
173 else: |
178 if "closehead" in self.__config["extensions"]: |
174 if "closehead" in self.__config["extensions"]: |
179 del self.__config["extensions"]["closehead"] |
175 del self.__config["extensions"]["closehead"] |
180 self.__config["extensions"]["#closehead"] = "" |
176 self.__config["extensions"]["#closehead"] = "" |
|
177 |
|
178 if self.fastexportCheckBox.isChecked(): |
|
179 self.__config["extensions"]["fastexport"] = "" |
|
180 else: |
|
181 if "fastexport" in self.__config["extensions"]: |
|
182 del self.__config["extensions"]["fastexport"] |
|
183 self.__config["extensions"]["#fastexport"] = "" |
|
184 |
|
185 if self.uncommitCheckBox.isChecked(): |
|
186 self.__config["extensions"]["uncommit"] = "" |
|
187 else: |
|
188 if "uncommit" in self.__config["uncommit"]: |
|
189 del self.__config["extensions"]["uncommit"] |
|
190 self.__config["extensions"]["#uncommit"] = "" |
|
191 |
181 ################################################################### |
192 ################################################################### |
182 ## http_proxy section |
193 ## http_proxy section |
183 ################################################################### |
194 ################################################################### |
184 if self.proxyHostEdit.text(): |
195 if self.proxyHostEdit.text(): |
185 self.__config["http_proxy"] = { |
196 self.__config["http_proxy"] = { |
190 if self.proxyBypassEdit.text(): |
201 if self.proxyBypassEdit.text(): |
191 self.__config["http_proxy"]["no"] = self.proxyBypassEdit.text() |
202 self.__config["http_proxy"]["no"] = self.proxyBypassEdit.text() |
192 else: |
203 else: |
193 if "http_proxy" in self.__config: |
204 if "http_proxy" in self.__config: |
194 del self.__config["http_proxy"] |
205 del self.__config["http_proxy"] |
|
206 |
195 ################################################################### |
207 ################################################################### |
196 ## hostfingerprints/hostsecurity section |
208 ## hostfingerprints/hostsecurity section |
197 ################################################################### |
209 ################################################################### |
198 if self.__version < (3, 9, 0): |
210 # |
199 # |
211 # hostsecurity section |
200 # delete hostsecurity section |
212 # |
201 # |
213 if "hostsecurity" not in self.__config: |
202 if "hostsecurity" in self.__config: |
214 self.__config["hostsecurity"] = {} |
203 del self.__config["hostsecurity"] |
215 |
204 |
216 if self.fingerprintsList.topLevelItemCount() > 0: |
205 # |
217 self.__clearFingerprints() |
206 # hostfingerprints section |
218 fingerprints = self.__assembleFingerprints() |
207 # |
219 for host in fingerprints: |
208 if self.fingerprintsList.topLevelItemCount() > 0: |
220 key = "{0}:fingerprints".format(host) |
209 self.__config["hostfingerprints"] = {} |
221 self.__config["hostsecurity"][key] = ", ".join(fingerprints[host]) |
210 for row in range(self.fingerprintsList.topLevelItemCount()): |
222 else: |
211 itm = self.fingerprintsList.topLevelItem(row) |
223 self.__clearFingerprints() |
212 fingerprint = itm.text(1) |
224 |
213 if fingerprint.startswith("sha1:"): |
225 if self.disableTls10WarningCheckBox.isChecked(): |
214 fingerprint = fingerprint[5:] |
226 disabletls10warning = "true" |
215 self.__config["hostfingerprints"][itm.text(0)] = fingerprint |
227 else: |
216 else: |
228 disabletls10warning = "false" |
217 if "hostfingerprints" in self.__config: |
229 self.__config["hostsecurity"]["disabletls10warning"] = disabletls10warning |
218 del self.__config["hostfingerprints"] |
230 |
219 else: |
231 if self.minimumProtocolComboBox.currentIndex() == 0: |
220 # |
232 self.__config.remove_option("hostsecurity", "minimumprotocol") |
221 # delete hostfingerprints section |
233 else: |
222 # |
234 minimumProtocol = self.minimumProtocolComboBox.itemData( |
223 if "hostfingerprints" in self.__config: |
235 self.minimumProtocolComboBox.currentIndex() |
224 del self.__config["hostfingerprints"] |
236 ) |
225 |
237 self.__config["hostsecurity"]["minimumprotocol"] = minimumProtocol |
226 # |
238 |
227 # hostsecurity section |
239 if self.protocolsList.topLevelItemCount() > 0: |
228 # |
240 self.__clearMinimumProtocols() |
229 if "hostsecurity" not in self.__config: |
241 minimumProtocols = self.__assembleMinimumProtocols() |
230 self.__config["hostsecurity"] = {} |
242 for host in minimumProtocols: |
231 |
243 key = "{0}:minimumprotocol".format(host) |
232 if self.fingerprintsList.topLevelItemCount() > 0: |
244 self.__config["hostsecurity"][key] = minimumProtocols[host] |
233 self.__clearFingerprints() |
245 else: |
234 fingerprints = self.__assembleFingerprints() |
246 self.__clearMinimumProtocols() |
235 for host in fingerprints: |
247 |
236 key = "{0}:fingerprints".format(host) |
248 if len(self.__config.options("hostsecurity")) == 0: |
237 self.__config["hostsecurity"][key] = ", ".join(fingerprints[host]) |
249 del self.__config["hostsecurity"] |
238 else: |
|
239 self.__clearFingerprints() |
|
240 |
|
241 if self.disableTls10WarningCheckBox.isChecked(): |
|
242 disabletls10warning = "true" |
|
243 else: |
|
244 disabletls10warning = "false" |
|
245 self.__config["hostsecurity"]["disabletls10warning"] = disabletls10warning |
|
246 |
|
247 if self.minimumProtocolComboBox.currentIndex() == 0: |
|
248 self.__config.remove_option("hostsecurity", "minimumprotocol") |
|
249 else: |
|
250 minimumProtocol = self.minimumProtocolComboBox.itemData( |
|
251 self.minimumProtocolComboBox.currentIndex() |
|
252 ) |
|
253 self.__config["hostsecurity"]["minimumprotocol"] = minimumProtocol |
|
254 |
|
255 if self.protocolsList.topLevelItemCount() > 0: |
|
256 self.__clearMinimumProtocols() |
|
257 minimumProtocols = self.__assembleMinimumProtocols() |
|
258 for host in minimumProtocols: |
|
259 key = "{0}:minimumprotocol".format(host) |
|
260 self.__config["hostsecurity"][key] = minimumProtocols[host] |
|
261 else: |
|
262 self.__clearMinimumProtocols() |
|
263 |
|
264 if len(self.__config.options("hostsecurity")) == 0: |
|
265 del self.__config["hostsecurity"] |
|
266 ################################################################### |
250 ################################################################### |
267 |
251 |
268 cfgFile = getConfigPath() |
252 cfgFile = getConfigPath() |
269 with open(cfgFile, "w") as configFile: |
253 with open(cfgFile, "w") as configFile: |
270 self.__config.write(configFile) |
254 self.__config.write(configFile) |
330 self.__config["http_proxy"]["passwd"] |
319 self.__config["http_proxy"]["passwd"] |
331 ) |
320 ) |
332 if "no" in self.__config["http_proxy"]: |
321 if "no" in self.__config["http_proxy"]: |
333 self.proxyBypassEdit.setText(self.__config["http_proxy"]["no"]) |
322 self.proxyBypassEdit.setText(self.__config["http_proxy"]["no"]) |
334 |
323 |
335 # step 5a: extract host fingerprints |
324 # step 5: extract hostsecurity fingerprints |
336 if "hostfingerprints" in self.__config: |
|
337 for host in self.__config.options("hostfingerprints"): |
|
338 if self.__version < (3, 9, 0): |
|
339 QTreeWidgetItem( |
|
340 self.fingerprintsList, |
|
341 [host, self.__config["hostfingerprints"][host]], |
|
342 ) |
|
343 else: |
|
344 # convert to hostsecurity fingerprint |
|
345 QTreeWidgetItem( |
|
346 self.fingerprintsList, |
|
347 [host, "sha1:" + self.__config["hostfingerprints"][host]], |
|
348 ) |
|
349 |
|
350 # step 5b: extract hostsecurity fingerprints |
|
351 if "hostsecurity" in self.__config: |
325 if "hostsecurity" in self.__config: |
352 for key in self.__config.options("hostsecurity"): |
326 for key in self.__config.options("hostsecurity"): |
353 if key.endswith(":fingerprints"): |
327 if key.endswith(":fingerprints"): |
354 host = key.replace(":fingerprints", "") |
328 host = key.replace(":fingerprints", "") |
355 fingerprints = self.__config["hostsecurity"][key].split(",") |
329 fingerprints = self.__config["hostsecurity"][key].split(",") |
356 for fingerprint in fingerprints: |
330 for fingerprint in fingerprints: |
357 if self.__version < (3, 9, 0): |
|
358 # downgrade from a newer version |
|
359 if fingerprint.startswith("sha1:"): |
|
360 fingerprint = fingerprint[5:] |
|
361 else: |
|
362 # Mercurial < 3.9.0 supports sha1 |
|
363 # fingerprints only |
|
364 continue |
|
365 QTreeWidgetItem( |
331 QTreeWidgetItem( |
366 self.fingerprintsList, |
332 self.fingerprintsList, |
367 [host, fingerprint.replace("\\", "").strip()], |
333 [host, fingerprint.replace("\\", "").strip()], |
368 ) |
334 ) |
369 |
335 |