Coverage report: /home/ellis/comp/core/lib/cry/pkg.lisp

KindCoveredAll%
expression051 0.0
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; pkg.lisp --- Crypto Packages
2
 
3
 ;; 
4
 
5
 ;;; Code:
6
 
7
 #|
8
 (ironclad:digest-file :sha1 "/tmp/picard01t0fjkc.jpg")
9
 
10
 (cry/b3::load-blake3)
11
 (cry/b3:b3sum "/tmp/picard01t0fjkc.jpg" :hex nil)
12
 |#
13
 
14
 (defpackage :cry
15
   (:nicknames :cryptography)
16
   (:shadowing-import-from :ironclad :integer-to-octets :octets-to-integer :xor)
17
   (:use :cl :std :sb-thread :ironclad :obj/db :obj/id)
18
   (:export :crypto-error :crypto-token-expired :crypto-token-invalid
19
    :crypto-key :token :crypto-token
20
    :*default-password-db* :*default-password-hasher* :*default-password-store* :*default-password-pepper*
21
    :password-db
22
    :crypto-condition))
23
 
24
 (defpackage :cry/hotp
25
   (:nicknames :hotp)
26
   (:use :cl :std :cry)
27
   (:export *digits*
28
            *hmac-sha-mode*
29
            hotp))
30
 
31
 (defpackage :cry/totp
32
   (:nicknames :totp)
33
   (:use :cl :std :cry/hotp)
34
   (:export *time-zero*
35
            *time-step-in-seconds* 
36
            totp))
37
 
38
 (defpackage :cry/crc64
39
   (:use :cl)
40
   (:export :+polynomial+ :+improved-polynomial+
41
            :init-crc64 :crc64-stream
42
            :crc64-file :crc64-sequence))
43
 
44
 (defpackage :cry/b3
45
   (:nicknames :b3)
46
   (:use :cl :std :blake3 :sb-alien)
47
   (:export :b3hash :b3sum
48
            :b3hash-string))
49
 
50
 (defpackage :cry/jwt
51
   (:use :cl :std :dat/json :dat/base64 :cry)
52
   (:export
53
    #:hs256-digest
54
    #:compare-hs256-digest
55
    #:jwt-decode))
56
 
57
 (defpackage :cry/authinfo
58
   (:use :cl :std :cry)
59
   (:export
60
    #:authinfo))
61
 
62
 (defpackage :cry/keyring
63
   (:use :cl :std :cry :keyutils :id :db :sb-alien)
64
   (:export
65
    :get-key
66
    :keyring
67
    :make-keyring
68
    :clear-keys))
69
 
70
 (defpackage :cry/password
71
   (:use :cl :std :obj/secret)
72
   (:export :password :password-hash :password-salt :make-password-hash :auth))
73
 
74
 (defpackage :cry/drm
75
   (:use :cl :std))
76
   
77
 (in-package :cry)
78
 
79
 (defvar *password-db* nil
80
   "The default password database.")
81
 (defvar *password-hasher* nil
82
   "The default password hasher.")
83
 (defvar *password-store* nil
84
   "The default password store.")
85
 (defvar *password-pepper* nil
86
   "The default pepper value for password hashing. Make sure you change this.")
87
 
88
 (defclass token (id) ())
89
 
90
 (defun random-token () 
91
   (let ((id (make-array 64 :element-type '(unsigned-byte 8) :fill-pointer 0)))
92
     (dotimes (i 64)
93
       (vector-push (random 128) id))
94
     (make-instance 'token :id id)))
95
 
96
 (defgeneric token-bytes (self)
97
   (:method ((self token))
98
     (id self)))
99
 
100
 (defgeneric token-string (self)
101
   (:method ((self token))
102
     (sb-ext:octets-to-string (obj/id:id self))))
103
 
104
 (defclass crypto-token (token) ())
105
 (defclass crypto-key (id) ())
106
 (defclass password-db (database) ())
107
 (defclass password-store (store) ())
108
 
109
 ;;; Proto
110
 (defgeneric register-user (user &key store password deadline)
111
   (:documentation "Register user identified by TOKEN in store specified by STORE. Returns
112
 the user object and an optionally a confirmation token."))
113
 (defgeneric get-confirmation-token (user &key store duration)
114
   (:documentation "Create a new user confirmation token which must be
115
   validated within DURATION if non-nil. Register it for USER in STORE."))
116
 (defgeneric confirm-registration (user confirmation &key store)
117
   (:documentation "Confirm USER using CONFIRMATION in STORE."))
118
 (defgeneric user-pending-p (user &key store)
119
   (:documentation "Return non-nil if USER isn't pending confirmation, else nil."))
120
 (defgeneric user-known-p (user &key store)
121
   (:documentation "Return non-nil if USER is known in STORE."))
122
 (defgeneric authenticate-user (user password &key store)
123
   (:documentation "Check whether USER successfully authenticates with PASSWORD in STORE. If user had a reset-token pending, clear it upon success."))
124
 (defgeneric get-reset-token (user &key store duration)
125
   (:documentation "Create a new reset token, register it for USER in STORE for DURATION."))
126
 (defgeneric clear-reset-token (user &key store)
127
   (:documentation "Clear reset token of USER."))
128
 (defgeneric reset-password (user reset new &key store)
129
   (:documentation "Reset password of USER in STORE to NEW, authenticating with RESET."))
130
 (defgeneric delete-user (user &key store error-p)
131
   (:documentation "Delete user identified by USER in STORE. Signal an error if user can't be found and ERROR-P is non-nil."))