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 41 53 4e 31 5f 53 54 52 49 to_Hex(ASN1_STRI
0850: 4e 47 5f 67 65 74 30 5f 64 61 74 61 28 61 73 74 NG_get0_data(ast
0860: 72 69 6e 67 29 2c 0a 09 20 20 20 20 41 53 4e 31 ring),.. ASN1
0870: 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 61 _STRING_length(a
0880: 73 74 72 69 6e 67 29 2c 20 62 75 66 66 65 72 2c string), buffer,
0890: 20 31 30 32 34 29 3b 0a 20 20 20 20 7d 0a 20 20 1024);. }.
08a0: 20 20 72 65 73 75 6c 74 50 74 72 20 3d 20 54 63 resultPtr = Tc
08b0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 62 l_NewStringObj(b
08c0: 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 uffer, (Tcl_Size
08d0: 29 20 6c 65 6e 29 3b 0a 20 20 20 20 72 65 74 75 ) len);. retu
08e0: 72 6e 20 72 65 73 75 6c 74 50 74 72 3b 0a 7d 0a rn resultPtr;.}.
08f0: 0a 2f 2a 0a 20 2a 20 47 65 74 20 4b 65 79 20 55 ./*. * Get Key U
0900: 73 61 67 65 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a sage. */.Tcl_Obj
0910: 20 2a 54 6c 73 5f 78 35 30 39 4b 65 79 55 73 61 *Tls_x509KeyUsa
0920: 67 65 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 ge(Tcl_Interp *i
0930: 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 nterp, X509 *cer
0940: 74 2c 20 75 69 6e 74 33 32 5f 74 20 78 66 6c 61 t, uint32_t xfla
0950: 67 73 29 20 7b 0a 20 20 20 20 75 69 6e 74 33 32 gs) {. uint32
0960: 5f 74 20 75 73 61 67 65 20 3d 20 58 35 30 39 5f _t usage = X509_
0970: 67 65 74 5f 6b 65 79 5f 75 73 61 67 65 28 63 65 get_key_usage(ce
0980: 72 74 29 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a rt);. Tcl_Obj
0990: 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f *listPtr = Tcl_
09a0: 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 NewListObj(0, NU
09b0: 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 LL);.. if (li
09c0: 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b stPtr == NULL) {
09d0: 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 ..return NULL;.
09e0: 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 28 78 }.. if ((x
09f0: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 4b flags & EXFLAG_K
0a00: 55 53 41 47 45 29 20 26 26 20 75 73 61 67 65 20 USAGE) && usage
0a10: 3c 20 55 49 4e 54 33 32 5f 4d 41 58 29 20 7b 0a < UINT32_MAX) {.
0a20: 09 69 66 20 28 75 73 61 67 65 20 26 20 4b 55 5f .if (usage & KU_
0a30: 44 49 47 49 54 41 4c 5f 53 49 47 4e 41 54 55 52 DIGITAL_SIGNATUR
0a40: 45 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 E) {.. Tcl_Li
0a50: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 stObjAppendEleme
0a60: 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 nt(interp, listP
0a70: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e tr, Tcl_NewStrin
0a80: 67 4f 62 6a 28 22 44 69 67 69 74 61 6c 20 53 69 gObj("Digital Si
0a90: 67 6e 61 74 75 72 65 22 2c 20 2d 31 29 29 3b 0a gnature", -1));.
0aa0: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 .}..if (usage &
0ab0: 4b 55 5f 4e 4f 4e 5f 52 45 50 55 44 49 41 54 49 KU_NON_REPUDIATI
0ac0: 4f 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c ON) {.. Tcl_L
0ad0: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d istObjAppendElem
0ae0: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 ent(interp, list
0af0: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 Ptr, Tcl_NewStri
0b00: 6e 67 4f 62 6a 28 22 4e 6f 6e 2d 52 65 70 75 64 ngObj("Non-Repud
0b10: 69 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09 iation", -1));..
0b20: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 4b }..if (usage & K
0b30: 55 5f 4b 45 59 5f 45 4e 43 49 50 48 45 52 4d 45 U_KEY_ENCIPHERME
0b40: 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c NT) {.. Tcl_L
0b50: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d istObjAppendElem
0b60: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 ent(interp, list
0b70: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 Ptr, Tcl_NewStri
0b80: 6e 67 4f 62 6a 28 22 4b 65 79 20 45 6e 63 69 70 ngObj("Key Encip
0b90: 68 65 72 6d 65 6e 74 22 2c 20 2d 31 29 29 3b 0a herment", -1));.
0ba0: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 .}..if (usage &
0bb0: 4b 55 5f 44 41 54 41 5f 45 4e 43 49 50 48 45 52 KU_DATA_ENCIPHER
0bc0: 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 6c MENT) {.. Tcl
0bd0: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
0be0: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 ement(interp, li
0bf0: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 stPtr, Tcl_NewSt
0c00: 72 69 6e 67 4f 62 6a 28 22 44 61 74 61 20 45 6e ringObj("Data En
0c10: 63 69 70 68 65 72 6d 65 6e 74 22 2c 20 2d 31 29 cipherment", -1)
0c20: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 );..}..if (usage
0c30: 20 26 20 4b 55 5f 4b 45 59 5f 41 47 52 45 45 4d & KU_KEY_AGREEM
0c40: 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f ENT) {.. Tcl_
0c50: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
0c60: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 ment(interp, lis
0c70: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 tPtr, Tcl_NewStr
0c80: 69 6e 67 4f 62 6a 28 22 4b 65 79 20 41 67 72 65 ingObj("Key Agre
0c90: 65 6d 65 6e 74 22 2c 20 2d 31 29 29 3b 0a 09 7d ement", -1));..}
0ca0: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 4b 55 ..if (usage & KU
0cb0: 5f 4b 45 59 5f 43 45 52 54 5f 53 49 47 4e 29 20 _KEY_CERT_SIGN)
0cc0: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f {.. Tcl_ListO
0cd0: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 bjAppendElement(
0ce0: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
0cf0: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
0d00: 6a 28 22 43 65 72 74 69 66 69 63 61 74 65 20 53 j("Certificate S
0d10: 69 67 6e 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 igning", -1));..
0d20: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 4b }..if (usage & K
0d30: 55 5f 43 52 4c 5f 53 49 47 4e 29 20 7b 0a 09 20 U_CRL_SIGN) {..
0d40: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 Tcl_ListObjAp
0d50: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
0d60: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c rp, listPtr, Tcl
0d70: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 43 _NewStringObj("C
0d80: 52 4c 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31 29 RL Signing", -1)
0d90: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 );..}..if (usage
0da0: 20 26 20 4b 55 5f 45 4e 43 49 50 48 45 52 5f 4f & KU_ENCIPHER_O
0db0: 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f NLY) {.. Tcl_
0dc0: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
0dd0: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 ment(interp, lis
0de0: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 tPtr, Tcl_NewStr
0df0: 69 6e 67 4f 62 6a 28 22 45 6e 63 69 70 68 65 72 ingObj("Encipher
0e00: 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b 0a 09 7d Only", -1));..}
0e10: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 4b 55 ..if (usage & KU
0e20: 5f 44 45 43 49 50 48 45 52 5f 4f 4e 4c 59 29 20 _DECIPHER_ONLY)
0e30: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f {.. Tcl_ListO
0e40: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 bjAppendElement(
0e50: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
0e60: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
0e70: 6a 28 22 44 65 63 69 70 68 65 72 20 4f 6e 6c 79 j("Decipher Only
0e80: 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 20 20 ", -1));..}.
0e90: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 } else {.. Tc
0ea0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
0eb0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
0ec0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
0ed0: 74 72 69 6e 67 4f 62 6a 28 22 75 6e 72 65 73 74 tringObj("unrest
0ee0: 72 69 63 74 65 64 22 2c 20 2d 31 29 29 3b 0a 20 ricted", -1));.
0ef0: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
0f00: 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 listPtr;.}../*.
0f10: 2a 20 47 65 74 20 43 65 72 74 69 66 69 63 61 74 * Get Certificat
0f20: 65 20 50 75 72 70 6f 73 65 0a 20 2a 2f 0a 63 68 e Purpose. */.ch
0f30: 61 72 20 2a 54 6c 73 5f 78 35 30 39 50 75 72 70 ar *Tls_x509Purp
0f40: 6f 73 65 28 58 35 30 39 20 2a 63 65 72 74 29 20 ose(X509 *cert)
0f50: 7b 0a 20 20 20 20 63 68 61 72 20 2a 70 75 72 70 {. char *purp
0f60: 6f 73 65 20 3d 20 4e 55 4c 4c 3b 0a 0a 20 20 20 ose = NULL;..
0f70: 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f if (X509_check_
0f80: 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 purpose(cert, X5
0f90: 30 39 5f 50 55 52 50 4f 53 45 5f 53 53 4c 5f 43 09_PURPOSE_SSL_C
0fa0: 4c 49 45 4e 54 2c 20 30 29 20 3e 20 30 29 20 7b LIENT, 0) > 0) {
0fb0: 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 53 53 4c ..purpose = "SSL
0fc0: 20 43 6c 69 65 6e 74 22 3b 0a 20 20 20 20 7d 20 Client";. }
0fd0: 65 6c 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 else if (X509_ch
0fe0: 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 eck_purpose(cert
0ff0: 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 53 , X509_PURPOSE_S
1000: 53 4c 5f 53 45 52 56 45 52 2c 20 30 29 20 3e 20 SL_SERVER, 0) >
1010: 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 0) {..purpose =
1020: 22 53 53 4c 20 53 65 72 76 65 72 22 3b 0a 20 20 "SSL Server";.
1030: 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 } else if (X50
1040: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 9_check_purpose(
1050: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f cert, X509_PURPO
1060: 53 45 5f 4e 53 5f 53 53 4c 5f 53 45 52 56 45 52 SE_NS_SSL_SERVER
1070: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 , 0) > 0) {..pur
1080: 70 6f 73 65 20 3d 20 22 4d 53 53 20 53 53 4c 20 pose = "MSS SSL
1090: 53 65 72 76 65 72 22 3b 0a 20 20 20 20 7d 20 65 Server";. } e
10a0: 6c 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 lse if (X509_che
10b0: 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c ck_purpose(cert,
10c0: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 53 4d X509_PURPOSE_SM
10d0: 49 4d 45 5f 53 49 47 4e 2c 20 30 29 20 3e 20 30 IME_SIGN, 0) > 0
10e0: 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 ) {..purpose = "
10f0: 53 4d 49 4d 45 20 53 69 67 6e 69 6e 67 22 3b 0a SMIME Signing";.
1100: 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 } else if (X
1110: 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 509_check_purpos
1120: 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 e(cert, X509_PUR
1130: 50 4f 53 45 5f 53 4d 49 4d 45 5f 45 4e 43 52 59 POSE_SMIME_ENCRY
1140: 50 54 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 PT, 0) > 0) {..p
1150: 75 72 70 6f 73 65 20 3d 20 22 53 4d 49 4d 45 20 urpose = "SMIME
1160: 45 6e 63 72 79 70 74 69 6f 6e 22 3b 0a 20 20 20 Encryption";.
1170: 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 } else if (X509
1180: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 _check_purpose(c
1190: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 ert, X509_PURPOS
11a0: 45 5f 43 52 4c 5f 53 49 47 4e 2c 20 30 29 20 3e E_CRL_SIGN, 0) >
11b0: 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 0) {..purpose =
11c0: 20 22 43 52 4c 20 53 69 67 6e 69 6e 67 22 3b 0a "CRL Signing";.
11d0: 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 } else if (X
11e0: 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 509_check_purpos
11f0: 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 e(cert, X509_PUR
1200: 50 4f 53 45 5f 41 4e 59 2c 20 30 29 20 3e 20 30 POSE_ANY, 0) > 0
1210: 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 ) {..purpose = "
1220: 41 6e 79 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 Any";. } else
1230: 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f if (X509_check_
1240: 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 purpose(cert, X5
1250: 30 39 5f 50 55 52 50 4f 53 45 5f 4f 43 53 50 5f 09_PURPOSE_OCSP_
1260: 48 45 4c 50 45 52 2c 20 30 29 20 3e 20 30 29 20 HELPER, 0) > 0)
1270: 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 4f 43 {..purpose = "OC
1280: 53 50 20 48 65 6c 70 65 72 22 3b 0a 20 20 20 20 SP Helper";.
1290: 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 5f } else if (X509_
12a0: 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 check_purpose(ce
12b0: 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 rt, X509_PURPOSE
12c0: 5f 54 49 4d 45 53 54 41 4d 50 5f 53 49 47 4e 2c _TIMESTAMP_SIGN,
12d0: 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 0) > 0) {..purp
12e0: 6f 73 65 20 3d 20 22 54 69 6d 65 73 74 61 6d 70 ose = "Timestamp
12f0: 20 53 69 67 6e 69 6e 67 22 3b 0a 20 20 20 20 7d Signing";. }
1300: 20 65 6c 73 65 20 7b 0a 09 70 75 72 70 6f 73 65 else {..purpose
1310: 20 3d 20 22 22 3b 0a 20 20 20 20 7d 0a 20 20 20 = "";. }.
1320: 20 72 65 74 75 72 6e 20 70 75 72 70 6f 73 65 3b return purpose;
1330: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 46 6f 72 20 65 61 .}../*. * For ea
1340: 63 68 20 70 75 72 70 6f 73 65 2c 20 67 65 74 20 ch purpose, get
1350: 63 65 72 74 69 66 69 63 61 74 65 20 61 70 70 6c certificate appl
1360: 69 63 61 62 69 6c 69 74 79 0a 20 2a 2f 0a 54 63 icability. */.Tc
1370: 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 50 l_Obj *Tls_x509P
1380: 75 72 70 6f 73 65 73 28 54 63 6c 5f 49 6e 74 65 urposes(Tcl_Inte
1390: 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 rp *interp, X509
13a0: 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 54 63 *cert) {. Tc
13b0: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d l_Obj *listPtr =
13c0: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 Tcl_NewListObj(
13d0: 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 58 35 0, NULL);. X5
13e0: 30 39 5f 50 55 52 50 4f 53 45 20 2a 70 74 6d 70 09_PURPOSE *ptmp
13f0: 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 73 74 50 ;.. if (listP
1400: 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 tr == NULL) {..r
1410: 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 eturn NULL;.
1420: 7d 0a 0a 20 20 20 20 66 6f 72 20 28 69 6e 74 20 }.. for (int
1430: 69 20 3d 20 30 3b 20 69 20 3c 20 58 35 30 39 5f i = 0; i < X509_
1440: 50 55 52 50 4f 53 45 5f 67 65 74 5f 63 6f 75 6e PURPOSE_get_coun
1450: 74 28 29 3b 20 69 2b 2b 29 20 7b 0a 09 70 74 6d t(); i++) {..ptm
1460: 70 20 3d 20 58 35 30 39 5f 50 55 52 50 4f 53 45 p = X509_PURPOSE
1470: 5f 67 65 74 30 28 69 29 3b 0a 09 54 63 6c 5f 4f _get0(i);..Tcl_O
1480: 62 6a 20 2a 74 6d 70 50 74 72 20 3d 20 54 63 6c bj *tmpPtr = Tcl
1490: 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e _NewListObj(0, N
14a0: 55 4c 4c 29 3b 0a 0a 09 66 6f 72 20 28 69 6e 74 ULL);...for (int
14b0: 20 6a 20 3d 20 30 3b 20 6a 20 3c 20 32 3b 20 6a j = 0; j < 2; j
14c0: 2b 2b 29 20 7b 0a 09 20 20 20 20 69 6e 74 20 69 ++) {.. int i
14d0: 64 72 65 74 20 3d 20 58 35 30 39 5f 63 68 65 63 dret = X509_chec
14e0: 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 k_purpose(cert,
14f0: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 74 X509_PURPOSE_get
1500: 5f 69 64 28 70 74 6d 70 29 2c 20 6a 29 3b 0a 09 _id(ptmp), j);..
1510: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
1520: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
1530: 65 72 70 2c 20 74 6d 70 50 74 72 2c 20 54 63 6c erp, tmpPtr, Tcl
1540: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 6a 20 _NewStringObj(j
1550: 3f 20 22 43 41 22 20 3a 20 22 6e 6f 6e 43 41 22 ? "CA" : "nonCA"
1560: 2c 20 2d 31 29 29 3b 0a 09 20 20 20 20 54 63 6c , -1));.. Tcl
1570: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
1580: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 74 6d ement(interp, tm
1590: 70 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 pPtr, Tcl_NewStr
15a0: 69 6e 67 4f 62 6a 28 69 64 72 65 74 20 3d 3d 20 ingObj(idret ==
15b0: 31 20 3f 20 22 59 65 73 22 20 3a 20 22 4e 6f 22 1 ? "Yes" : "No"
15c0: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 4c 41 50 50 , -1));..}..LAPP
15d0: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 END_OBJ(interp,
15e0: 6c 69 73 74 50 74 72 2c 20 58 35 30 39 5f 50 55 listPtr, X509_PU
15f0: 52 50 4f 53 45 5f 67 65 74 30 5f 6e 61 6d 65 28 RPOSE_get0_name(
1600: 70 74 6d 70 29 2c 20 74 6d 70 50 74 72 29 3b 0a ptmp), tmpPtr);.
1610: 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e }. return
1620: 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a listPtr;.}../*.
1630: 20 2a 20 47 65 74 20 53 75 62 6a 65 63 74 20 41 * Get Subject A
1640: 6c 74 65 72 6e 61 74 65 20 4e 61 6d 65 73 20 28 lternate Names (
1650: 53 41 4e 29 20 61 6e 64 20 49 73 73 75 65 72 20 SAN) and Issuer
1660: 41 6c 74 65 72 6e 61 74 65 20 4e 61 6d 65 73 0a Alternate Names.
1670: 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 */.Tcl_Obj *Tls
1680: 5f 78 35 30 39 4e 61 6d 65 73 28 54 63 6c 5f 49 _x509Names(Tcl_I
1690: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 nterp *interp, X
16a0: 35 30 39 20 2a 63 65 72 74 2c 20 69 6e 74 20 6e 509 *cert, int n
16b0: 69 64 2c 20 42 49 4f 20 2a 62 69 6f 29 20 7b 0a id, BIO *bio) {.
16c0: 20 20 20 20 53 54 41 43 4b 5f 4f 46 28 47 45 4e STACK_OF(GEN
16d0: 45 52 41 4c 5f 4e 41 4d 45 29 20 2a 6e 61 6d 65 ERAL_NAME) *name
16e0: 73 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a s;. Tcl_Obj *
16f0: 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 listPtr = Tcl_Ne
1700: 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c wListObj(0, NULL
1710: 29 3b 0a 20 20 20 20 69 6e 74 20 6c 65 6e 3b 0a );. int len;.
1720: 20 20 20 20 63 68 61 72 20 62 75 66 66 65 72 5b char buffer[
1730: 31 30 32 34 5d 3b 0a 0a 20 20 20 20 69 66 20 28 1024];.. if (
1740: 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 listPtr == NULL)
1750: 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b {..return NULL;
1760: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 . }.. if (
1770: 6e 61 6d 65 73 20 3d 20 58 35 30 39 5f 67 65 74 names = X509_get
1780: 5f 65 78 74 5f 64 32 69 28 63 65 72 74 2c 20 6e _ext_d2i(cert, n
1790: 69 64 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 29 id, NULL, NULL))
17a0: 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 3d 30 {..for (int i=0
17b0: 3b 20 69 20 3c 20 73 6b 5f 47 45 4e 45 52 41 4c ; i < sk_GENERAL
17c0: 5f 4e 41 4d 45 5f 6e 75 6d 28 6e 61 6d 65 73 29 _NAME_num(names)
17d0: 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20 63 6f ; i++) {.. co
17e0: 6e 73 74 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 nst GENERAL_NAME
17f0: 20 2a 6e 61 6d 65 20 3d 20 73 6b 5f 47 45 4e 45 *name = sk_GENE
1800: 52 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75 65 28 6e RAL_NAME_value(n
1810: 61 6d 65 73 2c 20 69 29 3b 0a 0a 09 20 20 20 20 ames, i);...
1820: 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 len = BIO_to_Buf
1830: 66 65 72 28 6e 61 6d 65 20 26 26 20 47 45 4e 45 fer(name && GENE
1840: 52 41 4c 5f 4e 41 4d 45 5f 70 72 69 6e 74 28 62 RAL_NAME_print(b
1850: 69 6f 2c 20 6e 61 6d 65 29 2c 20 62 69 6f 2c 20 io, name), bio,
1860: 62 75 66 66 65 72 2c 20 31 30 32 34 29 3b 0a 09 buffer, 1024);..
1870: 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 LAPPEND_STR(
1880: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
1890: 20 4e 55 4c 4c 2c 20 62 75 66 66 65 72 2c 20 28 NULL, buffer, (
18a0: 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a Tcl_Size) len);.
18b0: 09 7d 0a 09 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e .}..sk_GENERAL_N
18c0: 41 4d 45 5f 70 6f 70 5f 66 72 65 65 28 6e 61 6d AME_pop_free(nam
18d0: 65 73 2c 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 es, GENERAL_NAME
18e0: 5f 66 72 65 65 29 3b 0a 20 20 20 20 7d 0a 20 20 _free);. }.
18f0: 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 return listPtr
1900: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 45 ;.}../*. * Get E
1910: 58 74 65 6e 64 65 64 20 4b 65 79 20 55 73 61 67 Xtended Key Usag
1920: 65 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 e. */.Tcl_Obj *T
1930: 6c 73 5f 78 35 30 39 45 78 74 4b 65 79 55 73 61 ls_x509ExtKeyUsa
1940: 67 65 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 ge(Tcl_Interp *i
1950: 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 nterp, X509 *cer
1960: 74 2c 20 75 69 6e 74 33 32 5f 74 20 78 66 6c 61 t, uint32_t xfla
1970: 67 73 29 20 7b 0a 20 20 20 20 75 69 6e 74 33 32 gs) {. uint32
1980: 5f 74 20 75 73 61 67 65 20 3d 20 58 35 30 39 5f _t usage = X509_
1990: 67 65 74 5f 6b 65 79 5f 75 73 61 67 65 28 63 65 get_key_usage(ce
19a0: 72 74 29 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a rt);. Tcl_Obj
19b0: 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f *listPtr = Tcl_
19c0: 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 NewListObj(0, NU
19d0: 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 LL);.. if (li
19e0: 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b stPtr == NULL) {
19f0: 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 ..return NULL;.
1a00: 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 28 78 }.. if ((x
1a10: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 58 flags & EXFLAG_X
1a20: 4b 55 53 41 47 45 29 20 26 26 20 75 73 61 67 65 KUSAGE) && usage
1a30: 20 3c 20 55 49 4e 54 33 32 5f 4d 41 58 29 20 7b < UINT32_MAX) {
1a40: 0a 09 75 73 61 67 65 20 3d 20 58 35 30 39 5f 67 ..usage = X509_g
1a50: 65 74 5f 65 78 74 65 6e 64 65 64 5f 6b 65 79 5f et_extended_key_
1a60: 75 73 61 67 65 28 63 65 72 74 29 3b 0a 0a 09 69 usage(cert);...i
1a70: 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 53 f (usage & XKU_S
1a80: 53 4c 5f 53 45 52 56 45 52 29 20 7b 0a 09 20 20 SL_SERVER) {..
1a90: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
1aa0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
1ab0: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f p, listPtr, Tcl_
1ac0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 54 4c NewStringObj("TL
1ad0: 53 20 57 65 62 20 53 65 72 76 65 72 20 41 75 74 S Web Server Aut
1ae0: 68 65 6e 74 69 63 61 74 69 6f 6e 22 2c 20 2d 31 hentication", -1
1af0: 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 ));..}..if (usag
1b00: 65 20 26 20 58 4b 55 5f 53 53 4c 5f 43 4c 49 45 e & XKU_SSL_CLIE
1b10: 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c NT) {.. Tcl_L
1b20: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d istObjAppendElem
1b30: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 ent(interp, list
1b40: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 Ptr, Tcl_NewStri
1b50: 6e 67 4f 62 6a 28 22 54 4c 53 20 57 65 62 20 43 ngObj("TLS Web C
1b60: 6c 69 65 6e 74 20 41 75 74 68 65 6e 74 69 63 61 lient Authentica
1b70: 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a tion", -1));..}.
1b80: 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 .if (usage & XKU
1b90: 5f 53 4d 49 4d 45 29 20 7b 0a 09 20 20 20 20 54 _SMIME) {.. T
1ba0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
1bb0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
1bc0: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
1bd0: 53 74 72 69 6e 67 4f 62 6a 28 22 45 2d 6d 61 69 StringObj("E-mai
1be0: 6c 20 50 72 6f 74 65 63 74 69 6f 6e 22 2c 20 2d l Protection", -
1bf0: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 1));..}..if (usa
1c00: 67 65 20 26 20 58 4b 55 5f 43 4f 44 45 5f 53 49 ge & XKU_CODE_SI
1c10: 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c GN) {.. Tcl_L
1c20: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d istObjAppendElem
1c30: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 ent(interp, list
1c40: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 Ptr, Tcl_NewStri
1c50: 6e 67 4f 62 6a 28 22 43 6f 64 65 20 53 69 67 6e ngObj("Code Sign
1c60: 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 ing", -1));..}..
1c70: 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f if (usage & XKU_
1c80: 53 47 43 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f SGC) {.. Tcl_
1c90: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
1ca0: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 ment(interp, lis
1cb0: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 tPtr, Tcl_NewStr
1cc0: 69 6e 67 4f 62 6a 28 22 53 47 43 22 2c 20 2d 31 ingObj("SGC", -1
1cd0: 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 ));..}..if (usag
1ce0: 65 20 26 20 58 4b 55 5f 4f 43 53 50 5f 53 49 47 e & XKU_OCSP_SIG
1cf0: 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 N) {.. Tcl_Li
1d00: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 stObjAppendEleme
1d10: 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 nt(interp, listP
1d20: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e tr, Tcl_NewStrin
1d30: 67 4f 62 6a 28 22 4f 43 53 50 20 53 69 67 6e 69 gObj("OCSP Signi
1d40: 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 ng", -1));..}..i
1d50: 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 54 f (usage & XKU_T
1d60: 49 4d 45 53 54 41 4d 50 29 20 7b 0a 09 20 20 20 IMESTAMP) {..
1d70: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 Tcl_ListObjAppe
1d80: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 ndElement(interp
1d90: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e , listPtr, Tcl_N
1da0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 54 69 6d ewStringObj("Tim
1db0: 65 20 53 74 61 6d 70 69 6e 67 22 2c 20 2d 31 29 e Stamping", -1)
1dc0: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 );..}..if (usage
1dd0: 20 26 20 58 4b 55 5f 44 56 43 53 20 29 20 7b 0a & XKU_DVCS ) {.
1de0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
1df0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
1e00: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 terp, listPtr, T
1e10: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
1e20: 22 44 56 43 53 22 2c 20 2d 31 29 29 3b 0a 09 7d "DVCS", -1));..}
1e30: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b ..if (usage & XK
1e40: 55 5f 41 4e 59 45 4b 55 29 20 7b 0a 09 20 20 20 U_ANYEKU) {..
1e50: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 Tcl_ListObjAppe
1e60: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 ndElement(interp
1e70: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e , listPtr, Tcl_N
1e80: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 41 6e 79 ewStringObj("Any
1e90: 20 45 78 74 65 6e 64 65 64 20 4b 65 79 20 55 73 Extended Key Us
1ea0: 61 67 65 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 age", -1));..}.
1eb0: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 } else {..
1ec0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 Tcl_ListObjAppe
1ed0: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 ndElement(interp
1ee0: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e , listPtr, Tcl_N
1ef0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 75 6e 72 ewStringObj("unr
1f00: 65 73 74 72 69 63 74 65 64 22 2c 20 2d 31 29 29 estricted", -1))
1f10: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 ;. }. retu
1f20: 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f rn listPtr;.}../
1f30: 2a 0a 20 2a 20 47 65 74 20 43 52 4c 20 44 69 73 *. * Get CRL Dis
1f40: 74 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e 74 73 tribution Points
1f50: 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c . */.Tcl_Obj *Tl
1f60: 73 5f 78 35 30 39 43 72 6c 44 70 28 54 63 6c 5f s_x509CrlDp(Tcl_
1f70: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 Interp *interp,
1f80: 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 X509 *cert) {.
1f90: 20 20 53 54 41 43 4b 5f 4f 46 28 44 49 53 54 5f STACK_OF(DIST_
1fa0: 50 4f 49 4e 54 29 20 2a 63 72 6c 3b 0a 20 20 20 POINT) *crl;.
1fb0: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 Tcl_Obj *listPt
1fc0: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f r = Tcl_NewListO
1fd0: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 bj(0, NULL);..
1fe0: 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d if (listPtr ==
1ff0: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e NULL) {..return
2000: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 NULL;. }..
2010: 20 20 69 66 20 28 63 72 6c 20 3d 20 58 35 30 39 if (crl = X509
2020: 5f 67 65 74 5f 65 78 74 5f 64 32 69 28 63 65 72 _get_ext_d2i(cer
2030: 74 2c 20 4e 49 44 5f 63 72 6c 5f 64 69 73 74 72 t, NID_crl_distr
2040: 69 62 75 74 69 6f 6e 5f 70 6f 69 6e 74 73 2c 20 ibution_points,
2050: 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 29 20 7b 0a 09 NULL, NULL)) {..
2060: 66 6f 72 20 28 69 6e 74 20 69 3d 30 3b 20 69 20 for (int i=0; i
2070: 3c 20 73 6b 5f 44 49 53 54 5f 50 4f 49 4e 54 5f < sk_DIST_POINT_
2080: 6e 75 6d 28 63 72 6c 29 3b 20 69 2b 2b 29 20 7b num(crl); i++) {
2090: 0a 09 20 20 20 20 44 49 53 54 5f 50 4f 49 4e 54 .. DIST_POINT
20a0: 20 2a 64 70 20 3d 20 73 6b 5f 44 49 53 54 5f 50 *dp = sk_DIST_P
20b0: 4f 49 4e 54 5f 76 61 6c 75 65 28 63 72 6c 2c 20 OINT_value(crl,
20c0: 69 29 3b 0a 09 20 20 20 20 44 49 53 54 5f 50 4f i);.. DIST_PO
20d0: 49 4e 54 5f 4e 41 4d 45 20 2a 64 69 73 74 70 6f INT_NAME *distpo
20e0: 69 6e 74 20 3d 20 64 70 2d 3e 64 69 73 74 70 6f int = dp->distpo
20f0: 69 6e 74 3b 0a 0a 09 20 20 20 20 69 66 20 28 64 int;... if (d
2100: 69 73 74 70 6f 69 6e 74 2d 3e 74 79 70 65 20 3d istpoint->type =
2110: 3d 20 30 29 20 7b 0a 09 09 2f 2a 20 66 75 6c 6c = 0) {.../* full
2120: 2d 6e 61 6d 65 20 47 45 4e 45 52 41 4c 49 5a 45 -name GENERALIZE
2130: 44 4e 41 4d 45 20 2a 2f 0a 09 09 66 6f 72 20 28 DNAME */...for (
2140: 69 6e 74 20 6a 20 3d 20 30 3b 20 6a 20 3c 20 73 int j = 0; j < s
2150: 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e k_GENERAL_NAME_n
2160: 75 6d 28 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 um(distpoint->na
2170: 6d 65 2e 66 75 6c 6c 6e 61 6d 65 29 3b 20 6a 2b me.fullname); j+
2180: 2b 29 20 7b 0a 09 09 20 20 20 20 47 45 4e 45 52 +) {... GENER
2190: 41 4c 5f 4e 41 4d 45 20 2a 67 65 6e 20 3d 20 73 AL_NAME *gen = s
21a0: 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 76 k_GENERAL_NAME_v
21b0: 61 6c 75 65 28 64 69 73 74 70 6f 69 6e 74 2d 3e alue(distpoint->
21c0: 6e 61 6d 65 2e 66 75 6c 6c 6e 61 6d 65 2c 20 6a name.fullname, j
21d0: 29 3b 0a 09 09 20 20 20 20 69 6e 74 20 74 79 70 );... int typ
21e0: 65 3b 0a 09 09 20 20 20 20 41 53 4e 31 5f 53 54 e;... ASN1_ST
21f0: 52 49 4e 47 20 2a 75 72 69 20 3d 20 47 45 4e 45 RING *uri = GENE
2200: 52 41 4c 5f 4e 41 4d 45 5f 67 65 74 30 5f 76 61 RAL_NAME_get0_va
2210: 6c 75 65 28 67 65 6e 2c 20 26 74 79 70 65 29 3b lue(gen, &type);
2220: 0a 09 09 20 20 20 20 69 66 20 28 74 79 70 65 20 ... if (type
2230: 3d 3d 20 47 45 4e 5f 55 52 49 29 20 7b 0a 09 09 == GEN_URI) {...
2240: 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 .LAPPEND_STR(int
2250: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 erp, listPtr, NU
2260: 4c 4c 2c 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f LL, ASN1_STRING_
2270: 67 65 74 30 5f 64 61 74 61 28 75 72 69 29 2c 20 get0_data(uri),
2280: 28 54 63 6c 5f 53 69 7a 65 29 20 41 53 4e 31 5f (Tcl_Size) ASN1_
2290: 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 75 72 STRING_length(ur
22a0: 69 29 29 3b 0a 09 09 20 20 20 20 7d 0a 09 09 7d i));... }...}
22b0: 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 .. } else if
22c0: 28 64 69 73 74 70 6f 69 6e 74 2d 3e 74 79 70 65 (distpoint->type
22d0: 20 3d 3d 20 31 29 20 7b 0a 09 09 2f 2a 20 72 65 == 1) {.../* re
22e0: 6c 61 74 69 76 65 2d 6e 61 6d 65 20 58 35 30 39 lative-name X509
22f0: 4e 41 4d 45 20 2a 2f 0a 09 09 53 54 41 43 4b 5f NAME */...STACK_
2300: 4f 46 28 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 OF(X509_NAME_ENT
2310: 52 59 29 20 2a 73 6b 5f 72 65 6c 6e 61 6d 65 20 RY) *sk_relname
2320: 3d 20 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d = distpoint->nam
2330: 65 2e 72 65 6c 61 74 69 76 65 6e 61 6d 65 3b 0a e.relativename;.
2340: 09 09 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 ..for (int j = 0
2350: 3b 20 6a 20 3c 20 73 6b 5f 58 35 30 39 5f 4e 41 ; j < sk_X509_NA
2360: 4d 45 5f 45 4e 54 52 59 5f 6e 75 6d 28 73 6b 5f ME_ENTRY_num(sk_
2370: 72 65 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20 7b relname); j++) {
2380: 0a 09 09 20 20 20 20 58 35 30 39 5f 4e 41 4d 45 ... X509_NAME
2390: 5f 45 4e 54 52 59 20 2a 65 20 3d 20 73 6b 5f 58 _ENTRY *e = sk_X
23a0: 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 76 509_NAME_ENTRY_v
23b0: 61 6c 75 65 28 73 6b 5f 72 65 6c 6e 61 6d 65 2c alue(sk_relname,
23c0: 20 6a 29 3b 0a 09 09 20 20 20 20 41 53 4e 31 5f j);... ASN1_
23d0: 53 54 52 49 4e 47 20 2a 64 20 3d 20 58 35 30 39 STRING *d = X509
23e0: 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 67 65 74 5f _NAME_ENTRY_get_
23f0: 64 61 74 61 28 65 29 3b 0a 09 09 20 20 20 20 4c data(e);... L
2400: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 APPEND_STR(inter
2410: 70 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 4c 4c p, listPtr, NULL
2420: 2c 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 64 61 , ASN1_STRING_da
2430: 74 61 28 64 29 2c 20 28 54 63 6c 5f 53 69 7a 65 ta(d), (Tcl_Size
2440: 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 6c 65 ) ASN1_STRING_le
2450: 6e 67 74 68 28 64 29 29 3b 0a 09 09 7d 0a 09 20 ngth(d));...}..
2460: 20 20 20 7d 0a 09 7d 0a 09 43 52 4c 5f 44 49 53 }..}..CRL_DIS
2470: 54 5f 50 4f 49 4e 54 53 5f 66 72 65 65 28 63 72 T_POINTS_free(cr
2480: 6c 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 l);. }. re
2490: 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a turn listPtr;.}.
24a0: 0a 2f 2a 0a 20 2a 20 47 65 74 20 4f 6e 2d 6c 69 ./*. * Get On-li
24b0: 6e 65 20 43 65 72 74 69 66 69 63 61 74 65 20 53 ne Certificate S
24c0: 74 61 74 75 73 20 50 72 6f 74 6f 63 6f 6c 20 28 tatus Protocol (
24d0: 4f 53 43 50 29 20 55 52 4c 0a 20 2a 2f 0a 54 63 OSCP) URL. */.Tc
24e0: 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4f l_Obj *Tls_x509O
24f0: 73 63 70 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a scp(Tcl_Interp *
2500: 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 interp, X509 *ce
2510: 72 74 29 20 7b 0a 20 20 20 20 53 54 41 43 4b 5f rt) {. STACK_
2520: 4f 46 28 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e OF(OPENSSL_STRIN
2530: 47 29 20 2a 6f 63 73 70 3b 0a 20 20 20 20 54 63 G) *ocsp;. Tc
2540: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d l_Obj *listPtr =
2550: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 Tcl_NewListObj(
2560: 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 0, NULL);.. i
2570: 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 f (listPtr == NU
2580: 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 LL) {..return NU
2590: 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 LL;. }.. i
25a0: 66 20 28 6f 63 73 70 20 3d 20 58 35 30 39 5f 67 f (ocsp = X509_g
25b0: 65 74 31 5f 6f 63 73 70 28 63 65 72 74 29 29 20 et1_ocsp(cert))
25c0: 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 20 3d 20 {..for (int i =
25d0: 30 3b 20 69 20 3c 20 73 6b 5f 4f 50 45 4e 53 53 0; i < sk_OPENSS
25e0: 4c 5f 53 54 52 49 4e 47 5f 6e 75 6d 28 6f 63 73 L_STRING_num(ocs
25f0: 70 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20 p); i++) {..
2600: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
2610: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 4c rp, listPtr, NUL
2620: 4c 2c 20 73 6b 5f 4f 50 45 4e 53 53 4c 5f 53 54 L, sk_OPENSSL_ST
2630: 52 49 4e 47 5f 76 61 6c 75 65 28 6f 63 73 70 2c RING_value(ocsp,
2640: 20 69 29 2c 20 2d 31 29 3b 0a 09 7d 0a 09 58 35 i), -1);..}..X5
2650: 30 39 5f 65 6d 61 69 6c 5f 66 72 65 65 28 6f 63 09_email_free(oc
2660: 73 70 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 sp);. }. r
2670: 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d eturn listPtr;.}
2680: 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 65 72 74 ../*. * Get Cert
2690: 69 66 69 63 61 74 65 20 41 75 74 68 6f 72 69 74 ificate Authorit
26a0: 79 20 28 43 41 29 20 49 73 73 75 65 72 73 20 55 y (CA) Issuers U
26b0: 52 4c 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a RL. */.Tcl_Obj *
26c0: 54 6c 73 5f 78 35 30 39 43 61 49 73 73 75 65 72 Tls_x509CaIssuer
26d0: 73 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e s(Tcl_Interp *in
26e0: 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74 terp, X509 *cert
26f0: 29 20 7b 0a 20 20 20 20 53 54 41 43 4b 5f 4f 46 ) {. STACK_OF
2700: 28 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 (ACCESS_DESCRIPT
2710: 49 4f 4e 29 20 2a 61 64 73 3b 0a 20 20 20 20 41 ION) *ads;. A
2720: 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f CCESS_DESCRIPTIO
2730: 4e 20 2a 61 64 3b 0a 20 20 20 20 54 63 6c 5f 4f N *ad;. Tcl_O
2740: 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 63 bj *listPtr = Tc
2750: 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 l_NewListObj(0,
2760: 4e 55 4c 4c 29 3b 0a 20 20 20 20 75 6e 73 69 67 NULL);. unsig
2770: 6e 65 64 20 63 68 61 72 20 2a 62 75 66 3b 0a 20 ned char *buf;.
2780: 20 20 20 69 6e 74 20 6c 65 6e 3b 0a 0a 20 20 20 int len;..
2790: 20 69 66 20 28 61 64 73 20 3d 20 58 35 30 39 5f if (ads = X509_
27a0: 67 65 74 5f 65 78 74 5f 64 32 69 28 63 65 72 74 get_ext_d2i(cert
27b0: 2c 20 4e 49 44 5f 69 6e 66 6f 5f 61 63 63 65 73 , NID_info_acces
27c0: 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 29 20 s, NULL, NULL))
27d0: 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 20 3d 20 {..for (int i =
27e0: 30 3b 20 69 20 3c 20 73 6b 5f 41 43 43 45 53 53 0; i < sk_ACCESS
27f0: 5f 44 45 53 43 52 49 50 54 49 4f 4e 5f 6e 75 6d _DESCRIPTION_num
2800: 28 61 64 73 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 (ads); i++) {..
2810: 20 20 20 61 64 20 3d 20 73 6b 5f 41 43 43 45 53 ad = sk_ACCES
2820: 53 5f 44 45 53 43 52 49 50 54 49 4f 4e 5f 76 61 S_DESCRIPTION_va
2830: 6c 75 65 28 61 64 73 2c 20 69 29 3b 0a 09 20 20 lue(ads, i);..
2840: 20 20 69 66 20 28 4f 42 4a 5f 6f 62 6a 32 6e 69 if (OBJ_obj2ni
2850: 64 28 61 64 2d 3e 6d 65 74 68 6f 64 29 20 3d 3d d(ad->method) ==
2860: 20 4e 49 44 5f 61 64 5f 63 61 5f 69 73 73 75 65 NID_ad_ca_issue
2870: 72 73 20 26 26 20 61 64 2d 3e 6c 6f 63 61 74 69 rs && ad->locati
2880: 6f 6e 29 20 7b 0a 09 09 69 66 20 28 61 64 2d 3e on) {...if (ad->
2890: 6c 6f 63 61 74 69 6f 6e 2d 3e 74 79 70 65 20 3d location->type =
28a0: 3d 20 47 45 4e 5f 55 52 49 29 20 7b 0a 09 09 20 = GEN_URI) {...
28b0: 20 20 20 6c 65 6e 20 3d 20 41 53 4e 31 5f 53 54 len = ASN1_ST
28c0: 52 49 4e 47 5f 74 6f 5f 55 54 46 38 28 26 62 75 RING_to_UTF8(&bu
28d0: 66 2c 20 61 64 2d 3e 6c 6f 63 61 74 69 6f 6e 2d f, ad->location-
28e0: 3e 64 2e 75 6e 69 66 6f 72 6d 52 65 73 6f 75 72 >d.uniformResour
28f0: 63 65 49 64 65 6e 74 69 66 69 65 72 29 3b 0a 09 ceIdentifier);..
2900: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
2910: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
2920: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 terp, listPtr, T
2930: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
2940: 62 75 66 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 buf, (Tcl_Size)
2950: 6c 65 6e 29 29 3b 0a 09 09 20 20 20 20 4f 50 45 len));... OPE
2960: 4e 53 53 4c 5f 66 72 65 65 28 62 75 66 29 3b 0a NSSL_free(buf);.
2970: 09 09 20 20 20 20 62 72 65 61 6b 3b 0a 09 09 7d .. break;...}
2980: 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 2f 2a 20 73 .. }..}../* s
2990: 6b 5f 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 k_ACCESS_DESCRIP
29a0: 54 49 4f 4e 5f 70 6f 70 5f 66 72 65 65 28 61 64 TION_pop_free(ad
29b0: 73 2c 20 41 43 43 45 53 53 5f 44 45 53 43 52 49 s, ACCESS_DESCRI
29c0: 50 54 49 4f 4e 5f 66 72 65 65 29 3b 20 2a 2f 0a PTION_free); */.
29d0: 09 41 55 54 48 4f 52 49 54 59 5f 49 4e 46 4f 5f .AUTHORITY_INFO_
29e0: 41 43 43 45 53 53 5f 66 72 65 65 28 61 64 73 29 ACCESS_free(ads)
29f0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 ;. }. retu
2a00: 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0c 0a rn listPtr;.}...
2a10: 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d /*. *-----------
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 2a 0a 20 2a 0a -----------*. *.
2a50: 20 2a 09 54 6c 73 5f 4e 65 77 58 35 30 39 4f 62 *.Tls_NewX509Ob
2a60: 6a 20 2d 2d 0a 20 2a 0a 20 2a 09 2d 2d 2d 2d 2d j --. *. *.-----
2a70: 2d 2d 2d 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 2a 0a 20 2a 09 -----------*. *.
2aa0: 43 6f 6e 76 65 72 74 73 20 61 20 58 35 30 39 20 Converts a X509
2ab0: 63 65 72 74 69 66 69 63 61 74 65 20 69 6e 74 6f certificate into
2ac0: 20 61 20 54 63 6c 5f 4f 62 6a 0a 20 2a 09 2d 2d a Tcl_Obj. *.--
2ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
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 2a 0a --------------*.
2b00: 20 2a 0a 20 2a 09 53 69 64 65 20 65 66 66 65 63 *. *.Side effec
2b10: 74 73 3a 0a 20 2a 09 09 4e 6f 6e 65 0a 20 2a 0a ts:. *..None. *.
2b20: 20 2a 09 52 65 73 75 6c 74 3a 0a 20 2a 09 09 41 *.Result:. *..A
2b30: 20 54 63 6c 20 4c 69 73 74 20 4f 62 6a 65 63 74 Tcl List Object
2b40: 20 72 65 70 72 65 73 65 6e 74 69 6e 67 20 74 68 representing th
2b50: 65 20 70 72 6f 76 69 64 65 64 0a 20 2a 09 09 58 e provided. *..X
2b60: 35 30 39 20 63 65 72 74 69 66 69 63 61 74 65 2e 509 certificate.
2b70: 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d . *. *----------
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 2a 0a 20 2a ------------*. *
2bb0: 2f 0a 0a 54 63 6c 5f 4f 62 6a 2a 0a 54 6c 73 5f /..Tcl_Obj*.Tls_
2bc0: 4e 65 77 58 35 30 39 4f 62 6a 28 54 63 6c 5f 49 NewX509Obj(Tcl_I
2bd0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 nterp *interp, X
2be0: 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 509 *cert) {.
2bf0: 20 54 63 6c 5f 4f 62 6a 20 2a 63 65 72 74 50 74 Tcl_Obj *certPt
2c00: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f r = Tcl_NewListO
2c10: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 bj(0, NULL);.
2c20: 20 42 49 4f 20 2a 62 69 6f 20 3d 20 42 49 4f 5f BIO *bio = BIO_
2c30: 6e 65 77 28 42 49 4f 5f 73 5f 6d 65 6d 28 29 29 new(BIO_s_mem())
2c40: 3b 0a 20 20 20 20 69 6e 74 20 6d 64 6e 69 64 2c ;. int mdnid,
2c50: 20 70 6b 6e 69 64 2c 20 62 69 74 73 2c 20 6c 65 pknid, bits, le
2c60: 6e 3b 0a 20 20 20 20 75 69 6e 74 33 32 5f 74 20 n;. uint32_t
2c70: 78 66 6c 61 67 73 3b 0a 20 20 20 20 63 68 61 72 xflags;. char
2c80: 20 62 75 66 66 65 72 5b 42 55 46 53 49 5a 5d 3b buffer[BUFSIZ];
2c90: 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 63 68 . unsigned ch
2ca0: 61 72 20 6d 64 5b 45 56 50 5f 4d 41 58 5f 4d 44 ar md[EVP_MAX_MD
2cb0: 5f 53 49 5a 45 5d 3b 0a 20 20 20 20 75 6e 73 69 _SIZE];. unsi
2cc0: 67 6e 65 64 20 6c 6f 6e 67 20 66 6c 61 67 73 20 gned long flags
2cd0: 3d 20 58 4e 5f 46 4c 41 47 5f 52 46 43 32 32 35 = XN_FLAG_RFC225
2ce0: 33 20 7c 20 41 53 4e 31 5f 53 54 52 46 4c 47 53 3 | ASN1_STRFLGS
2cf0: 5f 55 54 46 38 5f 43 4f 4e 56 45 52 54 3b 0a 20 _UTF8_CONVERT;.
2d00: 20 20 20 66 6c 61 67 73 20 26 3d 20 7e 41 53 4e flags &= ~ASN
2d10: 31 5f 53 54 52 46 4c 47 53 5f 45 53 43 5f 4d 53 1_STRFLGS_ESC_MS
2d20: 42 3b 0a 0a 20 20 20 20 69 66 20 28 69 6e 74 65 B;.. if (inte
2d30: 72 70 20 3d 3d 20 4e 55 4c 4c 20 7c 7c 20 63 65 rp == NULL || ce
2d40: 72 74 20 3d 3d 20 4e 55 4c 4c 20 7c 7c 20 62 69 rt == NULL || bi
2d50: 6f 20 3d 3d 20 4e 55 4c 4c 20 7c 7c 20 63 65 72 o == NULL || cer
2d60: 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a tPtr == NULL) {.
2d70: 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 .return NULL;.
2d80: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 69 67 6e }.. /* Sign
2d90: 61 74 75 72 65 20 61 6c 67 6f 72 69 74 68 6d 20 ature algorithm
2da0: 61 6e 64 20 76 61 6c 75 65 20 2d 20 52 46 43 20 and value - RFC
2db0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 5280 section 4.1
2dc0: 2e 31 2e 32 20 61 6e 64 20 34 2e 31 2e 31 2e 33 .1.2 and 4.1.1.3
2dd0: 20 2a 2f 0a 20 20 20 20 2f 2a 20 73 69 67 6e 61 */. /* signa
2de0: 74 75 72 65 41 6c 67 6f 72 69 74 68 6d 20 69 73 tureAlgorithm is
2df0: 20 74 68 65 20 69 64 20 6f 66 20 74 68 65 20 63 the id of the c
2e00: 72 79 70 74 6f 67 72 61 70 68 69 63 20 61 6c 67 ryptographic alg
2e10: 6f 72 69 74 68 6d 20 75 73 65 64 20 62 79 20 74 orithm used by t
2e20: 68 65 0a 09 43 41 20 74 6f 20 73 69 67 6e 20 74 he..CA to sign t
2e30: 68 69 73 20 63 65 72 74 2e 20 73 69 67 6e 61 74 his cert. signat
2e40: 75 72 65 56 61 6c 75 65 20 69 73 20 74 68 65 20 ureValue is the
2e50: 64 69 67 69 74 61 6c 20 73 69 67 6e 61 74 75 72 digital signatur
2e60: 65 20 63 6f 6d 70 75 74 65 64 0a 09 75 70 6f 6e e computed..upon
2e70: 20 74 68 65 20 41 53 4e 2e 31 20 44 45 52 20 65 the ASN.1 DER e
2e80: 6e 63 6f 64 65 64 20 74 62 73 43 65 72 74 69 66 ncoded tbsCertif
2e90: 69 63 61 74 65 2e 20 2a 2f 0a 20 20 20 20 7b 0a icate. */. {.
2ea0: 09 63 6f 6e 73 74 20 58 35 30 39 5f 41 4c 47 4f .const X509_ALGO
2eb0: 52 20 2a 73 69 67 5f 61 6c 67 3b 0a 09 63 6f 6e R *sig_alg;..con
2ec0: 73 74 20 41 53 4e 31 5f 42 49 54 5f 53 54 52 49 st ASN1_BIT_STRI
2ed0: 4e 47 20 2a 73 69 67 3b 0a 09 69 6e 74 20 73 69 NG *sig;..int si
2ee0: 67 5f 6e 69 64 3b 0a 0a 09 58 35 30 39 5f 67 65 g_nid;...X509_ge
2ef0: 74 30 5f 73 69 67 6e 61 74 75 72 65 28 26 73 69 t0_signature(&si
2f00: 67 2c 20 26 73 69 67 5f 61 6c 67 2c 20 63 65 72 g, &sig_alg, cer
2f10: 74 29 3b 0a 09 2f 2a 20 73 69 67 5f 6e 69 64 20 t);../* sig_nid
2f20: 3d 20 58 35 30 39 5f 67 65 74 5f 73 69 67 6e 61 = X509_get_signa
2f30: 74 75 72 65 5f 6e 69 64 28 63 65 72 74 29 20 2a ture_nid(cert) *
2f40: 2f 0a 09 73 69 67 5f 6e 69 64 20 3d 20 4f 42 4a /..sig_nid = OBJ
2f50: 5f 6f 62 6a 32 6e 69 64 28 73 69 67 5f 61 6c 67 _obj2nid(sig_alg
2f60: 2d 3e 61 6c 67 6f 72 69 74 68 6d 29 3b 0a 09 4c ->algorithm);..L
2f70: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 APPEND_STR(inter
2f80: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 67 p, certPtr, "sig
2f90: 6e 61 74 75 72 65 41 6c 67 6f 72 69 74 68 6d 22 natureAlgorithm"
2fa0: 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 73 69 67 , OBJ_nid2ln(sig
2fb0: 5f 6e 69 64 29 2c 20 2d 31 29 3b 0a 09 6c 65 6e _nid), -1);..len
2fc0: 20 3d 20 28 73 69 67 5f 6e 69 64 20 21 3d 20 4e = (sig_nid != N
2fd0: 49 44 5f 75 6e 64 65 66 29 20 3f 20 53 74 72 69 ID_undef) ? Stri
2fe0: 6e 67 5f 74 6f 5f 48 65 78 28 73 69 67 2d 3e 64 ng_to_Hex(sig->d
2ff0: 61 74 61 2c 20 73 69 67 2d 3e 6c 65 6e 67 74 68 ata, sig->length
3000: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a , buffer, BUFSIZ
3010: 29 20 3a 20 30 3b 0a 09 4c 41 50 50 45 4e 44 5f ) : 0;..LAPPEND_
3020: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 STR(interp, cert
3030: 50 74 72 2c 20 22 73 69 67 6e 61 74 75 72 65 56 Ptr, "signatureV
3040: 61 6c 75 65 22 2c 20 62 75 66 66 65 72 2c 20 28 alue", buffer, (
3050: 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a Tcl_Size) len);.
3060: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 56 65 }.. /* Ve
3070: 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 65 6e 63 rsion of the enc
3080: 6f 64 65 64 20 63 65 72 74 69 66 69 63 61 74 65 oded certificate
3090: 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74 - RFC 5280 sect
30a0: 69 6f 6e 20 34 2e 31 2e 32 2e 31 20 2a 2f 0a 20 ion 4.1.2.1 */.
30b0: 20 20 20 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 28 LAPPEND_LONG(
30c0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
30d0: 20 22 76 65 72 73 69 6f 6e 22 2c 20 58 35 30 39 "version", X509
30e0: 5f 67 65 74 5f 76 65 72 73 69 6f 6e 28 63 65 72 _get_version(cer
30f0: 74 29 2b 31 29 3b 0a 0a 20 20 20 20 2f 2a 20 55 t)+1);.. /* U
3100: 6e 69 71 75 65 20 6e 75 6d 62 65 72 20 61 73 73 nique number ass
3110: 69 67 6e 65 64 20 62 79 20 43 41 20 74 6f 20 63 igned by CA to c
3120: 65 72 74 69 66 69 63 61 74 65 20 2d 20 52 46 43 ertificate - RFC
3130: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 5280 section 4.
3140: 31 2e 32 2e 32 20 2a 2f 0a 20 20 20 20 6c 65 6e 1.2.2 */. len
3150: 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 = BIO_to_Buffer
3160: 28 69 32 61 5f 41 53 4e 31 5f 49 4e 54 45 47 45 (i2a_ASN1_INTEGE
3170: 52 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30 R(bio, X509_get0
3180: 5f 73 65 72 69 61 6c 4e 75 6d 62 65 72 28 63 65 _serialNumber(ce
3190: 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 rt)), bio, buffe
31a0: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 20 r, BUFSIZ);.
31b0: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
31c0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65 rp, certPtr, "se
31d0: 72 69 61 6c 4e 75 6d 62 65 72 22 2c 20 62 75 66 rialNumber", buf
31e0: 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 fer, (Tcl_Size)
31f0: 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 69 len);.. /* Si
3200: 67 6e 61 74 75 72 65 20 61 6c 67 6f 72 69 74 68 gnature algorith
3210: 6d 20 75 73 65 64 20 62 79 20 74 68 65 20 43 41 m used by the CA
3220: 20 74 6f 20 73 69 67 6e 20 74 68 65 20 63 65 72 to sign the cer
3230: 74 69 66 69 63 61 74 65 2e 20 4d 75 73 74 20 6d tificate. Must m
3240: 61 74 63 68 0a 09 73 69 67 6e 61 74 75 72 65 41 atch..signatureA
3250: 6c 67 6f 72 69 74 68 6d 2e 20 52 46 43 20 35 32 lgorithm. RFC 52
3260: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 80 section 4.1.2
3270: 2e 33 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e .3 */. LAPPEN
3280: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 D_STR(interp, ce
3290: 72 74 50 74 72 2c 20 22 73 69 67 6e 61 74 75 72 rtPtr, "signatur
32a0: 65 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 58 e", OBJ_nid2ln(X
32b0: 35 30 39 5f 67 65 74 5f 73 69 67 6e 61 74 75 72 509_get_signatur
32c0: 65 5f 6e 69 64 28 63 65 72 74 29 29 2c 20 2d 31 e_nid(cert)), -1
32d0: 29 3b 0a 0a 20 20 20 20 2f 2a 20 49 73 73 75 65 );.. /* Issue
32e0: 72 20 69 64 65 6e 74 69 66 69 65 73 20 74 68 65 r identifies the
32f0: 20 65 6e 74 69 74 79 20 74 68 61 74 20 73 69 67 entity that sig
3300: 6e 65 64 20 61 6e 64 20 69 73 73 75 65 64 20 74 ned and issued t
3310: 68 65 20 63 65 72 74 2e 20 52 46 43 20 35 32 38 he cert. RFC 528
3320: 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 0 section 4.1.2.
3330: 34 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 4 */. len = B
3340: 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 IO_to_Buffer(X50
3350: 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f 65 78 28 9_NAME_print_ex(
3360: 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 5f 69 73 bio, X509_get_is
3370: 73 75 65 72 5f 6e 61 6d 65 28 63 65 72 74 29 2c suer_name(cert),
3380: 20 30 2c 20 66 6c 61 67 73 29 2c 20 62 69 6f 2c 0, flags), bio,
3390: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 buffer, BUFSIZ)
33a0: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 ;. LAPPEND_ST
33b0: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 R(interp, certPt
33c0: 72 2c 20 22 69 73 73 75 65 72 22 2c 20 62 75 66 r, "issuer", buf
33d0: 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 fer, (Tcl_Size)
33e0: 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 65 len);.. /* Ce
33f0: 72 74 69 66 69 63 61 74 65 20 76 61 6c 69 64 69 rtificate validi
3400: 74 79 20 70 65 72 69 6f 64 20 69 73 20 74 68 65 ty period is the
3410: 20 69 6e 74 65 72 76 61 6c 20 74 68 65 20 43 41 interval the CA
3420: 20 77 61 72 72 61 6e 74 73 20 74 68 61 74 20 69 warrants that i
3430: 74 20 77 69 6c 6c 0a 09 6d 61 69 6e 74 61 69 6e t will..maintain
3440: 20 69 6e 66 6f 20 6f 6e 20 74 68 65 20 73 74 61 info on the sta
3450: 74 75 73 20 6f 66 20 74 68 65 20 63 65 72 74 69 tus of the certi
3460: 66 69 63 61 74 65 2e 20 52 46 43 20 35 32 38 30 ficate. RFC 5280
3470: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 35 section 4.1.2.5
3480: 20 2a 2f 0a 20 20 20 20 2f 2a 20 47 65 74 20 56 */. /* Get V
3490: 61 6c 69 64 69 74 79 20 2d 20 4e 6f 74 20 42 65 alidity - Not Be
34a0: 66 6f 72 65 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 fore */. len
34b0: 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 = BIO_to_Buffer(
34c0: 41 53 4e 31 5f 54 49 4d 45 5f 70 72 69 6e 74 28 ASN1_TIME_print(
34d0: 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30 5f 6e bio, X509_get0_n
34e0: 6f 74 42 65 66 6f 72 65 28 63 65 72 74 29 29 2c otBefore(cert)),
34f0: 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 bio, buffer, BU
3500: 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 FSIZ);. LAPPE
3510: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 ND_STR(interp, c
3520: 65 72 74 50 74 72 2c 20 22 6e 6f 74 42 65 66 6f ertPtr, "notBefo
3530: 72 65 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 re", buffer, (Tc
3540: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 l_Size) len);..
3550: 20 20 20 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 /* Get Validi
3560: 74 79 20 2d 20 4e 6f 74 20 41 66 74 65 72 20 2a ty - Not After *
3570: 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f /. len = BIO_
3580: 74 6f 5f 42 75 66 66 65 72 28 41 53 4e 31 5f 54 to_Buffer(ASN1_T
3590: 49 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 IME_print(bio, X
35a0: 35 30 39 5f 67 65 74 30 5f 6e 6f 74 41 66 74 65 509_get0_notAfte
35b0: 72 28 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 r(cert)), bio, b
35c0: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a uffer, BUFSIZ);.
35d0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 LAPPEND_STR(
35e0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
35f0: 20 22 6e 6f 74 41 66 74 65 72 22 2c 20 62 75 66 "notAfter", buf
3600: 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 fer, (Tcl_Size)
3610: 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 75 len);.. /* Su
3620: 62 6a 65 63 74 20 69 64 65 6e 74 69 66 69 65 73 bject identifies
3630: 20 74 68 65 20 65 6e 74 69 74 79 20 61 73 73 6f the entity asso
3640: 63 69 61 74 65 64 20 77 69 74 68 20 74 68 65 20 ciated with the
3650: 70 75 62 6c 69 63 20 6b 65 79 20 73 74 6f 72 65 public key store
3660: 64 20 69 6e 0a 09 74 68 65 20 73 75 62 6a 65 63 d in..the subjec
3670: 74 20 70 75 62 6c 69 63 20 6b 65 79 20 66 69 65 t public key fie
3680: 6c 64 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 ld. RFC 5280 sec
3690: 74 69 6f 6e 20 34 2e 31 2e 32 2e 36 20 2a 2f 0a tion 4.1.2.6 */.
36a0: 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f len = BIO_to
36b0: 5f 42 75 66 66 65 72 28 58 35 30 39 5f 4e 41 4d _Buffer(X509_NAM
36c0: 45 5f 70 72 69 6e 74 5f 65 78 28 62 69 6f 2c 20 E_print_ex(bio,
36d0: 58 35 30 39 5f 67 65 74 5f 73 75 62 6a 65 63 74 X509_get_subject
36e0: 5f 6e 61 6d 65 28 63 65 72 74 29 2c 20 30 2c 20 _name(cert), 0,
36f0: 66 6c 61 67 73 29 2c 20 62 69 6f 2c 20 62 75 66 flags), bio, buf
3700: 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20 fer, BUFSIZ);.
3710: 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e LAPPEND_STR(in
3720: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
3730: 73 75 62 6a 65 63 74 22 2c 20 62 75 66 66 65 72 subject", buffer
3740: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e , (Tcl_Size) len
3750: 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 48 41 31 20 );.. /* SHA1
3760: 44 69 67 65 73 74 20 28 46 69 6e 67 65 72 70 72 Digest (Fingerpr
3770: 69 6e 74 29 20 6f 66 20 63 65 72 74 20 2d 20 44 int) of cert - D
3780: 45 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f ER representatio
3790: 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30 n */. if (X50
37a0: 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45 9_digest(cert, E
37b0: 56 50 5f 73 68 61 31 28 29 2c 20 6d 64 2c 20 26 VP_sha1(), md, &
37c0: 6c 65 6e 29 29 20 7b 0a 09 6c 65 6e 20 3d 20 53 len)) {..len = S
37d0: 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c tring_to_Hex(md,
37e0: 20 6c 65 6e 2c 20 62 75 66 66 65 72 2c 20 42 55 len, buffer, BU
37f0: 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f FSIZ);..LAPPEND_
3800: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 STR(interp, cert
3810: 50 74 72 2c 20 22 73 68 61 31 5f 68 61 73 68 22 Ptr, "sha1_hash"
3820: 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 , buffer, (Tcl_S
3830: 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d ize) len);. }
3840: 0a 0a 20 20 20 20 2f 2a 20 53 48 41 32 35 36 20 .. /* SHA256
3850: 44 69 67 65 73 74 20 28 46 69 6e 67 65 72 70 72 Digest (Fingerpr
3860: 69 6e 74 29 20 6f 66 20 63 65 72 74 20 2d 20 44 int) of cert - D
3870: 45 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f ER representatio
3880: 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30 n */. if (X50
3890: 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45 9_digest(cert, E
38a0: 56 50 5f 73 68 61 32 35 36 28 29 2c 20 6d 64 2c VP_sha256(), md,
38b0: 20 26 6c 65 6e 29 29 20 7b 0a 09 6c 65 6e 20 3d &len)) {..len =
38c0: 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d String_to_Hex(m
38d0: 64 2c 20 6c 65 6e 2c 20 62 75 66 66 65 72 2c 20 d, len, buffer,
38e0: 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e BUFSIZ);..LAPPEN
38f0: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 D_STR(interp, ce
3900: 72 74 50 74 72 2c 20 22 73 68 61 32 35 36 5f 68 rtPtr, "sha256_h
3910: 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20 28 54 ash", buffer, (T
3920: 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 cl_Size) len);.
3930: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 75 62 }.. /* Sub
3940: 6a 65 63 74 20 50 75 62 6c 69 63 20 4b 65 79 20 ject Public Key
3950: 49 6e 66 6f 20 73 70 65 63 69 66 69 65 73 20 74 Info specifies t
3960: 68 65 20 70 75 62 6c 69 63 20 6b 65 79 20 61 6e he public key an
3970: 64 20 69 64 65 6e 74 69 66 69 65 73 20 74 68 65 d identifies the
3980: 0a 09 61 6c 67 6f 72 69 74 68 6d 20 77 69 74 68 ..algorithm with
3990: 20 77 68 69 63 68 20 74 68 65 20 6b 65 79 20 69 which the key i
39a0: 73 20 75 73 65 64 2e 20 52 46 43 20 35 32 38 30 s used. RFC 5280
39b0: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 37 section 4.1.2.7
39c0: 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30 39 */. if (X509
39d0: 5f 67 65 74 5f 73 69 67 6e 61 74 75 72 65 5f 69 _get_signature_i
39e0: 6e 66 6f 28 63 65 72 74 2c 20 26 6d 64 6e 69 64 nfo(cert, &mdnid
39f0: 2c 20 26 70 6b 6e 69 64 2c 20 26 62 69 74 73 2c , &pknid, &bits,
3a00: 20 26 78 66 6c 61 67 73 29 29 20 7b 0a 09 41 53 &xflags)) {..AS
3a10: 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a 6b N1_BIT_STRING *k
3a20: 65 79 3b 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e ey;..unsigned in
3a30: 74 20 6e 3b 0a 0a 09 4c 41 50 50 45 4e 44 5f 53 t n;...LAPPEND_S
3a40: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 TR(interp, certP
3a50: 74 72 2c 20 22 73 69 67 6e 69 6e 67 44 69 67 65 tr, "signingDige
3a60: 73 74 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 st", OBJ_nid2ln(
3a70: 6d 64 6e 69 64 29 2c 20 2d 31 29 3b 0a 09 4c 41 mdnid), -1);..LA
3a80: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 PPEND_STR(interp
3a90: 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75 62 6c , certPtr, "publ
3aa0: 69 63 4b 65 79 41 6c 67 6f 72 69 74 68 6d 22 2c icKeyAlgorithm",
3ab0: 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 70 6b 6e 69 OBJ_nid2ln(pkni
3ac0: 64 29 2c 20 2d 31 29 3b 0a 09 4c 41 50 50 45 4e d), -1);..LAPPEN
3ad0: 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20 63 65 D_INT(interp, ce
3ae0: 72 74 50 74 72 2c 20 22 62 69 74 73 22 2c 20 62 rtPtr, "bits", b
3af0: 69 74 73 29 3b 20 2f 2a 20 45 66 66 65 63 74 69 its); /* Effecti
3b00: 76 65 20 73 65 63 75 72 69 74 79 20 62 69 74 73 ve security bits
3b10: 20 2a 2f 0a 0a 09 6b 65 79 20 3d 20 58 35 30 39 */...key = X509
3b20: 5f 67 65 74 30 5f 70 75 62 6b 65 79 5f 62 69 74 _get0_pubkey_bit
3b30: 73 74 72 28 63 65 72 74 29 3b 0a 09 6c 65 6e 20 str(cert);..len
3b40: 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 = String_to_Hex(
3b50: 6b 65 79 2d 3e 64 61 74 61 2c 20 6b 65 79 2d 3e key->data, key->
3b60: 6c 65 6e 67 74 68 2c 20 62 75 66 66 65 72 2c 20 length, buffer,
3b70: 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e BUFSIZ);..LAPPEN
3b80: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 D_STR(interp, ce
3b90: 72 74 50 74 72 2c 20 22 70 75 62 6c 69 63 4b 65 rtPtr, "publicKe
3ba0: 79 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c y", buffer, (Tcl
3bb0: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 6c _Size) len);...l
3bc0: 65 6e 20 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 en = 0;..if (X50
3bd0: 39 5f 70 75 62 6b 65 79 5f 64 69 67 65 73 74 28 9_pubkey_digest(
3be0: 63 65 72 74 2c 20 45 56 50 5f 67 65 74 5f 64 69 cert, EVP_get_di
3bf0: 67 65 73 74 62 79 6e 69 64 28 70 6b 6e 69 64 29 gestbynid(pknid)
3c00: 2c 20 6d 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20 , md, &n)) {..
3c10: 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 len = String_t
3c20: 6f 5f 48 65 78 28 6d 64 2c 20 28 69 6e 74 29 6e o_Hex(md, (int)n
3c30: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a , buffer, BUFSIZ
3c40: 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 );..}..LAPPEND_S
3c50: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 TR(interp, certP
3c60: 74 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 48 61 tr, "publicKeyHa
3c70: 73 68 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 sh", buffer, (Tc
3c80: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 l_Size) len);...
3c90: 2f 2a 20 64 69 67 65 73 74 20 6f 66 20 74 68 65 /* digest of the
3ca0: 20 44 45 52 20 72 65 70 72 65 73 65 6e 74 61 74 DER representat
3cb0: 69 6f 6e 20 6f 66 20 74 68 65 20 63 65 72 74 69 ion of the certi
3cc0: 66 69 63 61 74 65 20 2a 2f 0a 09 6c 65 6e 20 3d ficate */..len =
3cd0: 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f 64 69 0;..if (X509_di
3ce0: 67 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f 67 gest(cert, EVP_g
3cf0: 65 74 5f 64 69 67 65 73 74 62 79 6e 69 64 28 6d et_digestbynid(m
3d00: 64 6e 69 64 29 2c 20 6d 64 2c 20 26 6e 29 29 20 dnid), md, &n))
3d10: 7b 0a 09 20 20 20 20 6c 65 6e 20 3d 20 53 74 72 {.. len = Str
3d20: 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 28 ing_to_Hex(md, (
3d30: 69 6e 74 29 6e 2c 20 62 75 66 66 65 72 2c 20 42 int)n, buffer, B
3d40: 55 46 53 49 5a 29 3b 0a 09 7d 0a 09 4c 41 50 50 UFSIZ);..}..LAPP
3d50: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 END_STR(interp,
3d60: 63 65 72 74 50 74 72 2c 20 22 73 69 67 6e 61 74 certPtr, "signat
3d70: 75 72 65 48 61 73 68 22 2c 20 62 75 66 66 65 72 ureHash", buffer
3d80: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e , (Tcl_Size) len
3d90: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a );. }.. /*
3da0: 20 43 65 72 74 69 66 69 63 61 74 65 20 50 75 72 Certificate Pur
3db0: 70 6f 73 65 2e 20 43 61 6c 6c 20 62 65 66 6f 72 pose. Call befor
3dc0: 65 20 63 68 65 63 6b 69 6e 67 20 66 6f 72 20 65 e checking for e
3dd0: 78 74 65 6e 73 69 6f 6e 73 2e 20 2a 2f 0a 20 20 xtensions. */.
3de0: 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e LAPPEND_STR(in
3df0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
3e00: 70 75 72 70 6f 73 65 22 2c 20 54 6c 73 5f 78 35 purpose", Tls_x5
3e10: 30 39 50 75 72 70 6f 73 65 28 63 65 72 74 29 2c 09Purpose(cert),
3e20: 20 2d 31 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e -1);. LAPPEN
3e30: 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 D_OBJ(interp, ce
3e40: 72 74 50 74 72 2c 20 22 63 65 72 74 69 66 69 63 rtPtr, "certific
3e50: 61 74 65 50 75 72 70 6f 73 65 22 2c 20 54 6c 73 atePurpose", Tls
3e60: 5f 78 35 30 39 50 75 72 70 6f 73 65 73 28 69 6e _x509Purposes(in
3e70: 74 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 terp, cert));..
3e80: 20 20 20 2f 2a 20 47 65 74 20 65 78 74 65 6e 73 /* Get extens
3e90: 69 6f 6e 73 20 66 6c 61 67 73 20 2a 2f 0a 20 20 ions flags */.
3ea0: 20 20 78 66 6c 61 67 73 20 3d 20 58 35 30 39 5f xflags = X509_
3eb0: 67 65 74 5f 65 78 74 65 6e 73 69 6f 6e 5f 66 6c get_extension_fl
3ec0: 61 67 73 28 63 65 72 74 29 3b 0a 20 20 20 20 4c ags(cert);. L
3ed0: 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 APPEND_INT(inter
3ee0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 74 p, certPtr, "ext
3ef0: 46 6c 61 67 73 22 2c 20 78 66 6c 61 67 73 29 3b Flags", xflags);
3f00: 0a 0a 20 20 20 20 2f 2a 20 43 68 65 63 6b 20 69 .. /* Check i
3f10: 66 20 63 65 72 74 20 77 61 73 20 69 73 73 75 65 f cert was issue
3f20: 64 20 62 79 20 43 41 20 63 65 72 74 20 69 73 73 d by CA cert iss
3f30: 75 65 72 20 6f 72 20 73 65 6c 66 20 73 69 67 6e uer or self sign
3f40: 65 64 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e ed */. LAPPEN
3f50: 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 D_BOOL(interp, c
3f60: 65 72 74 50 74 72 2c 20 22 73 65 6c 66 49 73 73 ertPtr, "selfIss
3f70: 75 65 64 22 2c 20 78 66 6c 61 67 73 20 26 20 45 ued", xflags & E
3f80: 58 46 4c 41 47 5f 53 49 29 3b 0a 20 20 20 20 4c XFLAG_SI);. L
3f90: 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 APPEND_BOOL(inte
3fa0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65 rp, certPtr, "se
3fb0: 6c 66 53 69 67 6e 65 64 22 2c 20 78 66 6c 61 67 lfSigned", xflag
3fc0: 73 20 26 20 45 58 46 4c 41 47 5f 53 53 29 3b 0a s & EXFLAG_SS);.
3fd0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c LAPPEND_BOOL
3fe0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3ff0: 2c 20 22 69 73 50 72 6f 78 79 43 65 72 74 22 2c , "isProxyCert",
4000: 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 xflags & EXFLAG
4010: 5f 50 52 4f 58 59 29 3b 0a 20 20 20 20 4c 41 50 _PROXY);. LAP
4020: 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 PEND_BOOL(interp
4030: 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 74 49 , certPtr, "extI
4040: 6e 76 61 6c 69 64 22 2c 20 78 66 6c 61 67 73 20 nvalid", xflags
4050: 26 20 45 58 46 4c 41 47 5f 49 4e 56 41 4c 49 44 & EXFLAG_INVALID
4060: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 );. LAPPEND_B
4070: 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 OOL(interp, cert
4080: 50 74 72 2c 20 22 69 73 43 41 43 65 72 74 22 2c Ptr, "isCACert",
4090: 20 58 35 30 39 5f 63 68 65 63 6b 5f 63 61 28 63 X509_check_ca(c
40a0: 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 54 ert));.. /* T
40b0: 68 65 20 55 6e 69 71 75 65 20 49 64 73 20 61 72 he Unique Ids ar
40c0: 65 20 75 73 65 64 20 74 6f 20 68 61 6e 64 6c 65 e used to handle
40d0: 20 74 68 65 20 70 6f 73 73 69 62 69 6c 69 74 79 the possibility
40e0: 20 6f 66 20 72 65 75 73 65 20 6f 66 20 73 75 62 of reuse of sub
40f0: 6a 65 63 74 0a 09 61 6e 64 2f 6f 72 20 69 73 73 ject..and/or iss
4100: 75 65 72 20 6e 61 6d 65 73 20 6f 76 65 72 20 74 uer names over t
4110: 69 6d 65 2e 20 52 46 43 20 35 32 38 30 20 73 65 ime. RFC 5280 se
4120: 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 38 20 2a 2f ction 4.1.2.8 */
4130: 0a 20 20 20 20 7b 0a 09 63 6f 6e 73 74 20 41 53 . {..const AS
4140: 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a 69 N1_BIT_STRING *i
4150: 75 69 64 2c 20 2a 73 75 69 64 3b 0a 09 58 35 30 uid, *suid;..X50
4160: 39 5f 67 65 74 30 5f 75 69 64 73 28 63 65 72 74 9_get0_uids(cert
4170: 2c 20 26 69 75 69 64 2c 20 26 73 75 69 64 29 3b , &iuid, &suid);
4180: 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 ...Tcl_ListObjAp
4190: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
41a0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c rp, certPtr, Tcl
41b0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 69 _NewStringObj("i
41c0: 73 73 75 65 72 55 6e 69 71 75 65 49 64 22 2c 20 ssuerUniqueId",
41d0: 2d 31 29 29 3b 0a 09 69 66 20 28 69 75 69 64 20 -1));..if (iuid
41e0: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 != NULL) {..
41f0: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e Tcl_ListObjAppen
4200: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c dElement(interp,
4210: 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 certPtr, Tcl_Ne
4220: 77 42 79 74 65 41 72 72 61 79 4f 62 6a 28 28 63 wByteArrayObj((c
4230: 68 61 72 20 2a 29 69 75 69 64 2d 3e 64 61 74 61 har *)iuid->data
4240: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 69 75 69 , (Tcl_Size) iui
4250: 64 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 7d 20 d->length));..}
4260: 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 6c 5f else {.. Tcl_
4270: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
4280: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 ment(interp, cer
4290: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 tPtr, Tcl_NewStr
42a0: 69 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 29 3b ingObj("", -1));
42b0: 0a 09 7d 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 ..}...Tcl_ListOb
42c0: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 jAppendElement(i
42d0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
42e0: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a Tcl_NewStringObj
42f0: 28 22 73 75 62 6a 65 63 74 55 6e 69 71 75 65 49 ("subjectUniqueI
4300: 64 22 2c 20 2d 31 29 29 3b 0a 09 69 66 20 28 73 d", -1));..if (s
4310: 75 69 64 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 uid != NULL) {..
4320: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
4330: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
4340: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 erp, certPtr, Tc
4350: 6c 5f 4e 65 77 42 79 74 65 41 72 72 61 79 4f 62 l_NewByteArrayOb
4360: 6a 28 28 63 68 61 72 20 2a 29 73 75 69 64 2d 3e j((char *)suid->
4370: 64 61 74 61 2c 20 28 54 63 6c 5f 53 69 7a 65 29 data, (Tcl_Size)
4380: 20 73 75 69 64 2d 3e 6c 65 6e 67 74 68 29 29 3b suid->length));
4390: 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 ..} else {..
43a0: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e Tcl_ListObjAppen
43b0: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c dElement(interp,
43c0: 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 certPtr, Tcl_Ne
43d0: 77 53 74 72 69 6e 67 4f 62 6a 28 22 22 2c 20 2d wStringObj("", -
43e0: 31 29 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 1));..}. }..
43f0: 20 20 20 2f 2a 20 58 35 30 39 20 76 33 20 45 78 /* X509 v3 Ex
4400: 74 65 6e 73 69 6f 6e 73 20 2d 20 52 46 43 20 35 tensions - RFC 5
4410: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 280 section 4.1.
4420: 32 2e 39 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 2.9 */. LAPPE
4430: 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20 63 ND_INT(interp, c
4440: 65 72 74 50 74 72 2c 20 22 65 78 74 43 6f 75 6e ertPtr, "extCoun
4450: 74 22 2c 20 58 35 30 39 5f 67 65 74 5f 65 78 74 t", X509_get_ext
4460: 5f 63 6f 75 6e 74 28 63 65 72 74 29 29 3b 0a 20 _count(cert));.
4470: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 LAPPEND_OBJ(i
4480: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
4490: 22 65 78 74 65 6e 73 69 6f 6e 73 22 2c 20 54 6c "extensions", Tl
44a0: 73 5f 78 35 30 39 45 78 74 65 6e 73 69 6f 6e 73 s_x509Extensions
44b0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 29 3b (interp, cert));
44c0: 0a 0a 20 20 20 20 2f 2a 20 41 75 74 68 6f 72 69 .. /* Authori
44d0: 74 79 20 4b 65 79 20 49 64 65 6e 74 69 66 69 65 ty Key Identifie
44e0: 72 20 28 41 4b 49 29 20 69 73 20 74 68 65 20 53 r (AKI) is the S
44f0: 75 62 6a 65 63 74 20 4b 65 79 20 49 64 65 6e 74 ubject Key Ident
4500: 69 66 69 65 72 20 28 53 4b 49 29 20 6f 66 0a 09 ifier (SKI) of..
4510: 69 74 73 20 73 69 67 6e 65 72 20 28 74 68 65 20 its signer (the
4520: 43 41 29 2e 20 52 46 43 20 35 32 38 30 20 73 65 CA). RFC 5280 se
4530: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 2c 20 4e ction 4.2.1.1, N
4540: 49 44 5f 61 75 74 68 6f 72 69 74 79 5f 6b 65 79 ID_authority_key
4550: 5f 69 64 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 _identifier */.
4560: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 LAPPEND_OBJ(i
4570: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
4580: 22 61 75 74 68 6f 72 69 74 79 4b 65 79 49 64 65 "authorityKeyIde
4590: 6e 74 69 66 69 65 72 22 2c 0a 09 54 6c 73 5f 78 ntifier",..Tls_x
45a0: 35 30 39 49 64 65 6e 74 69 66 69 65 72 28 58 35 509Identifier(X5
45b0: 30 39 5f 67 65 74 30 5f 61 75 74 68 6f 72 69 74 09_get0_authorit
45c0: 79 5f 6b 65 79 5f 69 64 28 63 65 72 74 29 29 29 y_key_id(cert)))
45d0: 3b 0a 20 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 ;. . /* Subje
45e0: 63 74 20 4b 65 79 20 49 64 65 6e 74 69 66 69 65 ct Key Identifie
45f0: 72 20 28 53 4b 49 29 20 69 73 20 75 73 65 64 20 r (SKI) is used
4600: 74 6f 20 69 64 65 6e 74 69 66 79 20 63 65 72 74 to identify cert
4610: 69 66 69 63 61 74 65 73 20 74 68 61 74 20 63 6f ificates that co
4620: 6e 74 61 69 6e 0a 09 61 20 70 61 72 74 69 63 75 ntain..a particu
4630: 6c 61 72 20 70 75 62 6c 69 63 20 6b 65 79 2e 20 lar public key.
4640: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
4650: 20 34 2e 32 2e 31 2e 32 2c 20 4e 49 44 5f 73 75 4.2.1.2, NID_su
4660: 62 6a 65 63 74 5f 6b 65 79 5f 69 64 65 6e 74 69 bject_key_identi
4670: 66 69 65 72 20 2a 2f 0a 20 20 20 20 4c 41 50 50 fier */. LAPP
4680: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 END_OBJ(interp,
4690: 63 65 72 74 50 74 72 2c 20 22 73 75 62 6a 65 63 certPtr, "subjec
46a0: 74 4b 65 79 49 64 65 6e 74 69 66 69 65 72 22 2c tKeyIdentifier",
46b0: 0a 09 54 6c 73 5f 78 35 30 39 49 64 65 6e 74 69 ..Tls_x509Identi
46c0: 66 69 65 72 28 58 35 30 39 5f 67 65 74 30 5f 73 fier(X509_get0_s
46d0: 75 62 6a 65 63 74 5f 6b 65 79 5f 69 64 28 63 65 ubject_key_id(ce
46e0: 72 74 29 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 4b rt)));.. /* K
46f0: 65 79 20 75 73 61 67 65 20 65 78 74 65 6e 73 69 ey usage extensi
4700: 6f 6e 20 64 65 66 69 6e 65 73 20 74 68 65 20 70 on defines the p
4710: 75 72 70 6f 73 65 20 28 65 2e 67 2e 2c 20 65 6e urpose (e.g., en
4720: 63 69 70 68 65 72 6d 65 6e 74 2c 20 73 69 67 6e cipherment, sign
4730: 61 74 75 72 65 2c 20 63 65 72 74 69 66 69 63 61 ature, certifica
4740: 74 65 0a 09 73 69 67 6e 69 6e 67 29 20 6f 66 20 te..signing) of
4750: 74 68 65 20 6b 65 79 20 69 6e 20 74 68 65 20 63 the key in the c
4760: 65 72 74 69 66 69 63 61 74 65 2e 20 52 46 43 20 ertificate. RFC
4770: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 5280 section 4.2
4780: 2e 31 2e 33 2c 20 4e 49 44 5f 6b 65 79 5f 75 73 .1.3, NID_key_us
4790: 61 67 65 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 age */. LAPPE
47a0: 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 ND_OBJ(interp, c
47b0: 65 72 74 50 74 72 2c 20 22 6b 65 79 55 73 61 67 ertPtr, "keyUsag
47c0: 65 22 2c 20 54 6c 73 5f 78 35 30 39 4b 65 79 55 e", Tls_x509KeyU
47d0: 73 61 67 65 28 69 6e 74 65 72 70 2c 20 63 65 72 sage(interp, cer
47e0: 74 2c 20 78 66 6c 61 67 73 29 29 3b 0a 0a 20 20 t, xflags));..
47f0: 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65 /* Certificate
4800: 20 50 6f 6c 69 63 69 65 73 20 2d 20 69 6e 64 69 Policies - indi
4810: 63 61 74 65 73 20 74 68 65 20 69 73 73 75 69 6e cates the issuin
4820: 67 20 43 41 20 63 6f 6e 73 69 64 65 72 73 20 69 g CA considers i
4830: 74 73 20 69 73 73 75 65 72 44 6f 6d 61 69 6e 50 ts issuerDomainP
4840: 6f 6c 69 63 79 0a 09 65 71 75 69 76 61 6c 65 6e olicy..equivalen
4850: 74 20 74 6f 20 74 68 65 20 73 75 62 6a 65 63 74 t to the subject
4860: 20 43 41 27 73 20 73 75 62 6a 65 63 74 44 6f 6d CA's subjectDom
4870: 61 69 6e 50 6f 6c 69 63 79 2e 20 52 46 43 20 35 ainPolicy. RFC 5
4880: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 280 section 4.2.
4890: 31 2e 34 2c 20 4e 49 44 5f 63 65 72 74 69 66 69 1.4, NID_certifi
48a0: 63 61 74 65 5f 70 6f 6c 69 63 69 65 73 20 2a 2f cate_policies */
48b0: 0a 20 20 20 20 69 66 20 28 78 66 6c 61 67 73 20 . if (xflags
48c0: 26 20 45 58 46 4c 41 47 5f 49 4e 56 41 4c 49 44 & EXFLAG_INVALID
48d0: 5f 50 4f 4c 49 43 59 29 20 7b 0a 09 2f 2a 20 52 _POLICY) {../* R
48e0: 65 6a 65 63 74 20 63 65 72 74 20 2a 2f 0a 20 20 eject cert */.
48f0: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c 69 }.. /* Poli
4900: 63 79 20 4d 61 70 70 69 6e 67 73 20 2d 20 52 46 cy Mappings - RF
4910: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 C 5280 section 4
4920: 2e 32 2e 31 2e 35 2c 20 4e 49 44 5f 70 6f 6c 69 .2.1.5, NID_poli
4930: 63 79 5f 6d 61 70 70 69 6e 67 73 20 2a 2f 0a 0a cy_mappings */..
4940: 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 41 /* Subject A
4950: 6c 74 65 72 6e 61 74 69 76 65 20 4e 61 6d 65 20 lternative Name
4960: 28 53 41 4e 29 20 63 6f 6e 74 61 69 6e 73 20 61 (SAN) contains a
4970: 64 64 69 74 69 6f 6e 61 6c 20 55 52 4c 73 2c 20 dditional URLs,
4980: 44 4e 53 20 6e 61 6d 65 73 2c 20 6f 72 20 49 50 DNS names, or IP
4990: 0a 09 61 64 64 72 65 73 73 65 73 20 62 6f 75 6e ..addresses boun
49a0: 64 20 74 6f 20 63 65 72 74 69 66 69 63 61 74 65 d to certificate
49b0: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
49c0: 6f 6e 20 34 2e 32 2e 31 2e 36 2c 20 4e 49 44 5f on 4.2.1.6, NID_
49d0: 73 75 62 6a 65 63 74 5f 61 6c 74 5f 6e 61 6d 65 subject_alt_name
49e0: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f */. LAPPEND_
49f0: 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 OBJ(interp, cert
4a00: 50 74 72 2c 20 22 73 75 62 6a 65 63 74 41 6c 74 Ptr, "subjectAlt
4a10: 4e 61 6d 65 22 2c 20 54 6c 73 5f 78 35 30 39 4e Name", Tls_x509N
4a20: 61 6d 65 73 28 69 6e 74 65 72 70 2c 20 63 65 72 ames(interp, cer
4a30: 74 2c 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f 61 t, NID_subject_a
4a40: 6c 74 5f 6e 61 6d 65 2c 20 62 69 6f 29 29 3b 0a lt_name, bio));.
4a50: 0a 20 20 20 20 2f 2a 20 49 73 73 75 65 72 20 41 . /* Issuer A
4a60: 6c 74 65 72 6e 61 74 69 76 65 20 4e 61 6d 65 20 lternative Name
4a70: 69 73 20 75 73 65 64 20 74 6f 20 61 73 73 6f 63 is used to assoc
4a80: 69 61 74 65 20 49 6e 74 65 72 6e 65 74 20 73 74 iate Internet st
4a90: 79 6c 65 20 69 64 65 6e 74 69 74 69 65 73 0a 09 yle identities..
4aa0: 77 69 74 68 20 74 68 65 20 63 65 72 74 69 66 69 with the certifi
4ab0: 63 61 74 65 20 69 73 73 75 65 72 2e 20 52 46 43 cate issuer. RFC
4ac0: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 5280 section 4.
4ad0: 32 2e 31 2e 37 2c 20 4e 49 44 5f 69 73 73 75 65 2.1.7, NID_issue
4ae0: 72 5f 61 6c 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20 r_alt_name */.
4af0: 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e LAPPEND_OBJ(in
4b00: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
4b10: 69 73 73 75 65 72 41 6c 74 4e 61 6d 65 22 2c 20 issuerAltName",
4b20: 54 6c 73 5f 78 35 30 39 4e 61 6d 65 73 28 69 6e Tls_x509Names(in
4b30: 74 65 72 70 2c 20 63 65 72 74 2c 20 4e 49 44 5f terp, cert, NID_
4b40: 69 73 73 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 2c issuer_alt_name,
4b50: 20 62 69 6f 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 bio));.. /*
4b60: 53 75 62 6a 65 63 74 20 44 69 72 65 63 74 6f 72 Subject Director
4b70: 79 20 41 74 74 72 69 62 75 74 65 73 20 70 72 6f y Attributes pro
4b80: 76 69 64 65 73 20 69 64 65 6e 74 69 66 69 63 61 vides identifica
4b90: 74 69 6f 6e 20 61 74 74 72 69 62 75 74 65 73 20 tion attributes
4ba0: 28 65 2e 67 2e 2c 20 6e 61 74 69 6f 6e 61 6c 69 (e.g., nationali
4bb0: 74 79 29 0a 09 6f 66 20 74 68 65 20 73 75 62 6a ty)..of the subj
4bc0: 65 63 74 2e 20 52 46 43 20 35 32 38 30 20 73 65 ect. RFC 5280 se
4bd0: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 38 20 28 73 ction 4.2.1.8 (s
4be0: 75 62 6a 65 63 74 44 69 72 65 63 74 6f 72 79 41 ubjectDirectoryA
4bf0: 74 74 72 69 62 75 74 65 73 29 20 2a 2f 0a 0a 20 ttributes) */..
4c00: 20 20 20 2f 2a 20 42 61 73 69 63 20 43 6f 6e 73 /* Basic Cons
4c10: 74 72 61 69 6e 74 73 20 69 64 65 6e 74 69 66 69 traints identifi
4c20: 65 73 20 77 68 65 74 68 65 72 20 74 68 65 20 73 es whether the s
4c30: 75 62 6a 65 63 74 20 6f 66 20 74 68 65 20 63 65 ubject of the ce
4c40: 72 74 20 69 73 20 61 20 43 41 20 61 6e 64 0a 09 rt is a CA and..
4c50: 74 68 65 20 6d 61 78 20 64 65 70 74 68 20 6f 66 the max depth of
4c60: 20 76 61 6c 69 64 20 63 65 72 74 20 70 61 74 68 valid cert path
4c70: 73 20 66 6f 72 20 74 68 69 73 20 63 65 72 74 2e s for this cert.
4c80: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f RFC 5280 sectio
4c90: 6e 20 34 2e 32 2e 31 2e 39 2c 20 4e 49 44 5f 62 n 4.2.1.9, NID_b
4ca0: 61 73 69 63 5f 63 6f 6e 73 74 72 61 69 6e 74 73 asic_constraints
4cb0: 20 2a 2f 0a 20 20 20 20 69 66 20 28 21 28 78 66 */. if (!(xf
4cc0: 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 50 52 lags & EXFLAG_PR
4cd0: 4f 58 59 29 29 20 7b 0a 09 4c 41 50 50 45 4e 44 OXY)) {..LAPPEND
4ce0: 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63 65 _LONG(interp, ce
4cf0: 72 74 50 74 72 2c 20 22 70 61 74 68 4c 65 6e 22 rtPtr, "pathLen"
4d00: 2c 20 58 35 30 39 5f 67 65 74 5f 70 61 74 68 6c , X509_get_pathl
4d10: 65 6e 28 63 65 72 74 29 29 3b 0a 20 20 20 20 7d en(cert));. }
4d20: 20 65 6c 73 65 20 7b 0a 09 4c 41 50 50 45 4e 44 else {..LAPPEND
4d30: 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63 65 _LONG(interp, ce
4d40: 72 74 50 74 72 2c 20 22 70 61 74 68 4c 65 6e 22 rtPtr, "pathLen"
4d50: 2c 20 58 35 30 39 5f 67 65 74 5f 70 72 6f 78 79 , X509_get_proxy
4d60: 5f 70 61 74 68 6c 65 6e 28 63 65 72 74 29 29 3b _pathlen(cert));
4d70: 0a 20 20 20 20 7d 0a 20 20 20 20 4c 41 50 50 45 . }. LAPPE
4d80: 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 ND_BOOL(interp,
4d90: 63 65 72 74 50 74 72 2c 20 22 62 61 73 69 63 43 certPtr, "basicC
4da0: 6f 6e 73 74 72 61 69 6e 74 73 43 41 22 2c 20 78 onstraintsCA", x
4db0: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 43 flags & EXFLAG_C
4dc0: 41 29 3b 0a 0a 20 20 20 20 2f 2a 20 4e 61 6d 65 A);.. /* Name
4dd0: 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 73 20 Constraints is
4de0: 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 43 41 20 only used in CA
4df0: 63 65 72 74 73 20 74 6f 20 69 6e 64 69 63 61 74 certs to indicat
4e00: 65 20 74 68 65 20 6e 61 6d 65 20 73 70 61 63 65 e the name space
4e10: 20 66 6f 72 0a 09 61 6c 6c 20 73 75 62 6a 65 63 for..all subjec
4e20: 74 20 6e 61 6d 65 73 20 69 6e 20 73 75 62 73 65 t names in subse
4e30: 71 75 65 6e 74 20 63 65 72 74 69 66 69 63 61 74 quent certificat
4e40: 65 73 20 69 6e 20 61 20 63 65 72 74 69 66 69 63 es in a certific
4e50: 61 74 69 6f 6e 20 70 61 74 68 0a 09 4d 55 53 54 ation path..MUST
4e60: 20 62 65 20 6c 6f 63 61 74 65 64 2e 20 52 46 43 be located. RFC
4e70: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 5280 section 4.
4e80: 32 2e 31 2e 31 30 2c 20 4e 49 44 5f 6e 61 6d 65 2.1.10, NID_name
4e90: 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a _constraints */.
4ea0: 0a 20 20 20 20 2f 2a 20 50 6f 6c 69 63 79 20 43 . /* Policy C
4eb0: 6f 6e 73 74 72 61 69 6e 74 73 20 69 73 20 6f 6e onstraints is on
4ec0: 6c 79 20 75 73 65 64 20 69 6e 20 43 41 20 63 65 ly used in CA ce
4ed0: 72 74 73 20 74 6f 20 6c 69 6d 69 74 20 74 68 65 rts to limit the
4ee0: 20 6c 65 6e 67 74 68 20 6f 66 20 61 0a 09 63 65 length of a..ce
4ef0: 72 74 20 63 68 61 69 6e 20 66 6f 72 20 74 68 61 rt chain for tha
4f00: 74 20 43 41 2e 20 52 46 43 20 35 32 38 30 20 73 t CA. RFC 5280 s
4f10: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 31 2c ection 4.2.1.11,
4f20: 20 4e 49 44 5f 70 6f 6c 69 63 79 5f 63 6f 6e 73 NID_policy_cons
4f30: 74 72 61 69 6e 74 73 20 2a 2f 0a 0a 20 20 20 20 traints */..
4f40: 2f 2a 20 45 78 74 65 6e 64 65 64 20 4b 65 79 20 /* Extended Key
4f50: 55 73 61 67 65 20 69 6e 64 69 63 61 74 65 73 20 Usage indicates
4f60: 74 68 65 20 70 75 72 70 6f 73 65 73 20 74 68 65 the purposes the
4f70: 20 63 65 72 74 69 66 69 65 64 20 70 75 62 6c 69 certified publi
4f80: 63 20 6b 65 79 20 6d 61 79 20 62 65 0a 09 75 73 c key may be..us
4f90: 65 64 2c 20 62 65 79 6f 6e 64 20 74 68 65 20 62 ed, beyond the b
4fa0: 61 73 69 63 20 70 75 72 70 6f 73 65 73 2e 20 52 asic purposes. R
4fb0: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 FC 5280 section
4fc0: 34 2e 32 2e 31 2e 31 32 2c 20 4e 49 44 5f 65 78 4.2.1.12, NID_ex
4fd0: 74 5f 6b 65 79 5f 75 73 61 67 65 20 2a 2f 0a 20 t_key_usage */.
4fe0: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 LAPPEND_OBJ(i
4ff0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
5000: 22 65 78 74 65 6e 64 65 64 4b 65 79 55 73 61 67 "extendedKeyUsag
5010: 65 22 2c 20 54 6c 73 5f 78 35 30 39 45 78 74 4b e", Tls_x509ExtK
5020: 65 79 55 73 61 67 65 28 69 6e 74 65 72 70 2c 20 eyUsage(interp,
5030: 63 65 72 74 2c 20 78 66 6c 61 67 73 29 29 3b 0a cert, xflags));.
5040: 0a 20 20 20 20 2f 2a 20 43 52 4c 20 44 69 73 74 . /* CRL Dist
5050: 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e 74 73 20 ribution Points
5060: 69 64 65 6e 74 69 66 69 65 73 20 77 68 65 72 65 identifies where
5070: 20 43 52 4c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e CRL information
5080: 20 63 61 6e 20 62 65 20 6f 62 74 61 69 6e 65 64 can be obtained
5090: 2e 0a 09 52 46 43 20 35 32 38 30 20 73 65 63 74 ...RFC 5280 sect
50a0: 69 6f 6e 20 34 2e 32 2e 31 2e 31 33 2a 2f 0a 20 ion 4.2.1.13*/.
50b0: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 LAPPEND_OBJ(i
50c0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
50d0: 22 63 72 6c 44 69 73 74 72 69 62 75 74 69 6f 6e "crlDistribution
50e0: 50 6f 69 6e 74 73 22 2c 20 54 6c 73 5f 78 35 30 Points", Tls_x50
50f0: 39 43 72 6c 44 70 28 69 6e 74 65 72 70 2c 20 63 9CrlDp(interp, c
5100: 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 46 ert));.. /* F
5110: 72 65 73 68 65 73 74 20 43 52 4c 20 65 78 74 65 reshest CRL exte
5120: 6e 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 66 20 nsion */. if
5130: 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 (xflags & EXFLAG
5140: 5f 46 52 45 53 48 45 53 54 29 20 7b 0a 20 20 20 _FRESHEST) {.
5150: 20 7d 0a 0a 20 20 20 20 2f 2a 20 41 75 74 68 6f }.. /* Autho
5160: 72 69 74 79 20 49 6e 66 6f 72 6d 61 74 69 6f 6e rity Information
5170: 20 41 63 63 65 73 73 20 69 6e 64 69 63 61 74 65 Access indicate
5180: 73 20 68 6f 77 20 74 6f 20 61 63 63 65 73 73 20 s how to access
5190: 69 6e 66 6f 20 61 6e 64 20 73 65 72 76 69 63 65 info and service
51a0: 73 0a 09 66 6f 72 20 74 68 65 20 63 65 72 74 69 s..for the certi
51b0: 66 69 63 61 74 65 20 69 73 73 75 65 72 2e 20 52 ficate issuer. R
51c0: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 FC 5280 section
51d0: 34 2e 32 2e 32 2e 31 2c 20 4e 49 44 5f 69 6e 66 4.2.2.1, NID_inf
51e0: 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a 20 20 20 o_access */..
51f0: 20 2f 2a 20 47 65 74 20 4f 6e 2d 6c 69 6e 65 20 /* Get On-line
5200: 43 65 72 74 69 66 69 63 61 74 65 20 53 74 61 74 Certificate Stat
5210: 75 73 20 50 72 6f 74 6f 63 6f 6c 20 28 4f 53 43 us Protocol (OSC
5220: 50 29 20 52 65 73 70 6f 6e 64 65 72 73 20 55 52 P) Responders UR
5230: 4c 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 L */. LAPPEND
5240: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 _OBJ(interp, cer
5250: 74 50 74 72 2c 20 22 6f 63 73 70 52 65 73 70 6f tPtr, "ocspRespo
5260: 6e 64 65 72 73 22 2c 20 54 6c 73 5f 78 35 30 39 nders", Tls_x509
5270: 4f 73 63 70 28 69 6e 74 65 72 70 2c 20 63 65 72 Oscp(interp, cer
5280: 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74 t));.. /* Get
5290: 20 43 65 72 74 69 66 69 63 61 74 65 20 41 75 74 Certificate Aut
52a0: 68 6f 72 69 74 79 20 28 43 41 29 20 49 73 73 75 hority (CA) Issu
52b0: 65 72 73 20 55 52 4c 20 2a 2f 0a 20 20 20 20 4c ers URL */. L
52c0: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 APPEND_OBJ(inter
52d0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 61 49 p, certPtr, "caI
52e0: 73 73 75 65 72 73 22 2c 20 54 6c 73 5f 78 35 30 ssuers", Tls_x50
52f0: 39 43 61 49 73 73 75 65 72 73 28 69 6e 74 65 72 9CaIssuers(inter
5300: 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 p, cert));..
5310: 2f 2a 20 53 75 62 6a 65 63 74 20 49 6e 66 6f 72 /* Subject Infor
5320: 6d 61 74 69 6f 6e 20 41 63 63 65 73 73 20 2d 20 mation Access -
5330: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
5340: 20 34 2e 32 2e 32 2e 32 2c 20 4e 49 44 5f 73 69 4.2.2.2, NID_si
5350: 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a 20 nfo_access */..
5360: 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 /* Certificat
5370: 65 20 41 6c 69 61 73 2e 20 49 66 20 75 73 65 73 e Alias. If uses
5380: 20 61 20 50 4b 43 53 23 31 32 20 73 74 72 75 63 a PKCS#12 struc
5390: 74 75 72 65 2c 20 61 6c 69 61 73 20 77 69 6c 6c ture, alias will
53a0: 20 72 65 66 6c 65 63 74 20 74 68 65 0a 09 66 72 reflect the..fr
53b0: 69 65 6e 64 6c 79 4e 61 6d 65 20 61 74 74 72 69 iendlyName attri
53c0: 62 75 74 65 20 28 52 46 43 20 32 39 38 35 29 2e bute (RFC 2985).
53d0: 20 2a 2f 0a 20 20 20 20 7b 0a 09 6c 65 6e 20 3d */. {..len =
53e0: 20 30 3b 0a 20 20 20 20 20 20 20 20 63 68 61 72 0;. char
53f0: 20 2a 73 74 72 69 6e 67 20 3d 20 58 35 30 39 5f *string = X509_
5400: 61 6c 69 61 73 5f 67 65 74 30 28 63 65 72 74 2c alias_get0(cert,
5410: 20 26 6c 65 6e 29 3b 0a 09 4c 41 50 50 45 4e 44 &len);..LAPPEND
5420: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 _STR(interp, cer
5430: 74 50 74 72 2c 20 22 61 6c 69 61 73 22 2c 20 73 tPtr, "alias", s
5440: 74 72 69 6e 67 2c 20 28 54 63 6c 5f 53 69 7a 65 tring, (Tcl_Size
5450: 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 ) len);. }..
5460: 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 /* Certificat
5470: 65 20 61 6e 64 20 64 75 6d 70 20 61 6c 6c 20 64 e and dump all d
5480: 61 74 61 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 68 ata */. {..ch
5490: 61 72 20 63 65 72 74 53 74 72 5b 43 45 52 54 5f ar certStr[CERT_
54a0: 53 54 52 5f 53 49 5a 45 5d 3b 0a 0a 09 2f 2a 20 STR_SIZE];.../*
54b0: 47 65 74 20 63 65 72 74 69 66 69 63 61 74 65 20 Get certificate
54c0: 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f */..len = BIO_to
54d0: 5f 42 75 66 66 65 72 28 50 45 4d 5f 77 72 69 74 _Buffer(PEM_writ
54e0: 65 5f 62 69 6f 5f 58 35 30 39 28 62 69 6f 2c 20 e_bio_X509(bio,
54f0: 63 65 72 74 29 2c 20 62 69 6f 2c 20 63 65 72 74 cert), bio, cert
5500: 53 74 72 2c 20 43 45 52 54 5f 53 54 52 5f 53 49 Str, CERT_STR_SI
5510: 5a 45 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 ZE);..LAPPEND_ST
5520: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 R(interp, certPt
5530: 72 2c 20 22 63 65 72 74 69 66 69 63 61 74 65 22 r, "certificate"
5540: 2c 20 63 65 72 74 53 74 72 2c 20 28 54 63 6c 5f , certStr, (Tcl_
5550: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 2f 2a Size) len);.../*
5560: 20 47 65 74 20 61 6c 6c 20 63 65 72 74 20 69 6e Get all cert in
5570: 66 6f 20 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f fo */..len = BIO
5580: 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39 5f _to_Buffer(X509_
5590: 70 72 69 6e 74 5f 65 78 28 62 69 6f 2c 20 63 65 print_ex(bio, ce
55a0: 72 74 2c 20 66 6c 61 67 73 2c 20 30 29 2c 20 62 rt, flags, 0), b
55b0: 69 6f 2c 20 63 65 72 74 53 74 72 2c 20 43 45 52 io, certStr, CER
55c0: 54 5f 53 54 52 5f 53 49 5a 45 29 3b 0a 09 4c 41 T_STR_SIZE);..LA
55d0: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 PPEND_STR(interp
55e0: 2c 20 63 65 72 74 50 74 72 2c 20 22 61 6c 6c 22 , certPtr, "all"
55f0: 2c 20 63 65 72 74 53 74 72 2c 20 28 54 63 6c 5f , certStr, (Tcl_
5600: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 20 Size) len);.
5610: 7d 0a 0a 20 20 20 20 42 49 4f 5f 66 72 65 65 28 }.. BIO_free(
5620: 62 69 6f 29 3b 0a 20 20 20 20 72 65 74 75 72 6e bio);. return
5630: 20 63 65 72 74 50 74 72 3b 0a 7d 0a certPtr;.}.