unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob fa8ac5caa059ce22287b23ab779de76a20021ef8 2912 bytes (raw)
name: etc/new-client-cert.scm 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
 
#!/usr/bin/env -S guix shell guile openssl -- guile \\
--no-auto-compile -e main -s
!#
;;;; cuirass.scm -- Cuirass public interface.
;;; Copyright © 2023 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of Cuirass.
;;;
;;; Cuirass is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;;; the Free Software Foundation, either version 3 of the License, or
;;; (at your option) any later version.
;;;
;;; Cuirass is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Cuirass.  If not, see <http://www.gnu.org/licenses/>.

(use-modules (ice-9 match)
             (guix build utils))

(define %CA-directory
  "/etc/ssl-ca")

(define CA-key
  (string-append %CA-directory "/private/ca.key"))
(define CA-cert
  (string-append %CA-directory "/certs/ca.crt"))

(define* (output who file)
  (string-append (getcwd) "/" who file))

(define (key-file who)
  "Return the absolute file name of the key file for WHO."
  (output who ".key"))

(define (csr-file who)
  "Return the absolute file name of the CSR file for WHO."
  (output who ".csr"))

(define (client-cert-file who)
  "Return the absolute file name of the client certificate file for
WHO."
  (output who ".crt"))

(define (exported-cert-file who)
  "Return the absolute file name of the pkcs12 client certificate file
for WHO.  This is the file that users should import into their
browsers."
  (output who ".p12"))

(define (generate-csr! who)
  "Generate a new certificate signing request and key for WHO."
  (invoke "openssl" "req" "-newkey" "rsa:4096"
	  "-nodes" ;no password
	  "-subj"
	  (format #false "/C=DE/ST=Berlin/L=Berlin/O=GNU Guix/OU=Cuirass/CN=~a" who)
          "-keyout" (key-file who)
	  "-out" (csr-file who)))

(define* (generate-client-certificate! who #:key (expiry 365))
  "Generate a client certificate for WHO."
  (invoke "openssl" "x509" "-req"
          "-in" (csr-file who)
          "-CA" CA-cert
          "-CAkey" CA-key
          "-out" (client-cert-file who)
          "-days" (number->string expiry)))

(define (export-p12! who)
  (invoke "openssl" "pkcs12" "-export"
	  "-in" (client-cert-file who)
	  "-inkey" (key-file who)
	  "-out" (exported-cert-file who)))

(define (main args)
  (match (command-line)
    ((script)
     (set-program-arguments (list script (or (getenv "SUDO_USER")
                                             (getenv "USER"))))
     (apply main args))
    ((script who)
     (generate-csr! who)
     (generate-client-certificate! who)
     (export-p12! who))
    ((script . rest)
     (format (current-error-port) "usage: ~a [name]~%" script))))

debug log:

solving fa8ac5c ...
found fa8ac5c in https://yhetil.org/guix-patches/20230508160745.10144-1-maxim.cournoyer@gmail.com/ ||
	https://yhetil.org/guix-patches/20230508170701.11548-1-maxim.cournoyer@gmail.com/

applying [1/1] https://yhetil.org/guix-patches/20230508160745.10144-1-maxim.cournoyer@gmail.com/
diff --git a/etc/new-client-cert.scm b/etc/new-client-cert.scm
new file mode 100755
index 0000000..fa8ac5c

Checking patch etc/new-client-cert.scm...
Applied patch etc/new-client-cert.scm cleanly.

skipping https://yhetil.org/guix-patches/20230508170701.11548-1-maxim.cournoyer@gmail.com/ for fa8ac5c
index at:
100755 fa8ac5caa059ce22287b23ab779de76a20021ef8	etc/new-client-cert.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).