Hex Artifact Content

Artifact 033f00bcbce7c3b1ad30824bb6d37c531a91344a294037b3a6d4ee15fb9743d2:


0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20  /*. * Copyright 
0010: 28 43 29 20 31 39 39 37 2d 32 30 30 30 20 53 65  (C) 1997-2000 Se
0020: 6e 73 75 73 20 43 6f 6e 73 75 6c 74 69 6e 67 20  nsus Consulting 
0030: 4c 74 64 2e 0a 20 2a 20 4d 61 74 74 20 4e 65 77  Ltd.. * Matt New
0040: 6d 61 6e 20 3c 6d 61 74 74 40 73 65 6e 73 75 73  man <matt@sensus
0050: 2e 6f 72 67 3e 0a 20 2a 20 43 6f 70 79 72 69 67  .org>. * Copyrig
0060: 68 74 20 28 43 29 20 32 30 32 33 20 42 72 69 61  ht (C) 2023 Bria
0070: 6e 20 4f 27 48 61 67 61 6e 0a 20 2a 2f 0a 23 69  n O'Hagan. */.#i
0080: 6e 63 6c 75 64 65 20 3c 74 63 6c 2e 68 3e 0a 23  nclude <tcl.h>.#
0090: 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68  include <stdio.h
00a0: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e  >.#include <open
00b0: 73 73 6c 2f 62 69 6f 2e 68 3e 0a 23 69 6e 63 6c  ssl/bio.h>.#incl
00c0: 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 73 68 61  ude <openssl/sha
00d0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70  .h>.#include <op
00e0: 65 6e 73 73 6c 2f 78 35 30 39 2e 68 3e 0a 23 69  enssl/x509.h>.#i
00f0: 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f  nclude <openssl/
0100: 78 35 30 39 76 33 2e 68 3e 0a 23 69 6e 63 6c 75  x509v3.h>.#inclu
0110: 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 78 35 30 39  de <openssl/x509
0120: 5f 76 66 79 2e 68 3e 0a 23 69 6e 63 6c 75 64 65  _vfy.h>.#include
0130: 20 3c 6f 70 65 6e 73 73 6c 2f 61 73 6e 31 2e 68   <openssl/asn1.h
0140: 3e 0a 23 69 6e 63 6c 75 64 65 20 22 74 6c 73 49  >.#include "tlsI
0150: 6e 74 2e 68 22 0a 0a 2f 2a 20 44 65 66 69 6e 65  nt.h"../* Define
0160: 20 6d 61 78 69 6d 75 6d 20 63 65 72 74 69 66 69   maximum certifi
0170: 63 61 74 65 20 73 69 7a 65 2e 20 4d 61 78 20 50  cate size. Max P
0180: 45 4d 20 73 69 7a 65 20 31 30 30 6b 42 20 61 6e  EM size 100kB an
0190: 64 20 44 45 52 20 73 69 7a 65 20 69 73 20 32 34  d DER size is 24
01a0: 6b 42 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43  kB. */.#define C
01b0: 45 52 54 5f 53 54 52 5f 53 49 5a 45 20 33 32 37  ERT_STR_SIZE 327
01c0: 36 38 0a 0a 0c 0a 2f 2a 0a 20 2a 20 42 69 6e 61  68..../*. * Bina
01d0: 72 79 20 73 74 72 69 6e 67 20 74 6f 20 68 65 78  ry string to hex
01e0: 20 73 74 72 69 6e 67 0a 20 2a 2f 0a 69 6e 74 20   string. */.int 
01f0: 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 75 6e  String_to_Hex(un
0200: 73 69 67 6e 65 64 20 63 68 61 72 2a 20 69 6e 70  signed char* inp
0210: 75 74 2c 20 69 6e 74 20 69 6c 65 6e 2c 20 75 6e  ut, int ilen, un
0220: 73 69 67 6e 65 64 20 63 68 61 72 20 2a 6f 75 74  signed char *out
0230: 70 75 74 2c 20 69 6e 74 20 6f 6c 65 6e 29 20 7b  put, int olen) {
0240: 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d  .    int count =
0250: 20 30 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 64   0;.    unsigned
0260: 20 63 68 61 72 20 2a 69 70 74 72 20 3d 20 69 6e   char *iptr = in
0270: 70 75 74 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65  put;.    unsigne
0280: 64 20 63 68 61 72 20 2a 6f 70 74 72 20 3d 20 26  d char *optr = &
0290: 6f 75 74 70 75 74 5b 30 5d 3b 0a 20 20 20 20 63  output[0];.    c
02a0: 6f 6e 73 74 20 63 68 61 72 20 2a 68 65 78 20 3d  onst char *hex =
02b0: 20 22 30 31 32 33 34 35 36 37 38 39 61 62 63 64   "0123456789abcd
02c0: 65 66 22 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69  ef";..    for (i
02d0: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 69 6c  nt i = 0; i < il
02e0: 65 6e 20 26 26 20 63 6f 75 6e 74 20 3c 20 6f 6c  en && count < ol
02f0: 65 6e 20 2d 20 31 3b 20 69 2b 2b 2c 20 63 6f 75  en - 1; i++, cou
0300: 6e 74 20 2b 3d 20 32 29 20 7b 0a 20 20 20 20 20  nt += 2) {.     
0310: 20 20 20 2a 6f 70 74 72 2b 2b 20 3d 20 68 65 78     *optr++ = hex
0320: 5b 28 2a 69 70 74 72 3e 3e 34 29 26 30 78 46 5d  [(*iptr>>4)&0xF]
0330: 3b 0a 20 20 20 20 20 20 20 20 2a 6f 70 74 72 2b  ;.        *optr+
0340: 2b 20 3d 20 68 65 78 5b 28 2a 69 70 74 72 2b 2b  + = hex[(*iptr++
0350: 29 26 30 78 46 5d 3b 0a 20 20 20 20 7d 0a 20 20  )&0xF];.    }.  
0360: 20 20 2a 6f 70 74 72 20 3d 20 30 3b 0a 20 20 20    *optr = 0;.   
0370: 20 72 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 7d   return count;.}
0380: 0a 0a 2f 2a 0a 20 2a 20 42 49 4f 20 74 6f 20 42  ../*. * BIO to B
0390: 75 66 66 65 72 0a 20 2a 2f 0a 69 6e 74 20 42 49  uffer. */.int BI
03a0: 4f 5f 74 6f 5f 42 75 66 66 65 72 28 69 6e 74 20  O_to_Buffer(int 
03b0: 72 65 73 75 6c 74 2c 20 42 49 4f 20 2a 62 69 6f  result, BIO *bio
03c0: 2c 20 76 6f 69 64 20 2a 62 75 66 66 65 72 2c 20  , void *buffer, 
03d0: 69 6e 74 20 73 69 7a 65 29 20 7b 0a 20 20 20 20  int size) {.    
03e0: 69 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20  int len = 0;.   
03f0: 20 69 6e 74 20 70 65 6e 64 69 6e 67 20 3d 20 42   int pending = B
0400: 49 4f 5f 70 65 6e 64 69 6e 67 28 62 69 6f 29 3b  IO_pending(bio);
0410: 0a 0a 20 20 20 20 69 66 20 28 72 65 73 75 6c 74  ..    if (result
0420: 29 20 7b 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 72  ) {..len = BIO_r
0430: 65 61 64 28 62 69 6f 2c 20 62 75 66 66 65 72 2c  ead(bio, buffer,
0440: 20 28 70 65 6e 64 69 6e 67 20 3c 20 73 69 7a 65   (pending < size
0450: 29 20 3f 20 70 65 6e 64 69 6e 67 20 3a 20 73 69  ) ? pending : si
0460: 7a 65 29 3b 0a 09 28 76 6f 69 64 29 42 49 4f 5f  ze);..(void)BIO_
0470: 66 6c 75 73 68 28 62 69 6f 29 3b 0a 09 69 66 20  flush(bio);..if 
0480: 28 6c 65 6e 20 3c 20 30 29 20 7b 0a 09 20 20 20  (len < 0) {..   
0490: 20 6c 65 6e 20 3d 20 30 3b 0a 09 7d 0a 20 20 20   len = 0;..}.   
04a0: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 65   }.    return le
04b0: 6e 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 47 65 74  n;.}.../*. * Get
04c0: 20 58 35 30 39 20 43 65 72 74 69 66 69 63 61 74   X509 Certificat
04d0: 65 20 45 78 74 65 6e 73 69 6f 6e 73 0a 20 2a 2f  e Extensions. */
04e0: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35  .Tcl_Obj *Tls_x5
04f0: 30 39 45 78 74 65 6e 73 69 6f 6e 73 28 54 63 6c  09Extensions(Tcl
0500: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
0510: 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20   X509 *cert) {. 
0520: 20 20 20 63 6f 6e 73 74 20 53 54 41 43 4b 5f 4f     const STACK_O
0530: 46 28 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e  F(X509_EXTENSION
0540: 29 20 2a 65 78 74 73 3b 0a 20 20 20 20 54 63 6c  ) *exts;.    Tcl
0550: 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20  _Obj *listPtr = 
0560: 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30  Tcl_NewListObj(0
0570: 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66  , NULL);..    if
0580: 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c   (listPtr == NUL
0590: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c  L) {..return NUL
05a0: 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66  L;.    }..    if
05b0: 20 28 28 65 78 74 73 20 3d 20 58 35 30 39 5f 67   ((exts = X509_g
05c0: 65 74 30 5f 65 78 74 65 6e 73 69 6f 6e 73 28 63  et0_extensions(c
05d0: 65 72 74 29 29 20 21 3d 20 4e 55 4c 4c 29 20 7b  ert)) != NULL) {
05e0: 0a 09 66 6f 72 20 28 69 6e 74 20 69 3d 30 3b 20  ..for (int i=0; 
05f0: 69 20 3c 20 58 35 30 39 5f 67 65 74 5f 65 78 74  i < X509_get_ext
0600: 5f 63 6f 75 6e 74 28 63 65 72 74 29 3b 20 69 2b  _count(cert); i+
0610: 2b 29 20 7b 0a 09 20 20 20 20 58 35 30 39 5f 45  +) {..    X509_E
0620: 58 54 45 4e 53 49 4f 4e 20 2a 65 78 20 3d 20 73  XTENSION *ex = s
0630: 6b 5f 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e  k_X509_EXTENSION
0640: 5f 76 61 6c 75 65 28 65 78 74 73 2c 20 69 29 3b  _value(exts, i);
0650: 0a 09 20 20 20 20 41 53 4e 31 5f 4f 42 4a 45 43  ..    ASN1_OBJEC
0660: 54 20 2a 6f 62 6a 20 3d 20 58 35 30 39 5f 45 58  T *obj = X509_EX
0670: 54 45 4e 53 49 4f 4e 5f 67 65 74 5f 6f 62 6a 65  TENSION_get_obje
0680: 63 74 28 65 78 29 3b 0a 09 20 20 20 20 2f 2a 20  ct(ex);..    /* 
0690: 41 53 4e 31 5f 4f 43 54 45 54 5f 53 54 52 49 4e  ASN1_OCTET_STRIN
06a0: 47 20 2a 64 61 74 61 20 3d 20 58 35 30 39 5f 45  G *data = X509_E
06b0: 58 54 45 4e 53 49 4f 4e 5f 67 65 74 5f 64 61 74  XTENSION_get_dat
06c0: 61 28 65 78 29 3b 20 2a 2f 0a 09 20 20 20 20 69  a(ex); */..    i
06d0: 6e 74 20 63 72 69 74 69 63 61 6c 20 3d 20 58 35  nt critical = X5
06e0: 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67 65 74  09_EXTENSION_get
06f0: 5f 63 72 69 74 69 63 61 6c 28 65 78 29 3b 0a 09  _critical(ex);..
0700: 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c      LAPPEND_BOOL
0710: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
0720: 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 4f 42 4a  , OBJ_nid2ln(OBJ
0730: 5f 6f 62 6a 32 6e 69 64 28 6f 62 6a 29 29 2c 20  _obj2nid(obj)), 
0740: 63 72 69 74 69 63 61 6c 29 3b 0a 09 7d 0a 20 20  critical);..}.  
0750: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c    }.    return l
0760: 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a  istPtr;.}../*. *
0770: 20 47 65 74 20 41 75 74 68 6f 72 69 74 79 20 61   Get Authority a
0780: 6e 64 20 53 75 62 6a 65 63 74 20 4b 65 79 20 49  nd Subject Key I
0790: 64 65 6e 74 69 66 69 65 72 73 0a 20 2a 2f 0a 54  dentifiers. */.T
07a0: 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39  cl_Obj *Tls_x509
07b0: 49 64 65 6e 74 69 66 69 65 72 28 63 6f 6e 73 74  Identifier(const
07c0: 20 41 53 4e 31 5f 4f 43 54 45 54 5f 53 54 52 49   ASN1_OCTET_STRI
07d0: 4e 47 20 2a 61 73 74 72 69 6e 67 29 20 7b 0a 20  NG *astring) {. 
07e0: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 72 65 73 75     Tcl_Obj *resu
07f0: 6c 74 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20  ltPtr = NULL;.  
0800: 20 20 69 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20    int len = 0;. 
0810: 20 20 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72     unsigned char
0820: 20 62 75 66 66 65 72 5b 31 30 32 34 5d 3b 0a 0a   buffer[1024];..
0830: 20 20 20 20 69 66 20 28 61 73 74 72 69 6e 67 20      if (astring 
0840: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 6c 65 6e 20  != NULL) {..len 
0850: 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28  = String_to_Hex(
0860: 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a  (unsigned char *
0870: 29 41 53 4e 31 5f 53 54 52 49 4e 47 5f 67 65 74  )ASN1_STRING_get
0880: 30 5f 64 61 74 61 28 61 73 74 72 69 6e 67 29 2c  0_data(astring),
0890: 0a 09 20 20 20 20 41 53 4e 31 5f 53 54 52 49 4e  ..    ASN1_STRIN
08a0: 47 5f 6c 65 6e 67 74 68 28 61 73 74 72 69 6e 67  G_length(astring
08b0: 29 2c 20 62 75 66 66 65 72 2c 20 31 30 32 34 29  ), buffer, 1024)
08c0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 73 75  ;.    }.    resu
08d0: 6c 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 53  ltPtr = Tcl_NewS
08e0: 74 72 69 6e 67 4f 62 6a 28 28 63 68 61 72 20 2a  tringObj((char *
08f0: 29 20 26 62 75 66 66 65 72 5b 30 5d 2c 20 28 54  ) &buffer[0], (T
0900: 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20  cl_Size) len);. 
0910: 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c 74     return result
0920: 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65  Ptr;.}../*. * Ge
0930: 74 20 4b 65 79 20 55 73 61 67 65 0a 20 2a 2f 0a  t Key Usage. */.
0940: 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30  Tcl_Obj *Tls_x50
0950: 39 4b 65 79 55 73 61 67 65 28 54 63 6c 5f 49 6e  9KeyUsage(Tcl_In
0960: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35  terp *interp, X5
0970: 30 39 20 2a 63 65 72 74 2c 20 75 69 6e 74 33 32  09 *cert, uint32
0980: 5f 74 20 78 66 6c 61 67 73 29 20 7b 0a 20 20 20  _t xflags) {.   
0990: 20 75 69 6e 74 33 32 5f 74 20 75 73 61 67 65 20   uint32_t usage 
09a0: 3d 20 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f 75  = X509_get_key_u
09b0: 73 61 67 65 28 63 65 72 74 29 3b 0a 20 20 20 20  sage(cert);.    
09c0: 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72  Tcl_Obj *listPtr
09d0: 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62   = Tcl_NewListOb
09e0: 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20  j(0, NULL);..   
09f0: 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20   if (listPtr == 
0a00: 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20  NULL) {..return 
0a10: 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  NULL;.    }..   
0a20: 20 69 66 20 28 28 78 66 6c 61 67 73 20 26 20 45   if ((xflags & E
0a30: 58 46 4c 41 47 5f 4b 55 53 41 47 45 29 20 26 26  XFLAG_KUSAGE) &&
0a40: 20 75 73 61 67 65 20 3c 20 55 49 4e 54 33 32 5f   usage < UINT32_
0a50: 4d 41 58 29 20 7b 0a 09 69 66 20 28 75 73 61 67  MAX) {..if (usag
0a60: 65 20 26 20 4b 55 5f 44 49 47 49 54 41 4c 5f 53  e & KU_DIGITAL_S
0a70: 49 47 4e 41 54 55 52 45 29 20 7b 0a 09 20 20 20  IGNATURE) {..   
0a80: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
0a90: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
0aa0: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e  , listPtr, Tcl_N
0ab0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 69 67  ewStringObj("Dig
0ac0: 69 74 61 6c 20 53 69 67 6e 61 74 75 72 65 22 2c  ital Signature",
0ad0: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
0ae0: 73 61 67 65 20 26 20 4b 55 5f 4e 4f 4e 5f 52 45  sage & KU_NON_RE
0af0: 50 55 44 49 41 54 49 4f 4e 29 20 7b 0a 09 20 20  PUDIATION) {..  
0b00: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
0b10: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
0b20: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
0b30: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4e 6f  NewStringObj("No
0b40: 6e 2d 52 65 70 75 64 69 61 74 69 6f 6e 22 2c 20  n-Repudiation", 
0b50: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
0b60: 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 45 4e 43  age & KU_KEY_ENC
0b70: 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a 09 20 20  IPHERMENT) {..  
0b80: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
0b90: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
0ba0: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
0bb0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b 65  NewStringObj("Ke
0bc0: 79 20 45 6e 63 69 70 68 65 72 6d 65 6e 74 22 2c  y Encipherment",
0bd0: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
0be0: 73 61 67 65 20 26 20 4b 55 5f 44 41 54 41 5f 45  sage & KU_DATA_E
0bf0: 4e 43 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a 09  NCIPHERMENT) {..
0c00: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
0c10: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
0c20: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
0c30: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
0c40: 44 61 74 61 20 45 6e 63 69 70 68 65 72 6d 65 6e  Data Enciphermen
0c50: 74 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66  t", -1));..}..if
0c60: 20 28 75 73 61 67 65 20 26 20 4b 55 5f 4b 45 59   (usage & KU_KEY
0c70: 5f 41 47 52 45 45 4d 45 4e 54 29 20 7b 0a 09 20  _AGREEMENT) {.. 
0c80: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
0c90: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
0ca0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
0cb0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b  _NewStringObj("K
0cc0: 65 79 20 41 67 72 65 65 6d 65 6e 74 22 2c 20 2d  ey Agreement", -
0cd0: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
0ce0: 67 65 20 26 20 4b 55 5f 4b 45 59 5f 43 45 52 54  ge & KU_KEY_CERT
0cf0: 5f 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 63  _SIGN) {..    Tc
0d00: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
0d10: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
0d20: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
0d30: 74 72 69 6e 67 4f 62 6a 28 22 43 65 72 74 69 66  tringObj("Certif
0d40: 69 63 61 74 65 20 53 69 67 6e 69 6e 67 22 2c 20  icate Signing", 
0d50: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
0d60: 61 67 65 20 26 20 4b 55 5f 43 52 4c 5f 53 49 47  age & KU_CRL_SIG
0d70: 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69  N) {..    Tcl_Li
0d80: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
0d90: 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  nt(interp, listP
0da0: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  tr, Tcl_NewStrin
0db0: 67 4f 62 6a 28 22 43 52 4c 20 53 69 67 6e 69 6e  gObj("CRL Signin
0dc0: 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66  g", -1));..}..if
0dd0: 20 28 75 73 61 67 65 20 26 20 4b 55 5f 45 4e 43   (usage & KU_ENC
0de0: 49 50 48 45 52 5f 4f 4e 4c 59 29 20 7b 0a 09 20  IPHER_ONLY) {.. 
0df0: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
0e00: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
0e10: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
0e20: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 45  _NewStringObj("E
0e30: 6e 63 69 70 68 65 72 20 4f 6e 6c 79 22 2c 20 2d  ncipher Only", -
0e40: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
0e50: 67 65 20 26 20 4b 55 5f 44 45 43 49 50 48 45 52  ge & KU_DECIPHER
0e60: 5f 4f 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 63  _ONLY) {..    Tc
0e70: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
0e80: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
0e90: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
0ea0: 74 72 69 6e 67 4f 62 6a 28 22 44 65 63 69 70 68  tringObj("Deciph
0eb0: 65 72 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b 0a  er Only", -1));.
0ec0: 09 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a  .}.    } else {.
0ed0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
0ee0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
0ef0: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54  terp, listPtr, T
0f00: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
0f10: 22 75 6e 72 65 73 74 72 69 63 74 65 64 22 2c 20  "unrestricted", 
0f20: 2d 31 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  -1));.    }.    
0f30: 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a  return listPtr;.
0f40: 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 65 72  }../*. * Get Cer
0f50: 74 69 66 69 63 61 74 65 20 50 75 72 70 6f 73 65  tificate Purpose
0f60: 0a 20 2a 2f 0a 63 68 61 72 20 2a 54 6c 73 5f 78  . */.char *Tls_x
0f70: 35 30 39 50 75 72 70 6f 73 65 28 58 35 30 39 20  509Purpose(X509 
0f80: 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 63 68 61  *cert) {.    cha
0f90: 72 20 2a 70 75 72 70 6f 73 65 20 3d 20 4e 55 4c  r *purpose = NUL
0fa0: 4c 3b 0a 0a 20 20 20 20 69 66 20 28 58 35 30 39  L;..    if (X509
0fb0: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63  _check_purpose(c
0fc0: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53  ert, X509_PURPOS
0fd0: 45 5f 53 53 4c 5f 43 4c 49 45 4e 54 2c 20 30 29  E_SSL_CLIENT, 0)
0fe0: 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65   > 0) {..purpose
0ff0: 20 3d 20 22 53 53 4c 20 43 6c 69 65 6e 74 22 3b   = "SSL Client";
1000: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28  .    } else if (
1010: 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f  X509_check_purpo
1020: 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55  se(cert, X509_PU
1030: 52 50 4f 53 45 5f 53 53 4c 5f 53 45 52 56 45 52  RPOSE_SSL_SERVER
1040: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72  , 0) > 0) {..pur
1050: 70 6f 73 65 20 3d 20 22 53 53 4c 20 53 65 72 76  pose = "SSL Serv
1060: 65 72 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20  er";.    } else 
1070: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70  if (X509_check_p
1080: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30  urpose(cert, X50
1090: 39 5f 50 55 52 50 4f 53 45 5f 4e 53 5f 53 53 4c  9_PURPOSE_NS_SSL
10a0: 5f 53 45 52 56 45 52 2c 20 30 29 20 3e 20 30 29  _SERVER, 0) > 0)
10b0: 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 4d   {..purpose = "M
10c0: 53 53 20 53 53 4c 20 53 65 72 76 65 72 22 3b 0a  SS SSL Server";.
10d0: 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58      } else if (X
10e0: 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73  509_check_purpos
10f0: 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52  e(cert, X509_PUR
1100: 50 4f 53 45 5f 53 4d 49 4d 45 5f 53 49 47 4e 2c  POSE_SMIME_SIGN,
1110: 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70   0) > 0) {..purp
1120: 6f 73 65 20 3d 20 22 53 4d 49 4d 45 20 53 69 67  ose = "SMIME Sig
1130: 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c 73  ning";.    } els
1140: 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b  e if (X509_check
1150: 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58  _purpose(cert, X
1160: 35 30 39 5f 50 55 52 50 4f 53 45 5f 53 4d 49 4d  509_PURPOSE_SMIM
1170: 45 5f 45 4e 43 52 59 50 54 2c 20 30 29 20 3e 20  E_ENCRYPT, 0) > 
1180: 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20  0) {..purpose = 
1190: 22 53 4d 49 4d 45 20 45 6e 63 72 79 70 74 69 6f  "SMIME Encryptio
11a0: 6e 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69  n";.    } else i
11b0: 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75  f (X509_check_pu
11c0: 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39  rpose(cert, X509
11d0: 5f 50 55 52 50 4f 53 45 5f 43 52 4c 5f 53 49 47  _PURPOSE_CRL_SIG
11e0: 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75  N, 0) > 0) {..pu
11f0: 72 70 6f 73 65 20 3d 20 22 43 52 4c 20 53 69 67  rpose = "CRL Sig
1200: 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c 73  ning";.    } els
1210: 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b  e if (X509_check
1220: 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58  _purpose(cert, X
1230: 35 30 39 5f 50 55 52 50 4f 53 45 5f 41 4e 59 2c  509_PURPOSE_ANY,
1240: 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70   0) > 0) {..purp
1250: 6f 73 65 20 3d 20 22 41 6e 79 22 3b 0a 20 20 20  ose = "Any";.   
1260: 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39   } else if (X509
1270: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63  _check_purpose(c
1280: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53  ert, X509_PURPOS
1290: 45 5f 4f 43 53 50 5f 48 45 4c 50 45 52 2c 20 30  E_OCSP_HELPER, 0
12a0: 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73  ) > 0) {..purpos
12b0: 65 20 3d 20 22 4f 43 53 50 20 48 65 6c 70 65 72  e = "OCSP Helper
12c0: 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66  ";.    } else if
12d0: 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72   (X509_check_pur
12e0: 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f  pose(cert, X509_
12f0: 50 55 52 50 4f 53 45 5f 54 49 4d 45 53 54 41 4d  PURPOSE_TIMESTAM
1300: 50 5f 53 49 47 4e 2c 20 30 29 20 3e 20 30 29 20  P_SIGN, 0) > 0) 
1310: 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 54 69  {..purpose = "Ti
1320: 6d 65 73 74 61 6d 70 20 53 69 67 6e 69 6e 67 22  mestamp Signing"
1330: 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09  ;.    } else {..
1340: 70 75 72 70 6f 73 65 20 3d 20 22 22 3b 0a 20 20  purpose = "";.  
1350: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 70    }.    return p
1360: 75 72 70 6f 73 65 3b 0a 7d 0a 0a 2f 2a 0a 20 2a  urpose;.}../*. *
1370: 20 46 6f 72 20 65 61 63 68 20 70 75 72 70 6f 73   For each purpos
1380: 65 2c 20 67 65 74 20 63 65 72 74 69 66 69 63 61  e, get certifica
1390: 74 65 20 61 70 70 6c 69 63 61 62 69 6c 69 74 79  te applicability
13a0: 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c  . */.Tcl_Obj *Tl
13b0: 73 5f 78 35 30 39 50 75 72 70 6f 73 65 73 28 54  s_x509Purposes(T
13c0: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  cl_Interp *inter
13d0: 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b  p, X509 *cert) {
13e0: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69  .    Tcl_Obj *li
13f0: 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c  stPtr = Tcl_NewL
1400: 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b  istObj(0, NULL);
1410: 0a 20 20 20 20 58 35 30 39 5f 50 55 52 50 4f 53  .    X509_PURPOS
1420: 45 20 2a 70 74 6d 70 3b 0a 0a 20 20 20 20 69 66  E *ptmp;..    if
1430: 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c   (listPtr == NUL
1440: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c  L) {..return NUL
1450: 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 66 6f  L;.    }..    fo
1460: 72 20 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 20  r (int i = 0; i 
1470: 3c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67  < X509_PURPOSE_g
1480: 65 74 5f 63 6f 75 6e 74 28 29 3b 20 69 2b 2b 29  et_count(); i++)
1490: 20 7b 0a 09 70 74 6d 70 20 3d 20 58 35 30 39 5f   {..ptmp = X509_
14a0: 50 55 52 50 4f 53 45 5f 67 65 74 30 28 69 29 3b  PURPOSE_get0(i);
14b0: 0a 09 54 63 6c 5f 4f 62 6a 20 2a 74 6d 70 50 74  ..Tcl_Obj *tmpPt
14c0: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f  r = Tcl_NewListO
14d0: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 66  bj(0, NULL);...f
14e0: 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20 6a  or (int j = 0; j
14f0: 20 3c 20 32 3b 20 6a 2b 2b 29 20 7b 0a 09 20 20   < 2; j++) {..  
1500: 20 20 69 6e 74 20 69 64 72 65 74 20 3d 20 58 35    int idret = X5
1510: 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65  09_check_purpose
1520: 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50  (cert, X509_PURP
1530: 4f 53 45 5f 67 65 74 5f 69 64 28 70 74 6d 70 29  OSE_get_id(ptmp)
1540: 2c 20 6a 29 3b 0a 09 20 20 20 20 54 63 6c 5f 4c  , j);..    Tcl_L
1550: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
1560: 65 6e 74 28 69 6e 74 65 72 70 2c 20 74 6d 70 50  ent(interp, tmpP
1570: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  tr, Tcl_NewStrin
1580: 67 4f 62 6a 28 6a 20 3f 20 22 43 41 22 20 3a 20  gObj(j ? "CA" : 
1590: 22 6e 6f 6e 43 41 22 2c 20 2d 31 29 29 3b 0a 09  "nonCA", -1));..
15a0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
15b0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
15c0: 65 72 70 2c 20 74 6d 70 50 74 72 2c 20 54 63 6c  erp, tmpPtr, Tcl
15d0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 69 64  _NewStringObj(id
15e0: 72 65 74 20 3d 3d 20 31 20 3f 20 22 59 65 73 22  ret == 1 ? "Yes"
15f0: 20 3a 20 22 4e 6f 22 2c 20 2d 31 29 29 3b 0a 09   : "No", -1));..
1600: 7d 0a 09 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69  }..LAPPEND_OBJ(i
1610: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20  nterp, listPtr, 
1620: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 74  X509_PURPOSE_get
1630: 30 5f 6e 61 6d 65 28 70 74 6d 70 29 2c 20 74 6d  0_name(ptmp), tm
1640: 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20 20  pPtr);.    }.   
1650: 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b   return listPtr;
1660: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 53 75  .}../*. * Get Su
1670: 62 6a 65 63 74 20 41 6c 74 65 72 6e 61 74 65 20  bject Alternate 
1680: 4e 61 6d 65 73 20 28 53 41 4e 29 20 61 6e 64 20  Names (SAN) and 
1690: 49 73 73 75 65 72 20 41 6c 74 65 72 6e 61 74 65  Issuer Alternate
16a0: 20 4e 61 6d 65 73 0a 20 2a 2f 0a 54 63 6c 5f 4f   Names. */.Tcl_O
16b0: 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4e 61 6d 65  bj *Tls_x509Name
16c0: 73 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e  s(Tcl_Interp *in
16d0: 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74  terp, X509 *cert
16e0: 2c 20 69 6e 74 20 6e 69 64 2c 20 42 49 4f 20 2a  , int nid, BIO *
16f0: 62 69 6f 29 20 7b 0a 20 20 20 20 53 54 41 43 4b  bio) {.    STACK
1700: 5f 4f 46 28 47 45 4e 45 52 41 4c 5f 4e 41 4d 45  _OF(GENERAL_NAME
1710: 29 20 2a 6e 61 6d 65 73 3b 0a 20 20 20 20 54 63  ) *names;.    Tc
1720: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d  l_Obj *listPtr =
1730: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28   Tcl_NewListObj(
1740: 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 69 6e  0, NULL);.    in
1750: 74 20 6c 65 6e 3b 0a 20 20 20 20 63 68 61 72 20  t len;.    char 
1760: 62 75 66 66 65 72 5b 31 30 32 34 5d 3b 0a 0a 20  buffer[1024];.. 
1770: 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d     if (listPtr =
1780: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72  = NULL) {..retur
1790: 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20  n NULL;.    }.. 
17a0: 20 20 20 69 66 20 28 28 6e 61 6d 65 73 20 3d 20     if ((names = 
17b0: 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69  X509_get_ext_d2i
17c0: 28 63 65 72 74 2c 20 6e 69 64 2c 20 4e 55 4c 4c  (cert, nid, NULL
17d0: 2c 20 4e 55 4c 4c 29 29 20 21 3d 20 4e 55 4c 4c  , NULL)) != NULL
17e0: 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 3d  ) {..for (int i=
17f0: 30 3b 20 69 20 3c 20 73 6b 5f 47 45 4e 45 52 41  0; i < sk_GENERA
1800: 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 6e 61 6d 65 73  L_NAME_num(names
1810: 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20 63  ); i++) {..    c
1820: 6f 6e 73 74 20 47 45 4e 45 52 41 4c 5f 4e 41 4d  onst GENERAL_NAM
1830: 45 20 2a 6e 61 6d 65 20 3d 20 73 6b 5f 47 45 4e  E *name = sk_GEN
1840: 45 52 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75 65 28  ERAL_NAME_value(
1850: 6e 61 6d 65 73 2c 20 69 29 3b 0a 0a 09 20 20 20  names, i);...   
1860: 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75   len = BIO_to_Bu
1870: 66 66 65 72 28 6e 61 6d 65 20 26 26 20 47 45 4e  ffer(name && GEN
1880: 45 52 41 4c 5f 4e 41 4d 45 5f 70 72 69 6e 74 28  ERAL_NAME_print(
1890: 62 69 6f 2c 20 28 47 45 4e 45 52 41 4c 5f 4e 41  bio, (GENERAL_NA
18a0: 4d 45 20 2a 29 20 6e 61 6d 65 29 2c 20 62 69 6f  ME *) name), bio
18b0: 2c 20 62 75 66 66 65 72 2c 20 31 30 32 34 29 3b  , buffer, 1024);
18c0: 0a 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54  ..    LAPPEND_ST
18d0: 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74  R(interp, listPt
18e0: 72 2c 20 4e 55 4c 4c 2c 20 62 75 66 66 65 72 2c  r, NULL, buffer,
18f0: 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29   (Tcl_Size) len)
1900: 3b 0a 09 7d 0a 09 73 6b 5f 47 45 4e 45 52 41 4c  ;..}..sk_GENERAL
1910: 5f 4e 41 4d 45 5f 70 6f 70 5f 66 72 65 65 28 6e  _NAME_pop_free(n
1920: 61 6d 65 73 2c 20 47 45 4e 45 52 41 4c 5f 4e 41  ames, GENERAL_NA
1930: 4d 45 5f 66 72 65 65 29 3b 0a 20 20 20 20 7d 0a  ME_free);.    }.
1940: 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50      return listP
1950: 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74  tr;.}../*. * Get
1960: 20 45 58 74 65 6e 64 65 64 20 4b 65 79 20 55 73   EXtended Key Us
1970: 61 67 65 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20  age. */.Tcl_Obj 
1980: 2a 54 6c 73 5f 78 35 30 39 45 78 74 4b 65 79 55  *Tls_x509ExtKeyU
1990: 73 61 67 65 28 54 63 6c 5f 49 6e 74 65 72 70 20  sage(Tcl_Interp 
19a0: 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63  *interp, X509 *c
19b0: 65 72 74 2c 20 75 69 6e 74 33 32 5f 74 20 78 66  ert, uint32_t xf
19c0: 6c 61 67 73 29 20 7b 0a 20 20 20 20 75 69 6e 74  lags) {.    uint
19d0: 33 32 5f 74 20 75 73 61 67 65 20 3d 20 58 35 30  32_t usage = X50
19e0: 39 5f 67 65 74 5f 6b 65 79 5f 75 73 61 67 65 28  9_get_key_usage(
19f0: 63 65 72 74 29 3b 0a 20 20 20 20 54 63 6c 5f 4f  cert);.    Tcl_O
1a00: 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 63  bj *listPtr = Tc
1a10: 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20  l_NewListObj(0, 
1a20: 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28  NULL);..    if (
1a30: 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29  listPtr == NULL)
1a40: 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b   {..return NULL;
1a50: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28  .    }..    if (
1a60: 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47  (xflags & EXFLAG
1a70: 5f 58 4b 55 53 41 47 45 29 20 26 26 20 75 73 61  _XKUSAGE) && usa
1a80: 67 65 20 3c 20 55 49 4e 54 33 32 5f 4d 41 58 29  ge < UINT32_MAX)
1a90: 20 7b 0a 09 75 73 61 67 65 20 3d 20 58 35 30 39   {..usage = X509
1aa0: 5f 67 65 74 5f 65 78 74 65 6e 64 65 64 5f 6b 65  _get_extended_ke
1ab0: 79 5f 75 73 61 67 65 28 63 65 72 74 29 3b 0a 0a  y_usage(cert);..
1ac0: 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55  .if (usage & XKU
1ad0: 5f 53 53 4c 5f 53 45 52 56 45 52 29 20 7b 0a 09  _SSL_SERVER) {..
1ae0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
1af0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
1b00: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
1b10: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
1b20: 54 4c 53 20 57 65 62 20 53 65 72 76 65 72 20 41  TLS Web Server A
1b30: 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 22 2c 20  uthentication", 
1b40: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
1b50: 61 67 65 20 26 20 58 4b 55 5f 53 53 4c 5f 43 4c  age & XKU_SSL_CL
1b60: 49 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 6c  IENT) {..    Tcl
1b70: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
1b80: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69  ement(interp, li
1b90: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  stPtr, Tcl_NewSt
1ba0: 72 69 6e 67 4f 62 6a 28 22 54 4c 53 20 57 65 62  ringObj("TLS Web
1bb0: 20 43 6c 69 65 6e 74 20 41 75 74 68 65 6e 74 69   Client Authenti
1bc0: 63 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09  cation", -1));..
1bd0: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58  }..if (usage & X
1be0: 4b 55 5f 53 4d 49 4d 45 29 20 7b 0a 09 20 20 20  KU_SMIME) {..   
1bf0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
1c00: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
1c10: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e  , listPtr, Tcl_N
1c20: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 45 2d 6d  ewStringObj("E-m
1c30: 61 69 6c 20 50 72 6f 74 65 63 74 69 6f 6e 22 2c  ail Protection",
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 43 4f 44 45 5f  sage & XKU_CODE_
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 43 6f 64 65 20 53 69  ringObj("Code 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 53 47 43 29 20 7b 0a 09 20 20 20 20 54 63  U_SGC) {..    Tc
1ce0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
1cf0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
1d00: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
1d10: 74 72 69 6e 67 4f 62 6a 28 22 53 47 43 22 2c 20  tringObj("SGC", 
1d20: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
1d30: 61 67 65 20 26 20 58 4b 55 5f 4f 43 53 50 5f 53  age & XKU_OCSP_S
1d40: 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f  IGN) {..    Tcl_
1d50: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
1d60: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73  ment(interp, lis
1d70: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
1d80: 69 6e 67 4f 62 6a 28 22 4f 43 53 50 20 53 69 67  ingObj("OCSP Sig
1d90: 6e 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a  ning", -1));..}.
1da0: 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55  .if (usage & XKU
1db0: 5f 54 49 4d 45 53 54 41 4d 50 29 20 7b 0a 09 20  _TIMESTAMP) {.. 
1dc0: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
1dd0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
1de0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
1df0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 54  _NewStringObj("T
1e00: 69 6d 65 20 53 74 61 6d 70 69 6e 67 22 2c 20 2d  ime Stamping", -
1e10: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
1e20: 67 65 20 26 20 58 4b 55 5f 44 56 43 53 20 29 20  ge & XKU_DVCS ) 
1e30: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f  {..    Tcl_ListO
1e40: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28  bjAppendElement(
1e50: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c  interp, listPtr,
1e60: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62   Tcl_NewStringOb
1e70: 6a 28 22 44 56 43 53 22 2c 20 2d 31 29 29 3b 0a  j("DVCS", -1));.
1e80: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20  .}..if (usage & 
1e90: 58 4b 55 5f 41 4e 59 45 4b 55 29 20 7b 0a 09 20  XKU_ANYEKU) {.. 
1ea0: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
1eb0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
1ec0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
1ed0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 41  _NewStringObj("A
1ee0: 6e 79 20 45 78 74 65 6e 64 65 64 20 4b 65 79 20  ny Extended Key 
1ef0: 55 73 61 67 65 22 2c 20 2d 31 29 29 3b 0a 09 7d  Usage", -1));..}
1f00: 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 20  .    } else {.. 
1f10: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
1f20: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
1f30: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
1f40: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 75  _NewStringObj("u
1f50: 6e 72 65 73 74 72 69 63 74 65 64 22 2c 20 2d 31  nrestricted", -1
1f60: 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65  ));.    }.    re
1f70: 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a  turn listPtr;.}.
1f80: 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 52 4c 20 44  ./*. * Get CRL D
1f90: 69 73 74 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e  istribution Poin
1fa0: 74 73 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a  ts. */.Tcl_Obj *
1fb0: 54 6c 73 5f 78 35 30 39 43 72 6c 44 70 28 54 63  Tls_x509CrlDp(Tc
1fc0: 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70  l_Interp *interp
1fd0: 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a  , X509 *cert) {.
1fe0: 20 20 20 20 53 54 41 43 4b 5f 4f 46 28 44 49 53      STACK_OF(DIS
1ff0: 54 5f 50 4f 49 4e 54 29 20 2a 63 72 6c 3b 0a 20  T_POINT) *crl;. 
2000: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74     Tcl_Obj *list
2010: 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73  Ptr = Tcl_NewLis
2020: 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a  tObj(0, NULL);..
2030: 20 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 20      if (listPtr 
2040: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75  == NULL) {..retu
2050: 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a  rn NULL;.    }..
2060: 20 20 20 20 69 66 20 28 28 63 72 6c 20 3d 20 58      if ((crl = X
2070: 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 28  509_get_ext_d2i(
2080: 63 65 72 74 2c 20 4e 49 44 5f 63 72 6c 5f 64 69  cert, NID_crl_di
2090: 73 74 72 69 62 75 74 69 6f 6e 5f 70 6f 69 6e 74  stribution_point
20a0: 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 29 20  s, NULL, NULL)) 
20b0: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 66 6f 72 20  != NULL) {..for 
20c0: 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20 73 6b  (int i=0; i < sk
20d0: 5f 44 49 53 54 5f 50 4f 49 4e 54 5f 6e 75 6d 28  _DIST_POINT_num(
20e0: 63 72 6c 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20  crl); i++) {..  
20f0: 20 20 44 49 53 54 5f 50 4f 49 4e 54 20 2a 64 70    DIST_POINT *dp
2100: 20 3d 20 73 6b 5f 44 49 53 54 5f 50 4f 49 4e 54   = sk_DIST_POINT
2110: 5f 76 61 6c 75 65 28 63 72 6c 2c 20 69 29 3b 0a  _value(crl, i);.
2120: 09 20 20 20 20 44 49 53 54 5f 50 4f 49 4e 54 5f  .    DIST_POINT_
2130: 4e 41 4d 45 20 2a 64 69 73 74 70 6f 69 6e 74 20  NAME *distpoint 
2140: 3d 20 64 70 2d 3e 64 69 73 74 70 6f 69 6e 74 3b  = dp->distpoint;
2150: 0a 0a 09 20 20 20 20 69 66 20 28 64 69 73 74 70  ...    if (distp
2160: 6f 69 6e 74 2d 3e 74 79 70 65 20 3d 3d 20 30 29  oint->type == 0)
2170: 20 7b 0a 09 09 2f 2a 20 66 75 6c 6c 2d 6e 61 6d   {.../* full-nam
2180: 65 20 47 45 4e 45 52 41 4c 49 5a 45 44 4e 41 4d  e GENERALIZEDNAM
2190: 45 20 2a 2f 0a 09 09 66 6f 72 20 28 69 6e 74 20  E */...for (int 
21a0: 6a 20 3d 20 30 3b 20 6a 20 3c 20 73 6b 5f 47 45  j = 0; j < sk_GE
21b0: 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 64  NERAL_NAME_num(d
21c0: 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66  istpoint->name.f
21d0: 75 6c 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20 7b  ullname); j++) {
21e0: 0a 09 09 20 20 20 20 47 45 4e 45 52 41 4c 5f 4e  ...    GENERAL_N
21f0: 41 4d 45 20 2a 67 65 6e 20 3d 20 73 6b 5f 47 45  AME *gen = sk_GE
2200: 4e 45 52 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75 65  NERAL_NAME_value
2210: 28 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65  (distpoint->name
2220: 2e 66 75 6c 6c 6e 61 6d 65 2c 20 6a 29 3b 0a 09  .fullname, j);..
2230: 09 20 20 20 20 69 6e 74 20 74 79 70 65 3b 0a 09  .    int type;..
2240: 09 20 20 20 20 41 53 4e 31 5f 53 54 52 49 4e 47  .    ASN1_STRING
2250: 20 2a 75 72 69 20 3d 20 47 45 4e 45 52 41 4c 5f   *uri = GENERAL_
2260: 4e 41 4d 45 5f 67 65 74 30 5f 76 61 6c 75 65 28  NAME_get0_value(
2270: 67 65 6e 2c 20 26 74 79 70 65 29 3b 0a 09 09 20  gen, &type);... 
2280: 20 20 20 69 66 20 28 74 79 70 65 20 3d 3d 20 47     if (type == G
2290: 45 4e 5f 55 52 49 29 20 7b 0a 09 09 09 4c 41 50  EN_URI) {....LAP
22a0: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
22b0: 20 6c 69 73 74 50 74 72 2c 20 28 63 68 61 72 20   listPtr, (char 
22c0: 2a 29 20 4e 55 4c 4c 2c 20 28 63 68 61 72 20 2a  *) NULL, (char *
22d0: 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 67 65  ) ASN1_STRING_ge
22e0: 74 30 5f 64 61 74 61 28 75 72 69 29 2c 20 28 54  t0_data(uri), (T
22f0: 63 6c 5f 53 69 7a 65 29 20 41 53 4e 31 5f 53 54  cl_Size) ASN1_ST
2300: 52 49 4e 47 5f 6c 65 6e 67 74 68 28 75 72 69 29  RING_length(uri)
2310: 29 3b 0a 09 09 20 20 20 20 7d 0a 09 09 7d 0a 09  );...    }...}..
2320: 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 64      } else if (d
2330: 69 73 74 70 6f 69 6e 74 2d 3e 74 79 70 65 20 3d  istpoint->type =
2340: 3d 20 31 29 20 7b 0a 09 09 2f 2a 20 72 65 6c 61  = 1) {.../* rela
2350: 74 69 76 65 2d 6e 61 6d 65 20 58 35 30 39 4e 41  tive-name X509NA
2360: 4d 45 20 2a 2f 0a 09 09 53 54 41 43 4b 5f 4f 46  ME */...STACK_OF
2370: 28 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59  (X509_NAME_ENTRY
2380: 29 20 2a 73 6b 5f 72 65 6c 6e 61 6d 65 20 3d 20  ) *sk_relname = 
2390: 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e  distpoint->name.
23a0: 72 65 6c 61 74 69 76 65 6e 61 6d 65 3b 0a 09 09  relativename;...
23b0: 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20  for (int j = 0; 
23c0: 6a 20 3c 20 73 6b 5f 58 35 30 39 5f 4e 41 4d 45  j < sk_X509_NAME
23d0: 5f 45 4e 54 52 59 5f 6e 75 6d 28 73 6b 5f 72 65  _ENTRY_num(sk_re
23e0: 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20 7b 0a 09  lname); j++) {..
23f0: 09 20 20 20 20 58 35 30 39 5f 4e 41 4d 45 5f 45  .    X509_NAME_E
2400: 4e 54 52 59 20 2a 65 20 3d 20 73 6b 5f 58 35 30  NTRY *e = sk_X50
2410: 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 76 61 6c  9_NAME_ENTRY_val
2420: 75 65 28 73 6b 5f 72 65 6c 6e 61 6d 65 2c 20 6a  ue(sk_relname, j
2430: 29 3b 0a 09 09 20 20 20 20 41 53 4e 31 5f 53 54  );...    ASN1_ST
2440: 52 49 4e 47 20 2a 64 20 3d 20 58 35 30 39 5f 4e  RING *d = X509_N
2450: 41 4d 45 5f 45 4e 54 52 59 5f 67 65 74 5f 64 61  AME_ENTRY_get_da
2460: 74 61 28 65 29 3b 0a 09 09 20 20 20 20 4c 41 50  ta(e);...    LAP
2470: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
2480: 20 6c 69 73 74 50 74 72 2c 20 28 63 68 61 72 20   listPtr, (char 
2490: 2a 29 20 4e 55 4c 4c 2c 20 28 63 68 61 72 20 2a  *) NULL, (char *
24a0: 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 64 61  ) ASN1_STRING_da
24b0: 74 61 28 64 29 2c 20 28 54 63 6c 5f 53 69 7a 65  ta(d), (Tcl_Size
24c0: 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 6c 65  ) ASN1_STRING_le
24d0: 6e 67 74 68 28 64 29 29 3b 0a 09 09 7d 0a 09 20  ngth(d));...}.. 
24e0: 20 20 20 7d 0a 09 7d 0a 09 43 52 4c 5f 44 49 53     }..}..CRL_DIS
24f0: 54 5f 50 4f 49 4e 54 53 5f 66 72 65 65 28 63 72  T_POINTS_free(cr
2500: 6c 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65  l);.    }.    re
2510: 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a  turn listPtr;.}.
2520: 0a 2f 2a 0a 20 2a 20 47 65 74 20 4f 6e 2d 6c 69  ./*. * Get On-li
2530: 6e 65 20 43 65 72 74 69 66 69 63 61 74 65 20 53  ne Certificate S
2540: 74 61 74 75 73 20 50 72 6f 74 6f 63 6f 6c 20 28  tatus Protocol (
2550: 4f 53 43 50 29 20 55 52 4c 0a 20 2a 2f 0a 54 63  OSCP) URL. */.Tc
2560: 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4f  l_Obj *Tls_x509O
2570: 73 63 70 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a  scp(Tcl_Interp *
2580: 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65  interp, X509 *ce
2590: 72 74 29 20 7b 0a 20 20 20 20 53 54 41 43 4b 5f  rt) {.    STACK_
25a0: 4f 46 28 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e  OF(OPENSSL_STRIN
25b0: 47 29 20 2a 6f 63 73 70 3b 0a 20 20 20 20 54 63  G) *ocsp;.    Tc
25c0: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d  l_Obj *listPtr =
25d0: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28   Tcl_NewListObj(
25e0: 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69  0, NULL);..    i
25f0: 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55  f (listPtr == NU
2600: 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55  LL) {..return NU
2610: 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69  LL;.    }..    i
2620: 66 20 28 28 6f 63 73 70 20 3d 20 58 35 30 39 5f  f ((ocsp = X509_
2630: 67 65 74 31 5f 6f 63 73 70 28 63 65 72 74 29 29  get1_ocsp(cert))
2640: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 66 6f 72   != NULL) {..for
2650: 20 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c   (int i = 0; i <
2660: 20 73 6b 5f 4f 50 45 4e 53 53 4c 5f 53 54 52 49   sk_OPENSSL_STRI
2670: 4e 47 5f 6e 75 6d 28 6f 63 73 70 29 3b 20 69 2b  NG_num(ocsp); i+
2680: 2b 29 20 7b 0a 09 20 20 20 20 4c 41 50 50 45 4e  +) {..    LAPPEN
2690: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 6c 69  D_STR(interp, li
26a0: 73 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 73 6b 5f  stPtr, NULL, sk_
26b0: 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e 47 5f 76  OPENSSL_STRING_v
26c0: 61 6c 75 65 28 6f 63 73 70 2c 20 69 29 2c 20 2d  alue(ocsp, i), -
26d0: 31 29 3b 0a 09 7d 0a 09 58 35 30 39 5f 65 6d 61  1);..}..X509_ema
26e0: 69 6c 5f 66 72 65 65 28 6f 63 73 70 29 3b 0a 20  il_free(ocsp);. 
26f0: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20     }.    return 
2700: 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20  listPtr;.}../*. 
2710: 2a 20 47 65 74 20 43 65 72 74 69 66 69 63 61 74  * Get Certificat
2720: 65 20 41 75 74 68 6f 72 69 74 79 20 28 43 41 29  e Authority (CA)
2730: 20 49 73 73 75 65 72 73 20 55 52 4c 0a 20 2a 2f   Issuers URL. */
2740: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35  .Tcl_Obj *Tls_x5
2750: 30 39 43 61 49 73 73 75 65 72 73 28 54 63 6c 5f  09CaIssuers(Tcl_
2760: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20  Interp *interp, 
2770: 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20  X509 *cert) {.  
2780: 20 20 53 54 41 43 4b 5f 4f 46 28 41 43 43 45 53    STACK_OF(ACCES
2790: 53 5f 44 45 53 43 52 49 50 54 49 4f 4e 29 20 2a  S_DESCRIPTION) *
27a0: 61 64 73 3b 0a 20 20 20 20 41 43 43 45 53 53 5f  ads;.    ACCESS_
27b0: 44 45 53 43 52 49 50 54 49 4f 4e 20 2a 61 64 3b  DESCRIPTION *ad;
27c0: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69  .    Tcl_Obj *li
27d0: 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c  stPtr = Tcl_NewL
27e0: 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b  istObj(0, NULL);
27f0: 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 63 68  .    unsigned ch
2800: 61 72 20 2a 62 75 66 3b 0a 20 20 20 20 69 6e 74  ar *buf;.    int
2810: 20 6c 65 6e 3b 0a 0a 20 20 20 20 69 66 20 28 28   len;..    if ((
2820: 61 64 73 20 3d 20 58 35 30 39 5f 67 65 74 5f 65  ads = X509_get_e
2830: 78 74 5f 64 32 69 28 63 65 72 74 2c 20 4e 49 44  xt_d2i(cert, NID
2840: 5f 69 6e 66 6f 5f 61 63 63 65 73 73 2c 20 4e 55  _info_access, NU
2850: 4c 4c 2c 20 4e 55 4c 4c 29 29 20 21 3d 20 4e 55  LL, NULL)) != NU
2860: 4c 4c 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20  LL) {..for (int 
2870: 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b 5f 41 43  i = 0; i < sk_AC
2880: 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f 4e  CESS_DESCRIPTION
2890: 5f 6e 75 6d 28 61 64 73 29 3b 20 69 2b 2b 29 20  _num(ads); i++) 
28a0: 7b 0a 09 20 20 20 20 61 64 20 3d 20 73 6b 5f 41  {..    ad = sk_A
28b0: 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f  CCESS_DESCRIPTIO
28c0: 4e 5f 76 61 6c 75 65 28 61 64 73 2c 20 69 29 3b  N_value(ads, i);
28d0: 0a 09 20 20 20 20 69 66 20 28 4f 42 4a 5f 6f 62  ..    if (OBJ_ob
28e0: 6a 32 6e 69 64 28 61 64 2d 3e 6d 65 74 68 6f 64  j2nid(ad->method
28f0: 29 20 3d 3d 20 4e 49 44 5f 61 64 5f 63 61 5f 69  ) == NID_ad_ca_i
2900: 73 73 75 65 72 73 20 26 26 20 61 64 2d 3e 6c 6f  ssuers && ad->lo
2910: 63 61 74 69 6f 6e 29 20 7b 0a 09 09 69 66 20 28  cation) {...if (
2920: 61 64 2d 3e 6c 6f 63 61 74 69 6f 6e 2d 3e 74 79  ad->location->ty
2930: 70 65 20 3d 3d 20 47 45 4e 5f 55 52 49 29 20 7b  pe == GEN_URI) {
2940: 0a 09 09 20 20 20 20 6c 65 6e 20 3d 20 41 53 4e  ...    len = ASN
2950: 31 5f 53 54 52 49 4e 47 5f 74 6f 5f 55 54 46 38  1_STRING_to_UTF8
2960: 28 26 62 75 66 2c 20 61 64 2d 3e 6c 6f 63 61 74  (&buf, ad->locat
2970: 69 6f 6e 2d 3e 64 2e 75 6e 69 66 6f 72 6d 52 65  ion->d.uniformRe
2980: 73 6f 75 72 63 65 49 64 65 6e 74 69 66 69 65 72  sourceIdentifier
2990: 29 3b 0a 09 09 20 20 20 20 54 63 6c 5f 4c 69 73  );...    Tcl_Lis
29a0: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e  tObjAppendElemen
29b0: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74  t(interp, listPt
29c0: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67  r, Tcl_NewString
29d0: 4f 62 6a 28 28 63 68 61 72 20 2a 29 20 62 75 66  Obj((char *) buf
29e0: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e  , (Tcl_Size) len
29f0: 29 29 3b 0a 09 09 20 20 20 20 4f 50 45 4e 53 53  ));...    OPENSS
2a00: 4c 5f 66 72 65 65 28 62 75 66 29 3b 0a 09 09 20  L_free(buf);... 
2a10: 20 20 20 62 72 65 61 6b 3b 0a 09 09 7d 0a 09 20     break;...}.. 
2a20: 20 20 20 7d 0a 09 7d 0a 09 2f 2a 20 73 6b 5f 41     }..}../* sk_A
2a30: 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f  CCESS_DESCRIPTIO
2a40: 4e 5f 70 6f 70 5f 66 72 65 65 28 61 64 73 2c 20  N_pop_free(ads, 
2a50: 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49  ACCESS_DESCRIPTI
2a60: 4f 4e 5f 66 72 65 65 29 3b 20 2a 2f 0a 09 41 55  ON_free); */..AU
2a70: 54 48 4f 52 49 54 59 5f 49 4e 46 4f 5f 41 43 43  THORITY_INFO_ACC
2a80: 45 53 53 5f 66 72 65 65 28 61 64 73 29 3b 0a 20  ESS_free(ads);. 
2a90: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20     }.    return 
2aa0: 6c 69 73 74 50 74 72 3b 0a 7d 0a 0c 0a 2f 2a 0a  listPtr;.}.../*.
2ab0: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d   *--------------
2ac0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ae0: 2d 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 0a 20 2a 09  --------*. *. *.
2af0: 54 6c 73 5f 4e 65 77 58 35 30 39 4f 62 6a 20 2d  Tls_NewX509Obj -
2b00: 2d 0a 20 2a 0a 20 2a 09 2d 2d 2d 2d 2d 2d 2d 2d  -. *. *.--------
2b10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b30: 2d 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 09 43 6f 6e  --------*. *.Con
2b40: 76 65 72 74 73 20 61 20 58 35 30 39 20 63 65 72  verts a X509 cer
2b50: 74 69 66 69 63 61 74 65 20 69 6e 74 6f 20 61 20  tificate into a 
2b60: 54 63 6c 5f 4f 62 6a 0a 20 2a 09 2d 2d 2d 2d 2d  Tcl_Obj. *.-----
2b70: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 0a  -----------*. *.
2ba0: 20 2a 09 53 69 64 65 20 65 66 66 65 63 74 73 3a   *.Side effects:
2bb0: 0a 20 2a 09 09 4e 6f 6e 65 0a 20 2a 0a 20 2a 09  . *..None. *. *.
2bc0: 52 65 73 75 6c 74 3a 0a 20 2a 09 09 41 20 54 63  Result:. *..A Tc
2bd0: 6c 20 4c 69 73 74 20 4f 62 6a 65 63 74 20 72 65  l List Object re
2be0: 70 72 65 73 65 6e 74 69 6e 67 20 74 68 65 20 70  presenting the p
2bf0: 72 6f 76 69 64 65 64 0a 20 2a 09 09 58 35 30 39  rovided. *..X509
2c00: 20 63 65 72 74 69 66 69 63 61 74 65 2e 0a 20 2a   certificate.. *
2c10: 0a 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . *-------------
2c20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2c40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 2f 0a 0a  ---------*. */..
2c50: 54 63 6c 5f 4f 62 6a 2a 0a 54 6c 73 5f 4e 65 77  Tcl_Obj*.Tls_New
2c60: 58 35 30 39 4f 62 6a 28 0a 20 20 20 20 54 63 6c  X509Obj(.    Tcl
2c70: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
2c80: 0a 20 20 20 20 58 35 30 39 20 2a 63 65 72 74 29  .    X509 *cert)
2c90: 0a 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a  .{.    Tcl_Obj *
2ca0: 63 65 72 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65  certPtr = Tcl_Ne
2cb0: 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c  wListObj(0, NULL
2cc0: 29 3b 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f 20  );.    BIO *bio 
2cd0: 3d 20 42 49 4f 5f 6e 65 77 28 42 49 4f 5f 73 5f  = BIO_new(BIO_s_
2ce0: 6d 65 6d 28 29 29 3b 0a 20 20 20 20 69 6e 74 20  mem());.    int 
2cf0: 6d 64 6e 69 64 2c 20 70 6b 6e 69 64 2c 20 62 69  mdnid, pknid, bi
2d00: 74 73 2c 20 6c 65 6e 3b 0a 20 20 20 20 75 6e 73  ts, len;.    uns
2d10: 69 67 6e 65 64 20 69 6e 74 20 75 6c 65 6e 3b 0a  igned int ulen;.
2d20: 20 20 20 20 75 69 6e 74 33 32 5f 74 20 78 66 6c      uint32_t xfl
2d30: 61 67 73 3b 0a 20 20 20 20 63 68 61 72 20 62 75  ags;.    char bu
2d40: 66 66 65 72 5b 42 55 46 53 49 5a 5d 3b 0a 20 20  ffer[BUFSIZ];.  
2d50: 20 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20    unsigned char 
2d60: 6d 64 5b 45 56 50 5f 4d 41 58 5f 4d 44 5f 53 49  md[EVP_MAX_MD_SI
2d70: 5a 45 5d 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65  ZE];.    unsigne
2d80: 64 20 6c 6f 6e 67 20 66 6c 61 67 73 20 3d 20 58  d long flags = X
2d90: 4e 5f 46 4c 41 47 5f 52 46 43 32 32 35 33 20 7c  N_FLAG_RFC2253 |
2da0: 20 41 53 4e 31 5f 53 54 52 46 4c 47 53 5f 55 54   ASN1_STRFLGS_UT
2db0: 46 38 5f 43 4f 4e 56 45 52 54 3b 0a 20 20 20 20  F8_CONVERT;.    
2dc0: 66 6c 61 67 73 20 26 3d 20 7e 41 53 4e 31 5f 53  flags &= ~ASN1_S
2dd0: 54 52 46 4c 47 53 5f 45 53 43 5f 4d 53 42 3b 0a  TRFLGS_ESC_MSB;.
2de0: 0a 20 20 20 20 69 66 20 28 69 6e 74 65 72 70 20  .    if (interp 
2df0: 3d 3d 20 4e 55 4c 4c 20 7c 7c 20 63 65 72 74 20  == NULL || cert 
2e00: 3d 3d 20 4e 55 4c 4c 20 7c 7c 20 62 69 6f 20 3d  == NULL || bio =
2e10: 3d 20 4e 55 4c 4c 20 7c 7c 20 63 65 72 74 50 74  = NULL || certPt
2e20: 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65  r == NULL) {..re
2e30: 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d  turn NULL;.    }
2e40: 0a 0a 20 20 20 20 2f 2a 20 53 69 67 6e 61 74 75  ..    /* Signatu
2e50: 72 65 20 61 6c 67 6f 72 69 74 68 6d 20 61 6e 64  re algorithm and
2e60: 20 76 61 6c 75 65 20 2d 20 52 46 43 20 35 32 38   value - RFC 528
2e70: 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 31 2e  0 section 4.1.1.
2e80: 32 20 61 6e 64 20 34 2e 31 2e 31 2e 33 20 2a 2f  2 and 4.1.1.3 */
2e90: 0a 20 20 20 20 2f 2a 20 73 69 67 6e 61 74 75 72  .    /* signatur
2ea0: 65 41 6c 67 6f 72 69 74 68 6d 20 69 73 20 74 68  eAlgorithm is th
2eb0: 65 20 69 64 20 6f 66 20 74 68 65 20 63 72 79 70  e id of the cryp
2ec0: 74 6f 67 72 61 70 68 69 63 20 61 6c 67 6f 72 69  tographic algori
2ed0: 74 68 6d 20 75 73 65 64 20 62 79 20 74 68 65 0a  thm used by the.
2ee0: 09 43 41 20 74 6f 20 73 69 67 6e 20 74 68 69 73  .CA to sign this
2ef0: 20 63 65 72 74 2e 20 73 69 67 6e 61 74 75 72 65   cert. signature
2f00: 56 61 6c 75 65 20 69 73 20 74 68 65 20 64 69 67  Value is the dig
2f10: 69 74 61 6c 20 73 69 67 6e 61 74 75 72 65 20 63  ital signature c
2f20: 6f 6d 70 75 74 65 64 0a 09 75 70 6f 6e 20 74 68  omputed..upon th
2f30: 65 20 41 53 4e 2e 31 20 44 45 52 20 65 6e 63 6f  e ASN.1 DER enco
2f40: 64 65 64 20 74 62 73 43 65 72 74 69 66 69 63 61  ded tbsCertifica
2f50: 74 65 2e 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 6f  te. */.    {..co
2f60: 6e 73 74 20 58 35 30 39 5f 41 4c 47 4f 52 20 2a  nst X509_ALGOR *
2f70: 73 69 67 5f 61 6c 67 3b 0a 09 63 6f 6e 73 74 20  sig_alg;..const 
2f80: 41 53 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20  ASN1_BIT_STRING 
2f90: 2a 73 69 67 3b 0a 09 69 6e 74 20 73 69 67 5f 6e  *sig;..int sig_n
2fa0: 69 64 3b 0a 0a 09 58 35 30 39 5f 67 65 74 30 5f  id;...X509_get0_
2fb0: 73 69 67 6e 61 74 75 72 65 28 26 73 69 67 2c 20  signature(&sig, 
2fc0: 26 73 69 67 5f 61 6c 67 2c 20 63 65 72 74 29 3b  &sig_alg, cert);
2fd0: 0a 09 2f 2a 20 73 69 67 5f 6e 69 64 20 3d 20 58  ../* sig_nid = X
2fe0: 35 30 39 5f 67 65 74 5f 73 69 67 6e 61 74 75 72  509_get_signatur
2ff0: 65 5f 6e 69 64 28 63 65 72 74 29 20 2a 2f 0a 09  e_nid(cert) */..
3000: 73 69 67 5f 6e 69 64 20 3d 20 4f 42 4a 5f 6f 62  sig_nid = OBJ_ob
3010: 6a 32 6e 69 64 28 73 69 67 5f 61 6c 67 2d 3e 61  j2nid(sig_alg->a
3020: 6c 67 6f 72 69 74 68 6d 29 3b 0a 09 4c 41 50 50  lgorithm);..LAPP
3030: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20  END_STR(interp, 
3040: 63 65 72 74 50 74 72 2c 20 22 73 69 67 6e 61 74  certPtr, "signat
3050: 75 72 65 41 6c 67 6f 72 69 74 68 6d 22 2c 20 4f  ureAlgorithm", O
3060: 42 4a 5f 6e 69 64 32 6c 6e 28 73 69 67 5f 6e 69  BJ_nid2ln(sig_ni
3070: 64 29 2c 20 2d 31 29 3b 0a 09 6c 65 6e 20 3d 20  d), -1);..len = 
3080: 28 73 69 67 5f 6e 69 64 20 21 3d 20 4e 49 44 5f  (sig_nid != NID_
3090: 75 6e 64 65 66 29 20 3f 20 53 74 72 69 6e 67 5f  undef) ? String_
30a0: 74 6f 5f 48 65 78 28 73 69 67 2d 3e 64 61 74 61  to_Hex(sig->data
30b0: 2c 20 73 69 67 2d 3e 6c 65 6e 67 74 68 2c 20 28  , sig->length, (
30c0: 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 29  unsigned char *)
30d0: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29   buffer, BUFSIZ)
30e0: 20 3a 20 30 3b 0a 09 4c 41 50 50 45 4e 44 5f 53   : 0;..LAPPEND_S
30f0: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  TR(interp, certP
3100: 74 72 2c 20 22 73 69 67 6e 61 74 75 72 65 56 61  tr, "signatureVa
3110: 6c 75 65 22 2c 20 62 75 66 66 65 72 2c 20 28 54  lue", buffer, (T
3120: 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20  cl_Size) len);. 
3130: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 56 65 72     }..    /* Ver
3140: 73 69 6f 6e 20 6f 66 20 74 68 65 20 65 6e 63 6f  sion of the enco
3150: 64 65 64 20 63 65 72 74 69 66 69 63 61 74 65 20  ded certificate 
3160: 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  - RFC 5280 secti
3170: 6f 6e 20 34 2e 31 2e 32 2e 31 20 2a 2f 0a 20 20  on 4.1.2.1 */.  
3180: 20 20 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e    LAPPEND_INT(in
3190: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
31a0: 76 65 72 73 69 6f 6e 22 2c 20 58 35 30 39 5f 67  version", X509_g
31b0: 65 74 5f 76 65 72 73 69 6f 6e 28 63 65 72 74 29  et_version(cert)
31c0: 2b 31 29 3b 0a 0a 20 20 20 20 2f 2a 20 55 6e 69  +1);..    /* Uni
31d0: 71 75 65 20 6e 75 6d 62 65 72 20 61 73 73 69 67  que number assig
31e0: 6e 65 64 20 62 79 20 43 41 20 74 6f 20 63 65 72  ned by CA to cer
31f0: 74 69 66 69 63 61 74 65 20 2d 20 52 46 43 20 35  tificate - RFC 5
3200: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e  280 section 4.1.
3210: 32 2e 32 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d  2.2 */.    len =
3220: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 69   BIO_to_Buffer(i
3230: 32 61 5f 41 53 4e 31 5f 49 4e 54 45 47 45 52 28  2a_ASN1_INTEGER(
3240: 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30 5f 73  bio, X509_get0_s
3250: 65 72 69 61 6c 4e 75 6d 62 65 72 28 63 65 72 74  erialNumber(cert
3260: 29 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c  )), bio, buffer,
3270: 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41   BUFSIZ);.    LA
3280: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
3290: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65 72 69  , certPtr, "seri
32a0: 61 6c 4e 75 6d 62 65 72 22 2c 20 62 75 66 66 65  alNumber", buffe
32b0: 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65  r, (Tcl_Size) le
32c0: 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 69 67 6e  n);..    /* Sign
32d0: 61 74 75 72 65 20 61 6c 67 6f 72 69 74 68 6d 20  ature algorithm 
32e0: 75 73 65 64 20 62 79 20 74 68 65 20 43 41 20 74  used by the CA t
32f0: 6f 20 73 69 67 6e 20 74 68 65 20 63 65 72 74 69  o sign the certi
3300: 66 69 63 61 74 65 2e 20 4d 75 73 74 20 6d 61 74  ficate. Must mat
3310: 63 68 0a 09 73 69 67 6e 61 74 75 72 65 41 6c 67  ch..signatureAlg
3320: 6f 72 69 74 68 6d 2e 20 52 46 43 20 35 32 38 30  orithm. RFC 5280
3330: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 33   section 4.1.2.3
3340: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f   */.    LAPPEND_
3350: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
3360: 50 74 72 2c 20 22 73 69 67 6e 61 74 75 72 65 22  Ptr, "signature"
3370: 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 58 35 30  , OBJ_nid2ln(X50
3380: 39 5f 67 65 74 5f 73 69 67 6e 61 74 75 72 65 5f  9_get_signature_
3390: 6e 69 64 28 63 65 72 74 29 29 2c 20 2d 31 29 3b  nid(cert)), -1);
33a0: 0a 0a 20 20 20 20 2f 2a 20 49 73 73 75 65 72 20  ..    /* Issuer 
33b0: 69 64 65 6e 74 69 66 69 65 73 20 74 68 65 20 65  identifies the e
33c0: 6e 74 69 74 79 20 74 68 61 74 20 73 69 67 6e 65  ntity that signe
33d0: 64 20 61 6e 64 20 69 73 73 75 65 64 20 74 68 65  d and issued the
33e0: 20 63 65 72 74 2e 20 52 46 43 20 35 32 38 30 20   cert. RFC 5280 
33f0: 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 34 20  section 4.1.2.4 
3400: 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f  */.    len = BIO
3410: 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39 5f  _to_Buffer(X509_
3420: 4e 41 4d 45 5f 70 72 69 6e 74 5f 65 78 28 62 69  NAME_print_ex(bi
3430: 6f 2c 20 58 35 30 39 5f 67 65 74 5f 69 73 73 75  o, X509_get_issu
3440: 65 72 5f 6e 61 6d 65 28 63 65 72 74 29 2c 20 30  er_name(cert), 0
3450: 2c 20 66 6c 61 67 73 29 2c 20 62 69 6f 2c 20 62  , flags), bio, b
3460: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a  uffer, BUFSIZ);.
3470: 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28      LAPPEND_STR(
3480: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
3490: 20 22 69 73 73 75 65 72 22 2c 20 62 75 66 66 65   "issuer", buffe
34a0: 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65  r, (Tcl_Size) le
34b0: 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74  n);..    /* Cert
34c0: 69 66 69 63 61 74 65 20 76 61 6c 69 64 69 74 79  ificate validity
34d0: 20 70 65 72 69 6f 64 20 69 73 20 74 68 65 20 69   period is the i
34e0: 6e 74 65 72 76 61 6c 20 74 68 65 20 43 41 20 77  nterval the CA w
34f0: 61 72 72 61 6e 74 73 20 74 68 61 74 20 69 74 20  arrants that it 
3500: 77 69 6c 6c 0a 09 6d 61 69 6e 74 61 69 6e 20 69  will..maintain i
3510: 6e 66 6f 20 6f 6e 20 74 68 65 20 73 74 61 74 75  nfo on the statu
3520: 73 20 6f 66 20 74 68 65 20 63 65 72 74 69 66 69  s of the certifi
3530: 63 61 74 65 2e 20 52 46 43 20 35 32 38 30 20 73  cate. RFC 5280 s
3540: 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 35 20 2a  ection 4.1.2.5 *
3550: 2f 0a 20 20 20 20 2f 2a 20 47 65 74 20 56 61 6c  /.    /* Get Val
3560: 69 64 69 74 79 20 2d 20 4e 6f 74 20 42 65 66 6f  idity - Not Befo
3570: 72 65 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20  re */.    len = 
3580: 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 41 53  BIO_to_Buffer(AS
3590: 4e 31 5f 54 49 4d 45 5f 70 72 69 6e 74 28 62 69  N1_TIME_print(bi
35a0: 6f 2c 20 58 35 30 39 5f 67 65 74 30 5f 6e 6f 74  o, X509_get0_not
35b0: 42 65 66 6f 72 65 28 63 65 72 74 29 29 2c 20 62  Before(cert)), b
35c0: 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53  io, buffer, BUFS
35d0: 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44  IZ);.    LAPPEND
35e0: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72  _STR(interp, cer
35f0: 74 50 74 72 2c 20 22 6e 6f 74 42 65 66 6f 72 65  tPtr, "notBefore
3600: 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f  ", buffer, (Tcl_
3610: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20  Size) len);..   
3620: 20 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 74 79   /* Get Validity
3630: 20 2d 20 4e 6f 74 20 41 66 74 65 72 20 2a 2f 0a   - Not After */.
3640: 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f      len = BIO_to
3650: 5f 42 75 66 66 65 72 28 41 53 4e 31 5f 54 49 4d  _Buffer(ASN1_TIM
3660: 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 35 30  E_print(bio, X50
3670: 39 5f 67 65 74 30 5f 6e 6f 74 41 66 74 65 72 28  9_get0_notAfter(
3680: 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66  cert)), bio, buf
3690: 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20  fer, BUFSIZ);.  
36a0: 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e    LAPPEND_STR(in
36b0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
36c0: 6e 6f 74 41 66 74 65 72 22 2c 20 62 75 66 66 65  notAfter", buffe
36d0: 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65  r, (Tcl_Size) le
36e0: 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a  n);..    /* Subj
36f0: 65 63 74 20 69 64 65 6e 74 69 66 69 65 73 20 74  ect identifies t
3700: 68 65 20 65 6e 74 69 74 79 20 61 73 73 6f 63 69  he entity associ
3710: 61 74 65 64 20 77 69 74 68 20 74 68 65 20 70 75  ated with the pu
3720: 62 6c 69 63 20 6b 65 79 20 73 74 6f 72 65 64 20  blic key stored 
3730: 69 6e 0a 09 74 68 65 20 73 75 62 6a 65 63 74 20  in..the subject 
3740: 70 75 62 6c 69 63 20 6b 65 79 20 66 69 65 6c 64  public key field
3750: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
3760: 6f 6e 20 34 2e 31 2e 32 2e 36 20 2a 2f 0a 20 20  on 4.1.2.6 */.  
3770: 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42    len = BIO_to_B
3780: 75 66 66 65 72 28 58 35 30 39 5f 4e 41 4d 45 5f  uffer(X509_NAME_
3790: 70 72 69 6e 74 5f 65 78 28 62 69 6f 2c 20 58 35  print_ex(bio, X5
37a0: 30 39 5f 67 65 74 5f 73 75 62 6a 65 63 74 5f 6e  09_get_subject_n
37b0: 61 6d 65 28 63 65 72 74 29 2c 20 30 2c 20 66 6c  ame(cert), 0, fl
37c0: 61 67 73 29 2c 20 62 69 6f 2c 20 62 75 66 66 65  ags), bio, buffe
37d0: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 20  r, BUFSIZ);.    
37e0: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
37f0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 75  rp, certPtr, "su
3800: 62 6a 65 63 74 22 2c 20 62 75 66 66 65 72 2c 20  bject", buffer, 
3810: 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b  (Tcl_Size) len);
3820: 0a 0a 20 20 20 20 2f 2a 20 53 48 41 31 20 44 69  ..    /* SHA1 Di
3830: 67 65 73 74 20 28 46 69 6e 67 65 72 70 72 69 6e  gest (Fingerprin
3840: 74 29 20 6f 66 20 63 65 72 74 20 2d 20 44 45 52  t) of cert - DER
3850: 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20   representation 
3860: 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30 39 5f  */.    if (X509_
3870: 64 69 67 65 73 74 28 63 65 72 74 2c 20 45 56 50  digest(cert, EVP
3880: 5f 73 68 61 31 28 29 2c 20 6d 64 2c 20 26 75 6c  _sha1(), md, &ul
3890: 65 6e 29 29 20 7b 0a 20 20 20 20 6c 65 6e 20 3d  en)) {.    len =
38a0: 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d   String_to_Hex(m
38b0: 64 2c 20 6c 65 6e 2c 20 28 75 6e 73 69 67 6e 65  d, len, (unsigne
38c0: 64 20 63 68 61 72 20 2a 29 20 62 75 66 66 65 72  d char *) buffer
38d0: 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50  , BUFSIZ);..LAPP
38e0: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20  END_STR(interp, 
38f0: 63 65 72 74 50 74 72 2c 20 22 73 68 61 31 5f 68  certPtr, "sha1_h
3900: 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20 28 54  ash", buffer, (T
3910: 63 6c 5f 53 69 7a 65 29 20 75 6c 65 6e 29 3b 0a  cl_Size) ulen);.
3920: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 48      }..    /* SH
3930: 41 32 35 36 20 44 69 67 65 73 74 20 28 46 69 6e  A256 Digest (Fin
3940: 67 65 72 70 72 69 6e 74 29 20 6f 66 20 63 65 72  gerprint) of cer
3950: 74 20 2d 20 44 45 52 20 72 65 70 72 65 73 65 6e  t - DER represen
3960: 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 66  tation */.    if
3970: 20 28 58 35 30 39 5f 64 69 67 65 73 74 28 63 65   (X509_digest(ce
3980: 72 74 2c 20 45 56 50 5f 73 68 61 32 35 36 28 29  rt, EVP_sha256()
3990: 2c 20 6d 64 2c 20 26 75 6c 65 6e 29 29 20 7b 0a  , md, &ulen)) {.
39a0: 20 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67      len = String
39b0: 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 6c 65 6e 2c  _to_Hex(md, len,
39c0: 20 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20   (unsigned char 
39d0: 2a 29 20 62 75 66 66 65 72 2c 20 42 55 46 53 49  *) buffer, BUFSI
39e0: 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52  Z);..LAPPEND_STR
39f0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
3a00: 2c 20 22 73 68 61 32 35 36 5f 68 61 73 68 22 2c  , "sha256_hash",
3a10: 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69   buffer, (Tcl_Si
3a20: 7a 65 29 20 75 6c 65 6e 29 3b 0a 20 20 20 20 7d  ze) ulen);.    }
3a30: 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74  ..    /* Subject
3a40: 20 50 75 62 6c 69 63 20 4b 65 79 20 49 6e 66 6f   Public Key Info
3a50: 20 73 70 65 63 69 66 69 65 73 20 74 68 65 20 70   specifies the p
3a60: 75 62 6c 69 63 20 6b 65 79 20 61 6e 64 20 69 64  ublic key and id
3a70: 65 6e 74 69 66 69 65 73 20 74 68 65 0a 09 61 6c  entifies the..al
3a80: 67 6f 72 69 74 68 6d 20 77 69 74 68 20 77 68 69  gorithm with whi
3a90: 63 68 20 74 68 65 20 6b 65 79 20 69 73 20 75 73  ch the key is us
3aa0: 65 64 2e 20 52 46 43 20 35 32 38 30 20 73 65 63  ed. RFC 5280 sec
3ab0: 74 69 6f 6e 20 34 2e 31 2e 32 2e 37 20 2a 2f 0a  tion 4.1.2.7 */.
3ac0: 20 20 20 20 69 66 20 28 58 35 30 39 5f 67 65 74      if (X509_get
3ad0: 5f 73 69 67 6e 61 74 75 72 65 5f 69 6e 66 6f 28  _signature_info(
3ae0: 63 65 72 74 2c 20 26 6d 64 6e 69 64 2c 20 26 70  cert, &mdnid, &p
3af0: 6b 6e 69 64 2c 20 26 62 69 74 73 2c 20 26 78 66  knid, &bits, &xf
3b00: 6c 61 67 73 29 29 20 7b 0a 09 41 53 4e 31 5f 42  lags)) {..ASN1_B
3b10: 49 54 5f 53 54 52 49 4e 47 20 2a 6b 65 79 3b 0a  IT_STRING *key;.
3b20: 09 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 6e 3b  .unsigned int n;
3b30: 0a 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69  ...LAPPEND_STR(i
3b40: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
3b50: 22 73 69 67 6e 69 6e 67 44 69 67 65 73 74 22 2c  "signingDigest",
3b60: 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 6d 64 6e 69   OBJ_nid2ln(mdni
3b70: 64 29 2c 20 2d 31 29 3b 0a 09 4c 41 50 50 45 4e  d), -1);..LAPPEN
3b80: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65  D_STR(interp, ce
3b90: 72 74 50 74 72 2c 20 22 70 75 62 6c 69 63 4b 65  rtPtr, "publicKe
3ba0: 79 41 6c 67 6f 72 69 74 68 6d 22 2c 20 4f 42 4a  yAlgorithm", OBJ
3bb0: 5f 6e 69 64 32 6c 6e 28 70 6b 6e 69 64 29 2c 20  _nid2ln(pknid), 
3bc0: 2d 31 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 49 4e  -1);..LAPPEND_IN
3bd0: 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  T(interp, certPt
3be0: 72 2c 20 22 62 69 74 73 22 2c 20 62 69 74 73 29  r, "bits", bits)
3bf0: 3b 20 2f 2a 20 45 66 66 65 63 74 69 76 65 20 73  ; /* Effective s
3c00: 65 63 75 72 69 74 79 20 62 69 74 73 20 2a 2f 0a  ecurity bits */.
3c10: 0a 09 6b 65 79 20 3d 20 58 35 30 39 5f 67 65 74  ..key = X509_get
3c20: 30 5f 70 75 62 6b 65 79 5f 62 69 74 73 74 72 28  0_pubkey_bitstr(
3c30: 63 65 72 74 29 3b 0a 09 6c 65 6e 20 3d 20 53 74  cert);..len = St
3c40: 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6b 65 79 2d  ring_to_Hex(key-
3c50: 3e 64 61 74 61 2c 20 6b 65 79 2d 3e 6c 65 6e 67  >data, key->leng
3c60: 74 68 2c 20 28 75 6e 73 69 67 6e 65 64 20 63 68  th, (unsigned ch
3c70: 61 72 20 2a 29 20 62 75 66 66 65 72 2c 20 42 55  ar *) buffer, BU
3c80: 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f  FSIZ);..LAPPEND_
3c90: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
3ca0: 50 74 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 22  Ptr, "publicKey"
3cb0: 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53  , buffer, (Tcl_S
3cc0: 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 6c 65 6e  ize) len);...len
3cd0: 20 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f   = 0;..if (X509_
3ce0: 70 75 62 6b 65 79 5f 64 69 67 65 73 74 28 63 65  pubkey_digest(ce
3cf0: 72 74 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65  rt, EVP_get_dige
3d00: 73 74 62 79 6e 69 64 28 70 6b 6e 69 64 29 2c 20  stbynid(pknid), 
3d10: 6d 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20  md, &n)) {..    
3d20: 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f  len = String_to_
3d30: 48 65 78 28 6d 64 2c 20 28 69 6e 74 29 20 6e 2c  Hex(md, (int) n,
3d40: 20 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20   (unsigned char 
3d50: 2a 29 20 62 75 66 66 65 72 2c 20 42 55 46 53 49  *) buffer, BUFSI
3d60: 5a 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e 44 5f  Z);..}..LAPPEND_
3d70: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
3d80: 50 74 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 48  Ptr, "publicKeyH
3d90: 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20 28 54  ash", buffer, (T
3da0: 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a  cl_Size) len);..
3db0: 09 2f 2a 20 64 69 67 65 73 74 20 6f 66 20 74 68  ./* digest of th
3dc0: 65 20 44 45 52 20 72 65 70 72 65 73 65 6e 74 61  e DER representa
3dd0: 74 69 6f 6e 20 6f 66 20 74 68 65 20 63 65 72 74  tion of the cert
3de0: 69 66 69 63 61 74 65 20 2a 2f 0a 09 6c 65 6e 20  ificate */..len 
3df0: 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f 64  = 0;..if (X509_d
3e00: 69 67 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f  igest(cert, EVP_
3e10: 67 65 74 5f 64 69 67 65 73 74 62 79 6e 69 64 28  get_digestbynid(
3e20: 6d 64 6e 69 64 29 2c 20 6d 64 2c 20 26 6e 29 29  mdnid), md, &n))
3e30: 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d 20 53 74   {..    len = St
3e40: 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20  ring_to_Hex(md, 
3e50: 28 69 6e 74 29 20 6e 2c 20 28 75 6e 73 69 67 6e  (int) n, (unsign
3e60: 65 64 20 63 68 61 72 20 2a 29 20 62 75 66 66 65  ed char *) buffe
3e70: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 7d 0a 09  r, BUFSIZ);..}..
3e80: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
3e90: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69  rp, certPtr, "si
3ea0: 67 6e 61 74 75 72 65 48 61 73 68 22 2c 20 62 75  gnatureHash", bu
3eb0: 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29  ffer, (Tcl_Size)
3ec0: 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20   len);.    }..  
3ed0: 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65    /* Certificate
3ee0: 20 50 75 72 70 6f 73 65 2e 20 43 61 6c 6c 20 62   Purpose. Call b
3ef0: 65 66 6f 72 65 20 63 68 65 63 6b 69 6e 67 20 66  efore checking f
3f00: 6f 72 20 65 78 74 65 6e 73 69 6f 6e 73 2e 20 2a  or extensions. *
3f10: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54  /.    LAPPEND_ST
3f20: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
3f30: 72 2c 20 22 70 75 72 70 6f 73 65 22 2c 20 54 6c  r, "purpose", Tl
3f40: 73 5f 78 35 30 39 50 75 72 70 6f 73 65 28 63 65  s_x509Purpose(ce
3f50: 72 74 29 2c 20 2d 31 29 3b 0a 20 20 20 20 4c 41  rt), -1);.    LA
3f60: 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70  PPEND_OBJ(interp
3f70: 2c 20 63 65 72 74 50 74 72 2c 20 22 63 65 72 74  , certPtr, "cert
3f80: 69 66 69 63 61 74 65 50 75 72 70 6f 73 65 22 2c  ificatePurpose",
3f90: 20 54 6c 73 5f 78 35 30 39 50 75 72 70 6f 73 65   Tls_x509Purpose
3fa0: 73 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 29  s(interp, cert))
3fb0: 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74 20 65 78  ;..    /* Get ex
3fc0: 74 65 6e 73 69 6f 6e 73 20 66 6c 61 67 73 20 2a  tensions flags *
3fd0: 2f 0a 20 20 20 20 78 66 6c 61 67 73 20 3d 20 58  /.    xflags = X
3fe0: 35 30 39 5f 67 65 74 5f 65 78 74 65 6e 73 69 6f  509_get_extensio
3ff0: 6e 5f 66 6c 61 67 73 28 63 65 72 74 29 3b 0a 20  n_flags(cert);. 
4000: 20 20 20 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69     LAPPEND_INT(i
4010: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
4020: 22 65 78 74 46 6c 61 67 73 22 2c 20 78 66 6c 61  "extFlags", xfla
4030: 67 73 29 3b 0a 0a 09 2f 2a 20 43 68 65 63 6b 20  gs);.../* Check 
4040: 69 66 20 63 65 72 74 20 77 61 73 20 69 73 73 75  if cert was issu
4050: 65 64 20 62 79 20 43 41 20 63 65 72 74 20 69 73  ed by CA cert is
4060: 73 75 65 72 20 6f 72 20 73 65 6c 66 20 73 69 67  suer or self sig
4070: 6e 65 64 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45  ned */.    LAPPE
4080: 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20  ND_BOOL(interp, 
4090: 63 65 72 74 50 74 72 2c 20 22 73 65 6c 66 49 73  certPtr, "selfIs
40a0: 73 75 65 64 22 2c 20 78 66 6c 61 67 73 20 26 20  sued", xflags & 
40b0: 45 58 46 4c 41 47 5f 53 49 29 3b 0a 20 20 20 20  EXFLAG_SI);.    
40c0: 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74  LAPPEND_BOOL(int
40d0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73  erp, certPtr, "s
40e0: 65 6c 66 53 69 67 6e 65 64 22 2c 20 78 66 6c 61  elfSigned", xfla
40f0: 67 73 20 26 20 45 58 46 4c 41 47 5f 53 53 29 3b  gs & EXFLAG_SS);
4100: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f  .    LAPPEND_BOO
4110: 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  L(interp, certPt
4120: 72 2c 20 22 69 73 50 72 6f 78 79 43 65 72 74 22  r, "isProxyCert"
4130: 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41  , xflags & EXFLA
4140: 47 5f 50 52 4f 58 59 29 3b 0a 20 20 20 20 4c 41  G_PROXY);.    LA
4150: 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72  PPEND_BOOL(inter
4160: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 74  p, certPtr, "ext
4170: 49 6e 76 61 6c 69 64 22 2c 20 78 66 6c 61 67 73  Invalid", xflags
4180: 20 26 20 45 58 46 4c 41 47 5f 49 4e 56 41 4c 49   & EXFLAG_INVALI
4190: 44 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f  D);.    LAPPEND_
41a0: 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72  BOOL(interp, cer
41b0: 74 50 74 72 2c 20 22 69 73 43 41 43 65 72 74 22  tPtr, "isCACert"
41c0: 2c 20 58 35 30 39 5f 63 68 65 63 6b 5f 63 61 28  , X509_check_ca(
41d0: 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20  cert));..    /* 
41e0: 54 68 65 20 55 6e 69 71 75 65 20 49 64 73 20 61  The Unique Ids a
41f0: 72 65 20 75 73 65 64 20 74 6f 20 68 61 6e 64 6c  re used to handl
4200: 65 20 74 68 65 20 70 6f 73 73 69 62 69 6c 69 74  e the possibilit
4210: 79 20 6f 66 20 72 65 75 73 65 20 6f 66 20 73 75  y of reuse of su
4220: 62 6a 65 63 74 0a 09 61 6e 64 2f 6f 72 20 69 73  bject..and/or is
4230: 73 75 65 72 20 6e 61 6d 65 73 20 6f 76 65 72 20  suer names over 
4240: 74 69 6d 65 2e 20 52 46 43 20 35 32 38 30 20 73  time. RFC 5280 s
4250: 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 38 20 2a  ection 4.1.2.8 *
4260: 2f 0a 20 20 20 20 7b 0a 09 63 6f 6e 73 74 20 41  /.    {..const A
4270: 53 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a  SN1_BIT_STRING *
4280: 69 75 69 64 2c 20 2a 73 75 69 64 3b 0a 20 20 20  iuid, *suid;.   
4290: 20 20 20 20 20 58 35 30 39 5f 67 65 74 30 5f 75       X509_get0_u
42a0: 69 64 73 28 63 65 72 74 2c 20 26 69 75 69 64 2c  ids(cert, &iuid,
42b0: 20 26 73 75 69 64 29 3b 0a 0a 09 54 63 6c 5f 4c   &suid);...Tcl_L
42c0: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
42d0: 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74  ent(interp, cert
42e0: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
42f0: 6e 67 4f 62 6a 28 22 69 73 73 75 65 72 55 6e 69  ngObj("issuerUni
4300: 71 75 65 49 64 22 2c 20 2d 31 29 29 3b 0a 09 69  queId", -1));..i
4310: 66 20 28 69 75 69 64 20 21 3d 20 4e 55 4c 4c 29  f (iuid != NULL)
4320: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
4330: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
4340: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
4350: 2c 20 54 63 6c 5f 4e 65 77 42 79 74 65 41 72 72  , Tcl_NewByteArr
4360: 61 79 4f 62 6a 28 28 63 6f 6e 73 74 20 75 6e 73  ayObj((const uns
4370: 69 67 6e 65 64 20 63 68 61 72 20 2a 29 69 75 69  igned char *)iui
4380: 64 2d 3e 64 61 74 61 2c 20 28 54 63 6c 5f 53 69  d->data, (Tcl_Si
4390: 7a 65 29 20 69 75 69 64 2d 3e 6c 65 6e 67 74 68  ze) iuid->length
43a0: 29 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20  ));..} else {.. 
43b0: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
43c0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
43d0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c  rp, certPtr, Tcl
43e0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 22  _NewStringObj(""
43f0: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 0a 09 54 63 6c  , -1));..}...Tcl
4400: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
4410: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65  ement(interp, ce
4420: 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  rtPtr, Tcl_NewSt
4430: 72 69 6e 67 4f 62 6a 28 22 73 75 62 6a 65 63 74  ringObj("subject
4440: 55 6e 69 71 75 65 49 64 22 2c 20 2d 31 29 29 3b  UniqueId", -1));
4450: 0a 09 69 66 20 28 73 75 69 64 20 21 3d 20 4e 55  ..if (suid != NU
4460: 4c 4c 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  LL) {..    Tcl_L
4470: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
4480: 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74  ent(interp, cert
4490: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 42 79 74 65  Ptr, Tcl_NewByte
44a0: 41 72 72 61 79 4f 62 6a 28 28 63 6f 6e 73 74 20  ArrayObj((const 
44b0: 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 29  unsigned char *)
44c0: 73 75 69 64 2d 3e 64 61 74 61 2c 20 28 54 63 6c  suid->data, (Tcl
44d0: 5f 53 69 7a 65 29 20 73 75 69 64 2d 3e 6c 65 6e  _Size) suid->len
44e0: 67 74 68 29 29 3b 0a 09 7d 20 65 6c 73 65 20 7b  gth));..} else {
44f0: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62  ..    Tcl_ListOb
4500: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69  jAppendElement(i
4510: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
4520: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a  Tcl_NewStringObj
4530: 28 22 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20  ("", -1));..}.  
4540: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 58 35 30 39    }..    /* X509
4550: 20 76 33 20 45 78 74 65 6e 73 69 6f 6e 73 20 2d   v3 Extensions -
4560: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
4570: 6e 20 34 2e 31 2e 32 2e 39 20 2a 2f 0a 20 20 20  n 4.1.2.9 */.   
4580: 20 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74   LAPPEND_INT(int
4590: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65  erp, certPtr, "e
45a0: 78 74 43 6f 75 6e 74 22 2c 20 58 35 30 39 5f 67  xtCount", X509_g
45b0: 65 74 5f 65 78 74 5f 63 6f 75 6e 74 28 63 65 72  et_ext_count(cer
45c0: 74 29 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44  t));.    LAPPEND
45d0: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72  _OBJ(interp, cer
45e0: 74 50 74 72 2c 20 22 65 78 74 65 6e 73 69 6f 6e  tPtr, "extension
45f0: 73 22 2c 20 54 6c 73 5f 78 35 30 39 45 78 74 65  s", Tls_x509Exte
4600: 6e 73 69 6f 6e 73 28 69 6e 74 65 72 70 2c 20 63  nsions(interp, c
4610: 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 41  ert));..    /* A
4620: 75 74 68 6f 72 69 74 79 20 4b 65 79 20 49 64 65  uthority Key Ide
4630: 6e 74 69 66 69 65 72 20 28 41 4b 49 29 20 69 73  ntifier (AKI) is
4640: 20 74 68 65 20 53 75 62 6a 65 63 74 20 4b 65 79   the Subject Key
4650: 20 49 64 65 6e 74 69 66 69 65 72 20 28 53 4b 49   Identifier (SKI
4660: 29 20 6f 66 0a 09 69 74 73 20 73 69 67 6e 65 72  ) of..its signer
4670: 20 28 74 68 65 20 43 41 29 2e 20 52 46 43 20 35   (the CA). RFC 5
4680: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e  280 section 4.2.
4690: 31 2e 31 2c 20 4e 49 44 5f 61 75 74 68 6f 72 69  1.1, NID_authori
46a0: 74 79 5f 6b 65 79 5f 69 64 65 6e 74 69 66 69 65  ty_key_identifie
46b0: 72 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44  r */.    LAPPEND
46c0: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72  _OBJ(interp, cer
46d0: 74 50 74 72 2c 20 22 61 75 74 68 6f 72 69 74 79  tPtr, "authority
46e0: 4b 65 79 49 64 65 6e 74 69 66 69 65 72 22 2c 0a  KeyIdentifier",.
46f0: 09 54 6c 73 5f 78 35 30 39 49 64 65 6e 74 69 66  .Tls_x509Identif
4700: 69 65 72 28 58 35 30 39 5f 67 65 74 30 5f 61 75  ier(X509_get0_au
4710: 74 68 6f 72 69 74 79 5f 6b 65 79 5f 69 64 28 63  thority_key_id(c
4720: 65 72 74 29 29 29 3b 0a 0a 20 20 20 20 2f 2a 20  ert)));..    /* 
4730: 53 75 62 6a 65 63 74 20 4b 65 79 20 49 64 65 6e  Subject Key Iden
4740: 74 69 66 69 65 72 20 28 53 4b 49 29 20 69 73 20  tifier (SKI) is 
4750: 75 73 65 64 20 74 6f 20 69 64 65 6e 74 69 66 79  used to identify
4760: 20 63 65 72 74 69 66 69 63 61 74 65 73 20 74 68   certificates th
4770: 61 74 20 63 6f 6e 74 61 69 6e 0a 09 61 20 70 61  at contain..a pa
4780: 72 74 69 63 75 6c 61 72 20 70 75 62 6c 69 63 20  rticular public 
4790: 6b 65 79 2e 20 52 46 43 20 35 32 38 30 20 73 65  key. RFC 5280 se
47a0: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 32 2c 20 4e  ction 4.2.1.2, N
47b0: 49 44 5f 73 75 62 6a 65 63 74 5f 6b 65 79 5f 69  ID_subject_key_i
47c0: 64 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20 20  dentifier */.   
47d0: 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74   LAPPEND_OBJ(int
47e0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73  erp, certPtr, "s
47f0: 75 62 6a 65 63 74 4b 65 79 49 64 65 6e 74 69 66  ubjectKeyIdentif
4800: 69 65 72 22 2c 0a 09 54 6c 73 5f 78 35 30 39 49  ier",..Tls_x509I
4810: 64 65 6e 74 69 66 69 65 72 28 58 35 30 39 5f 67  dentifier(X509_g
4820: 65 74 30 5f 73 75 62 6a 65 63 74 5f 6b 65 79 5f  et0_subject_key_
4830: 69 64 28 63 65 72 74 29 29 29 3b 0a 0a 20 20 20  id(cert)));..   
4840: 20 2f 2a 20 4b 65 79 20 75 73 61 67 65 20 65 78   /* Key usage ex
4850: 74 65 6e 73 69 6f 6e 20 64 65 66 69 6e 65 73 20  tension defines 
4860: 74 68 65 20 70 75 72 70 6f 73 65 20 28 65 2e 67  the purpose (e.g
4870: 2e 2c 20 65 6e 63 69 70 68 65 72 6d 65 6e 74 2c  ., encipherment,
4880: 20 73 69 67 6e 61 74 75 72 65 2c 20 63 65 72 74   signature, cert
4890: 69 66 69 63 61 74 65 0a 09 73 69 67 6e 69 6e 67  ificate..signing
48a0: 29 20 6f 66 20 74 68 65 20 6b 65 79 20 69 6e 20  ) of the key in 
48b0: 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e  the certificate.
48c0: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
48d0: 6e 20 34 2e 32 2e 31 2e 33 2c 20 4e 49 44 5f 6b  n 4.2.1.3, NID_k
48e0: 65 79 5f 75 73 61 67 65 20 2a 2f 0a 20 20 20 20  ey_usage */.    
48f0: 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65  LAPPEND_OBJ(inte
4900: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 6b 65  rp, certPtr, "ke
4910: 79 55 73 61 67 65 22 2c 20 54 6c 73 5f 78 35 30  yUsage", Tls_x50
4920: 39 4b 65 79 55 73 61 67 65 28 69 6e 74 65 72 70  9KeyUsage(interp
4930: 2c 20 63 65 72 74 2c 20 78 66 6c 61 67 73 29 29  , cert, xflags))
4940: 3b 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66  ;..    /* Certif
4950: 69 63 61 74 65 20 50 6f 6c 69 63 69 65 73 20 2d  icate Policies -
4960: 20 69 6e 64 69 63 61 74 65 73 20 74 68 65 20 69   indicates the i
4970: 73 73 75 69 6e 67 20 43 41 20 63 6f 6e 73 69 64  ssuing CA consid
4980: 65 72 73 20 69 74 73 20 69 73 73 75 65 72 44 6f  ers its issuerDo
4990: 6d 61 69 6e 50 6f 6c 69 63 79 0a 09 65 71 75 69  mainPolicy..equi
49a0: 76 61 6c 65 6e 74 20 74 6f 20 74 68 65 20 73 75  valent to the su
49b0: 62 6a 65 63 74 20 43 41 27 73 20 73 75 62 6a 65  bject CA's subje
49c0: 63 74 44 6f 6d 61 69 6e 50 6f 6c 69 63 79 2e 20  ctDomainPolicy. 
49d0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
49e0: 20 34 2e 32 2e 31 2e 34 2c 20 4e 49 44 5f 63 65   4.2.1.4, NID_ce
49f0: 72 74 69 66 69 63 61 74 65 5f 70 6f 6c 69 63 69  rtificate_polici
4a00: 65 73 20 2a 2f 0a 20 20 20 20 69 66 20 28 78 66  es */.    if (xf
4a10: 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 49 4e  lags & EXFLAG_IN
4a20: 56 41 4c 49 44 5f 50 4f 4c 49 43 59 29 20 7b 0a  VALID_POLICY) {.
4a30: 09 2f 2a 20 52 65 6a 65 63 74 20 63 65 72 74 20  ./* Reject cert 
4a40: 2a 2f 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a  */.    }..    /*
4a50: 20 50 6f 6c 69 63 79 20 4d 61 70 70 69 6e 67 73   Policy Mappings
4a60: 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74   - RFC 5280 sect
4a70: 69 6f 6e 20 34 2e 32 2e 31 2e 35 2c 20 4e 49 44  ion 4.2.1.5, NID
4a80: 5f 70 6f 6c 69 63 79 5f 6d 61 70 70 69 6e 67 73  _policy_mappings
4a90: 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a   */..    /* Subj
4aa0: 65 63 74 20 41 6c 74 65 72 6e 61 74 69 76 65 20  ect Alternative 
4ab0: 4e 61 6d 65 20 28 53 41 4e 29 20 63 6f 6e 74 61  Name (SAN) conta
4ac0: 69 6e 73 20 61 64 64 69 74 69 6f 6e 61 6c 20 55  ins additional U
4ad0: 52 4c 73 2c 20 44 4e 53 20 6e 61 6d 65 73 2c 20  RLs, DNS names, 
4ae0: 6f 72 20 49 50 0a 09 61 64 64 72 65 73 73 65 73  or IP..addresses
4af0: 20 62 6f 75 6e 64 20 74 6f 20 63 65 72 74 69 66   bound to certif
4b00: 69 63 61 74 65 2e 20 52 46 43 20 35 32 38 30 20  icate. RFC 5280 
4b10: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 36 2c  section 4.2.1.6,
4b20: 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f 61 6c 74   NID_subject_alt
4b30: 5f 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 4c 41 50  _name */.    LAP
4b40: 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c  PEND_OBJ(interp,
4b50: 20 63 65 72 74 50 74 72 2c 20 22 73 75 62 6a 65   certPtr, "subje
4b60: 63 74 41 6c 74 4e 61 6d 65 22 2c 20 54 6c 73 5f  ctAltName", Tls_
4b70: 78 35 30 39 4e 61 6d 65 73 28 69 6e 74 65 72 70  x509Names(interp
4b80: 2c 20 63 65 72 74 2c 20 4e 49 44 5f 73 75 62 6a  , cert, NID_subj
4b90: 65 63 74 5f 61 6c 74 5f 6e 61 6d 65 2c 20 62 69  ect_alt_name, bi
4ba0: 6f 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 49 73 73  o));..    /* Iss
4bb0: 75 65 72 20 41 6c 74 65 72 6e 61 74 69 76 65 20  uer Alternative 
4bc0: 4e 61 6d 65 20 69 73 20 75 73 65 64 20 74 6f 20  Name is used to 
4bd0: 61 73 73 6f 63 69 61 74 65 20 49 6e 74 65 72 6e  associate Intern
4be0: 65 74 20 73 74 79 6c 65 20 69 64 65 6e 74 69 74  et style identit
4bf0: 69 65 73 0a 09 77 69 74 68 20 74 68 65 20 63 65  ies..with the ce
4c00: 72 74 69 66 69 63 61 74 65 20 69 73 73 75 65 72  rtificate issuer
4c10: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
4c20: 6f 6e 20 34 2e 32 2e 31 2e 37 2c 20 4e 49 44 5f  on 4.2.1.7, NID_
4c30: 69 73 73 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 20  issuer_alt_name 
4c40: 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f  */.    LAPPEND_O
4c50: 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  BJ(interp, certP
4c60: 74 72 2c 20 22 69 73 73 75 65 72 41 6c 74 4e 61  tr, "issuerAltNa
4c70: 6d 65 22 2c 20 54 6c 73 5f 78 35 30 39 4e 61 6d  me", Tls_x509Nam
4c80: 65 73 28 69 6e 74 65 72 70 2c 20 63 65 72 74 2c  es(interp, cert,
4c90: 20 4e 49 44 5f 69 73 73 75 65 72 5f 61 6c 74 5f   NID_issuer_alt_
4ca0: 6e 61 6d 65 2c 20 62 69 6f 29 29 3b 0a 0a 20 20  name, bio));..  
4cb0: 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 44 69 72    /* Subject Dir
4cc0: 65 63 74 6f 72 79 20 41 74 74 72 69 62 75 74 65  ectory Attribute
4cd0: 73 20 70 72 6f 76 69 64 65 73 20 69 64 65 6e 74  s provides ident
4ce0: 69 66 69 63 61 74 69 6f 6e 20 61 74 74 72 69 62  ification attrib
4cf0: 75 74 65 73 20 28 65 2e 67 2e 2c 20 6e 61 74 69  utes (e.g., nati
4d00: 6f 6e 61 6c 69 74 79 29 0a 09 6f 66 20 74 68 65  onality)..of the
4d10: 20 73 75 62 6a 65 63 74 2e 20 52 46 43 20 35 32   subject. RFC 52
4d20: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31  80 section 4.2.1
4d30: 2e 38 20 28 73 75 62 6a 65 63 74 44 69 72 65 63  .8 (subjectDirec
4d40: 74 6f 72 79 41 74 74 72 69 62 75 74 65 73 29 20  toryAttributes) 
4d50: 2a 2f 0a 0a 20 20 20 20 2f 2a 20 42 61 73 69 63  */..    /* Basic
4d60: 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 64 65   Constraints ide
4d70: 6e 74 69 66 69 65 73 20 77 68 65 74 68 65 72 20  ntifies whether 
4d80: 74 68 65 20 73 75 62 6a 65 63 74 20 6f 66 20 74  the subject of t
4d90: 68 65 20 63 65 72 74 20 69 73 20 61 20 43 41 20  he cert is a CA 
4da0: 61 6e 64 0a 09 74 68 65 20 6d 61 78 20 64 65 70  and..the max dep
4db0: 74 68 20 6f 66 20 76 61 6c 69 64 20 63 65 72 74  th of valid cert
4dc0: 20 70 61 74 68 73 20 66 6f 72 20 74 68 69 73 20   paths for this 
4dd0: 63 65 72 74 2e 20 52 46 43 20 35 32 38 30 20 73  cert. RFC 5280 s
4de0: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 39 2c 20  ection 4.2.1.9, 
4df0: 4e 49 44 5f 62 61 73 69 63 5f 63 6f 6e 73 74 72  NID_basic_constr
4e00: 61 69 6e 74 73 20 2a 2f 0a 20 20 20 20 69 66 20  aints */.    if 
4e10: 28 21 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c  (!(xflags & EXFL
4e20: 41 47 5f 50 52 4f 58 59 29 29 20 7b 0a 09 4c 41  AG_PROXY)) {..LA
4e30: 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70  PPEND_INT(interp
4e40: 2c 20 63 65 72 74 50 74 72 2c 20 22 70 61 74 68  , certPtr, "path
4e50: 4c 65 6e 22 2c 20 58 35 30 39 5f 67 65 74 5f 70  Len", X509_get_p
4e60: 61 74 68 6c 65 6e 28 63 65 72 74 29 29 3b 0a 20  athlen(cert));. 
4e70: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 4c 41 50     } else {..LAP
4e80: 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c  PEND_INT(interp,
4e90: 20 63 65 72 74 50 74 72 2c 20 22 70 61 74 68 4c   certPtr, "pathL
4ea0: 65 6e 22 2c 20 58 35 30 39 5f 67 65 74 5f 70 72  en", X509_get_pr
4eb0: 6f 78 79 5f 70 61 74 68 6c 65 6e 28 63 65 72 74  oxy_pathlen(cert
4ec0: 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 4c 41  ));.    }.    LA
4ed0: 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72  PPEND_BOOL(inter
4ee0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 62 61 73  p, certPtr, "bas
4ef0: 69 63 43 6f 6e 73 74 72 61 69 6e 74 73 43 41 22  icConstraintsCA"
4f00: 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41  , xflags & EXFLA
4f10: 47 5f 43 41 29 3b 0a 0a 20 20 20 20 2f 2a 20 4e  G_CA);..    /* N
4f20: 61 6d 65 20 43 6f 6e 73 74 72 61 69 6e 74 73 20  ame Constraints 
4f30: 69 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20  is only used in 
4f40: 43 41 20 63 65 72 74 73 20 74 6f 20 69 6e 64 69  CA certs to indi
4f50: 63 61 74 65 20 74 68 65 20 6e 61 6d 65 20 73 70  cate the name sp
4f60: 61 63 65 20 66 6f 72 0a 09 61 6c 6c 20 73 75 62  ace for..all sub
4f70: 6a 65 63 74 20 6e 61 6d 65 73 20 69 6e 20 73 75  ject names in su
4f80: 62 73 65 71 75 65 6e 74 20 63 65 72 74 69 66 69  bsequent certifi
4f90: 63 61 74 65 73 20 69 6e 20 61 20 63 65 72 74 69  cates in a certi
4fa0: 66 69 63 61 74 69 6f 6e 20 70 61 74 68 0a 09 4d  fication path..M
4fb0: 55 53 54 20 62 65 20 6c 6f 63 61 74 65 64 2e 20  UST be located. 
4fc0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
4fd0: 20 34 2e 32 2e 31 2e 31 30 2c 20 4e 49 44 5f 6e   4.2.1.10, NID_n
4fe0: 61 6d 65 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20  ame_constraints 
4ff0: 2a 2f 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c 69 63  */..    /* Polic
5000: 79 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 73  y Constraints is
5010: 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 43 41   only used in CA
5020: 20 63 65 72 74 73 20 74 6f 20 6c 69 6d 69 74 20   certs to limit 
5030: 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 61 0a  the length of a.
5040: 09 63 65 72 74 20 63 68 61 69 6e 20 66 6f 72 20  .cert chain for 
5050: 74 68 61 74 20 43 41 2e 20 52 46 43 20 35 32 38  that CA. RFC 528
5060: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e  0 section 4.2.1.
5070: 31 31 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 5f 63  11, NID_policy_c
5080: 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 0a 20  onstraints */.. 
5090: 20 20 20 2f 2a 20 45 78 74 65 6e 64 65 64 20 4b     /* Extended K
50a0: 65 79 20 55 73 61 67 65 20 69 6e 64 69 63 61 74  ey Usage indicat
50b0: 65 73 20 74 68 65 20 70 75 72 70 6f 73 65 73 20  es the purposes 
50c0: 74 68 65 20 63 65 72 74 69 66 69 65 64 20 70 75  the certified pu
50d0: 62 6c 69 63 20 6b 65 79 20 6d 61 79 20 62 65 0a  blic key may be.
50e0: 09 75 73 65 64 2c 20 62 65 79 6f 6e 64 20 74 68  .used, beyond th
50f0: 65 20 62 61 73 69 63 20 70 75 72 70 6f 73 65 73  e basic purposes
5100: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
5110: 6f 6e 20 34 2e 32 2e 31 2e 31 32 2c 20 4e 49 44  on 4.2.1.12, NID
5120: 5f 65 78 74 5f 6b 65 79 5f 75 73 61 67 65 20 2a  _ext_key_usage *
5130: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42  /.    LAPPEND_OB
5140: 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  J(interp, certPt
5150: 72 2c 20 22 65 78 74 65 6e 64 65 64 4b 65 79 55  r, "extendedKeyU
5160: 73 61 67 65 22 2c 20 54 6c 73 5f 78 35 30 39 45  sage", Tls_x509E
5170: 78 74 4b 65 79 55 73 61 67 65 28 69 6e 74 65 72  xtKeyUsage(inter
5180: 70 2c 20 63 65 72 74 2c 20 78 66 6c 61 67 73 29  p, cert, xflags)
5190: 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 52 4c 20 44  );..    /* CRL D
51a0: 69 73 74 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e  istribution Poin
51b0: 74 73 20 69 64 65 6e 74 69 66 69 65 73 20 77 68  ts identifies wh
51c0: 65 72 65 20 43 52 4c 20 69 6e 66 6f 72 6d 61 74  ere CRL informat
51d0: 69 6f 6e 20 63 61 6e 20 62 65 20 6f 62 74 61 69  ion can be obtai
51e0: 6e 65 64 2e 0a 09 52 46 43 20 35 32 38 30 20 73  ned...RFC 5280 s
51f0: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 33 2a  ection 4.2.1.13*
5200: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42  /.    LAPPEND_OB
5210: 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  J(interp, certPt
5220: 72 2c 20 22 63 72 6c 44 69 73 74 72 69 62 75 74  r, "crlDistribut
5230: 69 6f 6e 50 6f 69 6e 74 73 22 2c 20 54 6c 73 5f  ionPoints", Tls_
5240: 78 35 30 39 43 72 6c 44 70 28 69 6e 74 65 72 70  x509CrlDp(interp
5250: 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f  , cert));..    /
5260: 2a 20 46 72 65 73 68 65 73 74 20 43 52 4c 20 65  * Freshest CRL e
5270: 78 74 65 6e 73 69 6f 6e 20 2a 2f 0a 20 20 20 20  xtension */.    
5280: 69 66 20 28 78 66 6c 61 67 73 20 26 20 45 58 46  if (xflags & EXF
5290: 4c 41 47 5f 46 52 45 53 48 45 53 54 29 20 7b 0a  LAG_FRESHEST) {.
52a0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 41 75      }..    /* Au
52b0: 74 68 6f 72 69 74 79 20 49 6e 66 6f 72 6d 61 74  thority Informat
52c0: 69 6f 6e 20 41 63 63 65 73 73 20 69 6e 64 69 63  ion Access indic
52d0: 61 74 65 73 20 68 6f 77 20 74 6f 20 61 63 63 65  ates how to acce
52e0: 73 73 20 69 6e 66 6f 20 61 6e 64 20 73 65 72 76  ss info and serv
52f0: 69 63 65 73 0a 09 66 6f 72 20 74 68 65 20 63 65  ices..for the ce
5300: 72 74 69 66 69 63 61 74 65 20 69 73 73 75 65 72  rtificate issuer
5310: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
5320: 6f 6e 20 34 2e 32 2e 32 2e 31 2c 20 4e 49 44 5f  on 4.2.2.1, NID_
5330: 69 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a  info_access */..
5340: 20 20 20 20 2f 2a 20 47 65 74 20 4f 6e 2d 6c 69      /* Get On-li
5350: 6e 65 20 43 65 72 74 69 66 69 63 61 74 65 20 53  ne Certificate S
5360: 74 61 74 75 73 20 50 72 6f 74 6f 63 6f 6c 20 28  tatus Protocol (
5370: 4f 53 43 50 29 20 52 65 73 70 6f 6e 64 65 72 73  OSCP) Responders
5380: 20 55 52 4c 20 2a 2f 0a 20 20 20 20 4c 41 50 50   URL */.    LAPP
5390: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20  END_OBJ(interp, 
53a0: 63 65 72 74 50 74 72 2c 20 22 6f 63 73 70 52 65  certPtr, "ocspRe
53b0: 73 70 6f 6e 64 65 72 73 22 2c 20 54 6c 73 5f 78  sponders", Tls_x
53c0: 35 30 39 4f 73 63 70 28 69 6e 74 65 72 70 2c 20  509Oscp(interp, 
53d0: 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20  cert));..    /* 
53e0: 47 65 74 20 43 65 72 74 69 66 69 63 61 74 65 20  Get Certificate 
53f0: 41 75 74 68 6f 72 69 74 79 20 28 43 41 29 20 49  Authority (CA) I
5400: 73 73 75 65 72 73 20 55 52 4c 20 2a 2f 0a 20 20  ssuers URL */.  
5410: 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e    LAPPEND_OBJ(in
5420: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
5430: 63 61 49 73 73 75 65 72 73 22 2c 20 54 6c 73 5f  caIssuers", Tls_
5440: 78 35 30 39 43 61 49 73 73 75 65 72 73 28 69 6e  x509CaIssuers(in
5450: 74 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20  terp, cert));.. 
5460: 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 49 6e     /* Subject In
5470: 66 6f 72 6d 61 74 69 6f 6e 20 41 63 63 65 73 73  formation Access
5480: 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74   - RFC 5280 sect
5490: 69 6f 6e 20 34 2e 32 2e 32 2e 32 2c 20 4e 49 44  ion 4.2.2.2, NID
54a0: 5f 73 69 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f  _sinfo_access */
54b0: 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69  ..    /* Certifi
54c0: 63 61 74 65 20 41 6c 69 61 73 2e 20 49 66 20 75  cate Alias. If u
54d0: 73 65 73 20 61 20 50 4b 43 53 23 31 32 20 73 74  ses a PKCS#12 st
54e0: 72 75 63 74 75 72 65 2c 20 61 6c 69 61 73 20 77  ructure, alias w
54f0: 69 6c 6c 20 72 65 66 6c 65 63 74 20 74 68 65 0a  ill reflect the.
5500: 09 66 72 69 65 6e 64 6c 79 4e 61 6d 65 20 61 74  .friendlyName at
5510: 74 72 69 62 75 74 65 20 28 52 46 43 20 32 39 38  tribute (RFC 298
5520: 35 29 2e 20 2a 2f 0a 20 20 20 20 7b 0a 09 6c 65  5). */.    {..le
5530: 6e 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 75  n = 0;.        u
5540: 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 73 74  nsigned char *st
5550: 72 69 6e 67 20 3d 20 58 35 30 39 5f 61 6c 69 61  ring = X509_alia
5560: 73 5f 67 65 74 30 28 63 65 72 74 2c 20 26 6c 65  s_get0(cert, &le
5570: 6e 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52  n);..LAPPEND_STR
5580: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
5590: 2c 20 22 61 6c 69 61 73 22 2c 20 28 63 68 61 72  , "alias", (char
55a0: 20 2a 29 20 73 74 72 69 6e 67 2c 20 28 54 63 6c   *) string, (Tcl
55b0: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20  _Size) len);.   
55c0: 20 20 20 20 20 73 74 72 69 6e 67 20 3d 20 58 35       string = X5
55d0: 30 39 5f 6b 65 79 69 64 5f 67 65 74 30 28 63 65  09_keyid_get0(ce
55e0: 72 74 2c 20 26 6c 65 6e 29 3b 0a 09 4c 41 50 50  rt, &len);..LAPP
55f0: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20  END_STR(interp, 
5600: 63 65 72 74 50 74 72 2c 20 22 6b 65 79 49 64 22  certPtr, "keyId"
5610: 2c 20 28 63 68 61 72 20 2a 29 20 73 74 72 69 6e  , (char *) strin
5620: 67 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65  g, (Tcl_Size) le
5630: 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f  n);.    }..    /
5640: 2a 20 43 65 72 74 69 66 69 63 61 74 65 20 61 6e  * Certificate an
5650: 64 20 64 75 6d 70 20 61 6c 6c 20 64 61 74 61 20  d dump all data 
5660: 2a 2f 0a 20 20 20 20 7b 0a 09 63 68 61 72 20 63  */.    {..char c
5670: 65 72 74 53 74 72 5b 43 45 52 54 5f 53 54 52 5f  ertStr[CERT_STR_
5680: 53 49 5a 45 5d 3b 0a 0a 09 2f 2a 20 47 65 74 20  SIZE];.../* Get 
5690: 63 65 72 74 69 66 69 63 61 74 65 20 2a 2f 0a 09  certificate */..
56a0: 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66  len = BIO_to_Buf
56b0: 66 65 72 28 50 45 4d 5f 77 72 69 74 65 5f 62 69  fer(PEM_write_bi
56c0: 6f 5f 58 35 30 39 28 62 69 6f 2c 20 63 65 72 74  o_X509(bio, cert
56d0: 29 2c 20 62 69 6f 2c 20 63 65 72 74 53 74 72 2c  ), bio, certStr,
56e0: 20 43 45 52 54 5f 53 54 52 5f 53 49 5a 45 29 3b   CERT_STR_SIZE);
56f0: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e  ..LAPPEND_STR(in
5700: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
5710: 63 65 72 74 69 66 69 63 61 74 65 22 2c 20 63 65  certificate", ce
5720: 72 74 53 74 72 2c 20 28 54 63 6c 5f 53 69 7a 65  rtStr, (Tcl_Size
5730: 29 20 6c 65 6e 29 3b 0a 0a 09 2f 2a 20 47 65 74  ) len);.../* Get
5740: 20 61 6c 6c 20 63 65 72 74 20 69 6e 66 6f 20 2a   all cert info *
5750: 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f  /..len = BIO_to_
5760: 42 75 66 66 65 72 28 58 35 30 39 5f 70 72 69 6e  Buffer(X509_prin
5770: 74 5f 65 78 28 62 69 6f 2c 20 63 65 72 74 2c 20  t_ex(bio, cert, 
5780: 66 6c 61 67 73 2c 20 30 29 2c 20 62 69 6f 2c 20  flags, 0), bio, 
5790: 63 65 72 74 53 74 72 2c 20 43 45 52 54 5f 53 54  certStr, CERT_ST
57a0: 52 5f 53 49 5a 45 29 3b 0a 09 4c 41 50 50 45 4e  R_SIZE);..LAPPEN
57b0: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65  D_STR(interp, ce
57c0: 72 74 50 74 72 2c 20 22 61 6c 6c 22 2c 20 63 65  rtPtr, "all", ce
57d0: 72 74 53 74 72 2c 20 28 54 63 6c 5f 53 69 7a 65  rtStr, (Tcl_Size
57e0: 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20  ) len);.    }.. 
57f0: 20 20 20 42 49 4f 5f 66 72 65 65 28 62 69 6f 29     BIO_free(bio)
5800: 3b 0a 20 20 20 20 72 65 74 75 72 6e 20 63 65 72  ;.    return cer
5810: 74 50 74 72 3b 0a 7d 0a                          tPtr;.}.