Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/om/tls/rev.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / om / tls / rev.om` 1768 lines ยท 41184 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note om/tls/rev.om (module RV): certificate revocation for the om/tls client. SHA-1 (FIPS 180-4, only 3 note for OCSP CertID and KeyHash, never for a signature), stapled OCSP (RFC 6960 BasicOCSPResponse, 4 note RFC 8446 4.4.2.1 status_request in the leaf CertificateEntry), the TLS Feature extension 5 note (RFC 7633 must-staple) and CRL validation against a caller-supplied CRL (RFC 5280 5, 6.3). 6 note Library unit; compose after x509.om (it reuses der_hdr, der_time, x509_parse, chain_sig, 7 note chain_link, chain_time, chain_index, x509_errname). No globals. 8 note 9 note Inputs (rev_check, rev_ocsp, rev_crl): one buffer b and a descriptor p (ulong 16): p[0] unix now, 10 note p[1] p[2] leaf DER offset and length in b, p[3] p[4] the leaf issuer's DER (rev_issuer finds it), 11 note p[5] p[6] the stapled OCSPResponse (length 0: none), p[7] p[8] a CRL (length 0: none). 12 note 13 note Reject codes continue the x509.om table (rev_errname gives the names; 1..21 are x509.om's): 14 note 32 REVOKED the OCSP response or the CRL lists the leaf as revoked 15 note 33 STATUS_UNKNOWN the OCSP response says unknown, or has no SingleResponse for the leaf 16 note 34 STALE thisUpdate later than now + RVSKEW, nextUpdate absent, or nextUpdate <= now 17 note 35 NO_STAPLE the leaf carries TLS Feature status_request (must-staple) and no staple came 18 note 36 RESPONDER the OCSP signer is neither the issuer nor a certificate issued by it, valid now, 19 note with extKeyUsage id-kp-OCSPSigning; or the responderID names nobody presented 20 note 37 OCSP_STATUS responseStatus is not successful (malformedRequest, tryLater, ...) 21 note 38 CRL_SCOPE the CRL does not cover the leaf: issuer name differs, delta CRL, indirect CRL, 22 note onlyContainsCACerts / onlySomeReasons / onlyContainsAttributeCerts, a relative 23 note distribution point name, or an issuingDistributionPoint none of whose fullName 24 note names is in the leaf's cRLDistributionPoints 25 note x509.om codes used here: 1 MALFORMED, 6 BAD_SIGNATURE, 9 KEY_USAGE (issuer keyUsage without cRLSign), 11/12 algorithm or key policy 26 note (chain_sig), 13 CRITICAL_EXT, 18 ALG_MISMATCH. 27 note 28 note Policy (rev_check): a staple, when present, must verify and say good; a must-staple leaf without a 29 note staple is refused; a CRL, when given, must verify, cover the leaf, be fresh and not list it. With 30 note no staple, no must-staple and no CRL the result is 0: revocation was then NOT checked (soft fail 31 note open, as every browser does without must-staple), which the caller reports. Nothing here is 32 note secret; variable time by design. 33 note 34 note omc limits shape the code: a call carries at most 6 slots (an unsized array is 2, a sized one 1) 35 note and never names one array twice, so the leaf and the issuer are copied into local buffers and 36 note intermediate offsets travel in the sized state arrays o (ulong 32), w (ulong 128), ix (uchar 256). 37 38 const RVEREV ulong 32 39 const RVEUNK ulong 33 40 const RVESTALE ulong 34 41 const RVENOST ulong 35 42 const RVERESP ulong 36 43 const RVEOST ulong 37 44 const RVESCOPE ulong 38 45 note RVSKEW: seconds a thisUpdate may lie in the future (clock skew between responder and client) 46 const RVSKEW ulong 300 47 note RVANY: rev_exts skips the criticality rule; RVNONE: no extension may be critical / none wanted 48 const RVANY ulong 99 49 const RVNONE ulong 98 50 note RVHIT / RVMISS: "found" (must-staple, serial listed) and "absent / names another certificate" 51 note results, distinct from every error code (X5EMAL is 1) 52 const RVHIT ulong 97 53 const RVMISS ulong 96 54 const RVKBUF ulong 16896 55 note RVSER: serial number bytes of the leaf live at ix[RVSER ..), at most RVSERX of them 56 const RVSER ulong 128 57 const RVSERX ulong 128 58 59 note RVOIDS: OID content bytes (hex), space separated, 1-based index by rev_oidin: 60 note 1 id-pe-tlsfeature 1.3.6.1.5.5.7.1.24 (RFC 7633), 2 cRLDistributionPoints, 3 issuingDistributionPoint, 61 note 4 id-kp-OCSPSigning, 5 id-pkix-ocsp-basic, 6 id-sha1 1.3.14.3.2.26, 7 id-sha256, 8 extKeyUsage, 62 note 9 cRLNumber, 10 authorityKeyIdentifier, 11 deltaCRLIndicator, 12 freshestCRL, 13 reasonCode, 63 note 14 invalidityDate, 15 certificateIssuer, 16 id-pkix-ocsp-nonce, 17 authorityInfoAccess 64 text RVOIDS "`2b06010505070118` 551d1f 551d1c `2b06010505070309` `2b0601050507300101` `2b0e03021a` `608648016503040201` 551d25 551d14 551d23 551d1b 551d2e 551d15 551d18 551d1d `2b0601050507300102` `2b06010505070101` " 65 text RVNAMES "REV_ERR_REVOKED REV_ERR_STATUS_UNKNOWN REV_ERR_STALE REV_ERR_NO_STAPLE REV_ERR_RESPONDER REV_ERR_OCSP_STATUS REV_ERR_CRL_SCOPE " 66 67 note ---------------------------------------------------------------- SHA-1 (CertID only) 68 69 note sha1_f: round function and constant of SHA-1 step t (FIPS 180-4 4.1.1, 4.2.1), k selects 70 fn sha1_f t ulong b uint c uint d uint to uint 71 if lt t 20 72 ret or and b c and not b d 73 end 74 if lt t 40 75 ret xor xor b c d 76 end 77 if lt t 60 78 ret or or and b c and b d and c d 79 end 80 ret xor xor b c d 81 end 82 83 fn sha1_k t ulong to uint 84 if lt t 20 85 ret 0x5a827999 86 end 87 if lt t 40 88 ret 0x6ed9eba1 89 end 90 if lt t 60 91 ret 0x8f1bbcdc 92 end 93 ret 0xca62c1d6 94 end 95 96 note sha1_sched: message schedule w[0 .. 80) of the block m[o .. o+64) 97 fn sha1_sched w edit uint 80 m view uchar * o ulong to void 98 for t ulong 16 99 q = add o mul t 4 100 v = or shl uint get m q 24 shl uint get m add q 1 16 101 v = or v or shl uint get m add q 2 8 uint get m add q 3 102 put w t v 103 end 104 for t ulong 64 105 i = add t 16 106 x = xor get w sub i 3 get w sub i 8 107 x = xor x get w sub i 14 108 x = xor x get w sub i 16 109 put w i or shl x 1 shr x 31 110 end 111 end 112 113 note sha1_blk: one SHA-1 compression of m[o .. o+64) into the chaining value h[0 .. 5) 114 fn sha1_blk h edit uint 5 m view uchar * o ulong to void 115 w = new uint 80 0 116 sha1_sched w m o 117 a = get h 0 118 b = get h 1 119 c = get h 2 120 d = get h 3 121 e = get h 4 122 for t ulong 80 123 f = sha1_f t b c d 124 x = add or shl a 5 shr a 27 f 125 x = add x add e sha1_k t 126 x = add x get w t 127 e = d 128 d = c 129 c = or shl b 30 shr b 2 130 b = a 131 a = x 132 end 133 put h 0 add get h 0 a 134 put h 1 add get h 1 b 135 put h 2 add get h 2 c 136 put h 3 add get h 3 d 137 put h 4 add get h 4 e 138 end 139 140 note sha1_pad: the final block(s) after r tail bytes already in t: 0x80, zeros, the 64-bit bit 141 note length of an n-byte message; returns the padded length (64 or 128) 142 fn sha1_pad t edit uchar 128 n ulong r ulong to ulong 143 put t r 128 144 tl = ulong 64 145 if ge r 56 146 tl = 128 147 end 148 bits = mul n 8 149 for i ulong 8 150 q = sub sub tl 1 i 151 put t q uchar and shr bits mul i 8 255 152 end 153 ret tl 154 end 155 156 note sha1_out: the chaining value h big-endian into o[0 .. 20) 157 fn sha1_out h view uint 5 o edit uchar * to void 158 for i ulong 5 159 v = get h i 160 q = mul i 4 161 put o q uchar shr v 24 162 put o add q 1 uchar and shr v 16 255 163 put o add q 2 uchar and shr v 8 255 164 put o add q 3 uchar and v 255 165 end 166 end 167 168 note sha1_digest: SHA-1 of m (any length below 2^61 bytes) into o[0 .. 20); returns 20 169 fn sha1_digest m view uchar * o edit uchar * to ulong 170 h = new uint 5 0 171 t = new uchar 128 0 172 put h 0 0x67452301 173 put h 1 0xefcdab89 174 put h 2 0x98badcfe 175 put h 3 0x10325476 176 put h 4 0xc3d2e1f0 177 n = len m 178 nb = div n 64 179 for i ulong nb 180 sha1_blk h m mul i 64 181 end 182 r = sub n mul nb 64 183 for i ulong r 184 put t i get m add mul nb 64 i 185 end 186 tl = sha1_pad t n r 187 sha1_blk h t 0 188 if eq tl 128 189 sha1_blk h t 64 190 end 191 sha1_out h o 192 ret 20 193 end 194 195 note rev_hash: digest of m with OCSP CertID hash a (6 SHA-1, 7 SHA-256, rev_oidin) into o; length 196 fn rev_hash a ulong m view uchar * o edit uchar * to ulong 197 if eq a 6 198 ret sha1_digest m o 199 end 200 ret sha2_digest 256 m o 201 end 202 203 note ---------------------------------------------------------------- DER helpers 204 205 note rev_tag: der_hdr of the TLV at d[p] (content by e) whose tag must be g; 0 ok, 1 otherwise 206 fn rev_tag d view uchar * p ulong e ulong h edit ulong 3 g ulong to ulong 207 if ne der_hdr d p e h 0 208 ret 1 209 end 210 if ne get h 0 g 211 ret 1 212 end 213 ret 0 214 end 215 216 note rev_oidin: position (1-based) of the OID content d in RVOIDS, 0 when absent 217 fn rev_oidin d view uchar * to ulong 218 s = ulong 0 219 k = ulong 1 220 n = len RVOIDS 221 while lt s n bound 1000 222 j = s 223 while lt j n bound 1000 224 if eq get RVOIDS j 32 225 break 226 end 227 j = add j 1 228 end 229 if der_hexeq d part RVOIDS s sub j s 230 ret k 231 end 232 s = add j 1 233 k = add k 1 234 end 235 ret 0 236 end 237 238 note rev_ext1: one Extension, content c[a .. b) (RFC 5280 4.1): extnID, critical BOOLEAN (0x00 or 0xff, 239 note as x509_ext), extnValue. y[0] critical 0/1, y[1] y[2] extnValue content span, y[3] OID index 240 note (rev_oidin). 0 ok, 1 malformed. 241 fn rev_ext1 c view uchar * a ulong b ulong y edit ulong 4 to ulong 242 h = new ulong 3 0 243 if ne rev_tag c a b h 6 0 244 ret 1 245 end 246 put y 3 rev_oidin part c get h 1 sub get h 2 get h 1 247 put y 0 0 248 s = get h 2 249 if ne der_hdr c s b h 0 250 ret 1 251 end 252 if eq get h 0 1 253 if ne sub get h 2 get h 1 1 254 ret 1 255 end 256 v = ulong get c get h 1 257 if and ne v 0 ne v 255 258 ret 1 259 end 260 if eq v 255 261 put y 0 1 262 end 263 s = get h 2 264 if ne der_hdr c s b h 0 265 ret 1 266 end 267 end 268 if or ne get h 0 4 ne get h 2 b 269 ret 1 270 end 271 put y 1 get h 1 272 put y 2 b 273 ret 0 274 end 275 276 note rev_extk: criticality rule for the parsed extension y: x[13] is the one OID index that may be 277 note critical (RVNONE: none; RVANY: skip the rule). deltaCRLIndicator and certificateIssuer are 278 note RVESCOPE (delta and indirect CRLs are not supported); any other critical extension X5ECRIT. 279 fn rev_extk y view ulong 4 x view ulong 16 to ulong 280 ok = get x 13 281 if or eq ok RVANY eq get y 0 0 282 ret 0 283 end 284 o = get y 3 285 if and eq o ok ne o 0 286 ret 0 287 end 288 if or eq o 11 eq o 15 289 ret RVESCOPE 290 end 291 ret X5ECRIT 292 end 293 294 note rev_exts: Extensions SEQUENCE TLV that is exactly c[a .. b) (1..X5XMAX entries). The extension 295 note with OID index x[12] is recorded: x[4] 1, x[5] critical, x[6] x[7] its extnValue content span (a 296 note second one is X5EMAL). Criticality per rev_extk. 297 fn rev_exts c view uchar * a ulong b ulong x edit ulong 16 to ulong 298 h = new ulong 3 0 299 y = new ulong 4 0 300 put x 4 0 301 if ne rev_tag c a b h 0x30 0 302 ret X5EMAL 303 end 304 if or ne get h 2 b eq get h 1 b 305 ret X5EMAL 306 end 307 s = get h 1 308 n = ulong 0 309 while lt s b bound 100 310 n = add n 1 311 if gt n X5XMAX 312 ret X5EMAL 313 end 314 if ne rev_tag c s b h 0x30 0 315 ret X5EMAL 316 end 317 s = get h 2 318 if ne rev_ext1 c get h 1 s y 0 319 ret X5EMAL 320 end 321 k = rev_extk y x 322 if ne k 0 323 ret k 324 end 325 if eq get y 3 get x 12 326 if ne get x 4 0 327 ret X5EMAL 328 end 329 put x 4 1 330 put x 5 get y 0 331 put x 6 get y 1 332 put x 7 get y 2 333 end 334 end 335 ret 0 336 end 337 338 note rev_certx: in the certificate c (record r from x509_parse): its serialNumber INTEGER content span 339 note into x[10] x[11], and its Extensions SEQUENCE TLV into x[8] x[9] (both 0 when it has none). 340 note 0 ok, X5EMAL. 341 fn rev_certx c view uchar * r view ulong * x edit ulong 16 to ulong 342 h = new ulong 3 0 343 put x 8 0 344 put x 9 0 345 a = get r X5RTBO 346 if ne rev_tag c a len c h 0x30 0 347 ret X5EMAL 348 end 349 b = get h 2 350 s = get h 1 351 if ne der_hdr c s b h 0 352 ret X5EMAL 353 end 354 if eq get h 0 0xa0 355 s = get h 2 356 if ne der_hdr c s b h 0 357 ret X5EMAL 358 end 359 end 360 if ne get h 0 2 361 ret X5EMAL 362 end 363 put x 10 get h 1 364 put x 11 get h 2 365 s = get h 2 366 while lt s b bound 16 367 if ne der_hdr c s b h 0 368 ret X5EMAL 369 end 370 if eq get h 0 0xa3 371 s = get h 1 372 if ne der_hdr c s get h 2 h 0 373 ret X5EMAL 374 end 375 put x 8 s 376 put x 9 get h 2 377 ret 0 378 end 379 s = get h 2 380 end 381 ret 0 382 end 383 384 note rev_certext: extension with OID index x[12] of the certificate c (record r): 0 found (x[6] x[7] 385 note value span), RVMISS absent, X5EMAL. x509_parse already policed the certificate's criticality. 386 fn rev_certext c view uchar * r view ulong * x edit ulong 16 to ulong 387 v = rev_certx c r x 388 if ne v 0 389 ret v 390 end 391 if eq get x 9 0 392 ret RVMISS 393 end 394 put x 13 RVANY 395 v = rev_exts c get x 8 get x 9 x 396 if ne v 0 397 ret v 398 end 399 if eq get x 4 0 400 ret RVMISS 401 end 402 ret 0 403 end 404 405 note ---------------------------------------------------------------- must-staple (RFC 7633) 406 407 note rev_mustst: the certificate c: RVHIT when its TLS Feature extension lists status_request (5), 0 when 408 note it has none or the list lacks 5, X5EMAL when the certificate or the extension is malformed 409 note (Features ::= SEQUENCE OF INTEGER, each 0..65535, at least one) 410 fn rev_mustst c view uchar * to ulong 411 r = new ulong 32 0 412 x = new ulong 16 0 413 h = new ulong 3 0 414 if ne x509_parse c r 0 415 ret X5EMAL 416 end 417 put x 12 1 418 v = rev_certext c r x 419 if eq v RVMISS 420 ret 0 421 end 422 if ne v 0 423 ret v 424 end 425 b = get x 7 426 if ne rev_tag c get x 6 b h 0x30 0 427 ret X5EMAL 428 end 429 if or ne get h 2 b eq get h 1 b 430 ret X5EMAL 431 end 432 s = get h 1 433 m = ulong 0 434 while lt s b bound 1000 435 if ne rev_tag c s b h 2 0 436 ret X5EMAL 437 end 438 f = der_small part c s sub get h 2 s 439 if gt f 65535 440 ret X5EMAL 441 end 442 if eq f 5 443 m = RVHIT 444 end 445 s = get h 2 446 end 447 ret m 448 end 449 450 note ---------------------------------------------------------------- shared state and setup 451 452 note State o (ulong 32): 0 now (x509 seconds), 1 signed TLV start (ResponseData or tbsCertList), 2 its 453 note length, 3 signature algorithm (x509_algid), 4 signature value start, 5 its length. OCSP: 6 7 454 note certs content span (0 0 none), 8 responderID tag (0xa1 byName, 0xa2 byKey), 9 10 its content 455 note span, 11 12 responses content span, 13 14 responseExtensions span, 16 status (0 good, 1 revoked, 456 note 2 unknown), 17 thisUpdate, 18 nextUpdate (X5BIG none), 20 21 BasicOCSPResponse content span, 24 457 note 25 26 27 candidate signer subject and key spans, 28 29 CertID content span, 30 31 SingleResponse 458 note span. CRL: 11 12 revokedCertificates content span, 13 14 crlExtensions SEQUENCE span, 17 18 as 459 note above, 24 25 tbsCertList content span, 26 27 outer signatureAlgorithm TLV start and length, 28 29 460 note issuer Name TLV start and length, 30 31 issuingDistributionPoint fullName content span (0 0 461 note none). Both: 22 leaf serial length (bytes at ix[RVSER ..)). 462 note Workspace w (ulong 128): w[0 .. 32) and w[32 .. 64) are x509 records (leaf or candidate, issuer 463 note or signer: the chain_link layout), 64 leaf length, 65 issuer length, 66 now. 464 note ix (uchar 256): CertID hashes of the issuer (rev_ids) at 0 .. 104, the leaf serial at RVSER. 465 466 note rev_now: unix seconds nw as x509 seconds (x509_chain_verify's scale); X5BIG beyond 9999 467 fn rev_now nw ulong to ulong 468 if gt nw `253402300799` 469 ret X5BIG 470 end 471 ret add nw mul x509_days 1970 1 1 86400 472 end 473 474 note rev_span: p[i] .. p[i] + p[i+1] lies within b 475 fn rev_span b view uchar * p view ulong 16 i ulong to bool 476 a = get p i 477 if gt a len b 478 ret false 479 end 480 ret le get p add i 1 sub len b a 481 end 482 483 note rev_load: the certificate p[k] .. p[k] + p[k+1] of b copied into d and parsed into the x509 484 note record w[j*32 .. j*32+32) (j = (k-1)/2), its length into w[64+j]. 0 or X5EMAL. 485 fn rev_load b view uchar * p view ulong 16 k ulong d edit uchar 16896 w edit ulong 128 to ulong 486 if not rev_span b p k 487 ret X5EMAL 488 end 489 l = get p add k 1 490 if or eq l 0 gt l RVKBUF 491 ret X5EMAL 492 end 493 a = get p k 494 for i ulong l 495 put d i get b add a i 496 end 497 a = mul div sub k 1 2 X5RSZ 498 put w add 64 div a X5RSZ l 499 if ne x509_parse part d 0 l part w a X5RSZ 0 500 ret X5EMAL 501 end 502 ret 0 503 end 504 505 note rev_setup: now into w[66]; the leaf and the issuer (p[1 .. 4]) copied into lb and ib and parsed 506 note into w[0 .. 32) and w[32 .. 64); their lengths into w[64] w[65]. 0 or X5EMAL. 507 fn rev_setup b view uchar * p view ulong 16 lb edit uchar 16896 ib edit uchar 16896 w edit ulong 128 to ulong 508 nw = rev_now get p 0 509 if eq nw X5BIG 510 ret X5EMAL 511 end 512 put w 66 nw 513 if ne rev_load b p 1 lb w 0 514 ret X5EMAL 515 end 516 ret rev_load b p 3 ib w 517 end 518 519 note rev_serial: the leaf serial (INTEGER content, 1 .. RVSERX bytes) into ix[RVSER ..), length o[22] 520 fn rev_serial lb view uchar 16896 w view ulong 128 ix edit uchar 256 o edit ulong 32 to ulong 521 x = new ulong 16 0 522 v = rev_certx part lb 0 get w 64 part w 0 X5RSZ x 523 if ne v 0 524 ret v 525 end 526 a = get x 10 527 n = sub get x 11 a 528 if or eq n 0 gt n RVSERX 529 ret X5EMAL 530 end 531 for i ulong n 532 put ix add RVSER i get lb add a i 533 end 534 put o 22 n 535 ret 0 536 end 537 538 note rev_sereq: the INTEGER content d[a .. b) is the leaf serial (n bytes at t[RVSER ..)) 539 fn rev_sereq d view uchar * a ulong b ulong t view uchar 256 n ulong to bool 540 if ne sub b a n 541 ret false 542 end 543 for i ulong n 544 if ne get d add a i get t add RVSER i 545 ret false 546 end 547 end 548 ret true 549 end 550 551 note rev_sig: the signature over d[o[1] .. +o[2]) (algorithm o[3], value o[4] .. +o[5]) with the key of 552 note kd (record w[32 .. 64)); w[0 .. 32) becomes the pseudo-record chain_sig reads. chain_sig applies 553 note x509.om's algorithm and key policy. 0, X5ESIG, X5EALG, X5EWEAK. 554 fn rev_sig d view uchar * kd view uchar * w edit ulong 128 o view ulong 32 to ulong 555 put w X5RALG get o 3 556 put w X5RTBO get o 1 557 put w X5RTBL get o 2 558 put w X5RSGO get o 4 559 put w X5RSGL get o 5 560 ret chain_sig d kd part w 0 mul X5RSZ 2 561 end 562 563 note rev_fresh: thisUpdate o[17] <= now + RVSKEW, nextUpdate o[18] present and later than now (RFC 6960 564 note 4.2.2.1; RFC 5280 6.3.3 a.1 and a.2); 0 or RVESTALE 565 fn rev_fresh o view ulong 32 to ulong 566 nw = get o 0 567 if gt get o 17 add nw RVSKEW 568 ret RVESTALE 569 end 570 if eq get o 18 X5BIG 571 ret RVESTALE 572 end 573 if le get o 18 nw 574 ret RVESTALE 575 end 576 ret 0 577 end 578 579 note ---------------------------------------------------------------- OCSP (RFC 6960) 580 581 note rev_ids: the CertID hashes of the issuer ib (record w[32 .. 64)) into ix: SHA-1 of its subject 582 note Name DER at 0, of its subjectPublicKey bits at 20; SHA-256 of the same at 40 and 72 (RFC 6960 4.1.1) 583 fn rev_ids ib view uchar 16896 w view ulong 128 ix edit uchar 256 to void 584 d = new uchar 32 0 585 for k ulong 2 586 a = add ulong 6 k 587 n = rev_hash a part ib get w add X5RSZ X5RSBO get w add X5RSZ X5RSBL d 588 b = mul k 40 589 for i ulong n 590 put ix add b i get d i 591 end 592 n = rev_hash a part ib get w add X5RSZ X5RKO get w add X5RSZ X5RKL d 593 b = add b n 594 for i ulong n 595 put ix add b i get d i 596 end 597 end 598 end 599 600 note rev_octeq: the OCTET STRING TLV at d[p] (by e) holds the hash t[q ..) (20 bytes below q = 40, 601 note else 32); its end offset when it does, else 0 602 fn rev_octeq d view uchar * p ulong e ulong t view uchar 256 q ulong to ulong 603 h = new ulong 3 0 604 n = ulong 20 605 if ge q 40 606 n = 32 607 end 608 if ne rev_tag d p e h 4 0 609 ret 0 610 end 611 if ne sub get h 2 get h 1 n 612 ret 0 613 end 614 s = get h 1 615 for i ulong n 616 if ne get d add s i get t add q i 617 ret 0 618 end 619 end 620 ret get h 2 621 end 622 623 note rev_hashalg: AlgorithmIdentifier TLV that is exactly rs[a .. s): 6 SHA-1 or 7 SHA-256, parameters 624 note absent or NULL; 0 for anything else 625 fn rev_hashalg rs view uchar * a ulong s ulong to ulong 626 h = new ulong 3 0 627 if ne rev_tag rs a s h 0x30 0 628 ret 0 629 end 630 if ne get h 2 s 631 ret 0 632 end 633 if ne rev_tag rs get h 1 s h 6 0 634 ret 0 635 end 636 o = rev_oidin part rs get h 1 sub get h 2 get h 1 637 q = get h 2 638 if ne q s 639 if not der_null rs q s 640 ret 0 641 end 642 end 643 if or eq o 6 eq o 7 644 ret o 645 end 646 ret 0 647 end 648 649 note rev_certid: CertID content rs[o[28] .. o[29]): 0 when it names the leaf (issuer hashes ix, serial 650 note ix[RVSER ..)), RVMISS when it names another certificate, X5EMAL 651 fn rev_certid rs view uchar * o view ulong 32 ix view uchar 256 to ulong 652 h = new ulong 3 0 653 a = get o 28 654 b = get o 29 655 if ne rev_tag rs a b h 0x30 0 656 ret X5EMAL 657 end 658 s = get h 2 659 al = rev_hashalg rs a s 660 if eq al 0 661 ret RVMISS 662 end 663 q = ulong 0 664 r = ulong 20 665 if eq al 7 666 q = 40 667 r = 72 668 end 669 t = rev_octeq rs s b ix q 670 if eq t 0 671 ret RVMISS 672 end 673 t = rev_octeq rs t b ix r 674 if eq t 0 675 ret RVMISS 676 end 677 if ne rev_tag rs t b h 2 0 678 ret X5EMAL 679 end 680 if ne get h 2 b 681 ret X5EMAL 682 end 683 if not rev_sereq rs get h 1 b ix get o 22 684 ret RVMISS 685 end 686 ret 0 687 end 688 689 note rev_rinfo: RevokedInfo content rs[a .. b): revocationTime GeneralizedTime, optional 690 note revocationReason [0] EXPLICIT CRLReason (ENUMERATED 0..10, 7 unused). 0 or X5EMAL. 691 fn rev_rinfo rs view uchar * a ulong b ulong to ulong 692 h = new ulong 3 0 693 if ne rev_tag rs a b h 24 0 694 ret X5EMAL 695 end 696 if eq der_time part rs a sub get h 2 a X5BIG 697 ret X5EMAL 698 end 699 s = get h 2 700 if eq s b 701 ret 0 702 end 703 if ne rev_tag rs s b h 0xa0 0 704 ret X5EMAL 705 end 706 if ne get h 2 b 707 ret X5EMAL 708 end 709 if ne rev_tag rs get h 1 b h 10 0 710 ret X5EMAL 711 end 712 if or ne get h 2 b ne sub b get h 1 1 713 ret X5EMAL 714 end 715 v = ulong get rs get h 1 716 if or gt v 10 eq v 7 717 ret X5EMAL 718 end 719 ret 0 720 end 721 722 note rev_cstat: certStatus header h of rs: 0 good ([0] IMPLICIT NULL), 1 revoked ([1] RevokedInfo, 723 note checked), 2 unknown ([2] IMPLICIT NULL), 3 malformed 724 fn rev_cstat rs view uchar * h view ulong 3 to ulong 725 g = get h 0 726 n = sub get h 2 get h 1 727 if eq g 0x80 728 if eq n 0 729 ret 0 730 end 731 ret 3 732 end 733 if eq g 0x82 734 if eq n 0 735 ret 2 736 end 737 ret 3 738 end 739 if eq g 0xa1 740 if eq rev_rinfo rs get h 1 get h 2 0 741 ret 1 742 end 743 end 744 ret 3 745 end 746 747 note rev_single: the SingleResponse TLV that is exactly rs[o[30] .. o[31]): certID, certStatus, 748 note thisUpdate, optional nextUpdate [0], optional singleExtensions [1] (none critical). RVMISS when 749 note its CertID is not the leaf's; 0 when it is, with o[16] status, o[17] thisUpdate, o[18] nextUpdate. 750 fn rev_single rs view uchar * ix view uchar 256 o edit ulong 32 to ulong 751 h = new ulong 3 0 752 x = new ulong 16 0 753 b = get o 31 754 if ne rev_tag rs get o 30 b h 0x30 0 755 ret X5EMAL 756 end 757 if ne get h 2 b 758 ret X5EMAL 759 end 760 if ne rev_tag rs get h 1 b h 0x30 0 761 ret X5EMAL 762 end 763 put o 28 get h 1 764 put o 29 get h 2 765 s = get h 2 766 v = rev_certid rs o ix 767 if ne v 0 768 ret v 769 end 770 if ne der_hdr rs s b h 0 771 ret X5EMAL 772 end 773 v = rev_cstat rs h 774 if eq v 3 775 ret X5EMAL 776 end 777 put o 16 v 778 s = get h 2 779 if ne rev_tag rs s b h 24 0 780 ret X5EMAL 781 end 782 t = der_time part rs s sub get h 2 s 783 if eq t X5BIG 784 ret X5EMAL 785 end 786 put o 17 t 787 put o 18 X5BIG 788 s = get h 2 789 if lt s b 790 if ne der_hdr rs s b h 0 791 ret X5EMAL 792 end 793 if eq get h 0 0xa0 794 e = get h 2 795 s = get h 1 796 if ne rev_tag rs s e h 24 0 797 ret X5EMAL 798 end 799 if ne get h 2 e 800 ret X5EMAL 801 end 802 t = der_time part rs s sub e s 803 if eq t X5BIG 804 ret X5EMAL 805 end 806 put o 18 t 807 s = e 808 end 809 end 810 if lt s b 811 if ne rev_tag rs s b h 0xa1 0 812 ret X5EMAL 813 end 814 if ne get h 2 b 815 ret X5EMAL 816 end 817 put x 12 RVNONE 818 put x 13 RVNONE 819 v = rev_exts rs get h 1 b x 820 if ne v 0 821 ret v 822 end 823 s = b 824 end 825 if ne s b 826 ret X5EMAL 827 end 828 ret 0 829 end 830 831 note rev_resps: the responses o[11] .. o[12]: the first SingleResponse for the leaf (rev_single); 0 832 note found, RVMISS none, else a code. At most 256 SingleResponses. 833 fn rev_resps rs view uchar * ix view uchar 256 o edit ulong 32 to ulong 834 h = new ulong 3 0 835 s = get o 11 836 e = get o 12 837 n = ulong 0 838 while lt s e bound 1000 839 n = add n 1 840 if gt n 256 841 ret X5EMAL 842 end 843 if ne der_hdr rs s e h 0 844 ret X5EMAL 845 end 846 t = get h 2 847 put o 30 s 848 put o 31 t 849 v = rev_single rs ix o 850 if ne v RVMISS 851 ret v 852 end 853 s = t 854 end 855 ret RVMISS 856 end 857 858 note rev_ocsp1: OCSPResponse that is exactly rs: responseStatus successful (else RVEOST), responseBytes 859 note id-pkix-ocsp-basic; the BasicOCSPResponse content span into o[20] o[21] 860 fn rev_ocsp1 rs view uchar * o edit ulong 32 to ulong 861 h = new ulong 3 0 862 e = len rs 863 if ne rev_tag rs 0 e h 0x30 0 864 ret X5EMAL 865 end 866 if ne get h 2 e 867 ret X5EMAL 868 end 869 if ne rev_tag rs get h 1 e h 10 0 870 ret X5EMAL 871 end 872 if ne sub get h 2 get h 1 1 873 ret X5EMAL 874 end 875 c = ulong get rs get h 1 876 if ne c 0 877 if or gt c 6 eq c 4 878 ret X5EMAL 879 end 880 ret RVEOST 881 end 882 if ne rev_tag rs get h 2 e h 0xa0 0 883 ret X5EMAL 884 end 885 if ne get h 2 e 886 ret X5EMAL 887 end 888 if ne rev_tag rs get h 1 e h 0x30 0 889 ret X5EMAL 890 end 891 if ne get h 2 e 892 ret X5EMAL 893 end 894 if ne rev_tag rs get h 1 e h 6 0 895 ret X5EMAL 896 end 897 if ne rev_oidin part rs get h 1 sub get h 2 get h 1 5 898 ret X5EMAL 899 end 900 if ne rev_tag rs get h 2 e h 4 0 901 ret X5EMAL 902 end 903 if ne get h 2 e 904 ret X5EMAL 905 end 906 if ne rev_tag rs get h 1 e h 0x30 0 907 ret X5EMAL 908 end 909 if ne get h 2 e 910 ret X5EMAL 911 end 912 put o 20 get h 1 913 put o 21 e 914 ret 0 915 end 916 917 note rev_basic: BasicOCSPResponse content rs[o[20] .. o[21]): tbsResponseData, signatureAlgorithm, 918 note signature BIT STRING (no unused bits), optional certs [0] SEQUENCE OF Certificate 919 fn rev_basic rs view uchar * o edit ulong 32 to ulong 920 h = new ulong 3 0 921 e = get o 21 922 s = get o 20 923 if ne rev_tag rs s e h 0x30 0 924 ret X5EMAL 925 end 926 put o 1 s 927 put o 2 sub get h 2 s 928 s = get h 2 929 if ne rev_tag rs s e h 0x30 0 930 ret X5EMAL 931 end 932 put o 3 x509_algid part rs s sub get h 2 s 933 s = get h 2 934 if ne rev_tag rs s e h 3 0 935 ret X5EMAL 936 end 937 q = get h 1 938 if or ge q get h 2 ne get rs q 0 939 ret X5EMAL 940 end 941 put o 4 add q 1 942 put o 5 sub sub get h 2 q 1 943 s = get h 2 944 put o 6 0 945 put o 7 0 946 if eq s e 947 ret 0 948 end 949 if ne rev_tag rs s e h 0xa0 0 950 ret X5EMAL 951 end 952 if ne get h 2 e 953 ret X5EMAL 954 end 955 if ne rev_tag rs get h 1 e h 0x30 0 956 ret X5EMAL 957 end 958 if ne get h 2 e 959 ret X5EMAL 960 end 961 put o 6 get h 1 962 put o 7 e 963 ret 0 964 end 965 966 note rev_rdata: ResponseData (RFC 6960 4.2.1) at rs[o[1] .. +o[2]): version absent (v1; an explicit 967 note DEFAULT is not DER), responderID [1] or [2], producedAt, responses (at least one), optional 968 note responseExtensions [1] with no critical extension 969 fn rev_rdata rs view uchar * o edit ulong 32 to ulong 970 h = new ulong 3 0 971 x = new ulong 16 0 972 s = get o 1 973 e = add s get o 2 974 if ne rev_tag rs s e h 0x30 0 975 ret X5EMAL 976 end 977 s = get h 1 978 if ne der_hdr rs s e h 0 979 ret X5EMAL 980 end 981 g = get h 0 982 if and ne g 0xa1 ne g 0xa2 983 ret X5EMAL 984 end 985 put o 8 g 986 put o 9 get h 1 987 put o 10 get h 2 988 s = get h 2 989 if ne rev_tag rs s e h 24 0 990 ret X5EMAL 991 end 992 if eq der_time part rs s sub get h 2 s X5BIG 993 ret X5EMAL 994 end 995 s = get h 2 996 if ne rev_tag rs s e h 0x30 0 997 ret X5EMAL 998 end 999 if eq get h 1 get h 2 1000 ret X5EMAL 1001 end 1002 put o 11 get h 1 1003 put o 12 get h 2 1004 s = get h 2 1005 put o 13 0 1006 put o 14 0 1007 if eq s e 1008 ret 0 1009 end 1010 if ne rev_tag rs s e h 0xa1 0 1011 ret X5EMAL 1012 end 1013 if ne get h 2 e 1014 ret X5EMAL 1015 end 1016 put o 13 get h 1 1017 put o 14 e 1018 put x 12 RVNONE 1019 put x 13 RVNONE 1020 ret rev_exts rs get h 1 e x 1021 end 1022 1023 note rev_ridm: the responderID (o[8] tag, o[9] .. o[10] content) names the candidate c whose subject 1024 note and key spans are o[24] o[25] o[26] o[27]: byName [1] the Name DER equals the subject; byKey [2] 1025 note the KeyHash OCTET STRING is the SHA-1 of the subjectPublicKey bits (RFC 6960 4.2.1) 1026 fn rev_ridm rs view uchar * o view ulong 32 c view uchar * to bool 1027 d = new uchar 256 0 1028 a = get o 9 1029 b = get o 10 1030 if eq get o 8 0xa1 1031 ret der_same part rs a sub b a part c get o 24 get o 25 1032 end 1033 n = sha1_digest part c get o 26 get o 27 d 1034 if ne n 20 1035 ret false 1036 end 1037 ret eq rev_octeq rs a b d 0 b 1038 end 1039 1040 note rev_ocspeku: the certificate c (record r) has extKeyUsage with id-kp-OCSPSigning: 0, else 1 1041 fn rev_ocspeku c view uchar * r view ulong * to ulong 1042 x = new ulong 16 0 1043 h = new ulong 3 0 1044 put x 12 8 1045 if ne rev_certext c r x 0 1046 ret 1 1047 end 1048 b = get x 7 1049 if ne rev_tag c get x 6 b h 0x30 0 1050 ret 1 1051 end 1052 s = get h 1 1053 while lt s b bound 10000 1054 if ne rev_tag c s b h 6 0 1055 ret 1 1056 end 1057 if eq rev_oidin part c get h 1 sub get h 2 get h 1 4 1058 ret 0 1059 end 1060 s = get h 2 1061 end 1062 ret 1 1063 end 1064 1065 note rev_dchk: the candidate c (record in w[0 .. 32)) is an authorized responder for the issuer is 1066 note (record in w[32 .. 64)): issued by is (chain_link), valid at o[0], with extKeyUsage 1067 note id-kp-OCSPSigning. On success its record moves to w[32 .. 64) as the signer. 0 or RVERESP. 1068 fn rev_dchk c view uchar * is view uchar * w edit ulong 128 o view ulong 32 to ulong 1069 if ne chain_link c is part w 0 64 0 1070 ret RVERESP 1071 end 1072 if ne chain_time part w 0 X5RSZ get o 0 0 1073 ret RVERESP 1074 end 1075 if ne rev_ocspeku c part w 0 X5RSZ 0 1076 ret RVERESP 1077 end 1078 for i ulong X5RSZ 1079 put w add X5RSZ i get w i 1080 end 1081 ret 0 1082 end 1083 1084 note rev_cp: s[a .. a+l) into d[0 .. l) 1085 fn rev_cp d edit uchar * s view uchar * a ulong l ulong to void 1086 for i ulong l 1087 put d i get s add a i 1088 end 1089 end 1090 1091 note rev_deleg: the certificate among o[6] .. o[7] (the BasicOCSPResponse certs) that the responderID 1092 note names, copied into kb (length o[23]) with its record in w[0 .. 32). 0, RVERESP when none is 1093 note named (RFC 6960 4.2.2.2), X5EMAL on bad framing. 1094 fn rev_deleg rs view uchar * o edit ulong 32 w edit ulong 128 kb edit uchar 16896 to ulong 1095 h = new ulong 3 0 1096 s = get o 6 1097 while lt s get o 7 bound 64 1098 if ne rev_tag rs s get o 7 h 0x30 0 1099 ret X5EMAL 1100 end 1101 l = sub get h 2 s 1102 if gt l RVKBUF 1103 ret X5EMAL 1104 end 1105 rev_cp kb rs s l 1106 s = get h 2 1107 if ne x509_parse part kb 0 l part w 0 X5RSZ 0 1108 continue 1109 end 1110 put o 23 l 1111 put o 24 get w X5RSBO 1112 put o 25 get w X5RSBL 1113 put o 26 get w X5RKO 1114 put o 27 get w X5RKL 1115 if rev_ridm rs o part kb 0 l 1116 ret 0 1117 end 1118 end 1119 ret RVERESP 1120 end 1121 1122 note rev_auth: the response signer: the issuer is itself when the responderID names it, else the 1123 note named delegated responder (rev_deleg) when it is issued by is, valid at o[0] and carries 1124 note id-kp-OCSPSigning (rev_dchk); then the response signature with the signer's key. w[32 .. 64) 1125 note holds the record of is on entry. 1126 fn rev_auth rs view uchar * is view uchar * o edit ulong 32 w edit ulong 128 to ulong 1127 put o 24 get w add X5RSZ X5RSBO 1128 put o 25 get w add X5RSZ X5RSBL 1129 put o 26 get w add X5RSZ X5RKO 1130 put o 27 get w add X5RSZ X5RKL 1131 if rev_ridm rs o is 1132 ret rev_sig rs is w o 1133 end 1134 kb = new uchar 16896 0 1135 v = rev_deleg rs o w kb 1136 if ne v 0 1137 ret v 1138 end 1139 if ne rev_dchk part kb 0 get o 23 is w o 0 1140 ret RVERESP 1141 end 1142 ret rev_sig rs part kb 0 get o 23 w o 1143 end 1144 1145 note rev_ocspr: the OCSPResponse rs: framing and responseStatus, ResponseData, the signer and its 1146 note signature, the leaf's SingleResponse, its status (revoked RVEREV, unknown or missing RVEUNK), 1147 note then freshness (rev_fresh) 1148 fn rev_ocspr rs view uchar * ib view uchar 16896 o edit ulong 32 w edit ulong 128 ix view uchar 256 to ulong 1149 v = rev_ocsp1 rs o 1150 if eq v 0 1151 v = rev_basic rs o 1152 end 1153 if eq v 0 1154 v = rev_rdata rs o 1155 end 1156 if eq v 0 1157 v = rev_auth rs part ib 0 get w 65 o w 1158 end 1159 if ne v 0 1160 ret v 1161 end 1162 v = rev_resps rs ix o 1163 if eq v RVMISS 1164 ret RVEUNK 1165 end 1166 if ne v 0 1167 ret v 1168 end 1169 st = get o 16 1170 if eq st 1 1171 ret RVEREV 1172 end 1173 if eq st 2 1174 ret RVEUNK 1175 end 1176 ret rev_fresh o 1177 end 1178 1179 note rev_ocsp: the stapled OCSPResponse b[p[5] .. +p[6]) for the leaf p[1 .. 2] issued by p[3 .. 4] at 1180 note unix time p[0]; 0 = signed by an authorized responder, good and fresh 1181 fn rev_ocsp b view uchar * p view ulong 16 to ulong 1182 o = new ulong 32 0 1183 w = new ulong 128 0 1184 ix = new uchar 256 0 1185 lb = new uchar 16896 0 1186 ib = new uchar 16896 0 1187 v = rev_setup b p lb ib w 1188 if ne v 0 1189 ret v 1190 end 1191 put o 0 get w 66 1192 v = rev_serial lb w ix o 1193 if ne v 0 1194 ret v 1195 end 1196 rev_ids ib w ix 1197 if or eq get p 6 0 not rev_span b p 5 1198 ret X5EMAL 1199 end 1200 ret rev_ocspr part b get p 5 get p 6 ib o w ix 1201 end 1202 1203 note ---------------------------------------------------------------- CRL (RFC 5280 5, 6.3) 1204 1205 note rev_cl1: CertificateList that is exactly cr: tbsCertList, signatureAlgorithm, signatureValue 1206 note (BIT STRING, no unused bits) 1207 fn rev_cl1 cr view uchar * o edit ulong 32 to ulong 1208 h = new ulong 3 0 1209 e = len cr 1210 if ne rev_tag cr 0 e h 0x30 0 1211 ret X5EMAL 1212 end 1213 if ne get h 2 e 1214 ret X5EMAL 1215 end 1216 s = get h 1 1217 if ne rev_tag cr s e h 0x30 0 1218 ret X5EMAL 1219 end 1220 put o 1 s 1221 put o 2 sub get h 2 s 1222 put o 24 get h 1 1223 put o 25 get h 2 1224 s = get h 2 1225 if ne rev_tag cr s e h 0x30 0 1226 ret X5EMAL 1227 end 1228 put o 3 x509_algid part cr s sub get h 2 s 1229 put o 26 s 1230 put o 27 sub get h 2 s 1231 s = get h 2 1232 if ne rev_tag cr s e h 3 0 1233 ret X5EMAL 1234 end 1235 if ne get h 2 e 1236 ret X5EMAL 1237 end 1238 q = get h 1 1239 if or ge q e ne get cr q 0 1240 ret X5EMAL 1241 end 1242 put o 4 add q 1 1243 put o 5 sub sub e q 1 1244 ret 0 1245 end 1246 1247 note rev_times: thisUpdate and optional nextUpdate (UTCTime or GeneralizedTime) at cr[s ..) by e into 1248 note o[17] o[18] (X5BIG none); the offset after them, 0 when malformed 1249 fn rev_times cr view uchar * s ulong e ulong o edit ulong 32 to ulong 1250 h = new ulong 3 0 1251 if ne der_hdr cr s e h 0 1252 ret 0 1253 end 1254 if and ne get h 0 23 ne get h 0 24 1255 ret 0 1256 end 1257 t = der_time part cr s sub get h 2 s 1258 if eq t X5BIG 1259 ret 0 1260 end 1261 put o 17 t 1262 put o 18 X5BIG 1263 s = get h 2 1264 if lt s e 1265 if ne der_hdr cr s e h 0 1266 ret 0 1267 end 1268 if or eq get h 0 23 eq get h 0 24 1269 t = der_time part cr s sub get h 2 s 1270 if eq t X5BIG 1271 ret 0 1272 end 1273 put o 18 t 1274 s = get h 2 1275 end 1276 end 1277 ret s 1278 end 1279 1280 note rev_tbsl: tbsCertList content cr[o[24] .. o[25]): version v2 (INTEGER 1; required with 1281 note extensions, RFC 5280 5.1.2.1), signature equal to the outer algorithm (X5EAMIS), issuer (span into 1282 note o[28] o[29]), thisUpdate, optional nextUpdate, optional revokedCertificates (non-empty when 1283 note present), optional crlExtensions [0] 1284 fn rev_tbsl cr view uchar * o edit ulong 32 to ulong 1285 h = new ulong 3 0 1286 s = get o 24 1287 e = get o 25 1288 vr = ulong 0 1289 if ne der_hdr cr s e h 0 1290 ret X5EMAL 1291 end 1292 if eq get h 0 2 1293 if ne der_small part cr s sub get h 2 s 1 1294 ret X5EMAL 1295 end 1296 vr = 1 1297 s = get h 2 1298 end 1299 if ne rev_tag cr s e h 0x30 0 1300 ret X5EMAL 1301 end 1302 if ne sub get h 2 s get o 27 1303 ret X5EAMIS 1304 end 1305 if not der_eqat cr s get o 26 get o 27 1306 ret X5EAMIS 1307 end 1308 s = get h 2 1309 if ne rev_tag cr s e h 0x30 0 1310 ret X5EMAL 1311 end 1312 put o 28 s 1313 put o 29 sub get h 2 s 1314 s = rev_times cr get h 2 e o 1315 if eq s 0 1316 ret X5EMAL 1317 end 1318 put o 11 0 1319 put o 12 0 1320 put o 13 0 1321 put o 14 0 1322 if lt s e 1323 if ne der_hdr cr s e h 0 1324 ret X5EMAL 1325 end 1326 if eq get h 0 0x30 1327 if eq get h 1 get h 2 1328 ret X5EMAL 1329 end 1330 put o 11 get h 1 1331 put o 12 get h 2 1332 s = get h 2 1333 end 1334 end 1335 if lt s e 1336 if ne rev_tag cr s e h 0xa0 0 1337 ret X5EMAL 1338 end 1339 if or ne get h 2 e eq vr 0 1340 ret X5EMAL 1341 end 1342 put o 13 get h 1 1343 put o 14 e 1344 s = e 1345 end 1346 if ne s e 1347 ret X5EMAL 1348 end 1349 ret 0 1350 end 1351 1352 note rev_idp: issuingDistributionPoint value (x[6] .. x[7] of cr; RFC 5280 5.2.5). A distributionPoint 1353 note must be a fullName [0] (its GeneralNames content span into o[30] o[31]); onlyContainsUserCerts 1354 note TRUE is accepted (the leaf is an end entity, chain_leaf); nameRelativeToCRLIssuer, 1355 note onlyContainsCACerts, onlySomeReasons, indirectCRL and onlyContainsAttributeCerts are RVESCOPE. 1356 fn rev_idp cr view uchar * x view ulong 16 o edit ulong 32 to ulong 1357 h = new ulong 3 0 1358 a = get x 6 1359 b = get x 7 1360 if ne rev_tag cr a b h 0x30 0 1361 ret X5EMAL 1362 end 1363 if ne get h 2 b 1364 ret X5EMAL 1365 end 1366 s = get h 1 1367 while lt s b bound 8 1368 if ne der_hdr cr s b h 0 1369 ret X5EMAL 1370 end 1371 g = get h 0 1372 t = get h 2 1373 if eq g 0xa0 1374 if ne der_hdr cr get h 1 t h 0 1375 ret X5EMAL 1376 end 1377 if or ne get h 0 0xa0 ne get h 2 t 1378 ret RVESCOPE 1379 end 1380 if eq get h 1 t 1381 ret X5EMAL 1382 end 1383 put o 30 get h 1 1384 put o 31 t 1385 else 1386 if ne g 0x81 1387 if and ge g 0x82 le g 0x85 1388 ret RVESCOPE 1389 end 1390 ret X5EMAL 1391 end 1392 g = get h 1 1393 if ne sub t g 1 1394 ret X5EMAL 1395 end 1396 if ne get cr g 255 1397 ret X5EMAL 1398 end 1399 end 1400 s = t 1401 end 1402 ret 0 1403 end 1404 1405 note rev_crlx: crlExtensions o[13] .. o[14]: only issuingDistributionPoint may be critical 1406 note (deltaCRLIndicator RVESCOPE, others X5ECRIT, rev_exts); an IDP is checked by rev_idp 1407 fn rev_crlx cr view uchar * o edit ulong 32 to ulong 1408 x = new ulong 16 0 1409 put o 30 0 1410 put o 31 0 1411 if eq get o 14 0 1412 ret 0 1413 end 1414 put x 12 3 1415 put x 13 3 1416 v = rev_exts cr get o 13 get o 14 x 1417 if ne v 0 1418 ret v 1419 end 1420 if eq get x 4 0 1421 ret 0 1422 end 1423 ret rev_idp cr x o 1424 end 1425 1426 note rev_crlr: the CRL cr: framing, the issuer's signature (ib, record w[32 .. 64)), the issuer's 1427 note keyUsage includes cRLSign when present (X5EKU), the tbsCertList, issuer Name equal to the 1428 note issuer's subject DER (RVESCOPE), crlExtensions 1429 fn rev_crlr cr view uchar * ib view uchar 16896 o edit ulong 32 w edit ulong 128 to ulong 1430 v = rev_cl1 cr o 1431 if eq v 0 1432 v = rev_sig cr part ib 0 get w 65 w o 1433 end 1434 if ne v 0 1435 ret v 1436 end 1437 if eq get w add X5RSZ X5RKU 1 1438 if eq and get w add X5RSZ X5RKUB 2 0 1439 ret X5EKU 1440 end 1441 end 1442 v = rev_tbsl cr o 1443 if ne v 0 1444 ret v 1445 end 1446 a = get w add X5RSZ X5RSBO 1447 n = get w add X5RSZ X5RSBL 1448 if not der_same part cr get o 28 get o 29 part ib a n 1449 ret RVESCOPE 1450 end 1451 ret rev_crlx cr o 1452 end 1453 1454 note rev_gnin: the GeneralName TLV lf[g[0] .. g[1]) equals one of the GeneralName TLVs in cr[g[2] .. g[3]) 1455 fn rev_gnin cr view uchar * lf view uchar * g view ulong 8 to bool 1456 h = new ulong 3 0 1457 s = get g 2 1458 b = get g 3 1459 while lt s b bound 1000 1460 if ne der_hdr cr s b h 0 1461 ret false 1462 end 1463 e = sub get h 2 s 1464 a = get g 0 1465 if der_same part cr s e part lf a sub get g 1 a 1466 ret true 1467 end 1468 s = get h 2 1469 end 1470 ret false 1471 end 1472 1473 note rev_dpone: DistributionPoint content lf[g[4] .. g[5]): its distributionPoint fullName holds a 1474 note GeneralName that rev_gnin finds in the IDP fullName 1475 fn rev_dpone lf view uchar * cr view uchar * g edit ulong 8 to bool 1476 h = new ulong 3 0 1477 if ne rev_tag lf get g 4 get g 5 h 0xa0 0 1478 ret false 1479 end 1480 if ne rev_tag lf get h 1 get h 2 h 0xa0 0 1481 ret false 1482 end 1483 s = get h 1 1484 e = get h 2 1485 while lt s e bound 1000 1486 if ne der_hdr lf s e h 0 1487 ret false 1488 end 1489 put g 0 s 1490 put g 1 get h 2 1491 if rev_gnin cr lf g 1492 ret true 1493 end 1494 s = get h 2 1495 end 1496 ret false 1497 end 1498 1499 note rev_dpmatch: the leaf (lb, length w[64]) has a cRLDistributionPoints fullName name equal to one 1500 note of the IDP fullName names cr[o[30] .. o[31]) (RFC 5280 6.3.3 b.2.i); 0 yes, RVESCOPE otherwise 1501 note (also when the leaf has no cRLDistributionPoints) 1502 fn rev_dpmatch cr view uchar * lb view uchar 16896 w edit ulong 128 o view ulong 32 to ulong 1503 x = new ulong 16 0 1504 g = new ulong 8 0 1505 h = new ulong 3 0 1506 l = get w 64 1507 if ne x509_parse part lb 0 l part w 0 X5RSZ 0 1508 ret X5EMAL 1509 end 1510 put x 12 2 1511 if ne rev_certext part lb 0 l part w 0 X5RSZ x 0 1512 ret RVESCOPE 1513 end 1514 put g 2 get o 30 1515 put g 3 get o 31 1516 b = get x 7 1517 if ne rev_tag part lb 0 l get x 6 b h 0x30 0 1518 ret RVESCOPE 1519 end 1520 s = get h 1 1521 while lt s b bound 1000 1522 if ne rev_tag part lb 0 l s b h 0x30 0 1523 ret RVESCOPE 1524 end 1525 put g 4 get h 1 1526 put g 5 get h 2 1527 s = get h 2 1528 if rev_dpone part lb 0 l cr g 1529 ret 0 1530 end 1531 end 1532 ret RVESCOPE 1533 end 1534 1535 note rev_listed: revokedCertificates o[11] .. o[12]: every entry {userCertificate, revocationDate, 1536 note crlEntryExtensions} is framed and its extensions checked (certificateIssuer RVESCOPE: indirect 1537 note CRLs are not supported; unknown critical X5ECRIT). RVHIT when an entry has the leaf serial (ix), 1538 note 0 when none has, else a code. 1539 fn rev_listed cr view uchar * o view ulong 32 ix view uchar 256 to ulong 1540 h = new ulong 3 0 1541 x = new ulong 16 0 1542 t = new ulong 32 0 1543 put x 12 RVNONE 1544 put x 13 RVNONE 1545 s = get o 11 1546 e = get o 12 1547 n = get o 22 1548 hit = ulong 0 1549 while lt s e bound 999999 1550 if ne rev_tag cr s e h 0x30 0 1551 ret X5EMAL 1552 end 1553 u = get h 2 1554 if ne rev_tag cr get h 1 u h 2 0 1555 ret X5EMAL 1556 end 1557 if rev_sereq cr get h 1 get h 2 ix n 1558 hit = RVHIT 1559 end 1560 q = rev_times cr get h 2 u t 1561 if eq q 0 1562 ret X5EMAL 1563 end 1564 if ne get t 18 X5BIG 1565 ret X5EMAL 1566 end 1567 if lt q u 1568 v = rev_exts cr q u x 1569 if ne v 0 1570 ret v 1571 end 1572 end 1573 s = u 1574 end 1575 ret hit 1576 end 1577 1578 note rev_crl: the CRL b[p[7] .. +p[8]) for the leaf p[1 .. 2] issued by p[3 .. 4] at unix time p[0]. 1579 note Order: signature and keyUsage, tbsCertList, scope (issuer name, crlExtensions, IDP against the 1580 note leaf's cRLDistributionPoints), the entries (RVEREV when listed), then freshness (rev_fresh). 1581 fn rev_crl b view uchar * p view ulong 16 to ulong 1582 o = new ulong 32 0 1583 w = new ulong 128 0 1584 ix = new uchar 256 0 1585 lb = new uchar 16896 0 1586 ib = new uchar 16896 0 1587 v = rev_setup b p lb ib w 1588 if ne v 0 1589 ret v 1590 end 1591 put o 0 get w 66 1592 v = rev_serial lb w ix o 1593 if ne v 0 1594 ret v 1595 end 1596 if or eq get p 8 0 not rev_span b p 7 1597 ret X5EMAL 1598 end 1599 v = rev_crlr part b get p 7 get p 8 ib o w 1600 if ne v 0 1601 ret v 1602 end 1603 if ne get o 31 0 1604 v = rev_dpmatch part b get p 7 get p 8 lb w o 1605 if ne v 0 1606 ret v 1607 end 1608 end 1609 v = rev_listed part b get p 7 get p 8 o ix 1610 if eq v RVHIT 1611 ret RVEREV 1612 end 1613 if ne v 0 1614 ret v 1615 end 1616 ret rev_fresh o 1617 end 1618 1619 note ---------------------------------------------------------------- issuer lookup and policy 1620 1621 note rev_isstry: is c (the exact DER of a candidate) the issuer of the leaf lb (length w[64], record 1622 note w[0 .. 32))? chain_link: its subject is the leaf's issuer and the leaf signature verifies with its 1623 note key. Copies c into kb and returns its length when it is, else 0. 1624 fn rev_isstry lb view uchar 16896 c view uchar * w edit ulong 128 kb edit uchar * to ulong 1625 if gt len c len kb 1626 ret 0 1627 end 1628 if ne x509_parse c part w X5RSZ X5RSZ 0 1629 ret 0 1630 end 1631 if ne chain_link part lb 0 get w 64 c w 0 1632 ret 0 1633 end 1634 for i ulong len c 1635 put kb i get c i 1636 end 1637 ret len c 1638 end 1639 1640 note rev_isstore: rev_isstry over the entries of the store st (uint24 length, DER: x509_store_load) 1641 fn rev_isstore lb view uchar 16896 st view uchar * w edit ulong 128 kb edit uchar * to ulong 1642 p = ulong 0 1643 while lt add p 3 len st bound 100000 1644 k = der_u24 st p 1645 p = add p 3 1646 if or eq k 0 gt k sub len st p 1647 ret 0 1648 end 1649 m = rev_isstry lb part st p k w kb 1650 if ne m 0 1651 ret m 1652 end 1653 p = add p k 1654 end 1655 ret 0 1656 end 1657 1658 note rev_prs: x509_parse of d[0 .. l) into the record w[j*32 .. j*32+32) 1659 fn rev_prs d view uchar 16896 l ulong w edit ulong 128 j ulong to ulong 1660 a = mul j X5RSZ 1661 ret x509_parse part d 0 l part w a X5RSZ 1662 end 1663 1664 note rev_isslist: rev_isstry over the presented certificates after the leaf; the chain_index pairs are 1665 note in w[96 .. 128), the entry count in w[67] 1666 fn rev_isslist lb view uchar 16896 cl view uchar * w edit ulong 128 kb edit uchar * to ulong 1667 n = get w 67 1668 for j ulong n 1669 if eq j 0 1670 continue 1671 end 1672 a = add 96 mul j 2 1673 s = get w a 1674 l = get w add a 1 1675 m = rev_isstry lb part cl s l w kb 1676 if ne m 0 1677 ret m 1678 end 1679 end 1680 ret 0 1681 end 1682 1683 note rev_issuer: the issuer of the leaf of the TLS certificate_list cl (chain_index framing), looked 1684 note for among the presented certificates and then the store st, copied into kb; its length, 0 when 1685 note none. Run after x509_chain_verify accepted cl: any certificate whose subject is the leaf's issuer 1686 note and whose key verifies the leaf signature holds the issuing key, which is all OCSP CertID, OCSP 1687 note signer authorization and CRL signature checks need. 1688 fn rev_issuer cl view uchar * st view uchar * kb edit uchar * to ulong 1689 lb = new uchar 16896 0 1690 w = new ulong 128 0 1691 n = chain_index cl part w 96 32 1692 if eq n 0 1693 ret 0 1694 end 1695 put w 67 n 1696 l = get w 97 1697 if gt l RVKBUF 1698 ret 0 1699 end 1700 rev_cp lb cl get w 96 l 1701 put w 64 l 1702 if ne rev_prs lb l w 0 0 1703 ret 0 1704 end 1705 n = rev_isslist lb cl w kb 1706 if ne n 0 1707 ret n 1708 end 1709 ret rev_isstore lb st w kb 1710 end 1711 1712 note rev_check: revocation policy for b and p (see the head of this file). A staple must verify and 1713 note be good (rev_ocsp); a must-staple leaf without one is RVENOST; a given CRL must verify, cover the 1714 note leaf and not list it (rev_crl). 0 otherwise, including when nothing was supplied. 1715 fn rev_check b view uchar * p view ulong 16 to ulong 1716 if not rev_span b p 1 1717 ret X5EMAL 1718 end 1719 m = rev_mustst part b get p 1 get p 2 1720 if and ne m 0 ne m RVHIT 1721 ret m 1722 end 1723 if gt get p 6 0 1724 v = rev_ocsp b p 1725 if ne v 0 1726 ret v 1727 end 1728 else 1729 if eq m RVHIT 1730 ret RVENOST 1731 end 1732 end 1733 if gt get p 8 0 1734 ret rev_crl b p 1735 end 1736 ret 0 1737 end 1738 1739 note rev_errname: name of code into o (REV_ERR_* for 32 .. 38, else x509_errname); its length 1740 fn rev_errname code ulong o edit uchar * to ulong 1741 if or lt code RVEREV gt code RVESCOPE 1742 ret x509_errname code o 1743 end 1744 k = sub code RVEREV 1745 s = ulong 0 1746 n = len RVNAMES 1747 while lt s n bound 100 1748 j = s 1749 while lt j n bound 100 1750 if eq get RVNAMES j 32 1751 break 1752 end 1753 j = add j 1 1754 end 1755 if eq k 0 1756 m = sub j s 1757 for i ulong m 1758 if lt i len o 1759 put o i get RVNAMES add s i 1760 end 1761 end 1762 ret m 1763 end 1764 k = sub k 1 1765 s = add j 1 1766 end 1767 ret 0 1768 end