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 63 68 String_to_Hex(ch
0200: 61 72 2a 20 69 6e 70 75 74 2c 20 69 6e 74 20 69 ar* input, int i
0210: 6c 65 6e 2c 20 63 68 61 72 20 2a 6f 75 74 70 75 len, char *outpu
0220: 74 2c 20 69 6e 74 20 6f 6c 65 6e 29 20 7b 0a 20 t, int olen) {.
0230: 20 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d 20 30 int count = 0
0240: 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69 6e 74 20 ;.. for (int
0250: 69 20 3d 20 30 3b 20 69 20 3c 20 69 6c 65 6e 20 i = 0; i < ilen
0260: 26 26 20 63 6f 75 6e 74 20 3c 20 6f 6c 65 6e 20 && count < olen
0270: 2d 20 31 3b 20 69 2b 2b 2c 20 63 6f 75 6e 74 20 - 1; i++, count
0280: 2b 3d 20 32 29 20 7b 0a 09 73 70 72 69 6e 74 66 += 2) {..sprintf
0290: 28 6f 75 74 70 75 74 20 2b 20 63 6f 75 6e 74 2c (output + count,
02a0: 20 22 25 30 32 58 22 2c 20 69 6e 70 75 74 5b 69 "%02X", input[i
02b0: 5d 20 26 20 30 78 66 66 29 3b 0a 20 20 20 20 7d ] & 0xff);. }
02c0: 0a 20 20 20 20 6f 75 74 70 75 74 5b 63 6f 75 6e . output[coun
02d0: 74 5d 20 3d 20 30 3b 0a 20 20 20 20 72 65 74 75 t] = 0;. retu
02e0: 72 6e 20 63 6f 75 6e 74 3b 0a 7d 0a 0a 2f 2a 0a rn count;.}../*.
02f0: 20 2a 20 42 49 4f 20 74 6f 20 42 75 66 66 65 72 * BIO to Buffer
0300: 0a 20 2a 2f 0a 69 6e 74 20 42 49 4f 5f 74 6f 5f . */.int BIO_to_
0310: 42 75 66 66 65 72 28 69 6e 74 20 72 65 73 75 6c Buffer(int resul
0320: 74 2c 20 42 49 4f 20 2a 62 69 6f 2c 20 76 6f 69 t, BIO *bio, voi
0330: 64 20 2a 62 75 66 66 65 72 2c 20 69 6e 74 20 73 d *buffer, int s
0340: 69 7a 65 29 20 7b 0a 20 20 20 20 69 6e 74 20 6c ize) {. int l
0350: 65 6e 20 3d 20 30 3b 0a 20 20 20 20 69 6e 74 20 en = 0;. int
0360: 70 65 6e 64 69 6e 67 20 3d 20 42 49 4f 5f 70 65 pending = BIO_pe
0370: 6e 64 69 6e 67 28 62 69 6f 29 3b 0a 0a 20 20 20 nding(bio);..
0380: 20 69 66 20 28 72 65 73 75 6c 74 29 20 7b 0a 09 if (result) {..
0390: 6c 65 6e 20 3d 20 42 49 4f 5f 72 65 61 64 28 62 len = BIO_read(b
03a0: 69 6f 2c 20 62 75 66 66 65 72 2c 20 28 70 65 6e io, buffer, (pen
03b0: 64 69 6e 67 20 3c 20 73 69 7a 65 29 20 3f 20 70 ding < size) ? p
03c0: 65 6e 64 69 6e 67 20 3a 20 73 69 7a 65 29 3b 0a ending : size);.
03d0: 09 28 76 6f 69 64 29 42 49 4f 5f 66 6c 75 73 68 .(void)BIO_flush
03e0: 28 62 69 6f 29 3b 0a 09 69 66 20 28 6c 65 6e 20 (bio);..if (len
03f0: 3c 20 30 29 20 7b 0a 09 20 20 20 20 6c 65 6e 20 < 0) {.. len
0400: 3d 20 30 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 = 0;..}. }.
0410: 20 20 72 65 74 75 72 6e 20 6c 65 6e 3b 0a 7d 0a return len;.}.
0420: 0c 0a 2f 2a 0a 20 2a 20 47 65 74 20 58 35 30 39 ../*. * Get X509
0430: 20 43 65 72 74 69 66 69 63 61 74 65 20 45 78 74 Certificate Ext
0440: 65 6e 73 69 6f 6e 73 0a 20 2a 2f 0a 54 63 6c 5f ensions. */.Tcl_
0450: 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 45 78 74 Obj *Tls_x509Ext
0460: 65 6e 73 69 6f 6e 73 28 54 63 6c 5f 49 6e 74 65 ensions(Tcl_Inte
0470: 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 rp *interp, X509
0480: 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 63 6f *cert) {. co
0490: 6e 73 74 20 53 54 41 43 4b 5f 4f 46 28 58 35 30 nst STACK_OF(X50
04a0: 39 5f 45 58 54 45 4e 53 49 4f 4e 29 20 2a 65 78 9_EXTENSION) *ex
04b0: 74 73 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 ts;. Tcl_Obj
04c0: 2a 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e *listPtr = Tcl_N
04d0: 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c ewListObj(0, NUL
04e0: 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 73 L);.. if (lis
04f0: 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a tPtr == NULL) {.
0500: 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 .return NULL;.
0510: 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 65 78 74 }.. if (ext
0520: 73 20 3d 20 58 35 30 39 5f 67 65 74 30 5f 65 78 s = X509_get0_ex
0530: 74 65 6e 73 69 6f 6e 73 28 63 65 72 74 29 29 20 tensions(cert))
0540: 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 3d 30 3b {..for (int i=0;
0550: 20 69 20 3c 20 58 35 30 39 5f 67 65 74 5f 65 78 i < X509_get_ex
0560: 74 5f 63 6f 75 6e 74 28 63 65 72 74 29 3b 20 69 t_count(cert); i
0570: 2b 2b 29 20 7b 0a 09 20 20 20 20 58 35 30 39 5f ++) {.. X509_
0580: 45 58 54 45 4e 53 49 4f 4e 20 2a 65 78 20 3d 20 EXTENSION *ex =
0590: 73 6b 5f 58 35 30 39 5f 45 58 54 45 4e 53 49 4f sk_X509_EXTENSIO
05a0: 4e 5f 76 61 6c 75 65 28 65 78 74 73 2c 20 69 29 N_value(exts, i)
05b0: 3b 0a 09 20 20 20 20 41 53 4e 31 5f 4f 42 4a 45 ;.. ASN1_OBJE
05c0: 43 54 20 2a 6f 62 6a 20 3d 20 58 35 30 39 5f 45 CT *obj = X509_E
05d0: 58 54 45 4e 53 49 4f 4e 5f 67 65 74 5f 6f 62 6a XTENSION_get_obj
05e0: 65 63 74 28 65 78 29 3b 0a 09 20 20 20 20 2f 2a ect(ex);.. /*
05f0: 20 41 53 4e 31 5f 4f 43 54 45 54 5f 53 54 52 49 ASN1_OCTET_STRI
0600: 4e 47 20 2a 64 61 74 61 20 3d 20 58 35 30 39 5f NG *data = X509_
0610: 45 58 54 45 4e 53 49 4f 4e 5f 67 65 74 5f 64 61 EXTENSION_get_da
0620: 74 61 28 65 78 29 3b 20 2a 2f 0a 09 20 20 20 20 ta(ex); */..
0630: 69 6e 74 20 63 72 69 74 69 63 61 6c 20 3d 20 58 int critical = X
0640: 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67 65 509_EXTENSION_ge
0650: 74 5f 63 72 69 74 69 63 61 6c 28 65 78 29 3b 0a t_critical(ex);.
0660: 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f . LAPPEND_BOO
0670: 4c 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 L(interp, listPt
0680: 72 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 4f 42 r, OBJ_nid2ln(OB
0690: 4a 5f 6f 62 6a 32 6e 69 64 28 6f 62 6a 29 29 2c J_obj2nid(obj)),
06a0: 20 63 72 69 74 69 63 61 6c 29 3b 0a 09 7d 0a 20 critical);..}.
06b0: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
06c0: 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 listPtr;.}../*.
06d0: 2a 20 47 65 74 20 41 75 74 68 6f 72 69 74 79 20 * Get Authority
06e0: 61 6e 64 20 53 75 62 6a 65 63 74 20 4b 65 79 20 and Subject Key
06f0: 49 64 65 6e 74 69 66 69 65 72 73 0a 20 2a 2f 0a Identifiers. */.
0700: 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 Tcl_Obj *Tls_x50
0710: 39 49 64 65 6e 74 69 66 69 65 72 28 41 53 4e 31 9Identifier(ASN1
0720: 5f 4f 43 54 45 54 5f 53 54 52 49 4e 47 20 2a 61 _OCTET_STRING *a
0730: 73 74 72 69 6e 67 29 20 7b 0a 20 20 20 20 54 63 string) {. Tc
0740: 6c 5f 4f 62 6a 20 2a 72 65 73 75 6c 74 50 74 72 l_Obj *resultPtr
0750: 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 69 6e 74 = NULL;. int
0760: 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20 20 63 68 len = 0;. ch
0770: 61 72 20 62 75 66 66 65 72 5b 31 30 32 34 5d 3b ar buffer[1024];
0780: 0a 0a 20 20 20 20 69 66 20 28 61 73 74 72 69 6e .. if (astrin
0790: 67 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 6c 65 g != NULL) {..le
07a0: 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 n = String_to_He
07b0: 78 28 28 63 68 61 72 20 2a 29 41 53 4e 31 5f 53 x((char *)ASN1_S
07c0: 54 52 49 4e 47 5f 67 65 74 30 5f 64 61 74 61 28 TRING_get0_data(
07d0: 61 73 74 72 69 6e 67 29 2c 0a 09 20 20 20 20 41 astring),.. A
07e0: 53 4e 31 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 SN1_STRING_lengt
07f0: 68 28 61 73 74 72 69 6e 67 29 2c 20 62 75 66 66 h(astring), buff
0800: 65 72 2c 20 31 30 32 34 29 3b 0a 20 20 20 20 7d er, 1024);. }
0810: 0a 20 20 20 20 72 65 73 75 6c 74 50 74 72 20 3d . resultPtr =
0820: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
0830: 6a 28 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 j(buffer, (Tcl_S
0840: 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 20 72 ize) len);. r
0850: 65 74 75 72 6e 20 72 65 73 75 6c 74 50 74 72 3b eturn resultPtr;
0860: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 4b 65 .}../*. * Get Ke
0870: 79 20 55 73 61 67 65 0a 20 2a 2f 0a 54 63 6c 5f y Usage. */.Tcl_
0880: 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4b 65 79 Obj *Tls_x509Key
0890: 55 73 61 67 65 28 54 63 6c 5f 49 6e 74 65 72 70 Usage(Tcl_Interp
08a0: 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a *interp, X509 *
08b0: 63 65 72 74 2c 20 75 69 6e 74 33 32 5f 74 20 78 cert, uint32_t x
08c0: 66 6c 61 67 73 29 20 7b 0a 20 20 20 20 75 69 6e flags) {. uin
08d0: 74 33 32 5f 74 20 75 73 61 67 65 20 3d 20 58 35 t32_t usage = X5
08e0: 30 39 5f 67 65 74 5f 6b 65 79 5f 75 73 61 67 65 09_get_key_usage
08f0: 28 63 65 72 74 29 3b 0a 20 20 20 20 54 63 6c 5f (cert);. Tcl_
0900: 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 Obj *listPtr = T
0910: 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c cl_NewListObj(0,
0920: 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20 NULL);.. if
0930: 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c (listPtr == NULL
0940: 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c ) {..return NULL
0950: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 ;. }.. if
0960: 28 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 ((xflags & EXFLA
0970: 47 5f 4b 55 53 41 47 45 29 20 26 26 20 75 73 61 G_KUSAGE) && usa
0980: 67 65 20 3c 20 55 49 4e 54 33 32 5f 4d 41 58 29 ge < UINT32_MAX)
0990: 20 7b 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 {..if (usage &
09a0: 4b 55 5f 44 49 47 49 54 41 4c 5f 53 49 47 4e 41 KU_DIGITAL_SIGNA
09b0: 54 55 52 45 29 20 7b 0a 09 20 20 20 20 54 63 6c TURE) {.. Tcl
09c0: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
09d0: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 ement(interp, li
09e0: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 stPtr, Tcl_NewSt
09f0: 72 69 6e 67 4f 62 6a 28 22 44 69 67 69 74 61 6c ringObj("Digital
0a00: 20 53 69 67 6e 61 74 75 72 65 22 2c 20 2d 31 29 Signature", -1)
0a10: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 );..}..if (usage
0a20: 20 26 20 4b 55 5f 4e 4f 4e 5f 52 45 50 55 44 49 & KU_NON_REPUDI
0a30: 41 54 49 4f 4e 29 20 7b 0a 09 20 20 20 20 54 63 ATION) {.. Tc
0a40: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
0a50: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
0a60: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
0a70: 74 72 69 6e 67 4f 62 6a 28 22 4e 6f 6e 2d 52 65 tringObj("Non-Re
0a80: 70 75 64 69 61 74 69 6f 6e 22 2c 20 2d 31 29 29 pudiation", -1))
0a90: 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 ;..}..if (usage
0aa0: 26 20 4b 55 5f 4b 45 59 5f 45 4e 43 49 50 48 45 & KU_KEY_ENCIPHE
0ab0: 52 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 RMENT) {.. Tc
0ac0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
0ad0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
0ae0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
0af0: 74 72 69 6e 67 4f 62 6a 28 22 4b 65 79 20 45 6e tringObj("Key En
0b00: 63 69 70 68 65 72 6d 65 6e 74 22 2c 20 2d 31 29 cipherment", -1)
0b10: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 );..}..if (usage
0b20: 20 26 20 4b 55 5f 44 41 54 41 5f 45 4e 43 49 50 & KU_DATA_ENCIP
0b30: 48 45 52 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 HERMENT) {..
0b40: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e Tcl_ListObjAppen
0b50: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c dElement(interp,
0b60: 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 listPtr, Tcl_Ne
0b70: 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 61 74 61 wStringObj("Data
0b80: 20 45 6e 63 69 70 68 65 72 6d 65 6e 74 22 2c 20 Encipherment",
0b90: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 -1));..}..if (us
0ba0: 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 41 47 52 age & KU_KEY_AGR
0bb0: 45 45 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 EEMENT) {.. T
0bc0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
0bd0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
0be0: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
0bf0: 53 74 72 69 6e 67 4f 62 6a 28 22 4b 65 79 20 41 StringObj("Key A
0c00: 67 72 65 65 6d 65 6e 74 22 2c 20 2d 31 29 29 3b greement", -1));
0c10: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
0c20: 20 4b 55 5f 4b 45 59 5f 43 45 52 54 5f 53 49 47 KU_KEY_CERT_SIG
0c30: 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 N) {.. Tcl_Li
0c40: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 stObjAppendEleme
0c50: 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 nt(interp, listP
0c60: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e tr, Tcl_NewStrin
0c70: 67 4f 62 6a 28 22 43 65 72 74 69 66 69 63 61 74 gObj("Certificat
0c80: 65 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31 29 29 e Signing", -1))
0c90: 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 ;..}..if (usage
0ca0: 26 20 4b 55 5f 43 52 4c 5f 53 49 47 4e 29 20 7b & KU_CRL_SIGN) {
0cb0: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 .. Tcl_ListOb
0cc0: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 jAppendElement(i
0cd0: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 nterp, listPtr,
0ce0: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a Tcl_NewStringObj
0cf0: 28 22 43 52 4c 20 53 69 67 6e 69 6e 67 22 2c 20 ("CRL Signing",
0d00: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 -1));..}..if (us
0d10: 61 67 65 20 26 20 4b 55 5f 45 4e 43 49 50 48 45 age & KU_ENCIPHE
0d20: 52 5f 4f 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 R_ONLY) {.. T
0d30: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
0d40: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
0d50: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
0d60: 53 74 72 69 6e 67 4f 62 6a 28 22 45 6e 63 69 70 StringObj("Encip
0d70: 68 65 72 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b her Only", -1));
0d80: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
0d90: 20 4b 55 5f 44 45 43 49 50 48 45 52 5f 4f 4e 4c KU_DECIPHER_ONL
0da0: 59 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 Y) {.. Tcl_Li
0db0: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 stObjAppendEleme
0dc0: 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 nt(interp, listP
0dd0: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e tr, Tcl_NewStrin
0de0: 67 4f 62 6a 28 22 44 65 63 69 70 68 65 72 20 4f gObj("Decipher O
0df0: 6e 6c 79 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 nly", -1));..}.
0e00: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 } else {..
0e10: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 Tcl_ListObjAppe
0e20: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 ndElement(interp
0e30: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e , listPtr, Tcl_N
0e40: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 75 6e 72 ewStringObj("unr
0e50: 65 73 74 72 69 63 74 65 64 22 2c 20 2d 31 29 29 estricted", -1))
0e60: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 ;. }. retu
0e70: 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f rn listPtr;.}../
0e80: 2a 0a 20 2a 20 47 65 74 20 43 65 72 74 69 66 69 *. * Get Certifi
0e90: 63 61 74 65 20 50 75 72 70 6f 73 65 0a 20 2a 2f cate Purpose. */
0ea0: 0a 63 68 61 72 20 2a 54 6c 73 5f 78 35 30 39 50 .char *Tls_x509P
0eb0: 75 72 70 6f 73 65 28 58 35 30 39 20 2a 63 65 72 urpose(X509 *cer
0ec0: 74 29 20 7b 0a 20 20 20 20 63 68 61 72 20 2a 70 t) {. char *p
0ed0: 75 72 70 6f 73 65 20 3d 20 4e 55 4c 4c 3b 0a 0a urpose = NULL;..
0ee0: 20 20 20 20 69 66 20 28 58 35 30 39 5f 63 68 65 if (X509_che
0ef0: 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c ck_purpose(cert,
0f00: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 53 53 X509_PURPOSE_SS
0f10: 4c 5f 43 4c 49 45 4e 54 2c 20 30 29 20 3e 20 30 L_CLIENT, 0) > 0
0f20: 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 ) {..purpose = "
0f30: 53 53 4c 20 43 6c 69 65 6e 74 22 3b 0a 20 20 20 SSL Client";.
0f40: 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 } else if (X509
0f50: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 _check_purpose(c
0f60: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 ert, X509_PURPOS
0f70: 45 5f 53 53 4c 5f 53 45 52 56 45 52 2c 20 30 29 E_SSL_SERVER, 0)
0f80: 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 > 0) {..purpose
0f90: 20 3d 20 22 53 53 4c 20 53 65 72 76 65 72 22 3b = "SSL Server";
0fa0: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 . } else if (
0fb0: 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f X509_check_purpo
0fc0: 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 se(cert, X509_PU
0fd0: 52 50 4f 53 45 5f 4e 53 5f 53 53 4c 5f 53 45 52 RPOSE_NS_SSL_SER
0fe0: 56 45 52 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 VER, 0) > 0) {..
0ff0: 70 75 72 70 6f 73 65 20 3d 20 22 4d 53 53 20 53 purpose = "MSS S
1000: 53 4c 20 53 65 72 76 65 72 22 3b 0a 20 20 20 20 SL Server";.
1010: 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 5f } else if (X509_
1020: 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 check_purpose(ce
1030: 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 rt, X509_PURPOSE
1040: 5f 53 4d 49 4d 45 5f 53 49 47 4e 2c 20 30 29 20 _SMIME_SIGN, 0)
1050: 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 > 0) {..purpose
1060: 3d 20 22 53 4d 49 4d 45 20 53 69 67 6e 69 6e 67 = "SMIME Signing
1070: 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 ";. } else if
1080: 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 (X509_check_pur
1090: 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f pose(cert, X509_
10a0: 50 55 52 50 4f 53 45 5f 53 4d 49 4d 45 5f 45 4e PURPOSE_SMIME_EN
10b0: 43 52 59 50 54 2c 20 30 29 20 3e 20 30 29 20 7b CRYPT, 0) > 0) {
10c0: 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 53 4d 49 ..purpose = "SMI
10d0: 4d 45 20 45 6e 63 72 79 70 74 69 6f 6e 22 3b 0a ME Encryption";.
10e0: 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 } else if (X
10f0: 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 509_check_purpos
1100: 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 e(cert, X509_PUR
1110: 50 4f 53 45 5f 43 52 4c 5f 53 49 47 4e 2c 20 30 POSE_CRL_SIGN, 0
1120: 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 ) > 0) {..purpos
1130: 65 20 3d 20 22 43 52 4c 20 53 69 67 6e 69 6e 67 e = "CRL Signing
1140: 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 ";. } else if
1150: 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 (X509_check_pur
1160: 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f pose(cert, X509_
1170: 50 55 52 50 4f 53 45 5f 41 4e 59 2c 20 30 29 20 PURPOSE_ANY, 0)
1180: 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 > 0) {..purpose
1190: 3d 20 22 41 6e 79 22 3b 0a 20 20 20 20 7d 20 65 = "Any";. } e
11a0: 6c 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 lse if (X509_che
11b0: 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c ck_purpose(cert,
11c0: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 4f 43 X509_PURPOSE_OC
11d0: 53 50 5f 48 45 4c 50 45 52 2c 20 30 29 20 3e 20 SP_HELPER, 0) >
11e0: 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 0) {..purpose =
11f0: 22 4f 43 53 50 20 48 65 6c 70 65 72 22 3b 0a 20 "OCSP Helper";.
1200: 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 } else if (X5
1210: 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 09_check_purpose
1220: 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 (cert, X509_PURP
1230: 4f 53 45 5f 54 49 4d 45 53 54 41 4d 50 5f 53 49 OSE_TIMESTAMP_SI
1240: 47 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 GN, 0) > 0) {..p
1250: 75 72 70 6f 73 65 20 3d 20 22 54 69 6d 65 73 74 urpose = "Timest
1260: 61 6d 70 20 53 69 67 6e 69 6e 67 22 3b 0a 20 20 amp Signing";.
1270: 20 20 7d 20 65 6c 73 65 20 7b 0a 09 70 75 72 70 } else {..purp
1280: 6f 73 65 20 3d 20 22 22 3b 0a 20 20 20 20 7d 0a ose = "";. }.
1290: 20 20 20 20 72 65 74 75 72 6e 20 70 75 72 70 6f return purpo
12a0: 73 65 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 46 6f 72 se;.}../*. * For
12b0: 20 65 61 63 68 20 70 75 72 70 6f 73 65 2c 20 67 each purpose, g
12c0: 65 74 20 63 65 72 74 69 66 69 63 61 74 65 20 61 et certificate a
12d0: 70 70 6c 69 63 61 62 69 6c 69 74 79 0a 20 2a 2f pplicability. */
12e0: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 .Tcl_Obj *Tls_x5
12f0: 30 39 50 75 72 70 6f 73 65 73 28 54 63 6c 5f 49 09Purposes(Tcl_I
1300: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 nterp *interp, X
1310: 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 509 *cert) {.
1320: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 Tcl_Obj *listPt
1330: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f r = Tcl_NewListO
1340: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 bj(0, NULL);.
1350: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 20 2a 70 X509_PURPOSE *p
1360: 74 6d 70 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 tmp;.. if (li
1370: 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b stPtr == NULL) {
1380: 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 ..return NULL;.
1390: 20 20 20 7d 0a 0a 20 20 20 20 66 6f 72 20 28 69 }.. for (i
13a0: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 58 35 nt i = 0; i < X5
13b0: 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 74 5f 63 09_PURPOSE_get_c
13c0: 6f 75 6e 74 28 29 3b 20 69 2b 2b 29 20 7b 0a 09 ount(); i++) {..
13d0: 70 74 6d 70 20 3d 20 58 35 30 39 5f 50 55 52 50 ptmp = X509_PURP
13e0: 4f 53 45 5f 67 65 74 30 28 69 29 3b 0a 09 54 63 OSE_get0(i);..Tc
13f0: 6c 5f 4f 62 6a 20 2a 74 6d 70 50 74 72 20 3d 20 l_Obj *tmpPtr =
1400: 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 Tcl_NewListObj(0
1410: 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 66 6f 72 20 28 , NULL);...for (
1420: 69 6e 74 20 6a 20 3d 20 30 3b 20 6a 20 3c 20 32 int j = 0; j < 2
1430: 3b 20 6a 2b 2b 29 20 7b 0a 09 20 20 20 20 69 6e ; j++) {.. in
1440: 74 20 69 64 72 65 74 20 3d 20 58 35 30 39 5f 63 t idret = X509_c
1450: 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 heck_purpose(cer
1460: 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f t, X509_PURPOSE_
1470: 67 65 74 5f 69 64 28 70 74 6d 70 29 2c 20 6a 29 get_id(ptmp), j)
1480: 3b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f ;.. Tcl_ListO
1490: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 bjAppendElement(
14a0: 69 6e 74 65 72 70 2c 20 74 6d 70 50 74 72 2c 20 interp, tmpPtr,
14b0: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a Tcl_NewStringObj
14c0: 28 6a 20 3f 20 22 43 41 22 20 3a 20 22 6e 6f 6e (j ? "CA" : "non
14d0: 43 41 22 2c 20 2d 31 29 29 3b 0a 09 20 20 20 20 CA", -1));..
14e0: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e Tcl_ListObjAppen
14f0: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c dElement(interp,
1500: 20 74 6d 70 50 74 72 2c 20 54 63 6c 5f 4e 65 77 tmpPtr, Tcl_New
1510: 53 74 72 69 6e 67 4f 62 6a 28 69 64 72 65 74 20 StringObj(idret
1520: 3d 3d 20 31 20 3f 20 22 59 65 73 22 20 3a 20 22 == 1 ? "Yes" : "
1530: 4e 6f 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 4c No", -1));..}..L
1540: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 APPEND_OBJ(inter
1550: 70 2c 20 6c 69 73 74 50 74 72 2c 20 58 35 30 39 p, listPtr, X509
1560: 5f 50 55 52 50 4f 53 45 5f 67 65 74 30 5f 6e 61 _PURPOSE_get0_na
1570: 6d 65 28 70 74 6d 70 29 2c 20 74 6d 70 50 74 72 me(ptmp), tmpPtr
1580: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 );. }. ret
1590: 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a urn listPtr;.}..
15a0: 2f 2a 0a 20 2a 20 47 65 74 20 53 75 62 6a 65 63 /*. * Get Subjec
15b0: 74 20 41 6c 74 65 72 6e 61 74 65 20 4e 61 6d 65 t Alternate Name
15c0: 73 20 28 53 41 4e 29 20 61 6e 64 20 49 73 73 75 s (SAN) and Issu
15d0: 65 72 20 41 6c 74 65 72 6e 61 74 65 20 4e 61 6d er Alternate Nam
15e0: 65 73 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a es. */.Tcl_Obj *
15f0: 54 6c 73 5f 78 35 30 39 4e 61 6d 65 73 28 54 63 Tls_x509Names(Tc
1600: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 l_Interp *interp
1610: 2c 20 58 35 30 39 20 2a 63 65 72 74 2c 20 69 6e , X509 *cert, in
1620: 74 20 6e 69 64 2c 20 42 49 4f 20 2a 62 69 6f 29 t nid, BIO *bio)
1630: 20 7b 0a 20 20 20 20 53 54 41 43 4b 5f 4f 46 28 {. STACK_OF(
1640: 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 29 20 2a 6e GENERAL_NAME) *n
1650: 61 6d 65 73 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 ames;. Tcl_Ob
1660: 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 63 6c j *listPtr = Tcl
1670: 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e _NewListObj(0, N
1680: 55 4c 4c 29 3b 0a 20 20 20 20 69 6e 74 20 6c 65 ULL);. int le
1690: 6e 3b 0a 20 20 20 20 63 68 61 72 20 62 75 66 66 n;. char buff
16a0: 65 72 5b 31 30 32 34 5d 3b 0a 0a 20 20 20 20 69 er[1024];.. i
16b0: 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 f (listPtr == NU
16c0: 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 LL) {..return NU
16d0: 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 LL;. }.. i
16e0: 66 20 28 6e 61 6d 65 73 20 3d 20 58 35 30 39 5f f (names = X509_
16f0: 67 65 74 5f 65 78 74 5f 64 32 69 28 63 65 72 74 get_ext_d2i(cert
1700: 2c 20 6e 69 64 2c 20 4e 55 4c 4c 2c 20 4e 55 4c , nid, NULL, NUL
1710: 4c 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20 L)) {..for (int
1720: 69 3d 30 3b 20 69 20 3c 20 73 6b 5f 47 45 4e 45 i=0; i < sk_GENE
1730: 52 41 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 6e 61 6d RAL_NAME_num(nam
1740: 65 73 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 es); i++) {..
1750: 20 63 6f 6e 73 74 20 47 45 4e 45 52 41 4c 5f 4e const GENERAL_N
1760: 41 4d 45 20 2a 6e 61 6d 65 20 3d 20 73 6b 5f 47 AME *name = sk_G
1770: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75 ENERAL_NAME_valu
1780: 65 28 6e 61 6d 65 73 2c 20 69 29 3b 0a 0a 09 20 e(names, i);...
1790: 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f len = BIO_to_
17a0: 42 75 66 66 65 72 28 6e 61 6d 65 20 26 26 20 47 Buffer(name && G
17b0: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 70 72 69 6e ENERAL_NAME_prin
17c0: 74 28 62 69 6f 2c 20 6e 61 6d 65 29 2c 20 62 69 t(bio, name), bi
17d0: 6f 2c 20 62 75 66 66 65 72 2c 20 31 30 32 34 29 o, buffer, 1024)
17e0: 3b 0a 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 ;.. LAPPEND_S
17f0: 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 TR(interp, listP
1800: 74 72 2c 20 4e 55 4c 4c 2c 20 62 75 66 66 65 72 tr, NULL, buffer
1810: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e , (Tcl_Size) len
1820: 29 3b 0a 09 7d 0a 09 73 6b 5f 47 45 4e 45 52 41 );..}..sk_GENERA
1830: 4c 5f 4e 41 4d 45 5f 70 6f 70 5f 66 72 65 65 28 L_NAME_pop_free(
1840: 6e 61 6d 65 73 2c 20 47 45 4e 45 52 41 4c 5f 4e names, GENERAL_N
1850: 41 4d 45 5f 66 72 65 65 29 3b 0a 20 20 20 20 7d AME_free);. }
1860: 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74 . return list
1870: 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 Ptr;.}../*. * Ge
1880: 74 20 45 58 74 65 6e 64 65 64 20 4b 65 79 20 55 t EXtended Key U
1890: 73 61 67 65 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a sage. */.Tcl_Obj
18a0: 20 2a 54 6c 73 5f 78 35 30 39 45 78 74 4b 65 79 *Tls_x509ExtKey
18b0: 55 73 61 67 65 28 54 63 6c 5f 49 6e 74 65 72 70 Usage(Tcl_Interp
18c0: 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a *interp, X509 *
18d0: 63 65 72 74 2c 20 75 69 6e 74 33 32 5f 74 20 78 cert, uint32_t x
18e0: 66 6c 61 67 73 29 20 7b 0a 20 20 20 20 75 69 6e flags) {. uin
18f0: 74 33 32 5f 74 20 75 73 61 67 65 20 3d 20 58 35 t32_t usage = X5
1900: 30 39 5f 67 65 74 5f 6b 65 79 5f 75 73 61 67 65 09_get_key_usage
1910: 28 63 65 72 74 29 3b 0a 20 20 20 20 54 63 6c 5f (cert);. Tcl_
1920: 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 Obj *listPtr = T
1930: 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c cl_NewListObj(0,
1940: 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20 NULL);.. if
1950: 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c (listPtr == NULL
1960: 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c ) {..return NULL
1970: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 ;. }.. if
1980: 28 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 ((xflags & EXFLA
1990: 47 5f 58 4b 55 53 41 47 45 29 20 26 26 20 75 73 G_XKUSAGE) && us
19a0: 61 67 65 20 3c 20 55 49 4e 54 33 32 5f 4d 41 58 age < UINT32_MAX
19b0: 29 20 7b 0a 09 75 73 61 67 65 20 3d 20 58 35 30 ) {..usage = X50
19c0: 39 5f 67 65 74 5f 65 78 74 65 6e 64 65 64 5f 6b 9_get_extended_k
19d0: 65 79 5f 75 73 61 67 65 28 63 65 72 74 29 3b 0a ey_usage(cert);.
19e0: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b ..if (usage & XK
19f0: 55 5f 53 53 4c 5f 53 45 52 56 45 52 29 20 7b 0a U_SSL_SERVER) {.
1a00: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
1a10: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
1a20: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 terp, listPtr, T
1a30: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
1a40: 22 54 4c 53 20 57 65 62 20 53 65 72 76 65 72 20 "TLS Web Server
1a50: 41 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 22 2c Authentication",
1a60: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 -1));..}..if (u
1a70: 73 61 67 65 20 26 20 58 4b 55 5f 53 53 4c 5f 43 sage & XKU_SSL_C
1a80: 4c 49 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 LIENT) {.. Tc
1a90: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
1aa0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
1ab0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
1ac0: 74 72 69 6e 67 4f 62 6a 28 22 54 4c 53 20 57 65 tringObj("TLS We
1ad0: 62 20 43 6c 69 65 6e 74 20 41 75 74 68 65 6e 74 b Client Authent
1ae0: 69 63 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a ication", -1));.
1af0: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 .}..if (usage &
1b00: 58 4b 55 5f 53 4d 49 4d 45 29 20 7b 0a 09 20 20 XKU_SMIME) {..
1b10: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
1b20: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
1b30: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f p, listPtr, Tcl_
1b40: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 45 2d NewStringObj("E-
1b50: 6d 61 69 6c 20 50 72 6f 74 65 63 74 69 6f 6e 22 mail Protection"
1b60: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 , -1));..}..if (
1b70: 75 73 61 67 65 20 26 20 58 4b 55 5f 43 4f 44 45 usage & XKU_CODE
1b80: 5f 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 _SIGN) {.. Tc
1b90: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
1ba0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
1bb0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
1bc0: 74 72 69 6e 67 4f 62 6a 28 22 43 6f 64 65 20 53 tringObj("Code S
1bd0: 69 67 6e 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 igning", -1));..
1be0: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58 }..if (usage & X
1bf0: 4b 55 5f 53 47 43 29 20 7b 0a 09 20 20 20 20 54 KU_SGC) {.. T
1c00: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
1c10: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
1c20: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
1c30: 53 74 72 69 6e 67 4f 62 6a 28 22 53 47 43 22 2c StringObj("SGC",
1c40: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 -1));..}..if (u
1c50: 73 61 67 65 20 26 20 58 4b 55 5f 4f 43 53 50 5f sage & XKU_OCSP_
1c60: 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c SIGN) {.. Tcl
1c70: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
1c80: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 ement(interp, li
1c90: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 stPtr, Tcl_NewSt
1ca0: 72 69 6e 67 4f 62 6a 28 22 4f 43 53 50 20 53 69 ringObj("OCSP Si
1cb0: 67 6e 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d gning", -1));..}
1cc0: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b ..if (usage & XK
1cd0: 55 5f 54 49 4d 45 53 54 41 4d 50 29 20 7b 0a 09 U_TIMESTAMP) {..
1ce0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
1cf0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
1d00: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 erp, listPtr, Tc
1d10: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
1d20: 54 69 6d 65 20 53 74 61 6d 70 69 6e 67 22 2c 20 Time Stamping",
1d30: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 -1));..}..if (us
1d40: 61 67 65 20 26 20 58 4b 55 5f 44 56 43 53 20 29 age & XKU_DVCS )
1d50: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 {.. Tcl_List
1d60: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 ObjAppendElement
1d70: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 (interp, listPtr
1d80: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f , Tcl_NewStringO
1d90: 62 6a 28 22 44 56 43 53 22 2c 20 2d 31 29 29 3b bj("DVCS", -1));
1da0: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
1db0: 20 58 4b 55 5f 41 4e 59 45 4b 55 29 20 7b 0a 09 XKU_ANYEKU) {..
1dc0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
1dd0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
1de0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 erp, listPtr, Tc
1df0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
1e00: 41 6e 79 20 45 78 74 65 6e 64 65 64 20 4b 65 79 Any Extended Key
1e10: 20 55 73 61 67 65 22 2c 20 2d 31 29 29 3b 0a 09 Usage", -1));..
1e20: 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 }. } else {..
1e30: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
1e40: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
1e50: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 erp, listPtr, Tc
1e60: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
1e70: 75 6e 72 65 73 74 72 69 63 74 65 64 22 2c 20 2d unrestricted", -
1e80: 31 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 1));. }. r
1e90: 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d eturn listPtr;.}
1ea0: 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 52 4c 20 ../*. * Get CRL
1eb0: 44 69 73 74 72 69 62 75 74 69 6f 6e 20 50 6f 69 Distribution Poi
1ec0: 6e 74 73 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 nts. */.Tcl_Obj
1ed0: 2a 54 6c 73 5f 78 35 30 39 43 72 6c 44 70 28 54 *Tls_x509CrlDp(T
1ee0: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 cl_Interp *inter
1ef0: 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b p, X509 *cert) {
1f00: 0a 20 20 20 20 53 54 41 43 4b 5f 4f 46 28 44 49 . STACK_OF(DI
1f10: 53 54 5f 50 4f 49 4e 54 29 20 2a 63 72 6c 3b 0a ST_POINT) *crl;.
1f20: 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 Tcl_Obj *lis
1f30: 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 tPtr = Tcl_NewLi
1f40: 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a stObj(0, NULL);.
1f50: 0a 20 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 . if (listPtr
1f60: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 == NULL) {..ret
1f70: 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a urn NULL;. }.
1f80: 0a 20 20 20 20 69 66 20 28 63 72 6c 20 3d 20 58 . if (crl = X
1f90: 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 28 509_get_ext_d2i(
1fa0: 63 65 72 74 2c 20 4e 49 44 5f 63 72 6c 5f 64 69 cert, NID_crl_di
1fb0: 73 74 72 69 62 75 74 69 6f 6e 5f 70 6f 69 6e 74 stribution_point
1fc0: 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 29 20 s, NULL, NULL))
1fd0: 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 3d 30 3b {..for (int i=0;
1fe0: 20 69 20 3c 20 73 6b 5f 44 49 53 54 5f 50 4f 49 i < sk_DIST_POI
1ff0: 4e 54 5f 6e 75 6d 28 63 72 6c 29 3b 20 69 2b 2b NT_num(crl); i++
2000: 29 20 7b 0a 09 20 20 20 20 44 49 53 54 5f 50 4f ) {.. DIST_PO
2010: 49 4e 54 20 2a 64 70 20 3d 20 73 6b 5f 44 49 53 INT *dp = sk_DIS
2020: 54 5f 50 4f 49 4e 54 5f 76 61 6c 75 65 28 63 72 T_POINT_value(cr
2030: 6c 2c 20 69 29 3b 0a 09 20 20 20 20 44 49 53 54 l, i);.. DIST
2040: 5f 50 4f 49 4e 54 5f 4e 41 4d 45 20 2a 64 69 73 _POINT_NAME *dis
2050: 74 70 6f 69 6e 74 20 3d 20 64 70 2d 3e 64 69 73 tpoint = dp->dis
2060: 74 70 6f 69 6e 74 3b 0a 0a 09 20 20 20 20 69 66 tpoint;... if
2070: 20 28 64 69 73 74 70 6f 69 6e 74 2d 3e 74 79 70 (distpoint->typ
2080: 65 20 3d 3d 20 30 29 20 7b 0a 09 09 2f 2a 20 66 e == 0) {.../* f
2090: 75 6c 6c 2d 6e 61 6d 65 20 47 45 4e 45 52 41 4c ull-name GENERAL
20a0: 49 5a 45 44 4e 41 4d 45 20 2a 2f 0a 09 09 66 6f IZEDNAME */...fo
20b0: 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20 6a 20 r (int j = 0; j
20c0: 3c 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d < sk_GENERAL_NAM
20d0: 45 5f 6e 75 6d 28 64 69 73 74 70 6f 69 6e 74 2d E_num(distpoint-
20e0: 3e 6e 61 6d 65 2e 66 75 6c 6c 6e 61 6d 65 29 3b >name.fullname);
20f0: 20 6a 2b 2b 29 20 7b 0a 09 09 20 20 20 20 47 45 j++) {... GE
2100: 4e 45 52 41 4c 5f 4e 41 4d 45 20 2a 67 65 6e 20 NERAL_NAME *gen
2110: 3d 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d = sk_GENERAL_NAM
2120: 45 5f 76 61 6c 75 65 28 64 69 73 74 70 6f 69 6e E_value(distpoin
2130: 74 2d 3e 6e 61 6d 65 2e 66 75 6c 6c 6e 61 6d 65 t->name.fullname
2140: 2c 20 6a 29 3b 0a 09 09 20 20 20 20 69 6e 74 20 , j);... int
2150: 74 79 70 65 3b 0a 09 09 20 20 20 20 41 53 4e 31 type;... ASN1
2160: 5f 53 54 52 49 4e 47 20 2a 75 72 69 20 3d 20 47 _STRING *uri = G
2170: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 67 65 74 30 ENERAL_NAME_get0
2180: 5f 76 61 6c 75 65 28 67 65 6e 2c 20 26 74 79 70 _value(gen, &typ
2190: 65 29 3b 0a 09 09 20 20 20 20 69 66 20 28 74 79 e);... if (ty
21a0: 70 65 20 3d 3d 20 47 45 4e 5f 55 52 49 29 20 7b pe == GEN_URI) {
21b0: 0a 09 09 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 ....LAPPEND_STR(
21c0: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
21d0: 20 4e 55 4c 4c 2c 20 41 53 4e 31 5f 53 54 52 49 NULL, ASN1_STRI
21e0: 4e 47 5f 67 65 74 30 5f 64 61 74 61 28 75 72 69 NG_get0_data(uri
21f0: 29 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 41 53 ), (Tcl_Size) AS
2200: 4e 31 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 N1_STRING_length
2210: 28 75 72 69 29 29 3b 0a 09 09 20 20 20 20 7d 0a (uri));... }.
2220: 09 09 7d 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 ..}.. } else
2230: 69 66 20 28 64 69 73 74 70 6f 69 6e 74 2d 3e 74 if (distpoint->t
2240: 79 70 65 20 3d 3d 20 31 29 20 7b 0a 09 09 2f 2a ype == 1) {.../*
2250: 20 72 65 6c 61 74 69 76 65 2d 6e 61 6d 65 20 58 relative-name X
2260: 35 30 39 4e 41 4d 45 20 2a 2f 0a 09 09 53 54 41 509NAME */...STA
2270: 43 4b 5f 4f 46 28 58 35 30 39 5f 4e 41 4d 45 5f CK_OF(X509_NAME_
2280: 45 4e 54 52 59 29 20 2a 73 6b 5f 72 65 6c 6e 61 ENTRY) *sk_relna
2290: 6d 65 20 3d 20 64 69 73 74 70 6f 69 6e 74 2d 3e me = distpoint->
22a0: 6e 61 6d 65 2e 72 65 6c 61 74 69 76 65 6e 61 6d name.relativenam
22b0: 65 3b 0a 09 09 66 6f 72 20 28 69 6e 74 20 6a 20 e;...for (int j
22c0: 3d 20 30 3b 20 6a 20 3c 20 73 6b 5f 58 35 30 39 = 0; j < sk_X509
22d0: 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 6e 75 6d 28 _NAME_ENTRY_num(
22e0: 73 6b 5f 72 65 6c 6e 61 6d 65 29 3b 20 6a 2b 2b sk_relname); j++
22f0: 29 20 7b 0a 09 09 20 20 20 20 58 35 30 39 5f 4e ) {... X509_N
2300: 41 4d 45 5f 45 4e 54 52 59 20 2a 65 20 3d 20 73 AME_ENTRY *e = s
2310: 6b 5f 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 k_X509_NAME_ENTR
2320: 59 5f 76 61 6c 75 65 28 73 6b 5f 72 65 6c 6e 61 Y_value(sk_relna
2330: 6d 65 2c 20 6a 29 3b 0a 09 09 20 20 20 20 41 53 me, j);... AS
2340: 4e 31 5f 53 54 52 49 4e 47 20 2a 64 20 3d 20 58 N1_STRING *d = X
2350: 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 67 509_NAME_ENTRY_g
2360: 65 74 5f 64 61 74 61 28 65 29 3b 0a 09 09 20 20 et_data(e);...
2370: 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e LAPPEND_STR(in
2380: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 4e terp, listPtr, N
2390: 55 4c 4c 2c 20 41 53 4e 31 5f 53 54 52 49 4e 47 ULL, ASN1_STRING
23a0: 5f 64 61 74 61 28 64 29 2c 20 28 54 63 6c 5f 53 _data(d), (Tcl_S
23b0: 69 7a 65 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 ize) ASN1_STRING
23c0: 5f 6c 65 6e 67 74 68 28 64 29 29 3b 0a 09 09 7d _length(d));...}
23d0: 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 43 52 4c 5f .. }..}..CRL_
23e0: 44 49 53 54 5f 50 4f 49 4e 54 53 5f 66 72 65 65 DIST_POINTS_free
23f0: 28 63 72 6c 29 3b 0a 20 20 20 20 7d 0a 20 20 20 (crl);. }.
2400: 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b return listPtr;
2410: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 4f 6e .}../*. * Get On
2420: 2d 6c 69 6e 65 20 43 65 72 74 69 66 69 63 61 74 -line Certificat
2430: 65 20 53 74 61 74 75 73 20 50 72 6f 74 6f 63 6f e Status Protoco
2440: 6c 20 28 4f 53 43 50 29 20 55 52 4c 0a 20 2a 2f l (OSCP) URL. */
2450: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 .Tcl_Obj *Tls_x5
2460: 30 39 4f 73 63 70 28 54 63 6c 5f 49 6e 74 65 72 09Oscp(Tcl_Inter
2470: 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 p *interp, X509
2480: 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 53 54 41 *cert) {. STA
2490: 43 4b 5f 4f 46 28 4f 50 45 4e 53 53 4c 5f 53 54 CK_OF(OPENSSL_ST
24a0: 52 49 4e 47 29 20 2a 6f 63 73 70 3b 0a 20 20 20 RING) *ocsp;.
24b0: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 Tcl_Obj *listPt
24c0: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f r = Tcl_NewListO
24d0: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 bj(0, NULL);..
24e0: 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d if (listPtr ==
24f0: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e NULL) {..return
2500: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 NULL;. }..
2510: 20 20 69 66 20 28 6f 63 73 70 20 3d 20 58 35 30 if (ocsp = X50
2520: 39 5f 67 65 74 31 5f 6f 63 73 70 28 63 65 72 74 9_get1_ocsp(cert
2530: 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 )) {..for (int i
2540: 20 3d 20 30 3b 20 69 20 3c 20 73 6b 5f 4f 50 45 = 0; i < sk_OPE
2550: 4e 53 53 4c 5f 53 54 52 49 4e 47 5f 6e 75 6d 28 NSSL_STRING_num(
2560: 6f 63 73 70 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 ocsp); i++) {..
2570: 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 LAPPEND_STR(i
2580: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 nterp, listPtr,
2590: 4e 55 4c 4c 2c 20 73 6b 5f 4f 50 45 4e 53 53 4c NULL, sk_OPENSSL
25a0: 5f 53 54 52 49 4e 47 5f 76 61 6c 75 65 28 6f 63 _STRING_value(oc
25b0: 73 70 2c 20 69 29 2c 20 2d 31 29 3b 0a 09 7d 0a sp, i), -1);..}.
25c0: 09 58 35 30 39 5f 65 6d 61 69 6c 5f 66 72 65 65 .X509_email_free
25d0: 28 6f 63 73 70 29 3b 0a 20 20 20 20 7d 0a 20 20 (ocsp);. }.
25e0: 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 return listPtr
25f0: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 ;.}../*. * Get C
2600: 65 72 74 69 66 69 63 61 74 65 20 41 75 74 68 6f ertificate Autho
2610: 72 69 74 79 20 28 43 41 29 20 49 73 73 75 65 72 rity (CA) Issuer
2620: 73 20 55 52 4c 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 s URL. */.Tcl_Ob
2630: 6a 20 2a 54 6c 73 5f 78 35 30 39 43 61 49 73 73 j *Tls_x509CaIss
2640: 75 65 72 73 28 54 63 6c 5f 49 6e 74 65 72 70 20 uers(Tcl_Interp
2650: 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 *interp, X509 *c
2660: 65 72 74 29 20 7b 0a 20 20 20 20 53 54 41 43 4b ert) {. STACK
2670: 5f 4f 46 28 41 43 43 45 53 53 5f 44 45 53 43 52 _OF(ACCESS_DESCR
2680: 49 50 54 49 4f 4e 29 20 2a 61 64 73 3b 0a 20 20 IPTION) *ads;.
2690: 20 20 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 ACCESS_DESCRIP
26a0: 54 49 4f 4e 20 2a 61 64 3b 0a 20 20 20 20 54 63 TION *ad;. Tc
26b0: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d l_Obj *listPtr =
26c0: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 Tcl_NewListObj(
26d0: 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 75 6e 0, NULL);. un
26e0: 73 69 67 6e 65 64 20 63 68 61 72 20 2a 62 75 66 signed char *buf
26f0: 3b 0a 20 20 20 20 69 6e 74 20 6c 65 6e 3b 0a 0a ;. int len;..
2700: 20 20 20 20 69 66 20 28 61 64 73 20 3d 20 58 35 if (ads = X5
2710: 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 28 63 09_get_ext_d2i(c
2720: 65 72 74 2c 20 4e 49 44 5f 69 6e 66 6f 5f 61 63 ert, NID_info_ac
2730: 63 65 73 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c cess, NULL, NULL
2740: 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 )) {..for (int i
2750: 20 3d 20 30 3b 20 69 20 3c 20 73 6b 5f 41 43 43 = 0; i < sk_ACC
2760: 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f 4e 5f ESS_DESCRIPTION_
2770: 6e 75 6d 28 61 64 73 29 3b 20 69 2b 2b 29 20 7b num(ads); i++) {
2780: 0a 09 20 20 20 20 61 64 20 3d 20 73 6b 5f 41 43 .. ad = sk_AC
2790: 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f 4e CESS_DESCRIPTION
27a0: 5f 76 61 6c 75 65 28 61 64 73 2c 20 69 29 3b 0a _value(ads, i);.
27b0: 09 20 20 20 20 69 66 20 28 4f 42 4a 5f 6f 62 6a . if (OBJ_obj
27c0: 32 6e 69 64 28 61 64 2d 3e 6d 65 74 68 6f 64 29 2nid(ad->method)
27d0: 20 3d 3d 20 4e 49 44 5f 61 64 5f 63 61 5f 69 73 == NID_ad_ca_is
27e0: 73 75 65 72 73 20 26 26 20 61 64 2d 3e 6c 6f 63 suers && ad->loc
27f0: 61 74 69 6f 6e 29 20 7b 0a 09 09 69 66 20 28 61 ation) {...if (a
2800: 64 2d 3e 6c 6f 63 61 74 69 6f 6e 2d 3e 74 79 70 d->location->typ
2810: 65 20 3d 3d 20 47 45 4e 5f 55 52 49 29 20 7b 0a e == GEN_URI) {.
2820: 09 09 20 20 20 20 6c 65 6e 20 3d 20 41 53 4e 31 .. len = ASN1
2830: 5f 53 54 52 49 4e 47 5f 74 6f 5f 55 54 46 38 28 _STRING_to_UTF8(
2840: 26 62 75 66 2c 20 61 64 2d 3e 6c 6f 63 61 74 69 &buf, ad->locati
2850: 6f 6e 2d 3e 64 2e 75 6e 69 66 6f 72 6d 52 65 73 on->d.uniformRes
2860: 6f 75 72 63 65 49 64 65 6e 74 69 66 69 65 72 29 ourceIdentifier)
2870: 3b 0a 09 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 ;... Tcl_List
2880: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 ObjAppendElement
2890: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 (interp, listPtr
28a0: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f , Tcl_NewStringO
28b0: 62 6a 28 62 75 66 2c 20 28 54 63 6c 5f 53 69 7a bj(buf, (Tcl_Siz
28c0: 65 29 20 6c 65 6e 29 29 3b 0a 09 09 20 20 20 20 e) len));...
28d0: 4f 50 45 4e 53 53 4c 5f 66 72 65 65 28 62 75 66 OPENSSL_free(buf
28e0: 29 3b 0a 09 09 20 20 20 20 62 72 65 61 6b 3b 0a );... break;.
28f0: 09 09 7d 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 2f ..}.. }..}../
2900: 2a 20 73 6b 5f 41 43 43 45 53 53 5f 44 45 53 43 * sk_ACCESS_DESC
2910: 52 49 50 54 49 4f 4e 5f 70 6f 70 5f 66 72 65 65 RIPTION_pop_free
2920: 28 61 64 73 2c 20 41 43 43 45 53 53 5f 44 45 53 (ads, ACCESS_DES
2930: 43 52 49 50 54 49 4f 4e 5f 66 72 65 65 29 3b 20 CRIPTION_free);
2940: 2a 2f 0a 09 41 55 54 48 4f 52 49 54 59 5f 49 4e */..AUTHORITY_IN
2950: 46 4f 5f 41 43 43 45 53 53 5f 66 72 65 65 28 61 FO_ACCESS_free(a
2960: 64 73 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 ds);. }. r
2970: 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d eturn listPtr;.}
2980: 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d .../*. *--------
2990: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
29a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
29b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2a 0a --------------*.
29c0: 20 2a 0a 20 2a 09 54 6c 73 5f 4e 65 77 58 35 30 *. *.Tls_NewX50
29d0: 39 4f 62 6a 20 2d 2d 0a 20 2a 0a 20 2a 09 2d 2d 9Obj --. *. *.--
29e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
29f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2a 0a --------------*.
2a10: 20 2a 09 43 6f 6e 76 65 72 74 73 20 61 20 58 35 *.Converts a X5
2a20: 30 39 20 63 65 72 74 69 66 69 63 61 74 65 20 69 09 certificate i
2a30: 6e 74 6f 20 61 20 54 63 6c 5f 4f 62 6a 0a 20 2a nto a Tcl_Obj. *
2a40: 09 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d .---------------
2a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a70: 2d 2a 0a 20 2a 0a 20 2a 09 53 69 64 65 20 65 66 -*. *. *.Side ef
2a80: 66 65 63 74 73 3a 0a 20 2a 09 09 4e 6f 6e 65 0a fects:. *..None.
2a90: 20 2a 0a 20 2a 09 52 65 73 75 6c 74 3a 0a 20 2a *. *.Result:. *
2aa0: 09 09 41 20 54 63 6c 20 4c 69 73 74 20 4f 62 6a ..A Tcl List Obj
2ab0: 65 63 74 20 72 65 70 72 65 73 65 6e 74 69 6e 67 ect representing
2ac0: 20 74 68 65 20 70 72 6f 76 69 64 65 64 0a 20 2a the provided. *
2ad0: 09 09 58 35 30 39 20 63 65 72 74 69 66 69 63 61 ..X509 certifica
2ae0: 74 65 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d 2d 2d 2d te.. *. *-------
2af0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2b00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2b10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2a ---------------*
2b20: 0a 20 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a 2a 0a 54 . */..Tcl_Obj*.T
2b30: 6c 73 5f 4e 65 77 58 35 30 39 4f 62 6a 28 54 63 ls_NewX509Obj(Tc
2b40: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 l_Interp *interp
2b50: 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a , X509 *cert) {.
2b60: 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 63 65 72 Tcl_Obj *cer
2b70: 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 tPtr = Tcl_NewLi
2b80: 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a stObj(0, NULL);.
2b90: 20 20 20 20 42 49 4f 20 2a 62 69 6f 20 3d 20 42 BIO *bio = B
2ba0: 49 4f 5f 6e 65 77 28 42 49 4f 5f 73 5f 6d 65 6d IO_new(BIO_s_mem
2bb0: 28 29 29 3b 0a 20 20 20 20 69 6e 74 20 6d 64 6e ());. int mdn
2bc0: 69 64 2c 20 70 6b 6e 69 64 2c 20 62 69 74 73 2c id, pknid, bits,
2bd0: 20 6c 65 6e 3b 0a 20 20 20 20 75 69 6e 74 33 32 len;. uint32
2be0: 5f 74 20 78 66 6c 61 67 73 3b 0a 20 20 20 20 63 _t xflags;. c
2bf0: 68 61 72 20 62 75 66 66 65 72 5b 42 55 46 53 49 har buffer[BUFSI
2c00: 5a 5d 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 Z];. unsigned
2c10: 20 63 68 61 72 20 6d 64 5b 45 56 50 5f 4d 41 58 char md[EVP_MAX
2c20: 5f 4d 44 5f 53 49 5a 45 5d 3b 0a 20 20 20 20 75 _MD_SIZE];. u
2c30: 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 66 6c 61 nsigned long fla
2c40: 67 73 20 3d 20 58 4e 5f 46 4c 41 47 5f 52 46 43 gs = XN_FLAG_RFC
2c50: 32 32 35 33 20 7c 20 41 53 4e 31 5f 53 54 52 46 2253 | ASN1_STRF
2c60: 4c 47 53 5f 55 54 46 38 5f 43 4f 4e 56 45 52 54 LGS_UTF8_CONVERT
2c70: 3b 0a 20 20 20 20 66 6c 61 67 73 20 26 3d 20 7e ;. flags &= ~
2c80: 41 53 4e 31 5f 53 54 52 46 4c 47 53 5f 45 53 43 ASN1_STRFLGS_ESC
2c90: 5f 4d 53 42 3b 0a 0a 20 20 20 20 69 66 20 28 69 _MSB;.. if (i
2ca0: 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 20 7c 7c nterp == NULL ||
2cb0: 20 63 65 72 74 20 3d 3d 20 4e 55 4c 4c 20 7c 7c cert == NULL ||
2cc0: 20 62 69 6f 20 3d 3d 20 4e 55 4c 4c 20 7c 7c 20 bio == NULL ||
2cd0: 63 65 72 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 certPtr == NULL)
2ce0: 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b {..return NULL;
2cf0: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 . }.. /* S
2d00: 69 67 6e 61 74 75 72 65 20 61 6c 67 6f 72 69 74 ignature algorit
2d10: 68 6d 20 61 6e 64 20 76 61 6c 75 65 20 2d 20 52 hm and value - R
2d20: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 FC 5280 section
2d30: 34 2e 31 2e 31 2e 32 20 61 6e 64 20 34 2e 31 2e 4.1.1.2 and 4.1.
2d40: 31 2e 33 20 2a 2f 0a 20 20 20 20 2f 2a 20 73 69 1.3 */. /* si
2d50: 67 6e 61 74 75 72 65 41 6c 67 6f 72 69 74 68 6d gnatureAlgorithm
2d60: 20 69 73 20 74 68 65 20 69 64 20 6f 66 20 74 68 is the id of th
2d70: 65 20 63 72 79 70 74 6f 67 72 61 70 68 69 63 20 e cryptographic
2d80: 61 6c 67 6f 72 69 74 68 6d 20 75 73 65 64 20 62 algorithm used b
2d90: 79 20 74 68 65 0a 09 43 41 20 74 6f 20 73 69 67 y the..CA to sig
2da0: 6e 20 74 68 69 73 20 63 65 72 74 2e 20 73 69 67 n this cert. sig
2db0: 6e 61 74 75 72 65 56 61 6c 75 65 20 69 73 20 74 natureValue is t
2dc0: 68 65 20 64 69 67 69 74 61 6c 20 73 69 67 6e 61 he digital signa
2dd0: 74 75 72 65 20 63 6f 6d 70 75 74 65 64 0a 09 75 ture computed..u
2de0: 70 6f 6e 20 74 68 65 20 41 53 4e 2e 31 20 44 45 pon the ASN.1 DE
2df0: 52 20 65 6e 63 6f 64 65 64 20 74 62 73 43 65 72 R encoded tbsCer
2e00: 74 69 66 69 63 61 74 65 2e 20 2a 2f 0a 20 20 20 tificate. */.
2e10: 20 7b 0a 09 63 6f 6e 73 74 20 58 35 30 39 5f 41 {..const X509_A
2e20: 4c 47 4f 52 20 2a 73 69 67 5f 61 6c 67 3b 0a 09 LGOR *sig_alg;..
2e30: 63 6f 6e 73 74 20 41 53 4e 31 5f 42 49 54 5f 53 const ASN1_BIT_S
2e40: 54 52 49 4e 47 20 2a 73 69 67 3b 0a 09 69 6e 74 TRING *sig;..int
2e50: 20 73 69 67 5f 6e 69 64 3b 0a 0a 09 58 35 30 39 sig_nid;...X509
2e60: 5f 67 65 74 30 5f 73 69 67 6e 61 74 75 72 65 28 _get0_signature(
2e70: 26 73 69 67 2c 20 26 73 69 67 5f 61 6c 67 2c 20 &sig, &sig_alg,
2e80: 63 65 72 74 29 3b 0a 09 2f 2a 20 73 69 67 5f 6e cert);../* sig_n
2e90: 69 64 20 3d 20 58 35 30 39 5f 67 65 74 5f 73 69 id = X509_get_si
2ea0: 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 72 74 gnature_nid(cert
2eb0: 29 20 2a 2f 0a 09 73 69 67 5f 6e 69 64 20 3d 20 ) */..sig_nid =
2ec0: 4f 42 4a 5f 6f 62 6a 32 6e 69 64 28 73 69 67 5f OBJ_obj2nid(sig_
2ed0: 61 6c 67 2d 3e 61 6c 67 6f 72 69 74 68 6d 29 3b alg->algorithm);
2ee0: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e ..LAPPEND_STR(in
2ef0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
2f00: 73 69 67 6e 61 74 75 72 65 41 6c 67 6f 72 69 74 signatureAlgorit
2f10: 68 6d 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 hm", OBJ_nid2ln(
2f20: 73 69 67 5f 6e 69 64 29 2c 20 2d 31 29 3b 0a 09 sig_nid), -1);..
2f30: 6c 65 6e 20 3d 20 28 73 69 67 5f 6e 69 64 20 21 len = (sig_nid !
2f40: 3d 20 4e 49 44 5f 75 6e 64 65 66 29 20 3f 20 53 = NID_undef) ? S
2f50: 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 73 69 67 tring_to_Hex(sig
2f60: 2d 3e 64 61 74 61 2c 20 73 69 67 2d 3e 6c 65 6e ->data, sig->len
2f70: 67 74 68 2c 20 62 75 66 66 65 72 2c 20 42 55 46 gth, buffer, BUF
2f80: 53 49 5a 29 20 3a 20 30 3b 0a 09 4c 41 50 50 45 SIZ) : 0;..LAPPE
2f90: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 ND_STR(interp, c
2fa0: 65 72 74 50 74 72 2c 20 22 73 69 67 6e 61 74 75 ertPtr, "signatu
2fb0: 72 65 56 61 6c 75 65 22 2c 20 62 75 66 66 65 72 reValue", buffer
2fc0: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e , (Tcl_Size) len
2fd0: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a );. }.. /*
2fe0: 20 56 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 Version of the
2ff0: 65 6e 63 6f 64 65 64 20 63 65 72 74 69 66 69 63 encoded certific
3000: 61 74 65 20 2d 20 52 46 43 20 35 32 38 30 20 73 ate - RFC 5280 s
3010: 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 31 20 2a ection 4.1.2.1 *
3020: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 4f /. LAPPEND_LO
3030: 4e 47 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 NG(interp, certP
3040: 74 72 2c 20 22 76 65 72 73 69 6f 6e 22 2c 20 58 tr, "version", X
3050: 35 30 39 5f 67 65 74 5f 76 65 72 73 69 6f 6e 28 509_get_version(
3060: 63 65 72 74 29 2b 31 29 3b 0a 0a 20 20 20 20 2f cert)+1);.. /
3070: 2a 20 55 6e 69 71 75 65 20 6e 75 6d 62 65 72 20 * Unique number
3080: 61 73 73 69 67 6e 65 64 20 62 79 20 43 41 20 74 assigned by CA t
3090: 6f 20 63 65 72 74 69 66 69 63 61 74 65 20 2d 20 o certificate -
30a0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
30b0: 20 34 2e 31 2e 32 2e 32 20 2a 2f 0a 20 20 20 20 4.1.2.2 */.
30c0: 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 len = BIO_to_Buf
30d0: 66 65 72 28 69 32 61 5f 41 53 4e 31 5f 49 4e 54 fer(i2a_ASN1_INT
30e0: 45 47 45 52 28 62 69 6f 2c 20 58 35 30 39 5f 67 EGER(bio, X509_g
30f0: 65 74 30 5f 73 65 72 69 61 6c 4e 75 6d 62 65 72 et0_serialNumber
3100: 28 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 (cert)), bio, bu
3110: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 ffer, BUFSIZ);.
3120: 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 LAPPEND_STR(i
3130: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
3140: 22 73 65 72 69 61 6c 4e 75 6d 62 65 72 22 2c 20 "serialNumber",
3150: 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a buffer, (Tcl_Siz
3160: 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a e) len);.. /*
3170: 20 53 69 67 6e 61 74 75 72 65 20 61 6c 67 6f 72 Signature algor
3180: 69 74 68 6d 20 75 73 65 64 20 62 79 20 74 68 65 ithm used by the
3190: 20 43 41 20 74 6f 20 73 69 67 6e 20 74 68 65 20 CA to sign the
31a0: 63 65 72 74 69 66 69 63 61 74 65 2e 20 4d 75 73 certificate. Mus
31b0: 74 20 6d 61 74 63 68 0a 09 73 69 67 6e 61 74 75 t match..signatu
31c0: 72 65 41 6c 67 6f 72 69 74 68 6d 2e 20 52 46 43 reAlgorithm. RFC
31d0: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 5280 section 4.
31e0: 31 2e 32 2e 33 20 2a 2f 0a 20 20 20 20 4c 41 50 1.2.3 */. LAP
31f0: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c PEND_STR(interp,
3200: 20 63 65 72 74 50 74 72 2c 20 22 73 69 67 6e 61 certPtr, "signa
3210: 74 75 72 65 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c ture", OBJ_nid2l
3220: 6e 28 58 35 30 39 5f 67 65 74 5f 73 69 67 6e 61 n(X509_get_signa
3230: 74 75 72 65 5f 6e 69 64 28 63 65 72 74 29 29 2c ture_nid(cert)),
3240: 20 2d 31 29 3b 0a 0a 20 20 20 20 2f 2a 20 49 73 -1);.. /* Is
3250: 73 75 65 72 20 69 64 65 6e 74 69 66 69 65 73 20 suer identifies
3260: 74 68 65 20 65 6e 74 69 74 79 20 74 68 61 74 20 the entity that
3270: 73 69 67 6e 65 64 20 61 6e 64 20 69 73 73 75 65 signed and issue
3280: 64 20 74 68 65 20 63 65 72 74 2e 20 52 46 43 20 d the cert. RFC
3290: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 5280 section 4.1
32a0: 2e 32 2e 34 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 .2.4 */. len
32b0: 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 = BIO_to_Buffer(
32c0: 58 35 30 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f X509_NAME_print_
32d0: 65 78 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 ex(bio, X509_get
32e0: 5f 69 73 73 75 65 72 5f 6e 61 6d 65 28 63 65 72 _issuer_name(cer
32f0: 74 29 2c 20 30 2c 20 66 6c 61 67 73 29 2c 20 62 t), 0, flags), b
3300: 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 io, buffer, BUFS
3310: 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 IZ);. LAPPEND
3320: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 _STR(interp, cer
3330: 74 50 74 72 2c 20 22 69 73 73 75 65 72 22 2c 20 tPtr, "issuer",
3340: 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a buffer, (Tcl_Siz
3350: 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a e) len);.. /*
3360: 20 43 65 72 74 69 66 69 63 61 74 65 20 76 61 6c Certificate val
3370: 69 64 69 74 79 20 70 65 72 69 6f 64 20 69 73 20 idity period is
3380: 74 68 65 20 69 6e 74 65 72 76 61 6c 20 74 68 65 the interval the
3390: 20 43 41 20 77 61 72 72 61 6e 74 73 20 74 68 61 CA warrants tha
33a0: 74 20 69 74 20 77 69 6c 6c 0a 09 6d 61 69 6e 74 t it will..maint
33b0: 61 69 6e 20 69 6e 66 6f 20 6f 6e 20 74 68 65 20 ain info on the
33c0: 73 74 61 74 75 73 20 6f 66 20 74 68 65 20 63 65 status of the ce
33d0: 72 74 69 66 69 63 61 74 65 2e 20 52 46 43 20 35 rtificate. RFC 5
33e0: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 280 section 4.1.
33f0: 32 2e 35 20 2a 2f 0a 20 20 20 20 2f 2a 20 47 65 2.5 */. /* Ge
3400: 74 20 56 61 6c 69 64 69 74 79 20 2d 20 4e 6f 74 t Validity - Not
3410: 20 42 65 66 6f 72 65 20 2a 2f 0a 20 20 20 20 6c Before */. l
3420: 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 en = BIO_to_Buff
3430: 65 72 28 41 53 4e 31 5f 54 49 4d 45 5f 70 72 69 er(ASN1_TIME_pri
3440: 6e 74 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 nt(bio, X509_get
3450: 30 5f 6e 6f 74 42 65 66 6f 72 65 28 63 65 72 74 0_notBefore(cert
3460: 29 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c )), bio, buffer,
3470: 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 BUFSIZ);. LA
3480: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 PPEND_STR(interp
3490: 2c 20 63 65 72 74 50 74 72 2c 20 22 6e 6f 74 42 , certPtr, "notB
34a0: 65 66 6f 72 65 22 2c 20 62 75 66 66 65 72 2c 20 efore", buffer,
34b0: 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b (Tcl_Size) len);
34c0: 0a 0a 20 20 20 20 2f 2a 20 47 65 74 20 56 61 6c .. /* Get Val
34d0: 69 64 69 74 79 20 2d 20 4e 6f 74 20 41 66 74 65 idity - Not Afte
34e0: 72 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 r */. len = B
34f0: 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 41 53 4e IO_to_Buffer(ASN
3500: 31 5f 54 49 4d 45 5f 70 72 69 6e 74 28 62 69 6f 1_TIME_print(bio
3510: 2c 20 58 35 30 39 5f 67 65 74 30 5f 6e 6f 74 41 , X509_get0_notA
3520: 66 74 65 72 28 63 65 72 74 29 29 2c 20 62 69 6f fter(cert)), bio
3530: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a , buffer, BUFSIZ
3540: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 );. LAPPEND_S
3550: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 TR(interp, certP
3560: 74 72 2c 20 22 6e 6f 74 41 66 74 65 72 22 2c 20 tr, "notAfter",
3570: 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a buffer, (Tcl_Siz
3580: 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a e) len);.. /*
3590: 20 53 75 62 6a 65 63 74 20 69 64 65 6e 74 69 66 Subject identif
35a0: 69 65 73 20 74 68 65 20 65 6e 74 69 74 79 20 61 ies the entity a
35b0: 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 ssociated with t
35c0: 68 65 20 70 75 62 6c 69 63 20 6b 65 79 20 73 74 he public key st
35d0: 6f 72 65 64 20 69 6e 0a 09 74 68 65 20 73 75 62 ored in..the sub
35e0: 6a 65 63 74 20 70 75 62 6c 69 63 20 6b 65 79 20 ject public key
35f0: 66 69 65 6c 64 2e 20 52 46 43 20 35 32 38 30 20 field. RFC 5280
3600: 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 36 20 section 4.1.2.6
3610: 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f */. len = BIO
3620: 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39 5f _to_Buffer(X509_
3630: 4e 41 4d 45 5f 70 72 69 6e 74 5f 65 78 28 62 69 NAME_print_ex(bi
3640: 6f 2c 20 58 35 30 39 5f 67 65 74 5f 73 75 62 6a o, X509_get_subj
3650: 65 63 74 5f 6e 61 6d 65 28 63 65 72 74 29 2c 20 ect_name(cert),
3660: 30 2c 20 66 6c 61 67 73 29 2c 20 62 69 6f 2c 20 0, flags), bio,
3670: 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b buffer, BUFSIZ);
3680: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 . LAPPEND_STR
3690: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
36a0: 2c 20 22 73 75 62 6a 65 63 74 22 2c 20 62 75 66 , "subject", buf
36b0: 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 fer, (Tcl_Size)
36c0: 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 48 len);.. /* SH
36d0: 41 31 20 44 69 67 65 73 74 20 28 46 69 6e 67 65 A1 Digest (Finge
36e0: 72 70 72 69 6e 74 29 20 6f 66 20 63 65 72 74 20 rprint) of cert
36f0: 2d 20 44 45 52 20 72 65 70 72 65 73 65 6e 74 61 - DER representa
3700: 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 tion */. if (
3710: 58 35 30 39 5f 64 69 67 65 73 74 28 63 65 72 74 X509_digest(cert
3720: 2c 20 45 56 50 5f 73 68 61 31 28 29 2c 20 6d 64 , EVP_sha1(), md
3730: 2c 20 26 6c 65 6e 29 29 20 7b 0a 20 20 20 20 6c , &len)) {. l
3740: 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 en = String_to_H
3750: 65 78 28 6d 64 2c 20 6c 65 6e 2c 20 62 75 66 66 ex(md, len, buff
3760: 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 er, BUFSIZ);..LA
3770: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 PPEND_STR(interp
3780: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 68 61 31 , certPtr, "sha1
3790: 5f 68 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20 _hash", buffer,
37a0: 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b (Tcl_Size) len);
37b0: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 . }.. /* S
37c0: 48 41 32 35 36 20 44 69 67 65 73 74 20 28 46 69 HA256 Digest (Fi
37d0: 6e 67 65 72 70 72 69 6e 74 29 20 6f 66 20 63 65 ngerprint) of ce
37e0: 72 74 20 2d 20 44 45 52 20 72 65 70 72 65 73 65 rt - DER represe
37f0: 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 ntation */. i
3800: 66 20 28 58 35 30 39 5f 64 69 67 65 73 74 28 63 f (X509_digest(c
3810: 65 72 74 2c 20 45 56 50 5f 73 68 61 32 35 36 28 ert, EVP_sha256(
3820: 29 2c 20 6d 64 2c 20 26 6c 65 6e 29 29 20 7b 0a ), md, &len)) {.
3830: 20 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 len = String
3840: 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 6c 65 6e 2c _to_Hex(md, len,
3850: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 buffer, BUFSIZ)
3860: 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 ;..LAPPEND_STR(i
3870: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
3880: 22 73 68 61 32 35 36 5f 68 61 73 68 22 2c 20 62 "sha256_hash", b
3890: 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 uffer, (Tcl_Size
38a0: 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 ) len);. }..
38b0: 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 50 75 /* Subject Pu
38c0: 62 6c 69 63 20 4b 65 79 20 49 6e 66 6f 20 73 70 blic Key Info sp
38d0: 65 63 69 66 69 65 73 20 74 68 65 20 70 75 62 6c ecifies the publ
38e0: 69 63 20 6b 65 79 20 61 6e 64 20 69 64 65 6e 74 ic key and ident
38f0: 69 66 69 65 73 20 74 68 65 0a 09 61 6c 67 6f 72 ifies the..algor
3900: 69 74 68 6d 20 77 69 74 68 20 77 68 69 63 68 20 ithm with which
3910: 74 68 65 20 6b 65 79 20 69 73 20 75 73 65 64 2e the key is used.
3920: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f RFC 5280 sectio
3930: 6e 20 34 2e 31 2e 32 2e 37 20 2a 2f 0a 20 20 20 n 4.1.2.7 */.
3940: 20 69 66 20 28 58 35 30 39 5f 67 65 74 5f 73 69 if (X509_get_si
3950: 67 6e 61 74 75 72 65 5f 69 6e 66 6f 28 63 65 72 gnature_info(cer
3960: 74 2c 20 26 6d 64 6e 69 64 2c 20 26 70 6b 6e 69 t, &mdnid, &pkni
3970: 64 2c 20 26 62 69 74 73 2c 20 26 78 66 6c 61 67 d, &bits, &xflag
3980: 73 29 29 20 7b 0a 09 41 53 4e 31 5f 42 49 54 5f s)) {..ASN1_BIT_
3990: 53 54 52 49 4e 47 20 2a 6b 65 79 3b 0a 09 75 6e STRING *key;..un
39a0: 73 69 67 6e 65 64 20 69 6e 74 20 6e 3b 0a 0a 09 signed int n;...
39b0: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
39c0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 rp, certPtr, "si
39d0: 67 6e 69 6e 67 44 69 67 65 73 74 22 2c 20 4f 42 gningDigest", OB
39e0: 4a 5f 6e 69 64 32 6c 6e 28 6d 64 6e 69 64 29 2c J_nid2ln(mdnid),
39f0: 20 2d 31 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 -1);..LAPPEND_S
3a00: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 TR(interp, certP
3a10: 74 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 41 6c tr, "publicKeyAl
3a20: 67 6f 72 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e 69 gorithm", OBJ_ni
3a30: 64 32 6c 6e 28 70 6b 6e 69 64 29 2c 20 2d 31 29 d2ln(pknid), -1)
3a40: 3b 0a 09 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 ;..LAPPEND_INT(i
3a50: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
3a60: 22 62 69 74 73 22 2c 20 62 69 74 73 29 3b 20 2f "bits", bits); /
3a70: 2a 20 45 66 66 65 63 74 69 76 65 20 73 65 63 75 * Effective secu
3a80: 72 69 74 79 20 62 69 74 73 20 2a 2f 0a 0a 09 6b rity bits */...k
3a90: 65 79 20 3d 20 58 35 30 39 5f 67 65 74 30 5f 70 ey = X509_get0_p
3aa0: 75 62 6b 65 79 5f 62 69 74 73 74 72 28 63 65 72 ubkey_bitstr(cer
3ab0: 74 29 3b 0a 09 6c 65 6e 20 3d 20 53 74 72 69 6e t);..len = Strin
3ac0: 67 5f 74 6f 5f 48 65 78 28 6b 65 79 2d 3e 64 61 g_to_Hex(key->da
3ad0: 74 61 2c 20 6b 65 79 2d 3e 6c 65 6e 67 74 68 2c ta, key->length,
3ae0: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 buffer, BUFSIZ)
3af0: 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 ;..LAPPEND_STR(i
3b00: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
3b10: 22 70 75 62 6c 69 63 4b 65 79 22 2c 20 62 75 66 "publicKey", buf
3b20: 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 fer, (Tcl_Size)
3b30: 6c 65 6e 29 3b 0a 0a 09 6c 65 6e 20 3d 20 30 3b len);...len = 0;
3b40: 0a 09 69 66 20 28 58 35 30 39 5f 70 75 62 6b 65 ..if (X509_pubke
3b50: 79 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45 y_digest(cert, E
3b60: 56 50 5f 67 65 74 5f 64 69 67 65 73 74 62 79 6e VP_get_digestbyn
3b70: 69 64 28 70 6b 6e 69 64 29 2c 20 6d 64 2c 20 26 id(pknid), md, &
3b80: 6e 29 29 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d n)) {.. len =
3b90: 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d String_to_Hex(m
3ba0: 64 2c 20 28 69 6e 74 29 6e 2c 20 62 75 66 66 65 d, (int)n, buffe
3bb0: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 7d 0a 09 r, BUFSIZ);..}..
3bc0: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
3bd0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75 rp, certPtr, "pu
3be0: 62 6c 69 63 4b 65 79 48 61 73 68 22 2c 20 62 75 blicKeyHash", bu
3bf0: 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 ffer, (Tcl_Size)
3c00: 20 6c 65 6e 29 3b 0a 0a 09 2f 2a 20 64 69 67 65 len);.../* dige
3c10: 73 74 20 6f 66 20 74 68 65 20 44 45 52 20 72 65 st of the DER re
3c20: 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 6f 66 20 presentation of
3c30: 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 20 the certificate
3c40: 2a 2f 0a 09 6c 65 6e 20 3d 20 30 3b 0a 09 69 66 */..len = 0;..if
3c50: 20 28 58 35 30 39 5f 64 69 67 65 73 74 28 63 65 (X509_digest(ce
3c60: 72 74 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65 rt, EVP_get_dige
3c70: 73 74 62 79 6e 69 64 28 6d 64 6e 69 64 29 2c 20 stbynid(mdnid),
3c80: 6d 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20 md, &n)) {..
3c90: 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f len = String_to_
3ca0: 48 65 78 28 6d 64 2c 20 28 69 6e 74 29 6e 2c 20 Hex(md, (int)n,
3cb0: 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b buffer, BUFSIZ);
3cc0: 0a 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 ..}..LAPPEND_STR
3cd0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3ce0: 2c 20 22 73 69 67 6e 61 74 75 72 65 48 61 73 68 , "signatureHash
3cf0: 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f ", buffer, (Tcl_
3d00: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 20 Size) len);.
3d10: 7d 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 }.. /* Certif
3d20: 69 63 61 74 65 20 50 75 72 70 6f 73 65 2e 20 43 icate Purpose. C
3d30: 61 6c 6c 20 62 65 66 6f 72 65 20 63 68 65 63 6b all before check
3d40: 69 6e 67 20 66 6f 72 20 65 78 74 65 6e 73 69 6f ing for extensio
3d50: 6e 73 2e 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 ns. */. LAPPE
3d60: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 ND_STR(interp, c
3d70: 65 72 74 50 74 72 2c 20 22 70 75 72 70 6f 73 65 ertPtr, "purpose
3d80: 22 2c 20 54 6c 73 5f 78 35 30 39 50 75 72 70 6f ", Tls_x509Purpo
3d90: 73 65 28 63 65 72 74 29 2c 20 2d 31 29 3b 0a 20 se(cert), -1);.
3da0: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 LAPPEND_OBJ(i
3db0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
3dc0: 22 63 65 72 74 69 66 69 63 61 74 65 50 75 72 70 "certificatePurp
3dd0: 6f 73 65 22 2c 20 54 6c 73 5f 78 35 30 39 50 75 ose", Tls_x509Pu
3de0: 72 70 6f 73 65 73 28 69 6e 74 65 72 70 2c 20 63 rposes(interp, c
3df0: 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 ert));.. /* G
3e00: 65 74 20 65 78 74 65 6e 73 69 6f 6e 73 20 66 6c et extensions fl
3e10: 61 67 73 20 2a 2f 0a 20 20 20 20 78 66 6c 61 67 ags */. xflag
3e20: 73 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 s = X509_get_ext
3e30: 65 6e 73 69 6f 6e 5f 66 6c 61 67 73 28 63 65 72 ension_flags(cer
3e40: 74 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f t);. LAPPEND_
3e50: 49 4e 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 INT(interp, cert
3e60: 50 74 72 2c 20 22 65 78 74 46 6c 61 67 73 22 2c Ptr, "extFlags",
3e70: 20 78 66 6c 61 67 73 29 3b 0a 0a 09 2f 2a 20 43 xflags);.../* C
3e80: 68 65 63 6b 20 69 66 20 63 65 72 74 20 77 61 73 heck if cert was
3e90: 20 69 73 73 75 65 64 20 62 79 20 43 41 20 63 65 issued by CA ce
3ea0: 72 74 20 69 73 73 75 65 72 20 6f 72 20 73 65 6c rt issuer or sel
3eb0: 66 20 73 69 67 6e 65 64 20 2a 2f 0a 20 20 20 20 f signed */.
3ec0: 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 LAPPEND_BOOL(int
3ed0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 erp, certPtr, "s
3ee0: 65 6c 66 49 73 73 75 65 64 22 2c 20 78 66 6c 61 elfIssued", xfla
3ef0: 67 73 20 26 20 45 58 46 4c 41 47 5f 53 49 29 3b gs & EXFLAG_SI);
3f00: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f . LAPPEND_BOO
3f10: 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 L(interp, certPt
3f20: 72 2c 20 22 73 65 6c 66 53 69 67 6e 65 64 22 2c r, "selfSigned",
3f30: 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 xflags & EXFLAG
3f40: 5f 53 53 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e _SS);. 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 69 73 50 72 6f 78 79 ertPtr, "isProxy
3f70: 43 65 72 74 22 2c 20 78 66 6c 61 67 73 20 26 20 Cert", xflags &
3f80: 45 58 46 4c 41 47 5f 50 52 4f 58 59 29 3b 0a 20 EXFLAG_PROXY);.
3f90: 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 LAPPEND_BOOL(
3fa0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
3fb0: 20 22 65 78 74 49 6e 76 61 6c 69 64 22 2c 20 78 "extInvalid", x
3fc0: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 49 flags & EXFLAG_I
3fd0: 4e 56 41 4c 49 44 29 3b 0a 20 20 20 20 4c 41 50 NVALID);. LAP
3fe0: 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 PEND_BOOL(interp
3ff0: 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 43 41 , certPtr, "isCA
4000: 43 65 72 74 22 2c 20 58 35 30 39 5f 63 68 65 63 Cert", X509_chec
4010: 6b 5f 63 61 28 63 65 72 74 29 29 3b 0a 0a 20 20 k_ca(cert));..
4020: 20 20 2f 2a 20 54 68 65 20 55 6e 69 71 75 65 20 /* The Unique
4030: 49 64 73 20 61 72 65 20 75 73 65 64 20 74 6f 20 Ids are used to
4040: 68 61 6e 64 6c 65 20 74 68 65 20 70 6f 73 73 69 handle the possi
4050: 62 69 6c 69 74 79 20 6f 66 20 72 65 75 73 65 20 bility of reuse
4060: 6f 66 20 73 75 62 6a 65 63 74 0a 09 61 6e 64 2f of subject..and/
4070: 6f 72 20 69 73 73 75 65 72 20 6e 61 6d 65 73 20 or issuer names
4080: 6f 76 65 72 20 74 69 6d 65 2e 20 52 46 43 20 35 over time. RFC 5
4090: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 280 section 4.1.
40a0: 32 2e 38 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 6f 2.8 */. {..co
40b0: 6e 73 74 20 41 53 4e 31 5f 42 49 54 5f 53 54 52 nst ASN1_BIT_STR
40c0: 49 4e 47 20 2a 69 75 69 64 2c 20 2a 73 75 69 64 ING *iuid, *suid
40d0: 3b 0a 20 20 20 20 20 20 20 20 58 35 30 39 5f 67 ;. X509_g
40e0: 65 74 30 5f 75 69 64 73 28 63 65 72 74 2c 20 26 et0_uids(cert, &
40f0: 69 75 69 64 2c 20 26 73 75 69 64 29 3b 0a 0a 09 iuid, &suid);...
4100: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e Tcl_ListObjAppen
4110: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c dElement(interp,
4120: 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 certPtr, Tcl_Ne
4130: 77 53 74 72 69 6e 67 4f 62 6a 28 22 69 73 73 75 wStringObj("issu
4140: 65 72 55 6e 69 71 75 65 49 64 22 2c 20 2d 31 29 erUniqueId", -1)
4150: 29 3b 0a 09 69 66 20 28 69 75 69 64 20 21 3d 20 );..if (iuid !=
4160: 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 54 63 6c NULL) {.. Tcl
4170: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
4180: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 ement(interp, ce
4190: 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 42 79 rtPtr, Tcl_NewBy
41a0: 74 65 41 72 72 61 79 4f 62 6a 28 28 63 68 61 72 teArrayObj((char
41b0: 20 2a 29 69 75 69 64 2d 3e 64 61 74 61 2c 20 28 *)iuid->data, (
41c0: 54 63 6c 5f 53 69 7a 65 29 20 69 75 69 64 2d 3e Tcl_Size) iuid->
41d0: 6c 65 6e 67 74 68 29 29 3b 0a 09 7d 20 65 6c 73 length));..} els
41e0: 65 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 e {.. Tcl_Lis
41f0: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e tObjAppendElemen
4200: 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 t(interp, certPt
4210: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 r, Tcl_NewString
4220: 4f 62 6a 28 22 22 2c 20 2d 31 29 29 3b 0a 09 7d Obj("", -1));..}
4230: 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 ...Tcl_ListObjAp
4240: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
4250: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c rp, certPtr, Tcl
4260: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 73 _NewStringObj("s
4270: 75 62 6a 65 63 74 55 6e 69 71 75 65 49 64 22 2c ubjectUniqueId",
4280: 20 2d 31 29 29 3b 0a 09 69 66 20 28 73 75 69 64 -1));..if (suid
4290: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 != NULL) {..
42a0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 Tcl_ListObjAppe
42b0: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 ndElement(interp
42c0: 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e , certPtr, Tcl_N
42d0: 65 77 42 79 74 65 41 72 72 61 79 4f 62 6a 28 28 ewByteArrayObj((
42e0: 63 68 61 72 20 2a 29 73 75 69 64 2d 3e 64 61 74 char *)suid->dat
42f0: 61 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 73 75 a, (Tcl_Size) su
4300: 69 64 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 7d id->length));..}
4310: 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 6c else {.. Tcl
4320: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
4330: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 ement(interp, ce
4340: 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 rtPtr, Tcl_NewSt
4350: 72 69 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 29 ringObj("", -1))
4360: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 ;..}. }..
4370: 2f 2a 20 58 35 30 39 20 76 33 20 45 78 74 65 6e /* X509 v3 Exten
4380: 73 69 6f 6e 73 20 2d 20 52 46 43 20 35 32 38 30 sions - RFC 5280
4390: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 39 section 4.1.2.9
43a0: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f */. LAPPEND_
43b0: 49 4e 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 INT(interp, cert
43c0: 50 74 72 2c 20 22 65 78 74 43 6f 75 6e 74 22 2c Ptr, "extCount",
43d0: 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 63 6f X509_get_ext_co
43e0: 75 6e 74 28 63 65 72 74 29 29 3b 0a 20 20 20 20 unt(cert));.
43f0: 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 LAPPEND_OBJ(inte
4400: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 rp, certPtr, "ex
4410: 74 65 6e 73 69 6f 6e 73 22 2c 20 54 6c 73 5f 78 tensions", Tls_x
4420: 35 30 39 45 78 74 65 6e 73 69 6f 6e 73 28 69 6e 509Extensions(in
4430: 74 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 terp, cert));..
4440: 20 20 20 2f 2a 20 41 75 74 68 6f 72 69 74 79 20 /* Authority
4450: 4b 65 79 20 49 64 65 6e 74 69 66 69 65 72 20 28 Key Identifier (
4460: 41 4b 49 29 20 69 73 20 74 68 65 20 53 75 62 6a AKI) is the Subj
4470: 65 63 74 20 4b 65 79 20 49 64 65 6e 74 69 66 69 ect Key Identifi
4480: 65 72 20 28 53 4b 49 29 20 6f 66 0a 09 69 74 73 er (SKI) of..its
4490: 20 73 69 67 6e 65 72 20 28 74 68 65 20 43 41 29 signer (the CA)
44a0: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
44b0: 6f 6e 20 34 2e 32 2e 31 2e 31 2c 20 4e 49 44 5f on 4.2.1.1, NID_
44c0: 61 75 74 68 6f 72 69 74 79 5f 6b 65 79 5f 69 64 authority_key_id
44d0: 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20 20 20 entifier */.
44e0: 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 LAPPEND_OBJ(inte
44f0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 61 75 rp, certPtr, "au
4500: 74 68 6f 72 69 74 79 4b 65 79 49 64 65 6e 74 69 thorityKeyIdenti
4510: 66 69 65 72 22 2c 0a 09 54 6c 73 5f 78 35 30 39 fier",..Tls_x509
4520: 49 64 65 6e 74 69 66 69 65 72 28 58 35 30 39 5f Identifier(X509_
4530: 67 65 74 30 5f 61 75 74 68 6f 72 69 74 79 5f 6b get0_authority_k
4540: 65 79 5f 69 64 28 63 65 72 74 29 29 29 3b 0a 0a ey_id(cert)));..
4550: 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 4b /* Subject K
4560: 65 79 20 49 64 65 6e 74 69 66 69 65 72 20 28 53 ey Identifier (S
4570: 4b 49 29 20 69 73 20 75 73 65 64 20 74 6f 20 69 KI) is used to i
4580: 64 65 6e 74 69 66 79 20 63 65 72 74 69 66 69 63 dentify certific
4590: 61 74 65 73 20 74 68 61 74 20 63 6f 6e 74 61 69 ates that contai
45a0: 6e 0a 09 61 20 70 61 72 74 69 63 75 6c 61 72 20 n..a particular
45b0: 70 75 62 6c 69 63 20 6b 65 79 2e 20 52 46 43 20 public key. RFC
45c0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 5280 section 4.2
45d0: 2e 31 2e 32 2c 20 4e 49 44 5f 73 75 62 6a 65 63 .1.2, NID_subjec
45e0: 74 5f 6b 65 79 5f 69 64 65 6e 74 69 66 69 65 72 t_key_identifier
45f0: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f */. LAPPEND_
4600: 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 OBJ(interp, cert
4610: 50 74 72 2c 20 22 73 75 62 6a 65 63 74 4b 65 79 Ptr, "subjectKey
4620: 49 64 65 6e 74 69 66 69 65 72 22 2c 0a 09 54 6c Identifier",..Tl
4630: 73 5f 78 35 30 39 49 64 65 6e 74 69 66 69 65 72 s_x509Identifier
4640: 28 58 35 30 39 5f 67 65 74 30 5f 73 75 62 6a 65 (X509_get0_subje
4650: 63 74 5f 6b 65 79 5f 69 64 28 63 65 72 74 29 29 ct_key_id(cert))
4660: 29 3b 0a 0a 20 20 20 20 2f 2a 20 4b 65 79 20 75 );.. /* Key u
4670: 73 61 67 65 20 65 78 74 65 6e 73 69 6f 6e 20 64 sage extension d
4680: 65 66 69 6e 65 73 20 74 68 65 20 70 75 72 70 6f efines the purpo
4690: 73 65 20 28 65 2e 67 2e 2c 20 65 6e 63 69 70 68 se (e.g., enciph
46a0: 65 72 6d 65 6e 74 2c 20 73 69 67 6e 61 74 75 72 erment, signatur
46b0: 65 2c 20 63 65 72 74 69 66 69 63 61 74 65 0a 09 e, certificate..
46c0: 73 69 67 6e 69 6e 67 29 20 6f 66 20 74 68 65 20 signing) of the
46d0: 6b 65 79 20 69 6e 20 74 68 65 20 63 65 72 74 69 key in the certi
46e0: 66 69 63 61 74 65 2e 20 52 46 43 20 35 32 38 30 ficate. RFC 5280
46f0: 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 33 section 4.2.1.3
4700: 2c 20 4e 49 44 5f 6b 65 79 5f 75 73 61 67 65 20 , NID_key_usage
4710: 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f */. LAPPEND_O
4720: 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 BJ(interp, certP
4730: 74 72 2c 20 22 6b 65 79 55 73 61 67 65 22 2c 20 tr, "keyUsage",
4740: 54 6c 73 5f 78 35 30 39 4b 65 79 55 73 61 67 65 Tls_x509KeyUsage
4750: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 2c 20 78 (interp, cert, x
4760: 66 6c 61 67 73 29 29 3b 0a 0a 20 20 20 20 2f 2a flags));.. /*
4770: 20 43 65 72 74 69 66 69 63 61 74 65 20 50 6f 6c Certificate Pol
4780: 69 63 69 65 73 20 2d 20 69 6e 64 69 63 61 74 65 icies - indicate
4790: 73 20 74 68 65 20 69 73 73 75 69 6e 67 20 43 41 s the issuing CA
47a0: 20 63 6f 6e 73 69 64 65 72 73 20 69 74 73 20 69 considers its i
47b0: 73 73 75 65 72 44 6f 6d 61 69 6e 50 6f 6c 69 63 ssuerDomainPolic
47c0: 79 0a 09 65 71 75 69 76 61 6c 65 6e 74 20 74 6f y..equivalent to
47d0: 20 74 68 65 20 73 75 62 6a 65 63 74 20 43 41 27 the subject CA'
47e0: 73 20 73 75 62 6a 65 63 74 44 6f 6d 61 69 6e 50 s subjectDomainP
47f0: 6f 6c 69 63 79 2e 20 52 46 43 20 35 32 38 30 20 olicy. RFC 5280
4800: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 34 2c section 4.2.1.4,
4810: 20 4e 49 44 5f 63 65 72 74 69 66 69 63 61 74 65 NID_certificate
4820: 5f 70 6f 6c 69 63 69 65 73 20 2a 2f 0a 20 20 20 _policies */.
4830: 20 69 66 20 28 78 66 6c 61 67 73 20 26 20 45 58 if (xflags & EX
4840: 46 4c 41 47 5f 49 4e 56 41 4c 49 44 5f 50 4f 4c FLAG_INVALID_POL
4850: 49 43 59 29 20 7b 0a 09 2f 2a 20 52 65 6a 65 63 ICY) {../* Rejec
4860: 74 20 63 65 72 74 20 2a 2f 0a 20 20 20 20 7d 0a t cert */. }.
4870: 0a 20 20 20 20 2f 2a 20 50 6f 6c 69 63 79 20 4d . /* Policy M
4880: 61 70 70 69 6e 67 73 20 2d 20 52 46 43 20 35 32 appings - RFC 52
4890: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 80 section 4.2.1
48a0: 2e 35 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 5f 6d .5, NID_policy_m
48b0: 61 70 70 69 6e 67 73 20 2a 2f 0a 0a 20 20 20 20 appings */..
48c0: 2f 2a 20 53 75 62 6a 65 63 74 20 41 6c 74 65 72 /* Subject Alter
48d0: 6e 61 74 69 76 65 20 4e 61 6d 65 20 28 53 41 4e native Name (SAN
48e0: 29 20 63 6f 6e 74 61 69 6e 73 20 61 64 64 69 74 ) contains addit
48f0: 69 6f 6e 61 6c 20 55 52 4c 73 2c 20 44 4e 53 20 ional URLs, DNS
4900: 6e 61 6d 65 73 2c 20 6f 72 20 49 50 0a 09 61 64 names, or IP..ad
4910: 64 72 65 73 73 65 73 20 62 6f 75 6e 64 20 74 6f dresses bound to
4920: 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 52 46 certificate. RF
4930: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 C 5280 section 4
4940: 2e 32 2e 31 2e 36 2c 20 4e 49 44 5f 73 75 62 6a .2.1.6, NID_subj
4950: 65 63 74 5f 61 6c 74 5f 6e 61 6d 65 20 2a 2f 0a ect_alt_name */.
4960: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 LAPPEND_OBJ(
4970: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
4980: 20 22 73 75 62 6a 65 63 74 41 6c 74 4e 61 6d 65 "subjectAltName
4990: 22 2c 20 54 6c 73 5f 78 35 30 39 4e 61 6d 65 73 ", Tls_x509Names
49a0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 2c 20 4e (interp, cert, N
49b0: 49 44 5f 73 75 62 6a 65 63 74 5f 61 6c 74 5f 6e ID_subject_alt_n
49c0: 61 6d 65 2c 20 62 69 6f 29 29 3b 0a 0a 20 20 20 ame, bio));..
49d0: 20 2f 2a 20 49 73 73 75 65 72 20 41 6c 74 65 72 /* Issuer Alter
49e0: 6e 61 74 69 76 65 20 4e 61 6d 65 20 69 73 20 75 native Name is u
49f0: 73 65 64 20 74 6f 20 61 73 73 6f 63 69 61 74 65 sed to associate
4a00: 20 49 6e 74 65 72 6e 65 74 20 73 74 79 6c 65 20 Internet style
4a10: 69 64 65 6e 74 69 74 69 65 73 0a 09 77 69 74 68 identities..with
4a20: 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 the certificate
4a30: 20 69 73 73 75 65 72 2e 20 52 46 43 20 35 32 38 issuer. RFC 528
4a40: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 0 section 4.2.1.
4a50: 37 2c 20 4e 49 44 5f 69 73 73 75 65 72 5f 61 6c 7, NID_issuer_al
4a60: 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 4c 41 t_name */. LA
4a70: 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 PPEND_OBJ(interp
4a80: 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 73 75 , certPtr, "issu
4a90: 65 72 41 6c 74 4e 61 6d 65 22 2c 20 54 6c 73 5f erAltName", Tls_
4aa0: 78 35 30 39 4e 61 6d 65 73 28 69 6e 74 65 72 70 x509Names(interp
4ab0: 2c 20 63 65 72 74 2c 20 4e 49 44 5f 69 73 73 75 , cert, NID_issu
4ac0: 65 72 5f 61 6c 74 5f 6e 61 6d 65 2c 20 62 69 6f er_alt_name, bio
4ad0: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a ));.. /* Subj
4ae0: 65 63 74 20 44 69 72 65 63 74 6f 72 79 20 41 74 ect Directory At
4af0: 74 72 69 62 75 74 65 73 20 70 72 6f 76 69 64 65 tributes provide
4b00: 73 20 69 64 65 6e 74 69 66 69 63 61 74 69 6f 6e s identification
4b10: 20 61 74 74 72 69 62 75 74 65 73 20 28 65 2e 67 attributes (e.g
4b20: 2e 2c 20 6e 61 74 69 6f 6e 61 6c 69 74 79 29 0a ., nationality).
4b30: 09 6f 66 20 74 68 65 20 73 75 62 6a 65 63 74 2e .of the subject.
4b40: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f RFC 5280 sectio
4b50: 6e 20 34 2e 32 2e 31 2e 38 20 28 73 75 62 6a 65 n 4.2.1.8 (subje
4b60: 63 74 44 69 72 65 63 74 6f 72 79 41 74 74 72 69 ctDirectoryAttri
4b70: 62 75 74 65 73 29 20 2a 2f 0a 0a 20 20 20 20 2f butes) */.. /
4b80: 2a 20 42 61 73 69 63 20 43 6f 6e 73 74 72 61 69 * Basic Constrai
4b90: 6e 74 73 20 69 64 65 6e 74 69 66 69 65 73 20 77 nts identifies w
4ba0: 68 65 74 68 65 72 20 74 68 65 20 73 75 62 6a 65 hether the subje
4bb0: 63 74 20 6f 66 20 74 68 65 20 63 65 72 74 20 69 ct of the cert i
4bc0: 73 20 61 20 43 41 20 61 6e 64 0a 09 74 68 65 20 s a CA and..the
4bd0: 6d 61 78 20 64 65 70 74 68 20 6f 66 20 76 61 6c max depth of val
4be0: 69 64 20 63 65 72 74 20 70 61 74 68 73 20 66 6f id cert paths fo
4bf0: 72 20 74 68 69 73 20 63 65 72 74 2e 20 52 46 43 r this cert. RFC
4c00: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 5280 section 4.
4c10: 32 2e 31 2e 39 2c 20 4e 49 44 5f 62 61 73 69 63 2.1.9, NID_basic
4c20: 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a _constraints */.
4c30: 20 20 20 20 69 66 20 28 21 28 78 66 6c 61 67 73 if (!(xflags
4c40: 20 26 20 45 58 46 4c 41 47 5f 50 52 4f 58 59 29 & EXFLAG_PROXY)
4c50: 29 20 7b 0a 09 4c 41 50 50 45 4e 44 5f 4c 4f 4e ) {..LAPPEND_LON
4c60: 47 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 G(interp, certPt
4c70: 72 2c 20 22 70 61 74 68 4c 65 6e 22 2c 20 58 35 r, "pathLen", X5
4c80: 30 39 5f 67 65 74 5f 70 61 74 68 6c 65 6e 28 63 09_get_pathlen(c
4c90: 65 72 74 29 29 3b 0a 20 20 20 20 7d 20 65 6c 73 ert));. } els
4ca0: 65 20 7b 0a 09 4c 41 50 50 45 4e 44 5f 4c 4f 4e e {..LAPPEND_LON
4cb0: 47 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 G(interp, certPt
4cc0: 72 2c 20 22 70 61 74 68 4c 65 6e 22 2c 20 58 35 r, "pathLen", X5
4cd0: 30 39 5f 67 65 74 5f 70 72 6f 78 79 5f 70 61 74 09_get_proxy_pat
4ce0: 68 6c 65 6e 28 63 65 72 74 29 29 3b 0a 20 20 20 hlen(cert));.
4cf0: 20 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 }. LAPPEND_B
4d00: 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 OOL(interp, cert
4d10: 50 74 72 2c 20 22 62 61 73 69 63 43 6f 6e 73 74 Ptr, "basicConst
4d20: 72 61 69 6e 74 73 43 41 22 2c 20 78 66 6c 61 67 raintsCA", xflag
4d30: 73 20 26 20 45 58 46 4c 41 47 5f 43 41 29 3b 0a s & EXFLAG_CA);.
4d40: 0a 20 20 20 20 2f 2a 20 4e 61 6d 65 20 43 6f 6e . /* Name Con
4d50: 73 74 72 61 69 6e 74 73 20 69 73 20 6f 6e 6c 79 straints is only
4d60: 20 75 73 65 64 20 69 6e 20 43 41 20 63 65 72 74 used in CA cert
4d70: 73 20 74 6f 20 69 6e 64 69 63 61 74 65 20 74 68 s to indicate th
4d80: 65 20 6e 61 6d 65 20 73 70 61 63 65 20 66 6f 72 e name space for
4d90: 0a 09 61 6c 6c 20 73 75 62 6a 65 63 74 20 6e 61 ..all subject na
4da0: 6d 65 73 20 69 6e 20 73 75 62 73 65 71 75 65 6e mes in subsequen
4db0: 74 20 63 65 72 74 69 66 69 63 61 74 65 73 20 69 t certificates i
4dc0: 6e 20 61 20 63 65 72 74 69 66 69 63 61 74 69 6f n a certificatio
4dd0: 6e 20 70 61 74 68 0a 09 4d 55 53 54 20 62 65 20 n path..MUST be
4de0: 6c 6f 63 61 74 65 64 2e 20 52 46 43 20 35 32 38 located. RFC 528
4df0: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 0 section 4.2.1.
4e00: 31 30 2c 20 4e 49 44 5f 6e 61 6d 65 5f 63 6f 6e 10, NID_name_con
4e10: 73 74 72 61 69 6e 74 73 20 2a 2f 0a 0a 20 20 20 straints */..
4e20: 20 2f 2a 20 50 6f 6c 69 63 79 20 43 6f 6e 73 74 /* Policy Const
4e30: 72 61 69 6e 74 73 20 69 73 20 6f 6e 6c 79 20 75 raints is only u
4e40: 73 65 64 20 69 6e 20 43 41 20 63 65 72 74 73 20 sed in CA certs
4e50: 74 6f 20 6c 69 6d 69 74 20 74 68 65 20 6c 65 6e to limit the len
4e60: 67 74 68 20 6f 66 20 61 0a 09 63 65 72 74 20 63 gth of a..cert c
4e70: 68 61 69 6e 20 66 6f 72 20 74 68 61 74 20 43 41 hain for that CA
4e80: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
4e90: 6f 6e 20 34 2e 32 2e 31 2e 31 31 2c 20 4e 49 44 on 4.2.1.11, NID
4ea0: 5f 70 6f 6c 69 63 79 5f 63 6f 6e 73 74 72 61 69 _policy_constrai
4eb0: 6e 74 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 45 nts */.. /* E
4ec0: 78 74 65 6e 64 65 64 20 4b 65 79 20 55 73 61 67 xtended Key Usag
4ed0: 65 20 69 6e 64 69 63 61 74 65 73 20 74 68 65 20 e indicates the
4ee0: 70 75 72 70 6f 73 65 73 20 74 68 65 20 63 65 72 purposes the cer
4ef0: 74 69 66 69 65 64 20 70 75 62 6c 69 63 20 6b 65 tified public ke
4f00: 79 20 6d 61 79 20 62 65 0a 09 75 73 65 64 2c 20 y may be..used,
4f10: 62 65 79 6f 6e 64 20 74 68 65 20 62 61 73 69 63 beyond the basic
4f20: 20 70 75 72 70 6f 73 65 73 2e 20 52 46 43 20 35 purposes. RFC 5
4f30: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 280 section 4.2.
4f40: 31 2e 31 32 2c 20 4e 49 44 5f 65 78 74 5f 6b 65 1.12, NID_ext_ke
4f50: 79 5f 75 73 61 67 65 20 2a 2f 0a 20 20 20 20 4c y_usage */. L
4f60: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 APPEND_OBJ(inter
4f70: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 74 p, certPtr, "ext
4f80: 65 6e 64 65 64 4b 65 79 55 73 61 67 65 22 2c 20 endedKeyUsage",
4f90: 54 6c 73 5f 78 35 30 39 45 78 74 4b 65 79 55 73 Tls_x509ExtKeyUs
4fa0: 61 67 65 28 69 6e 74 65 72 70 2c 20 63 65 72 74 age(interp, cert
4fb0: 2c 20 78 66 6c 61 67 73 29 29 3b 0a 0a 20 20 20 , xflags));..
4fc0: 20 2f 2a 20 43 52 4c 20 44 69 73 74 72 69 62 75 /* CRL Distribu
4fd0: 74 69 6f 6e 20 50 6f 69 6e 74 73 20 69 64 65 6e tion Points iden
4fe0: 74 69 66 69 65 73 20 77 68 65 72 65 20 43 52 4c tifies where CRL
4ff0: 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 63 61 6e information can
5000: 20 62 65 20 6f 62 74 61 69 6e 65 64 2e 0a 09 52 be obtained...R
5010: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 FC 5280 section
5020: 34 2e 32 2e 31 2e 31 33 2a 2f 0a 20 20 20 20 4c 4.2.1.13*/. L
5030: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 APPEND_OBJ(inter
5040: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 72 6c p, certPtr, "crl
5050: 44 69 73 74 72 69 62 75 74 69 6f 6e 50 6f 69 6e DistributionPoin
5060: 74 73 22 2c 20 54 6c 73 5f 78 35 30 39 43 72 6c ts", Tls_x509Crl
5070: 44 70 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 Dp(interp, cert)
5080: 29 3b 0a 0a 20 20 20 20 2f 2a 20 46 72 65 73 68 );.. /* Fresh
5090: 65 73 74 20 43 52 4c 20 65 78 74 65 6e 73 69 6f est CRL extensio
50a0: 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 78 66 6c n */. if (xfl
50b0: 61 67 73 20 26 20 45 58 46 4c 41 47 5f 46 52 45 ags & EXFLAG_FRE
50c0: 53 48 45 53 54 29 20 7b 0a 20 20 20 20 7d 0a 0a SHEST) {. }..
50d0: 20 20 20 20 2f 2a 20 41 75 74 68 6f 72 69 74 79 /* Authority
50e0: 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 41 63 63 Information Acc
50f0: 65 73 73 20 69 6e 64 69 63 61 74 65 73 20 68 6f ess indicates ho
5100: 77 20 74 6f 20 61 63 63 65 73 73 20 69 6e 66 6f w to access info
5110: 20 61 6e 64 20 73 65 72 76 69 63 65 73 0a 09 66 and services..f
5120: 6f 72 20 74 68 65 20 63 65 72 74 69 66 69 63 61 or the certifica
5130: 74 65 20 69 73 73 75 65 72 2e 20 52 46 43 20 35 te issuer. RFC 5
5140: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 280 section 4.2.
5150: 32 2e 31 2c 20 4e 49 44 5f 69 6e 66 6f 5f 61 63 2.1, NID_info_ac
5160: 63 65 73 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 cess */.. /*
5170: 47 65 74 20 4f 6e 2d 6c 69 6e 65 20 43 65 72 74 Get On-line Cert
5180: 69 66 69 63 61 74 65 20 53 74 61 74 75 73 20 50 ificate Status P
5190: 72 6f 74 6f 63 6f 6c 20 28 4f 53 43 50 29 20 52 rotocol (OSCP) R
51a0: 65 73 70 6f 6e 64 65 72 73 20 55 52 4c 20 2a 2f esponders URL */
51b0: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a . LAPPEND_OBJ
51c0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
51d0: 2c 20 22 6f 63 73 70 52 65 73 70 6f 6e 64 65 72 , "ocspResponder
51e0: 73 22 2c 20 54 6c 73 5f 78 35 30 39 4f 73 63 70 s", Tls_x509Oscp
51f0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 29 3b (interp, cert));
5200: 0a 0a 20 20 20 20 2f 2a 20 47 65 74 20 43 65 72 .. /* Get Cer
5210: 74 69 66 69 63 61 74 65 20 41 75 74 68 6f 72 69 tificate Authori
5220: 74 79 20 28 43 41 29 20 49 73 73 75 65 72 73 20 ty (CA) Issuers
5230: 55 52 4c 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 URL */. LAPPE
5240: 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 ND_OBJ(interp, c
5250: 65 72 74 50 74 72 2c 20 22 63 61 49 73 73 75 65 ertPtr, "caIssue
5260: 72 73 22 2c 20 54 6c 73 5f 78 35 30 39 43 61 49 rs", Tls_x509CaI
5270: 73 73 75 65 72 73 28 69 6e 74 65 72 70 2c 20 63 ssuers(interp, c
5280: 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 ert));.. /* S
5290: 75 62 6a 65 63 74 20 49 6e 66 6f 72 6d 61 74 69 ubject Informati
52a0: 6f 6e 20 41 63 63 65 73 73 20 2d 20 52 46 43 20 on Access - RFC
52b0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 5280 section 4.2
52c0: 2e 32 2e 32 2c 20 4e 49 44 5f 73 69 6e 66 6f 5f .2.2, NID_sinfo_
52d0: 61 63 63 65 73 73 20 2a 2f 0a 0a 20 20 20 20 2f access */.. /
52e0: 2a 20 43 65 72 74 69 66 69 63 61 74 65 20 41 6c * Certificate Al
52f0: 69 61 73 2e 20 49 66 20 75 73 65 73 20 61 20 50 ias. If uses a P
5300: 4b 43 53 23 31 32 20 73 74 72 75 63 74 75 72 65 KCS#12 structure
5310: 2c 20 61 6c 69 61 73 20 77 69 6c 6c 20 72 65 66 , alias will ref
5320: 6c 65 63 74 20 74 68 65 0a 09 66 72 69 65 6e 64 lect the..friend
5330: 6c 79 4e 61 6d 65 20 61 74 74 72 69 62 75 74 65 lyName attribute
5340: 20 28 52 46 43 20 32 39 38 35 29 2e 20 2a 2f 0a (RFC 2985). */.
5350: 20 20 20 20 7b 0a 09 6c 65 6e 20 3d 20 30 3b 0a {..len = 0;.
5360: 20 20 20 20 20 20 20 20 63 68 61 72 20 2a 73 74 char *st
5370: 72 69 6e 67 20 3d 20 58 35 30 39 5f 61 6c 69 61 ring = X509_alia
5380: 73 5f 67 65 74 30 28 63 65 72 74 2c 20 26 6c 65 s_get0(cert, &le
5390: 6e 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 n);..LAPPEND_STR
53a0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
53b0: 2c 20 22 61 6c 69 61 73 22 2c 20 73 74 72 69 6e , "alias", strin
53c0: 67 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 g, (Tcl_Size) le
53d0: 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f n);. }.. /
53e0: 2a 20 43 65 72 74 69 66 69 63 61 74 65 20 61 6e * Certificate an
53f0: 64 20 64 75 6d 70 20 61 6c 6c 20 64 61 74 61 20 d dump all data
5400: 2a 2f 0a 20 20 20 20 7b 0a 09 63 68 61 72 20 63 */. {..char c
5410: 65 72 74 53 74 72 5b 43 45 52 54 5f 53 54 52 5f ertStr[CERT_STR_
5420: 53 49 5a 45 5d 3b 0a 0a 09 2f 2a 20 47 65 74 20 SIZE];.../* Get
5430: 63 65 72 74 69 66 69 63 61 74 65 20 2a 2f 0a 09 certificate */..
5440: 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 len = BIO_to_Buf
5450: 66 65 72 28 50 45 4d 5f 77 72 69 74 65 5f 62 69 fer(PEM_write_bi
5460: 6f 5f 58 35 30 39 28 62 69 6f 2c 20 63 65 72 74 o_X509(bio, cert
5470: 29 2c 20 62 69 6f 2c 20 63 65 72 74 53 74 72 2c ), bio, certStr,
5480: 20 43 45 52 54 5f 53 54 52 5f 53 49 5a 45 29 3b CERT_STR_SIZE);
5490: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e ..LAPPEND_STR(in
54a0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
54b0: 63 65 72 74 69 66 69 63 61 74 65 22 2c 20 63 65 certificate", ce
54c0: 72 74 53 74 72 2c 20 28 54 63 6c 5f 53 69 7a 65 rtStr, (Tcl_Size
54d0: 29 20 6c 65 6e 29 3b 0a 0a 09 2f 2a 20 47 65 74 ) len);.../* Get
54e0: 20 61 6c 6c 20 63 65 72 74 20 69 6e 66 6f 20 2a all cert info *
54f0: 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f /..len = BIO_to_
5500: 42 75 66 66 65 72 28 58 35 30 39 5f 70 72 69 6e Buffer(X509_prin
5510: 74 5f 65 78 28 62 69 6f 2c 20 63 65 72 74 2c 20 t_ex(bio, cert,
5520: 66 6c 61 67 73 2c 20 30 29 2c 20 62 69 6f 2c 20 flags, 0), bio,
5530: 63 65 72 74 53 74 72 2c 20 43 45 52 54 5f 53 54 certStr, CERT_ST
5540: 52 5f 53 49 5a 45 29 3b 0a 09 4c 41 50 50 45 4e R_SIZE);..LAPPEN
5550: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 D_STR(interp, ce
5560: 72 74 50 74 72 2c 20 22 61 6c 6c 22 2c 20 63 65 rtPtr, "all", ce
5570: 72 74 53 74 72 2c 20 28 54 63 6c 5f 53 69 7a 65 rtStr, (Tcl_Size
5580: 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 ) len);. }..
5590: 20 20 20 42 49 4f 5f 66 72 65 65 28 62 69 6f 29 BIO_free(bio)
55a0: 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 63 65 72 ;. return cer
55b0: 74 50 74 72 3b 0a 7d 0a tPtr;.}.