certs.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015 Andreas Enge <andreas@enge.fr>
  3. ;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
  4. ;;; Copyright © 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  5. ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
  6. ;;; Copyright © 2017, 2018 Tobias Geerinckx-Rice <me@tobias.gr>
  7. ;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  8. ;;; Copyright © 2021 Efraim Flashner <efraim@flashner.co.il>
  9. ;;; Copyright © 2021 Raghav Gururajan <rg@raghavgururajan.name>
  10. ;;;
  11. ;;; This file is part of GNU Guix.
  12. ;;;
  13. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  14. ;;; under the terms of the GNU General Public License as published by
  15. ;;; the Free Software Foundation; either version 3 of the License, or (at
  16. ;;; your option) any later version.
  17. ;;;
  18. ;;; GNU Guix is distributed in the hope that it will be useful, but
  19. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. ;;; GNU General Public License for more details.
  22. ;;;
  23. ;;; You should have received a copy of the GNU General Public License
  24. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  25. (define-module (gnu packages certs)
  26. #:use-module ((guix licenses) #:prefix license:)
  27. #:use-module (guix packages)
  28. #:use-module (guix utils)
  29. #:use-module (guix download)
  30. #:use-module (guix git-download)
  31. #:use-module (guix build-system copy)
  32. #:use-module (guix build-system gnu)
  33. #:use-module (guix build-system trivial)
  34. #:use-module (gnu packages)
  35. #:use-module (gnu packages nss)
  36. #:use-module (gnu packages curl)
  37. #:use-module (gnu packages python)
  38. #:use-module (gnu packages perl)
  39. #:use-module (gnu packages tls))
  40. (define-public desec-certbot-hook
  41. (let ((commit "68da7abc0793602fd336962a7e2348b57c5d6fd6")
  42. (revision "0"))
  43. (package
  44. (name "desec-certbot-hook")
  45. (version
  46. (git-version "0" revision commit))
  47. (source
  48. (origin
  49. (method git-fetch)
  50. (uri
  51. (git-reference
  52. (url "https://github.com/desec-io/desec-certbot-hook")
  53. (commit commit)))
  54. (file-name (git-file-name name version))
  55. (sha256
  56. (base32 "0qjqk6i85b1y7fgzcx74r4gn2i4dkjza34hkzp6kyn9hrb8f2gv2"))))
  57. (build-system copy-build-system)
  58. (arguments
  59. `(#:phases
  60. (modify-phases %standard-phases
  61. (add-after 'unpack 'patch-script
  62. (lambda* (#:key inputs #:allow-other-keys)
  63. (substitute* "hook.sh"
  64. ;; The hook-script look for '.dedynauth' file in $PWD.
  65. ;; But users cannot create or edit files in store.
  66. ;; So we patch the hook-script to look for '.dedynauth' file,
  67. ;; in /etc/desec.
  68. (("\\$\\(pwd\\)")
  69. "/etc/desec")
  70. ;; Make absolute reference to curl program.
  71. (("curl")
  72. (string-append (assoc-ref inputs "curl")
  73. "/bin/curl"))))))
  74. #:install-plan
  75. '(("." "etc/desec" #:include ("hook.sh")))))
  76. (inputs
  77. `(("curl" ,curl)))
  78. (synopsis "Certbot DNS challenge automatization for deSEC")
  79. (description "The deSEC can be used to obtain certificates with certbot
  80. DNS ownership verification. With the help of this hook script, you can obtain
  81. your Let's Encrypt certificate using certbot with authorization provided by the
  82. DNS challenge mechanism, that is, you will not need a running web server or any
  83. port forwarding to your local machine.")
  84. (home-page "https://desec.io")
  85. (license license:expat))))
  86. (define certdata2pem
  87. (let ((revision "1")
  88. (commit "4c576f350f44186d439179f63d5be19f710a73f5"))
  89. (package
  90. (name "certdata2pem")
  91. (version "0.0.0") ;no version
  92. (source (origin
  93. (method url-fetch)
  94. (uri (string-append
  95. "https://raw.githubusercontent.com/sabotage-linux/sabotage/"
  96. commit "/KEEP/certdata2pem.c"))
  97. (sha256
  98. (base32
  99. "1rywp29q4l1cs2baplkbcravxqs4kw2cys4yifhfznbc210pskq6"))))
  100. (build-system gnu-build-system)
  101. (arguments
  102. `(#:phases (modify-phases %standard-phases
  103. (delete 'configure)
  104. (add-before 'build 'fix-extension
  105. (lambda _
  106. (substitute* "certdata2pem.c"
  107. (("\\.crt")
  108. ".pem"))))
  109. (replace 'build
  110. (lambda _
  111. (invoke ,(cc-for-target) "certdata2pem.c"
  112. "-o" "certdata2pem")))
  113. (delete 'check) ;no test suite
  114. (replace 'install
  115. (lambda* (#:key outputs #:allow-other-keys)
  116. (let ((out (assoc-ref outputs "out")))
  117. (install-file "certdata2pem"
  118. (string-append out "/bin"))))))))
  119. (home-page "https://github.com/sabotage-linux/")
  120. (synopsis "Utility to split TLS certificates data into multiple PEM files")
  121. (description "This is a C version of the certdata2pem Python utility
  122. that was originally contributed to Debian.")
  123. (license license:isc))))
  124. (define-public nss-certs
  125. (package
  126. (name "nss-certs")
  127. (version "3.67")
  128. (source (origin
  129. (method url-fetch)
  130. (uri (let ((version-with-underscores
  131. (string-join (string-split version #\.) "_")))
  132. (string-append
  133. "https://ftp.mozilla.org/pub/mozilla.org/security/nss/"
  134. "releases/NSS_" version-with-underscores "_RTM/src/"
  135. "nss-" version ".tar.gz")))
  136. (sha256
  137. (base32
  138. "0zyfi27lbdz1bmk9dmsivcya4phx25rzlxqcnjab69yd928rlm7n"))))
  139. (build-system gnu-build-system)
  140. (outputs '("out"))
  141. (native-inputs
  142. `(("certdata2pem" ,certdata2pem)
  143. ("openssl" ,openssl)))
  144. (inputs '())
  145. (propagated-inputs '())
  146. (arguments
  147. `(#:modules ((guix build gnu-build-system)
  148. (guix build utils)
  149. (rnrs io ports)
  150. (srfi srfi-26))
  151. #:phases
  152. (modify-phases
  153. (map (cut assq <> %standard-phases)
  154. '(set-paths install-locale unpack))
  155. (add-after 'unpack 'install
  156. (lambda _
  157. (let ((certsdir (string-append %output "/etc/ssl/certs/")))
  158. (with-directory-excursion "nss/lib/ckfw/builtins/"
  159. (unless (file-exists? "blacklist.txt")
  160. (call-with-output-file "blacklist.txt" (const #t)))
  161. ;; Extract selected single certificates from blob.
  162. (invoke "certdata2pem")
  163. ;; Copy .pem files into the output.
  164. (for-each (cut install-file <> certsdir)
  165. (find-files "." ".*\\.pem$")))
  166. (invoke "openssl" "rehash" certsdir)))))))
  167. (synopsis "CA certificates from Mozilla")
  168. (description
  169. "This package provides certificates for Certification Authorities (CA)
  170. taken from the NSS package and thus ultimately from the Mozilla project.")
  171. (home-page "https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS")
  172. (license license:mpl2.0)))
  173. (define-public le-certs
  174. (package
  175. (name "le-certs")
  176. (version "1")
  177. (source #f)
  178. (build-system trivial-build-system)
  179. (arguments
  180. '(#:modules ((guix build utils))
  181. #:builder
  182. (begin
  183. (use-modules (guix build utils))
  184. (let ((root-rsa (assoc-ref %build-inputs "isrgrootx1.pem"))
  185. (root-ecdsa (assoc-ref %build-inputs "isrgrootx2.pem"))
  186. (intermediate-rsa (assoc-ref %build-inputs "letsencryptauthorityr3.pem"))
  187. (intermediate-ecdsa (assoc-ref %build-inputs "letsencryptauthoritye1.pem"))
  188. (backup-rsa (assoc-ref %build-inputs "letsencryptauthorityr4.pem"))
  189. (backup-ecdsa (assoc-ref %build-inputs "letsencryptauthoritye2.pem"))
  190. (out (string-append (assoc-ref %outputs "out") "/etc/ssl/certs"))
  191. (openssl (assoc-ref %build-inputs "openssl"))
  192. (perl (assoc-ref %build-inputs "perl")))
  193. (mkdir-p out)
  194. (for-each
  195. (lambda (cert)
  196. (copy-file cert (string-append out "/"
  197. (strip-store-file-name cert))))
  198. (list root-rsa root-ecdsa
  199. intermediate-rsa intermediate-ecdsa
  200. backup-rsa backup-ecdsa))
  201. ;; Create hash symlinks suitable for OpenSSL ('SSL_CERT_DIR' and
  202. ;; similar.)
  203. (chdir (string-append %output "/etc/ssl/certs"))
  204. (invoke (string-append perl "/bin/perl")
  205. (string-append openssl "/bin/c_rehash")
  206. ".")))))
  207. (native-inputs
  208. `(("openssl" ,openssl)
  209. ("perl" ,perl))) ;for 'c_rehash'
  210. (inputs
  211. `(; The Let's Encrypt root certificate, "ISRG Root X1".
  212. ("isrgrootx1.pem"
  213. ,(origin
  214. (method url-fetch)
  215. (uri "https://letsencrypt.org/certs/isrgrootx1.pem")
  216. (sha256
  217. (base32
  218. "1la36n2f31j9s03v847ig6ny9lr875q3g7smnq33dcsmf2i5gd92"))))
  219. ; Upcoming ECDSA Let's Encrypt root certificate, "ISRG Root X2"
  220. ; Let's Encrypt describes it as "Active, limited availability"
  221. ("isrgrootx2.pem"
  222. ,(origin
  223. (method url-fetch)
  224. (uri "https://letsencrypt.org/certs/isrg-root-x2.pem")
  225. (sha256
  226. (base32
  227. "04xh8912nwkghqydbqvvmslpqbcafgxgjh9qnn0z2vgy24g8hgd1"))))
  228. ;; "Let’s Encrypt Authority R3", the active Let's Encrypt intermediate
  229. ;; RSA certificate.
  230. ("letsencryptauthorityr3.pem"
  231. ,(origin
  232. (method url-fetch)
  233. (uri "https://letsencrypt.org/certs/lets-encrypt-r3.pem")
  234. (sha256
  235. (base32
  236. "0clxry49rx6qd3pgbzknpgzywbg3j96zy0227wwjnwivqj7inzhp"))))
  237. ;; "Let’s Encrypt Authority E1", the active Let's Encrypt intermediate
  238. ;; ECDSA certificate.
  239. ("letsencryptauthoritye1.pem"
  240. ,(origin
  241. (method url-fetch)
  242. (uri "https://letsencrypt.org/certs/lets-encrypt-e1.pem")
  243. (sha256
  244. (base32
  245. "1zwrc6dlk1qig0z23x6x7fib14rrw41ccbf2ds0rw75zccc59xx0"))))
  246. ;; "Let’s Encrypt Authority R4", the backup Let's Encrypt intermediate
  247. ;; RSA certificate. This will be used for disaster recovery and will only be
  248. ;; used should Let's Encrypt lose the ability to issue with "Let’s
  249. ;; Encrypt Authority R3".
  250. ("letsencryptauthorityr4.pem"
  251. ,(origin
  252. (method url-fetch)
  253. (uri "https://letsencrypt.org/certs/lets-encrypt-r4.pem")
  254. (sha256
  255. (base32
  256. "09bzxzbwb9x2xxan3p1fyj1pi2p5yks0879gwz5f28y9mzq8vmd8"))))
  257. ;; "Let’s Encrypt Authority E2", the backup Let's Encrypt intermediate
  258. ;; ECDSA certificate. This will be used for disaster recovery and will
  259. ;; only be used should Let's Encrypt lose the ability to issue with "Let’s
  260. ;; Encrypt Authority E1".
  261. ("letsencryptauthoritye2.pem"
  262. ,(origin
  263. (method url-fetch)
  264. (uri "https://letsencrypt.org/certs/lets-encrypt-e2.pem")
  265. (sha256
  266. (base32
  267. "1wfmsa29lyi9dkh6xdcamb2rhkp5yl2ppnsgrzcrjl5c7gbqh9ml"))))))
  268. (home-page "https://letsencrypt.org/certificates/")
  269. (synopsis "Let's Encrypt root and intermediate certificates")
  270. (description "This package provides a certificate store containing only the
  271. Let's Encrypt root and intermediate certificates. It is intended to be used
  272. within Guix.")
  273. (license license:public-domain)))