Hex Artifact Content

Artifact c5b889a2d5f346d9630ad4362b16e97483b04378d7410ab423a9ed311ae64f17:


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 2f 2a 20 43 6f 6d 6d 6f 6e 20 6d 61  68../* Common ma
01d0: 63 72 6f 73 20 2a 2f 0a 23 64 65 66 69 6e 65 20  cros */.#define 
01e0: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
01f0: 72 70 2c 20 6f 62 6a 2c 20 74 65 78 74 2c 20 76  rp, obj, text, v
0200: 61 6c 75 65 2c 20 73 69 7a 65 29 20 7b 5c 0a 20  alue, size) {\. 
0210: 20 20 20 69 66 20 28 74 65 78 74 20 21 3d 20 4e     if (text != N
0220: 55 4c 4c 29 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  ULL) Tcl_ListObj
0230: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
0240: 74 65 72 70 2c 20 6f 62 6a 2c 20 54 63 6c 5f 4e  terp, obj, Tcl_N
0250: 65 77 53 74 72 69 6e 67 4f 62 6a 28 74 65 78 74  ewStringObj(text
0260: 2c 20 2d 31 29 29 3b 20 5c 0a 20 20 20 20 54 63  , -1)); \.    Tc
0270: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
0280: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6f  lement(interp, o
0290: 62 6a 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  bj, Tcl_NewStrin
02a0: 67 4f 62 6a 28 76 61 6c 75 65 2c 20 73 69 7a 65  gObj(value, size
02b0: 29 29 3b 20 5c 0a 7d 0a 23 64 65 66 69 6e 65 20  )); \.}.#define 
02c0: 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65  LAPPEND_INT(inte
02d0: 72 70 2c 20 6f 62 6a 2c 20 74 65 78 74 2c 20 76  rp, obj, text, v
02e0: 61 6c 75 65 29 20 7b 5c 0a 20 20 20 20 69 66 20  alue) {\.    if 
02f0: 28 74 65 78 74 20 21 3d 20 4e 55 4c 4c 29 20 54  (text != NULL) T
0300: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
0310: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20  Element(interp, 
0320: 6f 62 6a 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  obj, Tcl_NewStri
0330: 6e 67 4f 62 6a 28 74 65 78 74 2c 20 2d 31 29 29  ngObj(text, -1))
0340: 3b 20 5c 0a 20 20 20 20 54 63 6c 5f 4c 69 73 74  ; \.    Tcl_List
0350: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
0360: 28 69 6e 74 65 72 70 2c 20 6f 62 6a 2c 20 54 63  (interp, obj, Tc
0370: 6c 5f 4e 65 77 49 6e 74 4f 62 6a 28 76 61 6c 75  l_NewIntObj(valu
0380: 65 29 29 3b 20 5c 0a 7d 0a 23 64 65 66 69 6e 65  e)); \.}.#define
0390: 20 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 28 69 6e   LAPPEND_LONG(in
03a0: 74 65 72 70 2c 20 6f 62 6a 2c 20 74 65 78 74 2c  terp, obj, text,
03b0: 20 76 61 6c 75 65 29 20 7b 5c 0a 20 20 20 20 69   value) {\.    i
03c0: 66 20 28 74 65 78 74 20 21 3d 20 4e 55 4c 4c 29  f (text != NULL)
03d0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
03e0: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
03f0: 2c 20 6f 62 6a 2c 20 54 63 6c 5f 4e 65 77 53 74  , obj, Tcl_NewSt
0400: 72 69 6e 67 4f 62 6a 28 74 65 78 74 2c 20 2d 31  ringObj(text, -1
0410: 29 29 3b 20 5c 0a 20 20 20 20 54 63 6c 5f 4c 69  )); \.    Tcl_Li
0420: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
0430: 6e 74 28 69 6e 74 65 72 70 2c 20 6f 62 6a 2c 20  nt(interp, obj, 
0440: 54 63 6c 5f 4e 65 77 4c 6f 6e 67 4f 62 6a 28 76  Tcl_NewLongObj(v
0450: 61 6c 75 65 29 29 3b 20 5c 0a 7d 0a 23 64 65 66  alue)); \.}.#def
0460: 69 6e 65 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c  ine LAPPEND_BOOL
0470: 28 69 6e 74 65 72 70 2c 20 6f 62 6a 2c 20 74 65  (interp, obj, te
0480: 78 74 2c 20 76 61 6c 75 65 29 20 7b 5c 0a 20 20  xt, value) {\.  
0490: 20 20 69 66 20 28 74 65 78 74 20 21 3d 20 4e 55    if (text != NU
04a0: 4c 4c 29 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41  LL) Tcl_ListObjA
04b0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
04c0: 65 72 70 2c 20 6f 62 6a 2c 20 54 63 6c 5f 4e 65  erp, obj, Tcl_Ne
04d0: 77 53 74 72 69 6e 67 4f 62 6a 28 74 65 78 74 2c  wStringObj(text,
04e0: 20 2d 31 29 29 3b 20 5c 0a 20 20 20 20 54 63 6c   -1)); \.    Tcl
04f0: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
0500: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6f 62  ement(interp, ob
0510: 6a 2c 20 54 63 6c 5f 4e 65 77 42 6f 6f 6c 65 61  j, Tcl_NewBoolea
0520: 6e 4f 62 6a 28 76 61 6c 75 65 29 29 3b 20 5c 0a  nObj(value)); \.
0530: 7d 0a 23 64 65 66 69 6e 65 20 4c 41 50 50 45 4e  }.#define LAPPEN
0540: 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 6f 62  D_OBJ(interp, ob
0550: 6a 2c 20 74 65 78 74 2c 20 6c 69 73 74 4f 62 6a  j, text, listObj
0560: 29 20 7b 5c 0a 20 20 20 20 69 66 20 28 74 65 78  ) {\.    if (tex
0570: 74 20 21 3d 20 4e 55 4c 4c 29 20 54 63 6c 5f 4c  t != NULL) Tcl_L
0580: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
0590: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6f 62 6a 2c  ent(interp, obj,
05a0: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62   Tcl_NewStringOb
05b0: 6a 28 74 65 78 74 2c 20 2d 31 29 29 3b 20 5c 0a  j(text, -1)); \.
05c0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
05d0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
05e0: 65 72 70 2c 20 6f 62 6a 2c 20 6c 69 73 74 4f 62  erp, obj, listOb
05f0: 6a 29 3b 20 5c 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20  j); \.}.../*. * 
0600: 42 69 6e 61 72 79 20 73 74 72 69 6e 67 20 74 6f  Binary string to
0610: 20 68 65 78 20 73 74 72 69 6e 67 0a 20 2a 2f 0a   hex string. */.
0620: 69 6e 74 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65  int String_to_He
0630: 78 28 63 68 61 72 2a 20 69 6e 70 75 74 2c 20 69  x(char* input, i
0640: 6e 74 20 69 6c 65 6e 2c 20 63 68 61 72 20 2a 6f  nt ilen, char *o
0650: 75 74 70 75 74 2c 20 69 6e 74 20 6f 6c 65 6e 29  utput, int olen)
0660: 20 7b 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e 74   {.    int count
0670: 20 3d 20 30 3b 0a 0a 20 20 20 20 66 6f 72 20 28   = 0;..    for (
0680: 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 69  int i = 0; i < i
0690: 6c 65 6e 20 26 26 20 63 6f 75 6e 74 20 3c 20 6f  len && count < o
06a0: 6c 65 6e 20 2d 20 31 3b 20 69 2b 2b 2c 20 63 6f  len - 1; i++, co
06b0: 75 6e 74 20 2b 3d 20 32 29 20 7b 0a 09 73 70 72  unt += 2) {..spr
06c0: 69 6e 74 66 28 6f 75 74 70 75 74 20 2b 20 63 6f  intf(output + co
06d0: 75 6e 74 2c 20 22 25 30 32 58 22 2c 20 69 6e 70  unt, "%02X", inp
06e0: 75 74 5b 69 5d 20 26 20 30 78 66 66 29 3b 0a 20  ut[i] & 0xff);. 
06f0: 20 20 20 7d 0a 20 20 20 20 6f 75 74 70 75 74 5b     }.    output[
0700: 63 6f 75 6e 74 5d 20 3d 20 30 3b 0a 20 20 20 20  count] = 0;.    
0710: 72 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 7d 0a  return count;.}.
0720: 0a 2f 2a 0a 20 2a 20 42 49 4f 20 74 6f 20 42 75  ./*. * BIO to Bu
0730: 66 66 65 72 0a 20 2a 2f 0a 69 6e 74 20 42 49 4f  ffer. */.int BIO
0740: 5f 74 6f 5f 42 75 66 66 65 72 28 69 6e 74 20 72  _to_Buffer(int r
0750: 65 73 75 6c 74 2c 20 42 49 4f 20 2a 62 69 6f 2c  esult, BIO *bio,
0760: 20 76 6f 69 64 20 2a 62 75 66 66 65 72 2c 20 69   void *buffer, i
0770: 6e 74 20 73 69 7a 65 29 20 7b 0a 20 20 20 20 69  nt size) {.    i
0780: 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20 20  nt len = 0;.    
0790: 69 6e 74 20 70 65 6e 64 69 6e 67 20 3d 20 42 49  int pending = BI
07a0: 4f 5f 70 65 6e 64 69 6e 67 28 62 69 6f 29 3b 0a  O_pending(bio);.
07b0: 0a 20 20 20 20 69 66 20 28 72 65 73 75 6c 74 29  .    if (result)
07c0: 20 7b 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 72 65   {..len = BIO_re
07d0: 61 64 28 62 69 6f 2c 20 62 75 66 66 65 72 2c 20  ad(bio, buffer, 
07e0: 28 70 65 6e 64 69 6e 67 20 3c 20 73 69 7a 65 29  (pending < size)
07f0: 20 3f 20 70 65 6e 64 69 6e 67 20 3a 20 73 69 7a   ? pending : siz
0800: 65 29 3b 0a 09 28 76 6f 69 64 29 42 49 4f 5f 66  e);..(void)BIO_f
0810: 6c 75 73 68 28 62 69 6f 29 3b 0a 09 69 66 20 28  lush(bio);..if (
0820: 6c 65 6e 20 3c 20 30 29 20 7b 0a 09 20 20 20 20  len < 0) {..    
0830: 6c 65 6e 20 3d 20 30 3b 0a 09 7d 0a 20 20 20 20  len = 0;..}.    
0840: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 65 6e  }.    return len
0850: 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 47 65 74 20  ;.}.../*. * Get 
0860: 58 35 30 39 20 43 65 72 74 69 66 69 63 61 74 65  X509 Certificate
0870: 20 45 78 74 65 6e 73 69 6f 6e 73 0a 20 2a 2f 0a   Extensions. */.
0880: 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30  Tcl_Obj *Tls_x50
0890: 39 45 78 74 65 6e 73 69 6f 6e 73 28 54 63 6c 5f  9Extensions(Tcl_
08a0: 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20  Interp *interp, 
08b0: 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20  X509 *cert) {.  
08c0: 20 20 63 6f 6e 73 74 20 53 54 41 43 4b 5f 4f 46    const STACK_OF
08d0: 28 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 29  (X509_EXTENSION)
08e0: 20 2a 65 78 74 73 3b 0a 20 20 20 20 54 63 6c 5f   *exts;.    Tcl_
08f0: 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54  Obj *listPtr = T
0900: 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c  cl_NewListObj(0,
0910: 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20   NULL);..    if 
0920: 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c  (listPtr == NULL
0930: 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c  ) {..return NULL
0940: 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20  ;.    }..    if 
0950: 28 65 78 74 73 20 3d 20 58 35 30 39 5f 67 65 74  (exts = X509_get
0960: 30 5f 65 78 74 65 6e 73 69 6f 6e 73 28 63 65 72  0_extensions(cer
0970: 74 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20  t)) {..for (int 
0980: 69 3d 30 3b 20 69 20 3c 20 58 35 30 39 5f 67 65  i=0; i < X509_ge
0990: 74 5f 65 78 74 5f 63 6f 75 6e 74 28 63 65 72 74  t_ext_count(cert
09a0: 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20 58  ); i++) {..    X
09b0: 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 20 2a 65  509_EXTENSION *e
09c0: 78 20 3d 20 73 6b 5f 58 35 30 39 5f 45 58 54 45  x = sk_X509_EXTE
09d0: 4e 53 49 4f 4e 5f 76 61 6c 75 65 28 65 78 74 73  NSION_value(exts
09e0: 2c 20 69 29 3b 0a 09 20 20 20 20 41 53 4e 31 5f  , i);..    ASN1_
09f0: 4f 42 4a 45 43 54 20 2a 6f 62 6a 20 3d 20 58 35  OBJECT *obj = X5
0a00: 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67 65 74  09_EXTENSION_get
0a10: 5f 6f 62 6a 65 63 74 28 65 78 29 3b 0a 09 20 20  _object(ex);..  
0a20: 20 20 2f 2a 20 41 53 4e 31 5f 4f 43 54 45 54 5f    /* ASN1_OCTET_
0a30: 53 54 52 49 4e 47 20 2a 64 61 74 61 20 3d 20 58  STRING *data = X
0a40: 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67 65  509_EXTENSION_ge
0a50: 74 5f 64 61 74 61 28 65 78 29 3b 20 2a 2f 0a 09  t_data(ex); */..
0a60: 20 20 20 20 69 6e 74 20 63 72 69 74 69 63 61 6c      int critical
0a70: 20 3d 20 58 35 30 39 5f 45 58 54 45 4e 53 49 4f   = X509_EXTENSIO
0a80: 4e 5f 67 65 74 5f 63 72 69 74 69 63 61 6c 28 65  N_get_critical(e
0a90: 78 29 3b 0a 09 20 20 20 20 4c 41 50 50 45 4e 44  x);..    LAPPEND
0aa0: 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 6c 69  _BOOL(interp, li
0ab0: 73 74 50 74 72 2c 20 4f 42 4a 5f 6e 69 64 32 6c  stPtr, OBJ_nid2l
0ac0: 6e 28 4f 42 4a 5f 6f 62 6a 32 6e 69 64 28 6f 62  n(OBJ_obj2nid(ob
0ad0: 6a 29 29 2c 20 63 72 69 74 69 63 61 6c 29 3b 0a  j)), critical);.
0ae0: 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74  .}.    }.    ret
0af0: 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a  urn listPtr;.}..
0b00: 2f 2a 0a 20 2a 20 47 65 74 20 41 75 74 68 6f 72  /*. * Get Author
0b10: 69 74 79 20 61 6e 64 20 53 75 62 6a 65 63 74 20  ity and Subject 
0b20: 4b 65 79 20 49 64 65 6e 74 69 66 69 65 72 73 0a  Key Identifiers.
0b30: 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73   */.Tcl_Obj *Tls
0b40: 5f 78 35 30 39 49 64 65 6e 74 69 66 69 65 72 28  _x509Identifier(
0b50: 41 53 4e 31 5f 4f 43 54 45 54 5f 53 54 52 49 4e  ASN1_OCTET_STRIN
0b60: 47 20 2a 61 73 74 72 69 6e 67 29 20 7b 0a 20 20  G *astring) {.  
0b70: 20 20 54 63 6c 5f 4f 62 6a 20 2a 72 65 73 75 6c    Tcl_Obj *resul
0b80: 74 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20  tPtr = NULL;.   
0b90: 20 69 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20 20   int len = 0;.  
0ba0: 20 20 63 68 61 72 20 62 75 66 66 65 72 5b 31 30    char buffer[10
0bb0: 32 34 5d 3b 0a 0a 20 20 20 20 69 66 20 28 61 73  24];..    if (as
0bc0: 74 72 69 6e 67 20 21 3d 20 4e 55 4c 4c 29 20 7b  tring != NULL) {
0bd0: 0a 09 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74  ..len = String_t
0be0: 6f 5f 48 65 78 28 28 63 68 61 72 20 2a 29 41 53  o_Hex((char *)AS
0bf0: 4e 31 5f 53 54 52 49 4e 47 5f 67 65 74 30 5f 64  N1_STRING_get0_d
0c00: 61 74 61 28 61 73 74 72 69 6e 67 29 2c 0a 09 20  ata(astring),.. 
0c10: 20 20 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 6c     ASN1_STRING_l
0c20: 65 6e 67 74 68 28 61 73 74 72 69 6e 67 29 2c 20  ength(astring), 
0c30: 62 75 66 66 65 72 2c 20 31 30 32 34 29 3b 0a 20  buffer, 1024);. 
0c40: 20 20 20 7d 0a 20 20 20 20 72 65 73 75 6c 74 50     }.    resultP
0c50: 74 72 20 3d 20 54 63 6c 5f 4e 65 77 53 74 72 69  tr = Tcl_NewStri
0c60: 6e 67 4f 62 6a 28 62 75 66 66 65 72 2c 20 28 54  ngObj(buffer, (T
0c70: 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20  cl_Size) len);. 
0c80: 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c 74     return result
0c90: 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65  Ptr;.}../*. * Ge
0ca0: 74 20 4b 65 79 20 55 73 61 67 65 0a 20 2a 2f 0a  t Key Usage. */.
0cb0: 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30  Tcl_Obj *Tls_x50
0cc0: 39 4b 65 79 55 73 61 67 65 28 54 63 6c 5f 49 6e  9KeyUsage(Tcl_In
0cd0: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35  terp *interp, X5
0ce0: 30 39 20 2a 63 65 72 74 2c 20 75 69 6e 74 33 32  09 *cert, uint32
0cf0: 5f 74 20 78 66 6c 61 67 73 29 20 7b 0a 20 20 20  _t xflags) {.   
0d00: 20 75 69 6e 74 33 32 5f 74 20 75 73 61 67 65 20   uint32_t usage 
0d10: 3d 20 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f 75  = X509_get_key_u
0d20: 73 61 67 65 28 63 65 72 74 29 3b 0a 20 20 20 20  sage(cert);.    
0d30: 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72  Tcl_Obj *listPtr
0d40: 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62   = Tcl_NewListOb
0d50: 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20  j(0, NULL);..   
0d60: 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20   if (listPtr == 
0d70: 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20  NULL) {..return 
0d80: 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  NULL;.    }..   
0d90: 20 69 66 20 28 28 78 66 6c 61 67 73 20 26 20 45   if ((xflags & E
0da0: 58 46 4c 41 47 5f 4b 55 53 41 47 45 29 20 26 26  XFLAG_KUSAGE) &&
0db0: 20 75 73 61 67 65 20 3c 20 55 49 4e 54 33 32 5f   usage < UINT32_
0dc0: 4d 41 58 29 20 7b 0a 09 69 66 20 28 75 73 61 67  MAX) {..if (usag
0dd0: 65 20 26 20 4b 55 5f 44 49 47 49 54 41 4c 5f 53  e & KU_DIGITAL_S
0de0: 49 47 4e 41 54 55 52 45 29 20 7b 0a 09 20 20 20  IGNATURE) {..   
0df0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
0e00: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
0e10: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e  , listPtr, Tcl_N
0e20: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 69 67  ewStringObj("Dig
0e30: 69 74 61 6c 20 53 69 67 6e 61 74 75 72 65 22 2c  ital Signature",
0e40: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
0e50: 73 61 67 65 20 26 20 4b 55 5f 4e 4f 4e 5f 52 45  sage & KU_NON_RE
0e60: 50 55 44 49 41 54 49 4f 4e 29 20 7b 0a 09 20 20  PUDIATION) {..  
0e70: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
0e80: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
0e90: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
0ea0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4e 6f  NewStringObj("No
0eb0: 6e 2d 52 65 70 75 64 69 61 74 69 6f 6e 22 2c 20  n-Repudiation", 
0ec0: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
0ed0: 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 45 4e 43  age & KU_KEY_ENC
0ee0: 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a 09 20 20  IPHERMENT) {..  
0ef0: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
0f00: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
0f10: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
0f20: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b 65  NewStringObj("Ke
0f30: 79 20 45 6e 63 69 70 68 65 72 6d 65 6e 74 22 2c  y Encipherment",
0f40: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
0f50: 73 61 67 65 20 26 20 4b 55 5f 44 41 54 41 5f 45  sage & KU_DATA_E
0f60: 4e 43 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a 09  NCIPHERMENT) {..
0f70: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
0f80: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
0f90: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
0fa0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
0fb0: 44 61 74 61 20 45 6e 63 69 70 68 65 72 6d 65 6e  Data Enciphermen
0fc0: 74 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66  t", -1));..}..if
0fd0: 20 28 75 73 61 67 65 20 26 20 4b 55 5f 4b 45 59   (usage & KU_KEY
0fe0: 5f 41 47 52 45 45 4d 45 4e 54 29 20 7b 0a 09 20  _AGREEMENT) {.. 
0ff0: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
1000: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
1010: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
1020: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b  _NewStringObj("K
1030: 65 79 20 41 67 72 65 65 6d 65 6e 74 22 2c 20 2d  ey Agreement", -
1040: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
1050: 67 65 20 26 20 4b 55 5f 4b 45 59 5f 43 45 52 54  ge & KU_KEY_CERT
1060: 5f 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 63  _SIGN) {..    Tc
1070: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
1080: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
1090: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
10a0: 74 72 69 6e 67 4f 62 6a 28 22 43 65 72 74 69 66  tringObj("Certif
10b0: 69 63 61 74 65 20 53 69 67 6e 69 6e 67 22 2c 20  icate Signing", 
10c0: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
10d0: 61 67 65 20 26 20 4b 55 5f 43 52 4c 5f 53 49 47  age & KU_CRL_SIG
10e0: 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69  N) {..    Tcl_Li
10f0: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
1100: 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  nt(interp, listP
1110: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  tr, Tcl_NewStrin
1120: 67 4f 62 6a 28 22 43 52 4c 20 53 69 67 6e 69 6e  gObj("CRL Signin
1130: 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66  g", -1));..}..if
1140: 20 28 75 73 61 67 65 20 26 20 4b 55 5f 45 4e 43   (usage & KU_ENC
1150: 49 50 48 45 52 5f 4f 4e 4c 59 29 20 7b 0a 09 20  IPHER_ONLY) {.. 
1160: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
1170: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
1180: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
1190: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 45  _NewStringObj("E
11a0: 6e 63 69 70 68 65 72 20 4f 6e 6c 79 22 2c 20 2d  ncipher Only", -
11b0: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
11c0: 67 65 20 26 20 4b 55 5f 44 45 43 49 50 48 45 52  ge & KU_DECIPHER
11d0: 5f 4f 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 63  _ONLY) {..    Tc
11e0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
11f0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
1200: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
1210: 74 72 69 6e 67 4f 62 6a 28 22 44 65 63 69 70 68  tringObj("Deciph
1220: 65 72 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b 0a  er Only", -1));.
1230: 09 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a  .}.    } else {.
1240: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
1250: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
1260: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54  terp, listPtr, T
1270: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
1280: 22 75 6e 72 65 73 74 72 69 63 74 65 64 22 2c 20  "unrestricted", 
1290: 2d 31 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  -1));.    }.    
12a0: 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a  return listPtr;.
12b0: 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 65 72  }../*. * Get Cer
12c0: 74 69 66 69 63 61 74 65 20 50 75 72 70 6f 73 65  tificate Purpose
12d0: 0a 20 2a 2f 0a 63 68 61 72 20 2a 54 6c 73 5f 78  . */.char *Tls_x
12e0: 35 30 39 50 75 72 70 6f 73 65 28 58 35 30 39 20  509Purpose(X509 
12f0: 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 63 68 61  *cert) {.    cha
1300: 72 20 2a 70 75 72 70 6f 73 65 20 3d 20 4e 55 4c  r *purpose = NUL
1310: 4c 3b 0a 0a 20 20 20 20 69 66 20 28 58 35 30 39  L;..    if (X509
1320: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63  _check_purpose(c
1330: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53  ert, X509_PURPOS
1340: 45 5f 53 53 4c 5f 43 4c 49 45 4e 54 2c 20 30 29  E_SSL_CLIENT, 0)
1350: 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65   > 0) {..purpose
1360: 20 3d 20 22 53 53 4c 20 43 6c 69 65 6e 74 22 3b   = "SSL Client";
1370: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28  .    } else if (
1380: 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f  X509_check_purpo
1390: 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55  se(cert, X509_PU
13a0: 52 50 4f 53 45 5f 53 53 4c 5f 53 45 52 56 45 52  RPOSE_SSL_SERVER
13b0: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72  , 0) > 0) {..pur
13c0: 70 6f 73 65 20 3d 20 22 53 53 4c 20 53 65 72 76  pose = "SSL Serv
13d0: 65 72 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20  er";.    } else 
13e0: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70  if (X509_check_p
13f0: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30  urpose(cert, X50
1400: 39 5f 50 55 52 50 4f 53 45 5f 4e 53 5f 53 53 4c  9_PURPOSE_NS_SSL
1410: 5f 53 45 52 56 45 52 2c 20 30 29 20 3e 20 30 29  _SERVER, 0) > 0)
1420: 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 4d   {..purpose = "M
1430: 53 53 20 53 53 4c 20 53 65 72 76 65 72 22 3b 0a  SS SSL Server";.
1440: 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58      } else if (X
1450: 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73  509_check_purpos
1460: 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52  e(cert, X509_PUR
1470: 50 4f 53 45 5f 53 4d 49 4d 45 5f 53 49 47 4e 2c  POSE_SMIME_SIGN,
1480: 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70   0) > 0) {..purp
1490: 6f 73 65 20 3d 20 22 53 4d 49 4d 45 20 53 69 67  ose = "SMIME Sig
14a0: 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c 73  ning";.    } els
14b0: 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b  e if (X509_check
14c0: 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58  _purpose(cert, X
14d0: 35 30 39 5f 50 55 52 50 4f 53 45 5f 53 4d 49 4d  509_PURPOSE_SMIM
14e0: 45 5f 45 4e 43 52 59 50 54 2c 20 30 29 20 3e 20  E_ENCRYPT, 0) > 
14f0: 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20  0) {..purpose = 
1500: 22 53 4d 49 4d 45 20 45 6e 63 72 79 70 74 69 6f  "SMIME Encryptio
1510: 6e 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69  n";.    } else i
1520: 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75  f (X509_check_pu
1530: 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39  rpose(cert, X509
1540: 5f 50 55 52 50 4f 53 45 5f 43 52 4c 5f 53 49 47  _PURPOSE_CRL_SIG
1550: 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75  N, 0) > 0) {..pu
1560: 72 70 6f 73 65 20 3d 20 22 43 52 4c 20 53 69 67  rpose = "CRL Sig
1570: 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c 73  ning";.    } els
1580: 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b  e if (X509_check
1590: 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58  _purpose(cert, X
15a0: 35 30 39 5f 50 55 52 50 4f 53 45 5f 41 4e 59 2c  509_PURPOSE_ANY,
15b0: 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70   0) > 0) {..purp
15c0: 6f 73 65 20 3d 20 22 41 6e 79 22 3b 0a 20 20 20  ose = "Any";.   
15d0: 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39   } else if (X509
15e0: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63  _check_purpose(c
15f0: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53  ert, X509_PURPOS
1600: 45 5f 4f 43 53 50 5f 48 45 4c 50 45 52 2c 20 30  E_OCSP_HELPER, 0
1610: 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73  ) > 0) {..purpos
1620: 65 20 3d 20 22 4f 43 53 50 20 48 65 6c 70 65 72  e = "OCSP Helper
1630: 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66  ";.    } else if
1640: 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72   (X509_check_pur
1650: 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f  pose(cert, X509_
1660: 50 55 52 50 4f 53 45 5f 54 49 4d 45 53 54 41 4d  PURPOSE_TIMESTAM
1670: 50 5f 53 49 47 4e 2c 20 30 29 20 3e 20 30 29 20  P_SIGN, 0) > 0) 
1680: 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 54 69  {..purpose = "Ti
1690: 6d 65 73 74 61 6d 70 20 53 69 67 6e 69 6e 67 22  mestamp Signing"
16a0: 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09  ;.    } else {..
16b0: 70 75 72 70 6f 73 65 20 3d 20 22 22 3b 0a 20 20  purpose = "";.  
16c0: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 70    }.    return p
16d0: 75 72 70 6f 73 65 3b 0a 7d 0a 0a 2f 2a 0a 20 2a  urpose;.}../*. *
16e0: 20 46 6f 72 20 65 61 63 68 20 70 75 72 70 6f 73   For each purpos
16f0: 65 2c 20 67 65 74 20 63 65 72 74 69 66 69 63 61  e, get certifica
1700: 74 65 20 61 70 70 6c 69 63 61 62 69 6c 69 74 79  te applicability
1710: 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c  . */.Tcl_Obj *Tl
1720: 73 5f 78 35 30 39 50 75 72 70 6f 73 65 73 28 54  s_x509Purposes(T
1730: 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72  cl_Interp *inter
1740: 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b  p, X509 *cert) {
1750: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69  .    Tcl_Obj *li
1760: 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c  stPtr = Tcl_NewL
1770: 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b  istObj(0, NULL);
1780: 0a 20 20 20 20 58 35 30 39 5f 50 55 52 50 4f 53  .    X509_PURPOS
1790: 45 20 2a 70 74 6d 70 3b 0a 0a 20 20 20 20 69 66  E *ptmp;..    if
17a0: 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c   (listPtr == NUL
17b0: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c  L) {..return NUL
17c0: 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 66 6f  L;.    }..    fo
17d0: 72 20 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 20  r (int i = 0; i 
17e0: 3c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67  < X509_PURPOSE_g
17f0: 65 74 5f 63 6f 75 6e 74 28 29 3b 20 69 2b 2b 29  et_count(); i++)
1800: 20 7b 0a 09 70 74 6d 70 20 3d 20 58 35 30 39 5f   {..ptmp = X509_
1810: 50 55 52 50 4f 53 45 5f 67 65 74 30 28 69 29 3b  PURPOSE_get0(i);
1820: 0a 09 54 63 6c 5f 4f 62 6a 20 2a 74 6d 70 50 74  ..Tcl_Obj *tmpPt
1830: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f  r = Tcl_NewListO
1840: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 66  bj(0, NULL);...f
1850: 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20 6a  or (int j = 0; j
1860: 20 3c 20 32 3b 20 6a 2b 2b 29 20 7b 0a 09 20 20   < 2; j++) {..  
1870: 20 20 69 6e 74 20 69 64 72 65 74 20 3d 20 58 35    int idret = X5
1880: 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65  09_check_purpose
1890: 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50  (cert, X509_PURP
18a0: 4f 53 45 5f 67 65 74 5f 69 64 28 70 74 6d 70 29  OSE_get_id(ptmp)
18b0: 2c 20 6a 29 3b 0a 09 20 20 20 20 54 63 6c 5f 4c  , j);..    Tcl_L
18c0: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
18d0: 65 6e 74 28 69 6e 74 65 72 70 2c 20 74 6d 70 50  ent(interp, tmpP
18e0: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  tr, Tcl_NewStrin
18f0: 67 4f 62 6a 28 6a 20 3f 20 22 43 41 22 20 3a 20  gObj(j ? "CA" : 
1900: 22 6e 6f 6e 43 41 22 2c 20 2d 31 29 29 3b 0a 09  "nonCA", -1));..
1910: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
1920: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
1930: 65 72 70 2c 20 74 6d 70 50 74 72 2c 20 54 63 6c  erp, tmpPtr, Tcl
1940: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 69 64  _NewStringObj(id
1950: 72 65 74 20 3d 3d 20 31 20 3f 20 22 59 65 73 22  ret == 1 ? "Yes"
1960: 20 3a 20 22 4e 6f 22 2c 20 2d 31 29 29 3b 0a 09   : "No", -1));..
1970: 7d 0a 09 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69  }..LAPPEND_OBJ(i
1980: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20  nterp, listPtr, 
1990: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 74  X509_PURPOSE_get
19a0: 30 5f 6e 61 6d 65 28 70 74 6d 70 29 2c 20 74 6d  0_name(ptmp), tm
19b0: 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20 20  pPtr);.    }.   
19c0: 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b   return listPtr;
19d0: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 53 75  .}../*. * Get Su
19e0: 62 6a 65 63 74 20 41 6c 74 65 72 6e 61 74 65 20  bject Alternate 
19f0: 4e 61 6d 65 73 20 28 53 41 4e 29 20 61 6e 64 20  Names (SAN) and 
1a00: 49 73 73 75 65 72 20 41 6c 74 65 72 6e 61 74 65  Issuer Alternate
1a10: 20 4e 61 6d 65 73 0a 20 2a 2f 0a 54 63 6c 5f 4f   Names. */.Tcl_O
1a20: 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4e 61 6d 65  bj *Tls_x509Name
1a30: 73 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e  s(Tcl_Interp *in
1a40: 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74  terp, X509 *cert
1a50: 2c 20 69 6e 74 20 6e 69 64 2c 20 42 49 4f 20 2a  , int nid, BIO *
1a60: 62 69 6f 29 20 7b 0a 20 20 20 20 53 54 41 43 4b  bio) {.    STACK
1a70: 5f 4f 46 28 47 45 4e 45 52 41 4c 5f 4e 41 4d 45  _OF(GENERAL_NAME
1a80: 29 20 2a 6e 61 6d 65 73 3b 0a 20 20 20 20 54 63  ) *names;.    Tc
1a90: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d  l_Obj *listPtr =
1aa0: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28   Tcl_NewListObj(
1ab0: 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 69 6e  0, NULL);.    in
1ac0: 74 20 6c 65 6e 3b 0a 20 20 20 20 63 68 61 72 20  t len;.    char 
1ad0: 62 75 66 66 65 72 5b 31 30 32 34 5d 3b 0a 0a 20  buffer[1024];.. 
1ae0: 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d     if (listPtr =
1af0: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72  = NULL) {..retur
1b00: 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20  n NULL;.    }.. 
1b10: 20 20 20 69 66 20 28 6e 61 6d 65 73 20 3d 20 58     if (names = X
1b20: 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 28  509_get_ext_d2i(
1b30: 63 65 72 74 2c 20 6e 69 64 2c 20 4e 55 4c 4c 2c  cert, nid, NULL,
1b40: 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 28   NULL)) {..for (
1b50: 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20 73 6b 5f  int i=0; i < sk_
1b60: 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e 75 6d  GENERAL_NAME_num
1b70: 28 6e 61 6d 65 73 29 3b 20 69 2b 2b 29 20 7b 0a  (names); i++) {.
1b80: 09 20 20 20 20 63 6f 6e 73 74 20 47 45 4e 45 52  .    const GENER
1b90: 41 4c 5f 4e 41 4d 45 20 2a 6e 61 6d 65 20 3d 20  AL_NAME *name = 
1ba0: 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f  sk_GENERAL_NAME_
1bb0: 76 61 6c 75 65 28 6e 61 6d 65 73 2c 20 69 29 3b  value(names, i);
1bc0: 0a 0a 09 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f  ...    len = BIO
1bd0: 5f 74 6f 5f 42 75 66 66 65 72 28 6e 61 6d 65 20  _to_Buffer(name 
1be0: 26 26 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f  && GENERAL_NAME_
1bf0: 70 72 69 6e 74 28 62 69 6f 2c 20 6e 61 6d 65 29  print(bio, name)
1c00: 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 31  , bio, buffer, 1
1c10: 30 32 34 29 3b 0a 09 20 20 20 20 4c 41 50 50 45  024);..    LAPPE
1c20: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 6c  ND_STR(interp, l
1c30: 69 73 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 62 75  istPtr, NULL, bu
1c40: 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29  ffer, (Tcl_Size)
1c50: 20 6c 65 6e 29 3b 0a 09 7d 0a 09 73 6b 5f 47 45   len);..}..sk_GE
1c60: 4e 45 52 41 4c 5f 4e 41 4d 45 5f 70 6f 70 5f 66  NERAL_NAME_pop_f
1c70: 72 65 65 28 6e 61 6d 65 73 2c 20 47 45 4e 45 52  ree(names, GENER
1c80: 41 4c 5f 4e 41 4d 45 5f 66 72 65 65 29 3b 0a 20  AL_NAME_free);. 
1c90: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20     }.    return 
1ca0: 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20  listPtr;.}../*. 
1cb0: 2a 20 47 65 74 20 45 58 74 65 6e 64 65 64 20 4b  * Get EXtended K
1cc0: 65 79 20 55 73 61 67 65 0a 20 2a 2f 0a 54 63 6c  ey Usage. */.Tcl
1cd0: 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 45 78  _Obj *Tls_x509Ex
1ce0: 74 4b 65 79 55 73 61 67 65 28 54 63 6c 5f 49 6e  tKeyUsage(Tcl_In
1cf0: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35  terp *interp, X5
1d00: 30 39 20 2a 63 65 72 74 2c 20 75 69 6e 74 33 32  09 *cert, uint32
1d10: 5f 74 20 78 66 6c 61 67 73 29 20 7b 0a 20 20 20  _t xflags) {.   
1d20: 20 75 69 6e 74 33 32 5f 74 20 75 73 61 67 65 20   uint32_t usage 
1d30: 3d 20 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f 75  = X509_get_key_u
1d40: 73 61 67 65 28 63 65 72 74 29 3b 0a 20 20 20 20  sage(cert);.    
1d50: 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72  Tcl_Obj *listPtr
1d60: 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62   = Tcl_NewListOb
1d70: 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20  j(0, NULL);..   
1d80: 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20   if (listPtr == 
1d90: 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20  NULL) {..return 
1da0: 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  NULL;.    }..   
1db0: 20 69 66 20 28 28 78 66 6c 61 67 73 20 26 20 45   if ((xflags & E
1dc0: 58 46 4c 41 47 5f 58 4b 55 53 41 47 45 29 20 26  XFLAG_XKUSAGE) &
1dd0: 26 20 75 73 61 67 65 20 3c 20 55 49 4e 54 33 32  & usage < UINT32
1de0: 5f 4d 41 58 29 20 7b 0a 09 75 73 61 67 65 20 3d  _MAX) {..usage =
1df0: 20 58 35 30 39 5f 67 65 74 5f 65 78 74 65 6e 64   X509_get_extend
1e00: 65 64 5f 6b 65 79 5f 75 73 61 67 65 28 63 65 72  ed_key_usage(cer
1e10: 74 29 3b 0a 0a 09 69 66 20 28 75 73 61 67 65 20  t);...if (usage 
1e20: 26 20 58 4b 55 5f 53 53 4c 5f 53 45 52 56 45 52  & XKU_SSL_SERVER
1e30: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73  ) {..    Tcl_Lis
1e40: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e  tObjAppendElemen
1e50: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74  t(interp, listPt
1e60: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67  r, Tcl_NewString
1e70: 4f 62 6a 28 22 54 4c 53 20 57 65 62 20 53 65 72  Obj("TLS Web Ser
1e80: 76 65 72 20 41 75 74 68 65 6e 74 69 63 61 74 69  ver Authenticati
1e90: 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69  on", -1));..}..i
1ea0: 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 53  f (usage & XKU_S
1eb0: 53 4c 5f 43 4c 49 45 4e 54 29 20 7b 0a 09 20 20  SL_CLIENT) {..  
1ec0: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
1ed0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
1ee0: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
1ef0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 54 4c  NewStringObj("TL
1f00: 53 20 57 65 62 20 43 6c 69 65 6e 74 20 41 75 74  S Web Client Aut
1f10: 68 65 6e 74 69 63 61 74 69 6f 6e 22 2c 20 2d 31  hentication", -1
1f20: 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67  ));..}..if (usag
1f30: 65 20 26 20 58 4b 55 5f 53 4d 49 4d 45 29 20 7b  e & XKU_SMIME) {
1f40: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62  ..    Tcl_ListOb
1f50: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69  jAppendElement(i
1f60: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20  nterp, listPtr, 
1f70: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a  Tcl_NewStringObj
1f80: 28 22 45 2d 6d 61 69 6c 20 50 72 6f 74 65 63 74  ("E-mail Protect
1f90: 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09  ion", -1));..}..
1fa0: 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f  if (usage & XKU_
1fb0: 43 4f 44 45 5f 53 49 47 4e 29 20 7b 0a 09 20 20  CODE_SIGN) {..  
1fc0: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
1fd0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
1fe0: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
1ff0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 43 6f  NewStringObj("Co
2000: 64 65 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31 29  de Signing", -1)
2010: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65  );..}..if (usage
2020: 20 26 20 58 4b 55 5f 53 47 43 29 20 7b 0a 09 20   & XKU_SGC) {.. 
2030: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
2040: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
2050: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
2060: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 53  _NewStringObj("S
2070: 47 43 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69  GC", -1));..}..i
2080: 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 4f  f (usage & XKU_O
2090: 43 53 50 5f 53 49 47 4e 29 20 7b 0a 09 20 20 20  CSP_SIGN) {..   
20a0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
20b0: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
20c0: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e  , listPtr, Tcl_N
20d0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4f 43 53  ewStringObj("OCS
20e0: 50 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31 29 29  P Signing", -1))
20f0: 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20  ;..}..if (usage 
2100: 26 20 58 4b 55 5f 54 49 4d 45 53 54 41 4d 50 29  & XKU_TIMESTAMP)
2110: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
2120: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
2130: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
2140: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
2150: 62 6a 28 22 54 69 6d 65 20 53 74 61 6d 70 69 6e  bj("Time Stampin
2160: 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66  g", -1));..}..if
2170: 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 44 56   (usage & XKU_DV
2180: 43 53 20 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f  CS ) {..    Tcl_
2190: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
21a0: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73  ment(interp, lis
21b0: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
21c0: 69 6e 67 4f 62 6a 28 22 44 56 43 53 22 2c 20 2d  ingObj("DVCS", -
21d0: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
21e0: 67 65 20 26 20 58 4b 55 5f 41 4e 59 45 4b 55 29  ge & XKU_ANYEKU)
21f0: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
2200: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
2210: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
2220: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
2230: 62 6a 28 22 41 6e 79 20 45 78 74 65 6e 64 65 64  bj("Any Extended
2240: 20 4b 65 79 20 55 73 61 67 65 22 2c 20 2d 31 29   Key Usage", -1)
2250: 29 3b 0a 09 7d 0a 20 20 20 20 7d 20 65 6c 73 65  );..}.    } else
2260: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
2270: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
2280: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
2290: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
22a0: 62 6a 28 22 75 6e 72 65 73 74 72 69 63 74 65 64  bj("unrestricted
22b0: 22 2c 20 2d 31 29 29 3b 0a 20 20 20 20 7d 0a 20  ", -1));.    }. 
22c0: 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74     return listPt
22d0: 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20  r;.}../*. * Get 
22e0: 43 52 4c 20 44 69 73 74 72 69 62 75 74 69 6f 6e  CRL Distribution
22f0: 20 50 6f 69 6e 74 73 0a 20 2a 2f 0a 54 63 6c 5f   Points. */.Tcl_
2300: 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 43 72 6c  Obj *Tls_x509Crl
2310: 44 70 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69  Dp(Tcl_Interp *i
2320: 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72  nterp, X509 *cer
2330: 74 29 20 7b 0a 20 20 20 20 53 54 41 43 4b 5f 4f  t) {.    STACK_O
2340: 46 28 44 49 53 54 5f 50 4f 49 4e 54 29 20 2a 63  F(DIST_POINT) *c
2350: 72 6c 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20  rl;.    Tcl_Obj 
2360: 2a 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e  *listPtr = Tcl_N
2370: 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c  ewListObj(0, NUL
2380: 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 73  L);..    if (lis
2390: 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a  tPtr == NULL) {.
23a0: 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20  .return NULL;.  
23b0: 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 63 72 6c    }..    if (crl
23c0: 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f   = X509_get_ext_
23d0: 64 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 63 72  d2i(cert, NID_cr
23e0: 6c 5f 64 69 73 74 72 69 62 75 74 69 6f 6e 5f 70  l_distribution_p
23f0: 6f 69 6e 74 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c  oints, NULL, NUL
2400: 4c 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20  L)) {..for (int 
2410: 69 3d 30 3b 20 69 20 3c 20 73 6b 5f 44 49 53 54  i=0; i < sk_DIST
2420: 5f 50 4f 49 4e 54 5f 6e 75 6d 28 63 72 6c 29 3b  _POINT_num(crl);
2430: 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20 44 49 53   i++) {..    DIS
2440: 54 5f 50 4f 49 4e 54 20 2a 64 70 20 3d 20 73 6b  T_POINT *dp = sk
2450: 5f 44 49 53 54 5f 50 4f 49 4e 54 5f 76 61 6c 75  _DIST_POINT_valu
2460: 65 28 63 72 6c 2c 20 69 29 3b 0a 09 20 20 20 20  e(crl, i);..    
2470: 44 49 53 54 5f 50 4f 49 4e 54 5f 4e 41 4d 45 20  DIST_POINT_NAME 
2480: 2a 64 69 73 74 70 6f 69 6e 74 20 3d 20 64 70 2d  *distpoint = dp-
2490: 3e 64 69 73 74 70 6f 69 6e 74 3b 0a 0a 09 20 20  >distpoint;...  
24a0: 20 20 69 66 20 28 64 69 73 74 70 6f 69 6e 74 2d    if (distpoint-
24b0: 3e 74 79 70 65 20 3d 3d 20 30 29 20 7b 0a 09 09  >type == 0) {...
24c0: 2f 2a 20 66 75 6c 6c 2d 6e 61 6d 65 20 47 45 4e  /* full-name GEN
24d0: 45 52 41 4c 49 5a 45 44 4e 41 4d 45 20 2a 2f 0a  ERALIZEDNAME */.
24e0: 09 09 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30  ..for (int j = 0
24f0: 3b 20 6a 20 3c 20 73 6b 5f 47 45 4e 45 52 41 4c  ; j < sk_GENERAL
2500: 5f 4e 41 4d 45 5f 6e 75 6d 28 64 69 73 74 70 6f  _NAME_num(distpo
2510: 69 6e 74 2d 3e 6e 61 6d 65 2e 66 75 6c 6c 6e 61  int->name.fullna
2520: 6d 65 29 3b 20 6a 2b 2b 29 20 7b 0a 09 09 20 20  me); j++) {...  
2530: 20 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 20 2a    GENERAL_NAME *
2540: 67 65 6e 20 3d 20 73 6b 5f 47 45 4e 45 52 41 4c  gen = sk_GENERAL
2550: 5f 4e 41 4d 45 5f 76 61 6c 75 65 28 64 69 73 74  _NAME_value(dist
2560: 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66 75 6c 6c  point->name.full
2570: 6e 61 6d 65 2c 20 6a 29 3b 0a 09 09 20 20 20 20  name, j);...    
2580: 69 6e 74 20 74 79 70 65 3b 0a 09 09 20 20 20 20  int type;...    
2590: 41 53 4e 31 5f 53 54 52 49 4e 47 20 2a 75 72 69  ASN1_STRING *uri
25a0: 20 3d 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f   = GENERAL_NAME_
25b0: 67 65 74 30 5f 76 61 6c 75 65 28 67 65 6e 2c 20  get0_value(gen, 
25c0: 26 74 79 70 65 29 3b 0a 09 09 20 20 20 20 69 66  &type);...    if
25d0: 20 28 74 79 70 65 20 3d 3d 20 47 45 4e 5f 55 52   (type == GEN_UR
25e0: 49 29 20 7b 0a 09 09 09 4c 41 50 50 45 4e 44 5f  I) {....LAPPEND_
25f0: 53 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74  STR(interp, list
2600: 50 74 72 2c 20 4e 55 4c 4c 2c 20 41 53 4e 31 5f  Ptr, NULL, ASN1_
2610: 53 54 52 49 4e 47 5f 67 65 74 30 5f 64 61 74 61  STRING_get0_data
2620: 28 75 72 69 29 2c 20 28 54 63 6c 5f 53 69 7a 65  (uri), (Tcl_Size
2630: 29 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 6c 65  ) ASN1_STRING_le
2640: 6e 67 74 68 28 75 72 69 29 29 3b 0a 09 09 20 20  ngth(uri));...  
2650: 20 20 7d 0a 09 09 7d 0a 09 20 20 20 20 7d 20 65    }...}..    } e
2660: 6c 73 65 20 69 66 20 28 64 69 73 74 70 6f 69 6e  lse if (distpoin
2670: 74 2d 3e 74 79 70 65 20 3d 3d 20 31 29 20 7b 0a  t->type == 1) {.
2680: 09 09 2f 2a 20 72 65 6c 61 74 69 76 65 2d 6e 61  ../* relative-na
2690: 6d 65 20 58 35 30 39 4e 41 4d 45 20 2a 2f 0a 09  me X509NAME */..
26a0: 09 53 54 41 43 4b 5f 4f 46 28 58 35 30 39 5f 4e  .STACK_OF(X509_N
26b0: 41 4d 45 5f 45 4e 54 52 59 29 20 2a 73 6b 5f 72  AME_ENTRY) *sk_r
26c0: 65 6c 6e 61 6d 65 20 3d 20 64 69 73 74 70 6f 69  elname = distpoi
26d0: 6e 74 2d 3e 6e 61 6d 65 2e 72 65 6c 61 74 69 76  nt->name.relativ
26e0: 65 6e 61 6d 65 3b 0a 09 09 66 6f 72 20 28 69 6e  ename;...for (in
26f0: 74 20 6a 20 3d 20 30 3b 20 6a 20 3c 20 73 6b 5f  t j = 0; j < sk_
2700: 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f  X509_NAME_ENTRY_
2710: 6e 75 6d 28 73 6b 5f 72 65 6c 6e 61 6d 65 29 3b  num(sk_relname);
2720: 20 6a 2b 2b 29 20 7b 0a 09 09 20 20 20 20 58 35   j++) {...    X5
2730: 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 20 2a 65  09_NAME_ENTRY *e
2740: 20 3d 20 73 6b 5f 58 35 30 39 5f 4e 41 4d 45 5f   = sk_X509_NAME_
2750: 45 4e 54 52 59 5f 76 61 6c 75 65 28 73 6b 5f 72  ENTRY_value(sk_r
2760: 65 6c 6e 61 6d 65 2c 20 6a 29 3b 0a 09 09 20 20  elname, j);...  
2770: 20 20 41 53 4e 31 5f 53 54 52 49 4e 47 20 2a 64    ASN1_STRING *d
2780: 20 3d 20 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54   = X509_NAME_ENT
2790: 52 59 5f 67 65 74 5f 64 61 74 61 28 65 29 3b 0a  RY_get_data(e);.
27a0: 09 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54  ..    LAPPEND_ST
27b0: 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74  R(interp, listPt
27c0: 72 2c 20 4e 55 4c 4c 2c 20 41 53 4e 31 5f 53 54  r, NULL, ASN1_ST
27d0: 52 49 4e 47 5f 64 61 74 61 28 64 29 2c 20 28 54  RING_data(d), (T
27e0: 63 6c 5f 53 69 7a 65 29 20 41 53 4e 31 5f 53 54  cl_Size) ASN1_ST
27f0: 52 49 4e 47 5f 6c 65 6e 67 74 68 28 64 29 29 3b  RING_length(d));
2800: 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 7d 0a 09  ...}..    }..}..
2810: 43 52 4c 5f 44 49 53 54 5f 50 4f 49 4e 54 53 5f  CRL_DIST_POINTS_
2820: 66 72 65 65 28 63 72 6c 29 3b 0a 20 20 20 20 7d  free(crl);.    }
2830: 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74  .    return list
2840: 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65  Ptr;.}../*. * Ge
2850: 74 20 4f 6e 2d 6c 69 6e 65 20 43 65 72 74 69 66  t On-line Certif
2860: 69 63 61 74 65 20 53 74 61 74 75 73 20 50 72 6f  icate Status Pro
2870: 74 6f 63 6f 6c 20 28 4f 53 43 50 29 20 55 52 4c  tocol (OSCP) URL
2880: 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c  . */.Tcl_Obj *Tl
2890: 73 5f 78 35 30 39 4f 73 63 70 28 54 63 6c 5f 49  s_x509Oscp(Tcl_I
28a0: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58  nterp *interp, X
28b0: 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20  509 *cert) {.   
28c0: 20 53 54 41 43 4b 5f 4f 46 28 4f 50 45 4e 53 53   STACK_OF(OPENSS
28d0: 4c 5f 53 54 52 49 4e 47 29 20 2a 6f 63 73 70 3b  L_STRING) *ocsp;
28e0: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69  .    Tcl_Obj *li
28f0: 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c  stPtr = Tcl_NewL
2900: 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b  istObj(0, NULL);
2910: 0a 0a 20 20 20 20 69 66 20 28 6c 69 73 74 50 74  ..    if (listPt
2920: 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65  r == NULL) {..re
2930: 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d  turn NULL;.    }
2940: 0a 0a 20 20 20 20 69 66 20 28 6f 63 73 70 20 3d  ..    if (ocsp =
2950: 20 58 35 30 39 5f 67 65 74 31 5f 6f 63 73 70 28   X509_get1_ocsp(
2960: 63 65 72 74 29 29 20 7b 0a 09 66 6f 72 20 28 69  cert)) {..for (i
2970: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b  nt i = 0; i < sk
2980: 5f 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e 47 5f  _OPENSSL_STRING_
2990: 6e 75 6d 28 6f 63 73 70 29 3b 20 69 2b 2b 29 20  num(ocsp); i++) 
29a0: 7b 0a 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 53  {..    LAPPEND_S
29b0: 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  TR(interp, listP
29c0: 74 72 2c 20 4e 55 4c 4c 2c 20 73 6b 5f 4f 50 45  tr, NULL, sk_OPE
29d0: 4e 53 53 4c 5f 53 54 52 49 4e 47 5f 76 61 6c 75  NSSL_STRING_valu
29e0: 65 28 6f 63 73 70 2c 20 69 29 2c 20 2d 31 29 3b  e(ocsp, i), -1);
29f0: 0a 09 7d 0a 09 58 35 30 39 5f 65 6d 61 69 6c 5f  ..}..X509_email_
2a00: 66 72 65 65 28 6f 63 73 70 29 3b 0a 20 20 20 20  free(ocsp);.    
2a10: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73  }.    return lis
2a20: 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47  tPtr;.}../*. * G
2a30: 65 74 20 43 65 72 74 69 66 69 63 61 74 65 20 41  et Certificate A
2a40: 75 74 68 6f 72 69 74 79 20 28 43 41 29 20 49 73  uthority (CA) Is
2a50: 73 75 65 72 73 20 55 52 4c 0a 20 2a 2f 0a 54 63  suers URL. */.Tc
2a60: 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 43  l_Obj *Tls_x509C
2a70: 61 49 73 73 75 65 72 73 28 54 63 6c 5f 49 6e 74  aIssuers(Tcl_Int
2a80: 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30  erp *interp, X50
2a90: 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 53  9 *cert) {.    S
2aa0: 54 41 43 4b 5f 4f 46 28 41 43 43 45 53 53 5f 44  TACK_OF(ACCESS_D
2ab0: 45 53 43 52 49 50 54 49 4f 4e 29 20 2a 61 64 73  ESCRIPTION) *ads
2ac0: 3b 0a 20 20 20 20 41 43 43 45 53 53 5f 44 45 53  ;.    ACCESS_DES
2ad0: 43 52 49 50 54 49 4f 4e 20 2a 61 64 3b 0a 20 20  CRIPTION *ad;.  
2ae0: 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50    Tcl_Obj *listP
2af0: 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74  tr = Tcl_NewList
2b00: 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20  Obj(0, NULL);.  
2b10: 20 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20    unsigned char 
2b20: 2a 62 75 66 3b 0a 20 20 20 20 69 6e 74 20 6c 65  *buf;.    int le
2b30: 6e 3b 0a 0a 20 20 20 20 69 66 20 28 61 64 73 20  n;..    if (ads 
2b40: 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64  = X509_get_ext_d
2b50: 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 69 6e 66  2i(cert, NID_inf
2b60: 6f 5f 61 63 63 65 73 73 2c 20 4e 55 4c 4c 2c 20  o_access, NULL, 
2b70: 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 28 69  NULL)) {..for (i
2b80: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b  nt i = 0; i < sk
2b90: 5f 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 54  _ACCESS_DESCRIPT
2ba0: 49 4f 4e 5f 6e 75 6d 28 61 64 73 29 3b 20 69 2b  ION_num(ads); i+
2bb0: 2b 29 20 7b 0a 09 20 20 20 20 61 64 20 3d 20 73  +) {..    ad = s
2bc0: 6b 5f 41 43 43 45 53 53 5f 44 45 53 43 52 49 50  k_ACCESS_DESCRIP
2bd0: 54 49 4f 4e 5f 76 61 6c 75 65 28 61 64 73 2c 20  TION_value(ads, 
2be0: 69 29 3b 0a 09 20 20 20 20 69 66 20 28 4f 42 4a  i);..    if (OBJ
2bf0: 5f 6f 62 6a 32 6e 69 64 28 61 64 2d 3e 6d 65 74  _obj2nid(ad->met
2c00: 68 6f 64 29 20 3d 3d 20 4e 49 44 5f 61 64 5f 63  hod) == NID_ad_c
2c10: 61 5f 69 73 73 75 65 72 73 20 26 26 20 61 64 2d  a_issuers && ad-
2c20: 3e 6c 6f 63 61 74 69 6f 6e 29 20 7b 0a 09 09 69  >location) {...i
2c30: 66 20 28 61 64 2d 3e 6c 6f 63 61 74 69 6f 6e 2d  f (ad->location-
2c40: 3e 74 79 70 65 20 3d 3d 20 47 45 4e 5f 55 52 49  >type == GEN_URI
2c50: 29 20 7b 0a 09 09 20 20 20 20 6c 65 6e 20 3d 20  ) {...    len = 
2c60: 41 53 4e 31 5f 53 54 52 49 4e 47 5f 74 6f 5f 55  ASN1_STRING_to_U
2c70: 54 46 38 28 26 62 75 66 2c 20 61 64 2d 3e 6c 6f  TF8(&buf, ad->lo
2c80: 63 61 74 69 6f 6e 2d 3e 64 2e 75 6e 69 66 6f 72  cation->d.unifor
2c90: 6d 52 65 73 6f 75 72 63 65 49 64 65 6e 74 69 66  mResourceIdentif
2ca0: 69 65 72 29 3b 0a 09 09 20 20 20 20 54 63 6c 5f  ier);...    Tcl_
2cb0: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
2cc0: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73  ment(interp, lis
2cd0: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
2ce0: 69 6e 67 4f 62 6a 28 62 75 66 2c 20 28 54 63 6c  ingObj(buf, (Tcl
2cf0: 5f 53 69 7a 65 29 20 6c 65 6e 29 29 3b 0a 09 09  _Size) len));...
2d00: 20 20 20 20 4f 50 45 4e 53 53 4c 5f 66 72 65 65      OPENSSL_free
2d10: 28 62 75 66 29 3b 0a 09 09 20 20 20 20 62 72 65  (buf);...    bre
2d20: 61 6b 3b 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09  ak;...}..    }..
2d30: 7d 0a 09 2f 2a 20 73 6b 5f 41 43 43 45 53 53 5f  }../* sk_ACCESS_
2d40: 44 45 53 43 52 49 50 54 49 4f 4e 5f 70 6f 70 5f  DESCRIPTION_pop_
2d50: 66 72 65 65 28 61 64 73 2c 20 41 43 43 45 53 53  free(ads, ACCESS
2d60: 5f 44 45 53 43 52 49 50 54 49 4f 4e 5f 66 72 65  _DESCRIPTION_fre
2d70: 65 29 3b 20 2a 2f 0a 09 41 55 54 48 4f 52 49 54  e); */..AUTHORIT
2d80: 59 5f 49 4e 46 4f 5f 41 43 43 45 53 53 5f 66 72  Y_INFO_ACCESS_fr
2d90: 65 65 28 61 64 73 29 3b 0a 20 20 20 20 7d 0a 20  ee(ads);.    }. 
2da0: 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74     return listPt
2db0: 72 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d  r;.}.../*. *----
2dc0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2dd0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2de0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2df0: 2d 2d 2a 0a 20 2a 0a 20 2a 09 54 6c 73 5f 4e 65  --*. *. *.Tls_Ne
2e00: 77 58 35 30 39 4f 62 6a 20 2d 2d 0a 20 2a 0a 20  wX509Obj --. *. 
2e10: 2a 09 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  *.--------------
2e20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2e30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2e40: 2d 2d 2a 0a 20 2a 09 43 6f 6e 76 65 72 74 73 20  --*. *.Converts 
2e50: 61 20 58 35 30 39 20 63 65 72 74 69 66 69 63 61  a X509 certifica
2e60: 74 65 20 69 6e 74 6f 20 61 20 54 63 6c 5f 4f 62  te into a Tcl_Ob
2e70: 6a 0a 20 2a 09 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  j. *.-----------
2e80: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2e90: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ea0: 2d 2d 2d 2d 2d 2a 0a 20 2a 0a 20 2a 09 53 69 64  -----*. *. *.Sid
2eb0: 65 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 09 4e  e effects:. *..N
2ec0: 6f 6e 65 0a 20 2a 0a 20 2a 09 52 65 73 75 6c 74  one. *. *.Result
2ed0: 3a 0a 20 2a 09 09 41 20 54 63 6c 20 4c 69 73 74  :. *..A Tcl List
2ee0: 20 4f 62 6a 65 63 74 20 72 65 70 72 65 73 65 6e   Object represen
2ef0: 74 69 6e 67 20 74 68 65 20 70 72 6f 76 69 64 65  ting the provide
2f00: 64 0a 20 2a 09 09 58 35 30 39 20 63 65 72 74 69  d. *..X509 certi
2f10: 66 69 63 61 74 65 2e 0a 20 2a 0a 20 2a 2d 2d 2d  ficate.. *. *---
2f20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2f50: 2d 2d 2d 2a 0a 20 2a 2f 0a 0a 54 63 6c 5f 4f 62  ---*. */..Tcl_Ob
2f60: 6a 2a 0a 54 6c 73 5f 4e 65 77 58 35 30 39 4f 62  j*.Tls_NewX509Ob
2f70: 6a 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e  j(Tcl_Interp *in
2f80: 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74  terp, X509 *cert
2f90: 29 20 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20  ) {.    Tcl_Obj 
2fa0: 2a 63 65 72 74 50 74 72 20 3d 20 54 63 6c 5f 4e  *certPtr = Tcl_N
2fb0: 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c  ewListObj(0, NUL
2fc0: 4c 29 3b 0a 20 20 20 20 42 49 4f 20 2a 62 69 6f  L);.    BIO *bio
2fd0: 20 3d 20 42 49 4f 5f 6e 65 77 28 42 49 4f 5f 73   = BIO_new(BIO_s
2fe0: 5f 6d 65 6d 28 29 29 3b 0a 20 20 20 20 69 6e 74  _mem());.    int
2ff0: 20 6d 64 6e 69 64 2c 20 70 6b 6e 69 64 2c 20 62   mdnid, pknid, b
3000: 69 74 73 2c 20 6c 65 6e 3b 0a 20 20 20 20 75 69  its, len;.    ui
3010: 6e 74 33 32 5f 74 20 78 66 6c 61 67 73 3b 0a 20  nt32_t xflags;. 
3020: 20 20 20 63 68 61 72 20 62 75 66 66 65 72 5b 42     char buffer[B
3030: 55 46 53 49 5a 5d 3b 0a 20 20 20 20 75 6e 73 69  UFSIZ];.    unsi
3040: 67 6e 65 64 20 63 68 61 72 20 6d 64 5b 45 56 50  gned char md[EVP
3050: 5f 4d 41 58 5f 4d 44 5f 53 49 5a 45 5d 3b 0a 20  _MAX_MD_SIZE];. 
3060: 20 20 20 75 6e 73 69 67 6e 65 64 20 6c 6f 6e 67     unsigned long
3070: 20 66 6c 61 67 73 20 3d 20 58 4e 5f 46 4c 41 47   flags = XN_FLAG
3080: 5f 52 46 43 32 32 35 33 20 7c 20 41 53 4e 31 5f  _RFC2253 | ASN1_
3090: 53 54 52 46 4c 47 53 5f 55 54 46 38 5f 43 4f 4e  STRFLGS_UTF8_CON
30a0: 56 45 52 54 3b 0a 20 20 20 20 66 6c 61 67 73 20  VERT;.    flags 
30b0: 26 3d 20 7e 41 53 4e 31 5f 53 54 52 46 4c 47 53  &= ~ASN1_STRFLGS
30c0: 5f 45 53 43 5f 4d 53 42 3b 0a 0a 20 20 20 20 69  _ESC_MSB;..    i
30d0: 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e 55 4c  f (interp == NUL
30e0: 4c 20 7c 7c 20 63 65 72 74 20 3d 3d 20 4e 55 4c  L || cert == NUL
30f0: 4c 20 7c 7c 20 62 69 6f 20 3d 3d 20 4e 55 4c 4c  L || bio == NULL
3100: 20 7c 7c 20 63 65 72 74 50 74 72 20 3d 3d 20 4e   || certPtr == N
3110: 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e  ULL) {..return N
3120: 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20  ULL;.    }..    
3130: 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61 6c 67  /* Signature alg
3140: 6f 72 69 74 68 6d 20 61 6e 64 20 76 61 6c 75 65  orithm and value
3150: 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74   - RFC 5280 sect
3160: 69 6f 6e 20 34 2e 31 2e 31 2e 32 20 61 6e 64 20  ion 4.1.1.2 and 
3170: 34 2e 31 2e 31 2e 33 20 2a 2f 0a 20 20 20 20 2f  4.1.1.3 */.    /
3180: 2a 20 73 69 67 6e 61 74 75 72 65 41 6c 67 6f 72  * signatureAlgor
3190: 69 74 68 6d 20 69 73 20 74 68 65 20 69 64 20 6f  ithm is the id o
31a0: 66 20 74 68 65 20 63 72 79 70 74 6f 67 72 61 70  f the cryptograp
31b0: 68 69 63 20 61 6c 67 6f 72 69 74 68 6d 20 75 73  hic algorithm us
31c0: 65 64 20 62 79 20 74 68 65 0a 09 43 41 20 74 6f  ed by the..CA to
31d0: 20 73 69 67 6e 20 74 68 69 73 20 63 65 72 74 2e   sign this cert.
31e0: 20 73 69 67 6e 61 74 75 72 65 56 61 6c 75 65 20   signatureValue 
31f0: 69 73 20 74 68 65 20 64 69 67 69 74 61 6c 20 73  is the digital s
3200: 69 67 6e 61 74 75 72 65 20 63 6f 6d 70 75 74 65  ignature compute
3210: 64 0a 09 75 70 6f 6e 20 74 68 65 20 41 53 4e 2e  d..upon the ASN.
3220: 31 20 44 45 52 20 65 6e 63 6f 64 65 64 20 74 62  1 DER encoded tb
3230: 73 43 65 72 74 69 66 69 63 61 74 65 2e 20 2a 2f  sCertificate. */
3240: 0a 20 20 20 20 7b 0a 09 63 6f 6e 73 74 20 58 35  .    {..const X5
3250: 30 39 5f 41 4c 47 4f 52 20 2a 73 69 67 5f 61 6c  09_ALGOR *sig_al
3260: 67 3b 0a 09 63 6f 6e 73 74 20 41 53 4e 31 5f 42  g;..const ASN1_B
3270: 49 54 5f 53 54 52 49 4e 47 20 2a 73 69 67 3b 0a  IT_STRING *sig;.
3280: 09 69 6e 74 20 73 69 67 5f 6e 69 64 3b 0a 0a 09  .int sig_nid;...
3290: 58 35 30 39 5f 67 65 74 30 5f 73 69 67 6e 61 74  X509_get0_signat
32a0: 75 72 65 28 26 73 69 67 2c 20 26 73 69 67 5f 61  ure(&sig, &sig_a
32b0: 6c 67 2c 20 63 65 72 74 29 3b 0a 09 2f 2a 20 73  lg, cert);../* s
32c0: 69 67 5f 6e 69 64 20 3d 20 58 35 30 39 5f 67 65  ig_nid = X509_ge
32d0: 74 5f 73 69 67 6e 61 74 75 72 65 5f 6e 69 64 28  t_signature_nid(
32e0: 63 65 72 74 29 20 2a 2f 0a 09 73 69 67 5f 6e 69  cert) */..sig_ni
32f0: 64 20 3d 20 4f 42 4a 5f 6f 62 6a 32 6e 69 64 28  d = OBJ_obj2nid(
3300: 73 69 67 5f 61 6c 67 2d 3e 61 6c 67 6f 72 69 74  sig_alg->algorit
3310: 68 6d 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54  hm);..LAPPEND_ST
3320: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
3330: 72 2c 20 22 73 69 67 6e 61 74 75 72 65 41 6c 67  r, "signatureAlg
3340: 6f 72 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e 69 64  orithm", OBJ_nid
3350: 32 6c 6e 28 73 69 67 5f 6e 69 64 29 2c 20 2d 31  2ln(sig_nid), -1
3360: 29 3b 0a 09 6c 65 6e 20 3d 20 28 73 69 67 5f 6e  );..len = (sig_n
3370: 69 64 20 21 3d 20 4e 49 44 5f 75 6e 64 65 66 29  id != NID_undef)
3380: 20 3f 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78   ? String_to_Hex
3390: 28 73 69 67 2d 3e 64 61 74 61 2c 20 73 69 67 2d  (sig->data, sig-
33a0: 3e 6c 65 6e 67 74 68 2c 20 62 75 66 66 65 72 2c  >length, buffer,
33b0: 20 42 55 46 53 49 5a 29 20 3a 20 30 3b 0a 09 4c   BUFSIZ) : 0;..L
33c0: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
33d0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 67  p, certPtr, "sig
33e0: 6e 61 74 75 72 65 56 61 6c 75 65 22 2c 20 62 75  natureValue", bu
33f0: 66 66 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29  ffer, (Tcl_Size)
3400: 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20   len);.    }..  
3410: 20 20 2f 2a 20 56 65 72 73 69 6f 6e 20 6f 66 20    /* Version of 
3420: 74 68 65 20 65 6e 63 6f 64 65 64 20 63 65 72 74  the encoded cert
3430: 69 66 69 63 61 74 65 20 2d 20 52 46 43 20 35 32  ificate - RFC 52
3440: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32  80 section 4.1.2
3450: 2e 31 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e  .1 */.    LAPPEN
3460: 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63  D_LONG(interp, c
3470: 65 72 74 50 74 72 2c 20 22 76 65 72 73 69 6f 6e  ertPtr, "version
3480: 22 2c 20 58 35 30 39 5f 67 65 74 5f 76 65 72 73  ", X509_get_vers
3490: 69 6f 6e 28 63 65 72 74 29 2b 31 29 3b 0a 0a 20  ion(cert)+1);.. 
34a0: 20 20 20 2f 2a 20 55 6e 69 71 75 65 20 6e 75 6d     /* Unique num
34b0: 62 65 72 20 61 73 73 69 67 6e 65 64 20 62 79 20  ber assigned by 
34c0: 43 41 20 74 6f 20 63 65 72 74 69 66 69 63 61 74  CA to certificat
34d0: 65 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63  e - RFC 5280 sec
34e0: 74 69 6f 6e 20 34 2e 31 2e 32 2e 32 20 2a 2f 0a  tion 4.1.2.2 */.
34f0: 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f      len = BIO_to
3500: 5f 42 75 66 66 65 72 28 69 32 61 5f 41 53 4e 31  _Buffer(i2a_ASN1
3510: 5f 49 4e 54 45 47 45 52 28 62 69 6f 2c 20 58 35  _INTEGER(bio, X5
3520: 30 39 5f 67 65 74 30 5f 73 65 72 69 61 6c 4e 75  09_get0_serialNu
3530: 6d 62 65 72 28 63 65 72 74 29 29 2c 20 62 69 6f  mber(cert)), bio
3540: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a  , buffer, BUFSIZ
3550: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53  );.    LAPPEND_S
3560: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  TR(interp, certP
3570: 74 72 2c 20 22 73 65 72 69 61 6c 4e 75 6d 62 65  tr, "serialNumbe
3580: 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c  r", buffer, (Tcl
3590: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20  _Size) len);..  
35a0: 20 20 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61    /* Signature a
35b0: 6c 67 6f 72 69 74 68 6d 20 75 73 65 64 20 62 79  lgorithm used by
35c0: 20 74 68 65 20 43 41 20 74 6f 20 73 69 67 6e 20   the CA to sign 
35d0: 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e  the certificate.
35e0: 20 4d 75 73 74 20 6d 61 74 63 68 0a 09 73 69 67   Must match..sig
35f0: 6e 61 74 75 72 65 41 6c 67 6f 72 69 74 68 6d 2e  natureAlgorithm.
3600: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
3610: 6e 20 34 2e 31 2e 32 2e 33 20 2a 2f 0a 20 20 20  n 4.1.2.3 */.   
3620: 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74   LAPPEND_STR(int
3630: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73  erp, certPtr, "s
3640: 69 67 6e 61 74 75 72 65 22 2c 20 4f 42 4a 5f 6e  ignature", OBJ_n
3650: 69 64 32 6c 6e 28 58 35 30 39 5f 67 65 74 5f 73  id2ln(X509_get_s
3660: 69 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 72  ignature_nid(cer
3670: 74 29 29 2c 20 2d 31 29 3b 0a 0a 20 20 20 20 2f  t)), -1);..    /
3680: 2a 20 49 73 73 75 65 72 20 69 64 65 6e 74 69 66  * Issuer identif
3690: 69 65 73 20 74 68 65 20 65 6e 74 69 74 79 20 74  ies the entity t
36a0: 68 61 74 20 73 69 67 6e 65 64 20 61 6e 64 20 69  hat signed and i
36b0: 73 73 75 65 64 20 74 68 65 20 63 65 72 74 2e 20  ssued the cert. 
36c0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
36d0: 20 34 2e 31 2e 32 2e 34 20 2a 2f 0a 20 20 20 20   4.1.2.4 */.    
36e0: 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66  len = BIO_to_Buf
36f0: 66 65 72 28 58 35 30 39 5f 4e 41 4d 45 5f 70 72  fer(X509_NAME_pr
3700: 69 6e 74 5f 65 78 28 62 69 6f 2c 20 58 35 30 39  int_ex(bio, X509
3710: 5f 67 65 74 5f 69 73 73 75 65 72 5f 6e 61 6d 65  _get_issuer_name
3720: 28 63 65 72 74 29 2c 20 30 2c 20 66 6c 61 67 73  (cert), 0, flags
3730: 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20  ), bio, buffer, 
3740: 42 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50  BUFSIZ);.    LAP
3750: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
3760: 20 63 65 72 74 50 74 72 2c 20 22 69 73 73 75 65   certPtr, "issue
3770: 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c  r", buffer, (Tcl
3780: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20  _Size) len);..  
3790: 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65    /* Certificate
37a0: 20 76 61 6c 69 64 69 74 79 20 70 65 72 69 6f 64   validity period
37b0: 20 69 73 20 74 68 65 20 69 6e 74 65 72 76 61 6c   is the interval
37c0: 20 74 68 65 20 43 41 20 77 61 72 72 61 6e 74 73   the CA warrants
37d0: 20 74 68 61 74 20 69 74 20 77 69 6c 6c 0a 09 6d   that it will..m
37e0: 61 69 6e 74 61 69 6e 20 69 6e 66 6f 20 6f 6e 20  aintain info on 
37f0: 74 68 65 20 73 74 61 74 75 73 20 6f 66 20 74 68  the status of th
3800: 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 52  e certificate. R
3810: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
3820: 34 2e 31 2e 32 2e 35 20 2a 2f 0a 20 20 20 20 2f  4.1.2.5 */.    /
3830: 2a 20 47 65 74 20 56 61 6c 69 64 69 74 79 20 2d  * Get Validity -
3840: 20 4e 6f 74 20 42 65 66 6f 72 65 20 2a 2f 0a 20   Not Before */. 
3850: 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f     len = BIO_to_
3860: 42 75 66 66 65 72 28 41 53 4e 31 5f 54 49 4d 45  Buffer(ASN1_TIME
3870: 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 35 30 39  _print(bio, X509
3880: 5f 67 65 74 30 5f 6e 6f 74 42 65 66 6f 72 65 28  _get0_notBefore(
3890: 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66  cert)), bio, buf
38a0: 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20  fer, BUFSIZ);.  
38b0: 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e    LAPPEND_STR(in
38c0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
38d0: 6e 6f 74 42 65 66 6f 72 65 22 2c 20 62 75 66 66  notBefore", buff
38e0: 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c  er, (Tcl_Size) l
38f0: 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74  en);..    /* Get
3900: 20 56 61 6c 69 64 69 74 79 20 2d 20 4e 6f 74 20   Validity - Not 
3910: 41 66 74 65 72 20 2a 2f 0a 20 20 20 20 6c 65 6e  After */.    len
3920: 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72   = BIO_to_Buffer
3930: 28 41 53 4e 31 5f 54 49 4d 45 5f 70 72 69 6e 74  (ASN1_TIME_print
3940: 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30 5f  (bio, X509_get0_
3950: 6e 6f 74 41 66 74 65 72 28 63 65 72 74 29 29 2c  notAfter(cert)),
3960: 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55   bio, buffer, BU
3970: 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45  FSIZ);.    LAPPE
3980: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
3990: 65 72 74 50 74 72 2c 20 22 6e 6f 74 41 66 74 65  ertPtr, "notAfte
39a0: 72 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c  r", buffer, (Tcl
39b0: 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20  _Size) len);..  
39c0: 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 69 64 65    /* Subject ide
39d0: 6e 74 69 66 69 65 73 20 74 68 65 20 65 6e 74 69  ntifies the enti
39e0: 74 79 20 61 73 73 6f 63 69 61 74 65 64 20 77 69  ty associated wi
39f0: 74 68 20 74 68 65 20 70 75 62 6c 69 63 20 6b 65  th the public ke
3a00: 79 20 73 74 6f 72 65 64 20 69 6e 0a 09 74 68 65  y stored in..the
3a10: 20 73 75 62 6a 65 63 74 20 70 75 62 6c 69 63 20   subject public 
3a20: 6b 65 79 20 66 69 65 6c 64 2e 20 52 46 43 20 35  key field. RFC 5
3a30: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e  280 section 4.1.
3a40: 32 2e 36 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d  2.6 */.    len =
3a50: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58   BIO_to_Buffer(X
3a60: 35 30 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f 65  509_NAME_print_e
3a70: 78 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 5f  x(bio, X509_get_
3a80: 73 75 62 6a 65 63 74 5f 6e 61 6d 65 28 63 65 72  subject_name(cer
3a90: 74 29 2c 20 30 2c 20 66 6c 61 67 73 29 2c 20 62  t), 0, flags), b
3aa0: 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53  io, buffer, BUFS
3ab0: 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44  IZ);.    LAPPEND
3ac0: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72  _STR(interp, cer
3ad0: 74 50 74 72 2c 20 22 73 75 62 6a 65 63 74 22 2c  tPtr, "subject",
3ae0: 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69   buffer, (Tcl_Si
3af0: 7a 65 29 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f  ze) len);..    /
3b00: 2a 20 53 48 41 31 20 44 69 67 65 73 74 20 28 46  * SHA1 Digest (F
3b10: 69 6e 67 65 72 70 72 69 6e 74 29 20 6f 66 20 63  ingerprint) of c
3b20: 65 72 74 20 2d 20 44 45 52 20 72 65 70 72 65 73  ert - DER repres
3b30: 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20  entation */.    
3b40: 69 66 20 28 58 35 30 39 5f 64 69 67 65 73 74 28  if (X509_digest(
3b50: 63 65 72 74 2c 20 45 56 50 5f 73 68 61 31 28 29  cert, EVP_sha1()
3b60: 2c 20 6d 64 2c 20 26 6c 65 6e 29 29 20 7b 0a 20  , md, &len)) {. 
3b70: 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f     len = String_
3b80: 74 6f 5f 48 65 78 28 6d 64 2c 20 6c 65 6e 2c 20  to_Hex(md, len, 
3b90: 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b  buffer, BUFSIZ);
3ba0: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e  ..LAPPEND_STR(in
3bb0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
3bc0: 73 68 61 31 5f 68 61 73 68 22 2c 20 62 75 66 66  sha1_hash", buff
3bd0: 65 72 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 6c  er, (Tcl_Size) l
3be0: 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20  en);.    }..    
3bf0: 2f 2a 20 53 48 41 32 35 36 20 44 69 67 65 73 74  /* SHA256 Digest
3c00: 20 28 46 69 6e 67 65 72 70 72 69 6e 74 29 20 6f   (Fingerprint) o
3c10: 66 20 63 65 72 74 20 2d 20 44 45 52 20 72 65 70  f cert - DER rep
3c20: 72 65 73 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20  resentation */. 
3c30: 20 20 20 69 66 20 28 58 35 30 39 5f 64 69 67 65     if (X509_dige
3c40: 73 74 28 63 65 72 74 2c 20 45 56 50 5f 73 68 61  st(cert, EVP_sha
3c50: 32 35 36 28 29 2c 20 6d 64 2c 20 26 6c 65 6e 29  256(), md, &len)
3c60: 29 20 7b 0a 20 20 20 20 6c 65 6e 20 3d 20 53 74  ) {.    len = St
3c70: 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20  ring_to_Hex(md, 
3c80: 6c 65 6e 2c 20 62 75 66 66 65 72 2c 20 42 55 46  len, buffer, BUF
3c90: 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53  SIZ);..LAPPEND_S
3ca0: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  TR(interp, certP
3cb0: 74 72 2c 20 22 73 68 61 32 35 36 5f 68 61 73 68  tr, "sha256_hash
3cc0: 22 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f  ", buffer, (Tcl_
3cd0: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 20  Size) len);.    
3ce0: 7d 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 63  }..    /* Subjec
3cf0: 74 20 50 75 62 6c 69 63 20 4b 65 79 20 49 6e 66  t Public Key Inf
3d00: 6f 20 73 70 65 63 69 66 69 65 73 20 74 68 65 20  o specifies the 
3d10: 70 75 62 6c 69 63 20 6b 65 79 20 61 6e 64 20 69  public key and i
3d20: 64 65 6e 74 69 66 69 65 73 20 74 68 65 0a 09 61  dentifies the..a
3d30: 6c 67 6f 72 69 74 68 6d 20 77 69 74 68 20 77 68  lgorithm with wh
3d40: 69 63 68 20 74 68 65 20 6b 65 79 20 69 73 20 75  ich the key is u
3d50: 73 65 64 2e 20 52 46 43 20 35 32 38 30 20 73 65  sed. RFC 5280 se
3d60: 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 37 20 2a 2f  ction 4.1.2.7 */
3d70: 0a 20 20 20 20 69 66 20 28 58 35 30 39 5f 67 65  .    if (X509_ge
3d80: 74 5f 73 69 67 6e 61 74 75 72 65 5f 69 6e 66 6f  t_signature_info
3d90: 28 63 65 72 74 2c 20 26 6d 64 6e 69 64 2c 20 26  (cert, &mdnid, &
3da0: 70 6b 6e 69 64 2c 20 26 62 69 74 73 2c 20 26 78  pknid, &bits, &x
3db0: 66 6c 61 67 73 29 29 20 7b 0a 09 41 53 4e 31 5f  flags)) {..ASN1_
3dc0: 42 49 54 5f 53 54 52 49 4e 47 20 2a 6b 65 79 3b  BIT_STRING *key;
3dd0: 0a 09 75 6e 73 69 67 6e 65 64 20 69 6e 74 20 6e  ..unsigned int n
3de0: 3b 0a 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28  ;...LAPPEND_STR(
3df0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
3e00: 20 22 73 69 67 6e 69 6e 67 44 69 67 65 73 74 22   "signingDigest"
3e10: 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 6d 64 6e  , OBJ_nid2ln(mdn
3e20: 69 64 29 2c 20 2d 31 29 3b 0a 09 4c 41 50 50 45  id), -1);..LAPPE
3e30: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
3e40: 65 72 74 50 74 72 2c 20 22 70 75 62 6c 69 63 4b  ertPtr, "publicK
3e50: 65 79 41 6c 67 6f 72 69 74 68 6d 22 2c 20 4f 42  eyAlgorithm", OB
3e60: 4a 5f 6e 69 64 32 6c 6e 28 70 6b 6e 69 64 29 2c  J_nid2ln(pknid),
3e70: 20 2d 31 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 49   -1);..LAPPEND_I
3e80: 4e 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  NT(interp, certP
3e90: 74 72 2c 20 22 62 69 74 73 22 2c 20 62 69 74 73  tr, "bits", bits
3ea0: 29 3b 20 2f 2a 20 45 66 66 65 63 74 69 76 65 20  ); /* Effective 
3eb0: 73 65 63 75 72 69 74 79 20 62 69 74 73 20 2a 2f  security bits */
3ec0: 0a 0a 09 6b 65 79 20 3d 20 58 35 30 39 5f 67 65  ...key = X509_ge
3ed0: 74 30 5f 70 75 62 6b 65 79 5f 62 69 74 73 74 72  t0_pubkey_bitstr
3ee0: 28 63 65 72 74 29 3b 0a 09 6c 65 6e 20 3d 20 53  (cert);..len = S
3ef0: 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6b 65 79  tring_to_Hex(key
3f00: 2d 3e 64 61 74 61 2c 20 6b 65 79 2d 3e 6c 65 6e  ->data, key->len
3f10: 67 74 68 2c 20 62 75 66 66 65 72 2c 20 42 55 46  gth, buffer, BUF
3f20: 53 49 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53  SIZ);..LAPPEND_S
3f30: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  TR(interp, certP
3f40: 74 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 22 2c  tr, "publicKey",
3f50: 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53 69   buffer, (Tcl_Si
3f60: 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 6c 65 6e 20  ze) len);...len 
3f70: 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f 70  = 0;..if (X509_p
3f80: 75 62 6b 65 79 5f 64 69 67 65 73 74 28 63 65 72  ubkey_digest(cer
3f90: 74 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65 73  t, EVP_get_diges
3fa0: 74 62 79 6e 69 64 28 70 6b 6e 69 64 29 2c 20 6d  tbynid(pknid), m
3fb0: 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20 6c  d, &n)) {..    l
3fc0: 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48  en = String_to_H
3fd0: 65 78 28 6d 64 2c 20 28 69 6e 74 29 6e 2c 20 62  ex(md, (int)n, b
3fe0: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a  uffer, BUFSIZ);.
3ff0: 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28  .}..LAPPEND_STR(
4000: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
4010: 20 22 70 75 62 6c 69 63 4b 65 79 48 61 73 68 22   "publicKeyHash"
4020: 2c 20 62 75 66 66 65 72 2c 20 28 54 63 6c 5f 53  , buffer, (Tcl_S
4030: 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 2f 2a 20  ize) len);.../* 
4040: 64 69 67 65 73 74 20 6f 66 20 74 68 65 20 44 45  digest of the DE
4050: 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e  R representation
4060: 20 6f 66 20 74 68 65 20 63 65 72 74 69 66 69 63   of the certific
4070: 61 74 65 20 2a 2f 0a 09 6c 65 6e 20 3d 20 30 3b  ate */..len = 0;
4080: 0a 09 69 66 20 28 58 35 30 39 5f 64 69 67 65 73  ..if (X509_diges
4090: 74 28 63 65 72 74 2c 20 45 56 50 5f 67 65 74 5f  t(cert, EVP_get_
40a0: 64 69 67 65 73 74 62 79 6e 69 64 28 6d 64 6e 69  digestbynid(mdni
40b0: 64 29 2c 20 6d 64 2c 20 26 6e 29 29 20 7b 0a 09  d), md, &n)) {..
40c0: 20 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67      len = String
40d0: 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 28 69 6e 74  _to_Hex(md, (int
40e0: 29 6e 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53  )n, buffer, BUFS
40f0: 49 5a 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e 44  IZ);..}..LAPPEND
4100: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72  _STR(interp, cer
4110: 74 50 74 72 2c 20 22 73 69 67 6e 61 74 75 72 65  tPtr, "signature
4120: 48 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20 28  Hash", buffer, (
4130: 54 63 6c 5f 53 69 7a 65 29 20 6c 65 6e 29 3b 0a  Tcl_Size) len);.
4140: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 43 65      }..    /* Ce
4150: 72 74 69 66 69 63 61 74 65 20 50 75 72 70 6f 73  rtificate Purpos
4160: 65 2e 20 43 61 6c 6c 20 62 65 66 6f 72 65 20 63  e. Call before c
4170: 68 65 63 6b 69 6e 67 20 66 6f 72 20 65 78 74 65  hecking for exte
4180: 6e 73 69 6f 6e 73 2e 20 2a 2f 0a 20 20 20 20 4c  nsions. */.    L
4190: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
41a0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75 72  p, certPtr, "pur
41b0: 70 6f 73 65 22 2c 20 54 6c 73 5f 78 35 30 39 50  pose", Tls_x509P
41c0: 75 72 70 6f 73 65 28 63 65 72 74 29 2c 20 2d 31  urpose(cert), -1
41d0: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f  );.    LAPPEND_O
41e0: 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  BJ(interp, certP
41f0: 74 72 2c 20 22 63 65 72 74 69 66 69 63 61 74 65  tr, "certificate
4200: 50 75 72 70 6f 73 65 22 2c 20 54 6c 73 5f 78 35  Purpose", Tls_x5
4210: 30 39 50 75 72 70 6f 73 65 73 28 69 6e 74 65 72  09Purposes(inter
4220: 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20  p, cert));..    
4230: 2f 2a 20 47 65 74 20 65 78 74 65 6e 73 69 6f 6e  /* Get extension
4240: 73 20 66 6c 61 67 73 20 2a 2f 0a 20 20 20 20 78  s flags */.    x
4250: 66 6c 61 67 73 20 3d 20 58 35 30 39 5f 67 65 74  flags = X509_get
4260: 5f 65 78 74 65 6e 73 69 6f 6e 5f 66 6c 61 67 73  _extension_flags
4270: 28 63 65 72 74 29 3b 0a 20 20 20 20 4c 41 50 50  (cert);.    LAPP
4280: 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20  END_INT(interp, 
4290: 63 65 72 74 50 74 72 2c 20 22 65 78 74 46 6c 61  certPtr, "extFla
42a0: 67 73 22 2c 20 78 66 6c 61 67 73 29 3b 0a 0a 09  gs", xflags);...
42b0: 2f 2a 20 43 68 65 63 6b 20 69 66 20 63 65 72 74  /* Check if cert
42c0: 20 77 61 73 20 69 73 73 75 65 64 20 62 79 20 43   was issued by C
42d0: 41 20 63 65 72 74 20 69 73 73 75 65 72 20 6f 72  A cert issuer or
42e0: 20 73 65 6c 66 20 73 69 67 6e 65 64 20 2a 2f 0a   self signed */.
42f0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c      LAPPEND_BOOL
4300: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
4310: 2c 20 22 73 65 6c 66 49 73 73 75 65 64 22 2c 20  , "selfIssued", 
4320: 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f  xflags & EXFLAG_
4330: 53 49 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44  SI);.    LAPPEND
4340: 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65  _BOOL(interp, ce
4350: 72 74 50 74 72 2c 20 22 73 65 6c 66 53 69 67 6e  rtPtr, "selfSign
4360: 65 64 22 2c 20 78 66 6c 61 67 73 20 26 20 45 58  ed", xflags & EX
4370: 46 4c 41 47 5f 53 53 29 3b 0a 20 20 20 20 4c 41  FLAG_SS);.    LA
4380: 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72  PPEND_BOOL(inter
4390: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 50  p, certPtr, "isP
43a0: 72 6f 78 79 43 65 72 74 22 2c 20 78 66 6c 61 67  roxyCert", xflag
43b0: 73 20 26 20 45 58 46 4c 41 47 5f 50 52 4f 58 59  s & EXFLAG_PROXY
43c0: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42  );.    LAPPEND_B
43d0: 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74  OOL(interp, cert
43e0: 50 74 72 2c 20 22 65 78 74 49 6e 76 61 6c 69 64  Ptr, "extInvalid
43f0: 22 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c  ", xflags & EXFL
4400: 41 47 5f 49 4e 56 41 4c 49 44 29 3b 0a 20 20 20  AG_INVALID);.   
4410: 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e   LAPPEND_BOOL(in
4420: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
4430: 69 73 43 41 43 65 72 74 22 2c 20 58 35 30 39 5f  isCACert", X509_
4440: 63 68 65 63 6b 5f 63 61 28 63 65 72 74 29 29 3b  check_ca(cert));
4450: 0a 0a 20 20 20 20 2f 2a 20 54 68 65 20 55 6e 69  ..    /* The Uni
4460: 71 75 65 20 49 64 73 20 61 72 65 20 75 73 65 64  que Ids are used
4470: 20 74 6f 20 68 61 6e 64 6c 65 20 74 68 65 20 70   to handle the p
4480: 6f 73 73 69 62 69 6c 69 74 79 20 6f 66 20 72 65  ossibility of re
4490: 75 73 65 20 6f 66 20 73 75 62 6a 65 63 74 0a 09  use of subject..
44a0: 61 6e 64 2f 6f 72 20 69 73 73 75 65 72 20 6e 61  and/or issuer na
44b0: 6d 65 73 20 6f 76 65 72 20 74 69 6d 65 2e 20 52  mes over time. R
44c0: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
44d0: 34 2e 31 2e 32 2e 38 20 2a 2f 0a 20 20 20 20 7b  4.1.2.8 */.    {
44e0: 0a 09 63 6f 6e 73 74 20 41 53 4e 31 5f 42 49 54  ..const ASN1_BIT
44f0: 5f 53 54 52 49 4e 47 20 2a 69 75 69 64 2c 20 2a  _STRING *iuid, *
4500: 73 75 69 64 3b 0a 20 20 20 20 20 20 20 20 58 35  suid;.        X5
4510: 30 39 5f 67 65 74 30 5f 75 69 64 73 28 63 65 72  09_get0_uids(cer
4520: 74 2c 20 26 69 75 69 64 2c 20 26 73 75 69 64 29  t, &iuid, &suid)
4530: 3b 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41  ;...Tcl_ListObjA
4540: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
4550: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63  erp, certPtr, Tc
4560: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
4570: 69 73 73 75 65 72 55 6e 69 71 75 65 49 64 22 2c  issuerUniqueId",
4580: 20 2d 31 29 29 3b 0a 09 69 66 20 28 69 75 69 64   -1));..if (iuid
4590: 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20   != NULL) {..   
45a0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
45b0: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
45c0: 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e  , certPtr, Tcl_N
45d0: 65 77 42 79 74 65 41 72 72 61 79 4f 62 6a 28 28  ewByteArrayObj((
45e0: 63 68 61 72 20 2a 29 69 75 69 64 2d 3e 64 61 74  char *)iuid->dat
45f0: 61 2c 20 28 54 63 6c 5f 53 69 7a 65 29 20 69 75  a, (Tcl_Size) iu
4600: 69 64 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 7d  id->length));..}
4610: 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 6c   else {..    Tcl
4620: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
4630: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65  ement(interp, ce
4640: 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  rtPtr, Tcl_NewSt
4650: 72 69 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 29  ringObj("", -1))
4660: 3b 0a 09 7d 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f  ;..}...Tcl_ListO
4670: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28  bjAppendElement(
4680: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
4690: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62   Tcl_NewStringOb
46a0: 6a 28 22 73 75 62 6a 65 63 74 55 6e 69 71 75 65  j("subjectUnique
46b0: 49 64 22 2c 20 2d 31 29 29 3b 0a 09 69 66 20 28  Id", -1));..if (
46c0: 73 75 69 64 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a  suid != NULL) {.
46d0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
46e0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
46f0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54  terp, certPtr, T
4700: 63 6c 5f 4e 65 77 42 79 74 65 41 72 72 61 79 4f  cl_NewByteArrayO
4710: 62 6a 28 28 63 68 61 72 20 2a 29 73 75 69 64 2d  bj((char *)suid-
4720: 3e 64 61 74 61 2c 20 28 54 63 6c 5f 53 69 7a 65  >data, (Tcl_Size
4730: 29 20 73 75 69 64 2d 3e 6c 65 6e 67 74 68 29 29  ) suid->length))
4740: 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20  ;..} else {..   
4750: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
4760: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
4770: 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e  , certPtr, Tcl_N
4780: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 22 2c 20  ewStringObj("", 
4790: 2d 31 29 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a  -1));..}.    }..
47a0: 20 20 20 20 2f 2a 20 58 35 30 39 20 76 33 20 45      /* X509 v3 E
47b0: 78 74 65 6e 73 69 6f 6e 73 20 2d 20 52 46 43 20  xtensions - RFC 
47c0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31  5280 section 4.1
47d0: 2e 32 2e 39 20 2a 2f 0a 20 20 20 20 4c 41 50 50  .2.9 */.    LAPP
47e0: 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20  END_INT(interp, 
47f0: 63 65 72 74 50 74 72 2c 20 22 65 78 74 43 6f 75  certPtr, "extCou
4800: 6e 74 22 2c 20 58 35 30 39 5f 67 65 74 5f 65 78  nt", X509_get_ex
4810: 74 5f 63 6f 75 6e 74 28 63 65 72 74 29 29 3b 0a  t_count(cert));.
4820: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28      LAPPEND_OBJ(
4830: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
4840: 20 22 65 78 74 65 6e 73 69 6f 6e 73 22 2c 20 54   "extensions", T
4850: 6c 73 5f 78 35 30 39 45 78 74 65 6e 73 69 6f 6e  ls_x509Extension
4860: 73 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 29  s(interp, cert))
4870: 3b 0a 0a 20 20 20 20 2f 2a 20 41 75 74 68 6f 72  ;..    /* Author
4880: 69 74 79 20 4b 65 79 20 49 64 65 6e 74 69 66 69  ity Key Identifi
4890: 65 72 20 28 41 4b 49 29 20 69 73 20 74 68 65 20  er (AKI) is the 
48a0: 53 75 62 6a 65 63 74 20 4b 65 79 20 49 64 65 6e  Subject Key Iden
48b0: 74 69 66 69 65 72 20 28 53 4b 49 29 20 6f 66 0a  tifier (SKI) of.
48c0: 09 69 74 73 20 73 69 67 6e 65 72 20 28 74 68 65  .its signer (the
48d0: 20 43 41 29 2e 20 52 46 43 20 35 32 38 30 20 73   CA). RFC 5280 s
48e0: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 2c 20  ection 4.2.1.1, 
48f0: 4e 49 44 5f 61 75 74 68 6f 72 69 74 79 5f 6b 65  NID_authority_ke
4900: 79 5f 69 64 65 6e 74 69 66 69 65 72 20 2a 2f 0a  y_identifier */.
4910: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28      LAPPEND_OBJ(
4920: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
4930: 20 22 61 75 74 68 6f 72 69 74 79 4b 65 79 49 64   "authorityKeyId
4940: 65 6e 74 69 66 69 65 72 22 2c 0a 09 54 6c 73 5f  entifier",..Tls_
4950: 78 35 30 39 49 64 65 6e 74 69 66 69 65 72 28 58  x509Identifier(X
4960: 35 30 39 5f 67 65 74 30 5f 61 75 74 68 6f 72 69  509_get0_authori
4970: 74 79 5f 6b 65 79 5f 69 64 28 63 65 72 74 29 29  ty_key_id(cert))
4980: 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65  );..    /* Subje
4990: 63 74 20 4b 65 79 20 49 64 65 6e 74 69 66 69 65  ct Key Identifie
49a0: 72 20 28 53 4b 49 29 20 69 73 20 75 73 65 64 20  r (SKI) is used 
49b0: 74 6f 20 69 64 65 6e 74 69 66 79 20 63 65 72 74  to identify cert
49c0: 69 66 69 63 61 74 65 73 20 74 68 61 74 20 63 6f  ificates that co
49d0: 6e 74 61 69 6e 0a 09 61 20 70 61 72 74 69 63 75  ntain..a particu
49e0: 6c 61 72 20 70 75 62 6c 69 63 20 6b 65 79 2e 20  lar public key. 
49f0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
4a00: 20 34 2e 32 2e 31 2e 32 2c 20 4e 49 44 5f 73 75   4.2.1.2, NID_su
4a10: 62 6a 65 63 74 5f 6b 65 79 5f 69 64 65 6e 74 69  bject_key_identi
4a20: 66 69 65 72 20 2a 2f 0a 20 20 20 20 4c 41 50 50  fier */.    LAPP
4a30: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20  END_OBJ(interp, 
4a40: 63 65 72 74 50 74 72 2c 20 22 73 75 62 6a 65 63  certPtr, "subjec
4a50: 74 4b 65 79 49 64 65 6e 74 69 66 69 65 72 22 2c  tKeyIdentifier",
4a60: 0a 09 54 6c 73 5f 78 35 30 39 49 64 65 6e 74 69  ..Tls_x509Identi
4a70: 66 69 65 72 28 58 35 30 39 5f 67 65 74 30 5f 73  fier(X509_get0_s
4a80: 75 62 6a 65 63 74 5f 6b 65 79 5f 69 64 28 63 65  ubject_key_id(ce
4a90: 72 74 29 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 4b  rt)));..    /* K
4aa0: 65 79 20 75 73 61 67 65 20 65 78 74 65 6e 73 69  ey usage extensi
4ab0: 6f 6e 20 64 65 66 69 6e 65 73 20 74 68 65 20 70  on defines the p
4ac0: 75 72 70 6f 73 65 20 28 65 2e 67 2e 2c 20 65 6e  urpose (e.g., en
4ad0: 63 69 70 68 65 72 6d 65 6e 74 2c 20 73 69 67 6e  cipherment, sign
4ae0: 61 74 75 72 65 2c 20 63 65 72 74 69 66 69 63 61  ature, certifica
4af0: 74 65 0a 09 73 69 67 6e 69 6e 67 29 20 6f 66 20  te..signing) of 
4b00: 74 68 65 20 6b 65 79 20 69 6e 20 74 68 65 20 63  the key in the c
4b10: 65 72 74 69 66 69 63 61 74 65 2e 20 52 46 43 20  ertificate. RFC 
4b20: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32  5280 section 4.2
4b30: 2e 31 2e 33 2c 20 4e 49 44 5f 6b 65 79 5f 75 73  .1.3, NID_key_us
4b40: 61 67 65 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45  age */.    LAPPE
4b50: 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63  ND_OBJ(interp, c
4b60: 65 72 74 50 74 72 2c 20 22 6b 65 79 55 73 61 67  ertPtr, "keyUsag
4b70: 65 22 2c 20 54 6c 73 5f 78 35 30 39 4b 65 79 55  e", Tls_x509KeyU
4b80: 73 61 67 65 28 69 6e 74 65 72 70 2c 20 63 65 72  sage(interp, cer
4b90: 74 2c 20 78 66 6c 61 67 73 29 29 3b 0a 0a 20 20  t, xflags));..  
4ba0: 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65    /* Certificate
4bb0: 20 50 6f 6c 69 63 69 65 73 20 2d 20 69 6e 64 69   Policies - indi
4bc0: 63 61 74 65 73 20 74 68 65 20 69 73 73 75 69 6e  cates the issuin
4bd0: 67 20 43 41 20 63 6f 6e 73 69 64 65 72 73 20 69  g CA considers i
4be0: 74 73 20 69 73 73 75 65 72 44 6f 6d 61 69 6e 50  ts issuerDomainP
4bf0: 6f 6c 69 63 79 0a 09 65 71 75 69 76 61 6c 65 6e  olicy..equivalen
4c00: 74 20 74 6f 20 74 68 65 20 73 75 62 6a 65 63 74  t to the subject
4c10: 20 43 41 27 73 20 73 75 62 6a 65 63 74 44 6f 6d   CA's subjectDom
4c20: 61 69 6e 50 6f 6c 69 63 79 2e 20 52 46 43 20 35  ainPolicy. RFC 5
4c30: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e  280 section 4.2.
4c40: 31 2e 34 2c 20 4e 49 44 5f 63 65 72 74 69 66 69  1.4, NID_certifi
4c50: 63 61 74 65 5f 70 6f 6c 69 63 69 65 73 20 2a 2f  cate_policies */
4c60: 0a 20 20 20 20 69 66 20 28 78 66 6c 61 67 73 20  .    if (xflags 
4c70: 26 20 45 58 46 4c 41 47 5f 49 4e 56 41 4c 49 44  & EXFLAG_INVALID
4c80: 5f 50 4f 4c 49 43 59 29 20 7b 0a 09 2f 2a 20 52  _POLICY) {../* R
4c90: 65 6a 65 63 74 20 63 65 72 74 20 2a 2f 0a 20 20  eject cert */.  
4ca0: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c 69    }..    /* Poli
4cb0: 63 79 20 4d 61 70 70 69 6e 67 73 20 2d 20 52 46  cy Mappings - RF
4cc0: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34  C 5280 section 4
4cd0: 2e 32 2e 31 2e 35 2c 20 4e 49 44 5f 70 6f 6c 69  .2.1.5, NID_poli
4ce0: 63 79 5f 6d 61 70 70 69 6e 67 73 20 2a 2f 0a 0a  cy_mappings */..
4cf0: 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 41      /* Subject A
4d00: 6c 74 65 72 6e 61 74 69 76 65 20 4e 61 6d 65 20  lternative Name 
4d10: 28 53 41 4e 29 20 63 6f 6e 74 61 69 6e 73 20 61  (SAN) contains a
4d20: 64 64 69 74 69 6f 6e 61 6c 20 55 52 4c 73 2c 20  dditional URLs, 
4d30: 44 4e 53 20 6e 61 6d 65 73 2c 20 6f 72 20 49 50  DNS names, or IP
4d40: 0a 09 61 64 64 72 65 73 73 65 73 20 62 6f 75 6e  ..addresses boun
4d50: 64 20 74 6f 20 63 65 72 74 69 66 69 63 61 74 65  d to certificate
4d60: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
4d70: 6f 6e 20 34 2e 32 2e 31 2e 36 2c 20 4e 49 44 5f  on 4.2.1.6, NID_
4d80: 73 75 62 6a 65 63 74 5f 61 6c 74 5f 6e 61 6d 65  subject_alt_name
4d90: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f   */.    LAPPEND_
4da0: 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74  OBJ(interp, cert
4db0: 50 74 72 2c 20 22 73 75 62 6a 65 63 74 41 6c 74  Ptr, "subjectAlt
4dc0: 4e 61 6d 65 22 2c 20 54 6c 73 5f 78 35 30 39 4e  Name", Tls_x509N
4dd0: 61 6d 65 73 28 69 6e 74 65 72 70 2c 20 63 65 72  ames(interp, cer
4de0: 74 2c 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f 61  t, NID_subject_a
4df0: 6c 74 5f 6e 61 6d 65 2c 20 62 69 6f 29 29 3b 0a  lt_name, bio));.
4e00: 0a 20 20 20 20 2f 2a 20 49 73 73 75 65 72 20 41  .    /* Issuer A
4e10: 6c 74 65 72 6e 61 74 69 76 65 20 4e 61 6d 65 20  lternative Name 
4e20: 69 73 20 75 73 65 64 20 74 6f 20 61 73 73 6f 63  is used to assoc
4e30: 69 61 74 65 20 49 6e 74 65 72 6e 65 74 20 73 74  iate Internet st
4e40: 79 6c 65 20 69 64 65 6e 74 69 74 69 65 73 0a 09  yle identities..
4e50: 77 69 74 68 20 74 68 65 20 63 65 72 74 69 66 69  with the certifi
4e60: 63 61 74 65 20 69 73 73 75 65 72 2e 20 52 46 43  cate issuer. RFC
4e70: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e   5280 section 4.
4e80: 32 2e 31 2e 37 2c 20 4e 49 44 5f 69 73 73 75 65  2.1.7, NID_issue
4e90: 72 5f 61 6c 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20  r_alt_name */.  
4ea0: 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e    LAPPEND_OBJ(in
4eb0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
4ec0: 69 73 73 75 65 72 41 6c 74 4e 61 6d 65 22 2c 20  issuerAltName", 
4ed0: 54 6c 73 5f 78 35 30 39 4e 61 6d 65 73 28 69 6e  Tls_x509Names(in
4ee0: 74 65 72 70 2c 20 63 65 72 74 2c 20 4e 49 44 5f  terp, cert, NID_
4ef0: 69 73 73 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 2c  issuer_alt_name,
4f00: 20 62 69 6f 29 29 3b 0a 0a 20 20 20 20 2f 2a 20   bio));..    /* 
4f10: 53 75 62 6a 65 63 74 20 44 69 72 65 63 74 6f 72  Subject Director
4f20: 79 20 41 74 74 72 69 62 75 74 65 73 20 70 72 6f  y Attributes pro
4f30: 76 69 64 65 73 20 69 64 65 6e 74 69 66 69 63 61  vides identifica
4f40: 74 69 6f 6e 20 61 74 74 72 69 62 75 74 65 73 20  tion attributes 
4f50: 28 65 2e 67 2e 2c 20 6e 61 74 69 6f 6e 61 6c 69  (e.g., nationali
4f60: 74 79 29 0a 09 6f 66 20 74 68 65 20 73 75 62 6a  ty)..of the subj
4f70: 65 63 74 2e 20 52 46 43 20 35 32 38 30 20 73 65  ect. RFC 5280 se
4f80: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 38 20 28 73  ction 4.2.1.8 (s
4f90: 75 62 6a 65 63 74 44 69 72 65 63 74 6f 72 79 41  ubjectDirectoryA
4fa0: 74 74 72 69 62 75 74 65 73 29 20 2a 2f 0a 0a 20  ttributes) */.. 
4fb0: 20 20 20 2f 2a 20 42 61 73 69 63 20 43 6f 6e 73     /* Basic Cons
4fc0: 74 72 61 69 6e 74 73 20 69 64 65 6e 74 69 66 69  traints identifi
4fd0: 65 73 20 77 68 65 74 68 65 72 20 74 68 65 20 73  es whether the s
4fe0: 75 62 6a 65 63 74 20 6f 66 20 74 68 65 20 63 65  ubject of the ce
4ff0: 72 74 20 69 73 20 61 20 43 41 20 61 6e 64 0a 09  rt is a CA and..
5000: 74 68 65 20 6d 61 78 20 64 65 70 74 68 20 6f 66  the max depth of
5010: 20 76 61 6c 69 64 20 63 65 72 74 20 70 61 74 68   valid cert path
5020: 73 20 66 6f 72 20 74 68 69 73 20 63 65 72 74 2e  s for this cert.
5030: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
5040: 6e 20 34 2e 32 2e 31 2e 39 2c 20 4e 49 44 5f 62  n 4.2.1.9, NID_b
5050: 61 73 69 63 5f 63 6f 6e 73 74 72 61 69 6e 74 73  asic_constraints
5060: 20 2a 2f 0a 20 20 20 20 69 66 20 28 21 28 78 66   */.    if (!(xf
5070: 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 50 52  lags & EXFLAG_PR
5080: 4f 58 59 29 29 20 7b 0a 09 4c 41 50 50 45 4e 44  OXY)) {..LAPPEND
5090: 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63 65  _LONG(interp, ce
50a0: 72 74 50 74 72 2c 20 22 70 61 74 68 4c 65 6e 22  rtPtr, "pathLen"
50b0: 2c 20 58 35 30 39 5f 67 65 74 5f 70 61 74 68 6c  , X509_get_pathl
50c0: 65 6e 28 63 65 72 74 29 29 3b 0a 20 20 20 20 7d  en(cert));.    }
50d0: 20 65 6c 73 65 20 7b 0a 09 4c 41 50 50 45 4e 44   else {..LAPPEND
50e0: 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63 65  _LONG(interp, ce
50f0: 72 74 50 74 72 2c 20 22 70 61 74 68 4c 65 6e 22  rtPtr, "pathLen"
5100: 2c 20 58 35 30 39 5f 67 65 74 5f 70 72 6f 78 79  , X509_get_proxy
5110: 5f 70 61 74 68 6c 65 6e 28 63 65 72 74 29 29 3b  _pathlen(cert));
5120: 0a 20 20 20 20 7d 0a 20 20 20 20 4c 41 50 50 45  .    }.    LAPPE
5130: 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20  ND_BOOL(interp, 
5140: 63 65 72 74 50 74 72 2c 20 22 62 61 73 69 63 43  certPtr, "basicC
5150: 6f 6e 73 74 72 61 69 6e 74 73 43 41 22 2c 20 78  onstraintsCA", x
5160: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 43  flags & EXFLAG_C
5170: 41 29 3b 0a 0a 20 20 20 20 2f 2a 20 4e 61 6d 65  A);..    /* Name
5180: 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 73 20   Constraints is 
5190: 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 43 41 20  only used in CA 
51a0: 63 65 72 74 73 20 74 6f 20 69 6e 64 69 63 61 74  certs to indicat
51b0: 65 20 74 68 65 20 6e 61 6d 65 20 73 70 61 63 65  e the name space
51c0: 20 66 6f 72 0a 09 61 6c 6c 20 73 75 62 6a 65 63   for..all subjec
51d0: 74 20 6e 61 6d 65 73 20 69 6e 20 73 75 62 73 65  t names in subse
51e0: 71 75 65 6e 74 20 63 65 72 74 69 66 69 63 61 74  quent certificat
51f0: 65 73 20 69 6e 20 61 20 63 65 72 74 69 66 69 63  es in a certific
5200: 61 74 69 6f 6e 20 70 61 74 68 0a 09 4d 55 53 54  ation path..MUST
5210: 20 62 65 20 6c 6f 63 61 74 65 64 2e 20 52 46 43   be located. RFC
5220: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e   5280 section 4.
5230: 32 2e 31 2e 31 30 2c 20 4e 49 44 5f 6e 61 6d 65  2.1.10, NID_name
5240: 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a  _constraints */.
5250: 0a 20 20 20 20 2f 2a 20 50 6f 6c 69 63 79 20 43  .    /* Policy C
5260: 6f 6e 73 74 72 61 69 6e 74 73 20 69 73 20 6f 6e  onstraints is on
5270: 6c 79 20 75 73 65 64 20 69 6e 20 43 41 20 63 65  ly used in CA ce
5280: 72 74 73 20 74 6f 20 6c 69 6d 69 74 20 74 68 65  rts to limit the
5290: 20 6c 65 6e 67 74 68 20 6f 66 20 61 0a 09 63 65   length of a..ce
52a0: 72 74 20 63 68 61 69 6e 20 66 6f 72 20 74 68 61  rt chain for tha
52b0: 74 20 43 41 2e 20 52 46 43 20 35 32 38 30 20 73  t CA. RFC 5280 s
52c0: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 31 2c  ection 4.2.1.11,
52d0: 20 4e 49 44 5f 70 6f 6c 69 63 79 5f 63 6f 6e 73   NID_policy_cons
52e0: 74 72 61 69 6e 74 73 20 2a 2f 0a 0a 20 20 20 20  traints */..    
52f0: 2f 2a 20 45 78 74 65 6e 64 65 64 20 4b 65 79 20  /* Extended Key 
5300: 55 73 61 67 65 20 69 6e 64 69 63 61 74 65 73 20  Usage indicates 
5310: 74 68 65 20 70 75 72 70 6f 73 65 73 20 74 68 65  the purposes the
5320: 20 63 65 72 74 69 66 69 65 64 20 70 75 62 6c 69   certified publi
5330: 63 20 6b 65 79 20 6d 61 79 20 62 65 0a 09 75 73  c key may be..us
5340: 65 64 2c 20 62 65 79 6f 6e 64 20 74 68 65 20 62  ed, beyond the b
5350: 61 73 69 63 20 70 75 72 70 6f 73 65 73 2e 20 52  asic purposes. R
5360: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
5370: 34 2e 32 2e 31 2e 31 32 2c 20 4e 49 44 5f 65 78  4.2.1.12, NID_ex
5380: 74 5f 6b 65 79 5f 75 73 61 67 65 20 2a 2f 0a 20  t_key_usage */. 
5390: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69     LAPPEND_OBJ(i
53a0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
53b0: 22 65 78 74 65 6e 64 65 64 4b 65 79 55 73 61 67  "extendedKeyUsag
53c0: 65 22 2c 20 54 6c 73 5f 78 35 30 39 45 78 74 4b  e", Tls_x509ExtK
53d0: 65 79 55 73 61 67 65 28 69 6e 74 65 72 70 2c 20  eyUsage(interp, 
53e0: 63 65 72 74 2c 20 78 66 6c 61 67 73 29 29 3b 0a  cert, xflags));.
53f0: 0a 20 20 20 20 2f 2a 20 43 52 4c 20 44 69 73 74  .    /* CRL Dist
5400: 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e 74 73 20  ribution Points 
5410: 69 64 65 6e 74 69 66 69 65 73 20 77 68 65 72 65  identifies where
5420: 20 43 52 4c 20 69 6e 66 6f 72 6d 61 74 69 6f 6e   CRL information
5430: 20 63 61 6e 20 62 65 20 6f 62 74 61 69 6e 65 64   can be obtained
5440: 2e 0a 09 52 46 43 20 35 32 38 30 20 73 65 63 74  ...RFC 5280 sect
5450: 69 6f 6e 20 34 2e 32 2e 31 2e 31 33 2a 2f 0a 20  ion 4.2.1.13*/. 
5460: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69     LAPPEND_OBJ(i
5470: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
5480: 22 63 72 6c 44 69 73 74 72 69 62 75 74 69 6f 6e  "crlDistribution
5490: 50 6f 69 6e 74 73 22 2c 20 54 6c 73 5f 78 35 30  Points", Tls_x50
54a0: 39 43 72 6c 44 70 28 69 6e 74 65 72 70 2c 20 63  9CrlDp(interp, c
54b0: 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 46  ert));..    /* F
54c0: 72 65 73 68 65 73 74 20 43 52 4c 20 65 78 74 65  reshest CRL exte
54d0: 6e 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 66 20  nsion */.    if 
54e0: 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47  (xflags & EXFLAG
54f0: 5f 46 52 45 53 48 45 53 54 29 20 7b 0a 20 20 20  _FRESHEST) {.   
5500: 20 7d 0a 0a 20 20 20 20 2f 2a 20 41 75 74 68 6f   }..    /* Autho
5510: 72 69 74 79 20 49 6e 66 6f 72 6d 61 74 69 6f 6e  rity Information
5520: 20 41 63 63 65 73 73 20 69 6e 64 69 63 61 74 65   Access indicate
5530: 73 20 68 6f 77 20 74 6f 20 61 63 63 65 73 73 20  s how to access 
5540: 69 6e 66 6f 20 61 6e 64 20 73 65 72 76 69 63 65  info and service
5550: 73 0a 09 66 6f 72 20 74 68 65 20 63 65 72 74 69  s..for the certi
5560: 66 69 63 61 74 65 20 69 73 73 75 65 72 2e 20 52  ficate issuer. R
5570: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
5580: 34 2e 32 2e 32 2e 31 2c 20 4e 49 44 5f 69 6e 66  4.2.2.1, NID_inf
5590: 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a 20 20 20  o_access */..   
55a0: 20 2f 2a 20 47 65 74 20 4f 6e 2d 6c 69 6e 65 20   /* Get On-line 
55b0: 43 65 72 74 69 66 69 63 61 74 65 20 53 74 61 74  Certificate Stat
55c0: 75 73 20 50 72 6f 74 6f 63 6f 6c 20 28 4f 53 43  us Protocol (OSC
55d0: 50 29 20 52 65 73 70 6f 6e 64 65 72 73 20 55 52  P) Responders UR
55e0: 4c 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44  L */.    LAPPEND
55f0: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72  _OBJ(interp, cer
5600: 74 50 74 72 2c 20 22 6f 63 73 70 52 65 73 70 6f  tPtr, "ocspRespo
5610: 6e 64 65 72 73 22 2c 20 54 6c 73 5f 78 35 30 39  nders", Tls_x509
5620: 4f 73 63 70 28 69 6e 74 65 72 70 2c 20 63 65 72  Oscp(interp, cer
5630: 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74  t));..    /* Get
5640: 20 43 65 72 74 69 66 69 63 61 74 65 20 41 75 74   Certificate Aut
5650: 68 6f 72 69 74 79 20 28 43 41 29 20 49 73 73 75  hority (CA) Issu
5660: 65 72 73 20 55 52 4c 20 2a 2f 0a 20 20 20 20 4c  ers URL */.    L
5670: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72  APPEND_OBJ(inter
5680: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 61 49  p, certPtr, "caI
5690: 73 73 75 65 72 73 22 2c 20 54 6c 73 5f 78 35 30  ssuers", Tls_x50
56a0: 39 43 61 49 73 73 75 65 72 73 28 69 6e 74 65 72  9CaIssuers(inter
56b0: 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20  p, cert));..    
56c0: 2f 2a 20 53 75 62 6a 65 63 74 20 49 6e 66 6f 72  /* Subject Infor
56d0: 6d 61 74 69 6f 6e 20 41 63 63 65 73 73 20 2d 20  mation Access - 
56e0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
56f0: 20 34 2e 32 2e 32 2e 32 2c 20 4e 49 44 5f 73 69   4.2.2.2, NID_si
5700: 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a 20  nfo_access */.. 
5710: 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74     /* Certificat
5720: 65 20 41 6c 69 61 73 2e 20 49 66 20 75 73 65 73  e Alias. If uses
5730: 20 61 20 50 4b 43 53 23 31 32 20 73 74 72 75 63   a PKCS#12 struc
5740: 74 75 72 65 2c 20 61 6c 69 61 73 20 77 69 6c 6c  ture, alias will
5750: 20 72 65 66 6c 65 63 74 20 74 68 65 0a 09 66 72   reflect the..fr
5760: 69 65 6e 64 6c 79 4e 61 6d 65 20 61 74 74 72 69  iendlyName attri
5770: 62 75 74 65 20 28 52 46 43 20 32 39 38 35 29 2e  bute (RFC 2985).
5780: 20 2a 2f 0a 20 20 20 20 7b 0a 09 6c 65 6e 20 3d   */.    {..len =
5790: 20 30 3b 0a 20 20 20 20 20 20 20 20 63 68 61 72   0;.        char
57a0: 20 2a 73 74 72 69 6e 67 20 3d 20 58 35 30 39 5f   *string = X509_
57b0: 61 6c 69 61 73 5f 67 65 74 30 28 63 65 72 74 2c  alias_get0(cert,
57c0: 20 26 6c 65 6e 29 3b 0a 09 4c 41 50 50 45 4e 44   &len);..LAPPEND
57d0: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72  _STR(interp, cer
57e0: 74 50 74 72 2c 20 22 61 6c 69 61 73 22 2c 20 73  tPtr, "alias", s
57f0: 74 72 69 6e 67 2c 20 28 54 63 6c 5f 53 69 7a 65  tring, (Tcl_Size
5800: 29 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20  ) len);.    }.. 
5810: 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74     /* Certificat
5820: 65 20 61 6e 64 20 64 75 6d 70 20 61 6c 6c 20 64  e and dump all d
5830: 61 74 61 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 68  ata */.    {..ch
5840: 61 72 20 63 65 72 74 53 74 72 5b 43 45 52 54 5f  ar certStr[CERT_
5850: 53 54 52 5f 53 49 5a 45 5d 3b 0a 0a 09 2f 2a 20  STR_SIZE];.../* 
5860: 47 65 74 20 63 65 72 74 69 66 69 63 61 74 65 20  Get certificate 
5870: 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f  */..len = BIO_to
5880: 5f 42 75 66 66 65 72 28 50 45 4d 5f 77 72 69 74  _Buffer(PEM_writ
5890: 65 5f 62 69 6f 5f 58 35 30 39 28 62 69 6f 2c 20  e_bio_X509(bio, 
58a0: 63 65 72 74 29 2c 20 62 69 6f 2c 20 63 65 72 74  cert), bio, cert
58b0: 53 74 72 2c 20 43 45 52 54 5f 53 54 52 5f 53 49  Str, CERT_STR_SI
58c0: 5a 45 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54  ZE);..LAPPEND_ST
58d0: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
58e0: 72 2c 20 22 63 65 72 74 69 66 69 63 61 74 65 22  r, "certificate"
58f0: 2c 20 63 65 72 74 53 74 72 2c 20 28 54 63 6c 5f  , certStr, (Tcl_
5900: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 0a 09 2f 2a  Size) len);.../*
5910: 20 47 65 74 20 61 6c 6c 20 63 65 72 74 20 69 6e   Get all cert in
5920: 66 6f 20 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f  fo */..len = BIO
5930: 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39 5f  _to_Buffer(X509_
5940: 70 72 69 6e 74 5f 65 78 28 62 69 6f 2c 20 63 65  print_ex(bio, ce
5950: 72 74 2c 20 66 6c 61 67 73 2c 20 30 29 2c 20 62  rt, flags, 0), b
5960: 69 6f 2c 20 63 65 72 74 53 74 72 2c 20 43 45 52  io, certStr, CER
5970: 54 5f 53 54 52 5f 53 49 5a 45 29 3b 0a 09 4c 41  T_STR_SIZE);..LA
5980: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
5990: 2c 20 63 65 72 74 50 74 72 2c 20 22 61 6c 6c 22  , certPtr, "all"
59a0: 2c 20 63 65 72 74 53 74 72 2c 20 28 54 63 6c 5f  , certStr, (Tcl_
59b0: 53 69 7a 65 29 20 6c 65 6e 29 3b 0a 20 20 20 20  Size) len);.    
59c0: 7d 0a 0a 20 20 20 20 42 49 4f 5f 66 72 65 65 28  }..    BIO_free(
59d0: 62 69 6f 29 3b 0a 20 20 20 20 72 65 74 75 72 6e  bio);.    return
59e0: 20 63 65 72 74 50 74 72 3b 0a 7d 0a               certPtr;.}.