gnu: perl-context-preserve: Update to 0.03.
[jackhill/guix/guix.git] / gnu / packages / certs.scm
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 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages certs)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (guix packages)
26 #:use-module (guix download)
27 #:use-module (guix build-system gnu)
28 #:use-module (guix build-system trivial)
29 #:use-module (gnu packages)
30 #:use-module (gnu packages python)
31 #:use-module (gnu packages perl)
32 #:use-module (gnu packages tls))
33
34 (define certdata2pem
35 (package
36 (name "certdata2pem")
37 (version "2013")
38 (source
39 (origin
40 (method url-fetch)
41 (uri
42 "http://pkgs.fedoraproject.org/cgit/ca-certificates.git/plain/certdata2pem.py?id=053dde8a2f5901e97028a58bf54e7d0ef8095a54")
43 (file-name "certdata2pem.py")
44 (sha256
45 (base32
46 "0zscrm41gnsf14zvlkxhy00h3dmgidyz645ldpda3y3vabnwv8dx"))))
47 (build-system trivial-build-system)
48 (inputs
49 `(("python" ,python-2)))
50 (arguments
51 `(#:modules ((guix build utils))
52 #:builder
53 (begin
54 (use-modules (guix build utils))
55 (let ((bin (string-append %output "/bin")))
56 (copy-file (assoc-ref %build-inputs "source") "certdata2pem.py")
57 (chmod "certdata2pem.py" #o555)
58 (substitute* "certdata2pem.py"
59 (("/usr/bin/python")
60 (string-append (assoc-ref %build-inputs "python")
61 "/bin/python"))
62 ;; Use the file extension .pem instead of .crt.
63 (("crt") "pem"))
64 (mkdir-p bin)
65 (copy-file "certdata2pem.py"
66 (string-append bin "/certdata2pem.py"))))))
67 (synopsis "Python script to extract .pem data from certificate collection")
68 (description
69 "certdata2pem.py is a Python script to transform X.509 certificate
70 \"source code\" as contained, for example, in the Mozilla sources, into
71 .pem formatted certificates.")
72 (license license:gpl2+)
73 (home-page "http://pkgs.fedoraproject.org/cgit/ca-certificates.git/")))
74
75 (define-public nss-certs
76 (package
77 (name "nss-certs")
78 (version "3.36.1")
79 (source (origin
80 (method url-fetch)
81 (uri (let ((version-with-underscores
82 (string-join (string-split version #\.) "_")))
83 (string-append
84 "https://ftp.mozilla.org/pub/mozilla.org/security/nss/"
85 "releases/NSS_" version-with-underscores "_RTM/src/"
86 "nss-" version ".tar.gz")))
87 (sha256
88 (base32
89 "1zrb49mp7cy3snnday1zv8d76h1mgppbcwxnlkqsgxlga8fl89b0"))))
90 (build-system gnu-build-system)
91 (outputs '("out"))
92 (native-inputs
93 `(("certdata2pem" ,certdata2pem)
94 ("openssl" ,openssl)
95 ("perl" ,perl))) ;for OpenSSL's 'c_rehash'
96 (inputs '())
97 (propagated-inputs '())
98 (arguments
99 `(#:modules ((guix build gnu-build-system)
100 (guix build utils)
101 (rnrs io ports)
102 (srfi srfi-26)
103 (ice-9 regex))
104 #:phases
105 (modify-phases
106 (map (cut assq <> %standard-phases)
107 '(set-paths install-locale unpack))
108 (add-after 'unpack 'install
109 (lambda _
110 (let ((certsdir (string-append %output "/etc/ssl/certs/"))
111 (trusted-rx (make-regexp "^# openssl-trust=[a-zA-Z]"
112 regexp/newline)))
113
114 (define (maybe-install-cert file)
115 (let ((cert (call-with-input-file file get-string-all)))
116 (when (regexp-exec trusted-rx cert)
117 (call-with-output-file
118 (string-append certsdir file)
119 (cut display cert <>)))))
120
121 (mkdir-p certsdir)
122 (with-directory-excursion "nss/lib/ckfw/builtins/"
123 ;; extract single certificates from blob
124 (system* "certdata2pem.py" "certdata.txt")
125 ;; copy selected .pem files into the output
126 (for-each maybe-install-cert
127 (find-files "." ".*\\.pem")))
128
129 (with-directory-excursion certsdir
130 ;; create symbolic links for and by openssl
131 ;; Strangely, the call (system* "c_rehash" certsdir)
132 ;; from inside the build dir fails with
133 ;; "Usage error; try -help."
134 ;; This looks like a bug in openssl-1.0.2, but we can also
135 ;; switch into the target directory.
136 (invoke "c_rehash" "."))
137 #t))))))
138
139 (synopsis "CA certificates from Mozilla")
140 (description
141 "This package provides certificates for Certification Authorities (CA)
142 taken from the NSS package and thus ultimately from the Mozilla project.")
143 (home-page "https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS")
144 (license license:mpl2.0)))
145
146 (define-public le-certs
147 (package
148 (name "le-certs")
149 (version "0")
150 (source #f)
151 (build-system trivial-build-system)
152 (arguments
153 '(#:modules ((guix build utils))
154 #:builder
155 (begin
156 (use-modules (guix build utils))
157 (let ((root (assoc-ref %build-inputs "isrgrootx1.pem"))
158 (intermediate (assoc-ref %build-inputs "letsencryptauthorityx3.pem"))
159 (backup (assoc-ref %build-inputs "letsencryptauthorityx4.pem"))
160 (out (string-append (assoc-ref %outputs "out") "/etc/ssl/certs"))
161 (openssl (assoc-ref %build-inputs "openssl"))
162 (perl (assoc-ref %build-inputs "perl")))
163 (mkdir-p out)
164 (for-each
165 (lambda (cert)
166 (copy-file cert (string-append out "/"
167 (strip-store-file-name cert))))
168 (list root intermediate backup))
169
170 ;; Create hash symlinks suitable for OpenSSL ('SSL_CERT_DIR' and
171 ;; similar.)
172 (chdir (string-append %output "/etc/ssl/certs"))
173 (unless (zero? (system* (string-append perl "/bin/perl")
174 (string-append openssl "/bin/c_rehash")
175 "."))
176 (error "'c_rehash' failed" openssl))))))
177 (native-inputs
178 `(("openssl" ,openssl)
179 ("perl" ,perl))) ;for 'c_rehash'
180 (inputs
181 `(; The Let's Encrypt root certificate, "ISRG Root X1".
182 ("isrgrootx1.pem"
183 ,(origin
184 (method url-fetch)
185 (uri "https://letsencrypt.org/certs/isrgrootx1.pem")
186 (sha256
187 (base32
188 "0zhd1ps7sz4w1x52xk3v7ng6d0rcyi7y7rcrplwkmilnq5hzjv1y"))))
189 ;; "Let’s Encrypt Authority X3", the active Let's Encrypt intermediate
190 ;; certificate.
191 ("letsencryptauthorityx3.pem"
192 ,(origin
193 (method url-fetch)
194 (uri "https://letsencrypt.org/certs/letsencryptauthorityx3.pem")
195 (sha256
196 (base32
197 "0zbamj6c7zqw1j9mbqygc8k1ykgj6xiisp9svmlif5lkbnyjhnkk"))))
198 ;; "Let’s Encrypt Authority X4", the backup Let's Encrypt intermediate
199 ;; certificate. This will be used for disaster recovery and will only be
200 ;; used should Let's Encrypt lose the ability to issue with "Let’s
201 ;; Encrypt Authority X3".
202 ("letsencryptauthorityx4.pem"
203 ,(origin
204 (method url-fetch)
205 (uri "https://letsencrypt.org/certs/letsencryptauthorityx4.pem")
206 (sha256
207 (base32
208 "003dc94c8qwj634h0dq743x7hqv9rdcfaisdksprkmi2jd107xq4"))))))
209 (home-page "https://letsencrypt.org/certificates/")
210 (synopsis "Let's Encrypt root and intermediate certificates")
211 (description "This package provides a certificate store containing only the
212 Let's Encrypt root and intermediate certificates. It is intended to be used
213 within Guix.")
214 (license license:public-domain)))