interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / omega / allen / tls-cert.om

1299 lines · 20413 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Bounded X509/TLS1.3 verifier for api.github.com; RFC5280,5480,5758,8446,9525.
3note Supports uncompressed named P256/P384 and ECDSA-SHA256/P256 or ECDSA-SHA384/P384.
4note No AIA, CRL/OCSP fetching, RSA, SHA1, explicit curves, policy/name constraints or fallback.
5note Unsupported critical extensions and constrained CA paths fail closed, even if noncritical.
6note Up to8 peer certificates, each <=8192 bytes, TLS body <=60000,32 extensions/certificate.
7note Exact DER issuer/subject matching is deliberately conservative; no ambiguous normalization.
8note Trust anchor is the local OS Sectigo Public Server Authentication Root E46 certificate.
9note Source /etc/ssl/certs/Sectigo_Public_Server_Authentication_Root_E46.pem, read2026-10-25.
10note DER SHA256 C90F26F0FB1B4018B22227519B5CA2B53E2CA5B3BE5CF18EFE1BEF47380C5383.
11note Trust is in this root, never in a downloaded self-signed or leaf certificate.
12note Root cross-signatures need not validate: path terminates at the locally trusted subject/key.
13note Caller must supply trustworthy current Unix seconds. No network time or zero-time bypass.
14global Certbuf uchar 65536
15global Certlen ulong 1
16global Certnow ulong 1
17global Certkey uchar 65
18global Cleaf uchar 65
19global Certmsg uchar 4096
20global Certsig uchar 128
21global Cready ulong 1
22global Cd ulong 4
23global Cm ulong 288
24global Ce ulong 64
25global Cen ulong 1
26global Ckey uchar 97
27global Csig uchar 96
28global Chash uchar 48
29global Ctime ulong 8
30global Cchain ulong 8
31global Ccount ulong 1
32text Chost "api.github.com"
33text Cwild "*.github.com"
34
35note Cd: tag,value-start,end. Definite minimal DER only, bounds checked before every access.
36fn ctder p ulong e ulong to bool
37if or gt e 65536 ge p e
38ret false
39end
40if lt sub e p 2
41ret false
42end
43t = get Certbuf p
44if or eq and t 31 31 eq t 0
45ret false
46end
47p = add p 1
48n = ulong get Certbuf p
49p = add p 1
50if ge n 128
51k = sub n 128
52if or eq k 0 gt k 3
53ret false
54end
55if gt k sub e p
56ret false
57end
58if eq get Certbuf p 0
59ret false
60end
61n = 0
62for j ulong k
63n = or shl n 8 ulong get Certbuf add p j
64end
65p = add p k
66if lt n 128
67ret false
68end
69end
70if gt n sub e p
71ret false
72end
73put Cd 0 ulong t
74put Cd 1 p
75put Cd 2 add p n
76ret true
77end
78
79fn cttake p ulong e ulong t ulong to bool
80if not ctder p e
81ret false
82end
83ret eq get Cd 0 t
84end
85
86fn ctequal a ulong ae ulong b ulong be ulong to bool
87if ne sub ae a sub be b
88ret false
89end
90x = uchar 0
91for i ulong sub ae a
92u = get Certbuf add a i
93v = get Certbuf add b i
94x = or x xor u v
95end
96ret eq x 0
97end
98
99note Minimal nonnegative DER INTEGER; zero optionally allowed by caller.
100fn ctint p ulong e ulong to bool
101if ge p e
102ret false
103end
104if ge get Certbuf p 128
105ret false
106end
107if gt sub e p 1
108if eq get Certbuf p 0
109if lt get Certbuf add p 1 128
110ret false
111end
112end
113end
114ret true
115end
116
117note OIDs are canonical base128 subidentifiers; max32 octets in this bounded profile.
118fn ctoid p ulong e ulong to bool
119if or ge p e gt sub e p 32
120ret false
121end
122fresh = true
123for i ulong sub e p
124c = get Certbuf add p i
125if and fresh eq c 128
126ret false
127end
128fresh = eq and c 128 0
129end
130ret fresh
131end
132
133fn ctnum p ulong n ulong to ulong
134v = ulong 0
135for i ulong n
136c = get Certbuf add p i
137if or lt c 48 gt c 57
138ret 10000
139end
140v = add mul v 10 sub ulong c 48
141end
142ret v
143end
144
145fn ctleap y ulong to bool
146ret and eq rem y 4 0 or ne rem y 100 0 eq rem y 400 0
147end
148
149fn ctmonth y ulong m ulong to ulong
150if eq m 2
151if ctleap y
152ret 29
153end
154ret 28
155end
156if or or eq m 4 eq m 6 or eq m 9 eq m 11
157ret 30
158end
159ret 31
160end
161
162note Absolute Gregorian seconds since 0001-01-01 avoids negative Unix conversions.
163fn cttime p ulong e ulong to bool
164if not ctder p e
165ret false
166end
167p = get Cd 1
168n = sub get Cd 2 p
169y = ulong 0
170if eq get Cd 0 23
171if ne n 13
172ret false
173end
174y = ctnum p 2
175if gt y 99
176ret false
177end
178if lt y 50
179y = add y 2000
180else
181y = add y 1900
182end
183p = add p 2
184else
185if ne get Cd 0 24
186ret false
187end
188if ne n 15
189ret false
190end
191y = ctnum p 4
192if or lt y 2050 gt y 9999
193ret false
194end
195p = add p 4
196end
197if ne get Certbuf add p 10 90
198ret false
199end
200put Ctime 0 y
201for i ulong 5
202put Ctime add i 1 ctnum add p mul i 2 2
203end
204ret true
205end
206
207fn ctepoch to ulong
208y = get Ctime 0
209m = get Ctime 1
210d = get Ctime 2
211if or lt m 1 gt m 12
212ret 0
213end
214if or lt d 1 gt d ctmonth y m
215ret 0
216end
217if gt get Ctime 3 23
218ret 0
219end
220if gt get Ctime 4 59
221ret 0
222end
223if gt get Ctime 5 59
224ret 0
225end
226y = sub y 1
227days = add mul y 365 div y 4
228days = sub days div y 100
229days = add days div y 400
230y = add y 1
231for i ulong sub m 1
232days = add days ctmonth y add i 1
233end
234days = add days sub d 1
235v = add mul days 24 get Ctime 3
236v = add mul v 60 get Ctime 4
237ret add mul v 60 get Ctime 5
238end
239
240fn ctvalid b ulong p ulong e ulong to bool
241if not cttake p e 48
242ret false
243end
244p = get Cd 1
245e = get Cd 2
246if not cttime p e
247ret false
248end
249p = get Cd 2
250put Cm add b 11 ctepoch
251if eq get Cm add b 11 0
252ret false
253end
254if not cttime p e
255ret false
256end
257if ne get Cd 2 e
258ret false
259end
260put Cm add b 12 ctepoch
261ret ge get Cm add b 12 get Cm add b 11
262end
263
264note Signature AlgorithmIdentifier requires absent parameters (RFC5758 section3.2).
265fn ctalg p ulong e ulong to ulong
266if not cttake p e 48
267ret 0
268end
269p = get Cd 1
270e = get Cd 2
271if not cttake p e 6
272ret 0
273end
274p = get Cd 1
275if or ne get Cd 2 e ne sub e p 8
276ret 0
277end
278if ne get Certbuf p 42
279ret 0
280end
281if or ne get Certbuf add p 1 134 ne get Certbuf add p 2 72
282ret 0
283end
284if or ne get Certbuf add p 3 206 ne get Certbuf add p 4 61
285ret 0
286end
287if or ne get Certbuf add p 5 4 ne get Certbuf add p 6 3
288ret 0
289end
290if eq get Certbuf add p 7 2
291ret 32
292end
293if eq get Certbuf add p 7 3
294ret 48
295end
296ret 0
297end
298
299note Name RDN/ATV syntax is checked; supported directory strings only. Empty subject is handled by SAN.
300fn ctattr p ulong e ulong to bool
301if not cttake p e 6
302ret false
303end
304if not ctoid get Cd 1 get Cd 2
305ret false
306end
307p = get Cd 2
308if not ctder p e
309ret false
310end
311if ne get Cd 2 e
312ret false
313end
314t = get Cd 0
315if not or or eq t 12 eq t 19 or eq t 20 or eq t 22 eq t 30
316ret false
317end
318ret gt get Cd 2 get Cd 1
319end
320
321fn ctname p ulong e ulong to bool
322if not cttake p e 48
323ret false
324end
325p = get Cd 1
326e = get Cd 2
327while lt p e bound 4096
328if not cttake p e 49
329ret false
330end
331q = get Cd 1
332r = get Cd 2
333if eq q r
334ret false
335end
336p = r
337while lt q r bound 4096
338if not cttake q r 48
339ret false
340end
341q = get Cd 2
342if not ctattr get Cd 1 q
343ret false
344end
345end
346end
347ret eq p e
348end
349
350note Exact ecPublicKey OID and named curves; no explicit/implicit parameters.
351fn ctcurve p ulong e ulong to ulong
352if not cttake p e 48
353ret 0
354end
355p = get Cd 1
356e = get Cd 2
357if not cttake p e 6
358ret 0
359end
360p = get Cd 1
361if ne sub get Cd 2 p 7
362ret 0
363end
364if or ne get Certbuf p 42 ne get Certbuf add p 1 134
365ret 0
366end
367if or ne get Certbuf add p 2 72 ne get Certbuf add p 3 206
368ret 0
369end
370if or ne get Certbuf add p 4 61 ne get Certbuf add p 5 2
371ret 0
372end
373if ne get Certbuf add p 6 1
374ret 0
375end
376p = get Cd 2
377if not cttake p e 6
378ret 0
379end
380p = get Cd 1
381if ne get Cd 2 e
382ret 0
383end
384if eq sub e p 5
385if or ne get Certbuf p 43 ne get Certbuf add p 1 129
386ret 0
387end
388if or ne get Certbuf add p 2 4 ne get Certbuf add p 3 0
389ret 0
390end
391if eq get Certbuf add p 4 34
392ret 48
393end
394ret 0
395end
396if ne sub e p 8
397ret 0
398end
399if or ne get Certbuf p 42 ne get Certbuf add p 1 134
400ret 0
401end
402if or ne get Certbuf add p 2 72 ne get Certbuf add p 3 206
403ret 0
404end
405if or ne get Certbuf add p 4 61 ne get Certbuf add p 5 3
406ret 0
407end
408if or ne get Certbuf add p 6 1 ne get Certbuf add p 7 7
409ret 0
410end
411ret 32
412end
413
414fn ctspki b ulong p ulong e ulong to bool
415if not cttake p e 48
416ret false
417end
418p = get Cd 1
419e = get Cd 2
420k = ctcurve p e
421if eq k 0
422ret false
423end
424p = get Cd 2
425if not cttake p e 3
426ret false
427end
428p = get Cd 1
429if ne get Cd 2 e
430ret false
431end
432if ne sub e p add mul k 2 2
433ret false
434end
435if ne get Certbuf p 0
436ret false
437end
438p = add p 1
439if ne get Certbuf p 4
440ret false
441end
442put Cm add b 7 p
443put Cm add b 8 sub e p
444put Cm add b 24 k
445ret true
446end
447
448note Canonical BIT STRING with at most9 defined KeyUsage bits, named-bit trailing zeros trimmed.
449fn ctusage b ulong p ulong e ulong to bool
450if not cttake p e 3
451ret false
452end
453p = get Cd 1
454if ne get Cd 2 e
455ret false
456end
457n = sub e p
458if or lt n 2 gt n 3
459ret false
460end
461u = ulong get Certbuf p
462if gt u 7
463ret false
464end
465last = ulong get Certbuf sub e 1
466if eq last 0
467ret false
468end
469if ne and last sub shl ulong 1 u 1 0
470ret false
471end
472if eq and shr last u 1 0
473ret false
474end
475if eq n 3
476if or ne u 7 ne last 128
477ret false
478end
479end
480put Cm add b 15 ulong get Certbuf add p 1
481put Cm add b 16 1
482ret true
483end
484
485fn ctbasic b ulong p ulong e ulong crit bool to bool
486if not cttake p e 48
487ret false
488end
489p = get Cd 1
490if ne get Cd 2 e
491ret false
492end
493put Cm add b 20 1
494if crit
495put Cm add b 21 1
496end
497if eq p e
498ret true
499end
500if not cttake p e 1
501ret false
502end
503if ne sub get Cd 2 get Cd 1 1
504ret false
505end
506if ne get Certbuf get Cd 1 255
507ret false
508end
509put Cm add b 13 1
510p = get Cd 2
511if eq p e
512ret true
513end
514if not cttake p e 2
515ret false
516end
517p = get Cd 1
518if ne get Cd 2 e
519ret false
520end
521if not ctint p e
522ret false
523end
524if gt sub e p 2
525ret false
526end
527v = ulong 0
528for i ulong sub e p
529v = or shl v 8 ulong get Certbuf add p i
530end
531put Cm add b 14 v
532ret true
533end
534
535fn ctdns p ulong e ulong to bool
536n = sub e p
537if or eq n 0 gt n 253
538ret false
539end
540for i ulong n
541c = get Certbuf add p i
542if or eq c 0 ge c 128
543ret false
544end
545end
546if eq n len Chost
547ok = true
548for j ulong n
549c = get Certbuf add p j
550if and ge c 65 le c 90
551c = add c 32
552end
553if ne c get Chost j
554ok = false
555end
556end
557ret ok
558end
559if eq n len Cwild
560ok = true
561for j ulong n
562c = get Certbuf add p j
563if and ge c 65 le c 90
564c = add c 32
565end
566if ne c get Cwild j
567ok = false
568end
569end
570ret ok
571end
572ret false
573end
574
575note GeneralName CHOICE tags other than dNSName: [0] [1] [3]-[8] (RFC5280 4.2.1.6).
576fn ctgname t ulong to bool
577if or eq t 160 eq t 129
578ret true
579end
580if and ge t 163 le t 165
581ret true
582end
583ret and ge t 134 le t 136
584end
585
586fn ctsan b ulong p ulong e ulong to bool
587if not cttake p e 48
588ret false
589end
590p = get Cd 1
591if or ne get Cd 2 e eq p e
592ret false
593end
594put Cm add b 23 1
595while lt p e bound 4096
596if not ctder p e
597ret false
598end
599p = get Cd 2
600t = get Cd 0
601if eq t 130
602if ctdns get Cd 1 p
603put Cm add b 18 1
604end
605else
606note The required identity is DNS. Other legal GeneralName alternatives never match it.
607if not ctgname t
608ret false
609end
610end
611end
612ret eq p e
613end
614
615fn cteku b ulong p ulong e ulong to bool
616if not cttake p e 48
617ret false
618end
619p = get Cd 1
620if or ne get Cd 2 e eq p e
621ret false
622end
623put Cm add b 22 1
624put Cm add b 17 0
625while lt p e bound 4096
626if not cttake p e 6
627ret false
628end
629p = get Cd 1
630q = get Cd 2
631if not ctoid p q
632ret false
633end
634if eq sub q p 8
635if and eq get Certbuf p 43 eq get Certbuf add p 1 6
636if and eq get Certbuf add p 2 1 eq get Certbuf add p 3 5
637if and eq get Certbuf add p 4 5 eq get Certbuf add p 5 7
638if and eq get Certbuf add p 6 3 eq get Certbuf add p 7 1
639put Cm add b 17 1
640end
641end
642end
643end
644end
645p = q
646end
647ret eq p e
648end
649
650note Duplicate extension OIDs, including unknown ones, are refused before interpretation.
651fn ctunique p ulong e ulong to bool
652if not ctoid p e
653ret false
654end
655n = get Cen 0
656if ge n 32
657ret false
658end
659for i ulong n
660if ctequal p e get Ce mul i 2 get Ce add mul i 2 1
661ret false
662end
663end
664put Ce mul n 2 p
665put Ce add mul n 2 1 e
666put Cen 0 add n 1
667ret true
668end
669
670fn ctextval b ulong id ulong p ulong e ulong crit bool to bool
671if eq id 19
672ret ctbasic b p e crit
673end
674if eq id 15
675ret ctusage b p e
676end
677if eq id 17
678ret ctsan b p e
679end
680if eq id 37
681ret cteku b p e
682end
683note Constraints needing further path processing cannot be silently ignored even if noncritical.
684if or or eq id 30 eq id 33 or eq id 36 eq id 54
685ret false
686end
687if crit
688ret false
689end
690ret true
691end
692
693fn ctextone b ulong p ulong e ulong to bool
694if not cttake p e 6
695ret false
696end
697p = get Cd 1
698q = get Cd 2
699if not ctunique p q
700ret false
701end
702id = ulong 0
703if eq sub q p 3
704if and eq get Certbuf p 85 eq get Certbuf add p 1 29
705id = ulong get Certbuf add p 2
706end
707end
708p = q
709crit = false
710if not ctder p e
711ret false
712end
713if eq get Cd 0 1
714if ne sub get Cd 2 get Cd 1 1
715ret false
716end
717if ne get Certbuf get Cd 1 255
718ret false
719end
720crit = true
721p = get Cd 2
722end
723if not cttake p e 4
724ret false
725end
726p = get Cd 1
727if ne get Cd 2 e
728ret false
729end
730ret ctextval b id p e crit
731end
732
733fn ctexts b ulong p ulong e ulong to bool
734if not cttake p e 163
735ret false
736end
737p = get Cd 1
738if ne get Cd 2 e
739ret false
740end
741if not cttake p e 48
742ret false
743end
744p = get Cd 1
745if or ne get Cd 2 e eq p e
746ret false
747end
748put Cen 0 0
749while lt p e bound 4096
750if not cttake p e 48
751ret false
752end
753p = get Cd 2
754if not ctextone b get Cd 1 p
755ret false
756end
757end
758ret eq p e
759end
760
761fn ctfront b ulong p ulong e ulong to ulong
762if not cttake p e 160
763ret 0
764end
765q = get Cd 1
766p = get Cd 2
767if not cttake q p 2
768ret 0
769end
770if or ne get Cd 2 p ne sub p get Cd 1 1
771ret 0
772end
773if ne get Certbuf get Cd 1 2
774ret 0
775end
776if not cttake p e 2
777ret 0
778end
779q = get Cd 1
780p = get Cd 2
781if not ctint q p
782ret 0
783end
784if or gt sub p q 21 eq sub p q 0
785ret 0
786end
787if and eq sub p q 21 ne get Certbuf q 0
788ret 0
789end
790v = uchar 0
791for i ulong sub p q
792v = or v get Certbuf add q i
793end
794if eq v 0
795ret 0
796end
797put Cm add b 2 ctalg p e
798if eq get Cm add b 2 0
799ret 0
800end
801ret get Cd 2
802end
803
804fn ctfields b ulong p ulong e ulong to ulong
805put Cm add b 3 p
806if not cttake p e 48
807ret 0
808end
809p = get Cd 2
810put Cm add b 4 p
811if not ctname get Cm add b 3 p
812ret 0
813end
814if not cttake p e 48
815ret 0
816end
817q = get Cd 2
818if not ctvalid b p q
819ret 0
820end
821p = q
822put Cm add b 5 p
823if not cttake p e 48
824ret 0
825end
826p = get Cd 2
827put Cm add b 6 p
828if not ctname get Cm add b 5 p
829ret 0
830end
831if not cttake p e 48
832ret 0
833end
834q = get Cd 2
835if not ctspki b p q
836ret 0
837end
838ret q
839end
840
841fn ctparse idx ulong p ulong e ulong to bool
842b = mul idx 32
843for i ulong 32
844put Cm add b i 0
845end
846put Cm add b 14 8
847put Cm add b 17 1
848if not cttake p e 48
849ret false
850end
851if ne get Cd 2 e
852ret false
853end
854p = get Cd 1
855put Cm b p
856if not cttake p e 48
857ret false
858end
859q = get Cd 2
860put Cm add b 1 q
861p = ctfront b get Cd 1 q
862if eq p 0
863ret false
864end
865p = ctfields b p q
866if eq p 0
867ret false
868end
869if lt p q
870if not ctexts b p q
871ret false
872end
873end
874p = q
875if ne ctalg p e get Cm add b 2
876ret false
877end
878p = get Cd 2
879if not cttake p e 3
880ret false
881end
882p = get Cd 1
883if or ne get Cd 2 e ge p e
884ret false
885end
886if ne get Certbuf p 0
887ret false
888end
889put Cm add b 9 add p 1
890put Cm add b 10 e
891put Cm add b 25 1
892ret true
893end
894
895fn ctrawint p ulong e ulong width ulong off ulong to bool
896if not ctint p e
897ret false
898end
899if eq get Certbuf p 0
900p = add p 1
901end
902n = sub e p
903if or eq n 0 gt n width
904ret false
905end
906for i ulong n
907put Csig add off add sub width n i get Certbuf add p i
908end
909ret true
910end
911
912fn ctrawsig p ulong e ulong width ulong to bool
913for i ulong 96
914put Csig i 0
915end
916if not cttake p e 48
917ret false
918end
919p = get Cd 1
920if ne get Cd 2 e
921ret false
922end
923if not cttake p e 2
924ret false
925end
926p = get Cd 1
927q = get Cd 2
928if not ctrawint p q width 0
929ret false
930end
931if not cttake q e 2
932ret false
933end
934p = get Cd 1
935if ne get Cd 2 e
936ret false
937end
938ret ctrawint p e width width
939end
940
941fn ctsha256 p ulong e ulong to void
942constants
943hinit
944for i ulong sub e p
945hbyte get Certbuf add p i
946end
947finish
948for j ulong 32
949put Chash j get Hash j
950end
951end
952
953fn ctsha384 p ulong e ulong to void
954m = new uchar 65536 0
955d = new uchar 64 0
956for i ulong sub e p
957put m i get Certbuf add p i
958end
959cs384hash m sub e p d
960for j ulong 48
961put Chash j get d j
962end
963end
964
965fn ctvp256 to bool
966w = new ulong 1024 0
967b = new uchar 4096 0
968for i ulong 65
969put b add 3072 i get Ckey i
970end
971for j ulong 64
972put b add 3200 j get Csig j
973end
974for k ulong 32
975put b add 3296 k get Chash k
976end
977cp2init w
978ret eq cp2vrfy w b 1
979end
980
981fn ctvp384 to bool
982w = new ulong 1536 0
983b = new uchar 4096 0
984for i ulong 97
985put b add 3072 i get Ckey i
986end
987for j ulong 96
988put b add 3200 j get Csig j
989end
990for k ulong 48
991put b add 3296 k get Chash k
992end
993cp3init w
994ret eq cp3vrfy w b 1
995end
996
997fn ctchecksig child ulong issuer ulong to bool
998c = mul child 32
999b = mul issuer 32
1000width = get Cm add c 2
1001if ne width get Cm add b 24
1002ret false
1003end
1004if not ctrawsig get Cm add c 9 get Cm add c 10 width
1005ret false
1006end
1007ko = get Cm add b 7
1008kn = get Cm add b 8
1009for i ulong kn
1010put Ckey i get Certbuf add ko i
1011end
1012if eq width 32
1013ctsha256 get Cm c get Cm add c 1
1014ret ctvp256
1015end
1016ctsha384 get Cm c get Cm add c 1
1017ret ctvp384
1018end
1019
1020fn ctclock idx ulong to bool
1021b = mul idx 32
1022if gt get Certnow 0 253402300799
1023ret false
1024end
1025now = add get Certnow 0 62135596800
1026ret and ge now get Cm add b 11 le now get Cm add b 12
1027end
1028
1029fn ctca idx ulong below ulong to bool
1030b = mul idx 32
1031if not ctclock idx
1032ret false
1033end
1034if or ne get Cm add b 13 1 ne get Cm add b 21 1
1035ret false
1036end
1037if or ne get Cm add b 16 1 eq and get Cm add b 15 4 0
1038ret false
1039end
1040if gt below get Cm add b 14
1041ret false
1042end
1043ret eq get Cm add b 17 1
1044end
1045
1046fn ctleaf to bool
1047if not ctclock 0
1048ret false
1049end
1050if ne get Cm 24 32
1051ret false
1052end
1053if ne get Cm 13 0
1054ret false
1055end
1056if or ne get Cm 16 1 eq and get Cm 15 128 0
1057ret false
1058end
1059if ne and get Cm 15 4 0
1060ret false
1061end
1062if or ne get Cm 22 1 ne get Cm 17 1
1063ret false
1064end
1065if or ne get Cm 23 1 ne get Cm 18 1
1066ret false
1067end
1068w = new ulong 1024 0
1069b = new uchar 4096 0
1070cp2init w
1071for i ulong 65
1072put b add 3072 i get Certbuf add get Cm 7 i
1073end
1074cp2ld w C2X b 3073
1075cp2ld w C2Y b 3105
1076ret cp2oncv w
1077end
1078
1079fn certreset to void
1080put Cready 0 0
1081for i ulong 65
1082put Certkey i 0
1083put Cleaf i 0
1084end
1085for i ulong 97
1086put Ckey i 0
1087end
1088for i ulong 96
1089put Csig i 0
1090end
1091for i ulong 48
1092put Chash i 0
1093end
1094for i ulong 4096
1095put Certmsg i 0
1096end
1097for i ulong 128
1098put Certsig i 0
1099end
1100for i ulong 288
1101put Cm i 0
1102end
1103for i ulong 64
1104put Ce i 0
1105end
1106for i ulong 8
1107put Cchain i 0
1108put Ctime i 0
1109end
1110put Cen 0 0
1111put Ccount 0 0
1112end
1113
1114fn ctbe p ulong n ulong to ulong
1115v = ulong 0
1116for i ulong n
1117v = or shl v 8 ulong get Certbuf add p i
1118end
1119ret v
1120end
1121
1122note Certificate-entry extensions are not negotiated by this client; unsolicited ones fail closed.
1123fn ctlist to bool
1124e = get Certlen 0
1125if or lt e 4 gt e 60000
1126ret false
1127end
1128if ne get Certbuf 0 0
1129ret false
1130end
1131if ne ctbe 1 3 sub e 4
1132ret false
1133end
1134p = ulong 4
1135n = ulong 0
1136while lt p e bound 9
1137if or ge n 8 lt sub e p 5
1138ret false
1139end
1140k = ctbe p 3
1141p = add p 3
1142if or eq k 0 gt k 8192
1143ret false
1144end
1145if gt k sub e p
1146ret false
1147end
1148q = add p k
1149note Unused extra certificates may use unsupported algorithms; only parsed ones can be issuers.
1150if not ctparse n p q
1151if eq n 0
1152ret false
1153end
1154end
1155p = q
1156if lt sub e p 2
1157ret false
1158end
1159if ne ctbe p 2 0
1160ret false
1161end
1162p = add p 2
1163n = add n 1
1164end
1165put Ccount 0 n
1166ret and eq p e gt n 0
1167end
1168
1169note Path building uses only supplied certificates plus the local root. Anchor is tried first.
1170note Child's exact issuer Name DER equals candidate parent's subject Name DER.
1171fn ctissued child ulong parent ulong to bool
1172c = mul child 32
1173q = mul parent 32
1174ret ctequal get Cm add c 3 get Cm add c 4 get Cm add q 5 get Cm add q 6
1175end
1176
1177fn ctpath to bool
1178if not ctleaf
1179ret false
1180end
1181idx = ulong 0
1182below = ulong 0
1183for depth ulong 8
1184if ne get Cchain idx 0
1185ret false
1186end
1187put Cchain idx 1
1188if ctissued idx 8
1189if not ctca 8 below
1190ret false
1191end
1192ret ctchecksig idx 8
1193end
1194next = ulong 8
1195for j ulong get Ccount 0
1196ok = eq get Cm add mul j 32 25 1
1197if and ok ctissued idx j
1198if ne next 8
1199ret false
1200end
1201next = j
1202end
1203end
1204if eq next 8
1205ret false
1206end
1207if not ctca next below
1208ret false
1209end
1210if not ctchecksig idx next
1211ret false
1212end
1213idx = next
1214below = add below 1
1215end
1216ret false
1217end
1218
1219fn cthexv c uchar to uchar
1220if and ge c 48 le c 57
1221ret sub c 48
1222end
1223if and ge c 97 le c 102
1224ret sub c 87
1225end
1226trap 5
1227end
1228
1229note Decode vendor/cert-root.om Croot to Certbuf 64000..64574, above every accepted peer byte.
1230fn ctroot to bool
1231if ne len Croot 1148
1232ret false
1233end
1234for i ulong 574
1235h = cthexv get Croot mul i 2
1236l = cthexv get Croot add mul i 2 1
1237put Certbuf add 64000 i or shl h 4 l
1238end
1239ret true
1240end
1241
1242fn certcheck to bool
1243certreset
1244if not ctroot
1245ret false
1246end
1247note The DER root is local and already trusted; parsing only exposes its subject, key and limits.
1248if not ctparse 8 64000 64574
1249ret false
1250end
1251if not ctlist
1252ret false
1253end
1254if not ctpath
1255ret false
1256end
1257for i ulong 65
1258put Certkey i get Certbuf add get Cm 7 i
1259put Cleaf i get Certkey i
1260end
1261put Cready 0 1
1262ret true
1263end
1264
1265note TLS CertificateVerify: current validated leaf required, DER signature and SHA256 message.
1266fn certsig n ulong siglen ulong to bool
1267if ne get Cready 0 1
1268ret false
1269end
1270if or gt n 4096 or eq siglen 0 gt siglen 128
1271certreset
1272ret false
1273end
1274for i ulong siglen
1275put Certbuf add 60000 i get Certsig i
1276end
1277if not ctrawsig 60000 add 60000 siglen 32
1278certreset
1279ret false
1280end
1281constants
1282hinit
1283for j ulong n
1284hbyte get Certmsg j
1285end
1286finish
1287for k ulong 32
1288put Chash k get Hash k
1289end
1290note Private copy: later caller writes to exported Certkey cannot change the authenticated key.
1291for m ulong 65
1292put Ckey m get Cleaf m
1293end
1294ok = ctvp256
1295if not ok
1296certreset
1297end
1298ret ok
1299end