Hex Artifact Content

Artifact 135215c951fb37f6923601dc43de213b9e6b761f99ca7e798481e820aabc7b98:


0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20  /*. * Copyright 
0010: 28 43 29 20 31 39 39 37 2d 32 30 30 30 20 53 65  (C) 1997-2000 Se
0020: 6e 73 75 73 20 43 6f 6e 73 75 6c 74 69 6e 67 20  nsus Consulting 
0030: 4c 74 64 2e 0a 20 2a 20 4d 61 74 74 20 4e 65 77  Ltd.. * Matt New
0040: 6d 61 6e 20 3c 6d 61 74 74 40 73 65 6e 73 75 73  man <matt@sensus
0050: 2e 6f 72 67 3e 0a 20 2a 20 43 6f 70 79 72 69 67  .org>. * Copyrig
0060: 68 74 20 28 43 29 20 32 30 32 33 20 42 72 69 61  ht (C) 2023 Bria
0070: 6e 20 4f 27 48 61 67 61 6e 0a 20 2a 2f 0a 23 69  n O'Hagan. */.#i
0080: 6e 63 6c 75 64 65 20 3c 74 63 6c 2e 68 3e 0a 23  nclude <tcl.h>.#
0090: 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68  include <stdio.h
00a0: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e  >.#include <open
00b0: 73 73 6c 2f 62 69 6f 2e 68 3e 0a 23 69 6e 63 6c  ssl/bio.h>.#incl
00c0: 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 73 68 61  ude <openssl/sha
00d0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70  .h>.#include <op
00e0: 65 6e 73 73 6c 2f 78 35 30 39 2e 68 3e 0a 23 69  enssl/x509.h>.#i
00f0: 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f  nclude <openssl/
0100: 78 35 30 39 76 33 2e 68 3e 0a 23 69 6e 63 6c 75  x509v3.h>.#inclu
0110: 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 78 35 30 39  de <openssl/x509
0120: 5f 76 66 79 2e 68 3e 0a 23 69 6e 63 6c 75 64 65  _vfy.h>.#include
0130: 20 3c 6f 70 65 6e 73 73 6c 2f 61 73 6e 31 2e 68   <openssl/asn1.h
0140: 3e 0a 23 69 6e 63 6c 75 64 65 20 22 74 6c 73 49  >.#include "tlsI
0150: 6e 74 2e 68 22 0a 0a 2f 2a 20 44 65 66 69 6e 65  nt.h"../* Define
0160: 20 6d 61 78 69 6d 75 6d 20 63 65 72 74 69 66 69   maximum certifi
0170: 63 61 74 65 20 73 69 7a 65 2e 20 4d 61 78 20 50  cate size. Max P
0180: 45 4d 20 73 69 7a 65 20 31 30 30 6b 42 20 61 6e  EM size 100kB an
0190: 64 20 44 45 52 20 73 69 7a 65 20 69 73 20 32 34  d DER size is 24
01a0: 6b 42 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43  kB. */.#define C
01b0: 45 52 54 5f 53 54 52 5f 53 49 5a 45 20 33 32 37  ERT_STR_SIZE 327
01c0: 36 38 0a 0a 0c 0a 2f 2a 0a 20 2a 20 42 69 6e 61  68..../*. * Bina
01d0: 72 79 20 73 74 72 69 6e 67 20 74 6f 20 68 65 78  ry string to hex
01e0: 20 73 74 72 69 6e 67 0a 20 2a 2f 0a 69 6e 74 20   string. */.int 
01f0: 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 75 6e  String_to_Hex(un
0200: 73 69 67 6e 65 64 20 63 68 61 72 2a 20 69 6e 70  signed char* inp
0210: 75 74 2c 20 69 6e 74 20 69 6c 65 6e 2c 20 75 6e  ut, int ilen, un
0220: 73 69 67 6e 65 64 20 63 68 61 72 20 2a 6f 75 74  signed char *out
0230: 70 75 74 2c 20 69 6e 74 20 6f 6c 65 6e 29 20 7b  put, int olen) {
0240: 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d  .    int count =
0250: 20 30 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 64   0;.    unsigned
0260: 20 63 68 61 72 20 2a 69 70 74 72 20 3d 20 69 6e   char *iptr = in
0270: 70 75 74 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65  put;.    unsigne
0280: 64 20 63 68 61 72 20 2a 6f 70 74 72 20 3d 20 26  d char *optr = &
0290: 6f 75 74 70 75 74 5b 30 5d 3b 0a 20 20 20 20 63  output[0];.    c
02a0: 6f 6e 73 74 20 63 68 61 72 20 2a 68 65 78 20 3d  onst char *hex =
02b0: 20 22 30 31 32 33 34 35 36 37 38 39 41 42 43 44   "0123456789ABCD
02c0: 45 46 22 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69  EF";..    for (i
02d0: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 69 6c  nt i = 0; i < il
02e0: 65 6e 20 26 26 20 63 6f 75 6e 74 20 3c 20 6f 6c  en && count < ol
02f0: 65 6e 20 2d 20 31 3b 20 69 2b 2b 2c 20 63 6f 75  en - 1; i++, cou
0300: 6e 74 20 2b 3d 20 32 29 20 7b 0a 20 20 20 20 20  nt += 2) {.     
0310: 20 20 20 2a 6f 70 74 72 2b 2b 20 3d 20 68 65 78     *optr++ = hex
0320: 5b 28 2a 69 70 74 72 3e 3e 34 29 26 30 78 46 5d  [(*iptr>>4)&0xF]
0330: 3b 0a 20 20 20 20 20 20 20 20 2a 6f 70 74 72 2b  ;.        *optr+
0340: 2b 20 3d 20 68 65 78 5b 28 2a 69 70 74 72 2b 2b  + = hex[(*iptr++
0350: 29 26 30 78 46 5d 3b 0a 20 20 20 20 7d 0a 20 20  )&0xF];.    }.  
0360: 20 20 2a 6f 70 74 72 20 3d 20 30 3b 0a 20 20 20    *optr = 0;.   
0370: 20 72 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 7d   return count;.}
0380: 0a 0a 2f 2a 0a 20 2a 20 42 49 4f 20 74 6f 20 42  ../*. * BIO to B
0390: 75 66 66 65 72 0a 20 2a 2f 0a 69 6e 74 20 42 49  uffer. */.int BI
03a0: 4f 5f 74 6f 5f 42 75 66 66 65 72 28 69 6e 74 20  O_to_Buffer(int 
03b0: 72 65 73 75 6c 74 2c 20 42 49 4f 20 2a 62 69 6f  result, BIO *bio
03c0: 2c 20 76 6f 69 64 20 2a 62 75 66 66 65 72 2c 20  , void *buffer, 
03d0: 69 6e 74 20 73 69 7a 65 29 20 7b 0a 20 20 20 20  int size) {.    
03e0: 69 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20  int len = 0;.   
03f0: 20 69 6e 74 20 70 65 6e 64 69 6e 67 20 3d 20 42   int pending = B
0400: 49 4f 5f 70 65 6e 64 69 6e 67 28 62 69 6f 29 3b  IO_pending(bio);
0410: 0a 0a 20 20 20 20 69 66 20 28 72 65 73 75 6c 74  ..    if (result
0420: 29 20 7b 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 72  ) {..len = BIO_r
0430: 65 61 64 28 62 69 6f 2c 20 62 75 66 66 65 72 2c  ead(bio, buffer,
0440: 20 28 70 65 6e 64 69 6e 67 20 3c 20 73 69 7a 65   (pending < size
0450: 29 20 3f 20 70 65 6e 64 69 6e 67 20 3a 20 73 69  ) ? pending : si
0460: 7a 65 29 3b 0a 09 28 76 6f 69 64 29 42 49 4f 5f  ze);..(void)BIO_
0470: 66 6c 75 73 68 28 62 69 6f 29 3b 0a 09 69 66 20  flush(bio);..if 
0480: 28 6c 65 6e 20 3c 20 30 29 20 7b 0a 09 20 20 20  (len < 0) {..   
0490: 20 6c 65 6e 20 3d 20 30 3b 0a 09 7d 0a 20 20 20   len = 0;..}.   
04a0: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 65   }.    return le
04b0: 6e 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 47 65 74  n;.}.../*. * Get
04c0: 20 58 35 30 39 20 43 65 72 74 69 66 69 63 61 74   X509 Certificat
04d0: 65 20 45 78 74 65 6e 73 69 6f 6e 73 0a 20 2a 2f  e Extensions. */
04e0: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35  .Tcl_Obj *Tls_x5
04f0: 30 39 45 78 74 65 6e 73 69 6f 6e 73 28 54 63 6c  09Extensions(Tcl
0500: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
0510: 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20   X509 *cert) {. 
0520: 20 20 20 63 6f 6e 73 74 20 53 54 41 43 4b 5f 4f     const STACK_O
0530: 46 28 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e  F(X509_EXTENSION
0540: 29 20 2a 65 78 74 73 3b 0a 20 20 20 20 54 63 6c  ) *exts;.    Tcl
0550: 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20  _Obj *listPtr = 
0560: 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30  Tcl_NewListObj(0
0570: 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66  , NULL);..    if
0580: 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c   (listPtr == NUL
0590: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c  L) {..return NUL
05a0: 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66  L;.    }..    if
05b0: 20 28 65 78 74 73 20 3d 20 58 35 30 39 5f 67 65   (exts = X509_ge
05c0: 74 30 5f 65 78 74 65 6e 73 69 6f 6e 73 28 63 65  t0_extensions(ce
05d0: 72 74 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74  rt)) {..for (int
05e0: 20 69 3d 30 3b 20 69 20 3c 20 58 35 30 39 5f 67   i=0; i < X509_g
05f0: 65 74 5f 65 78 74 5f 63 6f 75 6e 74 28 63 65 72  et_ext_count(cer
0600: 74 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20  t); i++) {..    
0610: 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 20 2a  X509_EXTENSION *
0620: 65 78 20 3d 20 73 6b 5f 58 35 30 39 5f 45 58 54  ex = sk_X509_EXT
0630: 45 4e 53 49 4f 4e 5f 76 61 6c 75 65 28 65 78 74  ENSION_value(ext
0640: 73 2c 20 69 29 3b 0a 09 20 20 20 20 41 53 4e 31  s, i);..    ASN1
0650: 5f 4f 42 4a 45 43 54 20 2a 6f 62 6a 20 3d 20 58  _OBJECT *obj = X
0660: 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67 65  509_EXTENSION_ge
0670: 74 5f 6f 62 6a 65 63 74 28 65 78 29 3b 0a 09 20  t_object(ex);.. 
0680: 20 20 20 2f 2a 20 41 53 4e 31 5f 4f 43 54 45 54     /* ASN1_OCTET
0690: 5f 53 54 52 49 4e 47 20 2a 64 61 74 61 20 3d 20  _STRING *data = 
06a0: 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67  X509_EXTENSION_g
06b0: 65 74 5f 64 61 74 61 28 65 78 29 3b 20 2a 2f 0a  et_data(ex); */.
06c0: 09 20 20 20 20 69 6e 74 20 63 72 69 74 69 63 61  .    int critica
06d0: 6c 20 3d 20 58 35 30 39 5f 45 58 54 45 4e 53 49  l = X509_EXTENSI
06e0: 4f 4e 5f 67 65 74 5f 63 72 69 74 69 63 61 6c 28  ON_get_critical(
06f0: 65 78 29 3b 0a 09 20 20 20 20 4c 41 50 50 45 4e  ex);..    LAPPEN
0700: 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 6c  D_BOOL(interp, l
0710: 69 73 74 50 74 72 2c 20 4f 42 4a 5f 6e 69 64 32  istPtr, OBJ_nid2
0720: 6c 6e 28 4f 42 4a 5f 6f 62 6a 32 6e 69 64 28 6f  ln(OBJ_obj2nid(o
0730: 62 6a 29 29 2c 20 63 72 69 74 69 63 61 6c 29 3b  bj)), critical);
0740: 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 20 20 72 65  ..}.    }.    re
0750: 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a  turn listPtr;.}.
0760: 0a 2f 2a 0a 20 2a 20 47 65 74 20 41 75 74 68 6f  ./*. * Get Autho
0770: 72 69 74 79 20 61 6e 64 20 53 75 62 6a 65 63 74  rity and Subject
0780: 20 4b 65 79 20 49 64 65 6e 74 69 66 69 65 72 73   Key Identifiers
0790: 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c  . */.Tcl_Obj *Tl
07a0: 73 5f 78 35 30 39 49 64 65 6e 74 69 66 69 65 72  s_x509Identifier
07b0: 28 41 53 4e 31 5f 4f 43 54 45 54 5f 53 54 52 49  (ASN1_OCTET_STRI
07c0: 4e 47 20 2a 61 73 74 72 69 6e 67 29 20 7b 0a 20  NG *astring) {. 
07d0: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 72 65 73 75     Tcl_Obj *resu
07e0: 6c 74 50 74 72 20 3d 20 4e 55 4c 4c 3b 0a 20 20  ltPtr = NULL;.  
07f0: 20 20 69 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20    int len = 0;. 
0800: 20 20 20 63 68 61 72 20 62 75 66 66 65 72 5b 31     char buffer[1
0810: 30 32 34 5d 3b 0a 0a 20 20 20 20 69 66 20 28 61  024];..    if (a
0820: 73 74 72 69 6e 67 20 21 3d 20 4e 55 4c 4c 29 20  string != NULL) 
0830: 7b 0a 09 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f  {..len = String_
0840: 74 6f 5f 48 65 78 28 41 53 4e 31 5f 53 54 52 49  to_Hex(ASN1_STRI
0850: 4e 47 5f 67 65 74 30 5f 64 61 74 61 28 61 73 74  NG_get0_data(ast
0860: 72 69 6e 67 29 2c 0a 09 20 20 20 20 41 53 4e 31  ring),..    ASN1
0870: 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 61  _STRING_length(a
0880: 73 74 72 69 6e 67 29 2c 20 62 75 66 66 65 72 2c  string), buffer,
0890: 20 31 30 32 34 29 3b 0a 20 20 20 20 7d 0a 20 20   1024);.    }.  
08a0: 20 20 72 65 73 75 6c 74 50 74 72 20 3d 20 54 63    resultPtr = Tc
08b0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 62  l_NewStringObj(b
08c0: 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 20 20 20  uffer, len);.   
08d0: 20 72 65 74 75 72 6e 20 72 65 73 75 6c 74 50 74   return resultPt
08e0: 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20  r;.}../*. * Get 
08f0: 4b 65 79 20 55 73 61 67 65 0a 20 2a 2f 0a 54 63  Key Usage. */.Tc
0900: 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4b  l_Obj *Tls_x509K
0910: 65 79 55 73 61 67 65 28 54 63 6c 5f 49 6e 74 65  eyUsage(Tcl_Inte
0920: 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39  rp *interp, X509
0930: 20 2a 63 65 72 74 2c 20 75 69 6e 74 33 32 5f 74   *cert, uint32_t
0940: 20 78 66 6c 61 67 73 29 20 7b 0a 20 20 20 20 75   xflags) {.    u
0950: 69 6e 74 33 32 5f 74 20 75 73 61 67 65 20 3d 20  int32_t usage = 
0960: 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f 75 73 61  X509_get_key_usa
0970: 67 65 28 63 65 72 74 29 3b 0a 20 20 20 20 54 63  ge(cert);.    Tc
0980: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d  l_Obj *listPtr =
0990: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28   Tcl_NewListObj(
09a0: 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69  0, NULL);..    i
09b0: 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55  f (listPtr == NU
09c0: 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55  LL) {..return NU
09d0: 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69  LL;.    }..    i
09e0: 66 20 28 28 78 66 6c 61 67 73 20 26 20 45 58 46  f ((xflags & EXF
09f0: 4c 41 47 5f 4b 55 53 41 47 45 29 20 26 26 20 75  LAG_KUSAGE) && u
0a00: 73 61 67 65 20 3c 20 55 49 4e 54 33 32 5f 4d 41  sage < UINT32_MA
0a10: 58 29 20 7b 0a 09 69 66 20 28 75 73 61 67 65 20  X) {..if (usage 
0a20: 26 20 4b 55 5f 44 49 47 49 54 41 4c 5f 53 49 47  & KU_DIGITAL_SIG
0a30: 4e 41 54 55 52 45 29 20 7b 0a 09 20 20 20 20 54  NATURE) {..    T
0a40: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
0a50: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20  Element(interp, 
0a60: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77  listPtr, Tcl_New
0a70: 53 74 72 69 6e 67 4f 62 6a 28 22 44 69 67 69 74  StringObj("Digit
0a80: 61 6c 20 53 69 67 6e 61 74 75 72 65 22 2c 20 2d  al Signature", -
0a90: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
0aa0: 67 65 20 26 20 4b 55 5f 4e 4f 4e 5f 52 45 50 55  ge & KU_NON_REPU
0ab0: 44 49 41 54 49 4f 4e 29 20 7b 0a 09 20 20 20 20  DIATION) {..    
0ac0: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e  Tcl_ListObjAppen
0ad0: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c  dElement(interp,
0ae0: 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65   listPtr, Tcl_Ne
0af0: 77 53 74 72 69 6e 67 4f 62 6a 28 22 4e 6f 6e 2d  wStringObj("Non-
0b00: 52 65 70 75 64 69 61 74 69 6f 6e 22 2c 20 2d 31  Repudiation", -1
0b10: 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67  ));..}..if (usag
0b20: 65 20 26 20 4b 55 5f 4b 45 59 5f 45 4e 43 49 50  e & KU_KEY_ENCIP
0b30: 48 45 52 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20  HERMENT) {..    
0b40: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e  Tcl_ListObjAppen
0b50: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c  dElement(interp,
0b60: 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65   listPtr, Tcl_Ne
0b70: 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b 65 79 20  wStringObj("Key 
0b80: 45 6e 63 69 70 68 65 72 6d 65 6e 74 22 2c 20 2d  Encipherment", -
0b90: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
0ba0: 67 65 20 26 20 4b 55 5f 44 41 54 41 5f 45 4e 43  ge & KU_DATA_ENC
0bb0: 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a 09 20 20  IPHERMENT) {..  
0bc0: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
0bd0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
0be0: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f  p, listPtr, Tcl_
0bf0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 61  NewStringObj("Da
0c00: 74 61 20 45 6e 63 69 70 68 65 72 6d 65 6e 74 22  ta Encipherment"
0c10: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28  , -1));..}..if (
0c20: 75 73 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 41  usage & KU_KEY_A
0c30: 47 52 45 45 4d 45 4e 54 29 20 7b 0a 09 20 20 20  GREEMENT) {..   
0c40: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
0c50: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
0c60: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e  , listPtr, Tcl_N
0c70: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b 65 79  ewStringObj("Key
0c80: 20 41 67 72 65 65 6d 65 6e 74 22 2c 20 2d 31 29   Agreement", -1)
0c90: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65  );..}..if (usage
0ca0: 20 26 20 4b 55 5f 4b 45 59 5f 43 45 52 54 5f 53   & KU_KEY_CERT_S
0cb0: 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f  IGN) {..    Tcl_
0cc0: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
0cd0: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73  ment(interp, lis
0ce0: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
0cf0: 69 6e 67 4f 62 6a 28 22 43 65 72 74 69 66 69 63  ingObj("Certific
0d00: 61 74 65 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31  ate Signing", -1
0d10: 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67  ));..}..if (usag
0d20: 65 20 26 20 4b 55 5f 43 52 4c 5f 53 49 47 4e 29  e & KU_CRL_SIGN)
0d30: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
0d40: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
0d50: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
0d60: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
0d70: 62 6a 28 22 43 52 4c 20 53 69 67 6e 69 6e 67 22  bj("CRL Signing"
0d80: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28  , -1));..}..if (
0d90: 75 73 61 67 65 20 26 20 4b 55 5f 45 4e 43 49 50  usage & KU_ENCIP
0da0: 48 45 52 5f 4f 4e 4c 59 29 20 7b 0a 09 20 20 20  HER_ONLY) {..   
0db0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
0dc0: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
0dd0: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e  , listPtr, Tcl_N
0de0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 45 6e 63  ewStringObj("Enc
0df0: 69 70 68 65 72 20 4f 6e 6c 79 22 2c 20 2d 31 29  ipher Only", -1)
0e00: 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65  );..}..if (usage
0e10: 20 26 20 4b 55 5f 44 45 43 49 50 48 45 52 5f 4f   & KU_DECIPHER_O
0e20: 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f  NLY) {..    Tcl_
0e30: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
0e40: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73  ment(interp, lis
0e50: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
0e60: 69 6e 67 4f 62 6a 28 22 44 65 63 69 70 68 65 72  ingObj("Decipher
0e70: 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b 0a 09 7d   Only", -1));..}
0e80: 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 20  .    } else {.. 
0e90: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
0ea0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
0eb0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c  rp, listPtr, Tcl
0ec0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 75  _NewStringObj("u
0ed0: 6e 72 65 73 74 72 69 63 74 65 64 22 2c 20 2d 31  nrestricted", -1
0ee0: 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65  ));.    }.    re
0ef0: 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a  turn listPtr;.}.
0f00: 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 65 72 74 69  ./*. * Get Certi
0f10: 66 69 63 61 74 65 20 50 75 72 70 6f 73 65 0a 20  ficate Purpose. 
0f20: 2a 2f 0a 63 68 61 72 20 2a 54 6c 73 5f 78 35 30  */.char *Tls_x50
0f30: 39 50 75 72 70 6f 73 65 28 58 35 30 39 20 2a 63  9Purpose(X509 *c
0f40: 65 72 74 29 20 7b 0a 20 20 20 20 63 68 61 72 20  ert) {.    char 
0f50: 2a 70 75 72 70 6f 73 65 20 3d 20 4e 55 4c 4c 3b  *purpose = NULL;
0f60: 0a 0a 20 20 20 20 69 66 20 28 58 35 30 39 5f 63  ..    if (X509_c
0f70: 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72  heck_purpose(cer
0f80: 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f  t, X509_PURPOSE_
0f90: 53 53 4c 5f 43 4c 49 45 4e 54 2c 20 30 29 20 3e  SSL_CLIENT, 0) >
0fa0: 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d   0) {..purpose =
0fb0: 20 22 53 53 4c 20 43 6c 69 65 6e 74 22 3b 0a 20   "SSL Client";. 
0fc0: 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35     } else if (X5
0fd0: 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65  09_check_purpose
0fe0: 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50  (cert, X509_PURP
0ff0: 4f 53 45 5f 53 53 4c 5f 53 45 52 56 45 52 2c 20  OSE_SSL_SERVER, 
1000: 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f  0) > 0) {..purpo
1010: 73 65 20 3d 20 22 53 53 4c 20 53 65 72 76 65 72  se = "SSL Server
1020: 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66  ";.    } else if
1030: 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72   (X509_check_pur
1040: 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f  pose(cert, X509_
1050: 50 55 52 50 4f 53 45 5f 4e 53 5f 53 53 4c 5f 53  PURPOSE_NS_SSL_S
1060: 45 52 56 45 52 2c 20 30 29 20 3e 20 30 29 20 7b  ERVER, 0) > 0) {
1070: 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 4d 53 53  ..purpose = "MSS
1080: 20 53 53 4c 20 53 65 72 76 65 72 22 3b 0a 20 20   SSL Server";.  
1090: 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30    } else if (X50
10a0: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28  9_check_purpose(
10b0: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f  cert, X509_PURPO
10c0: 53 45 5f 53 4d 49 4d 45 5f 53 49 47 4e 2c 20 30  SE_SMIME_SIGN, 0
10d0: 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73  ) > 0) {..purpos
10e0: 65 20 3d 20 22 53 4d 49 4d 45 20 53 69 67 6e 69  e = "SMIME Signi
10f0: 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20  ng";.    } else 
1100: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70  if (X509_check_p
1110: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30  urpose(cert, X50
1120: 39 5f 50 55 52 50 4f 53 45 5f 53 4d 49 4d 45 5f  9_PURPOSE_SMIME_
1130: 45 4e 43 52 59 50 54 2c 20 30 29 20 3e 20 30 29  ENCRYPT, 0) > 0)
1140: 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 53   {..purpose = "S
1150: 4d 49 4d 45 20 45 6e 63 72 79 70 74 69 6f 6e 22  MIME Encryption"
1160: 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20  ;.    } else if 
1170: 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70  (X509_check_purp
1180: 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50  ose(cert, X509_P
1190: 55 52 50 4f 53 45 5f 43 52 4c 5f 53 49 47 4e 2c  URPOSE_CRL_SIGN,
11a0: 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70   0) > 0) {..purp
11b0: 6f 73 65 20 3d 20 22 43 52 4c 20 53 69 67 6e 69  ose = "CRL Signi
11c0: 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20  ng";.    } else 
11d0: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70  if (X509_check_p
11e0: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30  urpose(cert, X50
11f0: 39 5f 50 55 52 50 4f 53 45 5f 41 4e 59 2c 20 30  9_PURPOSE_ANY, 0
1200: 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73  ) > 0) {..purpos
1210: 65 20 3d 20 22 41 6e 79 22 3b 0a 20 20 20 20 7d  e = "Any";.    }
1220: 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 5f 63   else if (X509_c
1230: 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72  heck_purpose(cer
1240: 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f  t, X509_PURPOSE_
1250: 4f 43 53 50 5f 48 45 4c 50 45 52 2c 20 30 29 20  OCSP_HELPER, 0) 
1260: 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20  > 0) {..purpose 
1270: 3d 20 22 4f 43 53 50 20 48 65 6c 70 65 72 22 3b  = "OCSP Helper";
1280: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28  .    } else if (
1290: 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f  X509_check_purpo
12a0: 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55  se(cert, X509_PU
12b0: 52 50 4f 53 45 5f 54 49 4d 45 53 54 41 4d 50 5f  RPOSE_TIMESTAMP_
12c0: 53 49 47 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a  SIGN, 0) > 0) {.
12d0: 09 70 75 72 70 6f 73 65 20 3d 20 22 54 69 6d 65  .purpose = "Time
12e0: 73 74 61 6d 70 20 53 69 67 6e 69 6e 67 22 3b 0a  stamp Signing";.
12f0: 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 70 75      } else {..pu
1300: 72 70 6f 73 65 20 3d 20 22 22 3b 0a 20 20 20 20  rpose = "";.    
1310: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 70 75 72  }.    return pur
1320: 70 6f 73 65 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 46  pose;.}../*. * F
1330: 6f 72 20 65 61 63 68 20 70 75 72 70 6f 73 65 2c  or each purpose,
1340: 20 67 65 74 20 63 65 72 74 69 66 69 63 61 74 65   get certificate
1350: 20 61 70 70 6c 69 63 61 62 69 6c 69 74 79 0a 20   applicability. 
1360: 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f  */.Tcl_Obj *Tls_
1370: 78 35 30 39 50 75 72 70 6f 73 65 73 28 54 63 6c  x509Purposes(Tcl
1380: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
1390: 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20   X509 *cert) {. 
13a0: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74     Tcl_Obj *list
13b0: 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73  Ptr = Tcl_NewLis
13c0: 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20  tObj(0, NULL);. 
13d0: 20 20 20 58 35 30 39 5f 50 55 52 50 4f 53 45 20     X509_PURPOSE 
13e0: 2a 70 74 6d 70 3b 0a 0a 20 20 20 20 69 66 20 28  *ptmp;..    if (
13f0: 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29  listPtr == NULL)
1400: 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b   {..return NULL;
1410: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 66 6f 72 20  .    }..    for 
1420: 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20  (int i = 0; i < 
1430: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 74  X509_PURPOSE_get
1440: 5f 63 6f 75 6e 74 28 29 3b 20 69 2b 2b 29 20 7b  _count(); i++) {
1450: 0a 09 70 74 6d 70 20 3d 20 58 35 30 39 5f 50 55  ..ptmp = X509_PU
1460: 52 50 4f 53 45 5f 67 65 74 30 28 69 29 3b 0a 09  RPOSE_get0(i);..
1470: 54 63 6c 5f 4f 62 6a 20 2a 74 6d 70 50 74 72 20  Tcl_Obj *tmpPtr 
1480: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a  = Tcl_NewListObj
1490: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 66 6f 72  (0, NULL);...for
14a0: 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20 6a 20 3c   (int j = 0; j <
14b0: 20 32 3b 20 6a 2b 2b 29 20 7b 0a 09 20 20 20 20   2; j++) {..    
14c0: 69 6e 74 20 69 64 72 65 74 20 3d 20 58 35 30 39  int idret = X509
14d0: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63  _check_purpose(c
14e0: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53  ert, X509_PURPOS
14f0: 45 5f 67 65 74 5f 69 64 28 70 74 6d 70 29 2c 20  E_get_id(ptmp), 
1500: 6a 29 3b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73  j);..    Tcl_Lis
1510: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e  tObjAppendElemen
1520: 74 28 69 6e 74 65 72 70 2c 20 74 6d 70 50 74 72  t(interp, tmpPtr
1530: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
1540: 62 6a 28 6a 20 3f 20 22 43 41 22 20 3a 20 22 6e  bj(j ? "CA" : "n
1550: 6f 6e 43 41 22 2c 20 2d 31 29 29 3b 0a 09 20 20  onCA", -1));..  
1560: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70    Tcl_ListObjApp
1570: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72  endElement(inter
1580: 70 2c 20 74 6d 70 50 74 72 2c 20 54 63 6c 5f 4e  p, tmpPtr, Tcl_N
1590: 65 77 53 74 72 69 6e 67 4f 62 6a 28 69 64 72 65  ewStringObj(idre
15a0: 74 20 3d 3d 20 31 20 3f 20 22 59 65 73 22 20 3a  t == 1 ? "Yes" :
15b0: 20 22 4e 6f 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a   "No", -1));..}.
15c0: 09 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74  .LAPPEND_OBJ(int
15d0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 58 35  erp, listPtr, X5
15e0: 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 74 30 5f  09_PURPOSE_get0_
15f0: 6e 61 6d 65 28 70 74 6d 70 29 2c 20 74 6d 70 50  name(ptmp), tmpP
1600: 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72  tr);.    }.    r
1610: 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d  eturn listPtr;.}
1620: 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 53 75 62 6a  ../*. * Get Subj
1630: 65 63 74 20 41 6c 74 65 72 6e 61 74 65 20 4e 61  ect Alternate Na
1640: 6d 65 73 20 28 53 41 4e 29 20 61 6e 64 20 49 73  mes (SAN) and Is
1650: 73 75 65 72 20 41 6c 74 65 72 6e 61 74 65 20 4e  suer Alternate N
1660: 61 6d 65 73 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a  ames. */.Tcl_Obj
1670: 20 2a 54 6c 73 5f 78 35 30 39 4e 61 6d 65 73 28   *Tls_x509Names(
1680: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65  Tcl_Interp *inte
1690: 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74 2c 20  rp, X509 *cert, 
16a0: 69 6e 74 20 6e 69 64 2c 20 42 49 4f 20 2a 62 69  int nid, BIO *bi
16b0: 6f 29 20 7b 0a 20 20 20 20 53 54 41 43 4b 5f 4f  o) {.    STACK_O
16c0: 46 28 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 29 20  F(GENERAL_NAME) 
16d0: 2a 6e 61 6d 65 73 3b 0a 20 20 20 20 54 63 6c 5f  *names;.    Tcl_
16e0: 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54  Obj *listPtr = T
16f0: 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c  cl_NewListObj(0,
1700: 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 69 6e 74 20   NULL);.    int 
1710: 6c 65 6e 3b 0a 20 20 20 20 63 68 61 72 20 62 75  len;.    char bu
1720: 66 66 65 72 5b 31 30 32 34 5d 3b 0a 0a 20 20 20  ffer[1024];..   
1730: 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20   if (listPtr == 
1740: 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20  NULL) {..return 
1750: 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  NULL;.    }..   
1760: 20 69 66 20 28 6e 61 6d 65 73 20 3d 20 58 35 30   if (names = X50
1770: 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 28 63 65  9_get_ext_d2i(ce
1780: 72 74 2c 20 6e 69 64 2c 20 4e 55 4c 4c 2c 20 4e  rt, nid, NULL, N
1790: 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e  ULL)) {..for (in
17a0: 74 20 69 3d 30 3b 20 69 20 3c 20 73 6b 5f 47 45  t i=0; i < sk_GE
17b0: 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 6e  NERAL_NAME_num(n
17c0: 61 6d 65 73 29 3b 20 69 2b 2b 29 20 7b 0a 09 20  ames); i++) {.. 
17d0: 20 20 20 63 6f 6e 73 74 20 47 45 4e 45 52 41 4c     const GENERAL
17e0: 5f 4e 41 4d 45 20 2a 6e 61 6d 65 20 3d 20 73 6b  _NAME *name = sk
17f0: 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 76 61  _GENERAL_NAME_va
1800: 6c 75 65 28 6e 61 6d 65 73 2c 20 69 29 3b 0a 0a  lue(names, i);..
1810: 09 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74  .    len = BIO_t
1820: 6f 5f 42 75 66 66 65 72 28 6e 61 6d 65 20 26 26  o_Buffer(name &&
1830: 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 70 72   GENERAL_NAME_pr
1840: 69 6e 74 28 62 69 6f 2c 20 6e 61 6d 65 29 2c 20  int(bio, name), 
1850: 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 31 30 32  bio, buffer, 102
1860: 34 29 3b 0a 09 20 20 20 20 4c 41 50 50 45 4e 44  4);..    LAPPEND
1870: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73  _STR(interp, lis
1880: 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 62 75 66 66  tPtr, NULL, buff
1890: 65 72 2c 20 6c 65 6e 29 3b 0a 09 7d 0a 09 73 6b  er, len);..}..sk
18a0: 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 70 6f  _GENERAL_NAME_po
18b0: 70 5f 66 72 65 65 28 6e 61 6d 65 73 2c 20 47 45  p_free(names, GE
18c0: 4e 45 52 41 4c 5f 4e 41 4d 45 5f 66 72 65 65 29  NERAL_NAME_free)
18d0: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 65 74 75  ;.    }.    retu
18e0: 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f  rn listPtr;.}../
18f0: 2a 0a 20 2a 20 47 65 74 20 45 58 74 65 6e 64 65  *. * Get EXtende
1900: 64 20 4b 65 79 20 55 73 61 67 65 0a 20 2a 2f 0a  d Key Usage. */.
1910: 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30  Tcl_Obj *Tls_x50
1920: 39 45 78 74 4b 65 79 55 73 61 67 65 28 54 63 6c  9ExtKeyUsage(Tcl
1930: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
1940: 20 58 35 30 39 20 2a 63 65 72 74 2c 20 75 69 6e   X509 *cert, uin
1950: 74 33 32 5f 74 20 78 66 6c 61 67 73 29 20 7b 0a  t32_t xflags) {.
1960: 20 20 20 20 75 69 6e 74 33 32 5f 74 20 75 73 61      uint32_t usa
1970: 67 65 20 3d 20 58 35 30 39 5f 67 65 74 5f 6b 65  ge = X509_get_ke
1980: 79 5f 75 73 61 67 65 28 63 65 72 74 29 3b 0a 20  y_usage(cert);. 
1990: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74     Tcl_Obj *list
19a0: 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73  Ptr = Tcl_NewLis
19b0: 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a  tObj(0, NULL);..
19c0: 20 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 20      if (listPtr 
19d0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75  == NULL) {..retu
19e0: 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a  rn NULL;.    }..
19f0: 20 20 20 20 69 66 20 28 28 78 66 6c 61 67 73 20      if ((xflags 
1a00: 26 20 45 58 46 4c 41 47 5f 58 4b 55 53 41 47 45  & EXFLAG_XKUSAGE
1a10: 29 20 26 26 20 75 73 61 67 65 20 3c 20 55 49 4e  ) && usage < UIN
1a20: 54 33 32 5f 4d 41 58 29 20 7b 0a 09 75 73 61 67  T32_MAX) {..usag
1a30: 65 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74  e = X509_get_ext
1a40: 65 6e 64 65 64 5f 6b 65 79 5f 75 73 61 67 65 28  ended_key_usage(
1a50: 63 65 72 74 29 3b 0a 0a 09 69 66 20 28 75 73 61  cert);...if (usa
1a60: 67 65 20 26 20 58 4b 55 5f 53 53 4c 5f 53 45 52  ge & XKU_SSL_SER
1a70: 56 45 52 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f  VER) {..    Tcl_
1a80: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
1a90: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73  ment(interp, lis
1aa0: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
1ab0: 69 6e 67 4f 62 6a 28 22 54 4c 53 20 57 65 62 20  ingObj("TLS Web 
1ac0: 53 65 72 76 65 72 20 41 75 74 68 65 6e 74 69 63  Server Authentic
1ad0: 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09 7d  ation", -1));..}
1ae0: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b  ..if (usage & XK
1af0: 55 5f 53 53 4c 5f 43 4c 49 45 4e 54 29 20 7b 0a  U_SSL_CLIENT) {.
1b00: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
1b10: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
1b20: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54  terp, listPtr, T
1b30: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
1b40: 22 54 4c 53 20 57 65 62 20 43 6c 69 65 6e 74 20  "TLS Web Client 
1b50: 41 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 22 2c  Authentication",
1b60: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
1b70: 73 61 67 65 20 26 20 58 4b 55 5f 53 4d 49 4d 45  sage & XKU_SMIME
1b80: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73  ) {..    Tcl_Lis
1b90: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e  tObjAppendElemen
1ba0: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74  t(interp, listPt
1bb0: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67  r, Tcl_NewString
1bc0: 4f 62 6a 28 22 45 2d 6d 61 69 6c 20 50 72 6f 74  Obj("E-mail Prot
1bd0: 65 63 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a 09  ection", -1));..
1be0: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58  }..if (usage & X
1bf0: 4b 55 5f 43 4f 44 45 5f 53 49 47 4e 29 20 7b 0a  KU_CODE_SIGN) {.
1c00: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a  .    Tcl_ListObj
1c10: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
1c20: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54  terp, listPtr, T
1c30: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
1c40: 22 43 6f 64 65 20 53 69 67 6e 69 6e 67 22 2c 20  "Code Signing", 
1c50: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73  -1));..}..if (us
1c60: 61 67 65 20 26 20 58 4b 55 5f 53 47 43 29 20 7b  age & XKU_SGC) {
1c70: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62  ..    Tcl_ListOb
1c80: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69  jAppendElement(i
1c90: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20  nterp, listPtr, 
1ca0: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a  Tcl_NewStringObj
1cb0: 28 22 53 47 43 22 2c 20 2d 31 29 29 3b 0a 09 7d  ("SGC", -1));..}
1cc0: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b  ..if (usage & XK
1cd0: 55 5f 4f 43 53 50 5f 53 49 47 4e 29 20 7b 0a 09  U_OCSP_SIGN) {..
1ce0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
1cf0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
1d00: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
1d10: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
1d20: 4f 43 53 50 20 53 69 67 6e 69 6e 67 22 2c 20 2d  OCSP Signing", -
1d30: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61  1));..}..if (usa
1d40: 67 65 20 26 20 58 4b 55 5f 54 49 4d 45 53 54 41  ge & XKU_TIMESTA
1d50: 4d 50 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  MP) {..    Tcl_L
1d60: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
1d70: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74  ent(interp, list
1d80: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
1d90: 6e 67 4f 62 6a 28 22 54 69 6d 65 20 53 74 61 6d  ngObj("Time Stam
1da0: 70 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a  ping", -1));..}.
1db0: 09 69 66 20 28 75 73 61 67 65 20 26 20 58 4b 55  .if (usage & XKU
1dc0: 5f 44 56 43 53 20 29 20 7b 0a 09 20 20 20 20 54  _DVCS ) {..    T
1dd0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
1de0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20  Element(interp, 
1df0: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77  listPtr, Tcl_New
1e00: 53 74 72 69 6e 67 4f 62 6a 28 22 44 56 43 53 22  StringObj("DVCS"
1e10: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28  , -1));..}..if (
1e20: 75 73 61 67 65 20 26 20 58 4b 55 5f 41 4e 59 45  usage & XKU_ANYE
1e30: 4b 55 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  KU) {..    Tcl_L
1e40: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
1e50: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74  ent(interp, list
1e60: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
1e70: 6e 67 4f 62 6a 28 22 41 6e 79 20 45 78 74 65 6e  ngObj("Any Exten
1e80: 64 65 64 20 4b 65 79 20 55 73 61 67 65 22 2c 20  ded Key Usage", 
1e90: 2d 31 29 29 3b 0a 09 7d 0a 20 20 20 20 7d 20 65  -1));..}.    } e
1ea0: 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  lse {..    Tcl_L
1eb0: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
1ec0: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74  ent(interp, list
1ed0: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
1ee0: 6e 67 4f 62 6a 28 22 75 6e 72 65 73 74 72 69 63  ngObj("unrestric
1ef0: 74 65 64 22 2c 20 2d 31 29 29 3b 0a 20 20 20 20  ted", -1));.    
1f00: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73  }.    return lis
1f10: 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47  tPtr;.}../*. * G
1f20: 65 74 20 43 52 4c 20 44 69 73 74 72 69 62 75 74  et CRL Distribut
1f30: 69 6f 6e 20 50 6f 69 6e 74 73 0a 20 2a 2f 0a 54  ion Points. */.T
1f40: 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39  cl_Obj *Tls_x509
1f50: 43 72 6c 44 70 28 54 63 6c 5f 49 6e 74 65 72 70  CrlDp(Tcl_Interp
1f60: 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a   *interp, X509 *
1f70: 63 65 72 74 29 20 7b 0a 20 20 20 20 53 54 41 43  cert) {.    STAC
1f80: 4b 5f 4f 46 28 44 49 53 54 5f 50 4f 49 4e 54 29  K_OF(DIST_POINT)
1f90: 20 2a 63 72 6c 3b 0a 20 20 20 20 54 63 6c 5f 4f   *crl;.    Tcl_O
1fa0: 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20 54 63  bj *listPtr = Tc
1fb0: 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20  l_NewListObj(0, 
1fc0: 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28  NULL);..    if (
1fd0: 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29  listPtr == NULL)
1fe0: 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b   {..return NULL;
1ff0: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66 20 28  .    }..    if (
2000: 63 72 6c 20 3d 20 58 35 30 39 5f 67 65 74 5f 65  crl = X509_get_e
2010: 78 74 5f 64 32 69 28 63 65 72 74 2c 20 4e 49 44  xt_d2i(cert, NID
2020: 5f 63 72 6c 5f 64 69 73 74 72 69 62 75 74 69 6f  _crl_distributio
2030: 6e 5f 70 6f 69 6e 74 73 2c 20 4e 55 4c 4c 2c 20  n_points, NULL, 
2040: 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 28 69  NULL)) {..for (i
2050: 6e 74 20 69 3d 30 3b 20 69 20 3c 20 73 6b 5f 44  nt i=0; i < sk_D
2060: 49 53 54 5f 50 4f 49 4e 54 5f 6e 75 6d 28 63 72  IST_POINT_num(cr
2070: 6c 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20  l); i++) {..    
2080: 44 49 53 54 5f 50 4f 49 4e 54 20 2a 64 70 20 3d  DIST_POINT *dp =
2090: 20 73 6b 5f 44 49 53 54 5f 50 4f 49 4e 54 5f 76   sk_DIST_POINT_v
20a0: 61 6c 75 65 28 63 72 6c 2c 20 69 29 3b 0a 09 20  alue(crl, i);.. 
20b0: 20 20 20 44 49 53 54 5f 50 4f 49 4e 54 5f 4e 41     DIST_POINT_NA
20c0: 4d 45 20 2a 64 69 73 74 70 6f 69 6e 74 20 3d 20  ME *distpoint = 
20d0: 64 70 2d 3e 64 69 73 74 70 6f 69 6e 74 3b 0a 0a  dp->distpoint;..
20e0: 09 20 20 20 20 69 66 20 28 64 69 73 74 70 6f 69  .    if (distpoi
20f0: 6e 74 2d 3e 74 79 70 65 20 3d 3d 20 30 29 20 7b  nt->type == 0) {
2100: 0a 09 09 2f 2a 20 66 75 6c 6c 2d 6e 61 6d 65 20  .../* full-name 
2110: 47 45 4e 45 52 41 4c 49 5a 45 44 4e 41 4d 45 20  GENERALIZEDNAME 
2120: 2a 2f 0a 09 09 66 6f 72 20 28 69 6e 74 20 6a 20  */...for (int j 
2130: 3d 20 30 3b 20 6a 20 3c 20 73 6b 5f 47 45 4e 45  = 0; j < sk_GENE
2140: 52 41 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 64 69 73  RAL_NAME_num(dis
2150: 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66 75 6c  tpoint->name.ful
2160: 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20 7b 0a 09  lname); j++) {..
2170: 09 20 20 20 20 47 45 4e 45 52 41 4c 5f 4e 41 4d  .    GENERAL_NAM
2180: 45 20 2a 67 65 6e 20 3d 20 73 6b 5f 47 45 4e 45  E *gen = sk_GENE
2190: 52 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75 65 28 64  RAL_NAME_value(d
21a0: 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66  istpoint->name.f
21b0: 75 6c 6c 6e 61 6d 65 2c 20 6a 29 3b 0a 09 09 20  ullname, j);... 
21c0: 20 20 20 69 6e 74 20 74 79 70 65 3b 0a 09 09 20     int type;... 
21d0: 20 20 20 41 53 4e 31 5f 53 54 52 49 4e 47 20 2a     ASN1_STRING *
21e0: 75 72 69 20 3d 20 47 45 4e 45 52 41 4c 5f 4e 41  uri = GENERAL_NA
21f0: 4d 45 5f 67 65 74 30 5f 76 61 6c 75 65 28 67 65  ME_get0_value(ge
2200: 6e 2c 20 26 74 79 70 65 29 3b 0a 09 09 20 20 20  n, &type);...   
2210: 20 69 66 20 28 74 79 70 65 20 3d 3d 20 47 45 4e   if (type == GEN
2220: 5f 55 52 49 29 20 7b 0a 09 09 09 4c 41 50 50 45  _URI) {....LAPPE
2230: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 6c  ND_STR(interp, l
2240: 69 73 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 41 53  istPtr, NULL, AS
2250: 4e 31 5f 53 54 52 49 4e 47 5f 67 65 74 30 5f 64  N1_STRING_get0_d
2260: 61 74 61 28 75 72 69 29 2c 20 41 53 4e 31 5f 53  ata(uri), ASN1_S
2270: 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 75 72 69  TRING_length(uri
2280: 29 29 3b 0a 09 09 20 20 20 20 7d 0a 09 09 7d 0a  ));...    }...}.
2290: 09 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28  .    } else if (
22a0: 64 69 73 74 70 6f 69 6e 74 2d 3e 74 79 70 65 20  distpoint->type 
22b0: 3d 3d 20 31 29 20 7b 0a 09 09 2f 2a 20 72 65 6c  == 1) {.../* rel
22c0: 61 74 69 76 65 2d 6e 61 6d 65 20 58 35 30 39 4e  ative-name X509N
22d0: 41 4d 45 20 2a 2f 0a 09 09 53 54 41 43 4b 5f 4f  AME */...STACK_O
22e0: 46 28 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52  F(X509_NAME_ENTR
22f0: 59 29 20 2a 73 6b 5f 72 65 6c 6e 61 6d 65 20 3d  Y) *sk_relname =
2300: 20 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65   distpoint->name
2310: 2e 72 65 6c 61 74 69 76 65 6e 61 6d 65 3b 0a 09  .relativename;..
2320: 09 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b  .for (int j = 0;
2330: 20 6a 20 3c 20 73 6b 5f 58 35 30 39 5f 4e 41 4d   j < sk_X509_NAM
2340: 45 5f 45 4e 54 52 59 5f 6e 75 6d 28 73 6b 5f 72  E_ENTRY_num(sk_r
2350: 65 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20 7b 0a  elname); j++) {.
2360: 09 09 20 20 20 20 58 35 30 39 5f 4e 41 4d 45 5f  ..    X509_NAME_
2370: 45 4e 54 52 59 20 2a 65 20 3d 20 73 6b 5f 58 35  ENTRY *e = sk_X5
2380: 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 76 61  09_NAME_ENTRY_va
2390: 6c 75 65 28 73 6b 5f 72 65 6c 6e 61 6d 65 2c 20  lue(sk_relname, 
23a0: 6a 29 3b 0a 09 09 20 20 20 20 41 53 4e 31 5f 53  j);...    ASN1_S
23b0: 54 52 49 4e 47 20 2a 64 20 3d 20 58 35 30 39 5f  TRING *d = X509_
23c0: 4e 41 4d 45 5f 45 4e 54 52 59 5f 67 65 74 5f 64  NAME_ENTRY_get_d
23d0: 61 74 61 28 65 29 3b 0a 09 09 20 20 20 20 4c 41  ata(e);...    LA
23e0: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
23f0: 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 4c 4c 2c  , listPtr, NULL,
2400: 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 64 61 74   ASN1_STRING_dat
2410: 61 28 64 29 2c 20 41 53 4e 31 5f 53 54 52 49 4e  a(d), ASN1_STRIN
2420: 47 5f 6c 65 6e 67 74 68 28 64 29 29 3b 0a 09 09  G_length(d));...
2430: 7d 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 43 52 4c  }..    }..}..CRL
2440: 5f 44 49 53 54 5f 50 4f 49 4e 54 53 5f 66 72 65  _DIST_POINTS_fre
2450: 65 28 63 72 6c 29 3b 0a 20 20 20 20 7d 0a 20 20  e(crl);.    }.  
2460: 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72    return listPtr
2470: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 4f  ;.}../*. * Get O
2480: 6e 2d 6c 69 6e 65 20 43 65 72 74 69 66 69 63 61  n-line Certifica
2490: 74 65 20 53 74 61 74 75 73 20 50 72 6f 74 6f 63  te Status Protoc
24a0: 6f 6c 20 28 4f 53 43 50 29 20 55 52 4c 0a 20 2a  ol (OSCP) URL. *
24b0: 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78  /.Tcl_Obj *Tls_x
24c0: 35 30 39 4f 73 63 70 28 54 63 6c 5f 49 6e 74 65  509Oscp(Tcl_Inte
24d0: 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39  rp *interp, X509
24e0: 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 53 54   *cert) {.    ST
24f0: 41 43 4b 5f 4f 46 28 4f 50 45 4e 53 53 4c 5f 53  ACK_OF(OPENSSL_S
2500: 54 52 49 4e 47 29 20 2a 6f 63 73 70 3b 0a 20 20  TRING) *ocsp;.  
2510: 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50    Tcl_Obj *listP
2520: 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74  tr = Tcl_NewList
2530: 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20  Obj(0, NULL);.. 
2540: 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d     if (listPtr =
2550: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72  = NULL) {..retur
2560: 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20  n NULL;.    }.. 
2570: 20 20 20 69 66 20 28 6f 63 73 70 20 3d 20 58 35     if (ocsp = X5
2580: 30 39 5f 67 65 74 31 5f 6f 63 73 70 28 63 65 72  09_get1_ocsp(cer
2590: 74 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20  t)) {..for (int 
25a0: 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b 5f 4f 50  i = 0; i < sk_OP
25b0: 45 4e 53 53 4c 5f 53 54 52 49 4e 47 5f 6e 75 6d  ENSSL_STRING_num
25c0: 28 6f 63 73 70 29 3b 20 69 2b 2b 29 20 7b 0a 09  (ocsp); i++) {..
25d0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28      LAPPEND_STR(
25e0: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c  interp, listPtr,
25f0: 20 4e 55 4c 4c 2c 20 73 6b 5f 4f 50 45 4e 53 53   NULL, sk_OPENSS
2600: 4c 5f 53 54 52 49 4e 47 5f 76 61 6c 75 65 28 6f  L_STRING_value(o
2610: 63 73 70 2c 20 69 29 2c 20 2d 31 29 3b 0a 09 7d  csp, i), -1);..}
2620: 0a 09 58 35 30 39 5f 65 6d 61 69 6c 5f 66 72 65  ..X509_email_fre
2630: 65 28 6f 63 73 70 29 3b 0a 20 20 20 20 7d 0a 20  e(ocsp);.    }. 
2640: 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74     return listPt
2650: 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20  r;.}../*. * Get 
2660: 43 65 72 74 69 66 69 63 61 74 65 20 41 75 74 68  Certificate Auth
2670: 6f 72 69 74 79 20 28 43 41 29 20 49 73 73 75 65  ority (CA) Issue
2680: 72 73 20 55 52 4c 0a 20 2a 2f 0a 54 63 6c 5f 4f  rs URL. */.Tcl_O
2690: 62 6a 20 2a 54 6c 73 5f 78 35 30 39 43 61 49 73  bj *Tls_x509CaIs
26a0: 73 75 65 72 73 28 54 63 6c 5f 49 6e 74 65 72 70  suers(Tcl_Interp
26b0: 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a   *interp, X509 *
26c0: 63 65 72 74 29 20 7b 0a 20 20 20 20 53 54 41 43  cert) {.    STAC
26d0: 4b 5f 4f 46 28 41 43 43 45 53 53 5f 44 45 53 43  K_OF(ACCESS_DESC
26e0: 52 49 50 54 49 4f 4e 29 20 2a 61 64 73 3b 0a 20  RIPTION) *ads;. 
26f0: 20 20 20 41 43 43 45 53 53 5f 44 45 53 43 52 49     ACCESS_DESCRI
2700: 50 54 49 4f 4e 20 2a 61 64 3b 0a 20 20 20 20 54  PTION *ad;.    T
2710: 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20  cl_Obj *listPtr 
2720: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a  = Tcl_NewListObj
2730: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 75  (0, NULL);.    u
2740: 6e 73 69 67 6e 65 64 20 63 68 61 72 20 2a 62 75  nsigned char *bu
2750: 66 3b 0a 20 20 20 20 69 6e 74 20 6c 65 6e 3b 0a  f;.    int len;.
2760: 0a 20 20 20 20 69 66 20 28 61 64 73 20 3d 20 58  .    if (ads = X
2770: 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 28  509_get_ext_d2i(
2780: 63 65 72 74 2c 20 4e 49 44 5f 69 6e 66 6f 5f 61  cert, NID_info_a
2790: 63 63 65 73 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c  ccess, NULL, NUL
27a0: 4c 29 29 20 7b 0a 09 66 6f 72 20 28 69 6e 74 20  L)) {..for (int 
27b0: 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b 5f 41 43  i = 0; i < sk_AC
27c0: 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f 4e  CESS_DESCRIPTION
27d0: 5f 6e 75 6d 28 61 64 73 29 3b 20 69 2b 2b 29 20  _num(ads); i++) 
27e0: 7b 0a 09 20 20 20 20 61 64 20 3d 20 73 6b 5f 41  {..    ad = sk_A
27f0: 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f  CCESS_DESCRIPTIO
2800: 4e 5f 76 61 6c 75 65 28 61 64 73 2c 20 69 29 3b  N_value(ads, i);
2810: 0a 09 20 20 20 20 69 66 20 28 4f 42 4a 5f 6f 62  ..    if (OBJ_ob
2820: 6a 32 6e 69 64 28 61 64 2d 3e 6d 65 74 68 6f 64  j2nid(ad->method
2830: 29 20 3d 3d 20 4e 49 44 5f 61 64 5f 63 61 5f 69  ) == NID_ad_ca_i
2840: 73 73 75 65 72 73 20 26 26 20 61 64 2d 3e 6c 6f  ssuers && ad->lo
2850: 63 61 74 69 6f 6e 29 20 7b 0a 09 09 69 66 20 28  cation) {...if (
2860: 61 64 2d 3e 6c 6f 63 61 74 69 6f 6e 2d 3e 74 79  ad->location->ty
2870: 70 65 20 3d 3d 20 47 45 4e 5f 55 52 49 29 20 7b  pe == GEN_URI) {
2880: 0a 09 09 20 20 20 20 6c 65 6e 20 3d 20 41 53 4e  ...    len = ASN
2890: 31 5f 53 54 52 49 4e 47 5f 74 6f 5f 55 54 46 38  1_STRING_to_UTF8
28a0: 28 26 62 75 66 2c 20 61 64 2d 3e 6c 6f 63 61 74  (&buf, ad->locat
28b0: 69 6f 6e 2d 3e 64 2e 75 6e 69 66 6f 72 6d 52 65  ion->d.uniformRe
28c0: 73 6f 75 72 63 65 49 64 65 6e 74 69 66 69 65 72  sourceIdentifier
28d0: 29 3b 0a 09 09 20 20 20 20 54 63 6c 5f 4c 69 73  );...    Tcl_Lis
28e0: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e  tObjAppendElemen
28f0: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74  t(interp, listPt
2900: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67  r, Tcl_NewString
2910: 4f 62 6a 28 62 75 66 2c 20 6c 65 6e 29 29 3b 0a  Obj(buf, len));.
2920: 09 09 20 20 20 20 4f 50 45 4e 53 53 4c 5f 66 72  ..    OPENSSL_fr
2930: 65 65 28 62 75 66 29 3b 0a 09 09 20 20 20 20 62  ee(buf);...    b
2940: 72 65 61 6b 3b 0a 09 09 7d 0a 09 20 20 20 20 7d  reak;...}..    }
2950: 0a 09 7d 0a 09 2f 2a 20 73 6b 5f 41 43 43 45 53  ..}../* sk_ACCES
2960: 53 5f 44 45 53 43 52 49 50 54 49 4f 4e 5f 70 6f  S_DESCRIPTION_po
2970: 70 5f 66 72 65 65 28 61 64 73 2c 20 41 43 43 45  p_free(ads, ACCE
2980: 53 53 5f 44 45 53 43 52 49 50 54 49 4f 4e 5f 66  SS_DESCRIPTION_f
2990: 72 65 65 29 3b 20 2a 2f 0a 09 41 55 54 48 4f 52  ree); */..AUTHOR
29a0: 49 54 59 5f 49 4e 46 4f 5f 41 43 43 45 53 53 5f  ITY_INFO_ACCESS_
29b0: 66 72 65 65 28 61 64 73 29 3b 0a 20 20 20 20 7d  free(ads);.    }
29c0: 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74  .    return list
29d0: 50 74 72 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d  Ptr;.}.../*. *--
29e0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
29f0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2a00: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2a10: 2d 2d 2d 2d 2a 0a 20 2a 0a 20 2a 09 54 6c 73 5f  ----*. *. *.Tls_
2a20: 4e 65 77 58 35 30 39 4f 62 6a 20 2d 2d 0a 20 2a  NewX509Obj --. *
2a30: 0a 20 2a 09 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . *.------------
2a40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2a50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2a60: 2d 2d 2d 2d 2a 0a 20 2a 09 43 6f 6e 76 65 72 74  ----*. *.Convert
2a70: 73 20 61 20 58 35 30 39 20 63 65 72 74 69 66 69  s a X509 certifi
2a80: 63 61 74 65 20 69 6e 74 6f 20 61 20 54 63 6c 5f  cate into a Tcl_
2a90: 4f 62 6a 0a 20 2a 09 2d 2d 2d 2d 2d 2d 2d 2d 2d  Obj. *.---------
2aa0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ab0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2ac0: 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 0a 20 2a 09 53  -------*. *. *.S
2ad0: 69 64 65 20 65 66 66 65 63 74 73 3a 0a 20 2a 09  ide effects:. *.
2ae0: 09 4e 6f 6e 65 0a 20 2a 0a 20 2a 09 52 65 73 75  .None. *. *.Resu
2af0: 6c 74 3a 0a 20 2a 09 09 41 20 54 63 6c 20 4c 69  lt:. *..A Tcl Li
2b00: 73 74 20 4f 62 6a 65 63 74 20 72 65 70 72 65 73  st Object repres
2b10: 65 6e 74 69 6e 67 20 74 68 65 20 70 72 6f 76 69  enting the provi
2b20: 64 65 64 0a 20 2a 09 09 58 35 30 39 20 63 65 72  ded. *..X509 cer
2b30: 74 69 66 69 63 61 74 65 2e 0a 20 2a 0a 20 2a 2d  tificate.. *. *-
2b40: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b50: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b60: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
2b70: 2d 2d 2d 2d 2d 2a 0a 20 2a 2f 0a 0a 54 63 6c 5f  -----*. */..Tcl_
2b80: 4f 62 6a 2a 0a 54 6c 73 5f 4e 65 77 58 35 30 39  Obj*.Tls_NewX509
2b90: 4f 62 6a 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a  Obj(Tcl_Interp *
2ba0: 69 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65  interp, X509 *ce
2bb0: 72 74 29 20 7b 0a 20 20 20 20 54 63 6c 5f 4f 62  rt) {.    Tcl_Ob
2bc0: 6a 20 2a 63 65 72 74 50 74 72 20 3d 20 54 63 6c  j *certPtr = Tcl
2bd0: 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e  _NewListObj(0, N
2be0: 55 4c 4c 29 3b 0a 20 20 20 20 42 49 4f 20 2a 62  ULL);.    BIO *b
2bf0: 69 6f 20 3d 20 42 49 4f 5f 6e 65 77 28 42 49 4f  io = BIO_new(BIO
2c00: 5f 73 5f 6d 65 6d 28 29 29 3b 0a 20 20 20 20 69  _s_mem());.    i
2c10: 6e 74 20 6d 64 6e 69 64 2c 20 70 6b 6e 69 64 2c  nt mdnid, pknid,
2c20: 20 62 69 74 73 2c 20 6c 65 6e 3b 0a 20 20 20 20   bits, len;.    
2c30: 75 69 6e 74 33 32 5f 74 20 78 66 6c 61 67 73 3b  uint32_t xflags;
2c40: 0a 20 20 20 20 63 68 61 72 20 62 75 66 66 65 72  .    char buffer
2c50: 5b 42 55 46 53 49 5a 5d 3b 0a 20 20 20 20 75 6e  [BUFSIZ];.    un
2c60: 73 69 67 6e 65 64 20 63 68 61 72 20 6d 64 5b 45  signed char md[E
2c70: 56 50 5f 4d 41 58 5f 4d 44 5f 53 49 5a 45 5d 3b  VP_MAX_MD_SIZE];
2c80: 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 20 6c 6f  .    unsigned lo
2c90: 6e 67 20 66 6c 61 67 73 20 3d 20 58 4e 5f 46 4c  ng flags = XN_FL
2ca0: 41 47 5f 52 46 43 32 32 35 33 20 7c 20 41 53 4e  AG_RFC2253 | ASN
2cb0: 31 5f 53 54 52 46 4c 47 53 5f 55 54 46 38 5f 43  1_STRFLGS_UTF8_C
2cc0: 4f 4e 56 45 52 54 3b 0a 20 20 20 20 66 6c 61 67  ONVERT;.    flag
2cd0: 73 20 26 3d 20 7e 41 53 4e 31 5f 53 54 52 46 4c  s &= ~ASN1_STRFL
2ce0: 47 53 5f 45 53 43 5f 4d 53 42 3b 0a 0a 20 20 20  GS_ESC_MSB;..   
2cf0: 20 69 66 20 28 69 6e 74 65 72 70 20 3d 3d 20 4e   if (interp == N
2d00: 55 4c 4c 20 7c 7c 20 63 65 72 74 20 3d 3d 20 4e  ULL || cert == N
2d10: 55 4c 4c 20 7c 7c 20 62 69 6f 20 3d 3d 20 4e 55  ULL || bio == NU
2d20: 4c 4c 20 7c 7c 20 63 65 72 74 50 74 72 20 3d 3d  LL || certPtr ==
2d30: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e   NULL) {..return
2d40: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20   NULL;.    }..  
2d50: 20 20 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61    /* Signature a
2d60: 6c 67 6f 72 69 74 68 6d 20 61 6e 64 20 76 61 6c  lgorithm and val
2d70: 75 65 20 2d 20 52 46 43 20 35 32 38 30 20 73 65  ue - RFC 5280 se
2d80: 63 74 69 6f 6e 20 34 2e 31 2e 31 2e 32 20 61 6e  ction 4.1.1.2 an
2d90: 64 20 34 2e 31 2e 31 2e 33 20 2a 2f 0a 20 20 20  d 4.1.1.3 */.   
2da0: 20 2f 2a 20 73 69 67 6e 61 74 75 72 65 41 6c 67   /* signatureAlg
2db0: 6f 72 69 74 68 6d 20 69 73 20 74 68 65 20 69 64  orithm is the id
2dc0: 20 6f 66 20 74 68 65 20 63 72 79 70 74 6f 67 72   of the cryptogr
2dd0: 61 70 68 69 63 20 61 6c 67 6f 72 69 74 68 6d 20  aphic algorithm 
2de0: 75 73 65 64 20 62 79 20 74 68 65 0a 09 43 41 20  used by the..CA 
2df0: 74 6f 20 73 69 67 6e 20 74 68 69 73 20 63 65 72  to sign this cer
2e00: 74 2e 20 73 69 67 6e 61 74 75 72 65 56 61 6c 75  t. signatureValu
2e10: 65 20 69 73 20 74 68 65 20 64 69 67 69 74 61 6c  e is the digital
2e20: 20 73 69 67 6e 61 74 75 72 65 20 63 6f 6d 70 75   signature compu
2e30: 74 65 64 0a 09 75 70 6f 6e 20 74 68 65 20 41 53  ted..upon the AS
2e40: 4e 2e 31 20 44 45 52 20 65 6e 63 6f 64 65 64 20  N.1 DER encoded 
2e50: 74 62 73 43 65 72 74 69 66 69 63 61 74 65 2e 20  tbsCertificate. 
2e60: 2a 2f 0a 20 20 20 20 7b 0a 09 63 6f 6e 73 74 20  */.    {..const 
2e70: 58 35 30 39 5f 41 4c 47 4f 52 20 2a 73 69 67 5f  X509_ALGOR *sig_
2e80: 61 6c 67 3b 0a 09 63 6f 6e 73 74 20 41 53 4e 31  alg;..const ASN1
2e90: 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a 73 69 67  _BIT_STRING *sig
2ea0: 3b 0a 09 69 6e 74 20 73 69 67 5f 6e 69 64 3b 0a  ;..int sig_nid;.
2eb0: 0a 09 58 35 30 39 5f 67 65 74 30 5f 73 69 67 6e  ..X509_get0_sign
2ec0: 61 74 75 72 65 28 26 73 69 67 2c 20 26 73 69 67  ature(&sig, &sig
2ed0: 5f 61 6c 67 2c 20 63 65 72 74 29 3b 0a 09 2f 2a  _alg, cert);../*
2ee0: 20 73 69 67 5f 6e 69 64 20 3d 20 58 35 30 39 5f   sig_nid = X509_
2ef0: 67 65 74 5f 73 69 67 6e 61 74 75 72 65 5f 6e 69  get_signature_ni
2f00: 64 28 63 65 72 74 29 20 2a 2f 0a 09 73 69 67 5f  d(cert) */..sig_
2f10: 6e 69 64 20 3d 20 4f 42 4a 5f 6f 62 6a 32 6e 69  nid = OBJ_obj2ni
2f20: 64 28 73 69 67 5f 61 6c 67 2d 3e 61 6c 67 6f 72  d(sig_alg->algor
2f30: 69 74 68 6d 29 3b 0a 09 4c 41 50 50 45 4e 44 5f  ithm);..LAPPEND_
2f40: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
2f50: 50 74 72 2c 20 22 73 69 67 6e 61 74 75 72 65 41  Ptr, "signatureA
2f60: 6c 67 6f 72 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e  lgorithm", OBJ_n
2f70: 69 64 32 6c 6e 28 73 69 67 5f 6e 69 64 29 2c 20  id2ln(sig_nid), 
2f80: 2d 31 29 3b 0a 09 6c 65 6e 20 3d 20 28 73 69 67  -1);..len = (sig
2f90: 5f 6e 69 64 20 21 3d 20 4e 49 44 5f 75 6e 64 65  _nid != NID_unde
2fa0: 66 29 20 3f 20 53 74 72 69 6e 67 5f 74 6f 5f 48  f) ? String_to_H
2fb0: 65 78 28 73 69 67 2d 3e 64 61 74 61 2c 20 73 69  ex(sig->data, si
2fc0: 67 2d 3e 6c 65 6e 67 74 68 2c 20 62 75 66 66 65  g->length, buffe
2fd0: 72 2c 20 42 55 46 53 49 5a 29 20 3a 20 30 3b 0a  r, BUFSIZ) : 0;.
2fe0: 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74  .LAPPEND_STR(int
2ff0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73  erp, certPtr, "s
3000: 69 67 6e 61 74 75 72 65 56 61 6c 75 65 22 2c 20  ignatureValue", 
3010: 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 20 20  buffer, len);.  
3020: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 56 65 72 73    }..    /* Vers
3030: 69 6f 6e 20 6f 66 20 74 68 65 20 65 6e 63 6f 64  ion of the encod
3040: 65 64 20 63 65 72 74 69 66 69 63 61 74 65 20 2d  ed certificate -
3050: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
3060: 6e 20 34 2e 31 2e 32 2e 31 20 2a 2f 0a 20 20 20  n 4.1.2.1 */.   
3070: 20 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 28 69 6e   LAPPEND_LONG(in
3080: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
3090: 76 65 72 73 69 6f 6e 22 2c 20 58 35 30 39 5f 67  version", X509_g
30a0: 65 74 5f 76 65 72 73 69 6f 6e 28 63 65 72 74 29  et_version(cert)
30b0: 2b 31 29 3b 0a 0a 20 20 20 20 2f 2a 20 55 6e 69  +1);..    /* Uni
30c0: 71 75 65 20 6e 75 6d 62 65 72 20 61 73 73 69 67  que number assig
30d0: 6e 65 64 20 62 79 20 43 41 20 74 6f 20 63 65 72  ned by CA to cer
30e0: 74 69 66 69 63 61 74 65 20 2d 20 52 46 43 20 35  tificate - RFC 5
30f0: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e  280 section 4.1.
3100: 32 2e 32 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d  2.2 */.    len =
3110: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 69   BIO_to_Buffer(i
3120: 32 61 5f 41 53 4e 31 5f 49 4e 54 45 47 45 52 28  2a_ASN1_INTEGER(
3130: 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30 5f 73  bio, X509_get0_s
3140: 65 72 69 61 6c 4e 75 6d 62 65 72 28 63 65 72 74  erialNumber(cert
3150: 29 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c  )), bio, buffer,
3160: 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41   BUFSIZ);.    LA
3170: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
3180: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65 72 69  , certPtr, "seri
3190: 61 6c 4e 75 6d 62 65 72 22 2c 20 62 75 66 66 65  alNumber", buffe
31a0: 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a  r, len);..    /*
31b0: 20 53 69 67 6e 61 74 75 72 65 20 61 6c 67 6f 72   Signature algor
31c0: 69 74 68 6d 20 75 73 65 64 20 62 79 20 74 68 65  ithm used by the
31d0: 20 43 41 20 74 6f 20 73 69 67 6e 20 74 68 65 20   CA to sign the 
31e0: 63 65 72 74 69 66 69 63 61 74 65 2e 20 4d 75 73  certificate. Mus
31f0: 74 20 6d 61 74 63 68 0a 09 73 69 67 6e 61 74 75  t match..signatu
3200: 72 65 41 6c 67 6f 72 69 74 68 6d 2e 20 52 46 43  reAlgorithm. RFC
3210: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e   5280 section 4.
3220: 31 2e 32 2e 33 20 2a 2f 0a 20 20 20 20 4c 41 50  1.2.3 */.    LAP
3230: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
3240: 20 63 65 72 74 50 74 72 2c 20 22 73 69 67 6e 61   certPtr, "signa
3250: 74 75 72 65 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c  ture", OBJ_nid2l
3260: 6e 28 58 35 30 39 5f 67 65 74 5f 73 69 67 6e 61  n(X509_get_signa
3270: 74 75 72 65 5f 6e 69 64 28 63 65 72 74 29 29 2c  ture_nid(cert)),
3280: 20 2d 31 29 3b 0a 0a 20 20 20 20 2f 2a 20 49 73   -1);..    /* Is
3290: 73 75 65 72 20 69 64 65 6e 74 69 66 69 65 73 20  suer identifies 
32a0: 74 68 65 20 65 6e 74 69 74 79 20 74 68 61 74 20  the entity that 
32b0: 73 69 67 6e 65 64 20 61 6e 64 20 69 73 73 75 65  signed and issue
32c0: 64 20 74 68 65 20 63 65 72 74 2e 20 52 46 43 20  d the cert. RFC 
32d0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31  5280 section 4.1
32e0: 2e 32 2e 34 20 2a 2f 0a 20 20 20 20 6c 65 6e 20  .2.4 */.    len 
32f0: 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28  = BIO_to_Buffer(
3300: 58 35 30 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f  X509_NAME_print_
3310: 65 78 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74  ex(bio, X509_get
3320: 5f 69 73 73 75 65 72 5f 6e 61 6d 65 28 63 65 72  _issuer_name(cer
3330: 74 29 2c 20 30 2c 20 66 6c 61 67 73 29 2c 20 62  t), 0, flags), b
3340: 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53  io, buffer, BUFS
3350: 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44  IZ);.    LAPPEND
3360: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72  _STR(interp, cer
3370: 74 50 74 72 2c 20 22 69 73 73 75 65 72 22 2c 20  tPtr, "issuer", 
3380: 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20  buffer, len);.. 
3390: 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74     /* Certificat
33a0: 65 20 76 61 6c 69 64 69 74 79 20 70 65 72 69 6f  e validity perio
33b0: 64 20 69 73 20 74 68 65 20 69 6e 74 65 72 76 61  d is the interva
33c0: 6c 20 74 68 65 20 43 41 20 77 61 72 72 61 6e 74  l the CA warrant
33d0: 73 20 74 68 61 74 20 69 74 20 77 69 6c 6c 0a 09  s that it will..
33e0: 6d 61 69 6e 74 61 69 6e 20 69 6e 66 6f 20 6f 6e  maintain info on
33f0: 20 74 68 65 20 73 74 61 74 75 73 20 6f 66 20 74   the status of t
3400: 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20  he certificate. 
3410: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
3420: 20 34 2e 31 2e 32 2e 35 20 2a 2f 0a 20 20 20 20   4.1.2.5 */.    
3430: 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 74 79 20  /* Get Validity 
3440: 2d 20 4e 6f 74 20 42 65 66 6f 72 65 20 2a 2f 0a  - Not Before */.
3450: 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f      len = BIO_to
3460: 5f 42 75 66 66 65 72 28 41 53 4e 31 5f 54 49 4d  _Buffer(ASN1_TIM
3470: 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 35 30  E_print(bio, X50
3480: 39 5f 67 65 74 30 5f 6e 6f 74 42 65 66 6f 72 65  9_get0_notBefore
3490: 28 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75  (cert)), bio, bu
34a0: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20  ffer, BUFSIZ);. 
34b0: 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69     LAPPEND_STR(i
34c0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
34d0: 22 6e 6f 74 42 65 66 6f 72 65 22 2c 20 62 75 66  "notBefore", buf
34e0: 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20  fer, len);..    
34f0: 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 74 79 20  /* Get Validity 
3500: 2d 20 4e 6f 74 20 41 66 74 65 72 20 2a 2f 0a 20  - Not After */. 
3510: 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f     len = BIO_to_
3520: 42 75 66 66 65 72 28 41 53 4e 31 5f 54 49 4d 45  Buffer(ASN1_TIME
3530: 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 35 30 39  _print(bio, X509
3540: 5f 67 65 74 30 5f 6e 6f 74 41 66 74 65 72 28 63  _get0_notAfter(c
3550: 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66 66  ert)), bio, buff
3560: 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20 20  er, BUFSIZ);.   
3570: 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74   LAPPEND_STR(int
3580: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 6e  erp, certPtr, "n
3590: 6f 74 41 66 74 65 72 22 2c 20 62 75 66 66 65 72  otAfter", buffer
35a0: 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20  , len);..    /* 
35b0: 53 75 62 6a 65 63 74 20 69 64 65 6e 74 69 66 69  Subject identifi
35c0: 65 73 20 74 68 65 20 65 6e 74 69 74 79 20 61 73  es the entity as
35d0: 73 6f 63 69 61 74 65 64 20 77 69 74 68 20 74 68  sociated with th
35e0: 65 20 70 75 62 6c 69 63 20 6b 65 79 20 73 74 6f  e public key sto
35f0: 72 65 64 20 69 6e 0a 09 74 68 65 20 73 75 62 6a  red in..the subj
3600: 65 63 74 20 70 75 62 6c 69 63 20 6b 65 79 20 66  ect public key f
3610: 69 65 6c 64 2e 20 52 46 43 20 35 32 38 30 20 73  ield. RFC 5280 s
3620: 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 36 20 2a  ection 4.1.2.6 *
3630: 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f  /.    len = BIO_
3640: 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39 5f 4e  to_Buffer(X509_N
3650: 41 4d 45 5f 70 72 69 6e 74 5f 65 78 28 62 69 6f  AME_print_ex(bio
3660: 2c 20 58 35 30 39 5f 67 65 74 5f 73 75 62 6a 65  , X509_get_subje
3670: 63 74 5f 6e 61 6d 65 28 63 65 72 74 29 2c 20 30  ct_name(cert), 0
3680: 2c 20 66 6c 61 67 73 29 2c 20 62 69 6f 2c 20 62  , flags), bio, b
3690: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a  uffer, BUFSIZ);.
36a0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28      LAPPEND_STR(
36b0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
36c0: 20 22 73 75 62 6a 65 63 74 22 2c 20 62 75 66 66   "subject", buff
36d0: 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f  er, len);..    /
36e0: 2a 20 53 48 41 31 20 44 69 67 65 73 74 20 28 46  * SHA1 Digest (F
36f0: 69 6e 67 65 72 70 72 69 6e 74 29 20 6f 66 20 63  ingerprint) of c
3700: 65 72 74 20 2d 20 44 45 52 20 72 65 70 72 65 73  ert - DER repres
3710: 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 20 20 20  entation */.    
3720: 69 66 20 28 58 35 30 39 5f 64 69 67 65 73 74 28  if (X509_digest(
3730: 63 65 72 74 2c 20 45 56 50 5f 73 68 61 31 28 29  cert, EVP_sha1()
3740: 2c 20 6d 64 2c 20 26 6c 65 6e 29 29 20 7b 0a 20  , md, &len)) {. 
3750: 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f     len = String_
3760: 74 6f 5f 48 65 78 28 6d 64 2c 20 6c 65 6e 2c 20  to_Hex(md, len, 
3770: 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b  buffer, BUFSIZ);
3780: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e  ..LAPPEND_STR(in
3790: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
37a0: 73 68 61 31 5f 68 61 73 68 22 2c 20 62 75 66 66  sha1_hash", buff
37b0: 65 72 2c 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a  er, len);.    }.
37c0: 0a 20 20 20 20 2f 2a 20 53 48 41 32 35 36 20 44  .    /* SHA256 D
37d0: 69 67 65 73 74 20 28 46 69 6e 67 65 72 70 72 69  igest (Fingerpri
37e0: 6e 74 29 20 6f 66 20 63 65 72 74 20 2d 20 44 45  nt) of cert - DE
37f0: 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e  R representation
3800: 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30 39   */.    if (X509
3810: 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45 56  _digest(cert, EV
3820: 50 5f 73 68 61 32 35 36 28 29 2c 20 6d 64 2c 20  P_sha256(), md, 
3830: 26 6c 65 6e 29 29 20 7b 0a 20 20 20 20 6c 65 6e  &len)) {.    len
3840: 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78   = String_to_Hex
3850: 28 6d 64 2c 20 6c 65 6e 2c 20 62 75 66 66 65 72  (md, len, buffer
3860: 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50  , BUFSIZ);..LAPP
3870: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20  END_STR(interp, 
3880: 63 65 72 74 50 74 72 2c 20 22 73 68 61 32 35 36  certPtr, "sha256
3890: 5f 68 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20  _hash", buffer, 
38a0: 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  len);.    }..   
38b0: 20 2f 2a 20 53 75 62 6a 65 63 74 20 50 75 62 6c   /* Subject Publ
38c0: 69 63 20 4b 65 79 20 49 6e 66 6f 20 73 70 65 63  ic Key Info spec
38d0: 69 66 69 65 73 20 74 68 65 20 70 75 62 6c 69 63  ifies the public
38e0: 20 6b 65 79 20 61 6e 64 20 69 64 65 6e 74 69 66   key and identif
38f0: 69 65 73 20 74 68 65 0a 09 61 6c 67 6f 72 69 74  ies the..algorit
3900: 68 6d 20 77 69 74 68 20 77 68 69 63 68 20 74 68  hm with which th
3910: 65 20 6b 65 79 20 69 73 20 75 73 65 64 2e 20 52  e key is used. R
3920: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
3930: 34 2e 31 2e 32 2e 37 20 2a 2f 0a 20 20 20 20 69  4.1.2.7 */.    i
3940: 66 20 28 58 35 30 39 5f 67 65 74 5f 73 69 67 6e  f (X509_get_sign
3950: 61 74 75 72 65 5f 69 6e 66 6f 28 63 65 72 74 2c  ature_info(cert,
3960: 20 26 6d 64 6e 69 64 2c 20 26 70 6b 6e 69 64 2c   &mdnid, &pknid,
3970: 20 26 62 69 74 73 2c 20 26 78 66 6c 61 67 73 29   &bits, &xflags)
3980: 29 20 7b 0a 09 41 53 4e 31 5f 42 49 54 5f 53 54  ) {..ASN1_BIT_ST
3990: 52 49 4e 47 20 2a 6b 65 79 3b 0a 09 75 6e 73 69  RING *key;..unsi
39a0: 67 6e 65 64 20 69 6e 74 20 6e 3b 0a 0a 09 4c 41  gned int n;...LA
39b0: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
39c0: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 67 6e  , certPtr, "sign
39d0: 69 6e 67 44 69 67 65 73 74 22 2c 20 4f 42 4a 5f  ingDigest", OBJ_
39e0: 6e 69 64 32 6c 6e 28 6d 64 6e 69 64 29 2c 20 2d  nid2ln(mdnid), -
39f0: 31 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52  1);..LAPPEND_STR
3a00: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
3a10: 2c 20 22 70 75 62 6c 69 63 4b 65 79 41 6c 67 6f  , "publicKeyAlgo
3a20: 72 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e 69 64 32  rithm", OBJ_nid2
3a30: 6c 6e 28 70 6b 6e 69 64 29 2c 20 2d 31 29 3b 0a  ln(pknid), -1);.
3a40: 09 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74  .LAPPEND_INT(int
3a50: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 62  erp, certPtr, "b
3a60: 69 74 73 22 2c 20 62 69 74 73 29 3b 20 2f 2a 20  its", bits); /* 
3a70: 45 66 66 65 63 74 69 76 65 20 73 65 63 75 72 69  Effective securi
3a80: 74 79 20 62 69 74 73 20 2a 2f 0a 0a 09 6b 65 79  ty bits */...key
3a90: 20 3d 20 58 35 30 39 5f 67 65 74 30 5f 70 75 62   = X509_get0_pub
3aa0: 6b 65 79 5f 62 69 74 73 74 72 28 63 65 72 74 29  key_bitstr(cert)
3ab0: 3b 0a 09 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f  ;..len = String_
3ac0: 74 6f 5f 48 65 78 28 6b 65 79 2d 3e 64 61 74 61  to_Hex(key->data
3ad0: 2c 20 6b 65 79 2d 3e 6c 65 6e 67 74 68 2c 20 62  , key->length, b
3ae0: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a  uffer, BUFSIZ);.
3af0: 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74  .LAPPEND_STR(int
3b00: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70  erp, certPtr, "p
3b10: 75 62 6c 69 63 4b 65 79 22 2c 20 62 75 66 66 65  ublicKey", buffe
3b20: 72 2c 20 6c 65 6e 29 3b 0a 0a 09 6c 65 6e 20 3d  r, len);...len =
3b30: 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f 70 75   0;..if (X509_pu
3b40: 62 6b 65 79 5f 64 69 67 65 73 74 28 63 65 72 74  bkey_digest(cert
3b50: 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65 73 74  , EVP_get_digest
3b60: 62 79 6e 69 64 28 70 6b 6e 69 64 29 2c 20 6d 64  bynid(pknid), md
3b70: 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20 6c 65  , &n)) {..    le
3b80: 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65  n = String_to_He
3b90: 78 28 6d 64 2c 20 28 69 6e 74 29 6e 2c 20 62 75  x(md, (int)n, bu
3ba0: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09  ffer, BUFSIZ);..
3bb0: 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69  }..LAPPEND_STR(i
3bc0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
3bd0: 22 70 75 62 6c 69 63 4b 65 79 48 61 73 68 22 2c  "publicKeyHash",
3be0: 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a   buffer, len);..
3bf0: 09 2f 2a 20 64 69 67 65 73 74 20 6f 66 20 74 68  ./* digest of th
3c00: 65 20 44 45 52 20 72 65 70 72 65 73 65 6e 74 61  e DER representa
3c10: 74 69 6f 6e 20 6f 66 20 74 68 65 20 63 65 72 74  tion of the cert
3c20: 69 66 69 63 61 74 65 20 2a 2f 0a 09 6c 65 6e 20  ificate */..len 
3c30: 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f 64  = 0;..if (X509_d
3c40: 69 67 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f  igest(cert, EVP_
3c50: 67 65 74 5f 64 69 67 65 73 74 62 79 6e 69 64 28  get_digestbynid(
3c60: 6d 64 6e 69 64 29 2c 20 6d 64 2c 20 26 6e 29 29  mdnid), md, &n))
3c70: 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d 20 53 74   {..    len = St
3c80: 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20  ring_to_Hex(md, 
3c90: 28 69 6e 74 29 6e 2c 20 62 75 66 66 65 72 2c 20  (int)n, buffer, 
3ca0: 42 55 46 53 49 5a 29 3b 0a 09 7d 0a 09 4c 41 50  BUFSIZ);..}..LAP
3cb0: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
3cc0: 20 63 65 72 74 50 74 72 2c 20 22 73 69 67 6e 61   certPtr, "signa
3cd0: 74 75 72 65 48 61 73 68 22 2c 20 62 75 66 66 65  tureHash", buffe
3ce0: 72 2c 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a  r, len);.    }..
3cf0: 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61      /* Certifica
3d00: 74 65 20 50 75 72 70 6f 73 65 2e 20 43 61 6c 6c  te Purpose. Call
3d10: 20 62 65 66 6f 72 65 20 63 68 65 63 6b 69 6e 67   before checking
3d20: 20 66 6f 72 20 65 78 74 65 6e 73 69 6f 6e 73 2e   for extensions.
3d30: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f   */.    LAPPEND_
3d40: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
3d50: 50 74 72 2c 20 22 70 75 72 70 6f 73 65 22 2c 20  Ptr, "purpose", 
3d60: 54 6c 73 5f 78 35 30 39 50 75 72 70 6f 73 65 28  Tls_x509Purpose(
3d70: 63 65 72 74 29 2c 20 2d 31 29 3b 0a 20 20 20 20  cert), -1);.    
3d80: 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65  LAPPEND_OBJ(inte
3d90: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 65  rp, certPtr, "ce
3da0: 72 74 69 66 69 63 61 74 65 50 75 72 70 6f 73 65  rtificatePurpose
3db0: 22 2c 20 54 6c 73 5f 78 35 30 39 50 75 72 70 6f  ", Tls_x509Purpo
3dc0: 73 65 73 28 69 6e 74 65 72 70 2c 20 63 65 72 74  ses(interp, cert
3dd0: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 65 74 20  ));..    /* Get 
3de0: 65 78 74 65 6e 73 69 6f 6e 73 20 66 6c 61 67 73  extensions flags
3df0: 20 2a 2f 0a 20 20 20 20 78 66 6c 61 67 73 20 3d   */.    xflags =
3e00: 20 58 35 30 39 5f 67 65 74 5f 65 78 74 65 6e 73   X509_get_extens
3e10: 69 6f 6e 5f 66 6c 61 67 73 28 63 65 72 74 29 3b  ion_flags(cert);
3e20: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 49 4e 54  .    LAPPEND_INT
3e30: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
3e40: 2c 20 22 65 78 74 46 6c 61 67 73 22 2c 20 78 66  , "extFlags", xf
3e50: 6c 61 67 73 29 3b 0a 0a 09 2f 2a 20 43 68 65 63  lags);.../* Chec
3e60: 6b 20 69 66 20 63 65 72 74 20 77 61 73 20 69 73  k if cert was is
3e70: 73 75 65 64 20 62 79 20 43 41 20 63 65 72 74 20  sued by CA cert 
3e80: 69 73 73 75 65 72 20 6f 72 20 73 65 6c 66 20 73  issuer or self s
3e90: 69 67 6e 65 64 20 2a 2f 0a 20 20 20 20 4c 41 50  igned */.    LAP
3ea0: 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70  PEND_BOOL(interp
3eb0: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65 6c 66  , certPtr, "self
3ec0: 49 73 73 75 65 64 22 2c 20 78 66 6c 61 67 73 20  Issued", xflags 
3ed0: 26 20 45 58 46 4c 41 47 5f 53 49 29 3b 0a 20 20  & EXFLAG_SI);.  
3ee0: 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69    LAPPEND_BOOL(i
3ef0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
3f00: 22 73 65 6c 66 53 69 67 6e 65 64 22 2c 20 78 66  "selfSigned", xf
3f10: 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 53 53  lags & EXFLAG_SS
3f20: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42  );.    LAPPEND_B
3f30: 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74  OOL(interp, cert
3f40: 50 74 72 2c 20 22 69 73 50 72 6f 78 79 43 65 72  Ptr, "isProxyCer
3f50: 74 22 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46  t", xflags & EXF
3f60: 4c 41 47 5f 50 52 4f 58 59 29 3b 0a 20 20 20 20  LAG_PROXY);.    
3f70: 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74  LAPPEND_BOOL(int
3f80: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65  erp, certPtr, "e
3f90: 78 74 49 6e 76 61 6c 69 64 22 2c 20 78 66 6c 61  xtInvalid", xfla
3fa0: 67 73 20 26 20 45 58 46 4c 41 47 5f 49 4e 56 41  gs & EXFLAG_INVA
3fb0: 4c 49 44 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e  LID);.    LAPPEN
3fc0: 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63  D_BOOL(interp, c
3fd0: 65 72 74 50 74 72 2c 20 22 69 73 43 41 43 65 72  ertPtr, "isCACer
3fe0: 74 22 2c 20 58 35 30 39 5f 63 68 65 63 6b 5f 63  t", X509_check_c
3ff0: 61 28 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f  a(cert));..    /
4000: 2a 20 54 68 65 20 55 6e 69 71 75 65 20 49 64 73  * The Unique Ids
4010: 20 61 72 65 20 75 73 65 64 20 74 6f 20 68 61 6e   are used to han
4020: 64 6c 65 20 74 68 65 20 70 6f 73 73 69 62 69 6c  dle the possibil
4030: 69 74 79 20 6f 66 20 72 65 75 73 65 20 6f 66 20  ity of reuse of 
4040: 73 75 62 6a 65 63 74 0a 09 61 6e 64 2f 6f 72 20  subject..and/or 
4050: 69 73 73 75 65 72 20 6e 61 6d 65 73 20 6f 76 65  issuer names ove
4060: 72 20 74 69 6d 65 2e 20 52 46 43 20 35 32 38 30  r time. RFC 5280
4070: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 38   section 4.1.2.8
4080: 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 6f 6e 73 74   */.    {..const
4090: 20 41 53 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47   ASN1_BIT_STRING
40a0: 20 2a 69 75 69 64 2c 20 2a 73 75 69 64 3b 0a 20   *iuid, *suid;. 
40b0: 20 20 20 20 20 20 20 58 35 30 39 5f 67 65 74 30         X509_get0
40c0: 5f 75 69 64 73 28 63 65 72 74 2c 20 26 69 75 69  _uids(cert, &iui
40d0: 64 2c 20 26 73 75 69 64 29 3b 0a 0a 09 54 63 6c  d, &suid);...Tcl
40e0: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
40f0: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65  ement(interp, ce
4100: 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  rtPtr, Tcl_NewSt
4110: 72 69 6e 67 4f 62 6a 28 22 69 73 73 75 65 72 55  ringObj("issuerU
4120: 6e 69 71 75 65 49 64 22 2c 20 2d 31 29 29 3b 0a  niqueId", -1));.
4130: 09 69 66 20 28 69 75 69 64 20 21 3d 20 4e 55 4c  .if (iuid != NUL
4140: 4c 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69  L) {..    Tcl_Li
4150: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
4160: 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  nt(interp, certP
4170: 74 72 2c 20 54 63 6c 5f 4e 65 77 42 79 74 65 41  tr, Tcl_NewByteA
4180: 72 72 61 79 4f 62 6a 28 28 63 68 61 72 20 2a 29  rrayObj((char *)
4190: 69 75 69 64 2d 3e 64 61 74 61 2c 20 69 75 69 64  iuid->data, iuid
41a0: 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 7d 20 65  ->length));..} e
41b0: 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  lse {..    Tcl_L
41c0: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
41d0: 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74  ent(interp, cert
41e0: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
41f0: 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 29 3b 0a  ngObj("", -1));.
4200: 09 7d 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 6a  .}...Tcl_ListObj
4210: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e  AppendElement(in
4220: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54  terp, certPtr, T
4230: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28  cl_NewStringObj(
4240: 22 73 75 62 6a 65 63 74 55 6e 69 71 75 65 49 64  "subjectUniqueId
4250: 22 2c 20 2d 31 29 29 3b 0a 09 69 66 20 28 73 75  ", -1));..if (su
4260: 69 64 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20  id != NULL) {.. 
4270: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
4280: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
4290: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c  rp, certPtr, Tcl
42a0: 5f 4e 65 77 42 79 74 65 41 72 72 61 79 4f 62 6a  _NewByteArrayObj
42b0: 28 28 63 68 61 72 20 2a 29 73 75 69 64 2d 3e 64  ((char *)suid->d
42c0: 61 74 61 2c 20 73 75 69 64 2d 3e 6c 65 6e 67 74  ata, suid->lengt
42d0: 68 29 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09  h));..} else {..
42e0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
42f0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
4300: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63  erp, certPtr, Tc
4310: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
4320: 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 20 20  ", -1));..}.    
4330: 7d 0a 0a 20 20 20 20 2f 2a 20 58 35 30 39 20 76  }..    /* X509 v
4340: 33 20 45 78 74 65 6e 73 69 6f 6e 73 20 2d 20 52  3 Extensions - R
4350: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
4360: 34 2e 31 2e 32 2e 39 20 2a 2f 0a 20 20 20 20 4c  4.1.2.9 */.    L
4370: 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72  APPEND_INT(inter
4380: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 74  p, certPtr, "ext
4390: 43 6f 75 6e 74 22 2c 20 58 35 30 39 5f 67 65 74  Count", X509_get
43a0: 5f 65 78 74 5f 63 6f 75 6e 74 28 63 65 72 74 29  _ext_count(cert)
43b0: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f  );.    LAPPEND_O
43c0: 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  BJ(interp, certP
43d0: 74 72 2c 20 22 65 78 74 65 6e 73 69 6f 6e 73 22  tr, "extensions"
43e0: 2c 20 54 6c 73 5f 78 35 30 39 45 78 74 65 6e 73  , Tls_x509Extens
43f0: 69 6f 6e 73 28 69 6e 74 65 72 70 2c 20 63 65 72  ions(interp, cer
4400: 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 41 75 74  t));..    /* Aut
4410: 68 6f 72 69 74 79 20 4b 65 79 20 49 64 65 6e 74  hority Key Ident
4420: 69 66 69 65 72 20 28 41 4b 49 29 20 69 73 20 74  ifier (AKI) is t
4430: 68 65 20 53 75 62 6a 65 63 74 20 4b 65 79 20 49  he Subject Key I
4440: 64 65 6e 74 69 66 69 65 72 20 28 53 4b 49 29 20  dentifier (SKI) 
4450: 6f 66 0a 09 69 74 73 20 73 69 67 6e 65 72 20 28  of..its signer (
4460: 74 68 65 20 43 41 29 2e 20 52 46 43 20 35 32 38  the CA). RFC 528
4470: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e  0 section 4.2.1.
4480: 31 2c 20 4e 49 44 5f 61 75 74 68 6f 72 69 74 79  1, NID_authority
4490: 5f 6b 65 79 5f 69 64 65 6e 74 69 66 69 65 72 20  _key_identifier 
44a0: 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f  */.    LAPPEND_O
44b0: 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  BJ(interp, certP
44c0: 74 72 2c 20 22 61 75 74 68 6f 72 69 74 79 4b 65  tr, "authorityKe
44d0: 79 49 64 65 6e 74 69 66 69 65 72 22 2c 0a 09 54  yIdentifier",..T
44e0: 6c 73 5f 78 35 30 39 49 64 65 6e 74 69 66 69 65  ls_x509Identifie
44f0: 72 28 58 35 30 39 5f 67 65 74 30 5f 61 75 74 68  r(X509_get0_auth
4500: 6f 72 69 74 79 5f 6b 65 79 5f 69 64 28 63 65 72  ority_key_id(cer
4510: 74 29 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 75  t)));..    /* Su
4520: 62 6a 65 63 74 20 4b 65 79 20 49 64 65 6e 74 69  bject Key Identi
4530: 66 69 65 72 20 28 53 4b 49 29 20 69 73 20 75 73  fier (SKI) is us
4540: 65 64 20 74 6f 20 69 64 65 6e 74 69 66 79 20 63  ed to identify c
4550: 65 72 74 69 66 69 63 61 74 65 73 20 74 68 61 74  ertificates that
4560: 20 63 6f 6e 74 61 69 6e 0a 09 61 20 70 61 72 74   contain..a part
4570: 69 63 75 6c 61 72 20 70 75 62 6c 69 63 20 6b 65  icular public ke
4580: 79 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74  y. RFC 5280 sect
4590: 69 6f 6e 20 34 2e 32 2e 31 2e 32 2c 20 4e 49 44  ion 4.2.1.2, NID
45a0: 5f 73 75 62 6a 65 63 74 5f 6b 65 79 5f 69 64 65  _subject_key_ide
45b0: 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20 20 20 4c  ntifier */.    L
45c0: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72  APPEND_OBJ(inter
45d0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 75 62  p, certPtr, "sub
45e0: 6a 65 63 74 4b 65 79 49 64 65 6e 74 69 66 69 65  jectKeyIdentifie
45f0: 72 22 2c 0a 09 54 6c 73 5f 78 35 30 39 49 64 65  r",..Tls_x509Ide
4600: 6e 74 69 66 69 65 72 28 58 35 30 39 5f 67 65 74  ntifier(X509_get
4610: 30 5f 73 75 62 6a 65 63 74 5f 6b 65 79 5f 69 64  0_subject_key_id
4620: 28 63 65 72 74 29 29 29 3b 0a 0a 20 20 20 20 2f  (cert)));..    /
4630: 2a 20 4b 65 79 20 75 73 61 67 65 20 65 78 74 65  * Key usage exte
4640: 6e 73 69 6f 6e 20 64 65 66 69 6e 65 73 20 74 68  nsion defines th
4650: 65 20 70 75 72 70 6f 73 65 20 28 65 2e 67 2e 2c  e purpose (e.g.,
4660: 20 65 6e 63 69 70 68 65 72 6d 65 6e 74 2c 20 73   encipherment, s
4670: 69 67 6e 61 74 75 72 65 2c 20 63 65 72 74 69 66  ignature, certif
4680: 69 63 61 74 65 0a 09 73 69 67 6e 69 6e 67 29 20  icate..signing) 
4690: 6f 66 20 74 68 65 20 6b 65 79 20 69 6e 20 74 68  of the key in th
46a0: 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 52  e certificate. R
46b0: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
46c0: 34 2e 32 2e 31 2e 33 2c 20 4e 49 44 5f 6b 65 79  4.2.1.3, NID_key
46d0: 5f 75 73 61 67 65 20 2a 2f 0a 20 20 20 20 4c 41  _usage */.    LA
46e0: 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70  PPEND_OBJ(interp
46f0: 2c 20 63 65 72 74 50 74 72 2c 20 22 6b 65 79 55  , certPtr, "keyU
4700: 73 61 67 65 22 2c 20 54 6c 73 5f 78 35 30 39 4b  sage", Tls_x509K
4710: 65 79 55 73 61 67 65 28 69 6e 74 65 72 70 2c 20  eyUsage(interp, 
4720: 63 65 72 74 2c 20 78 66 6c 61 67 73 29 29 3b 0a  cert, xflags));.
4730: 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63  .    /* Certific
4740: 61 74 65 20 50 6f 6c 69 63 69 65 73 20 2d 20 69  ate Policies - i
4750: 6e 64 69 63 61 74 65 73 20 74 68 65 20 69 73 73  ndicates the iss
4760: 75 69 6e 67 20 43 41 20 63 6f 6e 73 69 64 65 72  uing CA consider
4770: 73 20 69 74 73 20 69 73 73 75 65 72 44 6f 6d 61  s its issuerDoma
4780: 69 6e 50 6f 6c 69 63 79 0a 09 65 71 75 69 76 61  inPolicy..equiva
4790: 6c 65 6e 74 20 74 6f 20 74 68 65 20 73 75 62 6a  lent to the subj
47a0: 65 63 74 20 43 41 27 73 20 73 75 62 6a 65 63 74  ect CA's subject
47b0: 44 6f 6d 61 69 6e 50 6f 6c 69 63 79 2e 20 52 46  DomainPolicy. RF
47c0: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34  C 5280 section 4
47d0: 2e 32 2e 31 2e 34 2c 20 4e 49 44 5f 63 65 72 74  .2.1.4, NID_cert
47e0: 69 66 69 63 61 74 65 5f 70 6f 6c 69 63 69 65 73  ificate_policies
47f0: 20 2a 2f 0a 20 20 20 20 69 66 20 28 78 66 6c 61   */.    if (xfla
4800: 67 73 20 26 20 45 58 46 4c 41 47 5f 49 4e 56 41  gs & EXFLAG_INVA
4810: 4c 49 44 5f 50 4f 4c 49 43 59 29 20 7b 0a 09 2f  LID_POLICY) {../
4820: 2a 20 52 65 6a 65 63 74 20 63 65 72 74 20 2a 2f  * Reject cert */
4830: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 50  .    }..    /* P
4840: 6f 6c 69 63 79 20 4d 61 70 70 69 6e 67 73 20 2d  olicy Mappings -
4850: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
4860: 6e 20 34 2e 32 2e 31 2e 35 2c 20 4e 49 44 5f 70  n 4.2.1.5, NID_p
4870: 6f 6c 69 63 79 5f 6d 61 70 70 69 6e 67 73 20 2a  olicy_mappings *
4880: 2f 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 63  /..    /* Subjec
4890: 74 20 41 6c 74 65 72 6e 61 74 69 76 65 20 4e 61  t Alternative Na
48a0: 6d 65 20 28 53 41 4e 29 20 63 6f 6e 74 61 69 6e  me (SAN) contain
48b0: 73 20 61 64 64 69 74 69 6f 6e 61 6c 20 55 52 4c  s additional URL
48c0: 73 2c 20 44 4e 53 20 6e 61 6d 65 73 2c 20 6f 72  s, DNS names, or
48d0: 20 49 50 0a 09 61 64 64 72 65 73 73 65 73 20 62   IP..addresses b
48e0: 6f 75 6e 64 20 74 6f 20 63 65 72 74 69 66 69 63  ound to certific
48f0: 61 74 65 2e 20 52 46 43 20 35 32 38 30 20 73 65  ate. RFC 5280 se
4900: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 36 2c 20 4e  ction 4.2.1.6, N
4910: 49 44 5f 73 75 62 6a 65 63 74 5f 61 6c 74 5f 6e  ID_subject_alt_n
4920: 61 6d 65 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45  ame */.    LAPPE
4930: 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63  ND_OBJ(interp, c
4940: 65 72 74 50 74 72 2c 20 22 73 75 62 6a 65 63 74  ertPtr, "subject
4950: 41 6c 74 4e 61 6d 65 22 2c 20 54 6c 73 5f 78 35  AltName", Tls_x5
4960: 30 39 4e 61 6d 65 73 28 69 6e 74 65 72 70 2c 20  09Names(interp, 
4970: 63 65 72 74 2c 20 4e 49 44 5f 73 75 62 6a 65 63  cert, NID_subjec
4980: 74 5f 61 6c 74 5f 6e 61 6d 65 2c 20 62 69 6f 29  t_alt_name, bio)
4990: 29 3b 0a 0a 20 20 20 20 2f 2a 20 49 73 73 75 65  );..    /* Issue
49a0: 72 20 41 6c 74 65 72 6e 61 74 69 76 65 20 4e 61  r Alternative Na
49b0: 6d 65 20 69 73 20 75 73 65 64 20 74 6f 20 61 73  me is used to as
49c0: 73 6f 63 69 61 74 65 20 49 6e 74 65 72 6e 65 74  sociate Internet
49d0: 20 73 74 79 6c 65 20 69 64 65 6e 74 69 74 69 65   style identitie
49e0: 73 0a 09 77 69 74 68 20 74 68 65 20 63 65 72 74  s..with the cert
49f0: 69 66 69 63 61 74 65 20 69 73 73 75 65 72 2e 20  ificate issuer. 
4a00: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
4a10: 20 34 2e 32 2e 31 2e 37 2c 20 4e 49 44 5f 69 73   4.2.1.7, NID_is
4a20: 73 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 20 2a 2f  suer_alt_name */
4a30: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a  .    LAPPEND_OBJ
4a40: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
4a50: 2c 20 22 69 73 73 75 65 72 41 6c 74 4e 61 6d 65  , "issuerAltName
4a60: 22 2c 20 54 6c 73 5f 78 35 30 39 4e 61 6d 65 73  ", Tls_x509Names
4a70: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 2c 20 4e  (interp, cert, N
4a80: 49 44 5f 69 73 73 75 65 72 5f 61 6c 74 5f 6e 61  ID_issuer_alt_na
4a90: 6d 65 2c 20 62 69 6f 29 29 3b 0a 0a 20 20 20 20  me, bio));..    
4aa0: 2f 2a 20 53 75 62 6a 65 63 74 20 44 69 72 65 63  /* Subject Direc
4ab0: 74 6f 72 79 20 41 74 74 72 69 62 75 74 65 73 20  tory Attributes 
4ac0: 70 72 6f 76 69 64 65 73 20 69 64 65 6e 74 69 66  provides identif
4ad0: 69 63 61 74 69 6f 6e 20 61 74 74 72 69 62 75 74  ication attribut
4ae0: 65 73 20 28 65 2e 67 2e 2c 20 6e 61 74 69 6f 6e  es (e.g., nation
4af0: 61 6c 69 74 79 29 0a 09 6f 66 20 74 68 65 20 73  ality)..of the s
4b00: 75 62 6a 65 63 74 2e 20 52 46 43 20 35 32 38 30  ubject. RFC 5280
4b10: 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 38   section 4.2.1.8
4b20: 20 28 73 75 62 6a 65 63 74 44 69 72 65 63 74 6f   (subjectDirecto
4b30: 72 79 41 74 74 72 69 62 75 74 65 73 29 20 2a 2f  ryAttributes) */
4b40: 0a 0a 20 20 20 20 2f 2a 20 42 61 73 69 63 20 43  ..    /* Basic C
4b50: 6f 6e 73 74 72 61 69 6e 74 73 20 69 64 65 6e 74  onstraints ident
4b60: 69 66 69 65 73 20 77 68 65 74 68 65 72 20 74 68  ifies whether th
4b70: 65 20 73 75 62 6a 65 63 74 20 6f 66 20 74 68 65  e subject of the
4b80: 20 63 65 72 74 20 69 73 20 61 20 43 41 20 61 6e   cert is a CA an
4b90: 64 0a 09 74 68 65 20 6d 61 78 20 64 65 70 74 68  d..the max depth
4ba0: 20 6f 66 20 76 61 6c 69 64 20 63 65 72 74 20 70   of valid cert p
4bb0: 61 74 68 73 20 66 6f 72 20 74 68 69 73 20 63 65  aths for this ce
4bc0: 72 74 2e 20 52 46 43 20 35 32 38 30 20 73 65 63  rt. RFC 5280 sec
4bd0: 74 69 6f 6e 20 34 2e 32 2e 31 2e 39 2c 20 4e 49  tion 4.2.1.9, NI
4be0: 44 5f 62 61 73 69 63 5f 63 6f 6e 73 74 72 61 69  D_basic_constrai
4bf0: 6e 74 73 20 2a 2f 0a 20 20 20 20 69 66 20 28 21  nts */.    if (!
4c00: 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47  (xflags & EXFLAG
4c10: 5f 50 52 4f 58 59 29 29 20 7b 0a 09 4c 41 50 50  _PROXY)) {..LAPP
4c20: 45 4e 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c  END_LONG(interp,
4c30: 20 63 65 72 74 50 74 72 2c 20 22 70 61 74 68 4c   certPtr, "pathL
4c40: 65 6e 22 2c 20 58 35 30 39 5f 67 65 74 5f 70 61  en", X509_get_pa
4c50: 74 68 6c 65 6e 28 63 65 72 74 29 29 3b 0a 20 20  thlen(cert));.  
4c60: 20 20 7d 20 65 6c 73 65 20 7b 0a 09 4c 41 50 50    } else {..LAPP
4c70: 45 4e 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c  END_LONG(interp,
4c80: 20 63 65 72 74 50 74 72 2c 20 22 70 61 74 68 4c   certPtr, "pathL
4c90: 65 6e 22 2c 20 58 35 30 39 5f 67 65 74 5f 70 72  en", X509_get_pr
4ca0: 6f 78 79 5f 70 61 74 68 6c 65 6e 28 63 65 72 74  oxy_pathlen(cert
4cb0: 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 4c 41  ));.    }.    LA
4cc0: 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72  PPEND_BOOL(inter
4cd0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 62 61 73  p, certPtr, "bas
4ce0: 69 63 43 6f 6e 73 74 72 61 69 6e 74 73 43 41 22  icConstraintsCA"
4cf0: 2c 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41  , xflags & EXFLA
4d00: 47 5f 43 41 29 3b 0a 0a 20 20 20 20 2f 2a 20 4e  G_CA);..    /* N
4d10: 61 6d 65 20 43 6f 6e 73 74 72 61 69 6e 74 73 20  ame Constraints 
4d20: 69 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20  is only used in 
4d30: 43 41 20 63 65 72 74 73 20 74 6f 20 69 6e 64 69  CA certs to indi
4d40: 63 61 74 65 20 74 68 65 20 6e 61 6d 65 20 73 70  cate the name sp
4d50: 61 63 65 20 66 6f 72 0a 09 61 6c 6c 20 73 75 62  ace for..all sub
4d60: 6a 65 63 74 20 6e 61 6d 65 73 20 69 6e 20 73 75  ject names in su
4d70: 62 73 65 71 75 65 6e 74 20 63 65 72 74 69 66 69  bsequent certifi
4d80: 63 61 74 65 73 20 69 6e 20 61 20 63 65 72 74 69  cates in a certi
4d90: 66 69 63 61 74 69 6f 6e 20 70 61 74 68 0a 09 4d  fication path..M
4da0: 55 53 54 20 62 65 20 6c 6f 63 61 74 65 64 2e 20  UST be located. 
4db0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
4dc0: 20 34 2e 32 2e 31 2e 31 30 2c 20 4e 49 44 5f 6e   4.2.1.10, NID_n
4dd0: 61 6d 65 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20  ame_constraints 
4de0: 2a 2f 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c 69 63  */..    /* Polic
4df0: 79 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 73  y Constraints is
4e00: 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 43 41   only used in CA
4e10: 20 63 65 72 74 73 20 74 6f 20 6c 69 6d 69 74 20   certs to limit 
4e20: 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 61 0a  the length of a.
4e30: 09 63 65 72 74 20 63 68 61 69 6e 20 66 6f 72 20  .cert chain for 
4e40: 74 68 61 74 20 43 41 2e 20 52 46 43 20 35 32 38  that CA. RFC 528
4e50: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e  0 section 4.2.1.
4e60: 31 31 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 5f 63  11, NID_policy_c
4e70: 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 0a 20  onstraints */.. 
4e80: 20 20 20 2f 2a 20 45 78 74 65 6e 64 65 64 20 4b     /* Extended K
4e90: 65 79 20 55 73 61 67 65 20 69 6e 64 69 63 61 74  ey Usage indicat
4ea0: 65 73 20 74 68 65 20 70 75 72 70 6f 73 65 73 20  es the purposes 
4eb0: 74 68 65 20 63 65 72 74 69 66 69 65 64 20 70 75  the certified pu
4ec0: 62 6c 69 63 20 6b 65 79 20 6d 61 79 20 62 65 0a  blic key may be.
4ed0: 09 75 73 65 64 2c 20 62 65 79 6f 6e 64 20 74 68  .used, beyond th
4ee0: 65 20 62 61 73 69 63 20 70 75 72 70 6f 73 65 73  e basic purposes
4ef0: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
4f00: 6f 6e 20 34 2e 32 2e 31 2e 31 32 2c 20 4e 49 44  on 4.2.1.12, NID
4f10: 5f 65 78 74 5f 6b 65 79 5f 75 73 61 67 65 20 2a  _ext_key_usage *
4f20: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42  /.    LAPPEND_OB
4f30: 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  J(interp, certPt
4f40: 72 2c 20 22 65 78 74 65 6e 64 65 64 4b 65 79 55  r, "extendedKeyU
4f50: 73 61 67 65 22 2c 20 54 6c 73 5f 78 35 30 39 45  sage", Tls_x509E
4f60: 78 74 4b 65 79 55 73 61 67 65 28 69 6e 74 65 72  xtKeyUsage(inter
4f70: 70 2c 20 63 65 72 74 2c 20 78 66 6c 61 67 73 29  p, cert, xflags)
4f80: 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 52 4c 20 44  );..    /* CRL D
4f90: 69 73 74 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e  istribution Poin
4fa0: 74 73 20 69 64 65 6e 74 69 66 69 65 73 20 77 68  ts identifies wh
4fb0: 65 72 65 20 43 52 4c 20 69 6e 66 6f 72 6d 61 74  ere CRL informat
4fc0: 69 6f 6e 20 63 61 6e 20 62 65 20 6f 62 74 61 69  ion can be obtai
4fd0: 6e 65 64 2e 0a 09 52 46 43 20 35 32 38 30 20 73  ned...RFC 5280 s
4fe0: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 33 2a  ection 4.2.1.13*
4ff0: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42  /.    LAPPEND_OB
5000: 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  J(interp, certPt
5010: 72 2c 20 22 63 72 6c 44 69 73 74 72 69 62 75 74  r, "crlDistribut
5020: 69 6f 6e 50 6f 69 6e 74 73 22 2c 20 54 6c 73 5f  ionPoints", Tls_
5030: 78 35 30 39 43 72 6c 44 70 28 69 6e 74 65 72 70  x509CrlDp(interp
5040: 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f  , cert));..    /
5050: 2a 20 46 72 65 73 68 65 73 74 20 43 52 4c 20 65  * Freshest CRL e
5060: 78 74 65 6e 73 69 6f 6e 20 2a 2f 0a 20 20 20 20  xtension */.    
5070: 69 66 20 28 78 66 6c 61 67 73 20 26 20 45 58 46  if (xflags & EXF
5080: 4c 41 47 5f 46 52 45 53 48 45 53 54 29 20 7b 0a  LAG_FRESHEST) {.
5090: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 41 75      }..    /* Au
50a0: 74 68 6f 72 69 74 79 20 49 6e 66 6f 72 6d 61 74  thority Informat
50b0: 69 6f 6e 20 41 63 63 65 73 73 20 69 6e 64 69 63  ion Access indic
50c0: 61 74 65 73 20 68 6f 77 20 74 6f 20 61 63 63 65  ates how to acce
50d0: 73 73 20 69 6e 66 6f 20 61 6e 64 20 73 65 72 76  ss info and serv
50e0: 69 63 65 73 0a 09 66 6f 72 20 74 68 65 20 63 65  ices..for the ce
50f0: 72 74 69 66 69 63 61 74 65 20 69 73 73 75 65 72  rtificate issuer
5100: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
5110: 6f 6e 20 34 2e 32 2e 32 2e 31 2c 20 4e 49 44 5f  on 4.2.2.1, NID_
5120: 69 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a  info_access */..
5130: 20 20 20 20 2f 2a 20 47 65 74 20 4f 6e 2d 6c 69      /* Get On-li
5140: 6e 65 20 43 65 72 74 69 66 69 63 61 74 65 20 53  ne Certificate S
5150: 74 61 74 75 73 20 50 72 6f 74 6f 63 6f 6c 20 28  tatus Protocol (
5160: 4f 53 43 50 29 20 52 65 73 70 6f 6e 64 65 72 73  OSCP) Responders
5170: 20 55 52 4c 20 2a 2f 0a 20 20 20 20 4c 41 50 50   URL */.    LAPP
5180: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20  END_OBJ(interp, 
5190: 63 65 72 74 50 74 72 2c 20 22 6f 63 73 70 52 65  certPtr, "ocspRe
51a0: 73 70 6f 6e 64 65 72 73 22 2c 20 54 6c 73 5f 78  sponders", Tls_x
51b0: 35 30 39 4f 73 63 70 28 69 6e 74 65 72 70 2c 20  509Oscp(interp, 
51c0: 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20  cert));..    /* 
51d0: 47 65 74 20 43 65 72 74 69 66 69 63 61 74 65 20  Get Certificate 
51e0: 41 75 74 68 6f 72 69 74 79 20 28 43 41 29 20 49  Authority (CA) I
51f0: 73 73 75 65 72 73 20 55 52 4c 20 2a 2f 0a 20 20  ssuers URL */.  
5200: 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e    LAPPEND_OBJ(in
5210: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
5220: 63 61 49 73 73 75 65 72 73 22 2c 20 54 6c 73 5f  caIssuers", Tls_
5230: 78 35 30 39 43 61 49 73 73 75 65 72 73 28 69 6e  x509CaIssuers(in
5240: 74 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20  terp, cert));.. 
5250: 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 49 6e     /* Subject In
5260: 66 6f 72 6d 61 74 69 6f 6e 20 41 63 63 65 73 73  formation Access
5270: 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74   - RFC 5280 sect
5280: 69 6f 6e 20 34 2e 32 2e 32 2e 32 2c 20 4e 49 44  ion 4.2.2.2, NID
5290: 5f 73 69 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f  _sinfo_access */
52a0: 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69  ..    /* Certifi
52b0: 63 61 74 65 20 41 6c 69 61 73 2e 20 49 66 20 75  cate Alias. If u
52c0: 73 65 73 20 61 20 50 4b 43 53 23 31 32 20 73 74  ses a PKCS#12 st
52d0: 72 75 63 74 75 72 65 2c 20 61 6c 69 61 73 20 77  ructure, alias w
52e0: 69 6c 6c 20 72 65 66 6c 65 63 74 20 74 68 65 0a  ill reflect the.
52f0: 09 66 72 69 65 6e 64 6c 79 4e 61 6d 65 20 61 74  .friendlyName at
5300: 74 72 69 62 75 74 65 20 28 52 46 43 20 32 39 38  tribute (RFC 298
5310: 35 29 2e 20 2a 2f 0a 20 20 20 20 7b 0a 09 6c 65  5). */.    {..le
5320: 6e 20 3d 20 30 3b 0a 20 20 20 20 20 20 20 20 63  n = 0;.        c
5330: 68 61 72 20 2a 73 74 72 69 6e 67 20 3d 20 58 35  har *string = X5
5340: 30 39 5f 61 6c 69 61 73 5f 67 65 74 30 28 63 65  09_alias_get0(ce
5350: 72 74 2c 20 26 6c 65 6e 29 3b 0a 09 4c 41 50 50  rt, &len);..LAPP
5360: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20  END_STR(interp, 
5370: 63 65 72 74 50 74 72 2c 20 22 61 6c 69 61 73 22  certPtr, "alias"
5380: 2c 20 73 74 72 69 6e 67 2c 20 6c 65 6e 29 3b 0a  , string, len);.
5390: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 43 65      }..    /* Ce
53a0: 72 74 69 66 69 63 61 74 65 20 61 6e 64 20 64 75  rtificate and du
53b0: 6d 70 20 61 6c 6c 20 64 61 74 61 20 2a 2f 0a 20  mp all data */. 
53c0: 20 20 20 7b 0a 09 63 68 61 72 20 63 65 72 74 53     {..char certS
53d0: 74 72 5b 43 45 52 54 5f 53 54 52 5f 53 49 5a 45  tr[CERT_STR_SIZE
53e0: 5d 3b 0a 0a 09 2f 2a 20 47 65 74 20 63 65 72 74  ];.../* Get cert
53f0: 69 66 69 63 61 74 65 20 2a 2f 0a 09 6c 65 6e 20  ificate */..len 
5400: 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28  = BIO_to_Buffer(
5410: 50 45 4d 5f 77 72 69 74 65 5f 62 69 6f 5f 58 35  PEM_write_bio_X5
5420: 30 39 28 62 69 6f 2c 20 63 65 72 74 29 2c 20 62  09(bio, cert), b
5430: 69 6f 2c 20 63 65 72 74 53 74 72 2c 20 43 45 52  io, certStr, CER
5440: 54 5f 53 54 52 5f 53 49 5a 45 29 3b 0a 09 4c 41  T_STR_SIZE);..LA
5450: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
5460: 2c 20 63 65 72 74 50 74 72 2c 20 22 63 65 72 74  , certPtr, "cert
5470: 69 66 69 63 61 74 65 22 2c 20 63 65 72 74 53 74  ificate", certSt
5480: 72 2c 20 6c 65 6e 29 3b 0a 0a 09 2f 2a 20 47 65  r, len);.../* Ge
5490: 74 20 61 6c 6c 20 63 65 72 74 20 69 6e 66 6f 20  t all cert info 
54a0: 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f  */..len = BIO_to
54b0: 5f 42 75 66 66 65 72 28 58 35 30 39 5f 70 72 69  _Buffer(X509_pri
54c0: 6e 74 5f 65 78 28 62 69 6f 2c 20 63 65 72 74 2c  nt_ex(bio, cert,
54d0: 20 66 6c 61 67 73 2c 20 30 29 2c 20 62 69 6f 2c   flags, 0), bio,
54e0: 20 63 65 72 74 53 74 72 2c 20 43 45 52 54 5f 53   certStr, CERT_S
54f0: 54 52 5f 53 49 5a 45 29 3b 0a 09 4c 41 50 50 45  TR_SIZE);..LAPPE
5500: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
5510: 65 72 74 50 74 72 2c 20 22 61 6c 6c 22 2c 20 63  ertPtr, "all", c
5520: 65 72 74 53 74 72 2c 20 6c 65 6e 29 3b 0a 20 20  ertStr, len);.  
5530: 20 20 7d 0a 0a 20 20 20 20 42 49 4f 5f 66 72 65    }..    BIO_fre
5540: 65 28 62 69 6f 29 3b 0a 20 20 20 20 72 65 74 75  e(bio);.    retu
5550: 72 6e 20 63 65 72 74 50 74 72 3b 0a 7d 0a        rn certPtr;.}.