On this page:
sourced-signature?
well-formed-signature?
malformed-signature?
fetch-signature-payload
lock-signature
make-snake-oil-signature
MAX_  EXPECTED_  SIGNATURE_  PAYLOAD_  LENGTH
call-with-snake-oil-cipher-trust
DENXI_  TRUST_  ANY_  PUBLIC_  KEY
DENXI_  TRUST_  UNSIGNED
DENXI_  TRUST_  BAD_  SIGNATURE
DENXI_  TRUST_  PUBLIC_  KEYS
15.1 Signature Checking Primitives
signature
raw-signature?
make-signature/  c
verify-signature/  c
check-signature
signature-check-passed?
current-verify-signature
current-make-signature
15.2 Signature Checking FFI
signature-ffi-available?!
signature-ffi-make-signature!
signature-ffi-verify-signature!
signature-ffi-get-find-signature-size!
signature-ffi-get-make-md-context!
signature-ffi-get-start-signature!
signature-ffi-get-end-signature!
signature-ffi-get-verify-signature!
15.2.1 Signature Foreign Functions
15.3 Signature Prototyping
snake-oil-public-key
snake-oil-private-key
snake-oil-private-key-password
8.12

15 Signature Checking🔗ℹ

 (require denxi/signature) package: denxi

denxi/signature uses asymmetric cryptography to verify if a digest was signed by a private key. The quality of signature verification is therefore dependent on the quality of the CHF used to create the digest.

Duck typing contracts for signature instances.

sourced-signature? returns #t if at least one of the fields of the instance is a source. This is unlike sourced-integrity?, which only checks if the digest field is a source.

procedure

(fetch-signature-payload src exhaust)  any/c

  src : source-variant?
  exhaust : exhaust/c
Like fetch, except transfer limits are capped to MAX_EXPECTED_SIGNATURE_PAYLOAD_LENGTH and no transfer status information is reported. When the source has been successfully tapped, the return value is a byte string representing the full content of the requested resource.

In practice, the fetched bytes are expected to contain either a public key or a signature. In any case, the output is assumed to be compatible with the tool used to verify signatures.

procedure

(lock-signature [#:public-key-budget public-key-budget 
  #:signature-budget signature-budget] 
  siginfo 
  exhaust) 
  signature?
  public-key-budget : budget/c
   = MAX_EXPECTED_SIGNATURE_PAYLOAD_LENGTH
  signature-budget : budget/c
   = MAX_EXPECTED_SIGNATURE_PAYLOAD_LENGTH
  siginfo : well-formed-signature?
  exhaust : exhaust/c

procedure

(make-snake-oil-signature digest [chf-name])  raw-signature?

  digest : bytes?
  chf-name : symbol? = (get-default-chf)
Return a new signature using snake-oil-private-key.

Do not use in production code.

An estimated maximum number of bytes (chosen empirically) for a public key or signature.

procedure

(call-with-snake-oil-cipher-trust thunk)  any

  thunk : (-> any)
Calls thunk in tail position. While control is in the thunk, (DENXI_TRUST_PUBLIC_KEYS) is (list snake-oil-public-key).

Implies call-with-snake-oil-chf-trust.

CLI Flags: --trust-any-pubkey/--DENXI_TRUST_ANY_PUBLIC_KEY
Dangerous. When true, trust any public key used to verify a signature.

setting

DENXI_TRUST_UNSIGNED : boolean? = #f

CLI Flags: -U/--trust-unsigned/--DENXI_TRUST_UNSIGNED
Dangerous. When true, trust any input that lacks a valid signature.

CLI Flags: -T/--trust-bad-signature/--DENXI_TRUST_BAD_SIGNATURE
Dangerous. When true, trust any input that has a signature that does not match the input’s integrity information.

CLI Flags: +p/++trust-public-key/--DENXI_TRUST_PUBLIC_KEYS
A list of integrity information for public keys. Trusts public keys that can be used to reproduce an element of this list.

15.1 Signature Checking Primitives🔗ℹ

 (require denxi/signature/base) package: denxi

struct

(struct signature (public-key body)
    #:transparent)
  public-key : any/c
  body : any/c
Represents a claim that the bytes in body are a signature that can be verified using public-key.

A flat contract for signature claims that contain only unencoded bytes in memory.

value

make-signature/c : chaperone-contract?

 = 
(-> bytes?
    symbol?
    bytes?
    (or/c #f bytes?)
    bytes?)
A contract for procedures that return new signatures as unencoded bytes.

Arguments
  1. A digest as unencoded bytes

  2. A symbol representing the name of the cryptographic hash function used to create the first argument.

  3. A private key of some encoding.

  4. A password for the private key, or #f if there is no password.

value

verify-signature/c : chaperone-contract?

 = 
(-> bytes?
    symbol?
    bytes?
    bytes?
    boolean?)
A contract for procedures that return #t for trusted signatures.

Arguments
  1. A digest as unencoded bytes

  2. A symbol representing the name of the cryptographic hash function used to create the first argument.

  3. A public key of some encoding.

  4. An unencoded signature

Allowing #f in the arguments is intentional due to the possibility of missing information.

procedure

(check-signature #:trust-public-key? trust-public-key? 
  #:trust-unsigned trust-unsigned 
  #:verify-signature verify-signature 
  #:trust-bad-digest trust-bad-digest 
  sig 
  int) 
  symbol?
  trust-public-key? : (-> input-port? any/c)
  trust-unsigned : any/c
  verify-signature : verify-signature/c
  trust-bad-digest : any/c
  sig : (or/c #f signature?)
  int : (or/c #f integrity?)

'skip and 'skip-unsigned are not equivalent. check-signature only handles a lack of a signature when sig or int is malformed.

Returns

Returns #t if the argument is in the range of check-signature, and you can interpret it as permission to proceed in a larger procedure.

A parameter holding the current way to verify a signature.

If (signature-ffi-available?!) is #t, the default value is signature-ffi-verify-signature. Otherwise, (const #f).

A parameter holding the current way to make a signature. The default value returns an empty byte string.

15.2 Signature Checking FFI🔗ℹ

 (require denxi/signature/ffi) package: denxi

denxi/signature/ffi is a private module that defines FFI bindings for a bundled library.

Returns #t if the FFI dynamically linked against the bundled foreign library for the purposes of integrity checking operations.

Returns bytes for a new signature.

Returns #t if a signature was verified by a public key.

Returns a foreign function for computing the expected size of a signature, or #f if the function could not load.

Returns a foreign function for allocating a message digest context, or #f if the function could not load.

Returns a foreign function for starting use of a cipher algorithm, or #f if the function could not load.

Each call must be paired with a call to the function returned from (signature-ffi-get-end-signature!).

Returns a foreign function for concluding use of a cipher algorithm, or #f if the function could not load.

Returns a foreign function for verifying a signature using library-specific data types, or #f if the function could not load.

15.2.1 Signature Foreign Functions🔗ℹ

To be included.

15.3 Signature Prototyping🔗ℹ

 (require denxi/signature/snake-oil) package: denxi

An intentionally-leaked RSA keypair, with a password for the private key. The private key is encrypted using AES-128 (CBC).

Each key is PEM-encoded.

Use only for prototyping signature creation and verification. Distrust for all other purposes.