aboutsummaryrefslogtreecommitdiff
path: root/tests/pki.scm
blob: d6a6b476c70fb2066d80cd5935e38ad18fbc6fd0 (about) (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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.
;;;
;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-pki)
  #:use-module (guix pki)
  #:use-module (gcrypt pk-crypto)
  #:use-module (gcrypt hash)
  #:use-module (rnrs io ports)
  #:use-module (srfi srfi-64))

;; Test the (guix pki) module.

(define %public-key
  (call-with-input-file %public-key-file
    (compose string->canonical-sexp get-string-all)))

(define %secret-key
  (call-with-input-file %private-key-file
    (compose string->canonical-sexp get-string-all)))

(define %alternate-secret-key
  (string->canonical-sexp
   "
  (key-data
   (public-key
    (rsa
     (n #00FDBF170366AC43B7D95CF9085565C566FB1F21B17C0A36E68F35ABB500E7851E00B40D7B04C8CD25903371F38E4C298FACEFFC4C97E913B536A0672BAF99D04515AE98A1A56627CD7EB02502FCFBEEA21AF13CC1A853192AD6409B9EFBD9F549BDE32BD890AE01F9A221E81FEE1C407090550647790E0D60775B855E181C2FB5#)
     (e #010001#)))
   (private-key
    (rsa
     (n #00FDBF170366AC43B7D95CF9085565C566FB1F21B17C0A36E68F35ABB500E7851E00B40D7B04C8CD25903371F38E4C298FACEFFC4C97E913B536A0672BAF99D04515AE98A1A56627CD7EB02502FCFBEEA21AF13CC1A853192AD6409B9EFBD9F549BDE32BD890AE01F9A221E81FEE1C407090550647790E0D60775B855E181C2FB5#)
     (e #010001#)
     (d #2790250C2E74C2FD361A99288BBA19B878048F5A0F333F829CC71B3DD64582DB9DF3F4DB1EB0994DD7493225EDA4A1E1492F44D903617FA5643E47BFC7BA157EF48B492AB51229916B02DDBDA0E7DBC7B35A6B8332AB463DC61951CA694551A9760F5A836A375D39E3EA8F2C502A3B5D89CB8777A809B75D603BE7511CEB74E9#)
     (p #00FE15B1751E1C31125B724FF37462F9476239A2AFF4192FAB1550F76928C8D02407F4F5EFC83F7A0AF51BD93399DDC06A4B54DFA60A7079F160A9F618C0148AD9#)
     (q #00FFA8BE7005AAB7401B0926CD9D6AC30BC9BE7D12C8737C9438498A999F56BE9F5EA98B4D7F5364BEB6D550A5AEDDE34C1EC152C9DAF61A97FDE71740C73BAA3D#)
     (u #00FD4050EF4F31B41EC81C28E18D205DFFB3C188F15D8BBA300E30AD8B5C4D3E392EFE10269FC115A538B19F4025973AB09B6650A7FF97DA833FB726F3D8819319#))))"))

(test-begin "pki")

(test-assert "current-acl"
  (not (not (member (canonical-sexp->sexp %public-key)
                    (map canonical-sexp->sexp
                         (acl->public-keys (current-acl)))))))

(test-assert "authorized-key? public-key current-acl"
  (authorized-key? %public-key))

(test-assert "authorized-key? public-key empty-acl"
  (not (authorized-key? %public-key (public-keys->acl '()))))

(test-assert "authorized-key? public-key singleton"
  (authorized-key? %public-key (public-keys->acl (list %public-key))))

(test-assert "signature-case valid-signature"
  (let* ((hash (sha256 #vu8(1 2 3)))
         (data (bytevector->hash-data hash #:key-type (key-type %public-key)))
         (sig  (signature-sexp data %secret-key %public-key)))
   (signature-case (sig hash (public-keys->acl (list %public-key)))
     (valid-signature #t)
     (else #f))))

(test-eq "signature-case invalid-signature" 'i
  (let* ((hash (sha256 #vu8(1 2 3)))
         (data (bytevector->hash-data hash #:key-type (key-type %public-key)))
         (sig  (signature-sexp data %alternate-secret-key %public-key)))
    (signature-case (sig hash (public-keys->acl (list %public-key)))
      (valid-signature 'v)
      (invalid-signature 'i)
      (hash-mismatch 'm)
      (unauthorized-key 'u)
      (corrupt-signature 'c))))

(test-eq "signature-case hash-mismatch" 'm
  (let* ((hash (sha256 #vu8(1 2 3)))
         (data (bytevector->hash-data hash #:key-type (key-type %public-key)))
         (sig  (signature-sexp data %secret-key %public-key)))
    (signature-case (sig (sha256 #vu8())
                         (public-keys->acl (list %public-key)))
      (valid-signature 'v)
      (invalid-signature 'i)
      (hash-mismatch 'm)
      (unauthorized-key 'u)
      (corrupt-signature 'c))))

(test-eq "signature-case unauthorized-key" 'u
  (let* ((hash (sha256 #vu8(1 2 3)))
         (data (bytevector->hash-data hash #:key-type (key-type %public-key)))
         (sig  (signature-sexp data %secret-key %public-key)))
    (signature-case (sig hash (public-keys->acl '()))
      (valid-signature 'v)
      (invalid-signature 'i)
      (hash-mismatch 'm)
      (unauthorized-key 'u)
      (corrupt-signature 'c))))

(test-eq "signature-case corrupt-signature" 'c
  (let* ((hash (sha256 #vu8(1 2 3)))
         (sig  (string->canonical-sexp "(w tf)")))
    (signature-case (sig hash (public-keys->acl (list %public-key)))
      (valid-signature 'v)
      (invalid-signature 'i)
      (hash-mismatch 'm)
      (unauthorized-key 'u)
      (corrupt-signature 'c))))

(test-end)
3 11:22:22 +0100'>2021-02-23services: cuirass: Fix services requirements.Mathieu Othacehe * gnu/services/cuirass.scm (cuirass-shepherd-service): Add "postgres-roles" to cuirass requirements. Set cuirass-web requirements to cuirass only. Remove "guix-daemon" and "networking" from cuirass-remote-server requirements as are already required by cuirass. 2021-02-23services: cuirass: Improve simple-cuirass-services.Mathieu Othacehe Instead of returning multiple services in simple-cuirass-services, rely on the instantiate-missing-services procedure to instantiate postgresql and postgresql-role-service-type when missing. Turn simple-cuirass-services procedure into simple-cuirass-configuration->specs, that takes a simple-cuirass-configuration record and returns a Cuirass specification. Suggested-by: Ludovic Courtès <ludo@gnu.org> * gnu/services/cuirass.scm (%default-cuirass-config): Remove it. (simple-cuirass-services): Rename it to ... (simple-cuirass-configuration->specs): ... this procedure. * gnu/tests/cuirass.scm (cuirass-services): Remove postgresql and postgresql-role services that are automatically instantiated. (simple-cuirass-service): New variable. (%cuirass-simple-test): Adapt it to use simple-cuirass-configuration->specs instead of simple-cuirass-services. * doc/guix.texi (Simple Cuirass): Update it. 2021-02-22services: cuirass: Instantiate postgresql service.Mathieu Othacehe * gnu/services/cuirass.scm (cuirass-service-type): Instantiate postgresql service when missing. 2021-02-22services: cuirass: Add parameters support.Mathieu Othacehe * gnu/services/cuirass.scm (<cuirass-configuration>)[parameters]: New field. [zabbix-uri]: Remove it. (cuirass-shepherd-service): Honor it. 2021-02-19services: cuirass: Add "simple-cuirass-services".Mathieu Othacehe * gnu/services/cuirass.scm (<build-manifest>, <simple-cuirass-configuration>): New records. (build-manifest, build-manifest?, simple-cuirass-configuration, simple-cuirass-configuration?, simple-cuirass-services): New procedures. (%default-cuirass-config): New variable. * gnu/tests/cuirass.scm (%cuirass-simple-test): New variable. * doc/guix.texi (Continuous Integration): Document it. 2021-02-12services: cuirass: Add server argument for the remote-worker.Mathieu Othacehe * gnu/services/cuirass.scm (<cuirass-remote-worker-configuration>)[server]: New field. (cuirass-remote-worker-shepherd-service): Honor it. 2021-02-09services: cuirass: Move zabbix argument to the web process.Mathieu Othacehe This is a follow-up of 703e5c92eeb38d86455c2b1cace5cad9fc08b349. * gnu/services/cuirass.scm (cuirass-shepherd-service): Move "zabbix-uri" argument to the web process. 2021-02-08services: cuirass: Add Zabbix support.Mathieu Othacehe * gnu/services/cuirass.scm (<cuirass-configuration>)[zabbix-uri]: New field. (cuirass-shepherd-service): Honor it. 2021-01-28services: cuirass: Create remote-server cache directory.Mathieu Othacehe * gnu/services/cuirass.scm (cuirass-activation): Create remote-server cache directory if needed. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org> 2021-01-28services: cuirass: Fix syntax error.Mathieu Othacehe This is a follow-up of 189e62fa69049538884077155cc70cac43260118. * gnu/services/cuirass.scm (<cuirass-remote-server-configuration>): Fix syntax. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org> 2021-01-28services: cuirass: Add log-file support.Mathieu Othacehe * gnu/services/cuirass.scm (cuirass-remote-worker-shepherd-service): Add log-file support. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org> 2021-01-28services: cuirass: Fix workers argument.Mathieu Othacehe * gnu/services/cuirass.scm (cuirass-remote-worker-shepherd-service): Fix workers arguments. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org> 2021-01-28services: cuirass: Add systems argument.Mathieu Othacehe * gnu/services/cuirass.scm (<cuirass-remote-worker-configuration>)[systems]: New field. (cuirass-remote-worker-shepherd-service): Honor it. Signed-off-by: Mathieu Othacehe <othacehe@gnu.org> 2021-01-28services: cuirass: Add remote build support.Mathieu Othacehe 2021-01-28service: cuirass: Update it.Mathieu Othacehe 2020-12-08services: cuirass: Add queue-size option.Mathieu Othacehe * gnu/services/cuirass.scm (<cuirass-configuration>): Add "queue-size" field. (cuirass-shepherd-service): Honor it. * doc/guix.texi (Continuous Integration): Document it. 2020-10-02services: cuirass: Fix activation.Mathieu Othacehe Fixes: <https://issues.guix.gnu.org/43760>. * gnu/services/cuirass.scm (cuirass-activation): Do not create queries-log-file and web-queries-log-file if the corresponding config file are unset. 2020-09-24services: cuirass: Create queries log files at activation.Mathieu Othacehe * gnu/services/cuirass.scm (cuirass-activation)[queries-log-file]: Create and set user permissions on "queries-log-file" and "web-queries-log-file". 2020-09-24services: cuirass: Add web SQL queries logging support.Mathieu Othacehe * gnu/services/cuirass.scm (<cuirass-configuration>)[web-queries-log-file]: New field. (cuirass-shepherd-service): Honor it. (cuirass-log-rotations): If defined, add the web queries log file to the log rotation. 2020-09-24services: cuirass: Add SQL queries logging support.Mathieu Othacehe * gnu/services/cuirass.scm (<cuirass-configuration>)[queries-log-file]: New field. (cuirass-shepherd-service): Honor it. (cuirass-log-rotations): If defined, add the queries log file to the log rotation. 2020-03-08services: cuirass: Allow passing extra command line options.Christopher Baines This is so that the options supported by the service configuration don't have to always be changed. Generally though all options should be explicitly supported and documented, so this is mostly to facilitate experimentation. * gnu/services/cuirass.scm (<cuirass-configuration>): Add an extra-options field. (cuirass-shepherd-service): Pass the extra options to the shepherd servvices. * doc/guix.texi (Continuous Integration): Document it.