0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 /*. * Copyright
0010: 28 43 29 20 31 39 39 37 2d 32 30 30 30 20 53 65 (C) 1997-2000 Se
0020: 6e 73 75 73 20 43 6f 6e 73 75 6c 74 69 6e 67 20 nsus Consulting
0030: 4c 74 64 2e 0a 20 2a 20 4d 61 74 74 20 4e 65 77 Ltd.. * Matt New
0040: 6d 61 6e 20 3c 6d 61 74 74 40 73 65 6e 73 75 73 man <matt@sensus
0050: 2e 6f 72 67 3e 0a 20 2a 20 43 6f 70 79 72 69 67 .org>. * Copyrig
0060: 68 74 20 28 43 29 20 32 30 32 33 20 42 72 69 61 ht (C) 2023 Bria
0070: 6e 20 4f 27 48 61 67 61 6e 0a 20 2a 2f 0a 23 69 n O'Hagan. */.#i
0080: 6e 63 6c 75 64 65 20 3c 74 63 6c 2e 68 3e 0a 23 nclude <tcl.h>.#
0090: 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 include <stdio.h
00a0: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e >.#include <open
00b0: 73 73 6c 2f 62 69 6f 2e 68 3e 0a 23 69 6e 63 6c ssl/bio.h>.#incl
00c0: 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 73 68 61 ude <openssl/sha
00d0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 .h>.#include <op
00e0: 65 6e 73 73 6c 2f 78 35 30 39 2e 68 3e 0a 23 69 enssl/x509.h>.#i
00f0: 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f nclude <openssl/
0100: 78 35 30 39 76 33 2e 68 3e 0a 23 69 6e 63 6c 75 x509v3.h>.#inclu
0110: 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 78 35 30 39 de <openssl/x509
0120: 5f 76 66 79 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 _vfy.h>.#include
0130: 20 3c 6f 70 65 6e 73 73 6c 2f 61 73 6e 31 2e 68 <openssl/asn1.h
0140: 3e 0a 23 69 6e 63 6c 75 64 65 20 22 74 6c 73 49 >.#include "tlsI
0150: 6e 74 2e 68 22 0a 0a 2f 2a 20 44 65 66 69 6e 65 nt.h"../* Define
0160: 20 6d 61 78 69 6d 75 6d 20 63 65 72 74 69 66 69 maximum certifi
0170: 63 61 74 65 20 73 69 7a 65 2e 20 4d 61 78 20 50 cate size. Max P
0180: 45 4d 20 73 69 7a 65 20 31 30 30 6b 42 20 61 6e EM size 100kB an
0190: 64 20 44 45 52 20 73 69 7a 65 20 69 73 20 32 34 d DER size is 24
01a0: 6b 42 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 kB. */.#define C
01b0: 45 52 54 5f 53 54 52 5f 53 49 5a 45 20 33 32 37 ERT_STR_SIZE 327
01c0: 36 38 0a 0a 0c 0a 2f 2a 0a 20 2a 20 42 69 6e 61 68..../*. * Bina
01d0: 72 79 20 73 74 72 69 6e 67 20 74 6f 20 68 65 78 ry string to hex
01e0: 20 73 74 72 69 6e 67 0a 20 2a 2f 0a 69 6e 74 20 string. */.int
01f0: 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 75 6e String_to_Hex(un
0200: 73 69 67 6e 65 64 20 63 68 61 72 2a 20 69 6e 70 signed char* inp
0210: 75 74 2c 20 69 6e 74 20 69 6c 65 6e 2c 20 75 6e ut, int ilen, un
0220: 73 69 67 6e 65 64 20 63 68 61 72 20 2a 6f 75 74 signed char *out
0230: 70 75 74 2c 20 69 6e 74 20 6f 6c 65 6e 29 20 7b put, int olen) {
0240: 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d . int count =
0250: 20 30 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 0;. unsigned
0260: 20 63 68 61 72 20 2a 69 70 74 72 20 3d 20 69 6e char *iptr = in
0270: 70 75 74 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 put;. unsigne
0280: 64 20 63 68 61 72 20 2a 6f 70 74 72 20 3d 20 26 d char *optr = &
0290: 6f 75 74 70 75 74 5b 30 5d 3b 0a 20 20 20 20 63 output[0];. c
02a0: 6f 6e 73 74 20 63 68 61 72 20 2a 68 65 78 20 3d onst char *hex =
02b0: 20 22 30 31 32 33 34 35 36 37 38 39 61 62 63 64 "0123456789abcd
02c0: 65 66 22 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69 ef";.. for (i
02d0: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 69 6c nt i = 0; i < il
02e0: 65 6e 20 26 26 20 63 6f 75 6e 74 20 3c 20 6f 6c en && count < ol
02f0: 65 6e 20 2d 20 31 3b 20 69 2b 2b 2c 20 63 6f 75 en - 1; i++, cou
0300: 6e 74 20 2b 3d 20 32 29 20 7b 0a 20 20 20 20 20 nt += 2) {.
0310: 20 20 20 2a 6f 70 74 72 2b 2b 20 3d 20 68 65 78 *optr++ = hex
0320: 5b 28 2a 69 70 74 72 3e 3e 34 29 26 30 78 46 5d [(*iptr>>4)&0xF]
0330: 3b 0a 20 20 20 20 20 20 20 20 2a 6f 70 74 72 2b ;. *optr+
0340: 2b 20 3d 20 68 65 78 5b 28 2a 69 70 74 72 2b 2b + = hex[(*iptr++
0350: 29 26 30 78 46 5d 3b 0a 20 20 20 20 7d 0a 20 20 )&0xF];. }.
0360: 20 20 2a 6f 70 74 72 20 3d 20 30 3b 0a 20 20 20 *optr = 0;.
0370: 20 72 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 7d return count;.}
0380: 0a 0a 2f 2a 0a 20 2a 20 42 49 4f 20 74 6f 20 42 ../*. * BIO to B
0390: 75 66 66 65 72 0a 20 2a 2f 0a 69 6e 74 20 42 49 uffer. */.int BI
03a0: 4f 5f 74 6f 5f 42 75 66 66 65 72 28 69 6e 74 20 O_to_Buffer(int
03b0: 72 65 73 75 6c 74 2c 20 42 49 4f 20 2a 62 69 6f result, BIO *bio
03c0: 2c 20 76 6f 69 64 20 2a 62 75 66 66 65 72 2c 20 , void *buffer,
03d0: 69 6e 74 20 73 69 7a 65 29 20 7b 0a 20 20 20 20 int size) {.
03e0: 69 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20 int len = 0;.
03f0: 20 69 6e 74 20 70 65 6e 64 69 6e 67 20 3d 20 42 int pending = B
0400: 49 4f 5f 70 65 6e 64 69 6e 67 28 62 69 6f 29 3b IO_pending(bio);
0410: 0a 0a 20 20 20 20 69 66 20 28 72 65 73 75 6c 74 .. if (result
0420: 29 20 7b 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 72 ) {..len = BIO_r
0430: 65 61 64 28 62 69 6f 2c 20 62 75 66 66 65 72 2c ead(bio, buffer,
0440: 20 28 70 65 6e 64 69 6e 67 20 3c 20 73 69 7a 65 (pending < size
0450: 29 20 3f 20 70 65 6e 64 69 6e 67 20 3a 20 73 69 ) ? pending : si
0460: 7a 65 29 3b 0a 09 28 76 6f 69 64 29 42 49 4f 5f ze);..(void)BIO_
0470: 66 6c 75 73 68 28 62 69 6f 29 3b 0a 09 69 66 20 flush(bio);..if
0480: 28 6c 65 6e 20 3c 20 30 29 20 7b 0a 09 20 20 20 (len < 0) {..
0490: 20 6c 65 6e 20 3d 20 30 3b 0a 09 7d 0a 20 20 20 len = 0;..}.
04a0: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 65 }. return le
04b0: 6e 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 47 65 74 n;.}.../*. * Get
04c0: 20 58 35 30 39 20 43 65 72 74 69 66 69 63 61 74 X509 Certificat
04d0: 65 20 45 78 74 65 6e 73 69 6f 6e 73 0a 20 2a 2f e Extensions. */
04e0: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 .Tcl_Obj *Tls_x5
04f0: 30 39 45 78 74 65 6e 73 69 6f 6e 73 28 54 63 6c 09Extensions(Tcl
0500: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c _Interp *interp,
0510: 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 X509 *cert) {.
0520: 20 20 20 63 6f 6e 73 74 20 53 54 41 43 4b 5f 4f const STACK_O
0530: 46 28 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e F(X509_EXTENSION
0540: 29 20 2a 65 78 74 73 3b 0a 20 20 20 20 54 63 6c ) *exts;. Tcl
0550: 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 _Obj *listPtr =
0560: 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 Tcl_NewListObj(0
0570: 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 , NULL);.. if
0580: 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c (listPtr == NUL
0590: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c L) {..return NUL
05a0: 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 L;. }.. if
05b0: 20 28 65 78 74 73 20 3d 20 58 35 30 39 5f 67 65 (exts = X509_ge
05c0: 74 30 5f 65 78 74 65 6e 73 69 6f 6e 73 28 63 65 t0_extensions(ce
05d0: 72 74 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 rt)) {..for (int
05e0: 20 69 3d 30 3b 20 69 20 3c 20 58 35 30 39 5f 67 i=0; i < X509_g
05f0: 65 74 5f 65 78 74 5f 63 6f 75 6e 74 28 63 65 72 et_ext_count(cer
0600: 74 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20 t); i++) {..
0610: 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 20 2a X509_EXTENSION *
0620: 65 78 20 3d 20 73 6b 5f 58 35 30 39 5f 45 58 54 ex = sk_X509_EXT
0630: 45 4e 53 49 4f 4e 5f 76 61 6c 75 65 28 65 78 74 ENSION_value(ext
0640: 73 2c 20 69 29 3b 0a 09 20 20 20 20 41 53 4e 31 s, i);.. ASN1
0650: 5f 4f 42 4a 45 43 54 20 2a 6f 62 6a 20 3d 20 58 _OBJECT *obj = X
0660: 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67 65 509_EXTENSION_ge
0670: 74 5f 6f 62 6a 65 63 74 28 65 78 29 3b 0a 09 20 t_object(ex);..
0680: 20 20 20 2f 2a 20 41 53 4e 31 5f 4f 43 54 45 54 /* ASN1_OCTET
0690: 5f 53 54 52 49 4e 47 20 2a 64 61 74 61 20 3d 20 _STRING *data =
06a0: 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67 X509_EXTENSION_g
06b0: 65 74 5f 64 61 74 61 28 65 78 29 3b 20 2a 2f 0a et_data(ex); */.
06c0: 09 20 20 20 20 69 6e 74 20 63 72 69 74 69 63 61 . int critica
06d0: 6c 20 3d 20 58 35 30 39 5f 45 58 54 45 4e 53 49 l = X509_EXTENSI
06e0: 4f 4e 5f 67 65 74 5f 63 72 69 74 69 63 61 6c 28 ON_get_critical(
06f0: 65 78 29 3b 0a 09 20 20 20 20 4c 41 50 50 45 4e ex);.. LAPPEN
0700: 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 6c D_BOOL(interp, l
0710: 69 73 74 50 74 72 2c 20 4f 42 4a 5f 6e 69 64 32 istPtr, OBJ_nid2
0720: 6c 6e 28 4f 42 4a 5f 6f 62 6a 32 6e 69 64 28 6f ln(OBJ_obj2nid(o
0730: 62 6a 29 29 2c 20 63 72 69 74 69 63 61 6c 29 3b bj)), critical);
0740: 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 ..}. }. re
0750: 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a turn listPtr;.}.
0760: 0a 2f 2a 0a 20 2a 20 47 65 74 20 41 75 74 68 6f ./*. * Get Autho
0770: 72 69 74 79 20 61 6e 64 20 53 75 62 6a 65 63 74 rity and Subject
0780: 20 4b 65 79 20 49 64 65 6e 74 69 66 69 65 72 73 Key Identifiers
0790: 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c . */.Tcl_Obj *Tl
07a0: 73 5f 78 35 30 39 49 64 65 6e 74 69 66 69 65 72 s_x509Identifier
07b0: 28 41 53 4e 31 5f 4f 43 54 45 54 5f 53 54 52 49 (ASN1_OCTET_STRI
07c0: 4e 47 20 2a 61 73 74 72 69 6e 67 29 20 7b 0a 20 NG *astring) {.
07d0: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 72 65 73 75 Tcl_Obj *resu
07e0: 6c 74 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 ltPtr = NULL;.
07f0: 20 20 69 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20 int len = 0;.
0800: 20 20 20 63 68 61 72 20 62 75 66 66 65 72 5b 31 char buffer[1
0810: 30 32 34 5d 3b 0a 0a 20 20 20 20 69 66 20 28 61 024];.. if (a
0820: 73 74 72 69 6e 67 20 21 3d 20 4e 55 4c 4c 29 20 string != NULL)
0830: 7b 0a 09 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f {..len = String_
0840: 74 6f 5f 48 65 78 28 28 63 68 61 72 20 2a 29 41 to_Hex((char *)A
0850: 53 4e 31 5f 53 54 52 49 4e 47 5f 67 65 74 30 5f SN1_STRING_get0_
0860: 64 61 74 61 28 61 73 74 72 69 6e 67 29 2c 0a 09 data(astring),..
0870: 20 20 20 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f ASN1_STRING_
0880: 6c 65 6e 67 74 68 28 61 73 74 72 69 6e 67 29 2c length(astring),
0890: 20 62 75 66 66 65 72 2c 20 31 30 32 34 29 3b 0a buffer, 1024);.
08a0: 20 20 20 20 7d 0a 20 20 20 20 72 65 73 75 6c 74 }. result
08b0: 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 Ptr = Tcl_NewStr
08c0: 69 6e 67 4f 62 6a 28 62 75 66 66 65 72 2c 20 28 ingObj(buffer, (
08d0: 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a Tcl_Size) len);.
08e0: 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c return resul
08f0: 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 tPtr;.}../*. * G
0900: 65 74 20 4b 65 79 20 55 73 61 67 65 0a 20 2a 2f et Key Usage. */
0910: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 .Tcl_Obj *Tls_x5
0920: 30 39 4b 65 79 55 73 61 67 65 28 54 63 6c 5f 49 09KeyUsage(Tcl_I
0930: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 nterp *interp, X
0940: 35 30 39 20 2a 63 65 72 74 2c 20 75 69 6e 74 33 509 *cert, uint3
0950: 32 5f 74 20 78 66 6c 61 67 73 29 20 7b 0a 20 20 2_t xflags) {.
0960: 20 20 75 69 6e 74 33 32 5f 74 20 75 73 61 67 65 uint32_t usage
0970: 20 3d 20 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f = X509_get_key_
0980: 75 73 61 67 65 28 63 65 72 74 29 3b 0a 20 20 20 usage(cert);.
0990: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 Tcl_Obj *listPt
09a0: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f r = Tcl_NewListO
09b0: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 bj(0, NULL);..
09c0: 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d if (listPtr ==
09d0: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e NULL) {..return
09e0: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 NULL;. }..
09f0: 20 20 69 66 20 28 28 78 66 6c 61 67 73 20 26 20 if ((xflags &
0a00: 45 58 46 4c 41 47 5f 4b 55 53 41 47 45 29 20 26 EXFLAG_KUSAGE) &
0a10: 26 20 75 73 61 67 65 20 3c 20 55 49 4e 54 33 32 & usage < UINT32
0a20: 5f 4d 41 58 29 20 7b 0a 09 69 66 20 28 75 73 61 _MAX) {..if (usa
0a30: 67 65 20 26 20 4b 55 5f 44 49 47 49 54 41 4c 5f ge & KU_DIGITAL_
0a40: 53 49 47 4e 41 54 55 52 45 29 20 7b 0a 09 20 20 SIGNATURE) {..
0a50: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
0a60: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
0a70: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f p, listPtr, Tcl_
0a80: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 69 NewStringObj("Di
0a90: 67 69 74 61 6c 20 53 69 67 6e 61 74 75 72 65 22 gital Signature"
0aa0: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 , -1));..}..if (
0ab0: 75 73 61 67 65 20 26 20 4b 55 5f 4e 4f 4e 5f 52 usage & KU_NON_R
0ac0: 45 50 55 44 49 41 54 49 4f 4e 29 20 7b 0a 09 20 EPUDIATION) {..
0ad0: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 Tcl_ListObjAp
0ae0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
0af0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c rp, listPtr, Tcl
0b00: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4e _NewStringObj("N
0b10: 6f 6e 2d 52 65 70 75 64 69 61 74 69 6f 6e 22 2c on-Repudiation",
0b20: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 -1));..}..if (u
0b30: 73 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 45 4e sage & KU_KEY_EN
0b40: 43 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a 09 20 CIPHERMENT) {..
0b50: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 Tcl_ListObjAp
0b60: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
0b70: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c rp, listPtr, Tcl
0b80: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b _NewStringObj("K
0b90: 65 79 20 45 6e 63 69 70 68 65 72 6d 65 6e 74 22 ey Encipherment"
0ba0: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 , -1));..}..if (
0bb0: 75 73 61 67 65 20 26 20 4b 55 5f 44 41 54 41 5f usage & KU_DATA_
0bc0: 45 4e 43 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a ENCIPHERMENT) {.
0bd0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
0be0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
0bf0: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 terp, listPtr, T
0c00: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
0c10: 22 44 61 74 61 20 45 6e 63 69 70 68 65 72 6d 65 "Data Encipherme
0c20: 6e 74 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 nt", -1));..}..i
0c30: 66 20 28 75 73 61 67 65 20 26 20 4b 55 5f 4b 45 f (usage & KU_KE
0c40: 59 5f 41 47 52 45 45 4d 45 4e 54 29 20 7b 0a 09 Y_AGREEMENT) {..
0c50: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
0c60: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
0c70: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 erp, listPtr, Tc
0c80: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
0c90: 4b 65 79 20 41 67 72 65 65 6d 65 6e 74 22 2c 20 Key Agreement",
0ca0: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 -1));..}..if (us
0cb0: 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 43 45 52 age & KU_KEY_CER
0cc0: 54 5f 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 T_SIGN) {.. T
0cd0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
0ce0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
0cf0: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
0d00: 53 74 72 69 6e 67 4f 62 6a 28 22 43 65 72 74 69 StringObj("Certi
0d10: 66 69 63 61 74 65 20 53 69 67 6e 69 6e 67 22 2c ficate Signing",
0d20: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 -1));..}..if (u
0d30: 73 61 67 65 20 26 20 4b 55 5f 43 52 4c 5f 53 49 sage & KU_CRL_SI
0d40: 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c GN) {.. Tcl_L
0d50: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d istObjAppendElem
0d60: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 ent(interp, list
0d70: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 Ptr, Tcl_NewStri
0d80: 6e 67 4f 62 6a 28 22 43 52 4c 20 53 69 67 6e 69 ngObj("CRL Signi
0d90: 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 ng", -1));..}..i
0da0: 66 20 28 75 73 61 67 65 20 26 20 4b 55 5f 45 4e f (usage & KU_EN
0db0: 43 49 50 48 45 52 5f 4f 4e 4c 59 29 20 7b 0a 09 CIPHER_ONLY) {..
0dc0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
0dd0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
0de0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 erp, listPtr, Tc
0df0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
0e00: 45 6e 63 69 70 68 65 72 20 4f 6e 6c 79 22 2c 20 Encipher Only",
0e10: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 -1));..}..if (us
0e20: 61 67 65 20 26 20 4b 55 5f 44 45 43 49 50 48 45 age & KU_DECIPHE
0e30: 52 5f 4f 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 R_ONLY) {.. T
0e40: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
0e50: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
0e60: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
0e70: 53 74 72 69 6e 67 4f 62 6a 28 22 44 65 63 69 70 StringObj("Decip
0e80: 68 65 72 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b her Only", -1));
0e90: 0a 09 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b ..}. } else {
0ea0: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 .. Tcl_ListOb
0eb0: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 jAppendElement(i
0ec0: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 nterp, listPtr,
0ed0: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a Tcl_NewStringObj
0ee0: 28 22 75 6e 72 65 73 74 72 69 63 74 65 64 22 2c ("unrestricted",
0ef0: 20 2d 31 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 -1));. }.
0f00: 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b return listPtr;
0f10: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 65 .}../*. * Get Ce
0f20: 72 74 69 66 69 63 61 74 65 20 50 75 72 70 6f 73 rtificate Purpos
0f30: 65 0a 20 2a 2f 0a 63 68 61 72 20 2a 54 6c 73 5f e. */.char *Tls_
0f40: 78 35 30 39 50 75 72 70 6f 73 65 28 58 35 30 39 x509Purpose(X509
0f50: 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 63 68 *cert) {. ch
0f60: 61 72 20 2a 70 75 72 70 6f 73 65 20 3d 20 4e 55 ar *purpose = NU
0f70: 4c 4c 3b 0a 0a 20 20 20 20 69 66 20 28 58 35 30 LL;.. if (X50
0f80: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 9_check_purpose(
0f90: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f cert, X509_PURPO
0fa0: 53 45 5f 53 53 4c 5f 43 4c 49 45 4e 54 2c 20 30 SE_SSL_CLIENT, 0
0fb0: 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 ) > 0) {..purpos
0fc0: 65 20 3d 20 22 53 53 4c 20 43 6c 69 65 6e 74 22 e = "SSL Client"
0fd0: 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 ;. } else if
0fe0: 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 (X509_check_purp
0ff0: 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 ose(cert, X509_P
1000: 55 52 50 4f 53 45 5f 53 53 4c 5f 53 45 52 56 45 URPOSE_SSL_SERVE
1010: 52 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 R, 0) > 0) {..pu
1020: 72 70 6f 73 65 20 3d 20 22 53 53 4c 20 53 65 72 rpose = "SSL Ser
1030: 76 65 72 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 ver";. } else
1040: 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f if (X509_check_
1050: 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 purpose(cert, X5
1060: 30 39 5f 50 55 52 50 4f 53 45 5f 4e 53 5f 53 53 09_PURPOSE_NS_SS
1070: 4c 5f 53 45 52 56 45 52 2c 20 30 29 20 3e 20 30 L_SERVER, 0) > 0
1080: 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 ) {..purpose = "
1090: 4d 53 53 20 53 53 4c 20 53 65 72 76 65 72 22 3b MSS SSL Server";
10a0: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 . } else if (
10b0: 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f X509_check_purpo
10c0: 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 se(cert, X509_PU
10d0: 52 50 4f 53 45 5f 53 4d 49 4d 45 5f 53 49 47 4e RPOSE_SMIME_SIGN
10e0: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 , 0) > 0) {..pur
10f0: 70 6f 73 65 20 3d 20 22 53 4d 49 4d 45 20 53 69 pose = "SMIME Si
1100: 67 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c gning";. } el
1110: 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 se if (X509_chec
1120: 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 k_purpose(cert,
1130: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 53 4d 49 X509_PURPOSE_SMI
1140: 4d 45 5f 45 4e 43 52 59 50 54 2c 20 30 29 20 3e ME_ENCRYPT, 0) >
1150: 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 0) {..purpose =
1160: 20 22 53 4d 49 4d 45 20 45 6e 63 72 79 70 74 69 "SMIME Encrypti
1170: 6f 6e 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 on";. } else
1180: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 if (X509_check_p
1190: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 urpose(cert, X50
11a0: 39 5f 50 55 52 50 4f 53 45 5f 43 52 4c 5f 53 49 9_PURPOSE_CRL_SI
11b0: 47 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 GN, 0) > 0) {..p
11c0: 75 72 70 6f 73 65 20 3d 20 22 43 52 4c 20 53 69 urpose = "CRL Si
11d0: 67 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c gning";. } el
11e0: 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 se if (X509_chec
11f0: 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 k_purpose(cert,
1200: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 41 4e 59 X509_PURPOSE_ANY
1210: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 , 0) > 0) {..pur
1220: 70 6f 73 65 20 3d 20 22 41 6e 79 22 3b 0a 20 20 pose = "Any";.
1230: 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 } else if (X50
1240: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 9_check_purpose(
1250: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f cert, X509_PURPO
1260: 53 45 5f 4f 43 53 50 5f 48 45 4c 50 45 52 2c 20 SE_OCSP_HELPER,
1270: 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 0) > 0) {..purpo
1280: 73 65 20 3d 20 22 4f 43 53 50 20 48 65 6c 70 65 se = "OCSP Helpe
1290: 72 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 r";. } else i
12a0: 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 f (X509_check_pu
12b0: 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 rpose(cert, X509
12c0: 5f 50 55 52 50 4f 53 45 5f 54 49 4d 45 53 54 41 _PURPOSE_TIMESTA
12d0: 4d 50 5f 53 49 47 4e 2c 20 30 29 20 3e 20 30 29 MP_SIGN, 0) > 0)
12e0: 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 54 {..purpose = "T
12f0: 69 6d 65 73 74 61 6d 70 20 53 69 67 6e 69 6e 67 imestamp Signing
1300: 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a ";. } else {.
1310: 09 70 75 72 70 6f 73 65 20 3d 20 22 22 3b 0a 20 .purpose = "";.
1320: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
1330: 70 75 72 70 6f 73 65 3b 0a 7d 0a 0a 2f 2a 0a 20 purpose;.}../*.
1340: 2a 20 46 6f 72 20 65 61 63 68 20 70 75 72 70 6f * For each purpo
1350: 73 65 2c 20 67 65 74 20 63 65 72 74 69 66 69 63 se, get certific
1360: 61 74 65 20 61 70 70 6c 69 63 61 62 69 6c 69 74 ate applicabilit
1370: 79 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 y. */.Tcl_Obj *T
1380: 6c 73 5f 78 35 30 39 50 75 72 70 6f 73 65 73 28 ls_x509Purposes(
1390: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
13a0: 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20 rp, X509 *cert)
13b0: 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c {. Tcl_Obj *l
13c0: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 istPtr = Tcl_New
13d0: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 ListObj(0, NULL)
13e0: 3b 0a 20 20 20 20 58 35 30 39 5f 50 55 52 50 4f ;. X509_PURPO
13f0: 53 45 20 2a 70 74 6d 70 3b 0a 0a 20 20 20 20 69 SE *ptmp;.. i
1400: 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 f (listPtr == NU
1410: 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 LL) {..return NU
1420: 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 66 LL;. }.. f
1430: 6f 72 20 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 or (int i = 0; i
1440: 20 3c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f < X509_PURPOSE_
1450: 67 65 74 5f 63 6f 75 6e 74 28 29 3b 20 69 2b 2b get_count(); i++
1460: 29 20 7b 0a 09 70 74 6d 70 20 3d 20 58 35 30 39 ) {..ptmp = X509
1470: 5f 50 55 52 50 4f 53 45 5f 67 65 74 30 28 69 29 _PURPOSE_get0(i)
1480: 3b 0a 09 54 63 6c 5f 4f 62 6a 20 2a 74 6d 70 50 ;..Tcl_Obj *tmpP
1490: 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 tr = Tcl_NewList
14a0: 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 Obj(0, NULL);...
14b0: 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20 for (int j = 0;
14c0: 6a 20 3c 20 32 3b 20 6a 2b 2b 29 20 7b 0a 09 20 j < 2; j++) {..
14d0: 20 20 20 69 6e 74 20 69 64 72 65 74 20 3d 20 58 int idret = X
14e0: 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 509_check_purpos
14f0: 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 e(cert, X509_PUR
1500: 50 4f 53 45 5f 67 65 74 5f 69 64 28 70 74 6d 70 POSE_get_id(ptmp
1510: 29 2c 20 6a 29 3b 0a 09 20 20 20 20 54 63 6c 5f ), j);.. Tcl_
1520: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
1530: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 74 6d 70 ment(interp, tmp
1540: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 Ptr, Tcl_NewStri
1550: 6e 67 4f 62 6a 28 6a 20 3f 20 22 43 41 22 20 3a ngObj(j ? "CA" :
1560: 20 22 6e 6f 6e 43 41 22 2c 20 2d 31 29 29 3b 0a "nonCA", -1));.
1570: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
1580: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
1590: 74 65 72 70 2c 20 74 6d 70 50 74 72 2c 20 54 63 terp, tmpPtr, Tc
15a0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 69 l_NewStringObj(i
15b0: 64 72 65 74 20 3d 3d 20 31 20 3f 20 22 59 65 73 dret == 1 ? "Yes
15c0: 22 20 3a 20 22 4e 6f 22 2c 20 2d 31 29 29 3b 0a " : "No", -1));.
15d0: 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 .}..LAPPEND_OBJ(
15e0: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
15f0: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 X509_PURPOSE_ge
1600: 74 30 5f 6e 61 6d 65 28 70 74 6d 70 29 2c 20 74 t0_name(ptmp), t
1610: 6d 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20 mpPtr);. }.
1620: 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 return listPtr
1630: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 53 ;.}../*. * Get S
1640: 75 62 6a 65 63 74 20 41 6c 74 65 72 6e 61 74 65 ubject Alternate
1650: 20 4e 61 6d 65 73 20 28 53 41 4e 29 20 61 6e 64 Names (SAN) and
1660: 20 49 73 73 75 65 72 20 41 6c 74 65 72 6e 61 74 Issuer Alternat
1670: 65 20 4e 61 6d 65 73 0a 20 2a 2f 0a 54 63 6c 5f e Names. */.Tcl_
1680: 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4e 61 6d Obj *Tls_x509Nam
1690: 65 73 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 es(Tcl_Interp *i
16a0: 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 nterp, X509 *cer
16b0: 74 2c 20 69 6e 74 20 6e 69 64 2c 20 42 49 4f 20 t, int nid, BIO
16c0: 2a 62 69 6f 29 20 7b 0a 20 20 20 20 53 54 41 43 *bio) {. STAC
16d0: 4b 5f 4f 46 28 47 45 4e 45 52 41 4c 5f 4e 41 4d K_OF(GENERAL_NAM
16e0: 45 29 20 2a 6e 61 6d 65 73 3b 0a 20 20 20 20 54 E) *names;. T
16f0: 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 cl_Obj *listPtr
1700: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a = Tcl_NewListObj
1710: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 69 (0, NULL);. i
1720: 6e 74 20 6c 65 6e 3b 0a 20 20 20 20 63 68 61 72 nt len;. char
1730: 20 62 75 66 66 65 72 5b 31 30 32 34 5d 3b 0a 0a buffer[1024];..
1740: 20 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 if (listPtr
1750: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 == NULL) {..retu
1760: 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a rn NULL;. }..
1770: 20 20 20 20 69 66 20 28 6e 61 6d 65 73 20 3d 20 if (names =
1780: 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 X509_get_ext_d2i
1790: 28 63 65 72 74 2c 20 6e 69 64 2c 20 4e 55 4c 4c (cert, nid, NULL
17a0: 2c 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 , NULL)) {..for
17b0: 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20 73 6b (int i=0; i < sk
17c0: 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e 75 _GENERAL_NAME_nu
17d0: 6d 28 6e 61 6d 65 73 29 3b 20 69 2b 2b 29 20 7b m(names); i++) {
17e0: 0a 09 20 20 20 20 63 6f 6e 73 74 20 47 45 4e 45 .. const GENE
17f0: 52 41 4c 5f 4e 41 4d 45 20 2a 6e 61 6d 65 20 3d RAL_NAME *name =
1800: 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 sk_GENERAL_NAME
1810: 5f 76 61 6c 75 65 28 6e 61 6d 65 73 2c 20 69 29 _value(names, i)
1820: 3b 0a 0a 09 20 20 20 20 6c 65 6e 20 3d 20 42 49 ;... len = BI
1830: 4f 5f 74 6f 5f 42 75 66 66 65 72 28 6e 61 6d 65 O_to_Buffer(name
1840: 20 26 26 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 && GENERAL_NAME
1850: 5f 70 72 69 6e 74 28 62 69 6f 2c 20 6e 61 6d 65 _print(bio, name
1860: 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 ), bio, buffer,
1870: 31 30 32 34 29 3b 0a 09 20 20 20 20 4c 41 50 50 1024);.. LAPP
1880: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 END_STR(interp,
1890: 6c 69 73 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 62 listPtr, NULL, b
18a0: 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 uffer, (Tcl_Size
18b0: 29 20 6c 65 6e 29 3b 0a 09 7d 0a 09 73 6b 5f 47 ) len);..}..sk_G
18c0: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 70 6f 70 5f ENERAL_NAME_pop_
18d0: 66 72 65 65 28 6e 61 6d 65 73 2c 20 47 45 4e 45 free(names, GENE
18e0: 52 41 4c 5f 4e 41 4d 45 5f 66 72 65 65 29 3b 0a RAL_NAME_free);.
18f0: 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e }. return
1900: 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a listPtr;.}../*.
1910: 20 2a 20 47 65 74 20 45 58 74 65 6e 64 65 64 20 * Get EXtended
1920: 4b 65 79 20 55 73 61 67 65 0a 20 2a 2f 0a 54 63 Key Usage. */.Tc
1930: 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 45 l_Obj *Tls_x509E
1940: 78 74 4b 65 79 55 73 61 67 65 28 54 63 6c 5f 49 xtKeyUsage(Tcl_I
1950: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 nterp *interp, X
1960: 35 30 39 20 2a 63 65 72 74 2c 20 75 69 6e 74 33 509 *cert, uint3
1970: 32 5f 74 20 78 66 6c 61 67 73 29 20 7b 0a 20 20 2_t xflags) {.
1980: 20 20 75 69 6e 74 33 32 5f 74 20 75 73 61 67 65 uint32_t usage
1990: 20 3d 20 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f = X509_get_key_
19a0: 75 73 61 67 65 28 63 65 72 74 29 3b 0a 20 20 20 usage(cert);.
19b0: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 Tcl_Obj *listPt
19c0: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f r = Tcl_NewListO
19d0: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 bj(0, NULL);..
19e0: 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d if (listPtr ==
19f0: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e NULL) {..return
1a00: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 NULL;. }..
1a10: 20 20 69 66 20 28 28 78 66 6c 61 67 73 20 26 20 if ((xflags &
1a20: 45 58 46 4c 41 47 5f 58 4b 55 53 41 47 45 29 20 EXFLAG_XKUSAGE)
1a30: 26 26 20 75 73 61 67 65 20 3c 20 55 49 4e 54 33 && usage < UINT3
1a40: 32 5f 4d 41 58 29 20 7b 0a 09 75 73 61 67 65 20 2_MAX) {..usage
1a50: 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 65 6e = X509_get_exten
1a60: 64 65 64 5f 6b 65 79 5f 75 73 61 67 65 28 63 65 ded_key_usage(ce
1a70: 72 74 29 3b 0a 0a 09 69 66 20 28 75 73 61 67 65 rt);...if (usage
1a80: 20 26 20 58 4b 55 5f 53 53 4c 5f 53 45 52 56 45 & XKU_SSL_SERVE
1a90: 52 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 R) {.. Tcl_Li
1aa0: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 stObjAppendEleme
1ab0: 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 nt(interp, listP
1ac0: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e tr, Tcl_NewStrin
1ad0: 67 4f 62 6a 28 22 54 4c 53 20 57 65 62 20 53 65 gObj("TLS Web Se
1ae0: 72 76 65 72 20 41 75 74 68 65 6e 74 69 63 61 74 rver Authenticat
1af0: 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 ion", -1));..}..
1b00: 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f if (usage & XKU_
1b10: 53 53 4c 5f 43 4c 49 45 4e 54 29 20 7b 0a 09 20 SSL_CLIENT) {..
1b20: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 Tcl_ListObjAp
1b30: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
1b40: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c rp, listPtr, Tcl
1b50: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 54 _NewStringObj("T
1b60: 4c 53 20 57 65 62 20 43 6c 69 65 6e 74 20 41 75 LS Web Client Au
1b70: 74 68 65 6e 74 69 63 61 74 69 6f 6e 22 2c 20 2d thentication", -
1b80: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 1));..}..if (usa
1b90: 67 65 20 26 20 58 4b 55 5f 53 4d 49 4d 45 29 20 ge & XKU_SMIME)
1ba0: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f {.. Tcl_ListO
1bb0: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 bjAppendElement(
1bc0: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
1bd0: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
1be0: 6a 28 22 45 2d 6d 61 69 6c 20 50 72 6f 74 65 63 j("E-mail Protec
1bf0: 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a tion", -1));..}.
1c00: 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 .if (usage & XKU
1c10: 5f 43 4f 44 45 5f 53 49 47 4e 29 20 7b 0a 09 20 _CODE_SIGN) {..
1c20: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 Tcl_ListObjAp
1c30: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
1c40: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c rp, listPtr, Tcl
1c50: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 43 _NewStringObj("C
1c60: 6f 64 65 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31 ode Signing", -1
1c70: 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 ));..}..if (usag
1c80: 65 20 26 20 58 4b 55 5f 53 47 43 29 20 7b 0a 09 e & XKU_SGC) {..
1c90: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
1ca0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
1cb0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 erp, listPtr, Tc
1cc0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
1cd0: 53 47 43 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 SGC", -1));..}..
1ce0: 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f if (usage & XKU_
1cf0: 4f 43 53 50 5f 53 49 47 4e 29 20 7b 0a 09 20 20 OCSP_SIGN) {..
1d00: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
1d10: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
1d20: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f p, listPtr, Tcl_
1d30: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4f 43 NewStringObj("OC
1d40: 53 50 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31 29 SP Signing", -1)
1d50: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 );..}..if (usage
1d60: 20 26 20 58 4b 55 5f 54 49 4d 45 53 54 41 4d 50 & XKU_TIMESTAMP
1d70: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 ) {.. Tcl_Lis
1d80: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e tObjAppendElemen
1d90: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 t(interp, listPt
1da0: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 r, Tcl_NewString
1db0: 4f 62 6a 28 22 54 69 6d 65 20 53 74 61 6d 70 69 Obj("Time Stampi
1dc0: 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 ng", -1));..}..i
1dd0: 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 44 f (usage & XKU_D
1de0: 56 43 53 20 29 20 7b 0a 09 20 20 20 20 54 63 6c VCS ) {.. Tcl
1df0: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
1e00: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 ement(interp, li
1e10: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 stPtr, Tcl_NewSt
1e20: 72 69 6e 67 4f 62 6a 28 22 44 56 43 53 22 2c 20 ringObj("DVCS",
1e30: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 -1));..}..if (us
1e40: 61 67 65 20 26 20 58 4b 55 5f 41 4e 59 45 4b 55 age & XKU_ANYEKU
1e50: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 ) {.. Tcl_Lis
1e60: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e tObjAppendElemen
1e70: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 t(interp, listPt
1e80: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 r, Tcl_NewString
1e90: 4f 62 6a 28 22 41 6e 79 20 45 78 74 65 6e 64 65 Obj("Any Extende
1ea0: 64 20 4b 65 79 20 55 73 61 67 65 22 2c 20 2d 31 d Key Usage", -1
1eb0: 29 29 3b 0a 09 7d 0a 20 20 20 20 7d 20 65 6c 73 ));..}. } els
1ec0: 65 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 e {.. Tcl_Lis
1ed0: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e tObjAppendElemen
1ee0: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 t(interp, listPt
1ef0: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 r, Tcl_NewString
1f00: 4f 62 6a 28 22 75 6e 72 65 73 74 72 69 63 74 65 Obj("unrestricte
1f10: 64 22 2c 20 2d 31 29 29 3b 0a 20 20 20 20 7d 0a d", -1));. }.
1f20: 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 return listP
1f30: 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 tr;.}../*. * Get
1f40: 20 43 52 4c 20 44 69 73 74 72 69 62 75 74 69 6f CRL Distributio
1f50: 6e 20 50 6f 69 6e 74 73 0a 20 2a 2f 0a 54 63 6c n Points. */.Tcl
1f60: 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 43 72 _Obj *Tls_x509Cr
1f70: 6c 44 70 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a lDp(Tcl_Interp *
1f80: 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 interp, X509 *ce
1f90: 72 74 29 20 7b 0a 20 20 20 20 53 54 41 43 4b 5f rt) {. STACK_
1fa0: 4f 46 28 44 49 53 54 5f 50 4f 49 4e 54 29 20 2a OF(DIST_POINT) *
1fb0: 63 72 6c 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a crl;. Tcl_Obj
1fc0: 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f *listPtr = Tcl_
1fd0: 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 NewListObj(0, NU
1fe0: 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 LL);.. if (li
1ff0: 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b stPtr == NULL) {
2000: 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 ..return NULL;.
2010: 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 63 72 }.. if (cr
2020: 6c 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 l = X509_get_ext
2030: 5f 64 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 63 _d2i(cert, NID_c
2040: 72 6c 5f 64 69 73 74 72 69 62 75 74 69 6f 6e 5f rl_distribution_
2050: 70 6f 69 6e 74 73 2c 20 4e 55 4c 4c 2c 20 4e 55 points, NULL, NU
2060: 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 LL)) {..for (int
2070: 20 69 3d 30 3b 20 69 20 3c 20 73 6b 5f 44 49 53 i=0; i < sk_DIS
2080: 54 5f 50 4f 49 4e 54 5f 6e 75 6d 28 63 72 6c 29 T_POINT_num(crl)
2090: 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20 44 49 ; i++) {.. DI
20a0: 53 54 5f 50 4f 49 4e 54 20 2a 64 70 20 3d 20 73 ST_POINT *dp = s
20b0: 6b 5f 44 49 53 54 5f 50 4f 49 4e 54 5f 76 61 6c k_DIST_POINT_val
20c0: 75 65 28 63 72 6c 2c 20 69 29 3b 0a 09 20 20 20 ue(crl, i);..
20d0: 20 44 49 53 54 5f 50 4f 49 4e 54 5f 4e 41 4d 45 DIST_POINT_NAME
20e0: 20 2a 64 69 73 74 70 6f 69 6e 74 20 3d 20 64 70 *distpoint = dp
20f0: 2d 3e 64 69 73 74 70 6f 69 6e 74 3b 0a 0a 09 20 ->distpoint;...
2100: 20 20 20 69 66 20 28 64 69 73 74 70 6f 69 6e 74 if (distpoint
2110: 2d 3e 74 79 70 65 20 3d 3d 20 30 29 20 7b 0a 09 ->type == 0) {..
2120: 09 2f 2a 20 66 75 6c 6c 2d 6e 61 6d 65 20 47 45 ./* full-name GE
2130: 4e 45 52 41 4c 49 5a 45 44 4e 41 4d 45 20 2a 2f NERALIZEDNAME */
2140: 0a 09 09 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 ...for (int j =
2150: 30 3b 20 6a 20 3c 20 73 6b 5f 47 45 4e 45 52 41 0; j < sk_GENERA
2160: 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 64 69 73 74 70 L_NAME_num(distp
2170: 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66 75 6c 6c 6e oint->name.fulln
2180: 61 6d 65 29 3b 20 6a 2b 2b 29 20 7b 0a 09 09 20 ame); j++) {...
2190: 20 20 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 20 GENERAL_NAME
21a0: 2a 67 65 6e 20 3d 20 73 6b 5f 47 45 4e 45 52 41 *gen = sk_GENERA
21b0: 4c 5f 4e 41 4d 45 5f 76 61 6c 75 65 28 64 69 73 L_NAME_value(dis
21c0: 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66 75 6c tpoint->name.ful
21d0: 6c 6e 61 6d 65 2c 20 6a 29 3b 0a 09 09 20 20 20 lname, j);...
21e0: 20 69 6e 74 20 74 79 70 65 3b 0a 09 09 20 20 20 int type;...
21f0: 20 41 53 4e 31 5f 53 54 52 49 4e 47 20 2a 75 72 ASN1_STRING *ur
2200: 69 20 3d 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 i = GENERAL_NAME
2210: 5f 67 65 74 30 5f 76 61 6c 75 65 28 67 65 6e 2c _get0_value(gen,
2220: 20 26 74 79 70 65 29 3b 0a 09 09 20 20 20 20 69 &type);... i
2230: 66 20 28 74 79 70 65 20 3d 3d 20 47 45 4e 5f 55 f (type == GEN_U
2240: 52 49 29 20 7b 0a 09 09 09 4c 41 50 50 45 4e 44 RI) {....LAPPEND
2250: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 _STR(interp, lis
2260: 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 41 53 4e 31 tPtr, NULL, ASN1
2270: 5f 53 54 52 49 4e 47 5f 67 65 74 30 5f 64 61 74 _STRING_get0_dat
2280: 61 28 75 72 69 29 2c 20 28 54 63 6c 5f 53 69 7a a(uri), (Tcl_Siz
2290: 65 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 6c e) ASN1_STRING_l
22a0: 65 6e 67 74 68 28 75 72 69 29 29 3b 0a 09 09 20 ength(uri));...
22b0: 20 20 20 7d 0a 09 09 7d 0a 09 20 20 20 20 7d 20 }...}.. }
22c0: 65 6c 73 65 20 69 66 20 28 64 69 73 74 70 6f 69 else if (distpoi
22d0: 6e 74 2d 3e 74 79 70 65 20 3d 3d 20 31 29 20 7b nt->type == 1) {
22e0: 0a 09 09 2f 2a 20 72 65 6c 61 74 69 76 65 2d 6e .../* relative-n
22f0: 61 6d 65 20 58 35 30 39 4e 41 4d 45 20 2a 2f 0a ame X509NAME */.
2300: 09 09 53 54 41 43 4b 5f 4f 46 28 58 35 30 39 5f ..STACK_OF(X509_
2310: 4e 41 4d 45 5f 45 4e 54 52 59 29 20 2a 73 6b 5f NAME_ENTRY) *sk_
2320: 72 65 6c 6e 61 6d 65 20 3d 20 64 69 73 74 70 6f relname = distpo
2330: 69 6e 74 2d 3e 6e 61 6d 65 2e 72 65 6c 61 74 69 int->name.relati
2340: 76 65 6e 61 6d 65 3b 0a 09 09 66 6f 72 20 28 69 vename;...for (i
2350: 6e 74 20 6a 20 3d 20 30 3b 20 6a 20 3c 20 73 6b nt j = 0; j < sk
2360: 5f 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 _X509_NAME_ENTRY
2370: 5f 6e 75 6d 28 73 6b 5f 72 65 6c 6e 61 6d 65 29 _num(sk_relname)
2380: 3b 20 6a 2b 2b 29 20 7b 0a 09 09 20 20 20 20 58 ; j++) {... X
2390: 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 20 2a 509_NAME_ENTRY *
23a0: 65 20 3d 20 73 6b 5f 58 35 30 39 5f 4e 41 4d 45 e = sk_X509_NAME
23b0: 5f 45 4e 54 52 59 5f 76 61 6c 75 65 28 73 6b 5f _ENTRY_value(sk_
23c0: 72 65 6c 6e 61 6d 65 2c 20 6a 29 3b 0a 09 09 20 relname, j);...
23d0: 20 20 20 41 53 4e 31 5f 53 54 52 49 4e 47 20 2a ASN1_STRING *
23e0: 64 20 3d 20 58 35 30 39 5f 4e 41 4d 45 5f 45 4e d = X509_NAME_EN
23f0: 54 52 59 5f 67 65 74 5f 64 61 74 61 28 65 29 3b TRY_get_data(e);
2400: 0a 09 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 ... LAPPEND_S
2410: 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 TR(interp, listP
2420: 74 72 2c 20 4e 55 4c 4c 2c 20 41 53 4e 31 5f 53 tr, NULL, ASN1_S
2430: 54 52 49 4e 47 5f 64 61 74 61 28 64 29 2c 20 28 TRING_data(d), (
2440: 54 63 6c 5f 53 69 7a 65 29 20 41 53 4e 31 5f 53 Tcl_Size) ASN1_S
2450: 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 64 29 29 TRING_length(d))
2460: 3b 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 7d 0a ;...}.. }..}.
2470: 09 43 52 4c 5f 44 49 53 54 5f 50 4f 49 4e 54 53 .CRL_DIST_POINTS
2480: 5f 66 72 65 65 28 63 72 6c 29 3b 0a 20 20 20 20 _free(crl);.
2490: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 }. return lis
24a0: 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 tPtr;.}../*. * G
24b0: 65 74 20 4f 6e 2d 6c 69 6e 65 20 43 65 72 74 69 et On-line Certi
24c0: 66 69 63 61 74 65 20 53 74 61 74 75 73 20 50 72 ficate Status Pr
24d0: 6f 74 6f 63 6f 6c 20 28 4f 53 43 50 29 20 55 52 otocol (OSCP) UR
24e0: 4c 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 L. */.Tcl_Obj *T
24f0: 6c 73 5f 78 35 30 39 4f 73 63 70 28 54 63 6c 5f ls_x509Oscp(Tcl_
2500: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 Interp *interp,
2510: 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 X509 *cert) {.
2520: 20 20 53 54 41 43 4b 5f 4f 46 28 4f 50 45 4e 53 STACK_OF(OPENS
2530: 53 4c 5f 53 54 52 49 4e 47 29 20 2a 6f 63 73 70 SL_STRING) *ocsp
2540: 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c ;. Tcl_Obj *l
2550: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 istPtr = Tcl_New
2560: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 ListObj(0, NULL)
2570: 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 73 74 50 ;.. if (listP
2580: 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 tr == NULL) {..r
2590: 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 eturn NULL;.
25a0: 7d 0a 0a 20 20 20 20 69 66 20 28 6f 63 73 70 20 }.. if (ocsp
25b0: 3d 20 58 35 30 39 5f 67 65 74 31 5f 6f 63 73 70 = X509_get1_ocsp
25c0: 28 63 65 72 74 29 29 20 7b 0a 09 66 6f 72 20 28 (cert)) {..for (
25d0: 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 int i = 0; i < s
25e0: 6b 5f 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e 47 k_OPENSSL_STRING
25f0: 5f 6e 75 6d 28 6f 63 73 70 29 3b 20 69 2b 2b 29 _num(ocsp); i++)
2600: 20 7b 0a 09 20 20 20 20 4c 41 50 50 45 4e 44 5f {.. LAPPEND_
2610: 53 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 STR(interp, list
2620: 50 74 72 2c 20 4e 55 4c 4c 2c 20 73 6b 5f 4f 50 Ptr, NULL, sk_OP
2630: 45 4e 53 53 4c 5f 53 54 52 49 4e 47 5f 76 61 6c ENSSL_STRING_val
2640: 75 65 28 6f 63 73 70 2c 20 69 29 2c 20 2d 31 29 ue(ocsp, i), -1)
2650: 3b 0a 09 7d 0a 09 58 35 30 39 5f 65 6d 61 69 6c ;..}..X509_email
2660: 5f 66 72 65 65 28 6f 63 73 70 29 3b 0a 20 20 20 _free(ocsp);.
2670: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 }. return li
2680: 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 stPtr;.}../*. *
2690: 47 65 74 20 43 65 72 74 69 66 69 63 61 74 65 20 Get Certificate
26a0: 41 75 74 68 6f 72 69 74 79 20 28 43 41 29 20 49 Authority (CA) I
26b0: 73 73 75 65 72 73 20 55 52 4c 0a 20 2a 2f 0a 54 ssuers URL. */.T
26c0: 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 cl_Obj *Tls_x509
26d0: 43 61 49 73 73 75 65 72 73 28 54 63 6c 5f 49 6e CaIssuers(Tcl_In
26e0: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 terp *interp, X5
26f0: 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 09 *cert) {.
2700: 53 54 41 43 4b 5f 4f 46 28 41 43 43 45 53 53 5f STACK_OF(ACCESS_
2710: 44 45 53 43 52 49 50 54 49 4f 4e 29 20 2a 61 64 DESCRIPTION) *ad
2720: 73 3b 0a 20 20 20 20 41 43 43 45 53 53 5f 44 45 s;. ACCESS_DE
2730: 53 43 52 49 50 54 49 4f 4e 20 2a 61 64 3b 0a 20 SCRIPTION *ad;.
2740: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 Tcl_Obj *list
2750: 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 Ptr = Tcl_NewLis
2760: 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 tObj(0, NULL);.
2770: 20 20 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 unsigned char
2780: 20 2a 62 75 66 3b 0a 20 20 20 20 69 6e 74 20 6c *buf;. int l
2790: 65 6e 3b 0a 0a 20 20 20 20 69 66 20 28 61 64 73 en;.. if (ads
27a0: 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f = X509_get_ext_
27b0: 64 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 69 6e d2i(cert, NID_in
27c0: 66 6f 5f 61 63 63 65 73 73 2c 20 4e 55 4c 4c 2c fo_access, NULL,
27d0: 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 28 NULL)) {..for (
27e0: 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 int i = 0; i < s
27f0: 6b 5f 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 k_ACCESS_DESCRIP
2800: 54 49 4f 4e 5f 6e 75 6d 28 61 64 73 29 3b 20 69 TION_num(ads); i
2810: 2b 2b 29 20 7b 0a 09 20 20 20 20 61 64 20 3d 20 ++) {.. ad =
2820: 73 6b 5f 41 43 43 45 53 53 5f 44 45 53 43 52 49 sk_ACCESS_DESCRI
2830: 50 54 49 4f 4e 5f 76 61 6c 75 65 28 61 64 73 2c PTION_value(ads,
2840: 20 69 29 3b 0a 09 20 20 20 20 69 66 20 28 4f 42 i);.. if (OB
2850: 4a 5f 6f 62 6a 32 6e 69 64 28 61 64 2d 3e 6d 65 J_obj2nid(ad->me
2860: 74 68 6f 64 29 20 3d 3d 20 4e 49 44 5f 61 64 5f thod) == NID_ad_
2870: 63 61 5f 69 73 73 75 65 72 73 20 26 26 20 61 64 ca_issuers && ad
2880: 2d 3e 6c 6f 63 61 74 69 6f 6e 29 20 7b 0a 09 09 ->location) {...
2890: 69 66 20 28 61 64 2d 3e 6c 6f 63 61 74 69 6f 6e if (ad->location
28a0: 2d 3e 74 79 70 65 20 3d 3d 20 47 45 4e 5f 55 52 ->type == GEN_UR
28b0: 49 29 20 7b 0a 09 09 20 20 20 20 6c 65 6e 20 3d I) {... len =
28c0: 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 74 6f 5f ASN1_STRING_to_
28d0: 55 54 46 38 28 26 62 75 66 2c 20 61 64 2d 3e 6c UTF8(&buf, ad->l
28e0: 6f 63 61 74 69 6f 6e 2d 3e 64 2e 75 6e 69 66 6f ocation->d.unifo
28f0: 72 6d 52 65 73 6f 75 72 63 65 49 64 65 6e 74 69 rmResourceIdenti
2900: 66 69 65 72 29 3b 0a 09 09 20 20 20 20 54 63 6c fier);... Tcl
2910: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
2920: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 ement(interp, li
2930: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 stPtr, Tcl_NewSt
2940: 72 69 6e 67 4f 62 6a 28 62 75 66 2c 20 28 54 63 ringObj(buf, (Tc
2950: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 29 3b 0a 09 l_Size) len));..
2960: 09 20 20 20 20 4f 50 45 4e 53 53 4c 5f 66 72 65 . OPENSSL_fre
2970: 65 28 62 75 66 29 3b 0a 09 09 20 20 20 20 62 72 e(buf);... br
2980: 65 61 6b 3b 0a 09 09 7d 0a 09 20 20 20 20 7d 0a eak;...}.. }.
2990: 09 7d 0a 09 2f 2a 20 73 6b 5f 41 43 43 45 53 53 .}../* sk_ACCESS
29a0: 5f 44 45 53 43 52 49 50 54 49 4f 4e 5f 70 6f 70 _DESCRIPTION_pop
29b0: 5f 66 72 65 65 28 61 64 73 2c 20 41 43 43 45 53 _free(ads, ACCES
29c0: 53 5f 44 45 53 43 52 49 50 54 49 4f 4e 5f 66 72 S_DESCRIPTION_fr
29d0: 65 65 29 3b 20 2a 2f 0a 09 41 55 54 48 4f 52 49 ee); */..AUTHORI
29e0: 54 59 5f 49 4e 46 4f 5f 41 43 43 45 53 53 5f 66 TY_INFO_ACCESS_f
29f0: 72 65 65 28 61 64 73 29 3b 0a 20 20 20 20 7d 0a ree(ads);. }.
2a00: 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 return listP
2a10: 74 72 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d tr;.}.../*. *---
2a20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a50: 2d 2d 2d 2a 0a 20 2a 0a 20 2a 09 54 6c 73 5f 4e ---*. *. *.Tls_N
2a60: 65 77 58 35 30 39 4f 62 6a 20 2d 2d 0a 20 2a 0a ewX509Obj --. *.
2a70: 20 2a 09 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *.-------------
2a80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2aa0: 2d 2d 2d 2a 0a 20 2a 09 43 6f 6e 76 65 72 74 73 ---*. *.Converts
2ab0: 20 61 20 58 35 30 39 20 63 65 72 74 69 66 69 63 a X509 certific
2ac0: 61 74 65 20 69 6e 74 6f 20 61 20 54 63 6c 5f 4f ate into a Tcl_O
2ad0: 62 6a 0a 20 2a 09 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d bj. *.----------
2ae0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2af0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2b00: 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 0a 20 2a 09 53 69 ------*. *. *.Si
2b10: 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 09 de effects:. *..
2b20: 4e 6f 6e 65 0a 20 2a 0a 20 2a 09 52 65 73 75 6c None. *. *.Resul
2b30: 74 3a 0a 20 2a 09 09 41 20 54 63 6c 20 4c 69 73 t:. *..A Tcl Lis
2b40: 74 20 4f 62 6a 65 63 74 20 72 65 70 72 65 73 65 t Object represe
2b50: 6e 74 69 6e 67 20 74 68 65 20 70 72 6f 76 69 64 nting the provid
2b60: 65 64 0a 20 2a 09 09 58 35 30 39 20 63 65 72 74 ed. *..X509 cert
2b70: 69 66 69 63 61 74 65 2e 0a 20 2a 0a 20 2a 2d 2d ificate.. *. *--
2b80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2b90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2ba0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2bb0: 2d 2d 2d 2d 2a 0a 20 2a 2f 0a 0a 54 63 6c 5f 4f ----*. */..Tcl_O
2bc0: 62 6a 2a 0a 54 6c 73 5f 4e 65 77 58 35 30 39 4f bj*.Tls_NewX509O
2bd0: 62 6a 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 bj(Tcl_Interp *i
2be0: 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 nterp, X509 *cer
2bf0: 74 29 20 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a t) {. Tcl_Obj
2c00: 20 2a 63 65 72 74 50 74 72 20 3d 20 54 63 6c 5f *certPtr = Tcl_
2c10: 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 NewListObj(0, NU
2c20: 4c 4c 29 3b 0a 20 20 20 20 42 49 4f 20 2a 62 69 LL);. BIO *bi
2c30: 6f 20 3d 20 42 49 4f 5f 6e 65 77 28 42 49 4f 5f o = BIO_new(BIO_
2c40: 73 5f 6d 65 6d 28 29 29 3b 0a 20 20 20 20 69 6e s_mem());. in
2c50: 74 20 6d 64 6e 69 64 2c 20 70 6b 6e 69 64 2c 20 t mdnid, pknid,
2c60: 62 69 74 73 2c 20 6c 65 6e 3b 0a 20 20 20 20 75 bits, len;. u
2c70: 69 6e 74 33 32 5f 74 20 78 66 6c 61 67 73 3b 0a int32_t xflags;.
2c80: 20 20 20 20 63 68 61 72 20 62 75 66 66 65 72 5b char buffer[
2c90: 42 55 46 53 49 5a 5d 3b 0a 20 20 20 20 75 6e 73 BUFSIZ];. uns
2ca0: 69 67 6e 65 64 20 63 68 61 72 20 6d 64 5b 45 56 igned char md[EV
2cb0: 50 5f 4d 41 58 5f 4d 44 5f 53 49 5a 45 5d 3b 0a P_MAX_MD_SIZE];.
2cc0: 20 20 20 20 75 6e 73 69 67 6e 65 64 20 6c 6f 6e unsigned lon
2cd0: 67 20 66 6c 61 67 73 20 3d 20 58 4e 5f 46 4c 41 g flags = XN_FLA
2ce0: 47 5f 52 46 43 32 32 35 33 20 7c 20 41 53 4e 31 G_RFC2253 | ASN1
2cf0: 5f 53 54 52 46 4c 47 53 5f 55 54 46 38 5f 43 4f _STRFLGS_UTF8_CO
2d00: 4e 56 45 52 54 3b 0a 20 20 20 20 66 6c 61 67 73 NVERT;. flags
2d10: 20 26 3d 20 7e 41 53 4e 31 5f 53 54 52 46 4c 47 &= ~ASN1_STRFLG
2d20: 53 5f 45 53 43 5f 4d 53 42 3b 0a 0a 20 20 20 20 S_ESC_MSB;..
2d30: 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 if (interp == NU
2d40: 4c 4c 20 7c 7c 20 63 65 72 74 20 3d 3d 20 4e 55 LL || cert == NU
2d50: 4c 4c 20 7c 7c 20 62 69 6f 20 3d 3d 20 4e 55 4c LL || bio == NUL
2d60: 4c 20 7c 7c 20 63 65 72 74 50 74 72 20 3d 3d 20 L || certPtr ==
2d70: 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 NULL) {..return
2d80: 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 NULL;. }..
2d90: 20 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61 6c /* Signature al
2da0: 67 6f 72 69 74 68 6d 20 61 6e 64 20 76 61 6c 75 gorithm and valu
2db0: 65 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 e - RFC 5280 sec
2dc0: 74 69 6f 6e 20 34 2e 31 2e 31 2e 32 20 61 6e 64 tion 4.1.1.2 and
2dd0: 20 34 2e 31 2e 31 2e 33 20 2a 2f 0a 20 20 20 20 4.1.1.3 */.
2de0: 2f 2a 20 73 69 67 6e 61 74 75 72 65 41 6c 67 6f /* signatureAlgo
2df0: 72 69 74 68 6d 20 69 73 20 74 68 65 20 69 64 20 rithm is the id
2e00: 6f 66 20 74 68 65 20 63 72 79 70 74 6f 67 72 61 of the cryptogra
2e10: 70 68 69 63 20 61 6c 67 6f 72 69 74 68 6d 20 75 phic algorithm u
2e20: 73 65 64 20 62 79 20 74 68 65 0a 09 43 41 20 74 sed by the..CA t
2e30: 6f 20 73 69 67 6e 20 74 68 69 73 20 63 65 72 74 o sign this cert
2e40: 2e 20 73 69 67 6e 61 74 75 72 65 56 61 6c 75 65 . signatureValue
2e50: 20 69 73 20 74 68 65 20 64 69 67 69 74 61 6c 20 is the digital
2e60: 73 69 67 6e 61 74 75 72 65 20 63 6f 6d 70 75 74 signature comput
2e70: 65 64 0a 09 75 70 6f 6e 20 74 68 65 20 41 53 4e ed..upon the ASN
2e80: 2e 31 20 44 45 52 20 65 6e 63 6f 64 65 64 20 74 .1 DER encoded t
2e90: 62 73 43 65 72 74 69 66 69 63 61 74 65 2e 20 2a bsCertificate. *
2ea0: 2f 0a 20 20 20 20 7b 0a 09 63 6f 6e 73 74 20 58 /. {..const X
2eb0: 35 30 39 5f 41 4c 47 4f 52 20 2a 73 69 67 5f 61 509_ALGOR *sig_a
2ec0: 6c 67 3b 0a 09 63 6f 6e 73 74 20 41 53 4e 31 5f lg;..const ASN1_
2ed0: 42 49 54 5f 53 54 52 49 4e 47 20 2a 73 69 67 3b BIT_STRING *sig;
2ee0: 0a 09 69 6e 74 20 73 69 67 5f 6e 69 64 3b 0a 0a ..int sig_nid;..
2ef0: 09 58 35 30 39 5f 67 65 74 30 5f 73 69 67 6e 61 .X509_get0_signa
2f00: 74 75 72 65 28 26 73 69 67 2c 20 26 73 69 67 5f ture(&sig, &sig_
2f10: 61 6c 67 2c 20 63 65 72 74 29 3b 0a 09 2f 2a 20 alg, cert);../*
2f20: 73 69 67 5f 6e 69 64 20 3d 20 58 35 30 39 5f 67 sig_nid = X509_g
2f30: 65 74 5f 73 69 67 6e 61 74 75 72 65 5f 6e 69 64 et_signature_nid
2f40: 28 63 65 72 74 29 20 2a 2f 0a 09 73 69 67 5f 6e (cert) */..sig_n
2f50: 69 64 20 3d 20 4f 42 4a 5f 6f 62 6a 32 6e 69 64 id = OBJ_obj2nid
2f60: 28 73 69 67 5f 61 6c 67 2d 3e 61 6c 67 6f 72 69 (sig_alg->algori
2f70: 74 68 6d 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 thm);..LAPPEND_S
2f80: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 TR(interp, certP
2f90: 74 72 2c 20 22 73 69 67 6e 61 74 75 72 65 41 6c tr, "signatureAl
2fa0: 67 6f 72 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e 69 gorithm", OBJ_ni
2fb0: 64 32 6c 6e 28 73 69 67 5f 6e 69 64 29 2c 20 2d d2ln(sig_nid), -
2fc0: 31 29 3b 0a 09 6c 65 6e 20 3d 20 28 73 69 67 5f 1);..len = (sig_
2fd0: 6e 69 64 20 21 3d 20 4e 49 44 5f 75 6e 64 65 66 nid != NID_undef
2fe0: 29 20 3f 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 ) ? String_to_He
2ff0: 78 28 73 69 67 2d 3e 64 61 74 61 2c 20 73 69 67 x(sig->data, sig
3000: 2d 3e 6c 65 6e 67 74 68 2c 20 62 75 66 66 65 72 ->length, buffer
3010: 2c 20 42 55 46 53 49 5a 29 20 3a 20 30 3b 0a 09 , BUFSIZ) : 0;..
3020: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
3030: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 rp, certPtr, "si
3040: 67 6e 61 74 75 72 65 56 61 6c 75 65 22 2c 20 62 gnatureValue", b
3050: 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 uffer, (Tcl_Size
3060: 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 ) len);. }..
3070: 20 20 20 2f 2a 20 56 65 72 73 69 6f 6e 20 6f 66 /* Version of
3080: 20 74 68 65 20 65 6e 63 6f 64 65 64 20 63 65 72 the encoded cer
3090: 74 69 66 69 63 61 74 65 20 2d 20 52 46 43 20 35 tificate - RFC 5
30a0: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 280 section 4.1.
30b0: 32 2e 31 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 2.1 */. LAPPE
30c0: 4e 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 ND_LONG(interp,
30d0: 63 65 72 74 50 74 72 2c 20 22 76 65 72 73 69 6f certPtr, "versio
30e0: 6e 22 2c 20 58 35 30 39 5f 67 65 74 5f 76 65 72 n", X509_get_ver
30f0: 73 69 6f 6e 28 63 65 72 74 29 2b 31 29 3b 0a 0a sion(cert)+1);..
3100: 20 20 20 20 2f 2a 20 55 6e 69 71 75 65 20 6e 75 /* Unique nu
3110: 6d 62 65 72 20 61 73 73 69 67 6e 65 64 20 62 79 mber assigned by
3120: 20 43 41 20 74 6f 20 63 65 72 74 69 66 69 63 61 CA to certifica
3130: 74 65 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 te - RFC 5280 se
3140: 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 32 20 2a 2f ction 4.1.2.2 */
3150: 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 . len = BIO_t
3160: 6f 5f 42 75 66 66 65 72 28 69 32 61 5f 41 53 4e o_Buffer(i2a_ASN
3170: 31 5f 49 4e 54 45 47 45 52 28 62 69 6f 2c 20 58 1_INTEGER(bio, X
3180: 35 30 39 5f 67 65 74 30 5f 73 65 72 69 61 6c 4e 509_get0_serialN
3190: 75 6d 62 65 72 28 63 65 72 74 29 29 2c 20 62 69 umber(cert)), bi
31a0: 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 o, buffer, BUFSI
31b0: 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f Z);. LAPPEND_
31c0: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 STR(interp, cert
31d0: 50 74 72 2c 20 22 73 65 72 69 61 6c 4e 75 6d 62 Ptr, "serialNumb
31e0: 65 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 er", buffer, (Tc
31f0: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 l_Size) len);..
3200: 20 20 20 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 /* Signature
3210: 61 6c 67 6f 72 69 74 68 6d 20 75 73 65 64 20 62 algorithm used b
3220: 79 20 74 68 65 20 43 41 20 74 6f 20 73 69 67 6e y the CA to sign
3230: 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 the certificate
3240: 2e 20 4d 75 73 74 20 6d 61 74 63 68 0a 09 73 69 . Must match..si
3250: 67 6e 61 74 75 72 65 41 6c 67 6f 72 69 74 68 6d gnatureAlgorithm
3260: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
3270: 6f 6e 20 34 2e 31 2e 32 2e 33 20 2a 2f 0a 20 20 on 4.1.2.3 */.
3280: 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e LAPPEND_STR(in
3290: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
32a0: 73 69 67 6e 61 74 75 72 65 22 2c 20 4f 42 4a 5f signature", OBJ_
32b0: 6e 69 64 32 6c 6e 28 58 35 30 39 5f 67 65 74 5f nid2ln(X509_get_
32c0: 73 69 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 signature_nid(ce
32d0: 72 74 29 29 2c 20 2d 31 29 3b 0a 0a 20 20 20 20 rt)), -1);..
32e0: 2f 2a 20 49 73 73 75 65 72 20 69 64 65 6e 74 69 /* Issuer identi
32f0: 66 69 65 73 20 74 68 65 20 65 6e 74 69 74 79 20 fies the entity
3300: 74 68 61 74 20 73 69 67 6e 65 64 20 61 6e 64 20 that signed and
3310: 69 73 73 75 65 64 20 74 68 65 20 63 65 72 74 2e issued the cert.
3320: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f RFC 5280 sectio
3330: 6e 20 34 2e 31 2e 32 2e 34 20 2a 2f 0a 20 20 20 n 4.1.2.4 */.
3340: 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 len = BIO_to_Bu
3350: 66 66 65 72 28 58 35 30 39 5f 4e 41 4d 45 5f 70 ffer(X509_NAME_p
3360: 72 69 6e 74 5f 65 78 28 62 69 6f 2c 20 58 35 30 rint_ex(bio, X50
3370: 39 5f 67 65 74 5f 69 73 73 75 65 72 5f 6e 61 6d 9_get_issuer_nam
3380: 65 28 63 65 72 74 29 2c 20 30 2c 20 66 6c 61 67 e(cert), 0, flag
3390: 73 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c s), bio, buffer,
33a0: 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 BUFSIZ);. LA
33b0: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 PPEND_STR(interp
33c0: 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 73 75 , certPtr, "issu
33d0: 65 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 er", buffer, (Tc
33e0: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 l_Size) len);..
33f0: 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 /* Certificat
3400: 65 20 76 61 6c 69 64 69 74 79 20 70 65 72 69 6f e validity perio
3410: 64 20 69 73 20 74 68 65 20 69 6e 74 65 72 76 61 d is the interva
3420: 6c 20 74 68 65 20 43 41 20 77 61 72 72 61 6e 74 l the CA warrant
3430: 73 20 74 68 61 74 20 69 74 20 77 69 6c 6c 0a 09 s that it will..
3440: 6d 61 69 6e 74 61 69 6e 20 69 6e 66 6f 20 6f 6e maintain info on
3450: 20 74 68 65 20 73 74 61 74 75 73 20 6f 66 20 74 the status of t
3460: 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 he certificate.
3470: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
3480: 20 34 2e 31 2e 32 2e 35 20 2a 2f 0a 20 20 20 20 4.1.2.5 */.
3490: 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 74 79 20 /* Get Validity
34a0: 2d 20 4e 6f 74 20 42 65 66 6f 72 65 20 2a 2f 0a - Not Before */.
34b0: 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f len = BIO_to
34c0: 5f 42 75 66 66 65 72 28 41 53 4e 31 5f 54 49 4d _Buffer(ASN1_TIM
34d0: 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 35 30 E_print(bio, X50
34e0: 39 5f 67 65 74 30 5f 6e 6f 74 42 65 66 6f 72 65 9_get0_notBefore
34f0: 28 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 (cert)), bio, bu
3500: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 ffer, BUFSIZ);.
3510: 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 LAPPEND_STR(i
3520: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
3530: 22 6e 6f 74 42 65 66 6f 72 65 22 2c 20 62 75 66 "notBefore", buf
3540: 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 fer, (Tcl_Size)
3550: 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 len);.. /* Ge
3560: 74 20 56 61 6c 69 64 69 74 79 20 2d 20 4e 6f 74 t Validity - Not
3570: 20 41 66 74 65 72 20 2a 2f 0a 20 20 20 20 6c 65 After */. le
3580: 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 n = BIO_to_Buffe
3590: 72 28 41 53 4e 31 5f 54 49 4d 45 5f 70 72 69 6e r(ASN1_TIME_prin
35a0: 74 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30 t(bio, X509_get0
35b0: 5f 6e 6f 74 41 66 74 65 72 28 63 65 72 74 29 29 _notAfter(cert))
35c0: 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 , bio, buffer, B
35d0: 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 UFSIZ);. LAPP
35e0: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 END_STR(interp,
35f0: 63 65 72 74 50 74 72 2c 20 22 6e 6f 74 41 66 74 certPtr, "notAft
3600: 65 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 er", buffer, (Tc
3610: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 l_Size) len);..
3620: 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 69 64 /* Subject id
3630: 65 6e 74 69 66 69 65 73 20 74 68 65 20 65 6e 74 entifies the ent
3640: 69 74 79 20 61 73 73 6f 63 69 61 74 65 64 20 77 ity associated w
3650: 69 74 68 20 74 68 65 20 70 75 62 6c 69 63 20 6b ith the public k
3660: 65 79 20 73 74 6f 72 65 64 20 69 6e 0a 09 74 68 ey stored in..th
3670: 65 20 73 75 62 6a 65 63 74 20 70 75 62 6c 69 63 e subject public
3680: 20 6b 65 79 20 66 69 65 6c 64 2e 20 52 46 43 20 key field. RFC
3690: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 5280 section 4.1
36a0: 2e 32 2e 36 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 .2.6 */. len
36b0: 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 = BIO_to_Buffer(
36c0: 58 35 30 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f X509_NAME_print_
36d0: 65 78 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 ex(bio, X509_get
36e0: 5f 73 75 62 6a 65 63 74 5f 6e 61 6d 65 28 63 65 _subject_name(ce
36f0: 72 74 29 2c 20 30 2c 20 66 6c 61 67 73 29 2c 20 rt), 0, flags),
3700: 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46 bio, buffer, BUF
3710: 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e SIZ);. LAPPEN
3720: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 D_STR(interp, ce
3730: 72 74 50 74 72 2c 20 22 73 75 62 6a 65 63 74 22 rtPtr, "subject"
3740: 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 , buffer, (Tcl_S
3750: 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 ize) len);..
3760: 2f 2a 20 53 48 41 31 20 44 69 67 65 73 74 20 28 /* SHA1 Digest (
3770: 46 69 6e 67 65 72 70 72 69 6e 74 29 20 6f 66 20 Fingerprint) of
3780: 63 65 72 74 20 2d 20 44 45 52 20 72 65 70 72 65 cert - DER repre
3790: 73 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 sentation */.
37a0: 20 69 66 20 28 58 35 30 39 5f 64 69 67 65 73 74 if (X509_digest
37b0: 28 63 65 72 74 2c 20 45 56 50 5f 73 68 61 31 28 (cert, EVP_sha1(
37c0: 29 2c 20 6d 64 2c 20 26 6c 65 6e 29 29 20 7b 0a ), md, &len)) {.
37d0: 20 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 len = String
37e0: 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 6c 65 6e 2c _to_Hex(md, len,
37f0: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 buffer, BUFSIZ)
3800: 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 ;..LAPPEND_STR(i
3810: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
3820: 22 73 68 61 31 5f 68 61 73 68 22 2c 20 62 75 66 "sha1_hash", buf
3830: 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 fer, (Tcl_Size)
3840: 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 len);. }..
3850: 20 2f 2a 20 53 48 41 32 35 36 20 44 69 67 65 73 /* SHA256 Diges
3860: 74 20 28 46 69 6e 67 65 72 70 72 69 6e 74 29 20 t (Fingerprint)
3870: 6f 66 20 63 65 72 74 20 2d 20 44 45 52 20 72 65 of cert - DER re
3880: 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a presentation */.
3890: 20 20 20 20 69 66 20 28 58 35 30 39 5f 64 69 67 if (X509_dig
38a0: 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f 73 68 est(cert, EVP_sh
38b0: 61 32 35 36 28 29 2c 20 6d 64 2c 20 26 6c 65 6e a256(), md, &len
38c0: 29 29 20 7b 0a 20 20 20 20 6c 65 6e 20 3d 20 53 )) {. len = S
38d0: 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c tring_to_Hex(md,
38e0: 20 6c 65 6e 2c 20 62 75 66 66 65 72 2c 20 42 55 len, buffer, BU
38f0: 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f FSIZ);..LAPPEND_
3900: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 STR(interp, cert
3910: 50 74 72 2c 20 22 73 68 61 32 35 36 5f 68 61 73 Ptr, "sha256_has
3920: 68 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c h", buffer, (Tcl
3930: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 _Size) len);.
3940: 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 }.. /* Subje
3950: 63 74 20 50 75 62 6c 69 63 20 4b 65 79 20 49 6e ct Public Key In
3960: 66 6f 20 73 70 65 63 69 66 69 65 73 20 74 68 65 fo specifies the
3970: 20 70 75 62 6c 69 63 20 6b 65 79 20 61 6e 64 20 public key and
3980: 69 64 65 6e 74 69 66 69 65 73 20 74 68 65 0a 09 identifies the..
3990: 61 6c 67 6f 72 69 74 68 6d 20 77 69 74 68 20 77 algorithm with w
39a0: 68 69 63 68 20 74 68 65 20 6b 65 79 20 69 73 20 hich the key is
39b0: 75 73 65 64 2e 20 52 46 43 20 35 32 38 30 20 73 used. RFC 5280 s
39c0: 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 37 20 2a ection 4.1.2.7 *
39d0: 2f 0a 20 20 20 20 69 66 20 28 58 35 30 39 5f 67 /. if (X509_g
39e0: 65 74 5f 73 69 67 6e 61 74 75 72 65 5f 69 6e 66 et_signature_inf
39f0: 6f 28 63 65 72 74 2c 20 26 6d 64 6e 69 64 2c 20 o(cert, &mdnid,
3a00: 26 70 6b 6e 69 64 2c 20 26 62 69 74 73 2c 20 26 &pknid, &bits, &
3a10: 78 66 6c 61 67 73 29 29 20 7b 0a 09 41 53 4e 31 xflags)) {..ASN1
3a20: 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a 6b 65 79 _BIT_STRING *key
3a30: 3b 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 ;..unsigned int
3a40: 6e 3b 0a 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 n;...LAPPEND_STR
3a50: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3a60: 2c 20 22 73 69 67 6e 69 6e 67 44 69 67 65 73 74 , "signingDigest
3a70: 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 6d 64 ", OBJ_nid2ln(md
3a80: 6e 69 64 29 2c 20 2d 31 29 3b 0a 09 4c 41 50 50 nid), -1);..LAPP
3a90: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 END_STR(interp,
3aa0: 63 65 72 74 50 74 72 2c 20 22 70 75 62 6c 69 63 certPtr, "public
3ab0: 4b 65 79 41 6c 67 6f 72 69 74 68 6d 22 2c 20 4f KeyAlgorithm", O
3ac0: 42 4a 5f 6e 69 64 32 6c 6e 28 70 6b 6e 69 64 29 BJ_nid2ln(pknid)
3ad0: 2c 20 2d 31 29 3b 0a 09 4c 41 50 50 45 4e 44 5f , -1);..LAPPEND_
3ae0: 49 4e 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 INT(interp, cert
3af0: 50 74 72 2c 20 22 62 69 74 73 22 2c 20 62 69 74 Ptr, "bits", bit
3b00: 73 29 3b 20 2f 2a 20 45 66 66 65 63 74 69 76 65 s); /* Effective
3b10: 20 73 65 63 75 72 69 74 79 20 62 69 74 73 20 2a security bits *
3b20: 2f 0a 0a 09 6b 65 79 20 3d 20 58 35 30 39 5f 67 /...key = X509_g
3b30: 65 74 30 5f 70 75 62 6b 65 79 5f 62 69 74 73 74 et0_pubkey_bitst
3b40: 72 28 63 65 72 74 29 3b 0a 09 6c 65 6e 20 3d 20 r(cert);..len =
3b50: 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6b 65 String_to_Hex(ke
3b60: 79 2d 3e 64 61 74 61 2c 20 6b 65 79 2d 3e 6c 65 y->data, key->le
3b70: 6e 67 74 68 2c 20 62 75 66 66 65 72 2c 20 42 55 ngth, buffer, BU
3b80: 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f FSIZ);..LAPPEND_
3b90: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 STR(interp, cert
3ba0: 50 74 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 22 Ptr, "publicKey"
3bb0: 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 , buffer, (Tcl_S
3bc0: 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 6c 65 6e ize) len);...len
3bd0: 20 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f = 0;..if (X509_
3be0: 70 75 62 6b 65 79 5f 64 69 67 65 73 74 28 63 65 pubkey_digest(ce
3bf0: 72 74 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65 rt, EVP_get_dige
3c00: 73 74 62 79 6e 69 64 28 70 6b 6e 69 64 29 2c 20 stbynid(pknid),
3c10: 6d 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20 md, &n)) {..
3c20: 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f len = String_to_
3c30: 48 65 78 28 6d 64 2c 20 28 69 6e 74 29 6e 2c 20 Hex(md, (int)n,
3c40: 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b buffer, BUFSIZ);
3c50: 0a 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 ..}..LAPPEND_STR
3c60: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3c70: 2c 20 22 70 75 62 6c 69 63 4b 65 79 48 61 73 68 , "publicKeyHash
3c80: 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f ", buffer, (Tcl_
3c90: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 2f 2a Size) len);.../*
3ca0: 20 64 69 67 65 73 74 20 6f 66 20 74 68 65 20 44 digest of the D
3cb0: 45 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f ER representatio
3cc0: 6e 20 6f 66 20 74 68 65 20 63 65 72 74 69 66 69 n of the certifi
3cd0: 63 61 74 65 20 2a 2f 0a 09 6c 65 6e 20 3d 20 30 cate */..len = 0
3ce0: 3b 0a 09 69 66 20 28 58 35 30 39 5f 64 69 67 65 ;..if (X509_dige
3cf0: 73 74 28 63 65 72 74 2c 20 45 56 50 5f 67 65 74 st(cert, EVP_get
3d00: 5f 64 69 67 65 73 74 62 79 6e 69 64 28 6d 64 6e _digestbynid(mdn
3d10: 69 64 29 2c 20 6d 64 2c 20 26 6e 29 29 20 7b 0a id), md, &n)) {.
3d20: 09 20 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e . len = Strin
3d30: 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 28 69 6e g_to_Hex(md, (in
3d40: 74 29 6e 2c 20 62 75 66 66 65 72 2c 20 42 55 46 t)n, buffer, BUF
3d50: 53 49 5a 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e SIZ);..}..LAPPEN
3d60: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 D_STR(interp, ce
3d70: 72 74 50 74 72 2c 20 22 73 69 67 6e 61 74 75 72 rtPtr, "signatur
3d80: 65 48 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20 eHash", buffer,
3d90: 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b (Tcl_Size) len);
3da0: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 43 . }.. /* C
3db0: 65 72 74 69 66 69 63 61 74 65 20 50 75 72 70 6f ertificate Purpo
3dc0: 73 65 2e 20 43 61 6c 6c 20 62 65 66 6f 72 65 20 se. Call before
3dd0: 63 68 65 63 6b 69 6e 67 20 66 6f 72 20 65 78 74 checking for ext
3de0: 65 6e 73 69 6f 6e 73 2e 20 2a 2f 0a 20 20 20 20 ensions. */.
3df0: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
3e00: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75 rp, certPtr, "pu
3e10: 72 70 6f 73 65 22 2c 20 54 6c 73 5f 78 35 30 39 rpose", Tls_x509
3e20: 50 75 72 70 6f 73 65 28 63 65 72 74 29 2c 20 2d Purpose(cert), -
3e30: 31 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 1);. LAPPEND_
3e40: 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 OBJ(interp, cert
3e50: 50 74 72 2c 20 22 63 65 72 74 69 66 69 63 61 74 Ptr, "certificat
3e60: 65 50 75 72 70 6f 73 65 22 2c 20 54 6c 73 5f 78 ePurpose", Tls_x
3e70: 35 30 39 50 75 72 70 6f 73 65 73 28 69 6e 74 65 509Purposes(inte
3e80: 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 rp, cert));..
3e90: 20 2f 2a 20 47 65 74 20 65 78 74 65 6e 73 69 6f /* Get extensio
3ea0: 6e 73 20 66 6c 61 67 73 20 2a 2f 0a 20 20 20 20 ns flags */.
3eb0: 78 66 6c 61 67 73 20 3d 20 58 35 30 39 5f 67 65 xflags = X509_ge
3ec0: 74 5f 65 78 74 65 6e 73 69 6f 6e 5f 66 6c 61 67 t_extension_flag
3ed0: 73 28 63 65 72 74 29 3b 0a 20 20 20 20 4c 41 50 s(cert);. LAP
3ee0: 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c PEND_INT(interp,
3ef0: 20 63 65 72 74 50 74 72 2c 20 22 65 78 74 46 6c certPtr, "extFl
3f00: 61 67 73 22 2c 20 78 66 6c 61 67 73 29 3b 0a 0a ags", xflags);..
3f10: 09 2f 2a 20 43 68 65 63 6b 20 69 66 20 63 65 72 ./* Check if cer
3f20: 74 20 77 61 73 20 69 73 73 75 65 64 20 62 79 20 t was issued by
3f30: 43 41 20 63 65 72 74 20 69 73 73 75 65 72 20 6f CA cert issuer o
3f40: 72 20 73 65 6c 66 20 73 69 67 6e 65 64 20 2a 2f r self signed */
3f50: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f . LAPPEND_BOO
3f60: 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 L(interp, certPt
3f70: 72 2c 20 22 73 65 6c 66 49 73 73 75 65 64 22 2c r, "selfIssued",
3f80: 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 xflags & EXFLAG
3f90: 5f 53 49 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e _SI);. LAPPEN
3fa0: 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 D_BOOL(interp, c
3fb0: 65 72 74 50 74 72 2c 20 22 73 65 6c 66 53 69 67 ertPtr, "selfSig
3fc0: 6e 65 64 22 2c 20 78 66 6c 61 67 73 20 26 20 45 ned", xflags & E
3fd0: 58 46 4c 41 47 5f 53 53 29 3b 0a 20 20 20 20 4c XFLAG_SS);. L
3fe0: 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 APPEND_BOOL(inte
3ff0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 rp, certPtr, "is
4000: 50 72 6f 78 79 43 65 72 74 22 2c 20 78 66 6c 61 ProxyCert", xfla
4010: 67 73 20 26 20 45 58 46 4c 41 47 5f 50 52 4f 58 gs & EXFLAG_PROX
4020: 59 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f Y);. LAPPEND_
4030: 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 BOOL(interp, cer
4040: 74 50 74 72 2c 20 22 65 78 74 49 6e 76 61 6c 69 tPtr, "extInvali
4050: 64 22 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46 d", xflags & EXF
4060: 4c 41 47 5f 49 4e 56 41 4c 49 44 29 3b 0a 20 20 LAG_INVALID);.
4070: 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 LAPPEND_BOOL(i
4080: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
4090: 22 69 73 43 41 43 65 72 74 22 2c 20 58 35 30 39 "isCACert", X509
40a0: 5f 63 68 65 63 6b 5f 63 61 28 63 65 72 74 29 29 _check_ca(cert))
40b0: 3b 0a 0a 20 20 20 20 2f 2a 20 54 68 65 20 55 6e ;.. /* The Un
40c0: 69 71 75 65 20 49 64 73 20 61 72 65 20 75 73 65 ique Ids are use
40d0: 64 20 74 6f 20 68 61 6e 64 6c 65 20 74 68 65 20 d to handle the
40e0: 70 6f 73 73 69 62 69 6c 69 74 79 20 6f 66 20 72 possibility of r
40f0: 65 75 73 65 20 6f 66 20 73 75 62 6a 65 63 74 0a euse of subject.
4100: 09 61 6e 64 2f 6f 72 20 69 73 73 75 65 72 20 6e .and/or issuer n
4110: 61 6d 65 73 20 6f 76 65 72 20 74 69 6d 65 2e 20 ames over time.
4120: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
4130: 20 34 2e 31 2e 32 2e 38 20 2a 2f 0a 20 20 20 20 4.1.2.8 */.
4140: 7b 0a 09 63 6f 6e 73 74 20 41 53 4e 31 5f 42 49 {..const ASN1_BI
4150: 54 5f 53 54 52 49 4e 47 20 2a 69 75 69 64 2c 20 T_STRING *iuid,
4160: 2a 73 75 69 64 3b 0a 20 20 20 20 20 20 20 20 58 *suid;. X
4170: 35 30 39 5f 67 65 74 30 5f 75 69 64 73 28 63 65 509_get0_uids(ce
4180: 72 74 2c 20 26 69 75 69 64 2c 20 26 73 75 69 64 rt, &iuid, &suid
4190: 29 3b 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 6a );...Tcl_ListObj
41a0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
41b0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 terp, certPtr, T
41c0: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
41d0: 22 69 73 73 75 65 72 55 6e 69 71 75 65 49 64 22 "issuerUniqueId"
41e0: 2c 20 2d 31 29 29 3b 0a 09 69 66 20 28 69 75 69 , -1));..if (iui
41f0: 64 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 d != NULL) {..
4200: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
4210: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
4220: 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f p, certPtr, Tcl_
4230: 4e 65 77 42 79 74 65 41 72 72 61 79 4f 62 6a 28 NewByteArrayObj(
4240: 28 63 68 61 72 20 2a 29 69 75 69 64 2d 3e 64 61 (char *)iuid->da
4250: 74 61 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 69 ta, (Tcl_Size) i
4260: 75 69 64 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 uid->length));..
4270: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 } else {.. Tc
4280: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
4290: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 lement(interp, c
42a0: 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 ertPtr, Tcl_NewS
42b0: 74 72 69 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 tringObj("", -1)
42c0: 29 3b 0a 09 7d 0a 0a 09 54 63 6c 5f 4c 69 73 74 );..}...Tcl_List
42d0: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 ObjAppendElement
42e0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
42f0: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f , Tcl_NewStringO
4300: 62 6a 28 22 73 75 62 6a 65 63 74 55 6e 69 71 75 bj("subjectUniqu
4310: 65 49 64 22 2c 20 2d 31 29 29 3b 0a 09 69 66 20 eId", -1));..if
4320: 28 73 75 69 64 20 21 3d 20 4e 55 4c 4c 29 20 7b (suid != NULL) {
4330: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 .. Tcl_ListOb
4340: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 jAppendElement(i
4350: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
4360: 54 63 6c 5f 4e 65 77 42 79 74 65 41 72 72 61 79 Tcl_NewByteArray
4370: 4f 62 6a 28 28 63 68 61 72 20 2a 29 73 75 69 64 Obj((char *)suid
4380: 2d 3e 64 61 74 61 2c 20 28 54 63 6c 5f 53 69 7a ->data, (Tcl_Siz
4390: 65 29 20 73 75 69 64 2d 3e 6c 65 6e 67 74 68 29 e) suid->length)
43a0: 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 );..} else {..
43b0: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
43c0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
43d0: 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f p, certPtr, Tcl_
43e0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 22 2c NewStringObj("",
43f0: 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a -1));..}. }.
4400: 0a 20 20 20 20 2f 2a 20 58 35 30 39 20 76 33 20 . /* X509 v3
4410: 45 78 74 65 6e 73 69 6f 6e 73 20 2d 20 52 46 43 Extensions - RFC
4420: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 5280 section 4.
4430: 31 2e 32 2e 39 20 2a 2f 0a 20 20 20 20 4c 41 50 1.2.9 */. LAP
4440: 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c PEND_INT(interp,
4450: 20 63 65 72 74 50 74 72 2c 20 22 65 78 74 43 6f certPtr, "extCo
4460: 75 6e 74 22 2c 20 58 35 30 39 5f 67 65 74 5f 65 unt", X509_get_e
4470: 78 74 5f 63 6f 75 6e 74 28 63 65 72 74 29 29 3b xt_count(cert));
4480: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a . LAPPEND_OBJ
4490: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
44a0: 2c 20 22 65 78 74 65 6e 73 69 6f 6e 73 22 2c 20 , "extensions",
44b0: 54 6c 73 5f 78 35 30 39 45 78 74 65 6e 73 69 6f Tls_x509Extensio
44c0: 6e 73 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 ns(interp, cert)
44d0: 29 3b 0a 0a 20 20 20 20 2f 2a 20 41 75 74 68 6f );.. /* Autho
44e0: 72 69 74 79 20 4b 65 79 20 49 64 65 6e 74 69 66 rity Key Identif
44f0: 69 65 72 20 28 41 4b 49 29 20 69 73 20 74 68 65 ier (AKI) is the
4500: 20 53 75 62 6a 65 63 74 20 4b 65 79 20 49 64 65 Subject Key Ide
4510: 6e 74 69 66 69 65 72 20 28 53 4b 49 29 20 6f 66 ntifier (SKI) of
4520: 0a 09 69 74 73 20 73 69 67 6e 65 72 20 28 74 68 ..its signer (th
4530: 65 20 43 41 29 2e 20 52 46 43 20 35 32 38 30 20 e CA). RFC 5280
4540: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 2c section 4.2.1.1,
4550: 20 4e 49 44 5f 61 75 74 68 6f 72 69 74 79 5f 6b NID_authority_k
4560: 65 79 5f 69 64 65 6e 74 69 66 69 65 72 20 2a 2f ey_identifier */
4570: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a . LAPPEND_OBJ
4580: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
4590: 2c 20 22 61 75 74 68 6f 72 69 74 79 4b 65 79 49 , "authorityKeyI
45a0: 64 65 6e 74 69 66 69 65 72 22 2c 0a 09 54 6c 73 dentifier",..Tls
45b0: 5f 78 35 30 39 49 64 65 6e 74 69 66 69 65 72 28 _x509Identifier(
45c0: 58 35 30 39 5f 67 65 74 30 5f 61 75 74 68 6f 72 X509_get0_author
45d0: 69 74 79 5f 6b 65 79 5f 69 64 28 63 65 72 74 29 ity_key_id(cert)
45e0: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a ));.. /* Subj
45f0: 65 63 74 20 4b 65 79 20 49 64 65 6e 74 69 66 69 ect Key Identifi
4600: 65 72 20 28 53 4b 49 29 20 69 73 20 75 73 65 64 er (SKI) is used
4610: 20 74 6f 20 69 64 65 6e 74 69 66 79 20 63 65 72 to identify cer
4620: 74 69 66 69 63 61 74 65 73 20 74 68 61 74 20 63 tificates that c
4630: 6f 6e 74 61 69 6e 0a 09 61 20 70 61 72 74 69 63 ontain..a partic
4640: 75 6c 61 72 20 70 75 62 6c 69 63 20 6b 65 79 2e ular public key.
4650: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f RFC 5280 sectio
4660: 6e 20 34 2e 32 2e 31 2e 32 2c 20 4e 49 44 5f 73 n 4.2.1.2, NID_s
4670: 75 62 6a 65 63 74 5f 6b 65 79 5f 69 64 65 6e 74 ubject_key_ident
4680: 69 66 69 65 72 20 2a 2f 0a 20 20 20 20 4c 41 50 ifier */. LAP
4690: 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c PEND_OBJ(interp,
46a0: 20 63 65 72 74 50 74 72 2c 20 22 73 75 62 6a 65 certPtr, "subje
46b0: 63 74 4b 65 79 49 64 65 6e 74 69 66 69 65 72 22 ctKeyIdentifier"
46c0: 2c 0a 09 54 6c 73 5f 78 35 30 39 49 64 65 6e 74 ,..Tls_x509Ident
46d0: 69 66 69 65 72 28 58 35 30 39 5f 67 65 74 30 5f ifier(X509_get0_
46e0: 73 75 62 6a 65 63 74 5f 6b 65 79 5f 69 64 28 63 subject_key_id(c
46f0: 65 72 74 29 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 ert)));.. /*
4700: 4b 65 79 20 75 73 61 67 65 20 65 78 74 65 6e 73 Key usage extens
4710: 69 6f 6e 20 64 65 66 69 6e 65 73 20 74 68 65 20 ion defines the
4720: 70 75 72 70 6f 73 65 20 28 65 2e 67 2e 2c 20 65 purpose (e.g., e
4730: 6e 63 69 70 68 65 72 6d 65 6e 74 2c 20 73 69 67 ncipherment, sig
4740: 6e 61 74 75 72 65 2c 20 63 65 72 74 69 66 69 63 nature, certific
4750: 61 74 65 0a 09 73 69 67 6e 69 6e 67 29 20 6f 66 ate..signing) of
4760: 20 74 68 65 20 6b 65 79 20 69 6e 20 74 68 65 20 the key in the
4770: 63 65 72 74 69 66 69 63 61 74 65 2e 20 52 46 43 certificate. RFC
4780: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 5280 section 4.
4790: 32 2e 31 2e 33 2c 20 4e 49 44 5f 6b 65 79 5f 75 2.1.3, NID_key_u
47a0: 73 61 67 65 20 2a 2f 0a 20 20 20 20 4c 41 50 50 sage */. LAPP
47b0: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 END_OBJ(interp,
47c0: 63 65 72 74 50 74 72 2c 20 22 6b 65 79 55 73 61 certPtr, "keyUsa
47d0: 67 65 22 2c 20 54 6c 73 5f 78 35 30 39 4b 65 79 ge", Tls_x509Key
47e0: 55 73 61 67 65 28 69 6e 74 65 72 70 2c 20 63 65 Usage(interp, ce
47f0: 72 74 2c 20 78 66 6c 61 67 73 29 29 3b 0a 0a 20 rt, xflags));..
4800: 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 /* Certificat
4810: 65 20 50 6f 6c 69 63 69 65 73 20 2d 20 69 6e 64 e Policies - ind
4820: 69 63 61 74 65 73 20 74 68 65 20 69 73 73 75 69 icates the issui
4830: 6e 67 20 43 41 20 63 6f 6e 73 69 64 65 72 73 20 ng CA considers
4840: 69 74 73 20 69 73 73 75 65 72 44 6f 6d 61 69 6e its issuerDomain
4850: 50 6f 6c 69 63 79 0a 09 65 71 75 69 76 61 6c 65 Policy..equivale
4860: 6e 74 20 74 6f 20 74 68 65 20 73 75 62 6a 65 63 nt to the subjec
4870: 74 20 43 41 27 73 20 73 75 62 6a 65 63 74 44 6f t CA's subjectDo
4880: 6d 61 69 6e 50 6f 6c 69 63 79 2e 20 52 46 43 20 mainPolicy. RFC
4890: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 5280 section 4.2
48a0: 2e 31 2e 34 2c 20 4e 49 44 5f 63 65 72 74 69 66 .1.4, NID_certif
48b0: 69 63 61 74 65 5f 70 6f 6c 69 63 69 65 73 20 2a icate_policies *
48c0: 2f 0a 20 20 20 20 69 66 20 28 78 66 6c 61 67 73 /. if (xflags
48d0: 20 26 20 45 58 46 4c 41 47 5f 49 4e 56 41 4c 49 & EXFLAG_INVALI
48e0: 44 5f 50 4f 4c 49 43 59 29 20 7b 0a 09 2f 2a 20 D_POLICY) {../*
48f0: 52 65 6a 65 63 74 20 63 65 72 74 20 2a 2f 0a 20 Reject cert */.
4900: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c }.. /* Pol
4910: 69 63 79 20 4d 61 70 70 69 6e 67 73 20 2d 20 52 icy Mappings - R
4920: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 FC 5280 section
4930: 34 2e 32 2e 31 2e 35 2c 20 4e 49 44 5f 70 6f 6c 4.2.1.5, NID_pol
4940: 69 63 79 5f 6d 61 70 70 69 6e 67 73 20 2a 2f 0a icy_mappings */.
4950: 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 . /* Subject
4960: 41 6c 74 65 72 6e 61 74 69 76 65 20 4e 61 6d 65 Alternative Name
4970: 20 28 53 41 4e 29 20 63 6f 6e 74 61 69 6e 73 20 (SAN) contains
4980: 61 64 64 69 74 69 6f 6e 61 6c 20 55 52 4c 73 2c additional URLs,
4990: 20 44 4e 53 20 6e 61 6d 65 73 2c 20 6f 72 20 49 DNS names, or I
49a0: 50 0a 09 61 64 64 72 65 73 73 65 73 20 62 6f 75 P..addresses bou
49b0: 6e 64 20 74 6f 20 63 65 72 74 69 66 69 63 61 74 nd to certificat
49c0: 65 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 e. RFC 5280 sect
49d0: 69 6f 6e 20 34 2e 32 2e 31 2e 36 2c 20 4e 49 44 ion 4.2.1.6, NID
49e0: 5f 73 75 62 6a 65 63 74 5f 61 6c 74 5f 6e 61 6d _subject_alt_nam
49f0: 65 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 e */. LAPPEND
4a00: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 _OBJ(interp, cer
4a10: 74 50 74 72 2c 20 22 73 75 62 6a 65 63 74 41 6c tPtr, "subjectAl
4a20: 74 4e 61 6d 65 22 2c 20 54 6c 73 5f 78 35 30 39 tName", Tls_x509
4a30: 4e 61 6d 65 73 28 69 6e 74 65 72 70 2c 20 63 65 Names(interp, ce
4a40: 72 74 2c 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f rt, NID_subject_
4a50: 61 6c 74 5f 6e 61 6d 65 2c 20 62 69 6f 29 29 3b alt_name, bio));
4a60: 0a 0a 20 20 20 20 2f 2a 20 49 73 73 75 65 72 20 .. /* Issuer
4a70: 41 6c 74 65 72 6e 61 74 69 76 65 20 4e 61 6d 65 Alternative Name
4a80: 20 69 73 20 75 73 65 64 20 74 6f 20 61 73 73 6f is used to asso
4a90: 63 69 61 74 65 20 49 6e 74 65 72 6e 65 74 20 73 ciate Internet s
4aa0: 74 79 6c 65 20 69 64 65 6e 74 69 74 69 65 73 0a tyle identities.
4ab0: 09 77 69 74 68 20 74 68 65 20 63 65 72 74 69 66 .with the certif
4ac0: 69 63 61 74 65 20 69 73 73 75 65 72 2e 20 52 46 icate issuer. RF
4ad0: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 C 5280 section 4
4ae0: 2e 32 2e 31 2e 37 2c 20 4e 49 44 5f 69 73 73 75 .2.1.7, NID_issu
4af0: 65 72 5f 61 6c 74 5f 6e 61 6d 65 20 2a 2f 0a 20 er_alt_name */.
4b00: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 LAPPEND_OBJ(i
4b10: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
4b20: 22 69 73 73 75 65 72 41 6c 74 4e 61 6d 65 22 2c "issuerAltName",
4b30: 20 54 6c 73 5f 78 35 30 39 4e 61 6d 65 73 28 69 Tls_x509Names(i
4b40: 6e 74 65 72 70 2c 20 63 65 72 74 2c 20 4e 49 44 nterp, cert, NID
4b50: 5f 69 73 73 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 _issuer_alt_name
4b60: 2c 20 62 69 6f 29 29 3b 0a 0a 20 20 20 20 2f 2a , bio));.. /*
4b70: 20 53 75 62 6a 65 63 74 20 44 69 72 65 63 74 6f Subject Directo
4b80: 72 79 20 41 74 74 72 69 62 75 74 65 73 20 70 72 ry Attributes pr
4b90: 6f 76 69 64 65 73 20 69 64 65 6e 74 69 66 69 63 ovides identific
4ba0: 61 74 69 6f 6e 20 61 74 74 72 69 62 75 74 65 73 ation attributes
4bb0: 20 28 65 2e 67 2e 2c 20 6e 61 74 69 6f 6e 61 6c (e.g., national
4bc0: 69 74 79 29 0a 09 6f 66 20 74 68 65 20 73 75 62 ity)..of the sub
4bd0: 6a 65 63 74 2e 20 52 46 43 20 35 32 38 30 20 73 ject. RFC 5280 s
4be0: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 38 20 28 ection 4.2.1.8 (
4bf0: 73 75 62 6a 65 63 74 44 69 72 65 63 74 6f 72 79 subjectDirectory
4c00: 41 74 74 72 69 62 75 74 65 73 29 20 2a 2f 0a 0a Attributes) */..
4c10: 20 20 20 20 2f 2a 20 42 61 73 69 63 20 43 6f 6e /* Basic Con
4c20: 73 74 72 61 69 6e 74 73 20 69 64 65 6e 74 69 66 straints identif
4c30: 69 65 73 20 77 68 65 74 68 65 72 20 74 68 65 20 ies whether the
4c40: 73 75 62 6a 65 63 74 20 6f 66 20 74 68 65 20 63 subject of the c
4c50: 65 72 74 20 69 73 20 61 20 43 41 20 61 6e 64 0a ert is a CA and.
4c60: 09 74 68 65 20 6d 61 78 20 64 65 70 74 68 20 6f .the max depth o
4c70: 66 20 76 61 6c 69 64 20 63 65 72 74 20 70 61 74 f valid cert pat
4c80: 68 73 20 66 6f 72 20 74 68 69 73 20 63 65 72 74 hs for this cert
4c90: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
4ca0: 6f 6e 20 34 2e 32 2e 31 2e 39 2c 20 4e 49 44 5f on 4.2.1.9, NID_
4cb0: 62 61 73 69 63 5f 63 6f 6e 73 74 72 61 69 6e 74 basic_constraint
4cc0: 73 20 2a 2f 0a 20 20 20 20 69 66 20 28 21 28 78 s */. if (!(x
4cd0: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 50 flags & EXFLAG_P
4ce0: 52 4f 58 59 29 29 20 7b 0a 09 4c 41 50 50 45 4e ROXY)) {..LAPPEN
4cf0: 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63 D_LONG(interp, c
4d00: 65 72 74 50 74 72 2c 20 22 70 61 74 68 4c 65 6e ertPtr, "pathLen
4d10: 22 2c 20 58 35 30 39 5f 67 65 74 5f 70 61 74 68 ", X509_get_path
4d20: 6c 65 6e 28 63 65 72 74 29 29 3b 0a 20 20 20 20 len(cert));.
4d30: 7d 20 65 6c 73 65 20 7b 0a 09 4c 41 50 50 45 4e } else {..LAPPEN
4d40: 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63 D_LONG(interp, c
4d50: 65 72 74 50 74 72 2c 20 22 70 61 74 68 4c 65 6e ertPtr, "pathLen
4d60: 22 2c 20 58 35 30 39 5f 67 65 74 5f 70 72 6f 78 ", X509_get_prox
4d70: 79 5f 70 61 74 68 6c 65 6e 28 63 65 72 74 29 29 y_pathlen(cert))
4d80: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 4c 41 50 50 ;. }. LAPP
4d90: 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c END_BOOL(interp,
4da0: 20 63 65 72 74 50 74 72 2c 20 22 62 61 73 69 63 certPtr, "basic
4db0: 43 6f 6e 73 74 72 61 69 6e 74 73 43 41 22 2c 20 ConstraintsCA",
4dc0: 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f xflags & EXFLAG_
4dd0: 43 41 29 3b 0a 0a 20 20 20 20 2f 2a 20 4e 61 6d CA);.. /* Nam
4de0: 65 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 73 e Constraints is
4df0: 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 43 41 only used in CA
4e00: 20 63 65 72 74 73 20 74 6f 20 69 6e 64 69 63 61 certs to indica
4e10: 74 65 20 74 68 65 20 6e 61 6d 65 20 73 70 61 63 te the name spac
4e20: 65 20 66 6f 72 0a 09 61 6c 6c 20 73 75 62 6a 65 e for..all subje
4e30: 63 74 20 6e 61 6d 65 73 20 69 6e 20 73 75 62 73 ct names in subs
4e40: 65 71 75 65 6e 74 20 63 65 72 74 69 66 69 63 61 equent certifica
4e50: 74 65 73 20 69 6e 20 61 20 63 65 72 74 69 66 69 tes in a certifi
4e60: 63 61 74 69 6f 6e 20 70 61 74 68 0a 09 4d 55 53 cation path..MUS
4e70: 54 20 62 65 20 6c 6f 63 61 74 65 64 2e 20 52 46 T be located. RF
4e80: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 C 5280 section 4
4e90: 2e 32 2e 31 2e 31 30 2c 20 4e 49 44 5f 6e 61 6d .2.1.10, NID_nam
4ea0: 65 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f e_constraints */
4eb0: 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c 69 63 79 20 .. /* Policy
4ec0: 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 73 20 6f Constraints is o
4ed0: 6e 6c 79 20 75 73 65 64 20 69 6e 20 43 41 20 63 nly used in CA c
4ee0: 65 72 74 73 20 74 6f 20 6c 69 6d 69 74 20 74 68 erts to limit th
4ef0: 65 20 6c 65 6e 67 74 68 20 6f 66 20 61 0a 09 63 e length of a..c
4f00: 65 72 74 20 63 68 61 69 6e 20 66 6f 72 20 74 68 ert chain for th
4f10: 61 74 20 43 41 2e 20 52 46 43 20 35 32 38 30 20 at CA. RFC 5280
4f20: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 31 section 4.2.1.11
4f30: 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 5f 63 6f 6e , NID_policy_con
4f40: 73 74 72 61 69 6e 74 73 20 2a 2f 0a 0a 20 20 20 straints */..
4f50: 20 2f 2a 20 45 78 74 65 6e 64 65 64 20 4b 65 79 /* Extended Key
4f60: 20 55 73 61 67 65 20 69 6e 64 69 63 61 74 65 73 Usage indicates
4f70: 20 74 68 65 20 70 75 72 70 6f 73 65 73 20 74 68 the purposes th
4f80: 65 20 63 65 72 74 69 66 69 65 64 20 70 75 62 6c e certified publ
4f90: 69 63 20 6b 65 79 20 6d 61 79 20 62 65 0a 09 75 ic key may be..u
4fa0: 73 65 64 2c 20 62 65 79 6f 6e 64 20 74 68 65 20 sed, beyond the
4fb0: 62 61 73 69 63 20 70 75 72 70 6f 73 65 73 2e 20 basic purposes.
4fc0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
4fd0: 20 34 2e 32 2e 31 2e 31 32 2c 20 4e 49 44 5f 65 4.2.1.12, NID_e
4fe0: 78 74 5f 6b 65 79 5f 75 73 61 67 65 20 2a 2f 0a xt_key_usage */.
4ff0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 LAPPEND_OBJ(
5000: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
5010: 20 22 65 78 74 65 6e 64 65 64 4b 65 79 55 73 61 "extendedKeyUsa
5020: 67 65 22 2c 20 54 6c 73 5f 78 35 30 39 45 78 74 ge", Tls_x509Ext
5030: 4b 65 79 55 73 61 67 65 28 69 6e 74 65 72 70 2c KeyUsage(interp,
5040: 20 63 65 72 74 2c 20 78 66 6c 61 67 73 29 29 3b cert, xflags));
5050: 0a 0a 20 20 20 20 2f 2a 20 43 52 4c 20 44 69 73 .. /* CRL Dis
5060: 74 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e 74 73 tribution Points
5070: 20 69 64 65 6e 74 69 66 69 65 73 20 77 68 65 72 identifies wher
5080: 65 20 43 52 4c 20 69 6e 66 6f 72 6d 61 74 69 6f e CRL informatio
5090: 6e 20 63 61 6e 20 62 65 20 6f 62 74 61 69 6e 65 n can be obtaine
50a0: 64 2e 0a 09 52 46 43 20 35 32 38 30 20 73 65 63 d...RFC 5280 sec
50b0: 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 33 2a 2f 0a tion 4.2.1.13*/.
50c0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 LAPPEND_OBJ(
50d0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
50e0: 20 22 63 72 6c 44 69 73 74 72 69 62 75 74 69 6f "crlDistributio
50f0: 6e 50 6f 69 6e 74 73 22 2c 20 54 6c 73 5f 78 35 nPoints", Tls_x5
5100: 30 39 43 72 6c 44 70 28 69 6e 74 65 72 70 2c 20 09CrlDp(interp,
5110: 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 cert));.. /*
5120: 46 72 65 73 68 65 73 74 20 43 52 4c 20 65 78 74 Freshest CRL ext
5130: 65 6e 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 66 ension */. if
5140: 20 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 (xflags & EXFLA
5150: 47 5f 46 52 45 53 48 45 53 54 29 20 7b 0a 20 20 G_FRESHEST) {.
5160: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 41 75 74 68 }.. /* Auth
5170: 6f 72 69 74 79 20 49 6e 66 6f 72 6d 61 74 69 6f ority Informatio
5180: 6e 20 41 63 63 65 73 73 20 69 6e 64 69 63 61 74 n Access indicat
5190: 65 73 20 68 6f 77 20 74 6f 20 61 63 63 65 73 73 es how to access
51a0: 20 69 6e 66 6f 20 61 6e 64 20 73 65 72 76 69 63 info and servic
51b0: 65 73 0a 09 66 6f 72 20 74 68 65 20 63 65 72 74 es..for the cert
51c0: 69 66 69 63 61 74 65 20 69 73 73 75 65 72 2e 20 ificate issuer.
51d0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
51e0: 20 34 2e 32 2e 32 2e 31 2c 20 4e 49 44 5f 69 6e 4.2.2.1, NID_in
51f0: 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a 20 20 fo_access */..
5200: 20 20 2f 2a 20 47 65 74 20 4f 6e 2d 6c 69 6e 65 /* Get On-line
5210: 20 43 65 72 74 69 66 69 63 61 74 65 20 53 74 61 Certificate Sta
5220: 74 75 73 20 50 72 6f 74 6f 63 6f 6c 20 28 4f 53 tus Protocol (OS
5230: 43 50 29 20 52 65 73 70 6f 6e 64 65 72 73 20 55 CP) Responders U
5240: 52 4c 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e RL */. LAPPEN
5250: 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 D_OBJ(interp, ce
5260: 72 74 50 74 72 2c 20 22 6f 63 73 70 52 65 73 70 rtPtr, "ocspResp
5270: 6f 6e 64 65 72 73 22 2c 20 54 6c 73 5f 78 35 30 onders", Tls_x50
5280: 39 4f 73 63 70 28 69 6e 74 65 72 70 2c 20 63 65 9Oscp(interp, ce
5290: 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 rt));.. /* Ge
52a0: 74 20 43 65 72 74 69 66 69 63 61 74 65 20 41 75 t Certificate Au
52b0: 74 68 6f 72 69 74 79 20 28 43 41 29 20 49 73 73 thority (CA) Iss
52c0: 75 65 72 73 20 55 52 4c 20 2a 2f 0a 20 20 20 20 uers URL */.
52d0: 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 LAPPEND_OBJ(inte
52e0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 61 rp, certPtr, "ca
52f0: 49 73 73 75 65 72 73 22 2c 20 54 6c 73 5f 78 35 Issuers", Tls_x5
5300: 30 39 43 61 49 73 73 75 65 72 73 28 69 6e 74 65 09CaIssuers(inte
5310: 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 rp, cert));..
5320: 20 2f 2a 20 53 75 62 6a 65 63 74 20 49 6e 66 6f /* Subject Info
5330: 72 6d 61 74 69 6f 6e 20 41 63 63 65 73 73 20 2d rmation Access -
5340: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f RFC 5280 sectio
5350: 6e 20 34 2e 32 2e 32 2e 32 2c 20 4e 49 44 5f 73 n 4.2.2.2, NID_s
5360: 69 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a info_access */..
5370: 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 /* Certifica
5380: 74 65 20 41 6c 69 61 73 2e 20 49 66 20 75 73 65 te Alias. If use
5390: 73 20 61 20 50 4b 43 53 23 31 32 20 73 74 72 75 s a PKCS#12 stru
53a0: 63 74 75 72 65 2c 20 61 6c 69 61 73 20 77 69 6c cture, alias wil
53b0: 6c 20 72 65 66 6c 65 63 74 20 74 68 65 0a 09 66 l reflect the..f
53c0: 72 69 65 6e 64 6c 79 4e 61 6d 65 20 61 74 74 72 riendlyName attr
53d0: 69 62 75 74 65 20 28 52 46 43 20 32 39 38 35 29 ibute (RFC 2985)
53e0: 2e 20 2a 2f 0a 20 20 20 20 7b 0a 09 6c 65 6e 20 . */. {..len
53f0: 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 63 68 61 = 0;. cha
5400: 72 20 2a 73 74 72 69 6e 67 20 3d 20 58 35 30 39 r *string = X509
5410: 5f 61 6c 69 61 73 5f 67 65 74 30 28 63 65 72 74 _alias_get0(cert
5420: 2c 20 26 6c 65 6e 29 3b 0a 09 4c 41 50 50 45 4e , &len);..LAPPEN
5430: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 D_STR(interp, ce
5440: 72 74 50 74 72 2c 20 22 61 6c 69 61 73 22 2c 20 rtPtr, "alias",
5450: 73 74 72 69 6e 67 2c 20 28 54 63 6c 5f 53 69 7a string, (Tcl_Siz
5460: 65 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a e) len);. }..
5470: 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 /* Certifica
5480: 74 65 20 61 6e 64 20 64 75 6d 70 20 61 6c 6c 20 te and dump all
5490: 64 61 74 61 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 data */. {..c
54a0: 68 61 72 20 63 65 72 74 53 74 72 5b 43 45 52 54 har certStr[CERT
54b0: 5f 53 54 52 5f 53 49 5a 45 5d 3b 0a 0a 09 2f 2a _STR_SIZE];.../*
54c0: 20 47 65 74 20 63 65 72 74 69 66 69 63 61 74 65 Get certificate
54d0: 20 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 74 */..len = BIO_t
54e0: 6f 5f 42 75 66 66 65 72 28 50 45 4d 5f 77 72 69 o_Buffer(PEM_wri
54f0: 74 65 5f 62 69 6f 5f 58 35 30 39 28 62 69 6f 2c te_bio_X509(bio,
5500: 20 63 65 72 74 29 2c 20 62 69 6f 2c 20 63 65 72 cert), bio, cer
5510: 74 53 74 72 2c 20 43 45 52 54 5f 53 54 52 5f 53 tStr, CERT_STR_S
5520: 49 5a 45 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 IZE);..LAPPEND_S
5530: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 TR(interp, certP
5540: 74 72 2c 20 22 63 65 72 74 69 66 69 63 61 74 65 tr, "certificate
5550: 22 2c 20 63 65 72 74 53 74 72 2c 20 28 54 63 6c ", certStr, (Tcl
5560: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 2f _Size) len);.../
5570: 2a 20 47 65 74 20 61 6c 6c 20 63 65 72 74 20 69 * Get all cert i
5580: 6e 66 6f 20 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 nfo */..len = BI
5590: 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39 O_to_Buffer(X509
55a0: 5f 70 72 69 6e 74 5f 65 78 28 62 69 6f 2c 20 63 _print_ex(bio, c
55b0: 65 72 74 2c 20 66 6c 61 67 73 2c 20 30 29 2c 20 ert, flags, 0),
55c0: 62 69 6f 2c 20 63 65 72 74 53 74 72 2c 20 43 45 bio, certStr, CE
55d0: 52 54 5f 53 54 52 5f 53 49 5a 45 29 3b 0a 09 4c RT_STR_SIZE);..L
55e0: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 APPEND_STR(inter
55f0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 61 6c 6c p, certPtr, "all
5600: 22 2c 20 63 65 72 74 53 74 72 2c 20 28 54 63 6c ", certStr, (Tcl
5610: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 _Size) len);.
5620: 20 7d 0a 0a 20 20 20 20 42 49 4f 5f 66 72 65 65 }.. BIO_free
5630: 28 62 69 6f 29 3b 0a 20 20 20 20 72 65 74 75 72 (bio);. retur
5640: 6e 20 63 65 72 74 50 74 72 3b 0a 7d 0a n certPtr;.}.