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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
Rawsexprs: module
{
PATH: con "rawsexprs.dis";
Sexp: adt {
pick {
String =>
s: string;
hint: string;
Binary =>
data: array of byte;
hint: string;
List =>
l: cyclic list of ref Sexp;
}
unpack: fn(a: array of byte): (ref Sexp, array of byte, string);
text: fn(e: self ref Sexp): string;
packedsize: fn(e: self ref Sexp): int;
pack: fn(e: self ref Sexp): array of byte;
};
init: fn();
};
SPKI: module
{
PATH: con "/dis/lib/spki/spki.dis";
Hash: adt {
alg: string;
hash: array of byte;
sexp: fn(h: self ref Hash): ref Sexprs->Sexp;
text: fn(h: self ref Hash): string;
eq: fn(h1: self ref Hash, h2: ref Hash): int;
};
Key: adt {
pk: ref Keyring->PK; # either pk/sk or hash might be nil
sk: ref Keyring->SK;
nbits: int;
halg: string; # basic signature hash algorithm
henc: string; # pre-signature encoding
hash: list of ref Hash;
hashed: fn(k: self ref Key, alg: string): array of byte;
hashexp: fn(k: self ref Key, alg: string): ref Hash;
ishash: fn(k: self ref Key): int;
public: fn(k: self ref Key): ref Key;
sigalg: fn(k: self ref Key): string;
text: fn(k: self ref Key): string;
sexp: fn(k: self ref Key): ref Sexprs->Sexp;
eq: fn(k1: self ref Key, k2: ref Key): int;
};
Name: adt {
principal: ref Key;
names: list of string;
isprincipal: fn(n: self ref Name): int;
local: fn(n: self ref Name): ref Name;
islocal: fn(n: self ref Name): int;
isprefix: fn(n1: self ref Name, n2: ref Name): int;
text: fn(n: self ref Name): string;
sexp: fn(n: self ref Name): ref Sexprs->Sexp;
eq: fn(n1: self ref Name, n2: ref Name): int;
};
Cert: adt {
e: ref Sexprs->Sexp; # S-expression, if originally parsed
issuer: ref Name;
subject: ref Subject;
valid: ref Valid;
pick {
A or KH or O => # auth, keyholder or object
delegate: int;
tag: ref Sexprs->Sexp;
N => # name
}
text: fn(c: self ref Cert): string;
sexp: fn(c: self ref Cert): ref Sexprs->Sexp;
};
# the pick might move to a more general `Principal' structure,
# allowing compound and quoting principals
Subject: adt {
pick{
P =>
key: ref Key;
N =>
name: ref Name;
O =>
hash: ref Hash;
KH =>
holder: ref Name;
T =>
k, n: int;
subs: cyclic list of ref Subject;
}
eq: fn(s1: self ref Subject, s2: ref Subject): int;
principal: fn(s: self ref Subject): ref Key;
text: fn(s: self ref Subject): string;
sexp: fn(s: self ref Subject): ref Sexprs->Sexp;
};
Principal: adt[T] {
pick{
N =>
name: ref Name;
Q =>
quoter: T;
quotes: cyclic ref Principal;
}
};
Signature: adt {
hash: ref Hash;
key: ref Key; # find by hash if necessary
sa: string; # alg[-[encoding-]hash]
sig: list of (string, array of byte);
algs: fn(s: self ref Signature): (string, string, string);
sexp: fn(s: self ref Signature): ref Sexprs->Sexp;
text: fn(s: self ref Signature): string;
};
Seqel: adt {
pick{
C =>
c: ref Cert;
K =>
k: ref Key;
O =>
op: string;
args: list of ref Sexprs->Sexp;
S =>
sig: ref Signature;
RV => # <reval>
ok: list of (string, string);
onetime: array of byte;
valid: ref Valid;
CRL =>
bad: list of (string, string);
valid: ref Valid;
Delta =>
hash: string;
bad: list of (string, string);
valid: ref Valid;
E =>
exp: ref Sexprs->Sexp;
}
sexp: fn(se: self ref Seqel): ref Sexprs->Sexp;
text: fn(se: self ref Seqel): string;
};
Valid: adt {
notbefore: string;
notafter: string;
intersect: fn(a: self Valid, b: Valid): (int, Valid);
text: fn(a: self Valid): string;
sexp: fn(a: self Valid): ref Sexprs->Sexp;
};
Toplev: adt {
pick {
C =>
v: ref Cert;
Sig =>
v: ref Signature;
K =>
v: ref Key;
Seq =>
v: list of ref Seqel;
}
sexp: fn(t: self ref Toplev): ref Sexprs->Sexp;
text: fn(t: self ref Toplev): string;
};
init: fn();
# parse structures
parse: fn(s: ref Sexprs->Sexp): (ref Toplev, string);
parseseq: fn(s: ref Sexprs->Sexp): list of ref Seqel;
parsecert: fn(s: ref Sexprs->Sexp): ref Cert;
parsesig: fn(s: ref Sexprs->Sexp): ref Signature;
parsename: fn(s: ref Sexprs->Sexp): ref Name;
parsekey: fn(s: ref Sexprs->Sexp): ref Key;
parsehash: fn(s: ref Sexprs->Sexp): ref Hash;
parsecompound: fn(s: ref Sexprs->Sexp): ref Name;
parsevalid: fn(s: ref Sexprs->Sexp): ref Valid;
# signature checking
checksig: fn(c: ref Cert, sig: ref Signature): string;
sig2icert: fn(sig: ref Signature, signer: string, exp: int): ref Keyring->Certificate;
# signature making
signcert: fn(c: ref Cert, sigalg: string, key: ref Key): (ref Signature, string);
signbytes: fn(a: array of byte, sigalg: string, key: ref Key): (ref Signature, string);
# tags
maketag: fn(e: ref Sexprs->Sexp): ref Sexprs->Sexp;
tagintersect: fn(t1: ref Sexprs->Sexp, t2: ref Sexprs->Sexp): ref Sexprs->Sexp;
tagimplies: fn(t1: ref Sexprs->Sexp, t2: ref Sexprs->Sexp): int;
# hash canonical s-expression
hashbytes: fn(a: array of byte, alg: string): array of byte;
hashexp: fn(e: ref Sexprs->Sexp, alg: string): array of byte;
# convert between date and time strings and Inferno form
date2epoch: fn(s: string): int; # YYYY-MM-DD_HH:MM:SS
epoch2date: fn(t: int): string;
time2secs: fn(s: string): int; # HH:MM:SS
secs2time: fn(t: int): string;
# misc
sigalgs: fn(algs: string): (string, string, string);
# debugging
dump: fn(s: string, a: array of byte);
};
Proofs: module
{
Proof: adt {
n: int;
parse: fn(s: string): ref Proof;
sexp: fn(p: self ref Proof): ref Sexprs->Sexp;
text: fn(p: self ref Proof): string;
};
init: fn(): string;
};
Verifier: module
{
PATH: con "/dis/lib/spki/verifier.dis";
Speaksfor: adt {
subject: ref SPKI->Subject;
name: ref SPKI->Name;
regarding: ref Sexprs->Sexp;
valid: ref SPKI->Valid;
};
init: fn();
verify: fn(seq: list of ref SPKI->Seqel): (ref Speaksfor, list of ref SPKI->Seqel, string);
};
|