Hex Artifact Content

Artifact ea8ff7e7c820fb5917ecb154f817ce008df7f681cade0f6e9937e3c6e0b0a6f5:


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 54 63 6c 5f 49 6e 74 65  X509Obj(Tcl_Inte
2c70: 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39  rp *interp, X509
2c80: 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 54 63   *cert) {.    Tc
2c90: 6c 5f 4f 62 6a 20 2a 63 65 72 74 50 74 72 20 3d  l_Obj *certPtr =
2ca0: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28   Tcl_NewListObj(
2cb0: 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 42 49  0, NULL);.    BI
2cc0: 4f 20 2a 62 69 6f 20 3d 20 42 49 4f 5f 6e 65 77  O *bio = BIO_new
2cd0: 28 42 49 4f 5f 73 5f 6d 65 6d 28 29 29 3b 0a 20  (BIO_s_mem());. 
2ce0: 20 20 20 69 6e 74 20 6d 64 6e 69 64 2c 20 70 6b     int mdnid, pk
2cf0: 6e 69 64 2c 20 62 69 74 73 2c 20 6c 65 6e 3b 0a  nid, bits, len;.
2d00: 20 20 20 20 75 6e 73 69 67 6e 65 64 20 69 6e 74      unsigned int
2d10: 20 75 6c 65 6e 3b 0a 20 20 20 20 75 69 6e 74 33   ulen;.    uint3
2d20: 32 5f 74 20 78 66 6c 61 67 73 3b 0a 20 20 20 20  2_t xflags;.    
2d30: 63 68 61 72 20 62 75 66 66 65 72 5b 42 55 46 53  char buffer[BUFS
2d40: 49 5a 5d 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65  IZ];.    unsigne
2d50: 64 20 63 68 61 72 20 6d 64 5b 45 56 50 5f 4d 41  d char md[EVP_MA
2d60: 58 5f 4d 44 5f 53 49 5a 45 5d 3b 0a 20 20 20 20  X_MD_SIZE];.    
2d70: 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 66 6c  unsigned long fl
2d80: 61 67 73 20 3d 20 58 4e 5f 46 4c 41 47 5f 52 46  ags = XN_FLAG_RF
2d90: 43 32 32 35 33 20 7c 20 41 53 4e 31 5f 53 54 52  C2253 | ASN1_STR
2da0: 46 4c 47 53 5f 55 54 46 38 5f 43 4f 4e 56 45 52  FLGS_UTF8_CONVER
2db0: 54 3b 0a 20 20 20 20 66 6c 61 67 73 20 26 3d 20  T;.    flags &= 
2dc0: 7e 41 53 4e 31 5f 53 54 52 46 4c 47 53 5f 45 53  ~ASN1_STRFLGS_ES
2dd0: 43 5f 4d 53 42 3b 0a 0a 20 20 20 20 69 66 20 28  C_MSB;..    if (
2de0: 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 20 7c  interp == NULL |
2df0: 7c 20 63 65 72 74 20 3d 3d 20 4e 55 4c 4c 20 7c  | cert == NULL |
2e00: 7c 20 62 69 6f 20 3d 3d 20 4e 55 4c 4c 20 7c 7c  | bio == NULL ||
2e10: 20 63 65 72 74 50 74 72 20 3d 3d 20 4e 55 4c 4c   certPtr == NULL
2e20: 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c  ) {..return NULL
2e30: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20  ;.    }..    /* 
2e40: 53 69 67 6e 61 74 75 72 65 20 61 6c 67 6f 72 69  Signature algori
2e50: 74 68 6d 20 61 6e 64 20 76 61 6c 75 65 20 2d 20  thm and value - 
2e60: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
2e70: 20 34 2e 31 2e 31 2e 32 20 61 6e 64 20 34 2e 31   4.1.1.2 and 4.1
2e80: 2e 31 2e 33 20 2a 2f 0a 20 20 20 20 2f 2a 20 73  .1.3 */.    /* s
2e90: 69 67 6e 61 74 75 72 65 41 6c 67 6f 72 69 74 68  ignatureAlgorith
2ea0: 6d 20 69 73 20 74 68 65 20 69 64 20 6f 66 20 74  m is the id of t
2eb0: 68 65 20 63 72 79 70 74 6f 67 72 61 70 68 69 63  he cryptographic
2ec0: 20 61 6c 67 6f 72 69 74 68 6d 20 75 73 65 64 20   algorithm used 
2ed0: 62 79 20 74 68 65 0a 09 43 41 20 74 6f 20 73 69  by the..CA to si
2ee0: 67 6e 20 74 68 69 73 20 63 65 72 74 2e 20 73 69  gn this cert. si
2ef0: 67 6e 61 74 75 72 65 56 61 6c 75 65 20 69 73 20  gnatureValue is 
2f00: 74 68 65 20 64 69 67 69 74 61 6c 20 73 69 67 6e  the digital sign
2f10: 61 74 75 72 65 20 63 6f 6d 70 75 74 65 64 0a 09  ature computed..
2f20: 75 70 6f 6e 20 74 68 65 20 41 53 4e 2e 31 20 44  upon the ASN.1 D
2f30: 45 52 20 65 6e 63 6f 64 65 64 20 74 62 73 43 65  ER encoded tbsCe
2f40: 72 74 69 66 69 63 61 74 65 2e 20 2a 2f 0a 20 20  rtificate. */.  
2f50: 20 20 7b 0a 09 63 6f 6e 73 74 20 58 35 30 39 5f    {..const X509_
2f60: 41 4c 47 4f 52 20 2a 73 69 67 5f 61 6c 67 3b 0a  ALGOR *sig_alg;.
2f70: 09 63 6f 6e 73 74 20 41 53 4e 31 5f 42 49 54 5f  .const ASN1_BIT_
2f80: 53 54 52 49 4e 47 20 2a 73 69 67 3b 0a 09 69 6e  STRING *sig;..in
2f90: 74 20 73 69 67 5f 6e 69 64 3b 0a 0a 09 58 35 30  t sig_nid;...X50
2fa0: 39 5f 67 65 74 30 5f 73 69 67 6e 61 74 75 72 65  9_get0_signature
2fb0: 28 26 73 69 67 2c 20 26 73 69 67 5f 61 6c 67 2c  (&sig, &sig_alg,
2fc0: 20 63 65 72 74 29 3b 0a 09 2f 2a 20 73 69 67 5f   cert);../* sig_
2fd0: 6e 69 64 20 3d 20 58 35 30 39 5f 67 65 74 5f 73  nid = X509_get_s
2fe0: 69 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 72  ignature_nid(cer
2ff0: 74 29 20 2a 2f 0a 09 73 69 67 5f 6e 69 64 20 3d  t) */..sig_nid =
3000: 20 4f 42 4a 5f 6f 62 6a 32 6e 69 64 28 73 69 67   OBJ_obj2nid(sig
3010: 5f 61 6c 67 2d 3e 61 6c 67 6f 72 69 74 68 6d 29  _alg->algorithm)
3020: 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69  ;..LAPPEND_STR(i
3030: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
3040: 22 73 69 67 6e 61 74 75 72 65 41 6c 67 6f 72 69  "signatureAlgori
3050: 74 68 6d 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e  thm", OBJ_nid2ln
3060: 28 73 69 67 5f 6e 69 64 29 2c 20 2d 31 29 3b 0a  (sig_nid), -1);.
3070: 09 6c 65 6e 20 3d 20 28 73 69 67 5f 6e 69 64 20  .len = (sig_nid 
3080: 21 3d 20 4e 49 44 5f 75 6e 64 65 66 29 20 3f 20  != NID_undef) ? 
3090: 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 73 69  String_to_Hex(si
30a0: 67 2d 3e 64 61 74 61 2c 20 73 69 67 2d 3e 6c 65  g->data, sig->le
30b0: 6e 67 74 68 2c 20 28 75 6e 73 69 67 6e 65 64 20  ngth, (unsigned 
30c0: 63 68 61 72 20 2a 29 20 62 75 66 66 65 72 2c 20  char *) buffer, 
30d0: 42 55 46 53 49 5a 29 20 3a 20 30 3b 0a 09 4c 41  BUFSIZ) : 0;..LA
30e0: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
30f0: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 67 6e  , certPtr, "sign
3100: 61 74 75 72 65 56 61 6c 75 65 22 2c 20 62 75 66  atureValue", buf
3110: 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20  fer, (Tcl_Size) 
3120: 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  len);.    }..   
3130: 20 2f 2a 20 56 65 72 73 69 6f 6e 20 6f 66 20 74   /* Version of t
3140: 68 65 20 65 6e 63 6f 64 65 64 20 63 65 72 74 69  he encoded certi
3150: 66 69 63 61 74 65 20 2d 20 52 46 43 20 35 32 38  ficate - RFC 528
3160: 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e  0 section 4.1.2.
3170: 31 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44  1 */.    LAPPEND
3180: 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63 65  _LONG(interp, ce
3190: 72 74 50 74 72 2c 20 22 76 65 72 73 69 6f 6e 22  rtPtr, "version"
31a0: 2c 20 58 35 30 39 5f 67 65 74 5f 76 65 72 73 69  , X509_get_versi
31b0: 6f 6e 28 63 65 72 74 29 2b 31 29 3b 0a 0a 20 20  on(cert)+1);..  
31c0: 20 20 2f 2a 20 55 6e 69 71 75 65 20 6e 75 6d 62    /* Unique numb
31d0: 65 72 20 61 73 73 69 67 6e 65 64 20 62 79 20 43  er assigned by C
31e0: 41 20 74 6f 20 63 65 72 74 69 66 69 63 61 74 65  A to certificate
31f0: 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74   - RFC 5280 sect
3200: 69 6f 6e 20 34 2e 31 2e 32 2e 32 20 2a 2f 0a 20  ion 4.1.2.2 */. 
3210: 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f     len = BIO_to_
3220: 42 75 66 66 65 72 28 69 32 61 5f 41 53 4e 31 5f  Buffer(i2a_ASN1_
3230: 49 4e 54 45 47 45 52 28 62 69 6f 2c 20 58 35 30  INTEGER(bio, X50
3240: 39 5f 67 65 74 30 5f 73 65 72 69 61 6c 4e 75 6d  9_get0_serialNum
3250: 62 65 72 28 63 65 72 74 29 29 2c 20 62 69 6f 2c  ber(cert)), bio,
3260: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29   buffer, BUFSIZ)
3270: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54  ;.    LAPPEND_ST
3280: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
3290: 72 2c 20 22 73 65 72 69 61 6c 4e 75 6d 62 65 72  r, "serialNumber
32a0: 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f  ", buffer, (Tcl_
32b0: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20  Size) len);..   
32c0: 20 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61 6c   /* Signature al
32d0: 67 6f 72 69 74 68 6d 20 75 73 65 64 20 62 79 20  gorithm used by 
32e0: 74 68 65 20 43 41 20 74 6f 20 73 69 67 6e 20 74  the CA to sign t
32f0: 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20  he certificate. 
3300: 4d 75 73 74 20 6d 61 74 63 68 0a 09 73 69 67 6e  Must match..sign
3310: 61 74 75 72 65 41 6c 67 6f 72 69 74 68 6d 2e 20  atureAlgorithm. 
3320: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
3330: 20 34 2e 31 2e 32 2e 33 20 2a 2f 0a 20 20 20 20   4.1.2.3 */.    
3340: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
3350: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69  rp, certPtr, "si
3360: 67 6e 61 74 75 72 65 22 2c 20 4f 42 4a 5f 6e 69  gnature", OBJ_ni
3370: 64 32 6c 6e 28 58 35 30 39 5f 67 65 74 5f 73 69  d2ln(X509_get_si
3380: 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 72 74  gnature_nid(cert
3390: 29 29 2c 20 2d 31 29 3b 0a 0a 20 20 20 20 2f 2a  )), -1);..    /*
33a0: 20 49 73 73 75 65 72 20 69 64 65 6e 74 69 66 69   Issuer identifi
33b0: 65 73 20 74 68 65 20 65 6e 74 69 74 79 20 74 68  es the entity th
33c0: 61 74 20 73 69 67 6e 65 64 20 61 6e 64 20 69 73  at signed and is
33d0: 73 75 65 64 20 74 68 65 20 63 65 72 74 2e 20 52  sued the cert. R
33e0: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
33f0: 34 2e 31 2e 32 2e 34 20 2a 2f 0a 20 20 20 20 6c  4.1.2.4 */.    l
3400: 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66  en = BIO_to_Buff
3410: 65 72 28 58 35 30 39 5f 4e 41 4d 45 5f 70 72 69  er(X509_NAME_pri
3420: 6e 74 5f 65 78 28 62 69 6f 2c 20 58 35 30 39 5f  nt_ex(bio, X509_
3430: 67 65 74 5f 69 73 73 75 65 72 5f 6e 61 6d 65 28  get_issuer_name(
3440: 63 65 72 74 29 2c 20 30 2c 20 66 6c 61 67 73 29  cert), 0, flags)
3450: 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42  , bio, buffer, B
3460: 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50  UFSIZ);.    LAPP
3470: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20  END_STR(interp, 
3480: 63 65 72 74 50 74 72 2c 20 22 69 73 73 75 65 72  certPtr, "issuer
3490: 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f  ", buffer, (Tcl_
34a0: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20  Size) len);..   
34b0: 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65 20   /* Certificate 
34c0: 76 61 6c 69 64 69 74 79 20 70 65 72 69 6f 64 20  validity period 
34d0: 69 73 20 74 68 65 20 69 6e 74 65 72 76 61 6c 20  is the interval 
34e0: 74 68 65 20 43 41 20 77 61 72 72 61 6e 74 73 20  the CA warrants 
34f0: 74 68 61 74 20 69 74 20 77 69 6c 6c 0a 09 6d 61  that it will..ma
3500: 69 6e 74 61 69 6e 20 69 6e 66 6f 20 6f 6e 20 74  intain info on t
3510: 68 65 20 73 74 61 74 75 73 20 6f 66 20 74 68 65  he status of the
3520: 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 52 46   certificate. RF
3530: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34  C 5280 section 4
3540: 2e 31 2e 32 2e 35 20 2a 2f 0a 20 20 20 20 2f 2a  .1.2.5 */.    /*
3550: 20 47 65 74 20 56 61 6c 69 64 69 74 79 20 2d 20   Get Validity - 
3560: 4e 6f 74 20 42 65 66 6f 72 65 20 2a 2f 0a 20 20  Not Before */.  
3570: 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42    len = BIO_to_B
3580: 75 66 66 65 72 28 41 53 4e 31 5f 54 49 4d 45 5f  uffer(ASN1_TIME_
3590: 70 72 69 6e 74 28 62 69 6f 2c 20 58 35 30 39 5f  print(bio, X509_
35a0: 67 65 74 30 5f 6e 6f 74 42 65 66 6f 72 65 28 63  get0_notBefore(c
35b0: 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66 66  ert)), bio, buff
35c0: 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20 20  er, BUFSIZ);.   
35d0: 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74   LAPPEND_STR(int
35e0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 6e  erp, certPtr, "n
35f0: 6f 74 42 65 66 6f 72 65 22 2c 20 62 75 66 66 65  otBefore", buffe
3600: 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65  r, (Tcl_Size) le
3610: 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74 20  n);..    /* Get 
3620: 56 61 6c 69 64 69 74 79 20 2d 20 4e 6f 74 20 41  Validity - Not A
3630: 66 74 65 72 20 2a 2f 0a 20 20 20 20 6c 65 6e 20  fter */.    len 
3640: 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28  = BIO_to_Buffer(
3650: 41 53 4e 31 5f 54 49 4d 45 5f 70 72 69 6e 74 28  ASN1_TIME_print(
3660: 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30 5f 6e  bio, X509_get0_n
3670: 6f 74 41 66 74 65 72 28 63 65 72 74 29 29 2c 20  otAfter(cert)), 
3680: 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46  bio, buffer, BUF
3690: 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e  SIZ);.    LAPPEN
36a0: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65  D_STR(interp, ce
36b0: 72 74 50 74 72 2c 20 22 6e 6f 74 41 66 74 65 72  rtPtr, "notAfter
36c0: 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f  ", buffer, (Tcl_
36d0: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20  Size) len);..   
36e0: 20 2f 2a 20 53 75 62 6a 65 63 74 20 69 64 65 6e   /* Subject iden
36f0: 74 69 66 69 65 73 20 74 68 65 20 65 6e 74 69 74  tifies the entit
3700: 79 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74  y associated wit
3710: 68 20 74 68 65 20 70 75 62 6c 69 63 20 6b 65 79  h the public key
3720: 20 73 74 6f 72 65 64 20 69 6e 0a 09 74 68 65 20   stored in..the 
3730: 73 75 62 6a 65 63 74 20 70 75 62 6c 69 63 20 6b  subject public k
3740: 65 79 20 66 69 65 6c 64 2e 20 52 46 43 20 35 32  ey field. RFC 52
3750: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32  80 section 4.1.2
3760: 2e 36 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20  .6 */.    len = 
3770: 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58 35  BIO_to_Buffer(X5
3780: 30 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f 65 78  09_NAME_print_ex
3790: 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 5f 73  (bio, X509_get_s
37a0: 75 62 6a 65 63 74 5f 6e 61 6d 65 28 63 65 72 74  ubject_name(cert
37b0: 29 2c 20 30 2c 20 66 6c 61 67 73 29 2c 20 62 69  ), 0, flags), bi
37c0: 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49  o, buffer, BUFSI
37d0: 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f  Z);.    LAPPEND_
37e0: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
37f0: 50 74 72 2c 20 22 73 75 62 6a 65 63 74 22 2c 20  Ptr, "subject", 
3800: 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a  buffer, (Tcl_Siz
3810: 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a  e) len);..    /*
3820: 20 53 48 41 31 20 44 69 67 65 73 74 20 28 46 69   SHA1 Digest (Fi
3830: 6e 67 65 72 70 72 69 6e 74 29 20 6f 66 20 63 65  ngerprint) of ce
3840: 72 74 20 2d 20 44 45 52 20 72 65 70 72 65 73 65  rt - DER represe
3850: 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20 69  ntation */.    i
3860: 66 20 28 58 35 30 39 5f 64 69 67 65 73 74 28 63  f (X509_digest(c
3870: 65 72 74 2c 20 45 56 50 5f 73 68 61 31 28 29 2c  ert, EVP_sha1(),
3880: 20 6d 64 2c 20 26 75 6c 65 6e 29 29 20 7b 0a 20   md, &ulen)) {. 
3890: 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f     len = String_
38a0: 74 6f 5f 48 65 78 28 6d 64 2c 20 6c 65 6e 2c 20  to_Hex(md, len, 
38b0: 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a  (unsigned char *
38c0: 29 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a  ) buffer, BUFSIZ
38d0: 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28  );..LAPPEND_STR(
38e0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
38f0: 20 22 73 68 61 31 5f 68 61 73 68 22 2c 20 62 75   "sha1_hash", bu
3900: 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29  ffer, (Tcl_Size)
3910: 20 75 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20   ulen);.    }.. 
3920: 20 20 20 2f 2a 20 53 48 41 32 35 36 20 44 69 67     /* SHA256 Dig
3930: 65 73 74 20 28 46 69 6e 67 65 72 70 72 69 6e 74  est (Fingerprint
3940: 29 20 6f 66 20 63 65 72 74 20 2d 20 44 45 52 20  ) of cert - DER 
3950: 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 2a  representation *
3960: 2f 0a 20 20 20 20 69 66 20 28 58 35 30 39 5f 64  /.    if (X509_d
3970: 69 67 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f  igest(cert, EVP_
3980: 73 68 61 32 35 36 28 29 2c 20 6d 64 2c 20 26 75  sha256(), md, &u
3990: 6c 65 6e 29 29 20 7b 0a 20 20 20 20 6c 65 6e 20  len)) {.    len 
39a0: 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28  = String_to_Hex(
39b0: 6d 64 2c 20 6c 65 6e 2c 20 28 75 6e 73 69 67 6e  md, len, (unsign
39c0: 65 64 20 63 68 61 72 20 2a 29 20 62 75 66 66 65  ed char *) buffe
39d0: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50  r, BUFSIZ);..LAP
39e0: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
39f0: 20 63 65 72 74 50 74 72 2c 20 22 73 68 61 32 35   certPtr, "sha25
3a00: 36 5f 68 61 73 68 22 2c 20 62 75 66 66 65 72 2c  6_hash", buffer,
3a10: 20 28 54 63 6c 5f 53 69 7a 65 29 20 75 6c 65 6e   (Tcl_Size) ulen
3a20: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a  );.    }..    /*
3a30: 20 53 75 62 6a 65 63 74 20 50 75 62 6c 69 63 20   Subject Public 
3a40: 4b 65 79 20 49 6e 66 6f 20 73 70 65 63 69 66 69  Key Info specifi
3a50: 65 73 20 74 68 65 20 70 75 62 6c 69 63 20 6b 65  es the public ke
3a60: 79 20 61 6e 64 20 69 64 65 6e 74 69 66 69 65 73  y and identifies
3a70: 20 74 68 65 0a 09 61 6c 67 6f 72 69 74 68 6d 20   the..algorithm 
3a80: 77 69 74 68 20 77 68 69 63 68 20 74 68 65 20 6b  with which the k
3a90: 65 79 20 69 73 20 75 73 65 64 2e 20 52 46 43 20  ey is used. RFC 
3aa0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31  5280 section 4.1
3ab0: 2e 32 2e 37 20 2a 2f 0a 20 20 20 20 69 66 20 28  .2.7 */.    if (
3ac0: 58 35 30 39 5f 67 65 74 5f 73 69 67 6e 61 74 75  X509_get_signatu
3ad0: 72 65 5f 69 6e 66 6f 28 63 65 72 74 2c 20 26 6d  re_info(cert, &m
3ae0: 64 6e 69 64 2c 20 26 70 6b 6e 69 64 2c 20 26 62  dnid, &pknid, &b
3af0: 69 74 73 2c 20 26 78 66 6c 61 67 73 29 29 20 7b  its, &xflags)) {
3b00: 0a 09 41 53 4e 31 5f 42 49 54 5f 53 54 52 49 4e  ..ASN1_BIT_STRIN
3b10: 47 20 2a 6b 65 79 3b 0a 09 75 6e 73 69 67 6e 65  G *key;..unsigne
3b20: 64 20 69 6e 74 20 6e 3b 0a 0a 09 4c 41 50 50 45  d int n;...LAPPE
3b30: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
3b40: 65 72 74 50 74 72 2c 20 22 73 69 67 6e 69 6e 67  ertPtr, "signing
3b50: 44 69 67 65 73 74 22 2c 20 4f 42 4a 5f 6e 69 64  Digest", OBJ_nid
3b60: 32 6c 6e 28 6d 64 6e 69 64 29 2c 20 2d 31 29 3b  2ln(mdnid), -1);
3b70: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e  ..LAPPEND_STR(in
3b80: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
3b90: 70 75 62 6c 69 63 4b 65 79 41 6c 67 6f 72 69 74  publicKeyAlgorit
3ba0: 68 6d 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28  hm", OBJ_nid2ln(
3bb0: 70 6b 6e 69 64 29 2c 20 2d 31 29 3b 0a 09 4c 41  pknid), -1);..LA
3bc0: 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70  PPEND_INT(interp
3bd0: 2c 20 63 65 72 74 50 74 72 2c 20 22 62 69 74 73  , certPtr, "bits
3be0: 22 2c 20 62 69 74 73 29 3b 20 2f 2a 20 45 66 66  ", bits); /* Eff
3bf0: 65 63 74 69 76 65 20 73 65 63 75 72 69 74 79 20  ective security 
3c00: 62 69 74 73 20 2a 2f 0a 0a 09 6b 65 79 20 3d 20  bits */...key = 
3c10: 58 35 30 39 5f 67 65 74 30 5f 70 75 62 6b 65 79  X509_get0_pubkey
3c20: 5f 62 69 74 73 74 72 28 63 65 72 74 29 3b 0a 09  _bitstr(cert);..
3c30: 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f  len = String_to_
3c40: 48 65 78 28 6b 65 79 2d 3e 64 61 74 61 2c 20 6b  Hex(key->data, k
3c50: 65 79 2d 3e 6c 65 6e 67 74 68 2c 20 28 75 6e 73  ey->length, (uns
3c60: 69 67 6e 65 64 20 63 68 61 72 20 2a 29 20 62 75  igned char *) bu
3c70: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09  ffer, BUFSIZ);..
3c80: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
3c90: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75  rp, certPtr, "pu
3ca0: 62 6c 69 63 4b 65 79 22 2c 20 62 75 66 66 65 72  blicKey", buffer
3cb0: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e  , (Tcl_Size) len
3cc0: 29 3b 0a 0a 09 6c 65 6e 20 3d 20 30 3b 0a 09 69  );...len = 0;..i
3cd0: 66 20 28 58 35 30 39 5f 70 75 62 6b 65 79 5f 64  f (X509_pubkey_d
3ce0: 69 67 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f  igest(cert, EVP_
3cf0: 67 65 74 5f 64 69 67 65 73 74 62 79 6e 69 64 28  get_digestbynid(
3d00: 70 6b 6e 69 64 29 2c 20 6d 64 2c 20 26 6e 29 29  pknid), md, &n))
3d10: 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d 20 53 74   {..    len = St
3d20: 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20  ring_to_Hex(md, 
3d30: 28 69 6e 74 29 20 6e 2c 20 28 75 6e 73 69 67 6e  (int) n, (unsign
3d40: 65 64 20 63 68 61 72 20 2a 29 20 62 75 66 66 65  ed char *) buffe
3d50: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 7d 0a 09  r, BUFSIZ);..}..
3d60: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
3d70: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75  rp, certPtr, "pu
3d80: 62 6c 69 63 4b 65 79 48 61 73 68 22 2c 20 62 75  blicKeyHash", bu
3d90: 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29  ffer, (Tcl_Size)
3da0: 20 6c 65 6e 29 3b 0a 0a 09 2f 2a 20 64 69 67 65   len);.../* dige
3db0: 73 74 20 6f 66 20 74 68 65 20 44 45 52 20 72 65  st of the DER re
3dc0: 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 6f 66 20  presentation of 
3dd0: 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 20  the certificate 
3de0: 2a 2f 0a 09 6c 65 6e 20 3d 20 30 3b 0a 09 69 66  */..len = 0;..if
3df0: 20 28 58 35 30 39 5f 64 69 67 65 73 74 28 63 65   (X509_digest(ce
3e00: 72 74 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65  rt, EVP_get_dige
3e10: 73 74 62 79 6e 69 64 28 6d 64 6e 69 64 29 2c 20  stbynid(mdnid), 
3e20: 6d 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20  md, &n)) {..    
3e30: 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f  len = String_to_
3e40: 48 65 78 28 6d 64 2c 20 28 69 6e 74 29 20 6e 2c  Hex(md, (int) n,
3e50: 20 28 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20   (unsigned char 
3e60: 2a 29 20 62 75 66 66 65 72 2c 20 42 55 46 53 49  *) buffer, BUFSI
3e70: 5a 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e 44 5f  Z);..}..LAPPEND_
3e80: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
3e90: 50 74 72 2c 20 22 73 69 67 6e 61 74 75 72 65 48  Ptr, "signatureH
3ea0: 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20 28 54  ash", buffer, (T
3eb0: 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20  cl_Size) len);. 
3ec0: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 43 65 72     }..    /* Cer
3ed0: 74 69 66 69 63 61 74 65 20 50 75 72 70 6f 73 65  tificate Purpose
3ee0: 2e 20 43 61 6c 6c 20 62 65 66 6f 72 65 20 63 68  . Call before ch
3ef0: 65 63 6b 69 6e 67 20 66 6f 72 20 65 78 74 65 6e  ecking for exten
3f00: 73 69 6f 6e 73 2e 20 2a 2f 0a 20 20 20 20 4c 41  sions. */.    LA
3f10: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
3f20: 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75 72 70  , certPtr, "purp
3f30: 6f 73 65 22 2c 20 54 6c 73 5f 78 35 30 39 50 75  ose", Tls_x509Pu
3f40: 72 70 6f 73 65 28 63 65 72 74 29 2c 20 2d 31 29  rpose(cert), -1)
3f50: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42  ;.    LAPPEND_OB
3f60: 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  J(interp, certPt
3f70: 72 2c 20 22 63 65 72 74 69 66 69 63 61 74 65 50  r, "certificateP
3f80: 75 72 70 6f 73 65 22 2c 20 54 6c 73 5f 78 35 30  urpose", Tls_x50
3f90: 39 50 75 72 70 6f 73 65 73 28 69 6e 74 65 72 70  9Purposes(interp
3fa0: 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f  , cert));..    /
3fb0: 2a 20 47 65 74 20 65 78 74 65 6e 73 69 6f 6e 73  * Get extensions
3fc0: 20 66 6c 61 67 73 20 2a 2f 0a 20 20 20 20 78 66   flags */.    xf
3fd0: 6c 61 67 73 20 3d 20 58 35 30 39 5f 67 65 74 5f  lags = X509_get_
3fe0: 65 78 74 65 6e 73 69 6f 6e 5f 66 6c 61 67 73 28  extension_flags(
3ff0: 63 65 72 74 29 3b 0a 20 20 20 20 4c 41 50 50 45  cert);.    LAPPE
4000: 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20 63  ND_INT(interp, c
4010: 65 72 74 50 74 72 2c 20 22 65 78 74 46 6c 61 67  ertPtr, "extFlag
4020: 73 22 2c 20 78 66 6c 61 67 73 29 3b 0a 0a 09 2f  s", xflags);.../
4030: 2a 20 43 68 65 63 6b 20 69 66 20 63 65 72 74 20  * Check if cert 
4040: 77 61 73 20 69 73 73 75 65 64 20 62 79 20 43 41  was issued by CA
4050: 20 63 65 72 74 20 69 73 73 75 65 72 20 6f 72 20   cert issuer or 
4060: 73 65 6c 66 20 73 69 67 6e 65 64 20 2a 2f 0a 20  self signed */. 
4070: 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28     LAPPEND_BOOL(
4080: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
4090: 20 22 73 65 6c 66 49 73 73 75 65 64 22 2c 20 78   "selfIssued", x
40a0: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 53  flags & EXFLAG_S
40b0: 49 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f  I);.    LAPPEND_
40c0: 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72  BOOL(interp, cer
40d0: 74 50 74 72 2c 20 22 73 65 6c 66 53 69 67 6e 65  tPtr, "selfSigne
40e0: 64 22 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46  d", xflags & EXF
40f0: 4c 41 47 5f 53 53 29 3b 0a 20 20 20 20 4c 41 50  LAG_SS);.    LAP
4100: 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70  PEND_BOOL(interp
4110: 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 50 72  , certPtr, "isPr
4120: 6f 78 79 43 65 72 74 22 2c 20 78 66 6c 61 67 73  oxyCert", xflags
4130: 20 26 20 45 58 46 4c 41 47 5f 50 52 4f 58 59 29   & EXFLAG_PROXY)
4140: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f  ;.    LAPPEND_BO
4150: 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  OL(interp, certP
4160: 74 72 2c 20 22 65 78 74 49 6e 76 61 6c 69 64 22  tr, "extInvalid"
4170: 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41  , xflags & EXFLA
4180: 47 5f 49 4e 56 41 4c 49 44 29 3b 0a 20 20 20 20  G_INVALID);.    
4190: 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74  LAPPEND_BOOL(int
41a0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 69  erp, certPtr, "i
41b0: 73 43 41 43 65 72 74 22 2c 20 58 35 30 39 5f 63  sCACert", X509_c
41c0: 68 65 63 6b 5f 63 61 28 63 65 72 74 29 29 3b 0a  heck_ca(cert));.
41d0: 0a 20 20 20 20 2f 2a 20 54 68 65 20 55 6e 69 71  .    /* The Uniq
41e0: 75 65 20 49 64 73 20 61 72 65 20 75 73 65 64 20  ue Ids are used 
41f0: 74 6f 20 68 61 6e 64 6c 65 20 74 68 65 20 70 6f  to handle the po
4200: 73 73 69 62 69 6c 69 74 79 20 6f 66 20 72 65 75  ssibility of reu
4210: 73 65 20 6f 66 20 73 75 62 6a 65 63 74 0a 09 61  se of subject..a
4220: 6e 64 2f 6f 72 20 69 73 73 75 65 72 20 6e 61 6d  nd/or issuer nam
4230: 65 73 20 6f 76 65 72 20 74 69 6d 65 2e 20 52 46  es over time. RF
4240: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34  C 5280 section 4
4250: 2e 31 2e 32 2e 38 20 2a 2f 0a 20 20 20 20 7b 0a  .1.2.8 */.    {.
4260: 09 63 6f 6e 73 74 20 41 53 4e 31 5f 42 49 54 5f  .const ASN1_BIT_
4270: 53 54 52 49 4e 47 20 2a 69 75 69 64 2c 20 2a 73  STRING *iuid, *s
4280: 75 69 64 3b 0a 20 20 20 20 20 20 20 20 58 35 30  uid;.        X50
4290: 39 5f 67 65 74 30 5f 75 69 64 73 28 63 65 72 74  9_get0_uids(cert
42a0: 2c 20 26 69 75 69 64 2c 20 26 73 75 69 64 29 3b  , &iuid, &suid);
42b0: 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70  ...Tcl_ListObjAp
42c0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
42d0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c  rp, certPtr, Tcl
42e0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 69  _NewStringObj("i
42f0: 73 73 75 65 72 55 6e 69 71 75 65 49 64 22 2c 20  ssuerUniqueId", 
4300: 2d 31 29 29 3b 0a 09 69 66 20 28 69 75 69 64 20  -1));..if (iuid 
4310: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20  != NULL) {..    
4320: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e  Tcl_ListObjAppen
4330: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c  dElement(interp,
4340: 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65   certPtr, Tcl_Ne
4350: 77 42 79 74 65 41 72 72 61 79 4f 62 6a 28 28 63  wByteArrayObj((c
4360: 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64 20 63 68  onst unsigned ch
4370: 61 72 20 2a 29 69 75 69 64 2d 3e 64 61 74 61 2c  ar *)iuid->data,
4380: 20 28 54 63 6c 5f 53 69 7a 65 29 20 69 75 69 64   (Tcl_Size) iuid
4390: 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 7d 20 65  ->length));..} e
43a0: 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  lse {..    Tcl_L
43b0: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
43c0: 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74  ent(interp, cert
43d0: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
43e0: 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 29 3b 0a  ngObj("", -1));.
43f0: 09 7d 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 6a  .}...Tcl_ListObj
4400: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
4410: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54  terp, certPtr, T
4420: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
4430: 22 73 75 62 6a 65 63 74 55 6e 69 71 75 65 49 64  "subjectUniqueId
4440: 22 2c 20 2d 31 29 29 3b 0a 09 69 66 20 28 73 75  ", -1));..if (su
4450: 69 64 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20  id != NULL) {.. 
4460: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
4470: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
4480: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c  rp, certPtr, Tcl
4490: 5f 4e 65 77 42 79 74 65 41 72 72 61 79 4f 62 6a  _NewByteArrayObj
44a0: 28 28 63 6f 6e 73 74 20 75 6e 73 69 67 6e 65 64  ((const unsigned
44b0: 20 63 68 61 72 20 2a 29 73 75 69 64 2d 3e 64 61   char *)suid->da
44c0: 74 61 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 73  ta, (Tcl_Size) s
44d0: 75 69 64 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09  uid->length));..
44e0: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63  } else {..    Tc
44f0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
4500: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63  lement(interp, c
4510: 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  ertPtr, Tcl_NewS
4520: 74 72 69 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29  tringObj("", -1)
4530: 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20  );..}.    }..   
4540: 20 2f 2a 20 58 35 30 39 20 76 33 20 45 78 74 65   /* X509 v3 Exte
4550: 6e 73 69 6f 6e 73 20 2d 20 52 46 43 20 35 32 38  nsions - RFC 528
4560: 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e  0 section 4.1.2.
4570: 39 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44  9 */.    LAPPEND
4580: 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20 63 65 72  _INT(interp, cer
4590: 74 50 74 72 2c 20 22 65 78 74 43 6f 75 6e 74 22  tPtr, "extCount"
45a0: 2c 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 63  , X509_get_ext_c
45b0: 6f 75 6e 74 28 63 65 72 74 29 29 3b 0a 20 20 20  ount(cert));.   
45c0: 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74   LAPPEND_OBJ(int
45d0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65  erp, certPtr, "e
45e0: 78 74 65 6e 73 69 6f 6e 73 22 2c 20 54 6c 73 5f  xtensions", Tls_
45f0: 78 35 30 39 45 78 74 65 6e 73 69 6f 6e 73 28 69  x509Extensions(i
4600: 6e 74 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a  nterp, cert));..
4610: 20 20 20 20 2f 2a 20 41 75 74 68 6f 72 69 74 79      /* Authority
4620: 20 4b 65 79 20 49 64 65 6e 74 69 66 69 65 72 20   Key Identifier 
4630: 28 41 4b 49 29 20 69 73 20 74 68 65 20 53 75 62  (AKI) is the Sub
4640: 6a 65 63 74 20 4b 65 79 20 49 64 65 6e 74 69 66  ject Key Identif
4650: 69 65 72 20 28 53 4b 49 29 20 6f 66 0a 09 69 74  ier (SKI) of..it
4660: 73 20 73 69 67 6e 65 72 20 28 74 68 65 20 43 41  s signer (the CA
4670: 29 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74  ). RFC 5280 sect
4680: 69 6f 6e 20 34 2e 32 2e 31 2e 31 2c 20 4e 49 44  ion 4.2.1.1, NID
4690: 5f 61 75 74 68 6f 72 69 74 79 5f 6b 65 79 5f 69  _authority_key_i
46a0: 64 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20 20  dentifier */.   
46b0: 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74   LAPPEND_OBJ(int
46c0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 61  erp, certPtr, "a
46d0: 75 74 68 6f 72 69 74 79 4b 65 79 49 64 65 6e 74  uthorityKeyIdent
46e0: 69 66 69 65 72 22 2c 0a 09 54 6c 73 5f 78 35 30  ifier",..Tls_x50
46f0: 39 49 64 65 6e 74 69 66 69 65 72 28 58 35 30 39  9Identifier(X509
4700: 5f 67 65 74 30 5f 61 75 74 68 6f 72 69 74 79 5f  _get0_authority_
4710: 6b 65 79 5f 69 64 28 63 65 72 74 29 29 29 3b 0a  key_id(cert)));.
4720: 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20  .    /* Subject 
4730: 4b 65 79 20 49 64 65 6e 74 69 66 69 65 72 20 28  Key Identifier (
4740: 53 4b 49 29 20 69 73 20 75 73 65 64 20 74 6f 20  SKI) is used to 
4750: 69 64 65 6e 74 69 66 79 20 63 65 72 74 69 66 69  identify certifi
4760: 63 61 74 65 73 20 74 68 61 74 20 63 6f 6e 74 61  cates that conta
4770: 69 6e 0a 09 61 20 70 61 72 74 69 63 75 6c 61 72  in..a particular
4780: 20 70 75 62 6c 69 63 20 6b 65 79 2e 20 52 46 43   public key. RFC
4790: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e   5280 section 4.
47a0: 32 2e 31 2e 32 2c 20 4e 49 44 5f 73 75 62 6a 65  2.1.2, NID_subje
47b0: 63 74 5f 6b 65 79 5f 69 64 65 6e 74 69 66 69 65  ct_key_identifie
47c0: 72 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44  r */.    LAPPEND
47d0: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72  _OBJ(interp, cer
47e0: 74 50 74 72 2c 20 22 73 75 62 6a 65 63 74 4b 65  tPtr, "subjectKe
47f0: 79 49 64 65 6e 74 69 66 69 65 72 22 2c 0a 09 54  yIdentifier",..T
4800: 6c 73 5f 78 35 30 39 49 64 65 6e 74 69 66 69 65  ls_x509Identifie
4810: 72 28 58 35 30 39 5f 67 65 74 30 5f 73 75 62 6a  r(X509_get0_subj
4820: 65 63 74 5f 6b 65 79 5f 69 64 28 63 65 72 74 29  ect_key_id(cert)
4830: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 4b 65 79 20  ));..    /* Key 
4840: 75 73 61 67 65 20 65 78 74 65 6e 73 69 6f 6e 20  usage extension 
4850: 64 65 66 69 6e 65 73 20 74 68 65 20 70 75 72 70  defines the purp
4860: 6f 73 65 20 28 65 2e 67 2e 2c 20 65 6e 63 69 70  ose (e.g., encip
4870: 68 65 72 6d 65 6e 74 2c 20 73 69 67 6e 61 74 75  herment, signatu
4880: 72 65 2c 20 63 65 72 74 69 66 69 63 61 74 65 0a  re, certificate.
4890: 09 73 69 67 6e 69 6e 67 29 20 6f 66 20 74 68 65  .signing) of the
48a0: 20 6b 65 79 20 69 6e 20 74 68 65 20 63 65 72 74   key in the cert
48b0: 69 66 69 63 61 74 65 2e 20 52 46 43 20 35 32 38  ificate. RFC 528
48c0: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e  0 section 4.2.1.
48d0: 33 2c 20 4e 49 44 5f 6b 65 79 5f 75 73 61 67 65  3, NID_key_usage
48e0: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f   */.    LAPPEND_
48f0: 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74  OBJ(interp, cert
4900: 50 74 72 2c 20 22 6b 65 79 55 73 61 67 65 22 2c  Ptr, "keyUsage",
4910: 20 54 6c 73 5f 78 35 30 39 4b 65 79 55 73 61 67   Tls_x509KeyUsag
4920: 65 28 69 6e 74 65 72 70 2c 20 63 65 72 74 2c 20  e(interp, cert, 
4930: 78 66 6c 61 67 73 29 29 3b 0a 0a 20 20 20 20 2f  xflags));..    /
4940: 2a 20 43 65 72 74 69 66 69 63 61 74 65 20 50 6f  * Certificate Po
4950: 6c 69 63 69 65 73 20 2d 20 69 6e 64 69 63 61 74  licies - indicat
4960: 65 73 20 74 68 65 20 69 73 73 75 69 6e 67 20 43  es the issuing C
4970: 41 20 63 6f 6e 73 69 64 65 72 73 20 69 74 73 20  A considers its 
4980: 69 73 73 75 65 72 44 6f 6d 61 69 6e 50 6f 6c 69  issuerDomainPoli
4990: 63 79 0a 09 65 71 75 69 76 61 6c 65 6e 74 20 74  cy..equivalent t
49a0: 6f 20 74 68 65 20 73 75 62 6a 65 63 74 20 43 41  o the subject CA
49b0: 27 73 20 73 75 62 6a 65 63 74 44 6f 6d 61 69 6e  's subjectDomain
49c0: 50 6f 6c 69 63 79 2e 20 52 46 43 20 35 32 38 30  Policy. RFC 5280
49d0: 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 34   section 4.2.1.4
49e0: 2c 20 4e 49 44 5f 63 65 72 74 69 66 69 63 61 74  , NID_certificat
49f0: 65 5f 70 6f 6c 69 63 69 65 73 20 2a 2f 0a 20 20  e_policies */.  
4a00: 20 20 69 66 20 28 78 66 6c 61 67 73 20 26 20 45    if (xflags & E
4a10: 58 46 4c 41 47 5f 49 4e 56 41 4c 49 44 5f 50 4f  XFLAG_INVALID_PO
4a20: 4c 49 43 59 29 20 7b 0a 09 2f 2a 20 52 65 6a 65  LICY) {../* Reje
4a30: 63 74 20 63 65 72 74 20 2a 2f 0a 20 20 20 20 7d  ct cert */.    }
4a40: 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c 69 63 79 20  ..    /* Policy 
4a50: 4d 61 70 70 69 6e 67 73 20 2d 20 52 46 43 20 35  Mappings - RFC 5
4a60: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e  280 section 4.2.
4a70: 31 2e 35 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 5f  1.5, NID_policy_
4a80: 6d 61 70 70 69 6e 67 73 20 2a 2f 0a 0a 20 20 20  mappings */..   
4a90: 20 2f 2a 20 53 75 62 6a 65 63 74 20 41 6c 74 65   /* Subject Alte
4aa0: 72 6e 61 74 69 76 65 20 4e 61 6d 65 20 28 53 41  rnative Name (SA
4ab0: 4e 29 20 63 6f 6e 74 61 69 6e 73 20 61 64 64 69  N) contains addi
4ac0: 74 69 6f 6e 61 6c 20 55 52 4c 73 2c 20 44 4e 53  tional URLs, DNS
4ad0: 20 6e 61 6d 65 73 2c 20 6f 72 20 49 50 0a 09 61   names, or IP..a
4ae0: 64 64 72 65 73 73 65 73 20 62 6f 75 6e 64 20 74  ddresses bound t
4af0: 6f 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 52  o certificate. R
4b00: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
4b10: 34 2e 32 2e 31 2e 36 2c 20 4e 49 44 5f 73 75 62  4.2.1.6, NID_sub
4b20: 6a 65 63 74 5f 61 6c 74 5f 6e 61 6d 65 20 2a 2f  ject_alt_name */
4b30: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a  .    LAPPEND_OBJ
4b40: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
4b50: 2c 20 22 73 75 62 6a 65 63 74 41 6c 74 4e 61 6d  , "subjectAltNam
4b60: 65 22 2c 20 54 6c 73 5f 78 35 30 39 4e 61 6d 65  e", Tls_x509Name
4b70: 73 28 69 6e 74 65 72 70 2c 20 63 65 72 74 2c 20  s(interp, cert, 
4b80: 4e 49 44 5f 73 75 62 6a 65 63 74 5f 61 6c 74 5f  NID_subject_alt_
4b90: 6e 61 6d 65 2c 20 62 69 6f 29 29 3b 0a 0a 20 20  name, bio));..  
4ba0: 20 20 2f 2a 20 49 73 73 75 65 72 20 41 6c 74 65    /* Issuer Alte
4bb0: 72 6e 61 74 69 76 65 20 4e 61 6d 65 20 69 73 20  rnative Name is 
4bc0: 75 73 65 64 20 74 6f 20 61 73 73 6f 63 69 61 74  used to associat
4bd0: 65 20 49 6e 74 65 72 6e 65 74 20 73 74 79 6c 65  e Internet style
4be0: 20 69 64 65 6e 74 69 74 69 65 73 0a 09 77 69 74   identities..wit
4bf0: 68 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74  h the certificat
4c00: 65 20 69 73 73 75 65 72 2e 20 52 46 43 20 35 32  e issuer. RFC 52
4c10: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31  80 section 4.2.1
4c20: 2e 37 2c 20 4e 49 44 5f 69 73 73 75 65 72 5f 61  .7, NID_issuer_a
4c30: 6c 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 4c  lt_name */.    L
4c40: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72  APPEND_OBJ(inter
4c50: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 73  p, certPtr, "iss
4c60: 75 65 72 41 6c 74 4e 61 6d 65 22 2c 20 54 6c 73  uerAltName", Tls
4c70: 5f 78 35 30 39 4e 61 6d 65 73 28 69 6e 74 65 72  _x509Names(inter
4c80: 70 2c 20 63 65 72 74 2c 20 4e 49 44 5f 69 73 73  p, cert, NID_iss
4c90: 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 2c 20 62 69  uer_alt_name, bi
4ca0: 6f 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 75 62  o));..    /* Sub
4cb0: 6a 65 63 74 20 44 69 72 65 63 74 6f 72 79 20 41  ject Directory A
4cc0: 74 74 72 69 62 75 74 65 73 20 70 72 6f 76 69 64  ttributes provid
4cd0: 65 73 20 69 64 65 6e 74 69 66 69 63 61 74 69 6f  es identificatio
4ce0: 6e 20 61 74 74 72 69 62 75 74 65 73 20 28 65 2e  n attributes (e.
4cf0: 67 2e 2c 20 6e 61 74 69 6f 6e 61 6c 69 74 79 29  g., nationality)
4d00: 0a 09 6f 66 20 74 68 65 20 73 75 62 6a 65 63 74  ..of the subject
4d10: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
4d20: 6f 6e 20 34 2e 32 2e 31 2e 38 20 28 73 75 62 6a  on 4.2.1.8 (subj
4d30: 65 63 74 44 69 72 65 63 74 6f 72 79 41 74 74 72  ectDirectoryAttr
4d40: 69 62 75 74 65 73 29 20 2a 2f 0a 0a 20 20 20 20  ibutes) */..    
4d50: 2f 2a 20 42 61 73 69 63 20 43 6f 6e 73 74 72 61  /* Basic Constra
4d60: 69 6e 74 73 20 69 64 65 6e 74 69 66 69 65 73 20  ints identifies 
4d70: 77 68 65 74 68 65 72 20 74 68 65 20 73 75 62 6a  whether the subj
4d80: 65 63 74 20 6f 66 20 74 68 65 20 63 65 72 74 20  ect of the cert 
4d90: 69 73 20 61 20 43 41 20 61 6e 64 0a 09 74 68 65  is a CA and..the
4da0: 20 6d 61 78 20 64 65 70 74 68 20 6f 66 20 76 61   max depth of va
4db0: 6c 69 64 20 63 65 72 74 20 70 61 74 68 73 20 66  lid cert paths f
4dc0: 6f 72 20 74 68 69 73 20 63 65 72 74 2e 20 52 46  or this cert. RF
4dd0: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34  C 5280 section 4
4de0: 2e 32 2e 31 2e 39 2c 20 4e 49 44 5f 62 61 73 69  .2.1.9, NID_basi
4df0: 63 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f  c_constraints */
4e00: 0a 20 20 20 20 69 66 20 28 21 28 78 66 6c 61 67  .    if (!(xflag
4e10: 73 20 26 20 45 58 46 4c 41 47 5f 50 52 4f 58 59  s & EXFLAG_PROXY
4e20: 29 29 20 7b 0a 09 4c 41 50 50 45 4e 44 5f 4c 4f  )) {..LAPPEND_LO
4e30: 4e 47 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  NG(interp, certP
4e40: 74 72 2c 20 22 70 61 74 68 4c 65 6e 22 2c 20 58  tr, "pathLen", X
4e50: 35 30 39 5f 67 65 74 5f 70 61 74 68 6c 65 6e 28  509_get_pathlen(
4e60: 63 65 72 74 29 29 3b 0a 20 20 20 20 7d 20 65 6c  cert));.    } el
4e70: 73 65 20 7b 0a 09 4c 41 50 50 45 4e 44 5f 4c 4f  se {..LAPPEND_LO
4e80: 4e 47 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  NG(interp, certP
4e90: 74 72 2c 20 22 70 61 74 68 4c 65 6e 22 2c 20 58  tr, "pathLen", X
4ea0: 35 30 39 5f 67 65 74 5f 70 72 6f 78 79 5f 70 61  509_get_proxy_pa
4eb0: 74 68 6c 65 6e 28 63 65 72 74 29 29 3b 0a 20 20  thlen(cert));.  
4ec0: 20 20 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f    }.    LAPPEND_
4ed0: 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72  BOOL(interp, cer
4ee0: 74 50 74 72 2c 20 22 62 61 73 69 63 43 6f 6e 73  tPtr, "basicCons
4ef0: 74 72 61 69 6e 74 73 43 41 22 2c 20 78 66 6c 61  traintsCA", xfla
4f00: 67 73 20 26 20 45 58 46 4c 41 47 5f 43 41 29 3b  gs & EXFLAG_CA);
4f10: 0a 0a 20 20 20 20 2f 2a 20 4e 61 6d 65 20 43 6f  ..    /* Name Co
4f20: 6e 73 74 72 61 69 6e 74 73 20 69 73 20 6f 6e 6c  nstraints is onl
4f30: 79 20 75 73 65 64 20 69 6e 20 43 41 20 63 65 72  y used in CA cer
4f40: 74 73 20 74 6f 20 69 6e 64 69 63 61 74 65 20 74  ts to indicate t
4f50: 68 65 20 6e 61 6d 65 20 73 70 61 63 65 20 66 6f  he name space fo
4f60: 72 0a 09 61 6c 6c 20 73 75 62 6a 65 63 74 20 6e  r..all subject n
4f70: 61 6d 65 73 20 69 6e 20 73 75 62 73 65 71 75 65  ames in subseque
4f80: 6e 74 20 63 65 72 74 69 66 69 63 61 74 65 73 20  nt certificates 
4f90: 69 6e 20 61 20 63 65 72 74 69 66 69 63 61 74 69  in a certificati
4fa0: 6f 6e 20 70 61 74 68 0a 09 4d 55 53 54 20 62 65  on path..MUST be
4fb0: 20 6c 6f 63 61 74 65 64 2e 20 52 46 43 20 35 32   located. RFC 52
4fc0: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31  80 section 4.2.1
4fd0: 2e 31 30 2c 20 4e 49 44 5f 6e 61 6d 65 5f 63 6f  .10, NID_name_co
4fe0: 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 0a 20 20  nstraints */..  
4ff0: 20 20 2f 2a 20 50 6f 6c 69 63 79 20 43 6f 6e 73    /* Policy Cons
5000: 74 72 61 69 6e 74 73 20 69 73 20 6f 6e 6c 79 20  traints is only 
5010: 75 73 65 64 20 69 6e 20 43 41 20 63 65 72 74 73  used in CA certs
5020: 20 74 6f 20 6c 69 6d 69 74 20 74 68 65 20 6c 65   to limit the le
5030: 6e 67 74 68 20 6f 66 20 61 0a 09 63 65 72 74 20  ngth of a..cert 
5040: 63 68 61 69 6e 20 66 6f 72 20 74 68 61 74 20 43  chain for that C
5050: 41 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74  A. RFC 5280 sect
5060: 69 6f 6e 20 34 2e 32 2e 31 2e 31 31 2c 20 4e 49  ion 4.2.1.11, NI
5070: 44 5f 70 6f 6c 69 63 79 5f 63 6f 6e 73 74 72 61  D_policy_constra
5080: 69 6e 74 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20  ints */..    /* 
5090: 45 78 74 65 6e 64 65 64 20 4b 65 79 20 55 73 61  Extended Key Usa
50a0: 67 65 20 69 6e 64 69 63 61 74 65 73 20 74 68 65  ge indicates the
50b0: 20 70 75 72 70 6f 73 65 73 20 74 68 65 20 63 65   purposes the ce
50c0: 72 74 69 66 69 65 64 20 70 75 62 6c 69 63 20 6b  rtified public k
50d0: 65 79 20 6d 61 79 20 62 65 0a 09 75 73 65 64 2c  ey may be..used,
50e0: 20 62 65 79 6f 6e 64 20 74 68 65 20 62 61 73 69   beyond the basi
50f0: 63 20 70 75 72 70 6f 73 65 73 2e 20 52 46 43 20  c purposes. RFC 
5100: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32  5280 section 4.2
5110: 2e 31 2e 31 32 2c 20 4e 49 44 5f 65 78 74 5f 6b  .1.12, NID_ext_k
5120: 65 79 5f 75 73 61 67 65 20 2a 2f 0a 20 20 20 20  ey_usage */.    
5130: 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65  LAPPEND_OBJ(inte
5140: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78  rp, certPtr, "ex
5150: 74 65 6e 64 65 64 4b 65 79 55 73 61 67 65 22 2c  tendedKeyUsage",
5160: 20 54 6c 73 5f 78 35 30 39 45 78 74 4b 65 79 55   Tls_x509ExtKeyU
5170: 73 61 67 65 28 69 6e 74 65 72 70 2c 20 63 65 72  sage(interp, cer
5180: 74 2c 20 78 66 6c 61 67 73 29 29 3b 0a 0a 20 20  t, xflags));..  
5190: 20 20 2f 2a 20 43 52 4c 20 44 69 73 74 72 69 62    /* CRL Distrib
51a0: 75 74 69 6f 6e 20 50 6f 69 6e 74 73 20 69 64 65  ution Points ide
51b0: 6e 74 69 66 69 65 73 20 77 68 65 72 65 20 43 52  ntifies where CR
51c0: 4c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 63 61  L information ca
51d0: 6e 20 62 65 20 6f 62 74 61 69 6e 65 64 2e 0a 09  n be obtained...
51e0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
51f0: 20 34 2e 32 2e 31 2e 31 33 2a 2f 0a 20 20 20 20   4.2.1.13*/.    
5200: 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65  LAPPEND_OBJ(inte
5210: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 72  rp, certPtr, "cr
5220: 6c 44 69 73 74 72 69 62 75 74 69 6f 6e 50 6f 69  lDistributionPoi
5230: 6e 74 73 22 2c 20 54 6c 73 5f 78 35 30 39 43 72  nts", Tls_x509Cr
5240: 6c 44 70 28 69 6e 74 65 72 70 2c 20 63 65 72 74  lDp(interp, cert
5250: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 46 72 65 73  ));..    /* Fres
5260: 68 65 73 74 20 43 52 4c 20 65 78 74 65 6e 73 69  hest CRL extensi
5270: 6f 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 78 66  on */.    if (xf
5280: 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 46 52  lags & EXFLAG_FR
5290: 45 53 48 45 53 54 29 20 7b 0a 20 20 20 20 7d 0a  ESHEST) {.    }.
52a0: 0a 20 20 20 20 2f 2a 20 41 75 74 68 6f 72 69 74  .    /* Authorit
52b0: 79 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 41 63  y Information Ac
52c0: 63 65 73 73 20 69 6e 64 69 63 61 74 65 73 20 68  cess indicates h
52d0: 6f 77 20 74 6f 20 61 63 63 65 73 73 20 69 6e 66  ow to access inf
52e0: 6f 20 61 6e 64 20 73 65 72 76 69 63 65 73 0a 09  o and services..
52f0: 66 6f 72 20 74 68 65 20 63 65 72 74 69 66 69 63  for the certific
5300: 61 74 65 20 69 73 73 75 65 72 2e 20 52 46 43 20  ate issuer. RFC 
5310: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32  5280 section 4.2
5320: 2e 32 2e 31 2c 20 4e 49 44 5f 69 6e 66 6f 5f 61  .2.1, NID_info_a
5330: 63 63 65 73 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a  ccess */..    /*
5340: 20 47 65 74 20 4f 6e 2d 6c 69 6e 65 20 43 65 72   Get On-line Cer
5350: 74 69 66 69 63 61 74 65 20 53 74 61 74 75 73 20  tificate Status 
5360: 50 72 6f 74 6f 63 6f 6c 20 28 4f 53 43 50 29 20  Protocol (OSCP) 
5370: 52 65 73 70 6f 6e 64 65 72 73 20 55 52 4c 20 2a  Responders URL *
5380: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42  /.    LAPPEND_OB
5390: 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  J(interp, certPt
53a0: 72 2c 20 22 6f 63 73 70 52 65 73 70 6f 6e 64 65  r, "ocspResponde
53b0: 72 73 22 2c 20 54 6c 73 5f 78 35 30 39 4f 73 63  rs", Tls_x509Osc
53c0: 70 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 29  p(interp, cert))
53d0: 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74 20 43 65  ;..    /* Get Ce
53e0: 72 74 69 66 69 63 61 74 65 20 41 75 74 68 6f 72  rtificate Author
53f0: 69 74 79 20 28 43 41 29 20 49 73 73 75 65 72 73  ity (CA) Issuers
5400: 20 55 52 4c 20 2a 2f 0a 20 20 20 20 4c 41 50 50   URL */.    LAPP
5410: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20  END_OBJ(interp, 
5420: 63 65 72 74 50 74 72 2c 20 22 63 61 49 73 73 75  certPtr, "caIssu
5430: 65 72 73 22 2c 20 54 6c 73 5f 78 35 30 39 43 61  ers", Tls_x509Ca
5440: 49 73 73 75 65 72 73 28 69 6e 74 65 72 70 2c 20  Issuers(interp, 
5450: 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20  cert));..    /* 
5460: 53 75 62 6a 65 63 74 20 49 6e 66 6f 72 6d 61 74  Subject Informat
5470: 69 6f 6e 20 41 63 63 65 73 73 20 2d 20 52 46 43  ion Access - RFC
5480: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e   5280 section 4.
5490: 32 2e 32 2e 32 2c 20 4e 49 44 5f 73 69 6e 66 6f  2.2.2, NID_sinfo
54a0: 5f 61 63 63 65 73 73 20 2a 2f 0a 0a 20 20 20 20  _access */..    
54b0: 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65 20 41  /* Certificate A
54c0: 6c 69 61 73 2e 20 49 66 20 75 73 65 73 20 61 20  lias. If uses a 
54d0: 50 4b 43 53 23 31 32 20 73 74 72 75 63 74 75 72  PKCS#12 structur
54e0: 65 2c 20 61 6c 69 61 73 20 77 69 6c 6c 20 72 65  e, alias will re
54f0: 66 6c 65 63 74 20 74 68 65 0a 09 66 72 69 65 6e  flect the..frien
5500: 64 6c 79 4e 61 6d 65 20 61 74 74 72 69 62 75 74  dlyName attribut
5510: 65 20 28 52 46 43 20 32 39 38 35 29 2e 20 2a 2f  e (RFC 2985). */
5520: 0a 20 20 20 20 7b 0a 09 6c 65 6e 20 3d 20 30 3b  .    {..len = 0;
5530: 0a 20 20 20 20 20 20 20 20 75 6e 73 69 67 6e 65  .        unsigne
5540: 64 20 63 68 61 72 20 2a 73 74 72 69 6e 67 20 3d  d char *string =
5550: 20 58 35 30 39 5f 61 6c 69 61 73 5f 67 65 74 30   X509_alias_get0
5560: 28 63 65 72 74 2c 20 26 6c 65 6e 29 3b 0a 09 4c  (cert, &len);..L
5570: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
5580: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 61 6c 69  p, certPtr, "ali
5590: 61 73 22 2c 20 28 63 68 61 72 20 2a 29 20 73 74  as", (char *) st
55a0: 72 69 6e 67 2c 20 28 54 63 6c 5f 53 69 7a 65 29  ring, (Tcl_Size)
55b0: 20 6c 65 6e 29 3b 0a 20 20 20 20 20 20 20 20 73   len);.        s
55c0: 74 72 69 6e 67 20 3d 20 58 35 30 39 5f 6b 65 79  tring = X509_key
55d0: 69 64 5f 67 65 74 30 28 63 65 72 74 2c 20 26 6c  id_get0(cert, &l
55e0: 65 6e 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54  en);..LAPPEND_ST
55f0: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
5600: 72 2c 20 22 6b 65 79 49 64 22 2c 20 28 63 68 61  r, "keyId", (cha
5610: 72 20 2a 29 20 73 74 72 69 6e 67 2c 20 28 54 63  r *) string, (Tc
5620: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20  l_Size) len);.  
5630: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74    }..    /* Cert
5640: 69 66 69 63 61 74 65 20 61 6e 64 20 64 75 6d 70  ificate and dump
5650: 20 61 6c 6c 20 64 61 74 61 20 2a 2f 0a 20 20 20   all data */.   
5660: 20 7b 0a 09 63 68 61 72 20 63 65 72 74 53 74 72   {..char certStr
5670: 5b 43 45 52 54 5f 53 54 52 5f 53 49 5a 45 5d 3b  [CERT_STR_SIZE];
5680: 0a 0a 09 2f 2a 20 47 65 74 20 63 65 72 74 69 66  .../* Get certif
5690: 69 63 61 74 65 20 2a 2f 0a 09 6c 65 6e 20 3d 20  icate */..len = 
56a0: 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 50 45  BIO_to_Buffer(PE
56b0: 4d 5f 77 72 69 74 65 5f 62 69 6f 5f 58 35 30 39  M_write_bio_X509
56c0: 28 62 69 6f 2c 20 63 65 72 74 29 2c 20 62 69 6f  (bio, cert), bio
56d0: 2c 20 63 65 72 74 53 74 72 2c 20 43 45 52 54 5f  , certStr, CERT_
56e0: 53 54 52 5f 53 49 5a 45 29 3b 0a 09 4c 41 50 50  STR_SIZE);..LAPP
56f0: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20  END_STR(interp, 
5700: 63 65 72 74 50 74 72 2c 20 22 63 65 72 74 69 66  certPtr, "certif
5710: 69 63 61 74 65 22 2c 20 63 65 72 74 53 74 72 2c  icate", certStr,
5720: 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29   (Tcl_Size) len)
5730: 3b 0a 0a 09 2f 2a 20 47 65 74 20 61 6c 6c 20 63  ;.../* Get all c
5740: 65 72 74 20 69 6e 66 6f 20 2a 2f 0a 09 6c 65 6e  ert info */..len
5750: 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72   = BIO_to_Buffer
5760: 28 58 35 30 39 5f 70 72 69 6e 74 5f 65 78 28 62  (X509_print_ex(b
5770: 69 6f 2c 20 63 65 72 74 2c 20 66 6c 61 67 73 2c  io, cert, flags,
5780: 20 30 29 2c 20 62 69 6f 2c 20 63 65 72 74 53 74   0), bio, certSt
5790: 72 2c 20 43 45 52 54 5f 53 54 52 5f 53 49 5a 45  r, CERT_STR_SIZE
57a0: 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28  );..LAPPEND_STR(
57b0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
57c0: 20 22 61 6c 6c 22 2c 20 63 65 72 74 53 74 72 2c   "all", certStr,
57d0: 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29   (Tcl_Size) len)
57e0: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 42 49 4f  ;.    }..    BIO
57f0: 5f 66 72 65 65 28 62 69 6f 29 3b 0a 20 20 20 20  _free(bio);.    
5800: 72 65 74 75 72 6e 20 63 65 72 74 50 74 72 3b 0a  return certPtr;.
5810: 7d 0a                                            }.