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