This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
notary.rkt
114 lines (98 loc) · 3.08 KB
/
notary.rkt
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
#lang racket/base
(require racket/contract)
(provide (struct-out notary)
(contract-out
[lazy-notary notary?]
[make-fraudulent-notary
(-> symbol? notary?)]
[make-notary
(->* ()
(#:chf symbol?
#:private-key
(or/c #f source-variant?)
#:public-key-source
(or/c #f source-variant?)
#:private-key-password
(or/c #f source-variant?))
notary?)]
[notarize
(-> notary?
(or/c artifact? source-variant?)
(subprogram/c artifact?))]))
(require racket/file
racket/match
"artifact.rkt"
"crypto.rkt"
"integrity.rkt"
"signature.rkt"
"source.rkt"
"subprogram.rkt")
(struct notary
(chf
public-key-source
private-key
private-key-password))
(define (make-notary #:chf [chf (get-default-chf)]
#:public-key-source [pb #f]
#:private-key [pk #f]
#:private-key-password [pkp #f])
(notary chf pb pk pkp))
(define lazy-notary
(make-notary))
; Don't reduce to normal constructor call. This counts as implicit
; test coverage based on module instantiations.
(define (make-fraudulent-notary [chf (get-default-chf)])
(make-notary #:chf chf
#:public-key-source
snake-oil-public-key
#:private-key
snake-oil-private-key
#:private-key-password
snake-oil-private-key-password))
(define (notarize the-notary content)
(match-define (notary chf pubkey prvkey prvkeypass) the-notary)
(define user-source
(if (source-variant? content)
content
(artifact-source content)))
(define content-source
(coerce-source user-source))
(if chf
(subprogram-fetch
"notary"
content-source
(λ (in est-size)
(define intinfo
(and chf
(integrity
chf
(make-digest in chf))))
(close-input-port in)
(artifact user-source
intinfo
(and intinfo
pubkey
prvkey
(signature
pubkey
(make-signature
(integrity-digest intinfo)
(integrity-chf-symbol intinfo)
prvkey
prvkeypass))))))
(subprogram-unit (artifact user-source #f #f))))
(module+ test
(require rackunit
(submod "subprogram.rkt" test))
(check-pred notary? (make-notary))
(call-with-snake-oil-cipher-trust
(λ ()
(check-match
(get-subprogram-value
(notarize (make-fraudulent-notary)
(make-artifact #"abc")))
(artifact #"abc"
(integrity (? symbol? _)
(? bytes? _))
(signature (? bytes? _)
(? bytes? _)))))))