aboutsummaryrefslogtreecommitdiff
path: root/tests/pki.scm
blob: 876ad98d736d8cbf62fd18cc337f9d3366ef2735 (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 (guix pk-crypto)
  #:use-module (guix 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)
b17f7bb446e9538cf466ef311b63a8fbf'>logplainabout -rw-r--r--augeas.scm2449logplainabout -rw-r--r--autogen.scm2737logplainabout -rw-r--r--autotools.scm15517logplainabout -rw-r--r--avahi.scm4583logplainabout -rw-r--r--avr.scm7007logplainabout -rw-r--r--backup.scm24313logplainabout -rw-r--r--base.scm45747logplainabout -rw-r--r--bash.scm14045logplainabout -rw-r--r--bdw-gc.scm4370logplainabout -rw-r--r--benchmark.scm2588logplainabout -rw-r--r--bioinformatics.scm347376logplainabout -rw-r--r--bison.scm2397logplainabout -rw-r--r--bittorrent.scm17137logplainabout -rw-r--r--boost.scm5394logplainabout -rw-r--r--bootstrap.scm21215logplainabout d---------bootstrap155logplain -rw-r--r--busybox.scm4082logplainabout -rw-r--r--c.scm6727logplainabout -rw-r--r--calcurse.scm2150logplainabout -rw-r--r--calendar.scm7483logplainabout -rw-r--r--ccache.scm2409logplainabout -rw-r--r--cdrom.scm19936logplainabout -rw-r--r--certs.scm5840logplainabout -rw-r--r--check.scm10711logplainabout -rw-r--r--chez.scm24961logplainabout -rw-r--r--ci.scm11296logplainabout -rw-r--r--cmake.scm5395logplainabout -rw-r--r--code.scm13797logplainabout -rw-r--r--commencement.scm42326logplainabout -rw-r--r--compression.scm40504logplainabout -rw-r--r--compton.scm4189logplainabout -rw-r--r--conkeror.scm3730logplainabout -rw-r--r--conky.scm3189logplainabout -rw-r--r--connman.scm6574logplainabout -rw-r--r--cook.scm3472logplainabout -rw-r--r--cpio.scm2038logplainabout -rw-r--r--cppi.scm1774logplainabout -rw-r--r--cross-base.scm20758logplainabout -rw-r--r--crypto.scm17360logplainabout -rw-r--r--cryptsetup.scm5247logplainabout -rw-r--r--cups.scm19471logplainabout -rw-r--r--curl.scm5692logplainabout -rw-r--r--cyrus-sasl.scm3198logplainabout -rw-r--r--databases.scm57468logplainabout -rw-r--r--datamash.scm1911logplainabout -rw-r--r--datastructures.scm4189logplainabout -rw-r--r--dav.scm4599logplainabout -rw-r--r--dc.scm2176logplainabout -rw-r--r--debug.scm15399logplainabout -rw-r--r--dejagnu.scm3426logplainabout -rw-r--r--dico.scm3281logplainabout -rw-r--r--dictionaries.scm8552logplainabout -rw-r--r--dillo.scm2492logplainabout -rw-r--r--disk.scm12653logplainabout -rw-r--r--display-managers.scm10125logplainabout -rw-r--r--django.scm7229logplainabout -rw-r--r--djvu.scm1710logplainabout -rw-r--r--dns.scm12800logplainabout -rw-r--r--docbook.scm9715logplainabout -rw-r--r--docker.scm3871logplainabout -rw-r--r--documentation.scm7219logplainabout -rw-r--r--dunst.scm2717logplainabout -rw-r--r--dvtm.scm2311logplainabout -rw-r--r--ebook.scm6085logplainabout -rw-r--r--ed.scm2345logplainabout -rw-r--r--education.scm7943logplainabout -rw-r--r--elf.scm5867logplainabout -rw-r--r--elixir.scm4460logplainabout -rw-r--r--emacs.scm151055logplainabout -rw-r--r--embedded.scm30727logplainabout -rw-r--r--enchant.scm2381logplainabout -rw-r--r--engineering.scm32698logplainabout -rw-r--r--enlightenment.scm12191logplainabout -rw-r--r--entr.scm2854logplainabout -rw-r--r--erlang.scm8322logplainabout -rw-r--r--fcitx.scm4722logplainabout -rw-r--r--figlet.scm1797logplainabout -rw-r--r--file.scm2004logplainabout -rw-r--r--finance.scm12151logplainabout -rw-r--r--firmware.scm7298logplainabout -rw-r--r--flashing-tools.scm9691logplainabout -rw-r--r--flex.scm4382logplainabout -rw-r--r--fltk.scm5694logplainabout -rw-r--r--fonts.scm44743logplainabout -rw-r--r--fontutils.scm23836logplainabout -rw-r--r--fpga.scm13373logplainabout -rw-r--r--freedesktop.scm34875logplainabout -rw-r--r--freeipmi.scm2076logplainabout -rw-r--r--fribidi.scm1756logplainabout -rw-r--r--ftp.scm6838logplainabout -rw-r--r--fvwm.scm2509logplainabout -rw-r--r--game-development.scm24656logplainabout -rw-r--r--games.scm124401logplainabout -rw-r--r--gawk.scm3771logplainabout -rw-r--r--gcal.scm1979logplainabout -rw-r--r--gcc.scm37713logplainabout -rw-r--r--gd.scm7382logplainabout -rw-r--r--gdb.scm4579logplainabout -rw-r--r--geo.scm7480logplainabout -rw-r--r--gettext.scm7647logplainabout -rw-r--r--gforth.scm2440logplainabout -rw-r--r--ghostscript.scm13124logplainabout -rw-r--r--gimp.scm9953logplainabout -rw-r--r--gkrellm.scm2394logplainabout -rw-r--r--gl.scm24875logplainabout -rw-r--r--glib.scm28537logplainabout -rw-r--r--gnome.scm226874logplainabout -rw-r--r--gnu-doc.scm4075logplainabout -rw-r--r--gnu-pw-mgr.scm2095logplainabout -rw-r--r--gnucash.scm8149logplainabout -rw-r--r--gnunet.scm15052logplainabout -rw-r--r--gnupg.scm27548logplainabout -rw-r--r--gnustep.scm10477logplainabout -rw-r--r--gnuzilla.scm32966logplainabout -rw-r--r--gobby.scm4896logplainabout -rw-r--r--golang.scm18140logplainabout -rw-r--r--gperf.scm1784logplainabout -rw-r--r--gprolog.scm2560logplainabout -rw-r--r--gps.scm5200logplainabout -rw-r--r--graphics.scm22022logplainabout -rw-r--r--graphviz.scm8169logplainabout -rw-r--r--groff.scm4021logplainabout -rw-r--r--grub.scm6587logplainabout -rw-r--r--gsasl.scm3960logplainabout -rw-r--r--gstreamer.scm17243logplainabout -rw-r--r--gtk.scm55440logplainabout -rw-r--r--guile-wm.scm6385logplainabout -rw-r--r--guile.scm65413logplainabout -rw-r--r--gv.scm3246logplainabout -rw-r--r--gxmessage.scm2351logplainabout -rw-r--r--haskell.scm297898logplainabout -rw-r--r--hexedit.scm1892logplainabout -rw-r--r--hugs.scm3671logplainabout -rw-r--r--hurd.scm7855logplainabout -rw-r--r--ibus.scm11408logplainabout -rw-r--r--icu4c.scm2911logplainabout -rw-r--r--idris.scm11212logplainabout -rw-r--r--idutils.scm2088logplainabout -rw-r--r--image-viewers.scm10366logplainabout -rw-r--r--image.scm45117logplainabout -rw-r--r--imagemagick.scm9339logplainabout -rw-r--r--indent.scm2384logplainabout -rw-r--r--inklingreader.scm2239logplainabout -rw-r--r--inkscape.scm3050logplainabout -rw-r--r--irc.scm16835logplainabout -rw-r--r--iso-codes.scm2663logplainabout -rw-r--r--java.scm60277logplainabout -rw-r--r--jemalloc.scm1796logplainabout -rw-r--r--jrnl.scm2241logplainabout -rw-r--r--julia.scm15070logplainabout -rw-r--r--kde-frameworks.scm107697logplainabout -rw-r--r--kde.scm13730logplainabout -rw-r--r--kerberos.scm7530logplainabout -rw-r--r--key-mon.scm2079logplainabout -rw-r--r--kodi.scm11238logplainabout -rw-r--r--language.scm16380logplainabout -rw-r--r--ld-wrapper.in9597logplainabout -rw-r--r--ldc.scm13354logplainabout -rw-r--r--lego.scm2804logplainabout -rw-r--r--less.scm1883logplainabout -rw-r--r--lesstif.scm1817logplainabout -rw-r--r--libbsd.scm2092logplainabout -rw-r--r--libcanberra.scm5121logplainabout -rw-r--r--libdaemon.scm2903logplainabout -rw-r--r--libedit.scm1971logplainabout -rw-r--r--libevent.scm5985logplainabout -rw-r--r--libffcall.scm1901logplainabout -rw-r--r--libffi.scm2981logplainabout -rw-r--r--libftdi.scm1883logplainabout -rw-r--r--libidn.scm2976logplainabout -rw-r--r--libphidget.scm1635logplainabout -rw-r--r--libreoffice.scm32638logplainabout -rw-r--r--libsigsegv.scm2464logplainabout -rw-r--r--libunistring.scm2196logplainabout -rw-r--r--libunwind.scm2295logplainabout -rw-r--r--libupnp.scm2159logplainabout -rw-r--r--libusb.scm8727logplainabout -rw-r--r--lighting.scm3212logplainabout -rw-r--r--links.scm3511logplainabout -rw-r--r--linux-libre-4.1-i686.conf184802logplainabout -rw-r--r--linux-libre-4.1-x86_64.conf180741logplainabout -rw-r--r--linux-libre-4.4-i686.conf191658logplainabout -rw-r--r--linux-libre-4.4-x86_64.conf187756logplainabout -rw-r--r--linux-libre-4.9-i686.conf202077logplainabout -rw-r--r--linux-libre-4.9-x86_64.conf199148logplainabout -rw-r--r--linux.scm142502logplainabout -rw-r--r--lirc.scm5639logplainabout -rw-r--r--lisp.scm43812logplainabout -rw-r--r--llvm.scm11272logplainabout -rw-r--r--logging.scm3836logplainabout -rw-r--r--lolcode.scm2411logplainabout -rw-r--r--lout.scm5961logplainabout -rw-r--r--lsof.scm3601logplainabout -rw-r--r--lua.scm18787logplainabout -rw-r--r--lxde.scm9142logplainabout -rw-r--r--lxqt.scm7108logplainabout -rw-r--r--lynx.scm3534logplainabout -rw-r--r--m4.scm2626logplainabout -rw-r--r--machine-learning.scm24557logplainabout -rw-r--r--mail.scm72562logplainabout -rw-r--r--make-bootstrap.scm28861logplainabout -rw-r--r--man.scm8931logplainabout -rw-r--r--markdown.scm5571logplainabout -rw-r--r--marst.scm1758logplainabout -rw-r--r--mate.scm8425logplainabout -rw-r--r--maths.scm119657logplainabout -rw-r--r--mc.scm3054logplainabout -rw-r--r--mcrypt.scm4576logplainabout -rw-r--r--messaging.scm49069logplainabout -rw-r--r--mg.scm2535logplainabout -rw-r--r--microcom.scm2349logplainabout -rw-r--r--mingw.scm3647logplainabout -rw-r--r--moe.scm2210logplainabout -rw-r--r--monitoring.scm5469logplainabout -rw-r--r--mono.scm4676logplainabout -rw-r--r--moreutils.scm2884logplainabout -rw-r--r--mp3.scm20359logplainabout -rw-r--r--mpd.scm12400logplainabout -rw-r--r--mpi.scm6608logplainabout -rw-r--r--mtools.scm2551logplainabout -rw-r--r--multiprecision.scm6322logplainabout -rw-r--r--music.scm111398logplainabout -rw-r--r--musl.scm2170logplainabout -rw-r--r--nano.scm1970logplainabout -rw-r--r--ncdu.scm2051logplainabout -rw-r--r--ncurses.scm12685logplainabout -rw-r--r--netpbm.scm7380logplainabout -rw-r--r--nettle.scm3181logplainabout -rw-r--r--networking.scm41708logplainabout -rw-r--r--nfs.scm5283logplainabout -rw-r--r--nickle.scm2423logplainabout -rw-r--r--nim.scm2379logplainabout -rw-r--r--ninja.scm3154logplainabout -rw-r--r--node.scm5984logplainabout -rw-r--r--noweb.scm4688logplainabout -rw-r--r--ntp.scm6665logplainabout -rw-r--r--nutrition.scm2727logplainabout -rw-r--r--nvi.scm2848logplainabout -rw-r--r--ocaml.scm85538logplainabout -rw-r--r--ocr.scm3096logplainabout -rw-r--r--onc-rpc.scm3591logplainabout -rw-r--r--openbox.scm3942logplainabout -rw-r--r--openldap.scm3033logplainabout -rw-r--r--openstack.scm28958logplainabout -rw-r--r--orpheus.scm4224logplainabout -rw-r--r--ots.scm3227logplainabout -rw-r--r--package-management.scm23451logplainabout -rw-r--r--parallel.scm7392logplainabout -rw-r--r--password-utils.scm16224logplainabout d---------patches28357logplain -rw-r--r--patchutils.scm8603logplainabout -rw-r--r--pciutils.scm3670logplainabout -rw-r--r--pcre.scm4474logplainabout -rw-r--r--pdf.scm33576logplainabout -rw-r--r--pem.scm1794logplainabout -rw-r--r--perl-web.scm1994logplainabout -rw-r--r--perl.scm305783logplainabout -rw-r--r--photo.scm10073logplainabout -rw-r--r--php.scm16706logplainabout