tor.scm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2014, 2015 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2016, 2017, 2018, 2020, 2021 Efraim Flashner <efraim@flashner.co.il>
  5. ;;; Copyright © 2016, 2017 Nikita <nikita@n0.is>
  6. ;;; Copyright © 2017–2021 Tobias Geerinckx-Rice <me@tobias.gr>
  7. ;;; Copyright © 2017, 2018, 2019, 2021 Eric Bavier <bavier@posteo.net>
  8. ;;; Copyright © 2017 Rutger Helling <rhelling@mykolab.com>
  9. ;;; Copyright © 2018 Ricardo Wurmus <rekado@elephly.net>
  10. ;;; Copyright © 2020 Vincent Legoll <vincent.legoll@gmail.com>
  11. ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
  12. ;;; Copyright © 2020 André Batista <nandre@riseup.net>
  13. ;;; Copyright © 2021 Danial Behzadi <dani.behzi@ubuntu.com>
  14. ;;;
  15. ;;; This file is part of GNU Guix.
  16. ;;;
  17. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  18. ;;; under the terms of the GNU General Public License as published by
  19. ;;; the Free Software Foundation; either version 3 of the License, or (at
  20. ;;; your option) any later version.
  21. ;;;
  22. ;;; GNU Guix is distributed in the hope that it will be useful, but
  23. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  24. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. ;;; GNU General Public License for more details.
  26. ;;;
  27. ;;; You should have received a copy of the GNU General Public License
  28. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  29. (define-module (gnu packages tor)
  30. #:use-module ((guix licenses) #:prefix license:)
  31. #:use-module (guix packages)
  32. #:use-module (guix utils)
  33. #:use-module (guix download)
  34. #:use-module (guix git-download)
  35. #:use-module (guix build-system gnu)
  36. #:use-module (guix build-system python)
  37. #:use-module (gnu packages)
  38. #:use-module (gnu packages base)
  39. #:use-module (gnu packages libevent)
  40. #:use-module (gnu packages linux)
  41. #:use-module (gnu packages check)
  42. #:use-module (gnu packages compression)
  43. #:use-module (gnu packages pcre)
  44. #:use-module (gnu packages glib)
  45. #:use-module (gnu packages pkg-config)
  46. #:use-module (gnu packages python)
  47. #:use-module (gnu packages python-check)
  48. #:use-module (gnu packages python-crypto)
  49. #:use-module (gnu packages python-web)
  50. #:use-module (gnu packages python-xyz)
  51. #:use-module (gnu packages qt)
  52. #:use-module (gnu packages autotools)
  53. #:use-module (gnu packages tls)
  54. #:use-module (gnu packages w3m))
  55. (define-public tor
  56. (package
  57. (name "tor")
  58. (version "0.4.6.7")
  59. (source (origin
  60. (method url-fetch)
  61. (uri (string-append "https://dist.torproject.org/tor-"
  62. version ".tar.gz"))
  63. (sha256
  64. (base32
  65. "16hga7195va8v0x062dc05nbz4sm3dscifcqpl8235dj47hmqrpz"))))
  66. (build-system gnu-build-system)
  67. (arguments
  68. `(#:configure-flags
  69. (list "--enable-lzma"
  70. "--enable-zstd")
  71. #:phases
  72. (modify-phases %standard-phases
  73. (add-before 'check 'skip-practracker
  74. ;; This is a style linter. It doesn't get to throw fatal errors.
  75. (lambda _
  76. (setenv "TOR_DISABLE_PRACTRACKER" "set")
  77. #t)))))
  78. (native-inputs
  79. `(("pkg-config" ,pkg-config)
  80. ("python" ,python))) ; for tests
  81. (inputs
  82. `(("libevent" ,libevent)
  83. ("libseccomp" ,libseccomp)
  84. ("openssl" ,openssl)
  85. ("xz" ,xz)
  86. ("zlib" ,zlib)
  87. ("zstd" ,zstd "lib")))
  88. (home-page "https://www.torproject.org/")
  89. (synopsis "Anonymous network router to improve privacy on the Internet")
  90. (description
  91. "Tor protects you by bouncing your communications around a distributed
  92. network of relays run by volunteers all around the world: it prevents
  93. somebody watching your Internet connection from learning what sites you
  94. visit, and it prevents the sites you visit from learning your physical
  95. location. Tor works with many of your existing applications, including
  96. web browsers, instant messaging clients, remote login, and other
  97. applications based on the TCP protocol.
  98. This package is the full featured @code{tor} which is needed for running
  99. relays, bridges or directory authorities. If you just want to access the Tor
  100. network or to setup an onion service you may install @code{tor-client}
  101. instead.")
  102. (license license:bsd-3)))
  103. (define-public tor-client
  104. (package
  105. (inherit tor)
  106. (name "tor-client")
  107. (arguments
  108. (substitute-keyword-arguments (package-arguments tor)
  109. ((#:configure-flags flags)
  110. (append flags
  111. '("--disable-module-relay")))))
  112. (synopsis "Client to the anonymous Tor network")
  113. (description
  114. "Tor protects you by bouncing your communications around a distributed
  115. network of relays run by volunteers all around the world: it prevents
  116. somebody watching your Internet connection from learning what sites you
  117. visit, and it prevents the sites you visit from learning your physical
  118. location. Tor works with many of your existing applications, including
  119. web browsers, instant messaging clients, remote login, and other
  120. applications based on the TCP protocol.
  121. To @code{torify} applications (to take measures to ensure that an application,
  122. which has not been designed for use with Tor such as ssh, will use only Tor for
  123. internet connectivity, and also ensures that there are no leaks from DNS, UDP or
  124. the application layer) you need to install @code{torsocks}.
  125. This package only provides a client to the Tor Network.")))
  126. (define-public torsocks
  127. (package
  128. (name "torsocks")
  129. (version "2.3.0")
  130. (source (origin
  131. (method url-fetch)
  132. (uri (string-append "https://people.torproject.org/~dgoulet/"
  133. "torsocks/torsocks-" version ".tar.xz"))
  134. (sha256
  135. (base32
  136. "08inrkap29gikb6sdmb58z43hw4abwrfw7ny40c4xzdkss0vkwdr"))))
  137. (build-system gnu-build-system)
  138. (inputs
  139. `(("libcap" ,libcap)))
  140. (arguments
  141. `(#:phases (modify-phases %standard-phases
  142. (add-after 'build 'absolutize
  143. (lambda* (#:key inputs #:allow-other-keys)
  144. (substitute* "src/bin/torsocks"
  145. (("getcap=.*")
  146. (string-append "getcap=" (which "getcap") "\n")))
  147. #t)))))
  148. (home-page "https://www.torproject.org/")
  149. (synopsis "Use socks-friendly applications with Tor")
  150. (description
  151. "Torsocks allows you to use most socks-friendly applications in a safe
  152. way with Tor. It ensures that DNS requests are handled safely and explicitly
  153. rejects UDP traffic from the application you're using.")
  154. ;; All the files explicitly say "version 2 only".
  155. (license license:gpl2)))
  156. (define-public privoxy
  157. (package
  158. (name "privoxy")
  159. (version "3.0.32")
  160. (source (origin
  161. (method url-fetch)
  162. (uri (string-append "mirror://sourceforge/ijbswa/Sources/"
  163. version "%20%28stable%29/privoxy-"
  164. version "-stable-src.tar.gz"))
  165. (sha256
  166. (base32
  167. "1mzfxwnvnf1jkvfcrsivm6mjwdzjrc3h89qziz0mwi32ih0f87f6"))))
  168. (build-system gnu-build-system)
  169. (arguments
  170. '(;; The default 'sysconfdir' is $out/etc; change that to
  171. ;; $out/etc/privoxy.
  172. #:configure-flags (list (string-append "--sysconfdir="
  173. (assoc-ref %outputs "out")
  174. "/etc/privoxy")
  175. "--localstatedir=/var"
  176. "--with-brotli"
  177. "--with-openssl")
  178. #:tests? #f ; no test suite
  179. #:phases
  180. (modify-phases %standard-phases
  181. (add-after 'unpack 'patch-default-logging
  182. (lambda _
  183. (with-fluids ((%default-port-encoding "ISO-8859-1"))
  184. ;; Do not create /var/run nor /var/log/privoxy/logfile.
  185. (substitute* "GNUmakefile.in"
  186. (("(logfile \\|\\| exit )1" _ match)
  187. (string-append match "0"))
  188. (("(\\$\\(DESTDIR\\)\\$\\(SHARE_DEST\\)) \\\\" _ match)
  189. match)
  190. ((".*\\$\\(LOG_DEST\\) \\$\\(DESTDIR\\)\\$\\(PID_DEST\\).*")
  191. ""))
  192. ;; Disable logging in the default configuration to allow for
  193. ;; non-root users using it as is.
  194. (substitute* "config"
  195. (("^logdir") "#logdir")
  196. (("^logfile") "#logfile")))
  197. #t)))))
  198. (inputs
  199. `(("brotli" ,brotli)
  200. ("openssl" ,openssl)
  201. ("pcre" ,pcre)
  202. ("w3m" ,w3m)
  203. ("zlib" ,zlib)))
  204. (native-inputs
  205. `(("autoconf" ,autoconf)
  206. ("automake" ,automake)))
  207. (home-page "https://www.privoxy.org")
  208. (synopsis "Web proxy with advanced filtering capabilities for enhancing privacy")
  209. (description
  210. "Privoxy is a non-caching web proxy with advanced filtering capabilities
  211. for enhancing privacy, modifying web page data and HTTP headers, controlling
  212. access, and removing ads and other obnoxious Internet junk. Privoxy has a
  213. flexible configuration and can be customized to suit individual needs and
  214. tastes. It has application for both stand-alone systems and multi-user
  215. networks.")
  216. (license license:gpl2+)))
  217. (define-public onionshare-cli
  218. (package
  219. (name "onionshare-cli")
  220. (version "2.3.2")
  221. (source
  222. (origin
  223. (method git-fetch)
  224. (uri (git-reference
  225. (url "https://github.com/micahflee/onionshare")
  226. (commit (string-append "v" version))))
  227. (file-name (git-file-name name version))
  228. (sha256
  229. (base32 "1qk0zvbaws9md1lmi0al1jc8v86l65nf7n3w1s36iwsfzazc6clv"))))
  230. (build-system python-build-system)
  231. (native-inputs
  232. `(("python-pytest" ,python-pytest)))
  233. (inputs
  234. ;; TODO: obfs4proxy
  235. `(("python-click" ,python-click)
  236. ("python-colorama" ,python-colorama)
  237. ("python-eventlet" ,python-eventlet)
  238. ("python-flask" ,python-flask)
  239. ("python-flask-httpauth" ,python-flask-httpauth)
  240. ("python-flask-socketio" ,python-flask-socketio)
  241. ("python-psutil" ,python-psutil)
  242. ("python-pycryptodome" ,python-pycryptodome)
  243. ("python-pysocks" ,python-pysocks)
  244. ("python-requests" ,python-requests)
  245. ("python-stem" ,python-stem)
  246. ("python-unidecode" ,python-unidecode)
  247. ("python-urllib3" ,python-urllib3)
  248. ("tor" ,tor)))
  249. (arguments
  250. `(#:phases
  251. (modify-phases %standard-phases
  252. (add-after 'unpack 'bake-tor
  253. (lambda* (#:key inputs #:allow-other-keys)
  254. (substitute* (list "cli/onionshare_cli/common.py"
  255. "desktop/src/onionshare/gui_common.py")
  256. (("shutil\\.which\\(\\\"tor\\\"\\)")
  257. (string-append "\"" (which "tor") "\"")))
  258. #t))
  259. (add-before 'build 'change-directory
  260. (lambda _ (chdir "cli") #t))
  261. (replace 'check
  262. (lambda _
  263. (setenv "HOME" "/tmp")
  264. ;; Greendns is not needed for testing, and if eventlet tries to
  265. ;; load it, an OSError is thrown when getprotobyname is called.
  266. ;; Thankfully there is an environment variable to disable the
  267. ;; greendns import, so use it:
  268. (setenv "EVENTLET_NO_GREENDNS" "yes")
  269. (invoke "pytest" "-v" "./tests"))))))
  270. (home-page "https://onionshare.org/")
  271. (synopsis "Securely and anonymously share files")
  272. (description "OnionShare lets you securely and anonymously share files,
  273. host websites, and chat with friends using the Tor network.
  274. This package contains @code{onionshare-cli}, a command-line interface to
  275. OnionShare.")
  276. ;; Bundled, minified jquery and socket.io are expat licensed.
  277. (license (list license:gpl3+ license:expat))))
  278. (define-public onionshare
  279. (package (inherit onionshare-cli)
  280. (name "onionshare")
  281. (arguments
  282. (substitute-keyword-arguments (package-arguments onionshare-cli)
  283. ((#:phases phases)
  284. `(modify-phases ,phases
  285. (replace 'change-directory
  286. (lambda _ (chdir "desktop/src") #t))
  287. (add-after 'unpack 'patch-tests
  288. (lambda _
  289. ;; Disable tests that require starting servers, which will hang
  290. ;; during build:
  291. ;; - test_autostart_and_autostop_timer_mismatch
  292. ;; - test_autostart_timer
  293. ;; - test_autostart_timer_too_short
  294. ;; - test_autostop_timer_too_short
  295. (substitute* "desktop/tests/test_gui_share.py"
  296. (("import os" &)
  297. (string-append "import pytest\n" &))
  298. (("( *)def test_autost(art|op)_(timer(_too_short)?|and_[^(]*)\\(" & >)
  299. (string-append > "@pytest.mark.skip\n" &)))
  300. ;; - test_13_quit_with_server_started_should_warn
  301. (substitute* "desktop/tests/test_gui_tabs.py"
  302. (("import os" &)
  303. (string-append "import pytest\n" &))
  304. (("( *)def test_13" & >)
  305. (string-append > "@pytest.mark.skip\n" &)))
  306. ;; Remove multiline load-path adjustment, so that onionshare-cli
  307. ;; modules are loaded from input
  308. (use-modules (ice-9 regex)
  309. (ice-9 rdelim))
  310. (with-atomic-file-replacement "desktop/tests/conftest.py"
  311. (let ((start-rx (make-regexp "^# Allow importing")))
  312. (lambda (in out)
  313. (let loop ()
  314. (let ((line (read-line in 'concat)))
  315. (if (regexp-exec start-rx line)
  316. (begin ; slurp until closing paren
  317. (let slurp ()
  318. (let ((line (read-line in 'concat)))
  319. (if (string=? line ")\n")
  320. (dump-port in out) ; done
  321. (slurp)))))
  322. (begin
  323. (display line out)
  324. (loop))))))))))
  325. (replace 'check
  326. (lambda _
  327. ;; Some tests need a writable homedir:
  328. (setenv "HOME" "/tmp")
  329. ;; Ensure installed modules can be found:
  330. (setenv "PYTHONPATH"
  331. (string-append %output "/lib/python"
  332. ,(version-major+minor (package-version python))
  333. "/site-packages:"
  334. (getenv "PYTHONPATH")))
  335. ;; Avoid `getprotobyname` issues:
  336. (setenv "EVENTLET_NO_GREENDNS" "yes")
  337. ;; Make Qt render "offscreen":
  338. (setenv "QT_QPA_PLATFORM" "offscreen")
  339. ;; Must be run from "desktop" dir:
  340. (chdir "..")
  341. (invoke "./tests/run.sh")))
  342. (add-after 'install 'install-data
  343. (lambda* (#:key outputs #:allow-other-keys)
  344. (let* ((out (assoc-ref outputs "out"))
  345. (share (string-append out "/share")))
  346. (install-file "org.onionshare.OnionShare.svg"
  347. (string-append share "/icons/hicolor/scalable/apps"))
  348. (install-file "org.onionshare.OnionShare.desktop"
  349. (string-append share "/applications"))
  350. #t)))))))
  351. (native-inputs
  352. `(("python-pytest" ,python-pytest)))
  353. (inputs
  354. ;; TODO: obfs4proxy
  355. `(("onionshare-cli" ,onionshare-cli)
  356. ("python-shiboken-2" ,python-shiboken-2)
  357. ("python-pyside-2" ,python-pyside-2)
  358. ("python-qrcode" ,python-qrcode)
  359. ;; The desktop client uses onionshare-cli like a python module. But
  360. ;; propagating onionshare-cli's inputs is not great, since a user would
  361. ;; not expect to have those installed when using onionshare-cli as a
  362. ;; standalone utility. So add onionshare-cli's inputs here.
  363. ,@(package-inputs onionshare-cli)))
  364. (description "OnionShare lets you securely and anonymously share files,
  365. host websites, and chat with friends using the Tor network.")))
  366. (define-public nyx
  367. (package
  368. (name "nyx")
  369. (version "2.1.0")
  370. (source
  371. (origin
  372. (method url-fetch)
  373. (uri (pypi-uri name version))
  374. (sha256
  375. (base32
  376. "02rrlllz2ci6i6cs3iddyfns7ang9a54jrlygd2jw1f9s6418ll8"))))
  377. (build-system python-build-system)
  378. (inputs
  379. `(("python-stem" ,python-stem)))
  380. (arguments
  381. `(#:phases
  382. (modify-phases %standard-phases
  383. (add-after 'install 'install-man-page
  384. (lambda* (#:key outputs #:allow-other-keys)
  385. (let* ((out (assoc-ref outputs "out"))
  386. (man (string-append out "/share/man")))
  387. (install-file "nyx.1" (string-append man "/man1"))
  388. #t)))
  389. (add-after 'install 'install-sample-configuration
  390. (lambda* (#:key outputs #:allow-other-keys)
  391. (let* ((out (assoc-ref outputs "out"))
  392. (doc (string-append out "/share/doc/" ,name "-" ,version)))
  393. (install-file "web/nyxrc.sample" doc)
  394. #t))))
  395. ;; XXX The tests seem to require more of a real terminal than the build
  396. ;; environment provides:
  397. ;; _curses.error: setupterm: could not find terminal
  398. ;; With TERM=linux, the tests try to move the cursor and still fail:
  399. ;; _curses.error: cbreak() returned ERR
  400. #:tests? #f))
  401. (home-page "https://nyx.torproject.org/")
  402. (synopsis "Tor relay status monitor")
  403. (description
  404. "Nyx monitors the performance of relays participating in the
  405. @uref{https://www.torproject.org/, Tor anonymity network}. It displays this
  406. information visually and in real time, using a curses-based terminal interface.
  407. This makes Nyx well-suited for remote shell connections and servers without a
  408. graphical display. It's like @command{top} for Tor, providing detailed
  409. statistics and status reports on:
  410. @enumerate
  411. @item connections (with IP address, hostname, fingerprint, and consensus data),
  412. @item bandwidth, processor, and memory usage,
  413. @item the relay's current configuration,
  414. @item logged events,
  415. @item and much more.
  416. @end enumerate
  417. Potential client and exit connections are scrubbed of sensitive information.")
  418. (license license:gpl3+)))
  419. (define-public tractor
  420. (package
  421. (name "tractor")
  422. (version "3.12")
  423. (source
  424. (origin
  425. (method url-fetch)
  426. (uri (pypi-uri "traxtor" version))
  427. (sha256
  428. (base32
  429. "0bwj4l6szvx7hpjr8va3hlv0g79sxz02hsb60l61hb314c6d4r3q"))))
  430. (build-system python-build-system)
  431. (native-inputs
  432. `(("glib:bin" ,glib "bin"))) ; for glib-compile-schemas.
  433. (inputs
  434. `(("python-fire" ,python-fire)
  435. ("python-psutil" ,python-psutil)
  436. ("python-pygobject" ,python-pygobject)
  437. ("python-requests" ,python-requests)
  438. ("python-stem" ,python-stem)
  439. ("python-termcolor" ,python-termcolor)))
  440. (arguments
  441. `(#:phases
  442. (modify-phases %standard-phases
  443. (add-after 'install 'install-man-page
  444. (lambda* (#:key outputs #:allow-other-keys)
  445. (let* ((out (assoc-ref outputs "out"))
  446. (man1 (string-append out "/share/man/man1")))
  447. (install-file "tractor/man/tractor.1" man1)
  448. #t)))
  449. (add-after 'install 'install-gschema
  450. (lambda* (#:key outputs #:allow-other-keys)
  451. (let* ((out (assoc-ref outputs "out"))
  452. (schemas (string-append out "/share/glib-2.0/schemas")))
  453. (install-file "tractor/tractor.gschema.xml" schemas)
  454. #t))))))
  455. (home-page "https://framagit.org/tractor")
  456. (synopsis "Setup an onion routing proxy")
  457. (description
  458. "This package uses Python stem library to provide a connection through
  459. the onion proxy and sets up proxy in user session, so you don't have to mess
  460. up with TOR on your system anymore.")
  461. (license license:gpl3+)))