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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
#
# X.509 v3 by ITU-T Recommendation (11/93) & PKCS7 & PKCS10
#
X509: module {
PATH: con "/dis/lib/crypt/x509.dis";
init: fn(): string;
## x509 (id_at) and x509 extention v3 (id_ce) Object Identifiers
objIdTab : array of ASN1->Oid;
id_at,
id_at_commonName,
id_at_countryName,
id_at_localityName,
id_at_stateOrProvinceName,
id_at_organizationName,
id_at_organizationalUnitName,
id_at_userPassword,
id_at_userCertificate,
id_at_cAcertificate,
id_at_authorityRevocationList,
id_at_certificateRevocationList,
id_at_crossCertificatePair,
id_at_supportedAlgorithms,
id_at_deltaRevocationList,
id_ce,
id_ce_subjectDirectoryAttributes,
id_ce_subjectKeyIdentifier,
id_ce_keyUsage,
id_ce_privateKeyUsage,
id_ce_subjectAltName,
id_ce_issuerAltName,
id_ce_basicConstraints,
id_ce_cRLNumber,
id_ce_reasonCode,
id_ce_instructionCode,
id_ce_invalidityDate,
id_ce_deltaCRLIndicator,
id_ce_issuingDistributionPoint,
id_ce_certificateIssuer,
id_ce_nameConstraints,
id_ce_cRLDistributionPoint,
id_ce_certificatePolicies,
id_ce_policyMapping,
id_ce_authorityKeyIdentifier,
id_ce_policyConstraints,
id_mr,
id_mr_certificateExactMatch,
id_mr_certificateMatch,
id_mr_certificatePairExactMatch,
id_mr_certificatePairMatch,
id_mr_certificateListExactMatch,
id_mr_certificateListMatch,
id_mr_algorithmidentifierMatch : con iota;
## Signed (as Public Key, CRL, Attribute Certificates and CertificationRequest)
Signed: adt {
tobe_signed : array of byte;
alg : ref AlgIdentifier;
signature : array of byte; # BIT STRING, DER encoding
decode: fn(a: array of byte): (string, ref Signed);
encode: fn(s: self ref Signed): (string, array of byte);
sign: fn(s: self ref Signed, sk: ref PrivateKey, hash: int): (string, array of byte);
verify: fn(s: self ref Signed, pk: ref PublicKey, hash: int): int;
tostring: fn(s: self ref Signed): string;
};
## Certificate Path
verify_certchain: fn(cs: list of array of byte): (int, string);
verify_certpath: fn(cp: list of (ref Signed, ref Certificate)): (int, string);
## TBS (Public Key) Certificate
Certificate: adt {
version : int; # v1(0; default) or v2(1) or v3(2)
serial_number : ref Keyring->IPint;
sig : ref AlgIdentifier;
issuer : ref Name;
validity : ref Validity;
subject : ref Name;
subject_pkinfo : ref SubjectPKInfo;
# OPTIONAL for v2 and v3; must be in order
issuer_uid : array of byte; # v2
subject_uid : array of byte; # v2 or v3
exts : list of ref Extension; # v3
decode: fn(a: array of byte): (string, ref Certificate);
encode: fn(c: self ref Certificate): (string, array of byte);
tostring: fn(c: self ref Certificate): string;
is_expired: fn(c: self ref Certificate, date: int): int;
};
AlgIdentifier: adt {
oid : ref ASN1->Oid;
parameter : array of byte;
tostring: fn(a: self ref AlgIdentifier): string;
};
Name: adt {
rd_names : list of ref RDName;
equal: fn(a: self ref Name, b: ref Name): int;
tostring: fn(n: self ref Name): string;
};
RDName: adt {
avas : list of ref AVA;
equal: fn(a: self ref RDName, b: ref RDName): int;
tostring: fn(r: self ref RDName): string;
};
AVA: adt {
oid : ref ASN1->Oid;
value : string;
equal: fn(a: self ref AVA, b: ref AVA): int;
tostring: fn(a: self ref AVA): string;
};
Validity: adt {
not_before : int;
not_after : int;
tostring: fn(v: self ref Validity, format: string): string;
};
SubjectPKInfo: adt {
alg_id : ref AlgIdentifier;
subject_pk : array of byte; # BIT STRING
getPublicKey: fn(c: self ref SubjectPKInfo): (string, int, ref PublicKey);
tostring: fn(c: self ref SubjectPKInfo): string;
};
Extension: adt{
oid : ref ASN1->Oid;
critical : int; # default false
value : array of byte;
tostring: fn(e: self ref Extension): string;
};
PublicKey: adt {
pick {
RSA =>
pk : ref PKCS->RSAKey;
DSS =>
pk : ref PKCS->DSSPublicKey;
DH =>
pk : ref PKCS->DHPublicKey;
}
};
PrivateKey: adt {
pick {
RSA =>
sk : ref PKCS->RSAKey;
DSS =>
sk : ref PKCS->DSSPrivateKey;
DH =>
sk : ref PKCS->DHPrivateKey;
}
};
## Certificate Revocation List
CRL: adt {
version : int; # OPTIONAL; v2
sig : ref AlgIdentifier;
issuer : ref Name;
this_update : int;
next_update : int; # OPTIONAL
revoked_certs : list of ref RevokedCert; # OPTIONAL
exts : list of ref Extension; # OPTIONAL
decode: fn(a: array of byte): (string, ref CRL);
encode: fn(c: self ref CRL): (string, array of byte);
tostring: fn(c: self ref CRL): string;
is_revoked: fn(c: self ref CRL, sn: ref Keyring->IPint): int;
};
RevokedCert: adt {
user_cert : ref Keyring->IPint; # serial_number
revoc_date : int; # OPTIONAL
exts : list of ref Extension; # OPTIONAL; CRL entry extensions
tostring: fn(rc: self ref RevokedCert): string;
};
## Certificate Extensions
# get critical extensions
cr_exts: fn(es: list of ref Extension): list of ref Extension;
# get non-critical extensions
noncr_exts: fn(es: list of ref Extension): list of ref Extension;
# decode a list of extensions
parse_exts: fn(es: list of ref Extension): (string, list of ref ExtClass);
# extension classes
ExtClass: adt {
pick {
AuthorityKeyIdentifier =>
id : array of byte; # OCTET STRING
issuer : ref GeneralName;
serial_number : ref Keyring->IPint;
SubjectKeyIdentifier =>
id : array of byte; # OCTET STRING
BasicConstraints =>
depth : int; # certificate path constraints
KeyUsage =>
usage : int;
PrivateKeyUsage =>
period : ref Validity;
PolicyMapping => # (issuer, subject) domain policy pairs
pairs : list of (ref ASN1->Oid, ref ASN1->Oid);
CertificatePolicies =>
policies : list of ref PolicyInfo;
IssuerAltName =>
alias : list of ref GeneralName;
SubjectAltName =>
alias : list of ref GeneralName;
NameConstraints =>
permitted : list of ref GSubtree;
excluded : list of ref GSubtree;
PolicyConstraints =>
require : int;
inhibit : int;
CRLNumber =>
curr : int;
ReasonCode =>
code : int;
InstructionCode =>
oid : ref ASN1->Oid; # hold instruction code field
InvalidityDate =>
date : int;
CRLDistributionPoint =>
ps : list of ref DistrPoint;
IssuingDistributionPoint =>
name : ref DistrPointName;
only_usercerts : int; # DEFAULT FALSE
only_cacerts : int; # DEFAULT FALSE
only_reasons : int;
indirect_crl : int; # DEFAULT FALSE
CertificateIssuer =>
names : list of ref GeneralName;
DeltaCRLIndicator =>
number : ref Keyring->IPint;
SubjectDirectoryAttributes =>
attrs : list of ref Attribute;
UnknownType =>
ext : ref Extension;
}
decode: fn(ext: ref Extension): (string, ref ExtClass);
encode: fn(et: self ref ExtClass, critical: int): ref Extension;
tostring: fn(et: self ref ExtClass): string;
};
# key usage
KeyUsage_DigitalSignature, KeyUsage_NonRepudiation, KeyUsage_KeyEncipherment,
KeyUsage_DataEncipherment, KeyUsage_KeyAgreement, KeyUsage_KeyCertSign,
KeyUsage_CRLSign, KeyUsage_EncipherOnly, KeyUsage_DecipherOnly : con iota << 1;
# CRL reason
Reason_Unspecified, Reason_KeyCompromise, Reason_CACompromise,
Reason_AffiliationChanged, Reason_Superseded, Reason_CessationOfOperation,
Reason_CertificateHold, Reason_RemoveFromCRL : con iota << 1;
# General Name
GeneralName: adt {
pick {
otherName or # [0]
rfc822Name or # [1]
dNSName or # [2]
x400Address or # [3]
uniformResourceIdentifier => # [6]
str : string;
iPAddress => # [7]
ip : array of byte;
registeredID => # [8]
oid : ref ASN1->Oid;
ediPartyName => # [5]
nameAssigner : ref Name; # [0]
partyName : ref Name; # [1]
directoryName => # [4]
dir : ref Name;
}
tostring: fn(g: self ref GeneralName): string;
};
# security policies
PolicyInfo: adt {
oid : ref ASN1->Oid;
qualifiers : list of ref PolicyQualifier;
tostring: fn(pi: self ref PolicyInfo): string;
};
PolicyQualifier: adt {
oid : ref ASN1->Oid;
value : array of byte; # OCTET STRING; OPTIONAL
tostring: fn(pq: self ref PolicyQualifier): string;
};
GSubtree: adt {
base : ref GeneralName;
min : int;
max : int;
tostring: fn(gs: self ref GSubtree): string;
};
# crl distribution point
# with known reason code
# Unused [0], KeyCompromise [1], CACompromise [2], AffilationChanged [3],
# Superseded [4], CessationOfOperation [5], CertificateHold [6]
DistrPoint: adt{
name : ref DistrPointName;
reasons : int;
issuer : list of ref GeneralName;
tostring: fn(dp: self ref DistrPoint): string;
};
DistrPointName: adt {
full_name : list of ref GeneralName;
rdname : list of ref RDName;
};
Attribute: adt {
id : ASN1->Oid;
value : array of byte;
};
};
#X509Attribute: module {
#
# ## Attribute Certificate
#
# AttrCert: adt {
# version : int; # default v1
# base_certid : ref IssuerSerial; # [0]
# subject_name : list of ref GeneralName; # [1]
# issuer : list of ref GeneralName;
# serial_number : ref IPint;
# validity : ref Validity;
# attrs : list of ref Attribute;
# issuer_uid : array of byte; # OPTIONAL
# exts : list of ref Extension; # OPTIONAL
# };
#
# IssuerSerial: adt {
# issuer : list of ref GeneralName;
# serial : ref IPint;
# issuer_uid : array of byte; # OPTIONAL
# };
#};
|