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 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 67 65  ) ASN1_STRING_ge
0880: 74 30 5f 64 61 74 61 28 61 73 74 72 69 6e 67 29  t0_data(astring)
0890: 2c 0a 09 20 20 20 20 41 53 4e 31 5f 53 54 52 49  ,..    ASN1_STRI
08a0: 4e 47 5f 6c 65 6e 67 74 68 28 61 73 74 72 69 6e  NG_length(astrin
08b0: 67 29 2c 20 62 75 66 66 65 72 2c 20 31 30 32 34  g), buffer, 1024
08c0: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 73  );.    }.    res
08d0: 75 6c 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77  ultPtr = Tcl_New
08e0: 53 74 72 69 6e 67 4f 62 6a 28 28 63 68 61 72 20  StringObj((char 
08f0: 2a 29 20 26 62 75 66 66 65 72 5b 30 5d 2c 20 28  *) &buffer[0], (
0900: 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a  Tcl_Size) len);.
0910: 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c      return resul
0920: 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47  tPtr;.}../*. * G
0930: 65 74 20 4b 65 79 20 55 73 61 67 65 0a 20 2a 2f  et Key Usage. */
0940: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35  .Tcl_Obj *Tls_x5
0950: 30 39 4b 65 79 55 73 61 67 65 28 54 63 6c 5f 49  09KeyUsage(Tcl_I
0960: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58  nterp *interp, X
0970: 35 30 39 20 2a 63 65 72 74 2c 20 75 69 6e 74 33  509 *cert, uint3
0980: 32 5f 74 20 78 66 6c 61 67 73 29 20 7b 0a 20 20  2_t xflags) {.  
0990: 20 20 75 69 6e 74 33 32 5f 74 20 75 73 61 67 65    uint32_t usage
09a0: 20 3d 20 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f   = X509_get_key_
09b0: 75 73 61 67 65 28 63 65 72 74 29 3b 0a 20 20 20  usage(cert);.   
09c0: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74   Tcl_Obj *listPt
09d0: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f  r = Tcl_NewListO
09e0: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20  bj(0, NULL);..  
09f0: 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d    if (listPtr ==
0a00: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e   NULL) {..return
0a10: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20   NULL;.    }..  
0a20: 20 20 69 66 20 28 28 78 66 6c 61 67 73 20 26 20    if ((xflags & 
0a30: 45 58 46 4c 41 47 5f 4b 55 53 41 47 45 29 20 26  EXFLAG_KUSAGE) &
0a40: 26 20 75 73 61 67 65 20 3c 20 55 49 4e 54 33 32  & usage < UINT32
0a50: 5f 4d 41 58 29 20 7b 0a 09 69 66 20 28 75 73 61  _MAX) {..if (usa
0a60: 67 65 20 26 20 4b 55 5f 44 49 47 49 54 41 4c 5f  ge & KU_DIGITAL_
0a70: 53 49 47 4e 41 54 55 52 45 29 20 7b 0a 09 20 20  SIGNATURE) {..  
0a80: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
0a90: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
0aa0: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
0ab0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 69  NewStringObj("Di
0ac0: 67 69 74 61 6c 20 53 69 67 6e 61 74 75 72 65 22  gital Signature"
0ad0: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28  , -1));..}..if (
0ae0: 75 73 61 67 65 20 26 20 4b 55 5f 4e 4f 4e 5f 52  usage & KU_NON_R
0af0: 45 50 55 44 49 41 54 49 4f 4e 29 20 7b 0a 09 20  EPUDIATION) {.. 
0b00: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
0b10: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
0b20: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
0b30: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4e  _NewStringObj("N
0b40: 6f 6e 2d 52 65 70 75 64 69 61 74 69 6f 6e 22 2c  on-Repudiation",
0b50: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
0b60: 73 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 45 4e  sage & KU_KEY_EN
0b70: 43 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a 09 20  CIPHERMENT) {.. 
0b80: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
0b90: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
0ba0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
0bb0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b  _NewStringObj("K
0bc0: 65 79 20 45 6e 63 69 70 68 65 72 6d 65 6e 74 22  ey Encipherment"
0bd0: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28  , -1));..}..if (
0be0: 75 73 61 67 65 20 26 20 4b 55 5f 44 41 54 41 5f  usage & KU_DATA_
0bf0: 45 4e 43 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a  ENCIPHERMENT) {.
0c00: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
0c10: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
0c20: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54  terp, listPtr, T
0c30: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
0c40: 22 44 61 74 61 20 45 6e 63 69 70 68 65 72 6d 65  "Data Encipherme
0c50: 6e 74 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69  nt", -1));..}..i
0c60: 66 20 28 75 73 61 67 65 20 26 20 4b 55 5f 4b 45  f (usage & KU_KE
0c70: 59 5f 41 47 52 45 45 4d 45 4e 54 29 20 7b 0a 09  Y_AGREEMENT) {..
0c80: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
0c90: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
0ca0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
0cb0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
0cc0: 4b 65 79 20 41 67 72 65 65 6d 65 6e 74 22 2c 20  Key Agreement", 
0cd0: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
0ce0: 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 43 45 52  age & KU_KEY_CER
0cf0: 54 5f 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54  T_SIGN) {..    T
0d00: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
0d10: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20  Element(interp, 
0d20: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77  listPtr, Tcl_New
0d30: 53 74 72 69 6e 67 4f 62 6a 28 22 43 65 72 74 69  StringObj("Certi
0d40: 66 69 63 61 74 65 20 53 69 67 6e 69 6e 67 22 2c  ficate Signing",
0d50: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
0d60: 73 61 67 65 20 26 20 4b 55 5f 43 52 4c 5f 53 49  sage & KU_CRL_SI
0d70: 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  GN) {..    Tcl_L
0d80: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
0d90: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74  ent(interp, list
0da0: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
0db0: 6e 67 4f 62 6a 28 22 43 52 4c 20 53 69 67 6e 69  ngObj("CRL Signi
0dc0: 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69  ng", -1));..}..i
0dd0: 66 20 28 75 73 61 67 65 20 26 20 4b 55 5f 45 4e  f (usage & KU_EN
0de0: 43 49 50 48 45 52 5f 4f 4e 4c 59 29 20 7b 0a 09  CIPHER_ONLY) {..
0df0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
0e00: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
0e10: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
0e20: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
0e30: 45 6e 63 69 70 68 65 72 20 4f 6e 6c 79 22 2c 20  Encipher Only", 
0e40: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
0e50: 61 67 65 20 26 20 4b 55 5f 44 45 43 49 50 48 45  age & KU_DECIPHE
0e60: 52 5f 4f 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54  R_ONLY) {..    T
0e70: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
0e80: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20  Element(interp, 
0e90: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77  listPtr, Tcl_New
0ea0: 53 74 72 69 6e 67 4f 62 6a 28 22 44 65 63 69 70  StringObj("Decip
0eb0: 68 65 72 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b  her Only", -1));
0ec0: 0a 09 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b  ..}.    } else {
0ed0: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62  ..    Tcl_ListOb
0ee0: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69  jAppendElement(i
0ef0: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20  nterp, listPtr, 
0f00: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a  Tcl_NewStringObj
0f10: 28 22 75 6e 72 65 73 74 72 69 63 74 65 64 22 2c  ("unrestricted",
0f20: 20 2d 31 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20   -1));.    }.   
0f30: 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b   return listPtr;
0f40: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 65  .}../*. * Get Ce
0f50: 72 74 69 66 69 63 61 74 65 20 50 75 72 70 6f 73  rtificate Purpos
0f60: 65 0a 20 2a 2f 0a 63 68 61 72 20 2a 54 6c 73 5f  e. */.char *Tls_
0f70: 78 35 30 39 50 75 72 70 6f 73 65 28 58 35 30 39  x509Purpose(X509
0f80: 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 63 68   *cert) {.    ch
0f90: 61 72 20 2a 70 75 72 70 6f 73 65 20 3d 20 4e 55  ar *purpose = NU
0fa0: 4c 4c 3b 0a 0a 20 20 20 20 69 66 20 28 58 35 30  LL;..    if (X50
0fb0: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28  9_check_purpose(
0fc0: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f  cert, X509_PURPO
0fd0: 53 45 5f 53 53 4c 5f 43 4c 49 45 4e 54 2c 20 30  SE_SSL_CLIENT, 0
0fe0: 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73  ) > 0) {..purpos
0ff0: 65 20 3d 20 22 53 53 4c 20 43 6c 69 65 6e 74 22  e = "SSL Client"
1000: 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20  ;.    } else if 
1010: 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70  (X509_check_purp
1020: 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50  ose(cert, X509_P
1030: 55 52 50 4f 53 45 5f 53 53 4c 5f 53 45 52 56 45  URPOSE_SSL_SERVE
1040: 52 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75  R, 0) > 0) {..pu
1050: 72 70 6f 73 65 20 3d 20 22 53 53 4c 20 53 65 72  rpose = "SSL Ser
1060: 76 65 72 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65  ver";.    } else
1070: 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f   if (X509_check_
1080: 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35  purpose(cert, X5
1090: 30 39 5f 50 55 52 50 4f 53 45 5f 4e 53 5f 53 53  09_PURPOSE_NS_SS
10a0: 4c 5f 53 45 52 56 45 52 2c 20 30 29 20 3e 20 30  L_SERVER, 0) > 0
10b0: 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22  ) {..purpose = "
10c0: 4d 53 53 20 53 53 4c 20 53 65 72 76 65 72 22 3b  MSS SSL Server";
10d0: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28  .    } else if (
10e0: 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f  X509_check_purpo
10f0: 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55  se(cert, X509_PU
1100: 52 50 4f 53 45 5f 53 4d 49 4d 45 5f 53 49 47 4e  RPOSE_SMIME_SIGN
1110: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72  , 0) > 0) {..pur
1120: 70 6f 73 65 20 3d 20 22 53 4d 49 4d 45 20 53 69  pose = "SMIME Si
1130: 67 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c  gning";.    } el
1140: 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63  se if (X509_chec
1150: 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20  k_purpose(cert, 
1160: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 53 4d 49  X509_PURPOSE_SMI
1170: 4d 45 5f 45 4e 43 52 59 50 54 2c 20 30 29 20 3e  ME_ENCRYPT, 0) >
1180: 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d   0) {..purpose =
1190: 20 22 53 4d 49 4d 45 20 45 6e 63 72 79 70 74 69   "SMIME Encrypti
11a0: 6f 6e 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20  on";.    } else 
11b0: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70  if (X509_check_p
11c0: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30  urpose(cert, X50
11d0: 39 5f 50 55 52 50 4f 53 45 5f 43 52 4c 5f 53 49  9_PURPOSE_CRL_SI
11e0: 47 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70  GN, 0) > 0) {..p
11f0: 75 72 70 6f 73 65 20 3d 20 22 43 52 4c 20 53 69  urpose = "CRL Si
1200: 67 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c  gning";.    } el
1210: 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63  se if (X509_chec
1220: 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20  k_purpose(cert, 
1230: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 41 4e 59  X509_PURPOSE_ANY
1240: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72  , 0) > 0) {..pur
1250: 70 6f 73 65 20 3d 20 22 41 6e 79 22 3b 0a 20 20  pose = "Any";.  
1260: 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30    } else if (X50
1270: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28  9_check_purpose(
1280: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f  cert, X509_PURPO
1290: 53 45 5f 4f 43 53 50 5f 48 45 4c 50 45 52 2c 20  SE_OCSP_HELPER, 
12a0: 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f  0) > 0) {..purpo
12b0: 73 65 20 3d 20 22 4f 43 53 50 20 48 65 6c 70 65  se = "OCSP Helpe
12c0: 72 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69  r";.    } else i
12d0: 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75  f (X509_check_pu
12e0: 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39  rpose(cert, X509
12f0: 5f 50 55 52 50 4f 53 45 5f 54 49 4d 45 53 54 41  _PURPOSE_TIMESTA
1300: 4d 50 5f 53 49 47 4e 2c 20 30 29 20 3e 20 30 29  MP_SIGN, 0) > 0)
1310: 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 54   {..purpose = "T
1320: 69 6d 65 73 74 61 6d 70 20 53 69 67 6e 69 6e 67  imestamp Signing
1330: 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a  ";.    } else {.
1340: 09 70 75 72 70 6f 73 65 20 3d 20 22 22 3b 0a 20  .purpose = "";. 
1350: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20     }.    return 
1360: 70 75 72 70 6f 73 65 3b 0a 7d 0a 0a 2f 2a 0a 20  purpose;.}../*. 
1370: 2a 20 46 6f 72 20 65 61 63 68 20 70 75 72 70 6f  * For each purpo
1380: 73 65 2c 20 67 65 74 20 63 65 72 74 69 66 69 63  se, get certific
1390: 61 74 65 20 61 70 70 6c 69 63 61 62 69 6c 69 74  ate applicabilit
13a0: 79 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54  y. */.Tcl_Obj *T
13b0: 6c 73 5f 78 35 30 39 50 75 72 70 6f 73 65 73 28  ls_x509Purposes(
13c0: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65  Tcl_Interp *inte
13d0: 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20  rp, X509 *cert) 
13e0: 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c  {.    Tcl_Obj *l
13f0: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77  istPtr = Tcl_New
1400: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29  ListObj(0, NULL)
1410: 3b 0a 20 20 20 20 58 35 30 39 5f 50 55 52 50 4f  ;.    X509_PURPO
1420: 53 45 20 2a 70 74 6d 70 3b 0a 0a 20 20 20 20 69  SE *ptmp;..    i
1430: 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55  f (listPtr == NU
1440: 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55  LL) {..return NU
1450: 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 66  LL;.    }..    f
1460: 6f 72 20 28 69 6e 74 20 69 20 3d 20 30 3b 20 69  or (int i = 0; i
1470: 20 3c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f   < X509_PURPOSE_
1480: 67 65 74 5f 63 6f 75 6e 74 28 29 3b 20 69 2b 2b  get_count(); i++
1490: 29 20 7b 0a 09 70 74 6d 70 20 3d 20 58 35 30 39  ) {..ptmp = X509
14a0: 5f 50 55 52 50 4f 53 45 5f 67 65 74 30 28 69 29  _PURPOSE_get0(i)
14b0: 3b 0a 09 54 63 6c 5f 4f 62 6a 20 2a 74 6d 70 50  ;..Tcl_Obj *tmpP
14c0: 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74  tr = Tcl_NewList
14d0: 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 09  Obj(0, NULL);...
14e0: 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20  for (int j = 0; 
14f0: 6a 20 3c 20 32 3b 20 6a 2b 2b 29 20 7b 0a 09 20  j < 2; j++) {.. 
1500: 20 20 20 69 6e 74 20 69 64 72 65 74 20 3d 20 58     int idret = X
1510: 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73  509_check_purpos
1520: 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52  e(cert, X509_PUR
1530: 50 4f 53 45 5f 67 65 74 5f 69 64 28 70 74 6d 70  POSE_get_id(ptmp
1540: 29 2c 20 6a 29 3b 0a 09 20 20 20 20 54 63 6c 5f  ), j);..    Tcl_
1550: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
1560: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 74 6d 70  ment(interp, tmp
1570: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
1580: 6e 67 4f 62 6a 28 6a 20 3f 20 22 43 41 22 20 3a  ngObj(j ? "CA" :
1590: 20 22 6e 6f 6e 43 41 22 2c 20 2d 31 29 29 3b 0a   "nonCA", -1));.
15a0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
15b0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
15c0: 74 65 72 70 2c 20 74 6d 70 50 74 72 2c 20 54 63  terp, tmpPtr, Tc
15d0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 69  l_NewStringObj(i
15e0: 64 72 65 74 20 3d 3d 20 31 20 3f 20 22 59 65 73  dret == 1 ? "Yes
15f0: 22 20 3a 20 22 4e 6f 22 2c 20 2d 31 29 29 3b 0a  " : "No", -1));.
1600: 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 4f 42 4a 28  .}..LAPPEND_OBJ(
1610: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c  interp, listPtr,
1620: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65   X509_PURPOSE_ge
1630: 74 30 5f 6e 61 6d 65 28 70 74 6d 70 29 2c 20 74  t0_name(ptmp), t
1640: 6d 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20  mpPtr);.    }.  
1650: 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72    return listPtr
1660: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 53  ;.}../*. * Get S
1670: 75 62 6a 65 63 74 20 41 6c 74 65 72 6e 61 74 65  ubject Alternate
1680: 20 4e 61 6d 65 73 20 28 53 41 4e 29 20 61 6e 64   Names (SAN) and
1690: 20 49 73 73 75 65 72 20 41 6c 74 65 72 6e 61 74   Issuer Alternat
16a0: 65 20 4e 61 6d 65 73 0a 20 2a 2f 0a 54 63 6c 5f  e Names. */.Tcl_
16b0: 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4e 61 6d  Obj *Tls_x509Nam
16c0: 65 73 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69  es(Tcl_Interp *i
16d0: 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72  nterp, X509 *cer
16e0: 74 2c 20 69 6e 74 20 6e 69 64 2c 20 42 49 4f 20  t, int nid, BIO 
16f0: 2a 62 69 6f 29 20 7b 0a 20 20 20 20 53 54 41 43  *bio) {.    STAC
1700: 4b 5f 4f 46 28 47 45 4e 45 52 41 4c 5f 4e 41 4d  K_OF(GENERAL_NAM
1710: 45 29 20 2a 6e 61 6d 65 73 3b 0a 20 20 20 20 54  E) *names;.    T
1720: 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20  cl_Obj *listPtr 
1730: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a  = Tcl_NewListObj
1740: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 69  (0, NULL);.    i
1750: 6e 74 20 6c 65 6e 3b 0a 20 20 20 20 63 68 61 72  nt len;.    char
1760: 20 62 75 66 66 65 72 5b 31 30 32 34 5d 3b 0a 0a   buffer[1024];..
1770: 20 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 20      if (listPtr 
1780: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75  == NULL) {..retu
1790: 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a  rn NULL;.    }..
17a0: 20 20 20 20 69 66 20 28 28 6e 61 6d 65 73 20 3d      if ((names =
17b0: 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32   X509_get_ext_d2
17c0: 69 28 63 65 72 74 2c 20 6e 69 64 2c 20 4e 55 4c  i(cert, nid, NUL
17d0: 4c 2c 20 4e 55 4c 4c 29 29 20 21 3d 20 4e 55 4c  L, NULL)) != NUL
17e0: 4c 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69  L) {..for (int i
17f0: 3d 30 3b 20 69 20 3c 20 73 6b 5f 47 45 4e 45 52  =0; i < sk_GENER
1800: 41 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 6e 61 6d 65  AL_NAME_num(name
1810: 73 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20  s); i++) {..    
1820: 63 6f 6e 73 74 20 47 45 4e 45 52 41 4c 5f 4e 41  const GENERAL_NA
1830: 4d 45 20 2a 6e 61 6d 65 20 3d 20 73 6b 5f 47 45  ME *name = sk_GE
1840: 4e 45 52 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75 65  NERAL_NAME_value
1850: 28 6e 61 6d 65 73 2c 20 69 29 3b 0a 0a 09 20 20  (names, i);...  
1860: 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42    len = BIO_to_B
1870: 75 66 66 65 72 28 6e 61 6d 65 20 26 26 20 47 45  uffer(name && GE
1880: 4e 45 52 41 4c 5f 4e 41 4d 45 5f 70 72 69 6e 74  NERAL_NAME_print
1890: 28 62 69 6f 2c 20 28 47 45 4e 45 52 41 4c 5f 4e  (bio, (GENERAL_N
18a0: 41 4d 45 20 2a 29 20 6e 61 6d 65 29 2c 20 62 69  AME *) name), bi
18b0: 6f 2c 20 62 75 66 66 65 72 2c 20 31 30 32 34 29  o, buffer, 1024)
18c0: 3b 0a 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 53  ;..    LAPPEND_S
18d0: 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  TR(interp, listP
18e0: 74 72 2c 20 4e 55 4c 4c 2c 20 62 75 66 66 65 72  tr, NULL, buffer
18f0: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e  , (Tcl_Size) len
1900: 29 3b 0a 09 7d 0a 09 73 6b 5f 47 45 4e 45 52 41  );..}..sk_GENERA
1910: 4c 5f 4e 41 4d 45 5f 70 6f 70 5f 66 72 65 65 28  L_NAME_pop_free(
1920: 6e 61 6d 65 73 2c 20 47 45 4e 45 52 41 4c 5f 4e  names, GENERAL_N
1930: 41 4d 45 5f 66 72 65 65 29 3b 0a 20 20 20 20 7d  AME_free);.    }
1940: 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74  .    return list
1950: 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65  Ptr;.}../*. * Ge
1960: 74 20 45 58 74 65 6e 64 65 64 20 4b 65 79 20 55  t EXtended Key U
1970: 73 61 67 65 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a  sage. */.Tcl_Obj
1980: 20 2a 54 6c 73 5f 78 35 30 39 45 78 74 4b 65 79   *Tls_x509ExtKey
1990: 55 73 61 67 65 28 54 63 6c 5f 49 6e 74 65 72 70  Usage(Tcl_Interp
19a0: 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a   *interp, X509 *
19b0: 63 65 72 74 2c 20 75 69 6e 74 33 32 5f 74 20 78  cert, uint32_t x
19c0: 66 6c 61 67 73 29 20 7b 0a 20 20 20 20 75 69 6e  flags) {.    uin
19d0: 74 33 32 5f 74 20 75 73 61 67 65 20 3d 20 58 35  t32_t usage = X5
19e0: 30 39 5f 67 65 74 5f 6b 65 79 5f 75 73 61 67 65  09_get_key_usage
19f0: 28 63 65 72 74 29 3b 0a 20 20 20 20 54 63 6c 5f  (cert);.    Tcl_
1a00: 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54  Obj *listPtr = T
1a10: 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c  cl_NewListObj(0,
1a20: 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20   NULL);..    if 
1a30: 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c  (listPtr == NULL
1a40: 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c  ) {..return NULL
1a50: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20  ;.    }..    if 
1a60: 28 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41  ((xflags & EXFLA
1a70: 47 5f 58 4b 55 53 41 47 45 29 20 26 26 20 75 73  G_XKUSAGE) && us
1a80: 61 67 65 20 3c 20 55 49 4e 54 33 32 5f 4d 41 58  age < UINT32_MAX
1a90: 29 20 7b 0a 09 75 73 61 67 65 20 3d 20 58 35 30  ) {..usage = X50
1aa0: 39 5f 67 65 74 5f 65 78 74 65 6e 64 65 64 5f 6b  9_get_extended_k
1ab0: 65 79 5f 75 73 61 67 65 28 63 65 72 74 29 3b 0a  ey_usage(cert);.
1ac0: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b  ..if (usage & XK
1ad0: 55 5f 53 53 4c 5f 53 45 52 56 45 52 29 20 7b 0a  U_SSL_SERVER) {.
1ae0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
1af0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
1b00: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54  terp, listPtr, T
1b10: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
1b20: 22 54 4c 53 20 57 65 62 20 53 65 72 76 65 72 20  "TLS Web Server 
1b30: 41 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 22 2c  Authentication",
1b40: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
1b50: 73 61 67 65 20 26 20 58 4b 55 5f 53 53 4c 5f 43  sage & XKU_SSL_C
1b60: 4c 49 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63  LIENT) {..    Tc
1b70: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
1b80: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
1b90: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
1ba0: 74 72 69 6e 67 4f 62 6a 28 22 54 4c 53 20 57 65  tringObj("TLS We
1bb0: 62 20 43 6c 69 65 6e 74 20 41 75 74 68 65 6e 74  b Client Authent
1bc0: 69 63 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a  ication", -1));.
1bd0: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20  .}..if (usage & 
1be0: 58 4b 55 5f 53 4d 49 4d 45 29 20 7b 0a 09 20 20  XKU_SMIME) {..  
1bf0: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
1c00: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
1c10: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
1c20: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 45 2d  NewStringObj("E-
1c30: 6d 61 69 6c 20 50 72 6f 74 65 63 74 69 6f 6e 22  mail Protection"
1c40: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28  , -1));..}..if (
1c50: 75 73 61 67 65 20 26 20 58 4b 55 5f 43 4f 44 45  usage & XKU_CODE
1c60: 5f 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 63  _SIGN) {..    Tc
1c70: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
1c80: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
1c90: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
1ca0: 74 72 69 6e 67 4f 62 6a 28 22 43 6f 64 65 20 53  tringObj("Code S
1cb0: 69 67 6e 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09  igning", -1));..
1cc0: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58  }..if (usage & X
1cd0: 4b 55 5f 53 47 43 29 20 7b 0a 09 20 20 20 20 54  KU_SGC) {..    T
1ce0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
1cf0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20  Element(interp, 
1d00: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77  listPtr, Tcl_New
1d10: 53 74 72 69 6e 67 4f 62 6a 28 22 53 47 43 22 2c  StringObj("SGC",
1d20: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
1d30: 73 61 67 65 20 26 20 58 4b 55 5f 4f 43 53 50 5f  sage & XKU_OCSP_
1d40: 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c  SIGN) {..    Tcl
1d50: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
1d60: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69  ement(interp, li
1d70: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  stPtr, Tcl_NewSt
1d80: 72 69 6e 67 4f 62 6a 28 22 4f 43 53 50 20 53 69  ringObj("OCSP Si
1d90: 67 6e 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d  gning", -1));..}
1da0: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b  ..if (usage & XK
1db0: 55 5f 54 49 4d 45 53 54 41 4d 50 29 20 7b 0a 09  U_TIMESTAMP) {..
1dc0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
1dd0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
1de0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
1df0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
1e00: 54 69 6d 65 20 53 74 61 6d 70 69 6e 67 22 2c 20  Time Stamping", 
1e10: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
1e20: 61 67 65 20 26 20 58 4b 55 5f 44 56 43 53 20 29  age & XKU_DVCS )
1e30: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
1e40: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
1e50: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
1e60: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
1e70: 62 6a 28 22 44 56 43 53 22 2c 20 2d 31 29 29 3b  bj("DVCS", -1));
1e80: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26  ..}..if (usage &
1e90: 20 58 4b 55 5f 41 4e 59 45 4b 55 29 20 7b 0a 09   XKU_ANYEKU) {..
1ea0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
1eb0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
1ec0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
1ed0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
1ee0: 41 6e 79 20 45 78 74 65 6e 64 65 64 20 4b 65 79  Any Extended Key
1ef0: 20 55 73 61 67 65 22 2c 20 2d 31 29 29 3b 0a 09   Usage", -1));..
1f00: 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09  }.    } else {..
1f10: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
1f20: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
1f30: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
1f40: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
1f50: 75 6e 72 65 73 74 72 69 63 74 65 64 22 2c 20 2d  unrestricted", -
1f60: 31 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72  1));.    }.    r
1f70: 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d  eturn listPtr;.}
1f80: 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 52 4c 20  ../*. * Get CRL 
1f90: 44 69 73 74 72 69 62 75 74 69 6f 6e 20 50 6f 69  Distribution Poi
1fa0: 6e 74 73 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20  nts. */.Tcl_Obj 
1fb0: 2a 54 6c 73 5f 78 35 30 39 43 72 6c 44 70 28 54  *Tls_x509CrlDp(T
1fc0: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  cl_Interp *inter
1fd0: 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b  p, X509 *cert) {
1fe0: 0a 20 20 20 20 53 54 41 43 4b 5f 4f 46 28 44 49  .    STACK_OF(DI
1ff0: 53 54 5f 50 4f 49 4e 54 29 20 2a 63 72 6c 3b 0a  ST_POINT) *crl;.
2000: 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73      Tcl_Obj *lis
2010: 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69  tPtr = Tcl_NewLi
2020: 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a  stObj(0, NULL);.
2030: 0a 20 20 20 20 69 66 20 28 6c 69 73 74 50 74 72  .    if (listPtr
2040: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74   == NULL) {..ret
2050: 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a  urn NULL;.    }.
2060: 0a 20 20 20 20 69 66 20 28 28 63 72 6c 20 3d 20  .    if ((crl = 
2070: 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69  X509_get_ext_d2i
2080: 28 63 65 72 74 2c 20 4e 49 44 5f 63 72 6c 5f 64  (cert, NID_crl_d
2090: 69 73 74 72 69 62 75 74 69 6f 6e 5f 70 6f 69 6e  istribution_poin
20a0: 74 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c 4c 29 29  ts, NULL, NULL))
20b0: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 66 6f 72   != NULL) {..for
20c0: 20 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20 73   (int i=0; i < s
20d0: 6b 5f 44 49 53 54 5f 50 4f 49 4e 54 5f 6e 75 6d  k_DIST_POINT_num
20e0: 28 63 72 6c 29 3b 20 69 2b 2b 29 20 7b 0a 09 20  (crl); i++) {.. 
20f0: 20 20 20 44 49 53 54 5f 50 4f 49 4e 54 20 2a 64     DIST_POINT *d
2100: 70 20 3d 20 73 6b 5f 44 49 53 54 5f 50 4f 49 4e  p = sk_DIST_POIN
2110: 54 5f 76 61 6c 75 65 28 63 72 6c 2c 20 69 29 3b  T_value(crl, i);
2120: 0a 09 20 20 20 20 44 49 53 54 5f 50 4f 49 4e 54  ..    DIST_POINT
2130: 5f 4e 41 4d 45 20 2a 64 69 73 74 70 6f 69 6e 74  _NAME *distpoint
2140: 20 3d 20 64 70 2d 3e 64 69 73 74 70 6f 69 6e 74   = dp->distpoint
2150: 3b 0a 0a 09 20 20 20 20 69 66 20 28 64 69 73 74  ;...    if (dist
2160: 70 6f 69 6e 74 2d 3e 74 79 70 65 20 3d 3d 20 30  point->type == 0
2170: 29 20 7b 0a 09 09 2f 2a 20 66 75 6c 6c 2d 6e 61  ) {.../* full-na
2180: 6d 65 20 47 45 4e 45 52 41 4c 49 5a 45 44 4e 41  me GENERALIZEDNA
2190: 4d 45 20 2a 2f 0a 09 09 66 6f 72 20 28 69 6e 74  ME */...for (int
21a0: 20 6a 20 3d 20 30 3b 20 6a 20 3c 20 73 6b 5f 47   j = 0; j < sk_G
21b0: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e 75 6d 28  ENERAL_NAME_num(
21c0: 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e  distpoint->name.
21d0: 66 75 6c 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20  fullname); j++) 
21e0: 7b 0a 09 09 20 20 20 20 47 45 4e 45 52 41 4c 5f  {...    GENERAL_
21f0: 4e 41 4d 45 20 2a 67 65 6e 20 3d 20 73 6b 5f 47  NAME *gen = sk_G
2200: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75  ENERAL_NAME_valu
2210: 65 28 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d  e(distpoint->nam
2220: 65 2e 66 75 6c 6c 6e 61 6d 65 2c 20 6a 29 3b 0a  e.fullname, j);.
2230: 09 09 20 20 20 20 69 6e 74 20 74 79 70 65 3b 0a  ..    int type;.
2240: 09 09 20 20 20 20 41 53 4e 31 5f 53 54 52 49 4e  ..    ASN1_STRIN
2250: 47 20 2a 75 72 69 20 3d 20 47 45 4e 45 52 41 4c  G *uri = GENERAL
2260: 5f 4e 41 4d 45 5f 67 65 74 30 5f 76 61 6c 75 65  _NAME_get0_value
2270: 28 67 65 6e 2c 20 26 74 79 70 65 29 3b 0a 09 09  (gen, &type);...
2280: 20 20 20 20 69 66 20 28 74 79 70 65 20 3d 3d 20      if (type == 
2290: 47 45 4e 5f 55 52 49 29 20 7b 0a 09 09 09 4c 41  GEN_URI) {....LA
22a0: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
22b0: 2c 20 6c 69 73 74 50 74 72 2c 20 28 63 68 61 72  , listPtr, (char
22c0: 20 2a 29 20 4e 55 4c 4c 2c 20 28 63 68 61 72 20   *) NULL, (char 
22d0: 2a 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 67  *) ASN1_STRING_g
22e0: 65 74 30 5f 64 61 74 61 28 75 72 69 29 2c 20 28  et0_data(uri), (
22f0: 54 63 6c 5f 53 69 7a 65 29 20 41 53 4e 31 5f 53  Tcl_Size) ASN1_S
2300: 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 75 72 69  TRING_length(uri
2310: 29 29 3b 0a 09 09 20 20 20 20 7d 0a 09 09 7d 0a  ));...    }...}.
2320: 09 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28  .    } else if (
2330: 64 69 73 74 70 6f 69 6e 74 2d 3e 74 79 70 65 20  distpoint->type 
2340: 3d 3d 20 31 29 20 7b 0a 09 09 2f 2a 20 72 65 6c  == 1) {.../* rel
2350: 61 74 69 76 65 2d 6e 61 6d 65 20 58 35 30 39 4e  ative-name X509N
2360: 41 4d 45 20 2a 2f 0a 09 09 53 54 41 43 4b 5f 4f  AME */...STACK_O
2370: 46 28 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52  F(X509_NAME_ENTR
2380: 59 29 20 2a 73 6b 5f 72 65 6c 6e 61 6d 65 20 3d  Y) *sk_relname =
2390: 20 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65   distpoint->name
23a0: 2e 72 65 6c 61 74 69 76 65 6e 61 6d 65 3b 0a 09  .relativename;..
23b0: 09 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b  .for (int j = 0;
23c0: 20 6a 20 3c 20 73 6b 5f 58 35 30 39 5f 4e 41 4d   j < sk_X509_NAM
23d0: 45 5f 45 4e 54 52 59 5f 6e 75 6d 28 73 6b 5f 72  E_ENTRY_num(sk_r
23e0: 65 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20 7b 0a  elname); j++) {.
23f0: 09 09 20 20 20 20 58 35 30 39 5f 4e 41 4d 45 5f  ..    X509_NAME_
2400: 45 4e 54 52 59 20 2a 65 20 3d 20 73 6b 5f 58 35  ENTRY *e = sk_X5
2410: 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 76 61  09_NAME_ENTRY_va
2420: 6c 75 65 28 73 6b 5f 72 65 6c 6e 61 6d 65 2c 20  lue(sk_relname, 
2430: 6a 29 3b 0a 09 09 20 20 20 20 41 53 4e 31 5f 53  j);...    ASN1_S
2440: 54 52 49 4e 47 20 2a 64 20 3d 20 58 35 30 39 5f  TRING *d = X509_
2450: 4e 41 4d 45 5f 45 4e 54 52 59 5f 67 65 74 5f 64  NAME_ENTRY_get_d
2460: 61 74 61 28 65 29 3b 0a 09 09 20 20 20 20 4c 41  ata(e);...    LA
2470: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
2480: 2c 20 6c 69 73 74 50 74 72 2c 20 28 63 68 61 72  , listPtr, (char
2490: 20 2a 29 20 4e 55 4c 4c 2c 20 28 63 68 61 72 20   *) NULL, (char 
24a0: 2a 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 64  *) ASN1_STRING_d
24b0: 61 74 61 28 64 29 2c 20 28 54 63 6c 5f 53 69 7a  ata(d), (Tcl_Siz
24c0: 65 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 6c  e) ASN1_STRING_l
24d0: 65 6e 67 74 68 28 64 29 29 3b 0a 09 09 7d 0a 09  ength(d));...}..
24e0: 20 20 20 20 7d 0a 09 7d 0a 09 43 52 4c 5f 44 49      }..}..CRL_DI
24f0: 53 54 5f 50 4f 49 4e 54 53 5f 66 72 65 65 28 63  ST_POINTS_free(c
2500: 72 6c 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72  rl);.    }.    r
2510: 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d  eturn listPtr;.}
2520: 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 4f 6e 2d 6c  ../*. * Get On-l
2530: 69 6e 65 20 43 65 72 74 69 66 69 63 61 74 65 20  ine Certificate 
2540: 53 74 61 74 75 73 20 50 72 6f 74 6f 63 6f 6c 20  Status Protocol 
2550: 28 4f 53 43 50 29 20 55 52 4c 0a 20 2a 2f 0a 54  (OSCP) URL. */.T
2560: 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39  cl_Obj *Tls_x509
2570: 4f 73 63 70 28 54 63 6c 5f 49 6e 74 65 72 70 20  Oscp(Tcl_Interp 
2580: 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63  *interp, X509 *c
2590: 65 72 74 29 20 7b 0a 20 20 20 20 53 54 41 43 4b  ert) {.    STACK
25a0: 5f 4f 46 28 4f 50 45 4e 53 53 4c 5f 53 54 52 49  _OF(OPENSSL_STRI
25b0: 4e 47 29 20 2a 6f 63 73 70 3b 0a 20 20 20 20 54  NG) *ocsp;.    T
25c0: 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20  cl_Obj *listPtr 
25d0: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a  = Tcl_NewListObj
25e0: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20  (0, NULL);..    
25f0: 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e  if (listPtr == N
2600: 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e  ULL) {..return N
2610: 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20  ULL;.    }..    
2620: 69 66 20 28 28 6f 63 73 70 20 3d 20 58 35 30 39  if ((ocsp = X509
2630: 5f 67 65 74 31 5f 6f 63 73 70 28 63 65 72 74 29  _get1_ocsp(cert)
2640: 29 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 66 6f  ) != NULL) {..fo
2650: 72 20 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 20  r (int i = 0; i 
2660: 3c 20 73 6b 5f 4f 50 45 4e 53 53 4c 5f 53 54 52  < sk_OPENSSL_STR
2670: 49 4e 47 5f 6e 75 6d 28 6f 63 73 70 29 3b 20 69  ING_num(ocsp); i
2680: 2b 2b 29 20 7b 0a 09 20 20 20 20 4c 41 50 50 45  ++) {..    LAPPE
2690: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 6c  ND_STR(interp, l
26a0: 69 73 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 73 6b  istPtr, NULL, sk
26b0: 5f 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e 47 5f  _OPENSSL_STRING_
26c0: 76 61 6c 75 65 28 6f 63 73 70 2c 20 69 29 2c 20  value(ocsp, i), 
26d0: 2d 31 29 3b 0a 09 7d 0a 09 58 35 30 39 5f 65 6d  -1);..}..X509_em
26e0: 61 69 6c 5f 66 72 65 65 28 6f 63 73 70 29 3b 0a  ail_free(ocsp);.
26f0: 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e      }.    return
2700: 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a   listPtr;.}../*.
2710: 20 2a 20 47 65 74 20 43 65 72 74 69 66 69 63 61   * Get Certifica
2720: 74 65 20 41 75 74 68 6f 72 69 74 79 20 28 43 41  te Authority (CA
2730: 29 20 49 73 73 75 65 72 73 20 55 52 4c 0a 20 2a  ) Issuers URL. *
2740: 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78  /.Tcl_Obj *Tls_x
2750: 35 30 39 43 61 49 73 73 75 65 72 73 28 54 63 6c  509CaIssuers(Tcl
2760: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
2770: 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20   X509 *cert) {. 
2780: 20 20 20 53 54 41 43 4b 5f 4f 46 28 41 43 43 45     STACK_OF(ACCE
2790: 53 53 5f 44 45 53 43 52 49 50 54 49 4f 4e 29 20  SS_DESCRIPTION) 
27a0: 2a 61 64 73 3b 0a 20 20 20 20 41 43 43 45 53 53  *ads;.    ACCESS
27b0: 5f 44 45 53 43 52 49 50 54 49 4f 4e 20 2a 61 64  _DESCRIPTION *ad
27c0: 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c  ;.    Tcl_Obj *l
27d0: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77  istPtr = Tcl_New
27e0: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29  ListObj(0, NULL)
27f0: 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 63  ;.    unsigned c
2800: 68 61 72 20 2a 62 75 66 3b 0a 20 20 20 20 69 6e  har *buf;.    in
2810: 74 20 6c 65 6e 3b 0a 0a 20 20 20 20 69 66 20 28  t len;..    if (
2820: 28 61 64 73 20 3d 20 58 35 30 39 5f 67 65 74 5f  (ads = X509_get_
2830: 65 78 74 5f 64 32 69 28 63 65 72 74 2c 20 4e 49  ext_d2i(cert, NI
2840: 44 5f 69 6e 66 6f 5f 61 63 63 65 73 73 2c 20 4e  D_info_access, N
2850: 55 4c 4c 2c 20 4e 55 4c 4c 29 29 20 21 3d 20 4e  ULL, NULL)) != N
2860: 55 4c 4c 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74  ULL) {..for (int
2870: 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b 5f 41   i = 0; i < sk_A
2880: 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f  CCESS_DESCRIPTIO
2890: 4e 5f 6e 75 6d 28 61 64 73 29 3b 20 69 2b 2b 29  N_num(ads); i++)
28a0: 20 7b 0a 09 20 20 20 20 61 64 20 3d 20 73 6b 5f   {..    ad = sk_
28b0: 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49  ACCESS_DESCRIPTI
28c0: 4f 4e 5f 76 61 6c 75 65 28 61 64 73 2c 20 69 29  ON_value(ads, i)
28d0: 3b 0a 09 20 20 20 20 69 66 20 28 4f 42 4a 5f 6f  ;..    if (OBJ_o
28e0: 62 6a 32 6e 69 64 28 61 64 2d 3e 6d 65 74 68 6f  bj2nid(ad->metho
28f0: 64 29 20 3d 3d 20 4e 49 44 5f 61 64 5f 63 61 5f  d) == NID_ad_ca_
2900: 69 73 73 75 65 72 73 20 26 26 20 61 64 2d 3e 6c  issuers && ad->l
2910: 6f 63 61 74 69 6f 6e 29 20 7b 0a 09 09 69 66 20  ocation) {...if 
2920: 28 61 64 2d 3e 6c 6f 63 61 74 69 6f 6e 2d 3e 74  (ad->location->t
2930: 79 70 65 20 3d 3d 20 47 45 4e 5f 55 52 49 29 20  ype == GEN_URI) 
2940: 7b 0a 09 09 20 20 20 20 6c 65 6e 20 3d 20 41 53  {...    len = AS
2950: 4e 31 5f 53 54 52 49 4e 47 5f 74 6f 5f 55 54 46  N1_STRING_to_UTF
2960: 38 28 26 62 75 66 2c 20 61 64 2d 3e 6c 6f 63 61  8(&buf, ad->loca
2970: 74 69 6f 6e 2d 3e 64 2e 75 6e 69 66 6f 72 6d 52  tion->d.uniformR
2980: 65 73 6f 75 72 63 65 49 64 65 6e 74 69 66 69 65  esourceIdentifie
2990: 72 29 3b 0a 09 09 20 20 20 20 54 63 6c 5f 4c 69  r);...    Tcl_Li
29a0: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
29b0: 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  nt(interp, listP
29c0: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  tr, Tcl_NewStrin
29d0: 67 4f 62 6a 28 28 63 68 61 72 20 2a 29 20 62 75  gObj((char *) bu
29e0: 66 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65  f, (Tcl_Size) le
29f0: 6e 29 29 3b 0a 09 09 20 20 20 20 4f 50 45 4e 53  n));...    OPENS
2a00: 53 4c 5f 66 72 65 65 28 62 75 66 29 3b 0a 09 09  SL_free(buf);...
2a10: 20 20 20 20 62 72 65 61 6b 3b 0a 09 09 7d 0a 09      break;...}..
2a20: 20 20 20 20 7d 0a 09 7d 0a 09 2f 2a 20 73 6b 5f      }..}../* sk_
2a30: 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49  ACCESS_DESCRIPTI
2a40: 4f 4e 5f 70 6f 70 5f 66 72 65 65 28 61 64 73 2c  ON_pop_free(ads,
2a50: 20 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 54   ACCESS_DESCRIPT
2a60: 49 4f 4e 5f 66 72 65 65 29 3b 20 2a 2f 0a 09 41  ION_free); */..A
2a70: 55 54 48 4f 52 49 54 59 5f 49 4e 46 4f 5f 41 43  UTHORITY_INFO_AC
2a80: 43 45 53 53 5f 66 72 65 65 28 61 64 73 29 3b 0a  CESS_free(ads);.
2a90: 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e      }.    return
2aa0: 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0c 0a 2f 2a   listPtr;.}.../*
2ab0: 0a 20 2a 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 2d 2a 0a 20 2a 0a 20 2a  ---------*. *. *
2af0: 09 54 6c 73 5f 4e 65 77 58 35 30 39 4f 62 6a 20  .Tls_NewX509Obj 
2b00: 2d 2d 0a 20 2a 0a 20 2a 09 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 2d 2a 0a 20 2a 09 43 6f  ---------*. *.Co
2b40: 6e 76 65 72 74 73 20 61 20 58 35 30 39 20 63 65  nverts a X509 ce
2b50: 72 74 69 66 69 63 61 74 65 20 69 6e 74 6f 20 61  rtificate into a
2b60: 20 54 63 6c 5f 4f 62 6a 0a 20 2a 09 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 2d 2a 0a 20 2a  ------------*. *
2ba0: 0a 20 2a 09 53 69 64 65 20 65 66 66 65 63 74 73  . *.Side effects
2bb0: 3a 0a 20 2a 09 09 4e 6f 6e 65 0a 20 2a 0a 20 2a  :. *..None. *. *
2bc0: 09 52 65 73 75 6c 74 3a 0a 20 2a 09 09 41 20 54  .Result:. *..A T
2bd0: 63 6c 20 4c 69 73 74 20 4f 62 6a 65 63 74 20 72  cl List Object r
2be0: 65 70 72 65 73 65 6e 74 69 6e 67 20 74 68 65 20  epresenting the 
2bf0: 70 72 6f 76 69 64 65 64 0a 20 2a 09 09 58 35 30  provided. *..X50
2c00: 39 20 63 65 72 74 69 66 69 63 61 74 65 2e 0a 20  9 certificate.. 
2c10: 2a 0a 20 2a 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 2d 2a 0a 20 2a 2f 0a  ----------*. */.
2c50: 0a 54 63 6c 5f 4f 62 6a 2a 0a 54 6c 73 5f 4e 65  .Tcl_Obj*.Tls_Ne
2c60: 77 58 35 30 39 4f 62 6a 28 54 63 6c 5f 49 6e 74  wX509Obj(Tcl_Int
2c70: 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30  erp *interp, X50
2c80: 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 54  9 *cert) {.    T
2c90: 63 6c 5f 4f 62 6a 20 2a 63 65 72 74 50 74 72 20  cl_Obj *certPtr 
2ca0: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a  = Tcl_NewListObj
2cb0: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 42  (0, NULL);.    B
2cc0: 49 4f 20 2a 62 69 6f 20 3d 20 42 49 4f 5f 6e 65  IO *bio = BIO_ne
2cd0: 77 28 42 49 4f 5f 73 5f 6d 65 6d 28 29 29 3b 0a  w(BIO_s_mem());.
2ce0: 20 20 20 20 69 6e 74 20 6d 64 6e 69 64 2c 20 70      int mdnid, p
2cf0: 6b 6e 69 64 2c 20 62 69 74 73 2c 20 6c 65 6e 3b  knid, bits, len;
2d00: 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 69 6e  .    unsigned in
2d10: 74 20 75 6c 65 6e 3b 0a 20 20 20 20 75 69 6e 74  t ulen;.    uint
2d20: 33 32 5f 74 20 78 66 6c 61 67 73 3b 0a 20 20 20  32_t xflags;.   
2d30: 20 63 68 61 72 20 62 75 66 66 65 72 5b 42 55 46   char buffer[BUF
2d40: 53 49 5a 5d 3b 0a 20 20 20 20 75 6e 73 69 67 6e  SIZ];.    unsign
2d50: 65 64 20 63 68 61 72 20 6d 64 5b 45 56 50 5f 4d  ed char md[EVP_M
2d60: 41 58 5f 4d 44 5f 53 49 5a 45 5d 3b 0a 20 20 20  AX_MD_SIZE];.   
2d70: 20 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67 20 66   unsigned long f
2d80: 6c 61 67 73 20 3d 20 58 4e 5f 46 4c 41 47 5f 52  lags = XN_FLAG_R
2d90: 46 43 32 32 35 33 20 7c 20 41 53 4e 31 5f 53 54  FC2253 | ASN1_ST
2da0: 52 46 4c 47 53 5f 55 54 46 38 5f 43 4f 4e 56 45  RFLGS_UTF8_CONVE
2db0: 52 54 3b 0a 20 20 20 20 66 6c 61 67 73 20 26 3d  RT;.    flags &=
2dc0: 20 7e 41 53 4e 31 5f 53 54 52 46 4c 47 53 5f 45   ~ASN1_STRFLGS_E
2dd0: 53 43 5f 4d 53 42 3b 0a 0a 20 20 20 20 69 66 20  SC_MSB;..    if 
2de0: 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c 4c 20  (interp == NULL 
2df0: 7c 7c 20 63 65 72 74 20 3d 3d 20 4e 55 4c 4c 20  || cert == NULL 
2e00: 7c 7c 20 62 69 6f 20 3d 3d 20 4e 55 4c 4c 20 7c  || bio == NULL |
2e10: 7c 20 63 65 72 74 50 74 72 20 3d 3d 20 4e 55 4c  | certPtr == NUL
2e20: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c  L) {..return NUL
2e30: 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a  L;.    }..    /*
2e40: 20 53 69 67 6e 61 74 75 72 65 20 61 6c 67 6f 72   Signature algor
2e50: 69 74 68 6d 20 61 6e 64 20 76 61 6c 75 65 20 2d  ithm and value -
2e60: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
2e70: 6e 20 34 2e 31 2e 31 2e 32 20 61 6e 64 20 34 2e  n 4.1.1.2 and 4.
2e80: 31 2e 31 2e 33 20 2a 2f 0a 20 20 20 20 2f 2a 20  1.1.3 */.    /* 
2e90: 73 69 67 6e 61 74 75 72 65 41 6c 67 6f 72 69 74  signatureAlgorit
2ea0: 68 6d 20 69 73 20 74 68 65 20 69 64 20 6f 66 20  hm is the id of 
2eb0: 74 68 65 20 63 72 79 70 74 6f 67 72 61 70 68 69  the cryptographi
2ec0: 63 20 61 6c 67 6f 72 69 74 68 6d 20 75 73 65 64  c algorithm used
2ed0: 20 62 79 20 74 68 65 0a 09 43 41 20 74 6f 20 73   by the..CA to s
2ee0: 69 67 6e 20 74 68 69 73 20 63 65 72 74 2e 20 73  ign this cert. s
2ef0: 69 67 6e 61 74 75 72 65 56 61 6c 75 65 20 69 73  ignatureValue is
2f00: 20 74 68 65 20 64 69 67 69 74 61 6c 20 73 69 67   the digital sig
2f10: 6e 61 74 75 72 65 20 63 6f 6d 70 75 74 65 64 0a  nature computed.
2f20: 09 75 70 6f 6e 20 74 68 65 20 41 53 4e 2e 31 20  .upon the ASN.1 
2f30: 44 45 52 20 65 6e 63 6f 64 65 64 20 74 62 73 43  DER encoded tbsC
2f40: 65 72 74 69 66 69 63 61 74 65 2e 20 2a 2f 0a 20  ertificate. */. 
2f50: 20 20 20 7b 0a 09 63 6f 6e 73 74 20 58 35 30 39     {..const X509
2f60: 5f 41 4c 47 4f 52 20 2a 73 69 67 5f 61 6c 67 3b  _ALGOR *sig_alg;
2f70: 0a 09 63 6f 6e 73 74 20 41 53 4e 31 5f 42 49 54  ..const ASN1_BIT
2f80: 5f 53 54 52 49 4e 47 20 2a 73 69 67 3b 0a 09 69  _STRING *sig;..i
2f90: 6e 74 20 73 69 67 5f 6e 69 64 3b 0a 0a 09 58 35  nt sig_nid;...X5
2fa0: 30 39 5f 67 65 74 30 5f 73 69 67 6e 61 74 75 72  09_get0_signatur
2fb0: 65 28 26 73 69 67 2c 20 26 73 69 67 5f 61 6c 67  e(&sig, &sig_alg
2fc0: 2c 20 63 65 72 74 29 3b 0a 09 2f 2a 20 73 69 67  , cert);../* sig
2fd0: 5f 6e 69 64 20 3d 20 58 35 30 39 5f 67 65 74 5f  _nid = X509_get_
2fe0: 73 69 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65  signature_nid(ce
2ff0: 72 74 29 20 2a 2f 0a 09 73 69 67 5f 6e 69 64 20  rt) */..sig_nid 
3000: 3d 20 4f 42 4a 5f 6f 62 6a 32 6e 69 64 28 73 69  = OBJ_obj2nid(si
3010: 67 5f 61 6c 67 2d 3e 61 6c 67 6f 72 69 74 68 6d  g_alg->algorithm
3020: 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28  );..LAPPEND_STR(
3030: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
3040: 20 22 73 69 67 6e 61 74 75 72 65 41 6c 67 6f 72   "signatureAlgor
3050: 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c  ithm", OBJ_nid2l
3060: 6e 28 73 69 67 5f 6e 69 64 29 2c 20 2d 31 29 3b  n(sig_nid), -1);
3070: 0a 09 6c 65 6e 20 3d 20 28 73 69 67 5f 6e 69 64  ..len = (sig_nid
3080: 20 21 3d 20 4e 49 44 5f 75 6e 64 65 66 29 20 3f   != NID_undef) ?
3090: 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 73   String_to_Hex(s
30a0: 69 67 2d 3e 64 61 74 61 2c 20 73 69 67 2d 3e 6c  ig->data, sig->l
30b0: 65 6e 67 74 68 2c 20 28 75 6e 73 69 67 6e 65 64  ength, (unsigned
30c0: 20 63 68 61 72 20 2a 29 20 62 75 66 66 65 72 2c   char *) buffer,
30d0: 20 42 55 46 53 49 5a 29 20 3a 20 30 3b 0a 09 4c   BUFSIZ) : 0;..L
30e0: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
30f0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 67  p, certPtr, "sig
3100: 6e 61 74 75 72 65 56 61 6c 75 65 22 2c 20 62 75  natureValue", bu
3110: 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29  ffer, (Tcl_Size)
3120: 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20   len);.    }..  
3130: 20 20 2f 2a 20 56 65 72 73 69 6f 6e 20 6f 66 20    /* Version of 
3140: 74 68 65 20 65 6e 63 6f 64 65 64 20 63 65 72 74  the encoded cert
3150: 69 66 69 63 61 74 65 20 2d 20 52 46 43 20 35 32  ificate - RFC 52
3160: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32  80 section 4.1.2
3170: 2e 31 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e  .1 */.    LAPPEN
3180: 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63  D_LONG(interp, c
3190: 65 72 74 50 74 72 2c 20 22 76 65 72 73 69 6f 6e  ertPtr, "version
31a0: 22 2c 20 58 35 30 39 5f 67 65 74 5f 76 65 72 73  ", X509_get_vers
31b0: 69 6f 6e 28 63 65 72 74 29 2b 31 29 3b 0a 0a 20  ion(cert)+1);.. 
31c0: 20 20 20 2f 2a 20 55 6e 69 71 75 65 20 6e 75 6d     /* Unique num
31d0: 62 65 72 20 61 73 73 69 67 6e 65 64 20 62 79 20  ber assigned by 
31e0: 43 41 20 74 6f 20 63 65 72 74 69 66 69 63 61 74  CA to certificat
31f0: 65 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63  e - RFC 5280 sec
3200: 74 69 6f 6e 20 34 2e 31 2e 32 2e 32 20 2a 2f 0a  tion 4.1.2.2 */.
3210: 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f      len = BIO_to
3220: 5f 42 75 66 66 65 72 28 69 32 61 5f 41 53 4e 31  _Buffer(i2a_ASN1
3230: 5f 49 4e 54 45 47 45 52 28 62 69 6f 2c 20 58 35  _INTEGER(bio, X5
3240: 30 39 5f 67 65 74 30 5f 73 65 72 69 61 6c 4e 75  09_get0_serialNu
3250: 6d 62 65 72 28 63 65 72 74 29 29 2c 20 62 69 6f  mber(cert)), bio
3260: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a  , buffer, BUFSIZ
3270: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53  );.    LAPPEND_S
3280: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  TR(interp, certP
3290: 74 72 2c 20 22 73 65 72 69 61 6c 4e 75 6d 62 65  tr, "serialNumbe
32a0: 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c  r", buffer, (Tcl
32b0: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20  _Size) len);..  
32c0: 20 20 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61    /* Signature a
32d0: 6c 67 6f 72 69 74 68 6d 20 75 73 65 64 20 62 79  lgorithm used by
32e0: 20 74 68 65 20 43 41 20 74 6f 20 73 69 67 6e 20   the CA to sign 
32f0: 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e  the certificate.
3300: 20 4d 75 73 74 20 6d 61 74 63 68 0a 09 73 69 67   Must match..sig
3310: 6e 61 74 75 72 65 41 6c 67 6f 72 69 74 68 6d 2e  natureAlgorithm.
3320: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
3330: 6e 20 34 2e 31 2e 32 2e 33 20 2a 2f 0a 20 20 20  n 4.1.2.3 */.   
3340: 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74   LAPPEND_STR(int
3350: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73  erp, certPtr, "s
3360: 69 67 6e 61 74 75 72 65 22 2c 20 4f 42 4a 5f 6e  ignature", OBJ_n
3370: 69 64 32 6c 6e 28 58 35 30 39 5f 67 65 74 5f 73  id2ln(X509_get_s
3380: 69 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 72  ignature_nid(cer
3390: 74 29 29 2c 20 2d 31 29 3b 0a 0a 20 20 20 20 2f  t)), -1);..    /
33a0: 2a 20 49 73 73 75 65 72 20 69 64 65 6e 74 69 66  * Issuer identif
33b0: 69 65 73 20 74 68 65 20 65 6e 74 69 74 79 20 74  ies the entity t
33c0: 68 61 74 20 73 69 67 6e 65 64 20 61 6e 64 20 69  hat signed and i
33d0: 73 73 75 65 64 20 74 68 65 20 63 65 72 74 2e 20  ssued the cert. 
33e0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
33f0: 20 34 2e 31 2e 32 2e 34 20 2a 2f 0a 20 20 20 20   4.1.2.4 */.    
3400: 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66  len = BIO_to_Buf
3410: 66 65 72 28 58 35 30 39 5f 4e 41 4d 45 5f 70 72  fer(X509_NAME_pr
3420: 69 6e 74 5f 65 78 28 62 69 6f 2c 20 58 35 30 39  int_ex(bio, X509
3430: 5f 67 65 74 5f 69 73 73 75 65 72 5f 6e 61 6d 65  _get_issuer_name
3440: 28 63 65 72 74 29 2c 20 30 2c 20 66 6c 61 67 73  (cert), 0, flags
3450: 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20  ), bio, buffer, 
3460: 42 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50  BUFSIZ);.    LAP
3470: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
3480: 20 63 65 72 74 50 74 72 2c 20 22 69 73 73 75 65   certPtr, "issue
3490: 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c  r", buffer, (Tcl
34a0: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20  _Size) len);..  
34b0: 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65    /* Certificate
34c0: 20 76 61 6c 69 64 69 74 79 20 70 65 72 69 6f 64   validity period
34d0: 20 69 73 20 74 68 65 20 69 6e 74 65 72 76 61 6c   is the interval
34e0: 20 74 68 65 20 43 41 20 77 61 72 72 61 6e 74 73   the CA warrants
34f0: 20 74 68 61 74 20 69 74 20 77 69 6c 6c 0a 09 6d   that it will..m
3500: 61 69 6e 74 61 69 6e 20 69 6e 66 6f 20 6f 6e 20  aintain info on 
3510: 74 68 65 20 73 74 61 74 75 73 20 6f 66 20 74 68  the status of th
3520: 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 52  e certificate. R
3530: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
3540: 34 2e 31 2e 32 2e 35 20 2a 2f 0a 20 20 20 20 2f  4.1.2.5 */.    /
3550: 2a 20 47 65 74 20 56 61 6c 69 64 69 74 79 20 2d  * Get Validity -
3560: 20 4e 6f 74 20 42 65 66 6f 72 65 20 2a 2f 0a 20   Not Before */. 
3570: 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f     len = BIO_to_
3580: 42 75 66 66 65 72 28 41 53 4e 31 5f 54 49 4d 45  Buffer(ASN1_TIME
3590: 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 35 30 39  _print(bio, X509
35a0: 5f 67 65 74 30 5f 6e 6f 74 42 65 66 6f 72 65 28  _get0_notBefore(
35b0: 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66  cert)), bio, buf
35c0: 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20  fer, BUFSIZ);.  
35d0: 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e    LAPPEND_STR(in
35e0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
35f0: 6e 6f 74 42 65 66 6f 72 65 22 2c 20 62 75 66 66  notBefore", buff
3600: 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c  er, (Tcl_Size) l
3610: 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74  en);..    /* Get
3620: 20 56 61 6c 69 64 69 74 79 20 2d 20 4e 6f 74 20   Validity - Not 
3630: 41 66 74 65 72 20 2a 2f 0a 20 20 20 20 6c 65 6e  After */.    len
3640: 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72   = BIO_to_Buffer
3650: 28 41 53 4e 31 5f 54 49 4d 45 5f 70 72 69 6e 74  (ASN1_TIME_print
3660: 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30 5f  (bio, X509_get0_
3670: 6e 6f 74 41 66 74 65 72 28 63 65 72 74 29 29 2c  notAfter(cert)),
3680: 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55   bio, buffer, BU
3690: 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45  FSIZ);.    LAPPE
36a0: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
36b0: 65 72 74 50 74 72 2c 20 22 6e 6f 74 41 66 74 65  ertPtr, "notAfte
36c0: 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c  r", buffer, (Tcl
36d0: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20  _Size) len);..  
36e0: 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 69 64 65    /* Subject ide
36f0: 6e 74 69 66 69 65 73 20 74 68 65 20 65 6e 74 69  ntifies the enti
3700: 74 79 20 61 73 73 6f 63 69 61 74 65 64 20 77 69  ty associated wi
3710: 74 68 20 74 68 65 20 70 75 62 6c 69 63 20 6b 65  th the public ke
3720: 79 20 73 74 6f 72 65 64 20 69 6e 0a 09 74 68 65  y stored in..the
3730: 20 73 75 62 6a 65 63 74 20 70 75 62 6c 69 63 20   subject public 
3740: 6b 65 79 20 66 69 65 6c 64 2e 20 52 46 43 20 35  key field. RFC 5
3750: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e  280 section 4.1.
3760: 32 2e 36 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d  2.6 */.    len =
3770: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58   BIO_to_Buffer(X
3780: 35 30 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f 65  509_NAME_print_e
3790: 78 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 5f  x(bio, X509_get_
37a0: 73 75 62 6a 65 63 74 5f 6e 61 6d 65 28 63 65 72  subject_name(cer
37b0: 74 29 2c 20 30 2c 20 66 6c 61 67 73 29 2c 20 62  t), 0, flags), b
37c0: 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53  io, buffer, BUFS
37d0: 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44  IZ);.    LAPPEND
37e0: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72  _STR(interp, cer
37f0: 74 50 74 72 2c 20 22 73 75 62 6a 65 63 74 22 2c  tPtr, "subject",
3800: 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69   buffer, (Tcl_Si
3810: 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f  ze) len);..    /
3820: 2a 20 53 48 41 31 20 44 69 67 65 73 74 20 28 46  * SHA1 Digest (F
3830: 69 6e 67 65 72 70 72 69 6e 74 29 20 6f 66 20 63  ingerprint) of c
3840: 65 72 74 20 2d 20 44 45 52 20 72 65 70 72 65 73  ert - DER repres
3850: 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20  entation */.    
3860: 69 66 20 28 58 35 30 39 5f 64 69 67 65 73 74 28  if (X509_digest(
3870: 63 65 72 74 2c 20 45 56 50 5f 73 68 61 31 28 29  cert, EVP_sha1()
3880: 2c 20 6d 64 2c 20 26 75 6c 65 6e 29 29 20 7b 0a  , md, &ulen)) {.
3890: 09 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f  .len = String_to
38a0: 5f 48 65 78 28 6d 64 2c 20 6c 65 6e 2c 20 28 75  _Hex(md, len, (u
38b0: 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 29 20  nsigned char *) 
38c0: 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b  buffer, BUFSIZ);
38d0: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e  ..LAPPEND_STR(in
38e0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
38f0: 73 68 61 31 5f 68 61 73 68 22 2c 20 62 75 66 66  sha1_hash", buff
3900: 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 75  er, (Tcl_Size) u
3910: 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  len);.    }..   
3920: 20 2f 2a 20 53 48 41 32 35 36 20 44 69 67 65 73   /* SHA256 Diges
3930: 74 20 28 46 69 6e 67 65 72 70 72 69 6e 74 29 20  t (Fingerprint) 
3940: 6f 66 20 63 65 72 74 20 2d 20 44 45 52 20 72 65  of cert - DER re
3950: 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a  presentation */.
3960: 20 20 20 20 69 66 20 28 58 35 30 39 5f 64 69 67      if (X509_dig
3970: 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f 73 68  est(cert, EVP_sh
3980: 61 32 35 36 28 29 2c 20 6d 64 2c 20 26 75 6c 65  a256(), md, &ule
3990: 6e 29 29 20 7b 0a 09 6c 65 6e 20 3d 20 53 74 72  n)) {..len = Str
39a0: 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 6c  ing_to_Hex(md, l
39b0: 65 6e 2c 20 28 75 6e 73 69 67 6e 65 64 20 63 68  en, (unsigned ch
39c0: 61 72 20 2a 29 20 62 75 66 66 65 72 2c 20 42 55  ar *) buffer, BU
39d0: 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f  FSIZ);..LAPPEND_
39e0: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
39f0: 50 74 72 2c 20 22 73 68 61 32 35 36 5f 68 61 73  Ptr, "sha256_has
3a00: 68 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c  h", buffer, (Tcl
3a10: 5f 53 69 7a 65 29 20 75 6c 65 6e 29 3b 0a 20 20  _Size) ulen);.  
3a20: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a    }..    /* Subj
3a30: 65 63 74 20 50 75 62 6c 69 63 20 4b 65 79 20 49  ect Public Key I
3a40: 6e 66 6f 20 73 70 65 63 69 66 69 65 73 20 74 68  nfo specifies th
3a50: 65 20 70 75 62 6c 69 63 20 6b 65 79 20 61 6e 64  e public key and
3a60: 20 69 64 65 6e 74 69 66 69 65 73 20 74 68 65 0a   identifies the.
3a70: 09 61 6c 67 6f 72 69 74 68 6d 20 77 69 74 68 20  .algorithm with 
3a80: 77 68 69 63 68 20 74 68 65 20 6b 65 79 20 69 73  which the key is
3a90: 20 75 73 65 64 2e 20 52 46 43 20 35 32 38 30 20   used. RFC 5280 
3aa0: 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 37 20  section 4.1.2.7 
3ab0: 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30 39 5f  */.    if (X509_
3ac0: 67 65 74 5f 73 69 67 6e 61 74 75 72 65 5f 69 6e  get_signature_in
3ad0: 66 6f 28 63 65 72 74 2c 20 26 6d 64 6e 69 64 2c  fo(cert, &mdnid,
3ae0: 20 26 70 6b 6e 69 64 2c 20 26 62 69 74 73 2c 20   &pknid, &bits, 
3af0: 26 78 66 6c 61 67 73 29 29 20 7b 0a 09 41 53 4e  &xflags)) {..ASN
3b00: 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a 6b 65  1_BIT_STRING *ke
3b10: 79 3b 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e 74  y;..unsigned int
3b20: 20 6e 3b 0a 0a 09 4c 41 50 50 45 4e 44 5f 53 54   n;...LAPPEND_ST
3b30: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
3b40: 72 2c 20 22 73 69 67 6e 69 6e 67 44 69 67 65 73  r, "signingDiges
3b50: 74 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 6d  t", OBJ_nid2ln(m
3b60: 64 6e 69 64 29 2c 20 2d 31 29 3b 0a 09 4c 41 50  dnid), -1);..LAP
3b70: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
3b80: 20 63 65 72 74 50 74 72 2c 20 22 70 75 62 6c 69   certPtr, "publi
3b90: 63 4b 65 79 41 6c 67 6f 72 69 74 68 6d 22 2c 20  cKeyAlgorithm", 
3ba0: 4f 42 4a 5f 6e 69 64 32 6c 6e 28 70 6b 6e 69 64  OBJ_nid2ln(pknid
3bb0: 29 2c 20 2d 31 29 3b 0a 09 4c 41 50 50 45 4e 44  ), -1);..LAPPEND
3bc0: 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20 63 65 72  _INT(interp, cer
3bd0: 74 50 74 72 2c 20 22 62 69 74 73 22 2c 20 62 69  tPtr, "bits", bi
3be0: 74 73 29 3b 20 2f 2a 20 45 66 66 65 63 74 69 76  ts); /* Effectiv
3bf0: 65 20 73 65 63 75 72 69 74 79 20 62 69 74 73 20  e security bits 
3c00: 2a 2f 0a 0a 09 6b 65 79 20 3d 20 58 35 30 39 5f  */...key = X509_
3c10: 67 65 74 30 5f 70 75 62 6b 65 79 5f 62 69 74 73  get0_pubkey_bits
3c20: 74 72 28 63 65 72 74 29 3b 0a 09 6c 65 6e 20 3d  tr(cert);..len =
3c30: 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6b   String_to_Hex(k
3c40: 65 79 2d 3e 64 61 74 61 2c 20 6b 65 79 2d 3e 6c  ey->data, key->l
3c50: 65 6e 67 74 68 2c 20 28 75 6e 73 69 67 6e 65 64  ength, (unsigned
3c60: 20 63 68 61 72 20 2a 29 20 62 75 66 66 65 72 2c   char *) buffer,
3c70: 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45   BUFSIZ);..LAPPE
3c80: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
3c90: 65 72 74 50 74 72 2c 20 22 70 75 62 6c 69 63 4b  ertPtr, "publicK
3ca0: 65 79 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63  ey", buffer, (Tc
3cb0: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09  l_Size) len);...
3cc0: 6c 65 6e 20 3d 20 30 3b 0a 09 69 66 20 28 58 35  len = 0;..if (X5
3cd0: 30 39 5f 70 75 62 6b 65 79 5f 64 69 67 65 73 74  09_pubkey_digest
3ce0: 28 63 65 72 74 2c 20 45 56 50 5f 67 65 74 5f 64  (cert, EVP_get_d
3cf0: 69 67 65 73 74 62 79 6e 69 64 28 70 6b 6e 69 64  igestbynid(pknid
3d00: 29 2c 20 6d 64 2c 20 26 6e 29 29 20 7b 0a 09 20  ), md, &n)) {.. 
3d10: 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f     len = String_
3d20: 74 6f 5f 48 65 78 28 6d 64 2c 20 28 69 6e 74 29  to_Hex(md, (int)
3d30: 20 6e 2c 20 28 75 6e 73 69 67 6e 65 64 20 63 68   n, (unsigned ch
3d40: 61 72 20 2a 29 20 62 75 66 66 65 72 2c 20 42 55  ar *) buffer, BU
3d50: 46 53 49 5a 29 3b 0a 09 7d 0a 09 4c 41 50 50 45  FSIZ);..}..LAPPE
3d60: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
3d70: 65 72 74 50 74 72 2c 20 22 70 75 62 6c 69 63 4b  ertPtr, "publicK
3d80: 65 79 48 61 73 68 22 2c 20 62 75 66 66 65 72 2c  eyHash", buffer,
3d90: 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29   (Tcl_Size) len)
3da0: 3b 0a 0a 09 2f 2a 20 64 69 67 65 73 74 20 6f 66  ;.../* digest of
3db0: 20 74 68 65 20 44 45 52 20 72 65 70 72 65 73 65   the DER represe
3dc0: 6e 74 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 63  ntation of the c
3dd0: 65 72 74 69 66 69 63 61 74 65 20 2a 2f 0a 09 6c  ertificate */..l
3de0: 65 6e 20 3d 20 30 3b 0a 09 69 66 20 28 58 35 30  en = 0;..if (X50
3df0: 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45  9_digest(cert, E
3e00: 56 50 5f 67 65 74 5f 64 69 67 65 73 74 62 79 6e  VP_get_digestbyn
3e10: 69 64 28 6d 64 6e 69 64 29 2c 20 6d 64 2c 20 26  id(mdnid), md, &
3e20: 6e 29 29 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d  n)) {..    len =
3e30: 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d   String_to_Hex(m
3e40: 64 2c 20 28 69 6e 74 29 20 6e 2c 20 28 75 6e 73  d, (int) n, (uns
3e50: 69 67 6e 65 64 20 63 68 61 72 20 2a 29 20 62 75  igned char *) bu
3e60: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09  ffer, BUFSIZ);..
3e70: 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69  }..LAPPEND_STR(i
3e80: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
3e90: 22 73 69 67 6e 61 74 75 72 65 48 61 73 68 22 2c  "signatureHash",
3ea0: 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69   buffer, (Tcl_Si
3eb0: 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a  ze) len);.    }.
3ec0: 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63  .    /* Certific
3ed0: 61 74 65 20 50 75 72 70 6f 73 65 2e 20 43 61 6c  ate Purpose. Cal
3ee0: 6c 20 62 65 66 6f 72 65 20 63 68 65 63 6b 69 6e  l before checkin
3ef0: 67 20 66 6f 72 20 65 78 74 65 6e 73 69 6f 6e 73  g for extensions
3f00: 2e 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44  . */.    LAPPEND
3f10: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72  _STR(interp, cer
3f20: 74 50 74 72 2c 20 22 70 75 72 70 6f 73 65 22 2c  tPtr, "purpose",
3f30: 20 54 6c 73 5f 78 35 30 39 50 75 72 70 6f 73 65   Tls_x509Purpose
3f40: 28 63 65 72 74 29 2c 20 2d 31 29 3b 0a 20 20 20  (cert), -1);.   
3f50: 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74   LAPPEND_OBJ(int
3f60: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63  erp, certPtr, "c
3f70: 65 72 74 69 66 69 63 61 74 65 50 75 72 70 6f 73  ertificatePurpos
3f80: 65 22 2c 20 54 6c 73 5f 78 35 30 39 50 75 72 70  e", Tls_x509Purp
3f90: 6f 73 65 73 28 69 6e 74 65 72 70 2c 20 63 65 72  oses(interp, cer
3fa0: 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74  t));..    /* Get
3fb0: 20 65 78 74 65 6e 73 69 6f 6e 73 20 66 6c 61 67   extensions flag
3fc0: 73 20 2a 2f 0a 20 20 20 20 78 66 6c 61 67 73 20  s */.    xflags 
3fd0: 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 65 6e  = X509_get_exten
3fe0: 73 69 6f 6e 5f 66 6c 61 67 73 28 63 65 72 74 29  sion_flags(cert)
3ff0: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 49 4e  ;.    LAPPEND_IN
4000: 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  T(interp, certPt
4010: 72 2c 20 22 65 78 74 46 6c 61 67 73 22 2c 20 78  r, "extFlags", x
4020: 66 6c 61 67 73 29 3b 0a 0a 20 20 20 20 2f 2a 20  flags);..    /* 
4030: 43 68 65 63 6b 20 69 66 20 63 65 72 74 20 77 61  Check if cert wa
4040: 73 20 69 73 73 75 65 64 20 62 79 20 43 41 20 63  s issued by CA c
4050: 65 72 74 20 69 73 73 75 65 72 20 6f 72 20 73 65  ert issuer or se
4060: 6c 66 20 73 69 67 6e 65 64 20 2a 2f 0a 20 20 20  lf signed */.   
4070: 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e   LAPPEND_BOOL(in
4080: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
4090: 73 65 6c 66 49 73 73 75 65 64 22 2c 20 78 66 6c  selfIssued", xfl
40a0: 61 67 73 20 26 20 45 58 46 4c 41 47 5f 53 49 29  ags & EXFLAG_SI)
40b0: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f  ;.    LAPPEND_BO
40c0: 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  OL(interp, certP
40d0: 74 72 2c 20 22 73 65 6c 66 53 69 67 6e 65 64 22  tr, "selfSigned"
40e0: 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41  , xflags & EXFLA
40f0: 47 5f 53 53 29 3b 0a 20 20 20 20 4c 41 50 50 45  G_SS);.    LAPPE
4100: 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20  ND_BOOL(interp, 
4110: 63 65 72 74 50 74 72 2c 20 22 69 73 50 72 6f 78  certPtr, "isProx
4120: 79 43 65 72 74 22 2c 20 78 66 6c 61 67 73 20 26  yCert", xflags &
4130: 20 45 58 46 4c 41 47 5f 50 52 4f 58 59 29 3b 0a   EXFLAG_PROXY);.
4140: 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c      LAPPEND_BOOL
4150: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
4160: 2c 20 22 65 78 74 49 6e 76 61 6c 69 64 22 2c 20  , "extInvalid", 
4170: 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f  xflags & EXFLAG_
4180: 49 4e 56 41 4c 49 44 29 3b 0a 20 20 20 20 4c 41  INVALID);.    LA
4190: 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72  PPEND_BOOL(inter
41a0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 43  p, certPtr, "isC
41b0: 41 43 65 72 74 22 2c 20 58 35 30 39 5f 63 68 65  ACert", X509_che
41c0: 63 6b 5f 63 61 28 63 65 72 74 29 29 3b 0a 0a 20  ck_ca(cert));.. 
41d0: 20 20 20 2f 2a 20 54 68 65 20 55 6e 69 71 75 65     /* The Unique
41e0: 20 49 64 73 20 61 72 65 20 75 73 65 64 20 74 6f   Ids are used to
41f0: 20 68 61 6e 64 6c 65 20 74 68 65 20 70 6f 73 73   handle the poss
4200: 69 62 69 6c 69 74 79 20 6f 66 20 72 65 75 73 65  ibility of reuse
4210: 20 6f 66 20 73 75 62 6a 65 63 74 0a 09 61 6e 64   of subject..and
4220: 2f 6f 72 20 69 73 73 75 65 72 20 6e 61 6d 65 73  /or issuer names
4230: 20 6f 76 65 72 20 74 69 6d 65 2e 20 52 46 43 20   over time. RFC 
4240: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31  5280 section 4.1
4250: 2e 32 2e 38 20 2a 2f 0a 20 20 20 20 7b 0a 09 63  .2.8 */.    {..c
4260: 6f 6e 73 74 20 41 53 4e 31 5f 42 49 54 5f 53 54  onst ASN1_BIT_ST
4270: 52 49 4e 47 20 2a 69 75 69 64 2c 20 2a 73 75 69  RING *iuid, *sui
4280: 64 3b 0a 09 58 35 30 39 5f 67 65 74 30 5f 75 69  d;..X509_get0_ui
4290: 64 73 28 63 65 72 74 2c 20 26 69 75 69 64 2c 20  ds(cert, &iuid, 
42a0: 26 73 75 69 64 29 3b 0a 0a 09 54 63 6c 5f 4c 69  &suid);...Tcl_Li
42b0: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
42c0: 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  nt(interp, certP
42d0: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  tr, Tcl_NewStrin
42e0: 67 4f 62 6a 28 22 69 73 73 75 65 72 55 6e 69 71  gObj("issuerUniq
42f0: 75 65 49 64 22 2c 20 2d 31 29 29 3b 0a 09 69 66  ueId", -1));..if
4300: 20 28 69 75 69 64 20 21 3d 20 4e 55 4c 4c 29 20   (iuid != NULL) 
4310: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f  {..    Tcl_ListO
4320: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28  bjAppendElement(
4330: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
4340: 20 54 63 6c 5f 4e 65 77 42 79 74 65 41 72 72 61   Tcl_NewByteArra
4350: 79 4f 62 6a 28 28 63 6f 6e 73 74 20 75 6e 73 69  yObj((const unsi
4360: 67 6e 65 64 20 63 68 61 72 20 2a 29 69 75 69 64  gned char *)iuid
4370: 2d 3e 64 61 74 61 2c 20 28 54 63 6c 5f 53 69 7a  ->data, (Tcl_Siz
4380: 65 29 20 69 75 69 64 2d 3e 6c 65 6e 67 74 68 29  e) iuid->length)
4390: 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20  );..} else {..  
43a0: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
43b0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
43c0: 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f  p, certPtr, Tcl_
43d0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 22 2c  NewStringObj("",
43e0: 20 2d 31 29 29 3b 0a 09 7d 0a 0a 09 54 63 6c 5f   -1));..}...Tcl_
43f0: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
4400: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72  ment(interp, cer
4410: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
4420: 69 6e 67 4f 62 6a 28 22 73 75 62 6a 65 63 74 55  ingObj("subjectU
4430: 6e 69 71 75 65 49 64 22 2c 20 2d 31 29 29 3b 0a  niqueId", -1));.
4440: 09 69 66 20 28 73 75 69 64 20 21 3d 20 4e 55 4c  .if (suid != NUL
4450: 4c 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69  L) {..    Tcl_Li
4460: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
4470: 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  nt(interp, certP
4480: 74 72 2c 20 54 63 6c 5f 4e 65 77 42 79 74 65 41  tr, Tcl_NewByteA
4490: 72 72 61 79 4f 62 6a 28 28 63 6f 6e 73 74 20 75  rrayObj((const u
44a0: 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 29 73  nsigned char *)s
44b0: 75 69 64 2d 3e 64 61 74 61 2c 20 28 54 63 6c 5f  uid->data, (Tcl_
44c0: 53 69 7a 65 29 20 73 75 69 64 2d 3e 6c 65 6e 67  Size) suid->leng
44d0: 74 68 29 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a  th));..} else {.
44e0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
44f0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
4500: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54  terp, certPtr, T
4510: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
4520: 22 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 20  "", -1));..}.   
4530: 20 7d 0a 0a 20 20 20 20 2f 2a 20 58 35 30 39 20   }..    /* X509 
4540: 76 33 20 45 78 74 65 6e 73 69 6f 6e 73 20 2d 20  v3 Extensions - 
4550: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
4560: 20 34 2e 31 2e 32 2e 39 20 2a 2f 0a 20 20 20 20   4.1.2.9 */.    
4570: 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65  LAPPEND_INT(inte
4580: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78  rp, certPtr, "ex
4590: 74 43 6f 75 6e 74 22 2c 20 58 35 30 39 5f 67 65  tCount", X509_ge
45a0: 74 5f 65 78 74 5f 63 6f 75 6e 74 28 63 65 72 74  t_ext_count(cert
45b0: 29 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f  ));.    LAPPEND_
45c0: 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74  OBJ(interp, cert
45d0: 50 74 72 2c 20 22 65 78 74 65 6e 73 69 6f 6e 73  Ptr, "extensions
45e0: 22 2c 20 54 6c 73 5f 78 35 30 39 45 78 74 65 6e  ", Tls_x509Exten
45f0: 73 69 6f 6e 73 28 69 6e 74 65 72 70 2c 20 63 65  sions(interp, ce
4600: 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 41 75  rt));..    /* Au
4610: 74 68 6f 72 69 74 79 20 4b 65 79 20 49 64 65 6e  thority Key Iden
4620: 74 69 66 69 65 72 20 28 41 4b 49 29 20 69 73 20  tifier (AKI) is 
4630: 74 68 65 20 53 75 62 6a 65 63 74 20 4b 65 79 20  the Subject Key 
4640: 49 64 65 6e 74 69 66 69 65 72 20 28 53 4b 49 29  Identifier (SKI)
4650: 20 6f 66 0a 09 69 74 73 20 73 69 67 6e 65 72 20   of..its signer 
4660: 28 74 68 65 20 43 41 29 2e 20 52 46 43 20 35 32  (the CA). RFC 52
4670: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31  80 section 4.2.1
4680: 2e 31 2c 20 4e 49 44 5f 61 75 74 68 6f 72 69 74  .1, NID_authorit
4690: 79 5f 6b 65 79 5f 69 64 65 6e 74 69 66 69 65 72  y_key_identifier
46a0: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f   */.    LAPPEND_
46b0: 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74  OBJ(interp, cert
46c0: 50 74 72 2c 20 22 61 75 74 68 6f 72 69 74 79 4b  Ptr, "authorityK
46d0: 65 79 49 64 65 6e 74 69 66 69 65 72 22 2c 0a 09  eyIdentifier",..
46e0: 54 6c 73 5f 78 35 30 39 49 64 65 6e 74 69 66 69  Tls_x509Identifi
46f0: 65 72 28 58 35 30 39 5f 67 65 74 30 5f 61 75 74  er(X509_get0_aut
4700: 68 6f 72 69 74 79 5f 6b 65 79 5f 69 64 28 63 65  hority_key_id(ce
4710: 72 74 29 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 53  rt)));..    /* S
4720: 75 62 6a 65 63 74 20 4b 65 79 20 49 64 65 6e 74  ubject Key Ident
4730: 69 66 69 65 72 20 28 53 4b 49 29 20 69 73 20 75  ifier (SKI) is u
4740: 73 65 64 20 74 6f 20 69 64 65 6e 74 69 66 79 20  sed to identify 
4750: 63 65 72 74 69 66 69 63 61 74 65 73 20 74 68 61  certificates tha
4760: 74 20 63 6f 6e 74 61 69 6e 0a 09 61 20 70 61 72  t contain..a par
4770: 74 69 63 75 6c 61 72 20 70 75 62 6c 69 63 20 6b  ticular public k
4780: 65 79 2e 20 52 46 43 20 35 32 38 30 20 73 65 63  ey. RFC 5280 sec
4790: 74 69 6f 6e 20 34 2e 32 2e 31 2e 32 2c 20 4e 49  tion 4.2.1.2, NI
47a0: 44 5f 73 75 62 6a 65 63 74 5f 6b 65 79 5f 69 64  D_subject_key_id
47b0: 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20 20 20  entifier */.    
47c0: 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65  LAPPEND_OBJ(inte
47d0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 75  rp, certPtr, "su
47e0: 62 6a 65 63 74 4b 65 79 49 64 65 6e 74 69 66 69  bjectKeyIdentifi
47f0: 65 72 22 2c 0a 09 54 6c 73 5f 78 35 30 39 49 64  er",..Tls_x509Id
4800: 65 6e 74 69 66 69 65 72 28 58 35 30 39 5f 67 65  entifier(X509_ge
4810: 74 30 5f 73 75 62 6a 65 63 74 5f 6b 65 79 5f 69  t0_subject_key_i
4820: 64 28 63 65 72 74 29 29 29 3b 0a 0a 20 20 20 20  d(cert)));..    
4830: 2f 2a 20 4b 65 79 20 75 73 61 67 65 20 65 78 74  /* Key usage ext
4840: 65 6e 73 69 6f 6e 20 64 65 66 69 6e 65 73 20 74  ension defines t
4850: 68 65 20 70 75 72 70 6f 73 65 20 28 65 2e 67 2e  he purpose (e.g.
4860: 2c 20 65 6e 63 69 70 68 65 72 6d 65 6e 74 2c 20  , encipherment, 
4870: 73 69 67 6e 61 74 75 72 65 2c 20 63 65 72 74 69  signature, certi
4880: 66 69 63 61 74 65 0a 09 73 69 67 6e 69 6e 67 29  ficate..signing)
4890: 20 6f 66 20 74 68 65 20 6b 65 79 20 69 6e 20 74   of the key in t
48a0: 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20  he certificate. 
48b0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
48c0: 20 34 2e 32 2e 31 2e 33 2c 20 4e 49 44 5f 6b 65   4.2.1.3, NID_ke
48d0: 79 5f 75 73 61 67 65 20 2a 2f 0a 20 20 20 20 4c  y_usage */.    L
48e0: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72  APPEND_OBJ(inter
48f0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 6b 65 79  p, certPtr, "key
4900: 55 73 61 67 65 22 2c 20 54 6c 73 5f 78 35 30 39  Usage", Tls_x509
4910: 4b 65 79 55 73 61 67 65 28 69 6e 74 65 72 70 2c  KeyUsage(interp,
4920: 20 63 65 72 74 2c 20 78 66 6c 61 67 73 29 29 3b   cert, xflags));
4930: 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69  ..    /* Certifi
4940: 63 61 74 65 20 50 6f 6c 69 63 69 65 73 20 2d 20  cate Policies - 
4950: 69 6e 64 69 63 61 74 65 73 20 74 68 65 20 69 73  indicates the is
4960: 73 75 69 6e 67 20 43 41 20 63 6f 6e 73 69 64 65  suing CA conside
4970: 72 73 20 69 74 73 20 69 73 73 75 65 72 44 6f 6d  rs its issuerDom
4980: 61 69 6e 50 6f 6c 69 63 79 0a 09 65 71 75 69 76  ainPolicy..equiv
4990: 61 6c 65 6e 74 20 74 6f 20 74 68 65 20 73 75 62  alent to the sub
49a0: 6a 65 63 74 20 43 41 27 73 20 73 75 62 6a 65 63  ject CA's subjec
49b0: 74 44 6f 6d 61 69 6e 50 6f 6c 69 63 79 2e 20 52  tDomainPolicy. R
49c0: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
49d0: 34 2e 32 2e 31 2e 34 2c 20 4e 49 44 5f 63 65 72  4.2.1.4, NID_cer
49e0: 74 69 66 69 63 61 74 65 5f 70 6f 6c 69 63 69 65  tificate_policie
49f0: 73 20 2a 2f 0a 20 20 20 20 69 66 20 28 78 66 6c  s */.    if (xfl
4a00: 61 67 73 20 26 20 45 58 46 4c 41 47 5f 49 4e 56  ags & EXFLAG_INV
4a10: 41 4c 49 44 5f 50 4f 4c 49 43 59 29 20 7b 0a 09  ALID_POLICY) {..
4a20: 2f 2a 20 52 65 6a 65 63 74 20 63 65 72 74 20 2a  /* Reject cert *
4a30: 2f 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20  /.    }..    /* 
4a40: 50 6f 6c 69 63 79 20 4d 61 70 70 69 6e 67 73 20  Policy Mappings 
4a50: 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  - RFC 5280 secti
4a60: 6f 6e 20 34 2e 32 2e 31 2e 35 2c 20 4e 49 44 5f  on 4.2.1.5, NID_
4a70: 70 6f 6c 69 63 79 5f 6d 61 70 70 69 6e 67 73 20  policy_mappings 
4a80: 2a 2f 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65  */..    /* Subje
4a90: 63 74 20 41 6c 74 65 72 6e 61 74 69 76 65 20 4e  ct Alternative N
4aa0: 61 6d 65 20 28 53 41 4e 29 20 63 6f 6e 74 61 69  ame (SAN) contai
4ab0: 6e 73 20 61 64 64 69 74 69 6f 6e 61 6c 20 55 52  ns additional UR
4ac0: 4c 73 2c 20 44 4e 53 20 6e 61 6d 65 73 2c 20 6f  Ls, DNS names, o
4ad0: 72 20 49 50 0a 09 61 64 64 72 65 73 73 65 73 20  r IP..addresses 
4ae0: 62 6f 75 6e 64 20 74 6f 20 63 65 72 74 69 66 69  bound to certifi
4af0: 63 61 74 65 2e 20 52 46 43 20 35 32 38 30 20 73  cate. RFC 5280 s
4b00: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 36 2c 20  ection 4.2.1.6, 
4b10: 4e 49 44 5f 73 75 62 6a 65 63 74 5f 61 6c 74 5f  NID_subject_alt_
4b20: 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 4c 41 50 50  name */.    LAPP
4b30: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20  END_OBJ(interp, 
4b40: 63 65 72 74 50 74 72 2c 20 22 73 75 62 6a 65 63  certPtr, "subjec
4b50: 74 41 6c 74 4e 61 6d 65 22 2c 20 54 6c 73 5f 78  tAltName", Tls_x
4b60: 35 30 39 4e 61 6d 65 73 28 69 6e 74 65 72 70 2c  509Names(interp,
4b70: 20 63 65 72 74 2c 20 4e 49 44 5f 73 75 62 6a 65   cert, NID_subje
4b80: 63 74 5f 61 6c 74 5f 6e 61 6d 65 2c 20 62 69 6f  ct_alt_name, bio
4b90: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 49 73 73 75  ));..    /* Issu
4ba0: 65 72 20 41 6c 74 65 72 6e 61 74 69 76 65 20 4e  er Alternative N
4bb0: 61 6d 65 20 69 73 20 75 73 65 64 20 74 6f 20 61  ame is used to a
4bc0: 73 73 6f 63 69 61 74 65 20 49 6e 74 65 72 6e 65  ssociate Interne
4bd0: 74 20 73 74 79 6c 65 20 69 64 65 6e 74 69 74 69  t style identiti
4be0: 65 73 0a 09 77 69 74 68 20 74 68 65 20 63 65 72  es..with the cer
4bf0: 74 69 66 69 63 61 74 65 20 69 73 73 75 65 72 2e  tificate issuer.
4c00: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
4c10: 6e 20 34 2e 32 2e 31 2e 37 2c 20 4e 49 44 5f 69  n 4.2.1.7, NID_i
4c20: 73 73 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 20 2a  ssuer_alt_name *
4c30: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42  /.    LAPPEND_OB
4c40: 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  J(interp, certPt
4c50: 72 2c 20 22 69 73 73 75 65 72 41 6c 74 4e 61 6d  r, "issuerAltNam
4c60: 65 22 2c 20 54 6c 73 5f 78 35 30 39 4e 61 6d 65  e", Tls_x509Name
4c70: 73 28 69 6e 74 65 72 70 2c 20 63 65 72 74 2c 20  s(interp, cert, 
4c80: 4e 49 44 5f 69 73 73 75 65 72 5f 61 6c 74 5f 6e  NID_issuer_alt_n
4c90: 61 6d 65 2c 20 62 69 6f 29 29 3b 0a 0a 20 20 20  ame, bio));..   
4ca0: 20 2f 2a 20 53 75 62 6a 65 63 74 20 44 69 72 65   /* Subject Dire
4cb0: 63 74 6f 72 79 20 41 74 74 72 69 62 75 74 65 73  ctory Attributes
4cc0: 20 70 72 6f 76 69 64 65 73 20 69 64 65 6e 74 69   provides identi
4cd0: 66 69 63 61 74 69 6f 6e 20 61 74 74 72 69 62 75  fication attribu
4ce0: 74 65 73 20 28 65 2e 67 2e 2c 20 6e 61 74 69 6f  tes (e.g., natio
4cf0: 6e 61 6c 69 74 79 29 0a 09 6f 66 20 74 68 65 20  nality)..of the 
4d00: 73 75 62 6a 65 63 74 2e 20 52 46 43 20 35 32 38  subject. RFC 528
4d10: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e  0 section 4.2.1.
4d20: 38 20 28 73 75 62 6a 65 63 74 44 69 72 65 63 74  8 (subjectDirect
4d30: 6f 72 79 41 74 74 72 69 62 75 74 65 73 29 20 2a  oryAttributes) *
4d40: 2f 0a 0a 20 20 20 20 2f 2a 20 42 61 73 69 63 20  /..    /* Basic 
4d50: 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 64 65 6e  Constraints iden
4d60: 74 69 66 69 65 73 20 77 68 65 74 68 65 72 20 74  tifies whether t
4d70: 68 65 20 73 75 62 6a 65 63 74 20 6f 66 20 74 68  he subject of th
4d80: 65 20 63 65 72 74 20 69 73 20 61 20 43 41 20 61  e cert is a CA a
4d90: 6e 64 0a 09 74 68 65 20 6d 61 78 20 64 65 70 74  nd..the max dept
4da0: 68 20 6f 66 20 76 61 6c 69 64 20 63 65 72 74 20  h of valid cert 
4db0: 70 61 74 68 73 20 66 6f 72 20 74 68 69 73 20 63  paths for this c
4dc0: 65 72 74 2e 20 52 46 43 20 35 32 38 30 20 73 65  ert. RFC 5280 se
4dd0: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 39 2c 20 4e  ction 4.2.1.9, N
4de0: 49 44 5f 62 61 73 69 63 5f 63 6f 6e 73 74 72 61  ID_basic_constra
4df0: 69 6e 74 73 20 2a 2f 0a 20 20 20 20 69 66 20 28  ints */.    if (
4e00: 21 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41  !(xflags & EXFLA
4e10: 47 5f 50 52 4f 58 59 29 29 20 7b 0a 09 4c 41 50  G_PROXY)) {..LAP
4e20: 50 45 4e 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70  PEND_LONG(interp
4e30: 2c 20 63 65 72 74 50 74 72 2c 20 22 70 61 74 68  , certPtr, "path
4e40: 4c 65 6e 22 2c 20 58 35 30 39 5f 67 65 74 5f 70  Len", X509_get_p
4e50: 61 74 68 6c 65 6e 28 63 65 72 74 29 29 3b 0a 20  athlen(cert));. 
4e60: 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 4c 41 50     } else {..LAP
4e70: 50 45 4e 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70  PEND_LONG(interp
4e80: 2c 20 63 65 72 74 50 74 72 2c 20 22 70 61 74 68  , certPtr, "path
4e90: 4c 65 6e 22 2c 20 58 35 30 39 5f 67 65 74 5f 70  Len", X509_get_p
4ea0: 72 6f 78 79 5f 70 61 74 68 6c 65 6e 28 63 65 72  roxy_pathlen(cer
4eb0: 74 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 4c  t));.    }.    L
4ec0: 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65  APPEND_BOOL(inte
4ed0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 62 61  rp, certPtr, "ba
4ee0: 73 69 63 43 6f 6e 73 74 72 61 69 6e 74 73 43 41  sicConstraintsCA
4ef0: 22 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c  ", xflags & EXFL
4f00: 41 47 5f 43 41 29 3b 0a 0a 20 20 20 20 2f 2a 20  AG_CA);..    /* 
4f10: 4e 61 6d 65 20 43 6f 6e 73 74 72 61 69 6e 74 73  Name Constraints
4f20: 20 69 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e   is only used in
4f30: 20 43 41 20 63 65 72 74 73 20 74 6f 20 69 6e 64   CA certs to ind
4f40: 69 63 61 74 65 20 74 68 65 20 6e 61 6d 65 20 73  icate the name s
4f50: 70 61 63 65 20 66 6f 72 0a 09 61 6c 6c 20 73 75  pace for..all su
4f60: 62 6a 65 63 74 20 6e 61 6d 65 73 20 69 6e 20 73  bject names in s
4f70: 75 62 73 65 71 75 65 6e 74 20 63 65 72 74 69 66  ubsequent certif
4f80: 69 63 61 74 65 73 20 69 6e 20 61 20 63 65 72 74  icates in a cert
4f90: 69 66 69 63 61 74 69 6f 6e 20 70 61 74 68 0a 09  ification path..
4fa0: 4d 55 53 54 20 62 65 20 6c 6f 63 61 74 65 64 2e  MUST be located.
4fb0: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
4fc0: 6e 20 34 2e 32 2e 31 2e 31 30 2c 20 4e 49 44 5f  n 4.2.1.10, NID_
4fd0: 6e 61 6d 65 5f 63 6f 6e 73 74 72 61 69 6e 74 73  name_constraints
4fe0: 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c 69   */..    /* Poli
4ff0: 63 79 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69  cy Constraints i
5000: 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 43  s only used in C
5010: 41 20 63 65 72 74 73 20 74 6f 20 6c 69 6d 69 74  A certs to limit
5020: 20 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 61   the length of a
5030: 0a 09 63 65 72 74 20 63 68 61 69 6e 20 66 6f 72  ..cert chain for
5040: 20 74 68 61 74 20 43 41 2e 20 52 46 43 20 35 32   that CA. RFC 52
5050: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31  80 section 4.2.1
5060: 2e 31 31 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 5f  .11, NID_policy_
5070: 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 0a  constraints */..
5080: 20 20 20 20 2f 2a 20 45 78 74 65 6e 64 65 64 20      /* Extended 
5090: 4b 65 79 20 55 73 61 67 65 20 69 6e 64 69 63 61  Key Usage indica
50a0: 74 65 73 20 74 68 65 20 70 75 72 70 6f 73 65 73  tes the purposes
50b0: 20 74 68 65 20 63 65 72 74 69 66 69 65 64 20 70   the certified p
50c0: 75 62 6c 69 63 20 6b 65 79 20 6d 61 79 20 62 65  ublic key may be
50d0: 0a 09 75 73 65 64 2c 20 62 65 79 6f 6e 64 20 74  ..used, beyond t
50e0: 68 65 20 62 61 73 69 63 20 70 75 72 70 6f 73 65  he basic purpose
50f0: 73 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74  s. RFC 5280 sect
5100: 69 6f 6e 20 34 2e 32 2e 31 2e 31 32 2c 20 4e 49  ion 4.2.1.12, NI
5110: 44 5f 65 78 74 5f 6b 65 79 5f 75 73 61 67 65 20  D_ext_key_usage 
5120: 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f  */.    LAPPEND_O
5130: 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  BJ(interp, certP
5140: 74 72 2c 20 22 65 78 74 65 6e 64 65 64 4b 65 79  tr, "extendedKey
5150: 55 73 61 67 65 22 2c 20 54 6c 73 5f 78 35 30 39  Usage", Tls_x509
5160: 45 78 74 4b 65 79 55 73 61 67 65 28 69 6e 74 65  ExtKeyUsage(inte
5170: 72 70 2c 20 63 65 72 74 2c 20 78 66 6c 61 67 73  rp, cert, xflags
5180: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 52 4c 20  ));..    /* CRL 
5190: 44 69 73 74 72 69 62 75 74 69 6f 6e 20 50 6f 69  Distribution Poi
51a0: 6e 74 73 20 69 64 65 6e 74 69 66 69 65 73 20 77  nts identifies w
51b0: 68 65 72 65 20 43 52 4c 20 69 6e 66 6f 72 6d 61  here CRL informa
51c0: 74 69 6f 6e 20 63 61 6e 20 62 65 20 6f 62 74 61  tion can be obta
51d0: 69 6e 65 64 2e 0a 09 52 46 43 20 35 32 38 30 20  ined...RFC 5280 
51e0: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 33  section 4.2.1.13
51f0: 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f  */.    LAPPEND_O
5200: 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  BJ(interp, certP
5210: 74 72 2c 20 22 63 72 6c 44 69 73 74 72 69 62 75  tr, "crlDistribu
5220: 74 69 6f 6e 50 6f 69 6e 74 73 22 2c 20 54 6c 73  tionPoints", Tls
5230: 5f 78 35 30 39 43 72 6c 44 70 28 69 6e 74 65 72  _x509CrlDp(inter
5240: 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20  p, cert));..    
5250: 2f 2a 20 46 72 65 73 68 65 73 74 20 43 52 4c 20  /* Freshest CRL 
5260: 65 78 74 65 6e 73 69 6f 6e 20 2a 2f 0a 20 20 20  extension */.   
5270: 20 69 66 20 28 78 66 6c 61 67 73 20 26 20 45 58   if (xflags & EX
5280: 46 4c 41 47 5f 46 52 45 53 48 45 53 54 29 20 7b  FLAG_FRESHEST) {
5290: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 41  .    }..    /* A
52a0: 75 74 68 6f 72 69 74 79 20 49 6e 66 6f 72 6d 61  uthority Informa
52b0: 74 69 6f 6e 20 41 63 63 65 73 73 20 69 6e 64 69  tion Access indi
52c0: 63 61 74 65 73 20 68 6f 77 20 74 6f 20 61 63 63  cates how to acc
52d0: 65 73 73 20 69 6e 66 6f 20 61 6e 64 20 73 65 72  ess info and ser
52e0: 76 69 63 65 73 0a 09 66 6f 72 20 74 68 65 20 63  vices..for the c
52f0: 65 72 74 69 66 69 63 61 74 65 20 69 73 73 75 65  ertificate issue
5300: 72 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74  r. RFC 5280 sect
5310: 69 6f 6e 20 34 2e 32 2e 32 2e 31 2c 20 4e 49 44  ion 4.2.2.1, NID
5320: 5f 69 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a  _info_access */.
5330: 0a 20 20 20 20 2f 2a 20 47 65 74 20 4f 6e 2d 6c  .    /* Get On-l
5340: 69 6e 65 20 43 65 72 74 69 66 69 63 61 74 65 20  ine Certificate 
5350: 53 74 61 74 75 73 20 50 72 6f 74 6f 63 6f 6c 20  Status Protocol 
5360: 28 4f 53 43 50 29 20 52 65 73 70 6f 6e 64 65 72  (OSCP) Responder
5370: 73 20 55 52 4c 20 2a 2f 0a 20 20 20 20 4c 41 50  s URL */.    LAP
5380: 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c  PEND_OBJ(interp,
5390: 20 63 65 72 74 50 74 72 2c 20 22 6f 63 73 70 52   certPtr, "ocspR
53a0: 65 73 70 6f 6e 64 65 72 73 22 2c 20 54 6c 73 5f  esponders", Tls_
53b0: 78 35 30 39 4f 73 63 70 28 69 6e 74 65 72 70 2c  x509Oscp(interp,
53c0: 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a   cert));..    /*
53d0: 20 47 65 74 20 43 65 72 74 69 66 69 63 61 74 65   Get Certificate
53e0: 20 41 75 74 68 6f 72 69 74 79 20 28 43 41 29 20   Authority (CA) 
53f0: 49 73 73 75 65 72 73 20 55 52 4c 20 2a 2f 0a 20  Issuers URL */. 
5400: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69     LAPPEND_OBJ(i
5410: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
5420: 22 63 61 49 73 73 75 65 72 73 22 2c 20 54 6c 73  "caIssuers", Tls
5430: 5f 78 35 30 39 43 61 49 73 73 75 65 72 73 28 69  _x509CaIssuers(i
5440: 6e 74 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a  nterp, cert));..
5450: 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 49      /* Subject I
5460: 6e 66 6f 72 6d 61 74 69 6f 6e 20 41 63 63 65 73  nformation Acces
5470: 73 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63  s - RFC 5280 sec
5480: 74 69 6f 6e 20 34 2e 32 2e 32 2e 32 2c 20 4e 49  tion 4.2.2.2, NI
5490: 44 5f 73 69 6e 66 6f 5f 61 63 63 65 73 73 20 2a  D_sinfo_access *
54a0: 2f 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66  /..    /* Certif
54b0: 69 63 61 74 65 20 41 6c 69 61 73 2e 20 49 66 20  icate Alias. If 
54c0: 75 73 65 73 20 61 20 50 4b 43 53 23 31 32 20 73  uses a PKCS#12 s
54d0: 74 72 75 63 74 75 72 65 2c 20 61 6c 69 61 73 20  tructure, alias 
54e0: 77 69 6c 6c 20 72 65 66 6c 65 63 74 20 74 68 65  will reflect the
54f0: 0a 09 66 72 69 65 6e 64 6c 79 4e 61 6d 65 20 61  ..friendlyName a
5500: 74 74 72 69 62 75 74 65 20 28 52 46 43 20 32 39  ttribute (RFC 29
5510: 38 35 29 2e 20 2a 2f 0a 20 20 20 20 7b 0a 09 6c  85). */.    {..l
5520: 65 6e 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20  en = 0;.        
5530: 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 73  unsigned char *s
5540: 74 72 69 6e 67 20 3d 20 58 35 30 39 5f 61 6c 69  tring = X509_ali
5550: 61 73 5f 67 65 74 30 28 63 65 72 74 2c 20 26 6c  as_get0(cert, &l
5560: 65 6e 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54  en);..LAPPEND_ST
5570: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
5580: 72 2c 20 22 61 6c 69 61 73 22 2c 20 28 63 68 61  r, "alias", (cha
5590: 72 20 2a 29 20 73 74 72 69 6e 67 2c 20 28 54 63  r *) string, (Tc
55a0: 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 09 73  l_Size) len);..s
55b0: 74 72 69 6e 67 20 3d 20 58 35 30 39 5f 6b 65 79  tring = X509_key
55c0: 69 64 5f 67 65 74 30 20 28 63 65 72 74 2c 20 26  id_get0 (cert, &
55d0: 6c 65 6e 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53  len);..LAPPEND_S
55e0: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  TR(interp, certP
55f0: 74 72 2c 20 22 6b 65 79 49 64 22 2c 20 28 63 68  tr, "keyId", (ch
5600: 61 72 20 2a 29 20 73 74 72 69 6e 67 2c 20 28 54  ar *) string, (T
5610: 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20  cl_Size) len);. 
5620: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 43 65 72     }..    /* Cer
5630: 74 69 66 69 63 61 74 65 20 61 6e 64 20 64 75 6d  tificate and dum
5640: 70 20 61 6c 6c 20 64 61 74 61 20 2a 2f 0a 20 20  p all data */.  
5650: 20 20 7b 0a 09 63 68 61 72 20 63 65 72 74 53 74    {..char certSt
5660: 72 5b 43 45 52 54 5f 53 54 52 5f 53 49 5a 45 5d  r[CERT_STR_SIZE]
5670: 3b 0a 0a 09 2f 2a 20 47 65 74 20 63 65 72 74 69  ;.../* Get certi
5680: 66 69 63 61 74 65 20 2a 2f 0a 09 6c 65 6e 20 3d  ficate */..len =
5690: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 50   BIO_to_Buffer(P
56a0: 45 4d 5f 77 72 69 74 65 5f 62 69 6f 5f 58 35 30  EM_write_bio_X50
56b0: 39 28 62 69 6f 2c 20 63 65 72 74 29 2c 20 62 69  9(bio, cert), bi
56c0: 6f 2c 20 63 65 72 74 53 74 72 2c 20 43 45 52 54  o, certStr, CERT
56d0: 5f 53 54 52 5f 53 49 5a 45 29 3b 0a 09 4c 41 50  _STR_SIZE);..LAP
56e0: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
56f0: 20 63 65 72 74 50 74 72 2c 20 22 63 65 72 74 69   certPtr, "certi
5700: 66 69 63 61 74 65 22 2c 20 63 65 72 74 53 74 72  ficate", certStr
5710: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e  , (Tcl_Size) len
5720: 29 3b 0a 0a 09 2f 2a 20 47 65 74 20 61 6c 6c 20  );.../* Get all 
5730: 63 65 72 74 20 69 6e 66 6f 20 2a 2f 0a 09 6c 65  cert info */..le
5740: 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65  n = BIO_to_Buffe
5750: 72 28 58 35 30 39 5f 70 72 69 6e 74 5f 65 78 28  r(X509_print_ex(
5760: 62 69 6f 2c 20 63 65 72 74 2c 20 66 6c 61 67 73  bio, cert, flags
5770: 2c 20 30 29 2c 20 62 69 6f 2c 20 63 65 72 74 53  , 0), bio, certS
5780: 74 72 2c 20 43 45 52 54 5f 53 54 52 5f 53 49 5a  tr, CERT_STR_SIZ
5790: 45 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52  E);..LAPPEND_STR
57a0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
57b0: 2c 20 22 61 6c 6c 22 2c 20 63 65 72 74 53 74 72  , "all", certStr
57c0: 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e  , (Tcl_Size) len
57d0: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 42 49  );.    }..    BI
57e0: 4f 5f 66 72 65 65 28 62 69 6f 29 3b 0a 20 20 20  O_free(bio);.   
57f0: 20 72 65 74 75 72 6e 20 63 65 72 74 50 74 72 3b   return certPtr;
5800: 0a 7d 0a                                         .}.