Hex Artifact Content

Artifact ead2e837f395bfe6ac400c377517fce685685e7cd8a2a22ada98364b74beb42f:


0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20  /*. * Copyright 
0010: 28 43 29 20 31 39 39 37 2d 32 30 30 30 20 53 65  (C) 1997-2000 Se
0020: 6e 73 75 73 20 43 6f 6e 73 75 6c 74 69 6e 67 20  nsus Consulting 
0030: 4c 74 64 2e 0a 20 2a 20 4d 61 74 74 20 4e 65 77  Ltd.. * Matt New
0040: 6d 61 6e 20 3c 6d 61 74 74 40 73 65 6e 73 75 73  man <matt@sensus
0050: 2e 6f 72 67 3e 0a 20 2a 20 43 6f 70 79 72 69 67  .org>. * Copyrig
0060: 68 74 20 28 43 29 20 32 30 32 33 20 42 72 69 61  ht (C) 2023 Bria
0070: 6e 20 4f 27 48 61 67 61 6e 0a 20 2a 2f 0a 23 69  n O'Hagan. */.#i
0080: 6e 63 6c 75 64 65 20 3c 74 63 6c 2e 68 3e 0a 23  nclude <tcl.h>.#
0090: 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68  include <stdio.h
00a0: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e  >.#include <open
00b0: 73 73 6c 2f 62 69 6f 2e 68 3e 0a 23 69 6e 63 6c  ssl/bio.h>.#incl
00c0: 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 73 68 61  ude <openssl/sha
00d0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70  .h>.#include <op
00e0: 65 6e 73 73 6c 2f 78 35 30 39 2e 68 3e 0a 23 69  enssl/x509.h>.#i
00f0: 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f  nclude <openssl/
0100: 78 35 30 39 76 33 2e 68 3e 0a 23 69 6e 63 6c 75  x509v3.h>.#inclu
0110: 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 78 35 30 39  de <openssl/x509
0120: 5f 76 66 79 2e 68 3e 0a 23 69 6e 63 6c 75 64 65  _vfy.h>.#include
0130: 20 3c 6f 70 65 6e 73 73 6c 2f 61 73 6e 31 2e 68   <openssl/asn1.h
0140: 3e 0a 23 69 6e 63 6c 75 64 65 20 22 74 6c 73 49  >.#include "tlsI
0150: 6e 74 2e 68 22 0a 0a 2f 2a 20 44 65 66 69 6e 65  nt.h"../* Define
0160: 20 6d 61 78 69 6d 75 6d 20 63 65 72 74 69 66 69   maximum certifi
0170: 63 61 74 65 20 73 69 7a 65 2e 20 4d 61 78 20 50  cate size. Max P
0180: 45 4d 20 73 69 7a 65 20 31 30 30 6b 42 20 61 6e  EM size 100kB an
0190: 64 20 44 45 52 20 73 69 7a 65 20 69 73 20 32 34  d DER size is 24
01a0: 6b 42 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43  kB. */.#define C
01b0: 45 52 54 5f 53 54 52 5f 53 49 5a 45 20 33 32 37  ERT_STR_SIZE 327
01c0: 36 38 0a 0a 0c 0a 2f 2a 0a 20 2a 20 42 69 6e 61  68..../*. * Bina
01d0: 72 79 20 73 74 72 69 6e 67 20 74 6f 20 68 65 78  ry string to hex
01e0: 20 73 74 72 69 6e 67 0a 20 2a 2f 0a 69 6e 74 20   string. */.int 
01f0: 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 75 6e  String_to_Hex(un
0200: 73 69 67 6e 65 64 20 63 68 61 72 2a 20 69 6e 70  signed char* inp
0210: 75 74 2c 20 69 6e 74 20 69 6c 65 6e 2c 20 75 6e  ut, int ilen, un
0220: 73 69 67 6e 65 64 20 63 68 61 72 20 2a 6f 75 74  signed char *out
0230: 70 75 74 2c 20 69 6e 74 20 6f 6c 65 6e 29 20 7b  put, int olen) {
0240: 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d  .    int count =
0250: 20 30 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 64   0;.    unsigned
0260: 20 63 68 61 72 20 2a 69 70 74 72 20 3d 20 69 6e   char *iptr = in
0270: 70 75 74 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65  put;.    unsigne
0280: 64 20 63 68 61 72 20 2a 6f 70 74 72 20 3d 20 26  d char *optr = &
0290: 6f 75 74 70 75 74 5b 30 5d 3b 0a 20 20 20 20 63  output[0];.    c
02a0: 6f 6e 73 74 20 63 68 61 72 20 2a 68 65 78 20 3d  onst char *hex =
02b0: 20 22 30 31 32 33 34 35 36 37 38 39 61 62 63 64   "0123456789abcd
02c0: 65 66 22 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69  ef";..    for (i
02d0: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 69 6c  nt i = 0; i < il
02e0: 65 6e 20 26 26 20 63 6f 75 6e 74 20 3c 20 6f 6c  en && count < ol
02f0: 65 6e 20 2d 20 31 3b 20 69 2b 2b 2c 20 63 6f 75  en - 1; i++, cou
0300: 6e 74 20 2b 3d 20 32 29 20 7b 0a 20 20 20 20 20  nt += 2) {.     
0310: 20 20 20 2a 6f 70 74 72 2b 2b 20 3d 20 68 65 78     *optr++ = hex
0320: 5b 28 2a 69 70 74 72 3e 3e 34 29 26 30 78 46 5d  [(*iptr>>4)&0xF]
0330: 3b 0a 20 20 20 20 20 20 20 20 2a 6f 70 74 72 2b  ;.        *optr+
0340: 2b 20 3d 20 68 65 78 5b 28 2a 69 70 74 72 2b 2b  + = hex[(*iptr++
0350: 29 26 30 78 46 5d 3b 0a 20 20 20 20 7d 0a 20 20  )&0xF];.    }.  
0360: 20 20 2a 6f 70 74 72 20 3d 20 30 3b 0a 20 20 20    *optr = 0;.   
0370: 20 72 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 7d   return count;.}
0380: 0a 0a 2f 2a 0a 20 2a 20 42 49 4f 20 74 6f 20 42  ../*. * BIO to B
0390: 75 66 66 65 72 0a 20 2a 2f 0a 69 6e 74 20 42 49  uffer. */.int BI
03a0: 4f 5f 74 6f 5f 42 75 66 66 65 72 28 69 6e 74 20  O_to_Buffer(int 
03b0: 72 65 73 75 6c 74 2c 20 42 49 4f 20 2a 62 69 6f  result, BIO *bio
03c0: 2c 20 76 6f 69 64 20 2a 62 75 66 66 65 72 2c 20  , void *buffer, 
03d0: 69 6e 74 20 73 69 7a 65 29 20 7b 0a 20 20 20 20  int size) {.    
03e0: 69 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20  int len = 0;.   
03f0: 20 69 6e 74 20 70 65 6e 64 69 6e 67 20 3d 20 42   int pending = B
0400: 49 4f 5f 70 65 6e 64 69 6e 67 28 62 69 6f 29 3b  IO_pending(bio);
0410: 0a 0a 20 20 20 20 69 66 20 28 72 65 73 75 6c 74  ..    if (result
0420: 29 20 7b 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 72  ) {..len = BIO_r
0430: 65 61 64 28 62 69 6f 2c 20 62 75 66 66 65 72 2c  ead(bio, buffer,
0440: 20 28 70 65 6e 64 69 6e 67 20 3c 20 73 69 7a 65   (pending < size
0450: 29 20 3f 20 70 65 6e 64 69 6e 67 20 3a 20 73 69  ) ? pending : si
0460: 7a 65 29 3b 0a 09 28 76 6f 69 64 29 42 49 4f 5f  ze);..(void)BIO_
0470: 66 6c 75 73 68 28 62 69 6f 29 3b 0a 09 69 66 20  flush(bio);..if 
0480: 28 6c 65 6e 20 3c 20 30 29 20 7b 0a 09 20 20 20  (len < 0) {..   
0490: 20 6c 65 6e 20 3d 20 30 3b 0a 09 7d 0a 20 20 20   len = 0;..}.   
04a0: 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 65   }.    return le
04b0: 6e 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 20 47 65 74  n;.}.../*. * Get
04c0: 20 58 35 30 39 20 43 65 72 74 69 66 69 63 61 74   X509 Certificat
04d0: 65 20 45 78 74 65 6e 73 69 6f 6e 73 0a 20 2a 2f  e Extensions. */
04e0: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35  .Tcl_Obj *Tls_x5
04f0: 30 39 45 78 74 65 6e 73 69 6f 6e 73 28 54 63 6c  09Extensions(Tcl
0500: 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c  _Interp *interp,
0510: 20 58 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20   X509 *cert) {. 
0520: 20 20 20 63 6f 6e 73 74 20 53 54 41 43 4b 5f 4f     const STACK_O
0530: 46 28 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e  F(X509_EXTENSION
0540: 29 20 2a 65 78 74 73 3b 0a 20 20 20 20 54 63 6c  ) *exts;.    Tcl
0550: 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d 20  _Obj *listPtr = 
0560: 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30  Tcl_NewListObj(0
0570: 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 66  , NULL);..    if
0580: 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 4c   (listPtr == NUL
0590: 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 4c  L) {..return NUL
05a0: 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 66  L;.    }..    if
05b0: 20 28 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 09  , md, &len)) {..
3750: 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f  len = String_to_
3760: 48 65 78 28 6d 64 2c 20 6c 65 6e 2c 20 62 75 66  Hex(md, len, buf
3770: 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c  fer, BUFSIZ);..L
3780: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
3790: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 68 61  p, certPtr, "sha
37a0: 31 5f 68 61 73 68 22 2c 20 62 75 66 66 65 72 2c  1_hash", buffer,
37b0: 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20   len);.    }..  
37c0: 20 20 2f 2a 20 53 48 41 32 35 36 20 44 69 67 65    /* SHA256 Dige
37d0: 73 74 20 28 46 69 6e 67 65 72 70 72 69 6e 74 29  st (Fingerprint)
37e0: 20 6f 66 20 63 65 72 74 20 2d 20 44 45 52 20 72   of cert - DER r
37f0: 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 2a 2f  epresentation */
3800: 0a 20 20 20 20 69 66 20 28 58 35 30 39 5f 64 69  .    if (X509_di
3810: 67 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f 73  gest(cert, EVP_s
3820: 68 61 32 35 36 28 29 2c 20 6d 64 2c 20 26 6c 65  ha256(), md, &le
3830: 6e 29 29 20 7b 0a 09 6c 65 6e 20 3d 20 53 74 72  n)) {..len = Str
3840: 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 6c  ing_to_Hex(md, l
3850: 65 6e 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53  en, buffer, BUFS
3860: 49 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54  IZ);..LAPPEND_ST
3870: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
3880: 72 2c 20 22 73 68 61 32 35 36 5f 68 61 73 68 22  r, "sha256_hash"
3890: 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a  , buffer, len);.
38a0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 75      }..    /* Su
38b0: 62 6a 65 63 74 20 50 75 62 6c 69 63 20 4b 65 79  bject Public Key
38c0: 20 49 6e 66 6f 20 73 70 65 63 69 66 69 65 73 20   Info specifies 
38d0: 74 68 65 20 70 75 62 6c 69 63 20 6b 65 79 20 61  the public key a
38e0: 6e 64 20 69 64 65 6e 74 69 66 69 65 73 20 74 68  nd identifies th
38f0: 65 0a 09 61 6c 67 6f 72 69 74 68 6d 20 77 69 74  e..algorithm wit
3900: 68 20 77 68 69 63 68 20 74 68 65 20 6b 65 79 20  h which the key 
3910: 69 73 20 75 73 65 64 2e 20 52 46 43 20 35 32 38  is used. RFC 528
3920: 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e  0 section 4.1.2.
3930: 37 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30  7 */.    if (X50
3940: 39 5f 67 65 74 5f 73 69 67 6e 61 74 75 72 65 5f  9_get_signature_
3950: 69 6e 66 6f 28 63 65 72 74 2c 20 26 6d 64 6e 69  info(cert, &mdni
3960: 64 2c 20 26 70 6b 6e 69 64 2c 20 26 62 69 74 73  d, &pknid, &bits
3970: 2c 20 26 78 66 6c 61 67 73 29 29 20 7b 0a 09 41  , &xflags)) {..A
3980: 53 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a  SN1_BIT_STRING *
3990: 6b 65 79 3b 0a 09 75 6e 73 69 67 6e 65 64 20 69  key;..unsigned i
39a0: 6e 74 20 6e 3b 0a 0a 09 4c 41 50 50 45 4e 44 5f  nt n;...LAPPEND_
39b0: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74  STR(interp, cert
39c0: 50 74 72 2c 20 22 73 69 67 6e 69 6e 67 44 69 67  Ptr, "signingDig
39d0: 65 73 74 22 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e  est", OBJ_nid2ln
39e0: 28 6d 64 6e 69 64 29 2c 20 2d 31 29 3b 0a 09 4c  (mdnid), -1);..L
39f0: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
3a00: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75 62  p, certPtr, "pub
3a10: 6c 69 63 4b 65 79 41 6c 67 6f 72 69 74 68 6d 22  licKeyAlgorithm"
3a20: 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 70 6b 6e  , OBJ_nid2ln(pkn
3a30: 69 64 29 2c 20 2d 31 29 3b 0a 09 4c 41 50 50 45  id), -1);..LAPPE
3a40: 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20 63  ND_INT(interp, c
3a50: 65 72 74 50 74 72 2c 20 22 62 69 74 73 22 2c 20  ertPtr, "bits", 
3a60: 62 69 74 73 29 3b 20 2f 2a 20 45 66 66 65 63 74  bits); /* Effect
3a70: 69 76 65 20 73 65 63 75 72 69 74 79 20 62 69 74  ive security bit
3a80: 73 20 2a 2f 0a 0a 09 6b 65 79 20 3d 20 58 35 30  s */...key = X50
3a90: 39 5f 67 65 74 30 5f 70 75 62 6b 65 79 5f 62 69  9_get0_pubkey_bi
3aa0: 74 73 74 72 28 63 65 72 74 29 3b 0a 09 6c 65 6e  tstr(cert);..len
3ab0: 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78   = String_to_Hex
3ac0: 28 6b 65 79 2d 3e 64 61 74 61 2c 20 6b 65 79 2d  (key->data, key-
3ad0: 3e 6c 65 6e 67 74 68 2c 20 62 75 66 66 65 72 2c  >length, buffer,
3ae0: 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45   BUFSIZ);..LAPPE
3af0: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
3b00: 65 72 74 50 74 72 2c 20 22 70 75 62 6c 69 63 4b  ertPtr, "publicK
3b10: 65 79 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e  ey", buffer, len
3b20: 29 3b 0a 0a 09 6c 65 6e 20 3d 20 30 3b 0a 09 69  );...len = 0;..i
3b30: 66 20 28 58 35 30 39 5f 70 75 62 6b 65 79 5f 64  f (X509_pubkey_d
3b40: 69 67 65 73 74 28 63 65 72 74 2c 20 45 56 50 5f  igest(cert, EVP_
3b50: 67 65 74 5f 64 69 67 65 73 74 62 79 6e 69 64 28  get_digestbynid(
3b60: 70 6b 6e 69 64 29 2c 20 6d 64 2c 20 26 6e 29 29  pknid), md, &n))
3b70: 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d 20 53 74   {..    len = St
3b80: 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20  ring_to_Hex(md, 
3b90: 28 69 6e 74 29 6e 2c 20 62 75 66 66 65 72 2c 20  (int)n, buffer, 
3ba0: 42 55 46 53 49 5a 29 3b 0a 09 7d 0a 09 4c 41 50  BUFSIZ);..}..LAP
3bb0: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
3bc0: 20 63 65 72 74 50 74 72 2c 20 22 70 75 62 6c 69   certPtr, "publi
3bd0: 63 4b 65 79 48 61 73 68 22 2c 20 62 75 66 66 65  cKeyHash", buffe
3be0: 72 2c 20 6c 65 6e 29 3b 0a 0a 09 2f 2a 20 64 69  r, len);.../* di
3bf0: 67 65 73 74 20 6f 66 20 74 68 65 20 44 45 52 20  gest of the DER 
3c00: 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e 20 6f  representation o
3c10: 66 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74  f the certificat
3c20: 65 20 2a 2f 0a 09 6c 65 6e 20 3d 20 30 3b 0a 09  e */..len = 0;..
3c30: 69 66 20 28 58 35 30 39 5f 64 69 67 65 73 74 28  if (X509_digest(
3c40: 63 65 72 74 2c 20 45 56 50 5f 67 65 74 5f 64 69  cert, EVP_get_di
3c50: 67 65 73 74 62 79 6e 69 64 28 6d 64 6e 69 64 29  gestbynid(mdnid)
3c60: 2c 20 6d 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20  , md, &n)) {..  
3c70: 20 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74    len = String_t
3c80: 6f 5f 48 65 78 28 6d 64 2c 20 28 69 6e 74 29 6e  o_Hex(md, (int)n
3c90: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a  , buffer, BUFSIZ
3ca0: 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 53  );..}..LAPPEND_S
3cb0: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  TR(interp, certP
3cc0: 74 72 2c 20 22 73 69 67 6e 61 74 75 72 65 48 61  tr, "signatureHa
3cd0: 73 68 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e  sh", buffer, len
3ce0: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a  );.    }..    /*
3cf0: 20 43 65 72 74 69 66 69 63 61 74 65 20 50 75 72   Certificate Pur
3d00: 70 6f 73 65 2e 20 43 61 6c 6c 20 62 65 66 6f 72  pose. Call befor
3d10: 65 20 63 68 65 63 6b 69 6e 67 20 66 6f 72 20 65  e checking for e
3d20: 78 74 65 6e 73 69 6f 6e 73 2e 20 2a 2f 0a 20 20  xtensions. */.  
3d30: 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e    LAPPEND_STR(in
3d40: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
3d50: 70 75 72 70 6f 73 65 22 2c 20 54 6c 73 5f 78 35  purpose", Tls_x5
3d60: 30 39 50 75 72 70 6f 73 65 28 63 65 72 74 29 2c  09Purpose(cert),
3d70: 20 2d 31 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e   -1);.    LAPPEN
3d80: 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65  D_OBJ(interp, ce
3d90: 72 74 50 74 72 2c 20 22 63 65 72 74 69 66 69 63  rtPtr, "certific
3da0: 61 74 65 50 75 72 70 6f 73 65 22 2c 20 54 6c 73  atePurpose", Tls
3db0: 5f 78 35 30 39 50 75 72 70 6f 73 65 73 28 69 6e  _x509Purposes(in
3dc0: 74 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20  terp, cert));.. 
3dd0: 20 20 20 2f 2a 20 47 65 74 20 65 78 74 65 6e 73     /* Get extens
3de0: 69 6f 6e 73 20 66 6c 61 67 73 20 2a 2f 0a 20 20  ions flags */.  
3df0: 20 20 78 66 6c 61 67 73 20 3d 20 58 35 30 39 5f    xflags = X509_
3e00: 67 65 74 5f 65 78 74 65 6e 73 69 6f 6e 5f 66 6c  get_extension_fl
3e10: 61 67 73 28 63 65 72 74 29 3b 0a 20 20 20 20 4c  ags(cert);.    L
3e20: 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72  APPEND_INT(inter
3e30: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 74  p, certPtr, "ext
3e40: 46 6c 61 67 73 22 2c 20 78 66 6c 61 67 73 29 3b  Flags", xflags);
3e50: 0a 0a 20 20 20 20 2f 2a 20 43 68 65 63 6b 20 69  ..    /* Check i
3e60: 66 20 63 65 72 74 20 77 61 73 20 69 73 73 75 65  f cert was issue
3e70: 64 20 62 79 20 43 41 20 63 65 72 74 20 69 73 73  d by CA cert iss
3e80: 75 65 72 20 6f 72 20 73 65 6c 66 20 73 69 67 6e  uer or self sign
3e90: 65 64 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e  ed */.    LAPPEN
3ea0: 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63  D_BOOL(interp, c
3eb0: 65 72 74 50 74 72 2c 20 22 73 65 6c 66 49 73 73  ertPtr, "selfIss
3ec0: 75 65 64 22 2c 20 78 66 6c 61 67 73 20 26 20 45  ued", xflags & E
3ed0: 58 46 4c 41 47 5f 53 49 29 3b 0a 20 20 20 20 4c  XFLAG_SI);.    L
3ee0: 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65  APPEND_BOOL(inte
3ef0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65  rp, certPtr, "se
3f00: 6c 66 53 69 67 6e 65 64 22 2c 20 78 66 6c 61 67  lfSigned", xflag
3f10: 73 20 26 20 45 58 46 4c 41 47 5f 53 53 29 3b 0a  s & EXFLAG_SS);.
3f20: 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c      LAPPEND_BOOL
3f30: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
3f40: 2c 20 22 69 73 50 72 6f 78 79 43 65 72 74 22 2c  , "isProxyCert",
3f50: 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47   xflags & EXFLAG
3f60: 5f 50 52 4f 58 59 29 3b 0a 20 20 20 20 4c 41 50  _PROXY);.    LAP
3f70: 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70  PEND_BOOL(interp
3f80: 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 74 49  , certPtr, "extI
3f90: 6e 76 61 6c 69 64 22 2c 20 78 66 6c 61 67 73 20  nvalid", xflags 
3fa0: 26 20 45 58 46 4c 41 47 5f 49 4e 56 41 4c 49 44  & EXFLAG_INVALID
3fb0: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42  );.    LAPPEND_B
3fc0: 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74  OOL(interp, cert
3fd0: 50 74 72 2c 20 22 69 73 43 41 43 65 72 74 22 2c  Ptr, "isCACert",
3fe0: 20 58 35 30 39 5f 63 68 65 63 6b 5f 63 61 28 63   X509_check_ca(c
3ff0: 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 54  ert));..    /* T
4000: 68 65 20 55 6e 69 71 75 65 20 49 64 73 20 61 72  he Unique Ids ar
4010: 65 20 75 73 65 64 20 74 6f 20 68 61 6e 64 6c 65  e used to handle
4020: 20 74 68 65 20 70 6f 73 73 69 62 69 6c 69 74 79   the possibility
4030: 20 6f 66 20 72 65 75 73 65 20 6f 66 20 73 75 62   of reuse of sub
4040: 6a 65 63 74 0a 09 61 6e 64 2f 6f 72 20 69 73 73  ject..and/or iss
4050: 75 65 72 20 6e 61 6d 65 73 20 6f 76 65 72 20 74  uer names over t
4060: 69 6d 65 2e 20 52 46 43 20 35 32 38 30 20 73 65  ime. RFC 5280 se
4070: 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 38 20 2a 2f  ction 4.1.2.8 */
4080: 0a 20 20 20 20 7b 0a 09 63 6f 6e 73 74 20 41 53  .    {..const AS
4090: 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a 69  N1_BIT_STRING *i
40a0: 75 69 64 2c 20 2a 73 75 69 64 3b 0a 09 58 35 30  uid, *suid;..X50
40b0: 39 5f 67 65 74 30 5f 75 69 64 73 28 63 65 72 74  9_get0_uids(cert
40c0: 2c 20 26 69 75 69 64 2c 20 26 73 75 69 64 29 3b  , &iuid, &suid);
40d0: 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70  ...Tcl_ListObjAp
40e0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
40f0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c  rp, certPtr, Tcl
4100: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 69  _NewStringObj("i
4110: 73 73 75 65 72 55 6e 69 71 75 65 49 64 22 2c 20  ssuerUniqueId", 
4120: 2d 31 29 29 3b 0a 09 69 66 20 28 69 75 69 64 20  -1));..if (iuid 
4130: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20  != NULL) {..    
4140: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e  Tcl_ListObjAppen
4150: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c  dElement(interp,
4160: 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65   certPtr, Tcl_Ne
4170: 77 42 79 74 65 41 72 72 61 79 4f 62 6a 28 28 63  wByteArrayObj((c
4180: 68 61 72 20 2a 29 69 75 69 64 2d 3e 64 61 74 61  har *)iuid->data
4190: 2c 20 69 75 69 64 2d 3e 6c 65 6e 67 74 68 29 29  , iuid->length))
41a0: 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20  ;..} else {..   
41b0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
41c0: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
41d0: 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e  , certPtr, Tcl_N
41e0: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 22 2c 20  ewStringObj("", 
41f0: 2d 31 29 29 3b 0a 09 7d 0a 0a 09 54 63 6c 5f 4c  -1));..}...Tcl_L
4200: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
4210: 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74  ent(interp, cert
4220: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
4230: 6e 67 4f 62 6a 28 22 73 75 62 6a 65 63 74 55 6e  ngObj("subjectUn
4240: 69 71 75 65 49 64 22 2c 20 2d 31 29 29 3b 0a 09  iqueId", -1));..
4250: 69 66 20 28 73 75 69 64 20 21 3d 20 4e 55 4c 4c  if (suid != NULL
4260: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73  ) {..    Tcl_Lis
4270: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e  tObjAppendElemen
4280: 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  t(interp, certPt
4290: 72 2c 20 54 63 6c 5f 4e 65 77 42 79 74 65 41 72  r, Tcl_NewByteAr
42a0: 72 61 79 4f 62 6a 28 28 63 68 61 72 20 2a 29 73  rayObj((char *)s
42b0: 75 69 64 2d 3e 64 61 74 61 2c 20 73 75 69 64 2d  uid->data, suid-
42c0: 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 7d 20 65 6c  >length));..} el
42d0: 73 65 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69  se {..    Tcl_Li
42e0: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
42f0: 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  nt(interp, certP
4300: 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  tr, Tcl_NewStrin
4310: 67 4f 62 6a 28 22 22 2c 20 2d 31 29 29 3b 0a 09  gObj("", -1));..
4320: 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20  }.    }..    /* 
4330: 58 35 30 39 20 76 33 20 45 78 74 65 6e 73 69 6f  X509 v3 Extensio
4340: 6e 73 20 2d 20 52 46 43 20 35 32 38 30 20 73 65  ns - RFC 5280 se
4350: 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 39 20 2a 2f  ction 4.1.2.9 */
4360: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 49 4e 54  .    LAPPEND_INT
4370: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
4380: 2c 20 22 65 78 74 43 6f 75 6e 74 22 2c 20 58 35  , "extCount", X5
4390: 30 39 5f 67 65 74 5f 65 78 74 5f 63 6f 75 6e 74  09_get_ext_count
43a0: 28 63 65 72 74 29 29 3b 0a 20 20 20 20 4c 41 50  (cert));.    LAP
43b0: 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c  PEND_OBJ(interp,
43c0: 20 63 65 72 74 50 74 72 2c 20 22 65 78 74 65 6e   certPtr, "exten
43d0: 73 69 6f 6e 73 22 2c 20 54 6c 73 5f 78 35 30 39  sions", Tls_x509
43e0: 45 78 74 65 6e 73 69 6f 6e 73 28 69 6e 74 65 72  Extensions(inter
43f0: 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20  p, cert));..    
4400: 2f 2a 20 41 75 74 68 6f 72 69 74 79 20 4b 65 79  /* Authority Key
4410: 20 49 64 65 6e 74 69 66 69 65 72 20 28 41 4b 49   Identifier (AKI
4420: 29 20 69 73 20 74 68 65 20 53 75 62 6a 65 63 74  ) is the Subject
4430: 20 4b 65 79 20 49 64 65 6e 74 69 66 69 65 72 20   Key Identifier 
4440: 28 53 4b 49 29 20 6f 66 0a 09 69 74 73 20 73 69  (SKI) of..its si
4450: 67 6e 65 72 20 28 74 68 65 20 43 41 29 2e 20 52  gner (the CA). R
4460: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
4470: 34 2e 32 2e 31 2e 31 2c 20 4e 49 44 5f 61 75 74  4.2.1.1, NID_aut
4480: 68 6f 72 69 74 79 5f 6b 65 79 5f 69 64 65 6e 74  hority_key_ident
4490: 69 66 69 65 72 20 2a 2f 0a 20 20 20 20 4c 41 50  ifier */.    LAP
44a0: 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c  PEND_OBJ(interp,
44b0: 20 63 65 72 74 50 74 72 2c 20 22 61 75 74 68 6f   certPtr, "autho
44c0: 72 69 74 79 4b 65 79 49 64 65 6e 74 69 66 69 65  rityKeyIdentifie
44d0: 72 22 2c 0a 09 54 6c 73 5f 78 35 30 39 49 64 65  r",..Tls_x509Ide
44e0: 6e 74 69 66 69 65 72 28 58 35 30 39 5f 67 65 74  ntifier(X509_get
44f0: 30 5f 61 75 74 68 6f 72 69 74 79 5f 6b 65 79 5f  0_authority_key_
4500: 69 64 28 63 65 72 74 29 29 29 3b 0a 20 0a 20 20  id(cert)));. .  
4510: 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 4b 65 79    /* Subject Key
4520: 20 49 64 65 6e 74 69 66 69 65 72 20 28 53 4b 49   Identifier (SKI
4530: 29 20 69 73 20 75 73 65 64 20 74 6f 20 69 64 65  ) is used to ide
4540: 6e 74 69 66 79 20 63 65 72 74 69 66 69 63 61 74  ntify certificat
4550: 65 73 20 74 68 61 74 20 63 6f 6e 74 61 69 6e 0a  es that contain.
4560: 09 61 20 70 61 72 74 69 63 75 6c 61 72 20 70 75  .a particular pu
4570: 62 6c 69 63 20 6b 65 79 2e 20 52 46 43 20 35 32  blic key. RFC 52
4580: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31  80 section 4.2.1
4590: 2e 32 2c 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f  .2, NID_subject_
45a0: 6b 65 79 5f 69 64 65 6e 74 69 66 69 65 72 20 2a  key_identifier *
45b0: 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42  /.    LAPPEND_OB
45c0: 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  J(interp, certPt
45d0: 72 2c 20 22 73 75 62 6a 65 63 74 4b 65 79 49 64  r, "subjectKeyId
45e0: 65 6e 74 69 66 69 65 72 22 2c 0a 09 54 6c 73 5f  entifier",..Tls_
45f0: 78 35 30 39 49 64 65 6e 74 69 66 69 65 72 28 58  x509Identifier(X
4600: 35 30 39 5f 67 65 74 30 5f 73 75 62 6a 65 63 74  509_get0_subject
4610: 5f 6b 65 79 5f 69 64 28 63 65 72 74 29 29 29 3b  _key_id(cert)));
4620: 0a 0a 20 20 20 20 2f 2a 20 4b 65 79 20 75 73 61  ..    /* Key usa
4630: 67 65 20 65 78 74 65 6e 73 69 6f 6e 20 64 65 66  ge extension def
4640: 69 6e 65 73 20 74 68 65 20 70 75 72 70 6f 73 65  ines the purpose
4650: 20 28 65 2e 67 2e 2c 20 65 6e 63 69 70 68 65 72   (e.g., encipher
4660: 6d 65 6e 74 2c 20 73 69 67 6e 61 74 75 72 65 2c  ment, signature,
4670: 20 63 65 72 74 69 66 69 63 61 74 65 0a 09 73 69   certificate..si
4680: 67 6e 69 6e 67 29 20 6f 66 20 74 68 65 20 6b 65  gning) of the ke
4690: 79 20 69 6e 20 74 68 65 20 63 65 72 74 69 66 69  y in the certifi
46a0: 63 61 74 65 2e 20 52 46 43 20 35 32 38 30 20 73  cate. RFC 5280 s
46b0: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 33 2c 20  ection 4.2.1.3, 
46c0: 4e 49 44 5f 6b 65 79 5f 75 73 61 67 65 20 2a 2f  NID_key_usage */
46d0: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a  .    LAPPEND_OBJ
46e0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
46f0: 2c 20 22 6b 65 79 55 73 61 67 65 22 2c 20 54 6c  , "keyUsage", Tl
4700: 73 5f 78 35 30 39 4b 65 79 55 73 61 67 65 28 69  s_x509KeyUsage(i
4710: 6e 74 65 72 70 2c 20 63 65 72 74 2c 20 78 66 6c  nterp, cert, xfl
4720: 61 67 73 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 43  ags));..    /* C
4730: 65 72 74 69 66 69 63 61 74 65 20 50 6f 6c 69 63  ertificate Polic
4740: 69 65 73 20 2d 20 69 6e 64 69 63 61 74 65 73 20  ies - indicates 
4750: 74 68 65 20 69 73 73 75 69 6e 67 20 43 41 20 63  the issuing CA c
4760: 6f 6e 73 69 64 65 72 73 20 69 74 73 20 69 73 73  onsiders its iss
4770: 75 65 72 44 6f 6d 61 69 6e 50 6f 6c 69 63 79 0a  uerDomainPolicy.
4780: 09 65 71 75 69 76 61 6c 65 6e 74 20 74 6f 20 74  .equivalent to t
4790: 68 65 20 73 75 62 6a 65 63 74 20 43 41 27 73 20  he subject CA's 
47a0: 73 75 62 6a 65 63 74 44 6f 6d 61 69 6e 50 6f 6c  subjectDomainPol
47b0: 69 63 79 2e 20 52 46 43 20 35 32 38 30 20 73 65  icy. RFC 5280 se
47c0: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 34 2c 20 4e  ction 4.2.1.4, N
47d0: 49 44 5f 63 65 72 74 69 66 69 63 61 74 65 5f 70  ID_certificate_p
47e0: 6f 6c 69 63 69 65 73 20 2a 2f 0a 20 20 20 20 69  olicies */.    i
47f0: 66 20 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c  f (xflags & EXFL
4800: 41 47 5f 49 4e 56 41 4c 49 44 5f 50 4f 4c 49 43  AG_INVALID_POLIC
4810: 59 29 20 7b 0a 09 2f 2a 20 52 65 6a 65 63 74 20  Y) {../* Reject 
4820: 63 65 72 74 20 2a 2f 0a 20 20 20 20 7d 0a 0a 20  cert */.    }.. 
4830: 20 20 20 2f 2a 20 50 6f 6c 69 63 79 20 4d 61 70     /* Policy Map
4840: 70 69 6e 67 73 20 2d 20 52 46 43 20 35 32 38 30  pings - RFC 5280
4850: 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 35   section 4.2.1.5
4860: 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 5f 6d 61 70  , NID_policy_map
4870: 70 69 6e 67 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a  pings */..    /*
4880: 20 53 75 62 6a 65 63 74 20 41 6c 74 65 72 6e 61   Subject Alterna
4890: 74 69 76 65 20 4e 61 6d 65 20 28 53 41 4e 29 20  tive Name (SAN) 
48a0: 63 6f 6e 74 61 69 6e 73 20 61 64 64 69 74 69 6f  contains additio
48b0: 6e 61 6c 20 55 52 4c 73 2c 20 44 4e 53 20 6e 61  nal URLs, DNS na
48c0: 6d 65 73 2c 20 6f 72 20 49 50 0a 09 61 64 64 72  mes, or IP..addr
48d0: 65 73 73 65 73 20 62 6f 75 6e 64 20 74 6f 20 63  esses bound to c
48e0: 65 72 74 69 66 69 63 61 74 65 2e 20 52 46 43 20  ertificate. RFC 
48f0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32  5280 section 4.2
4900: 2e 31 2e 36 2c 20 4e 49 44 5f 73 75 62 6a 65 63  .1.6, NID_subjec
4910: 74 5f 61 6c 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20  t_alt_name */.  
4920: 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e    LAPPEND_OBJ(in
4930: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
4940: 73 75 62 6a 65 63 74 41 6c 74 4e 61 6d 65 22 2c  subjectAltName",
4950: 20 54 6c 73 5f 78 35 30 39 4e 61 6d 65 73 28 69   Tls_x509Names(i
4960: 6e 74 65 72 70 2c 20 63 65 72 74 2c 20 4e 49 44  nterp, cert, NID
4970: 5f 73 75 62 6a 65 63 74 5f 61 6c 74 5f 6e 61 6d  _subject_alt_nam
4980: 65 2c 20 62 69 6f 29 29 3b 0a 0a 20 20 20 20 2f  e, bio));..    /
4990: 2a 20 49 73 73 75 65 72 20 41 6c 74 65 72 6e 61  * Issuer Alterna
49a0: 74 69 76 65 20 4e 61 6d 65 20 69 73 20 75 73 65  tive Name is use
49b0: 64 20 74 6f 20 61 73 73 6f 63 69 61 74 65 20 49  d to associate I
49c0: 6e 74 65 72 6e 65 74 20 73 74 79 6c 65 20 69 64  nternet style id
49d0: 65 6e 74 69 74 69 65 73 0a 09 77 69 74 68 20 74  entities..with t
49e0: 68 65 20 63 65 72 74 69 66 69 63 61 74 65 20 69  he certificate i
49f0: 73 73 75 65 72 2e 20 52 46 43 20 35 32 38 30 20  ssuer. RFC 5280 
4a00: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 37 2c  section 4.2.1.7,
4a10: 20 4e 49 44 5f 69 73 73 75 65 72 5f 61 6c 74 5f   NID_issuer_alt_
4a20: 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 4c 41 50 50  name */.    LAPP
4a30: 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20  END_OBJ(interp, 
4a40: 63 65 72 74 50 74 72 2c 20 22 69 73 73 75 65 72  certPtr, "issuer
4a50: 41 6c 74 4e 61 6d 65 22 2c 20 54 6c 73 5f 78 35  AltName", Tls_x5
4a60: 30 39 4e 61 6d 65 73 28 69 6e 74 65 72 70 2c 20  09Names(interp, 
4a70: 63 65 72 74 2c 20 4e 49 44 5f 69 73 73 75 65 72  cert, NID_issuer
4a80: 5f 61 6c 74 5f 6e 61 6d 65 2c 20 62 69 6f 29 29  _alt_name, bio))
4a90: 3b 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 63  ;..    /* Subjec
4aa0: 74 20 44 69 72 65 63 74 6f 72 79 20 41 74 74 72  t Directory Attr
4ab0: 69 62 75 74 65 73 20 70 72 6f 76 69 64 65 73 20  ibutes provides 
4ac0: 69 64 65 6e 74 69 66 69 63 61 74 69 6f 6e 20 61  identification a
4ad0: 74 74 72 69 62 75 74 65 73 20 28 65 2e 67 2e 2c  ttributes (e.g.,
4ae0: 20 6e 61 74 69 6f 6e 61 6c 69 74 79 29 0a 09 6f   nationality)..o
4af0: 66 20 74 68 65 20 73 75 62 6a 65 63 74 2e 20 52  f the subject. R
4b00: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
4b10: 34 2e 32 2e 31 2e 38 20 28 73 75 62 6a 65 63 74  4.2.1.8 (subject
4b20: 44 69 72 65 63 74 6f 72 79 41 74 74 72 69 62 75  DirectoryAttribu
4b30: 74 65 73 29 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20  tes) */..    /* 
4b40: 42 61 73 69 63 20 43 6f 6e 73 74 72 61 69 6e 74  Basic Constraint
4b50: 73 20 69 64 65 6e 74 69 66 69 65 73 20 77 68 65  s identifies whe
4b60: 74 68 65 72 20 74 68 65 20 73 75 62 6a 65 63 74  ther the subject
4b70: 20 6f 66 20 74 68 65 20 63 65 72 74 20 69 73 20   of the cert is 
4b80: 61 20 43 41 20 61 6e 64 0a 09 74 68 65 20 6d 61  a CA and..the ma
4b90: 78 20 64 65 70 74 68 20 6f 66 20 76 61 6c 69 64  x depth of valid
4ba0: 20 63 65 72 74 20 70 61 74 68 73 20 66 6f 72 20   cert paths for 
4bb0: 74 68 69 73 20 63 65 72 74 2e 20 52 46 43 20 35  this cert. RFC 5
4bc0: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e  280 section 4.2.
4bd0: 31 2e 39 2c 20 4e 49 44 5f 62 61 73 69 63 5f 63  1.9, NID_basic_c
4be0: 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 20 20  onstraints */.  
4bf0: 20 20 69 66 20 28 21 28 78 66 6c 61 67 73 20 26    if (!(xflags &
4c00: 20 45 58 46 4c 41 47 5f 50 52 4f 58 59 29 29 20   EXFLAG_PROXY)) 
4c10: 7b 0a 09 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 28  {..LAPPEND_LONG(
4c20: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
4c30: 20 22 70 61 74 68 4c 65 6e 22 2c 20 58 35 30 39   "pathLen", X509
4c40: 5f 67 65 74 5f 70 61 74 68 6c 65 6e 28 63 65 72  _get_pathlen(cer
4c50: 74 29 29 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20  t));.    } else 
4c60: 7b 0a 09 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 28  {..LAPPEND_LONG(
4c70: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
4c80: 20 22 70 61 74 68 4c 65 6e 22 2c 20 58 35 30 39   "pathLen", X509
4c90: 5f 67 65 74 5f 70 72 6f 78 79 5f 70 61 74 68 6c  _get_proxy_pathl
4ca0: 65 6e 28 63 65 72 74 29 29 3b 0a 20 20 20 20 7d  en(cert));.    }
4cb0: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f  .    LAPPEND_BOO
4cc0: 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  L(interp, certPt
4cd0: 72 2c 20 22 62 61 73 69 63 43 6f 6e 73 74 72 61  r, "basicConstra
4ce0: 69 6e 74 73 43 41 22 2c 20 78 66 6c 61 67 73 20  intsCA", xflags 
4cf0: 26 20 45 58 46 4c 41 47 5f 43 41 29 3b 0a 0a 20  & EXFLAG_CA);.. 
4d00: 20 20 20 2f 2a 20 4e 61 6d 65 20 43 6f 6e 73 74     /* Name Const
4d10: 72 61 69 6e 74 73 20 69 73 20 6f 6e 6c 79 20 75  raints is only u
4d20: 73 65 64 20 69 6e 20 43 41 20 63 65 72 74 73 20  sed in CA certs 
4d30: 74 6f 20 69 6e 64 69 63 61 74 65 20 74 68 65 20  to indicate the 
4d40: 6e 61 6d 65 20 73 70 61 63 65 20 66 6f 72 0a 09  name space for..
4d50: 61 6c 6c 20 73 75 62 6a 65 63 74 20 6e 61 6d 65  all subject name
4d60: 73 20 69 6e 20 73 75 62 73 65 71 75 65 6e 74 20  s in subsequent 
4d70: 63 65 72 74 69 66 69 63 61 74 65 73 20 69 6e 20  certificates in 
4d80: 61 20 63 65 72 74 69 66 69 63 61 74 69 6f 6e 20  a certification 
4d90: 70 61 74 68 0a 09 4d 55 53 54 20 62 65 20 6c 6f  path..MUST be lo
4da0: 63 61 74 65 64 2e 20 52 46 43 20 35 32 38 30 20  cated. RFC 5280 
4db0: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 30  section 4.2.1.10
4dc0: 2c 20 4e 49 44 5f 6e 61 6d 65 5f 63 6f 6e 73 74  , NID_name_const
4dd0: 72 61 69 6e 74 73 20 2a 2f 0a 0a 20 20 20 20 2f  raints */..    /
4de0: 2a 20 50 6f 6c 69 63 79 20 43 6f 6e 73 74 72 61  * Policy Constra
4df0: 69 6e 74 73 20 69 73 20 6f 6e 6c 79 20 75 73 65  ints is only use
4e00: 64 20 69 6e 20 43 41 20 63 65 72 74 73 20 74 6f  d in CA certs to
4e10: 20 6c 69 6d 69 74 20 74 68 65 20 6c 65 6e 67 74   limit the lengt
4e20: 68 20 6f 66 20 61 0a 09 63 65 72 74 20 63 68 61  h of a..cert cha
4e30: 69 6e 20 66 6f 72 20 74 68 61 74 20 43 41 2e 20  in for that CA. 
4e40: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e  RFC 5280 section
4e50: 20 34 2e 32 2e 31 2e 31 31 2c 20 4e 49 44 5f 70   4.2.1.11, NID_p
4e60: 6f 6c 69 63 79 5f 63 6f 6e 73 74 72 61 69 6e 74  olicy_constraint
4e70: 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 45 78 74  s */..    /* Ext
4e80: 65 6e 64 65 64 20 4b 65 79 20 55 73 61 67 65 20  ended Key Usage 
4e90: 69 6e 64 69 63 61 74 65 73 20 74 68 65 20 70 75  indicates the pu
4ea0: 72 70 6f 73 65 73 20 74 68 65 20 63 65 72 74 69  rposes the certi
4eb0: 66 69 65 64 20 70 75 62 6c 69 63 20 6b 65 79 20  fied public key 
4ec0: 6d 61 79 20 62 65 0a 09 75 73 65 64 2c 20 62 65  may be..used, be
4ed0: 79 6f 6e 64 20 74 68 65 20 62 61 73 69 63 20 70  yond the basic p
4ee0: 75 72 70 6f 73 65 73 2e 20 52 46 43 20 35 32 38  urposes. RFC 528
4ef0: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e  0 section 4.2.1.
4f00: 31 32 2c 20 4e 49 44 5f 65 78 74 5f 6b 65 79 5f  12, NID_ext_key_
4f10: 75 73 61 67 65 20 2a 2f 0a 20 20 20 20 4c 41 50  usage */.    LAP
4f20: 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c  PEND_OBJ(interp,
4f30: 20 63 65 72 74 50 74 72 2c 20 22 65 78 74 65 6e   certPtr, "exten
4f40: 64 65 64 4b 65 79 55 73 61 67 65 22 2c 20 54 6c  dedKeyUsage", Tl
4f50: 73 5f 78 35 30 39 45 78 74 4b 65 79 55 73 61 67  s_x509ExtKeyUsag
4f60: 65 28 69 6e 74 65 72 70 2c 20 63 65 72 74 2c 20  e(interp, cert, 
4f70: 78 66 6c 61 67 73 29 29 3b 0a 0a 20 20 20 20 2f  xflags));..    /
4f80: 2a 20 43 52 4c 20 44 69 73 74 72 69 62 75 74 69  * CRL Distributi
4f90: 6f 6e 20 50 6f 69 6e 74 73 20 69 64 65 6e 74 69  on Points identi
4fa0: 66 69 65 73 20 77 68 65 72 65 20 43 52 4c 20 69  fies where CRL i
4fb0: 6e 66 6f 72 6d 61 74 69 6f 6e 20 63 61 6e 20 62  nformation can b
4fc0: 65 20 6f 62 74 61 69 6e 65 64 2e 0a 09 52 46 43  e obtained...RFC
4fd0: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e   5280 section 4.
4fe0: 32 2e 31 2e 31 33 2a 2f 0a 20 20 20 20 4c 41 50  2.1.13*/.    LAP
4ff0: 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c  PEND_OBJ(interp,
5000: 20 63 65 72 74 50 74 72 2c 20 22 63 72 6c 44 69   certPtr, "crlDi
5010: 73 74 72 69 62 75 74 69 6f 6e 50 6f 69 6e 74 73  stributionPoints
5020: 22 2c 20 54 6c 73 5f 78 35 30 39 43 72 6c 44 70  ", Tls_x509CrlDp
5030: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 29 3b  (interp, cert));
5040: 0a 0a 20 20 20 20 2f 2a 20 46 72 65 73 68 65 73  ..    /* Freshes
5050: 74 20 43 52 4c 20 65 78 74 65 6e 73 69 6f 6e 20  t CRL extension 
5060: 2a 2f 0a 20 20 20 20 69 66 20 28 78 66 6c 61 67  */.    if (xflag
5070: 73 20 26 20 45 58 46 4c 41 47 5f 46 52 45 53 48  s & EXFLAG_FRESH
5080: 45 53 54 29 20 7b 0a 20 20 20 20 7d 0a 0a 20 20  EST) {.    }..  
5090: 20 20 2f 2a 20 41 75 74 68 6f 72 69 74 79 20 49    /* Authority I
50a0: 6e 66 6f 72 6d 61 74 69 6f 6e 20 41 63 63 65 73  nformation Acces
50b0: 73 20 69 6e 64 69 63 61 74 65 73 20 68 6f 77 20  s indicates how 
50c0: 74 6f 20 61 63 63 65 73 73 20 69 6e 66 6f 20 61  to access info a
50d0: 6e 64 20 73 65 72 76 69 63 65 73 0a 09 66 6f 72  nd services..for
50e0: 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65   the certificate
50f0: 20 69 73 73 75 65 72 2e 20 52 46 43 20 35 32 38   issuer. RFC 528
5100: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 32 2e  0 section 4.2.2.
5110: 31 2c 20 4e 49 44 5f 69 6e 66 6f 5f 61 63 63 65  1, NID_info_acce
5120: 73 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 47 65  ss */..    /* Ge
5130: 74 20 4f 6e 2d 6c 69 6e 65 20 43 65 72 74 69 66  t On-line Certif
5140: 69 63 61 74 65 20 53 74 61 74 75 73 20 50 72 6f  icate Status Pro
5150: 74 6f 63 6f 6c 20 28 4f 53 43 50 29 20 52 65 73  tocol (OSCP) Res
5160: 70 6f 6e 64 65 72 73 20 55 52 4c 20 2a 2f 0a 20  ponders URL */. 
5170: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69     LAPPEND_OBJ(i
5180: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
5190: 22 6f 63 73 70 52 65 73 70 6f 6e 64 65 72 73 22  "ocspResponders"
51a0: 2c 20 54 6c 73 5f 78 35 30 39 4f 73 63 70 28 69  , Tls_x509Oscp(i
51b0: 6e 74 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a  nterp, cert));..
51c0: 20 20 20 20 2f 2a 20 47 65 74 20 43 65 72 74 69      /* Get Certi
51d0: 66 69 63 61 74 65 20 41 75 74 68 6f 72 69 74 79  ficate Authority
51e0: 20 28 43 41 29 20 49 73 73 75 65 72 73 20 55 52   (CA) Issuers UR
51f0: 4c 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44  L */.    LAPPEND
5200: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72  _OBJ(interp, cer
5210: 74 50 74 72 2c 20 22 63 61 49 73 73 75 65 72 73  tPtr, "caIssuers
5220: 22 2c 20 54 6c 73 5f 78 35 30 39 43 61 49 73 73  ", Tls_x509CaIss
5230: 75 65 72 73 28 69 6e 74 65 72 70 2c 20 63 65 72  uers(interp, cer
5240: 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 53 75 62  t));..    /* Sub
5250: 6a 65 63 74 20 49 6e 66 6f 72 6d 61 74 69 6f 6e  ject Information
5260: 20 41 63 63 65 73 73 20 2d 20 52 46 43 20 35 32   Access - RFC 52
5270: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 32  80 section 4.2.2
5280: 2e 32 2c 20 4e 49 44 5f 73 69 6e 66 6f 5f 61 63  .2, NID_sinfo_ac
5290: 63 65 73 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20  cess */..    /* 
52a0: 43 65 72 74 69 66 69 63 61 74 65 20 41 6c 69 61  Certificate Alia
52b0: 73 2e 20 49 66 20 75 73 65 73 20 61 20 50 4b 43  s. If uses a PKC
52c0: 53 23 31 32 20 73 74 72 75 63 74 75 72 65 2c 20  S#12 structure, 
52d0: 61 6c 69 61 73 20 77 69 6c 6c 20 72 65 66 6c 65  alias will refle
52e0: 63 74 20 74 68 65 0a 09 66 72 69 65 6e 64 6c 79  ct the..friendly
52f0: 4e 61 6d 65 20 61 74 74 72 69 62 75 74 65 20 28  Name attribute (
5300: 52 46 43 20 32 39 38 35 29 2e 20 2a 2f 0a 20 20  RFC 2985). */.  
5310: 20 20 7b 0a 09 6c 65 6e 20 3d 20 30 3b 0a 20 20    {..len = 0;.  
5320: 20 20 20 20 20 20 63 68 61 72 20 2a 73 74 72 69        char *stri
5330: 6e 67 20 3d 20 58 35 30 39 5f 61 6c 69 61 73 5f  ng = X509_alias_
5340: 67 65 74 30 28 63 65 72 74 2c 20 26 6c 65 6e 29  get0(cert, &len)
5350: 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69  ;..LAPPEND_STR(i
5360: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
5370: 22 61 6c 69 61 73 22 2c 20 73 74 72 69 6e 67 2c  "alias", string,
5380: 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20   len);.    }..  
5390: 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65    /* Certificate
53a0: 20 61 6e 64 20 64 75 6d 70 20 61 6c 6c 20 64 61   and dump all da
53b0: 74 61 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 68 61  ta */.    {..cha
53c0: 72 20 63 65 72 74 53 74 72 5b 43 45 52 54 5f 53  r certStr[CERT_S
53d0: 54 52 5f 53 49 5a 45 5d 3b 0a 0a 09 2f 2a 20 47  TR_SIZE];.../* G
53e0: 65 74 20 63 65 72 74 69 66 69 63 61 74 65 20 2a  et certificate *
53f0: 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f  /..len = BIO_to_
5400: 42 75 66 66 65 72 28 50 45 4d 5f 77 72 69 74 65  Buffer(PEM_write
5410: 5f 62 69 6f 5f 58 35 30 39 28 62 69 6f 2c 20 63  _bio_X509(bio, c
5420: 65 72 74 29 2c 20 62 69 6f 2c 20 63 65 72 74 53  ert), bio, certS
5430: 74 72 2c 20 43 45 52 54 5f 53 54 52 5f 53 49 5a  tr, CERT_STR_SIZ
5440: 45 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52  E);..LAPPEND_STR
5450: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
5460: 2c 20 22 63 65 72 74 69 66 69 63 61 74 65 22 2c  , "certificate",
5470: 20 63 65 72 74 53 74 72 2c 20 6c 65 6e 29 3b 0a   certStr, len);.
5480: 0a 09 2f 2a 20 47 65 74 20 61 6c 6c 20 63 65 72  ../* Get all cer
5490: 74 20 69 6e 66 6f 20 2a 2f 0a 09 6c 65 6e 20 3d  t info */..len =
54a0: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58   BIO_to_Buffer(X
54b0: 35 30 39 5f 70 72 69 6e 74 5f 65 78 28 62 69 6f  509_print_ex(bio
54c0: 2c 20 63 65 72 74 2c 20 66 6c 61 67 73 2c 20 30  , cert, flags, 0
54d0: 29 2c 20 62 69 6f 2c 20 63 65 72 74 53 74 72 2c  ), bio, certStr,
54e0: 20 43 45 52 54 5f 53 54 52 5f 53 49 5a 45 29 3b   CERT_STR_SIZE);
54f0: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e  ..LAPPEND_STR(in
5500: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
5510: 61 6c 6c 22 2c 20 63 65 72 74 53 74 72 2c 20 6c  all", certStr, l
5520: 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20  en);.    }..    
5530: 42 49 4f 5f 66 72 65 65 28 62 69 6f 29 3b 0a 20  BIO_free(bio);. 
5540: 20 20 20 72 65 74 75 72 6e 20 63 65 72 74 50 74     return certPt
5550: 72 3b 0a 7d 0a                                   r;.}.