14 Integrity Checking
(require denxi/integrity) | package: denxi |
denxi/integrity reprovides denxi/integrity/base, and is meant for use as a high-level interface to the integrity checking subsystem.
14.1 High-level Integrity Operations
procedure
(load-builtin-chf name [fail-thunk]) → any
name : symbol?
fail-thunk : (-> any) = (lambda () (raise ($chf-unavailable name)))
The output of this function may change across systems.
procedure
(fetch-digest intinfo exhaust) → any/c
intinfo : well-formed-integrity? exhaust : exhaust/c
No more than MAX_EXPECTED_DIGEST_LENGTH will be copied from the source.
procedure
(make-sourced-digest variant chf-name [ exhaust]) → bytes? variant : source-variant? chf-name : symbol? exhaust : exhaust/c = raise
procedure
(lock-integrity [ #:digest-budget digest-budget] to-lock [ exhaust]) → well-formed-integrity? digest-budget : budget/c = MAX_EXPECTED_DIGEST_LENGTH to-lock : well-formed-integrity? exhaust : exhaust/c = raise
Or, if the integrity information uses a source for the digest and that source is exhausted, returns exhaust applied to the contextual failure value.
(raw-integrity? L) is #t if a new digest can be created using no more than digest-budget bytes of overhead in the content. Otherwise, L is eq? to to-lock.
procedure
(make-trusted-integrity source [chf]) → raw-integrity?
source : source-variant? chf : symbol? = (get-default-chf)
value
= (struct/c integrity symbol? source?)
value
= (or/c raw-integrity? sourced-integrity?)
value
= (not/c well-formed-integrity?)
14.2 Integrity Settings
setting
DENXI_TRUST_BAD_DIGEST : boolean? = #f
setting
DENXI_TRUST_CHFS : (listof symbol?) = ()
14.3 Integrity-based Trust
procedure
(bind-trust-list trusted [chfs]) → (-> input-port? boolean?)
trusted : (listof integrity?) chfs : (listof chf?) = (current-chfs)
(P input-port) is #t if it can reproduce an element of trusted using chfs.
make-user-chf-trust-predicate is the fastest way to check if a user trusts a CHF.
procedure
procedure
(build-builtin-chf-trust trust-chfs) → (listof chf?)
trust-chfs : (listof symbol?)
The implementations of the given CHFs come from a bundled C library, any input symbols must appear in (integrity-ffi-get-c-chfs!).
14.4 Prototyping Integrity Checks
value
snake-oil-chf : chf? = (chf 'sha1 #px"^(?i:sha-?1)$" sha1-bytes)
Do not use in production if you can avoid doing so.
procedure
(call-with-snake-oil-chf-trust thunk) → any
thunk : (-> any)
14.5 Integrity Checking Primitives
(require denxi/integrity/base) | package: denxi |
Unlike denxi/integrity, denxi/integrity/base provides fundamental definitions for integrity checking.
The fields may be any value to address particular scenarios. Use raw-integrity?, well-formed-integrity?, malformed-integrity?, and sourced-integrity? to classify instances.
value
This contract does not validate the content of the fields, but an instance that passes this contract is suitable for use with check-integrity.
Allowing #f in the arguments is intentional due to the possibility of missing information.
procedure
(check-integrity #:trust-bad-digest trust-bad-digest trust-chf? int expected-digest) → symbol? trust-bad-digest : any/c trust-chf? : (-> symbol? any/c) int : (or/c #f integrity?) expected-digest : (or/c #f bytes?)
'digests-match if the digests are equal? and the user trusts the CHF.
'digests-differ if the digests are not equal?, but the user trusts the CHF.
'skip if trust-bad-digest is a true value.
'blocked-chf if the user does not trust the CHF.
'malformed-input if (raw-integrity? int) is #f.
procedure
(make-digest in [chf-name]) → bytes?
in : (or/c bytes? path-string? input-port?) chf-name : (or/c #f symbol?) = (get-default-chf)
If in is a path string, it is coerced to an input port using call-with-input-file*.
If in is a byte string, it is coerced to an input port using open-input-bytes.
If chf-name is #f, or no CHF implementation is available for it, make-digest will raise ($chf-unavailable chf-name).
14.5.1 Cryptographic Hash Functions
struct
canonical-name : symbol? alias-pattern : regexp? implementation : chf-impl/c
canonical-name represents the primary name of the CHF in the context of the running process. alias-pattern captures variations of the canonical name. implementation produces a digest using the CHF’s specification.
An instance might encode SHA-1 as follows:
(chf 'sha1 #px"^(?i:sha[-_ ]?1)$" sha1-bytes) ; openssl/sha1, file/sha1
The name fields capture possible variation where CHF symbols appear, such as in integrity instances.
(integrity 'SHA1 #"...") (integrity 'SHA-1 #"...") (integrity 'Sha_1 #"...") (integrity 'sha1 #"...") ; <- canonical (integrity 'sha-1 #"...")
chf implements prop:procedure, such that applying the instance to arguments will forward those arguments to the procedure bound to the implementation field.
chf implements gen:equal+hash, such that two instances are equal? if their canonical names are eq?.
struct
(struct $chf-unavailable (name) #:prefab) name : symbol?
value
The procedure must return a byte string representing an unencoded digest.
The first argument is an input port that produces bytes from an arbitrary source, such as an HTTP response or a file. The output digest must represent all bytes drawn from the port.
value
current-chfs : (parameter/c (listof chf?))
Defaults to null, which disables digest creation and integrity checks.
procedure
(chf-bind-trust [chfs]) → predicate/c
chfs : (listof chf?) = (current-chfs)
procedure
(chf-fold-trust select-implementation trusted-chf-names) → (listof chf?) select-implementation : (-> symbol? chf-impl/c) trusted-chf-names : (listof symbol?)
For each name in trusted-chf-names, the output list will contain:
(chf name (pregexp (format "^(?i:~a)$" name)) (select-implementation name))
procedure
(get-default-chf [trusted]) → (or/c #f symbol?)
trusted : (listof chf?) = (current-chfs)
procedure
haystack : (listof chf?) needle : symbol? = (get-default-chf haystack)
Returns #f if no instance meets the criteria.
14.6 Integrity FFI
(require denxi/integrity/ffi) | package: denxi |
denxi/integrity/ffi is a private module that defines FFI bindings for a bundled library dedicated to integrity checking.
procedure
procedure
(integrity-ffi-get-c-chfs!) → (or/c #f (listof symbol?))
procedure
→ (or/c #f exact-nonnegative-integer?)
Do not confuse this index with get-default-chf. The default is a suggestion by the library among its own implementations, and does not apply as a default for the runtime unless it is installed using current-chfs.
procedure
procedure
procedure
procedure
→ (or/c #f exact-positive-integer?)
The integer represents the number of CHFs supported by the C runtime, not the number of implementations available.
procedure
14.6.1 Integrity Foreign Functions
To be included.