Hex Artifact Content

Artifact 2bf827806d2f69c74fe906bf5e848a2885c231287ada88979e1e27a6f64ae0d3:


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 61 73 6e 31  de <openssl/asn1
0120: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 22 74 6c  .h>.#include "tl
0130: 73 49 6e 74 2e 68 22 0a 0a 2f 2a 20 44 65 66 69  sInt.h"../* Defi
0140: 6e 65 20 6d 61 78 69 6d 75 6d 20 63 65 72 74 69  ne maximum certi
0150: 66 69 63 61 74 65 20 73 69 7a 65 2e 20 4d 61 78  ficate size. Max
0160: 20 50 45 4d 20 73 69 7a 65 20 31 30 30 6b 42 20   PEM size 100kB 
0170: 61 6e 64 20 44 45 52 20 73 69 7a 65 20 69 73 20  and DER size is 
0180: 32 34 6b 42 2e 20 2a 2f 0a 23 64 65 66 69 6e 65  24kB. */.#define
0190: 20 43 45 52 54 5f 53 54 52 5f 53 49 5a 45 20 33   CERT_STR_SIZE 3
01a0: 32 37 36 38 0a 0a 2f 2a 20 43 6f 6d 6d 6f 6e 20  2768../* Common 
01b0: 6d 61 63 72 6f 73 20 2a 2f 0a 23 64 65 66 69 6e  macros */.#defin
01c0: 65 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e  e LAPPEND_STR(in
01d0: 74 65 72 70 2c 20 6f 62 6a 2c 20 74 65 78 74 2c  terp, obj, text,
01e0: 20 76 61 6c 75 65 2c 20 73 69 7a 65 29 20 7b 5c   value, size) {\
01f0: 0a 20 20 20 20 69 66 20 28 74 65 78 74 20 21 3d  .    if (text !=
0200: 20 4e 55 4c 4c 29 20 54 63 6c 5f 4c 69 73 74 4f   NULL) Tcl_ListO
0210: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28  bjAppendElement(
0220: 69 6e 74 65 72 70 2c 20 6f 62 6a 2c 20 54 63 6c  interp, obj, Tcl
0230: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 74 65  _NewStringObj(te
0240: 78 74 2c 20 2d 31 29 29 3b 20 5c 0a 20 20 20 20  xt, -1)); \.    
0250: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e  Tcl_ListObjAppen
0260: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c  dElement(interp,
0270: 20 6f 62 6a 2c 20 54 63 6c 5f 4e 65 77 53 74 72   obj, Tcl_NewStr
0280: 69 6e 67 4f 62 6a 28 76 61 6c 75 65 2c 20 73 69  ingObj(value, si
0290: 7a 65 29 29 3b 20 5c 0a 7d 0a 23 64 65 66 69 6e  ze)); \.}.#defin
02a0: 65 20 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e  e LAPPEND_INT(in
02b0: 74 65 72 70 2c 20 6f 62 6a 2c 20 74 65 78 74 2c  terp, obj, text,
02c0: 20 76 61 6c 75 65 29 20 7b 5c 0a 20 20 20 20 69   value) {\.    i
02d0: 66 20 28 74 65 78 74 20 21 3d 20 4e 55 4c 4c 29  f (text != NULL)
02e0: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
02f0: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
0300: 2c 20 6f 62 6a 2c 20 54 63 6c 5f 4e 65 77 53 74  , obj, Tcl_NewSt
0310: 72 69 6e 67 4f 62 6a 28 74 65 78 74 2c 20 2d 31  ringObj(text, -1
0320: 29 29 3b 20 5c 0a 20 20 20 20 54 63 6c 5f 4c 69  )); \.    Tcl_Li
0330: 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65  stObjAppendEleme
0340: 6e 74 28 69 6e 74 65 72 70 2c 20 6f 62 6a 2c 20  nt(interp, obj, 
0350: 54 63 6c 5f 4e 65 77 49 6e 74 4f 62 6a 28 76 61  Tcl_NewIntObj(va
0360: 6c 75 65 29 29 3b 20 5c 0a 7d 0a 23 64 65 66 69  lue)); \.}.#defi
0370: 6e 65 20 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 28  ne LAPPEND_LONG(
0380: 69 6e 74 65 72 70 2c 20 6f 62 6a 2c 20 74 65 78  interp, obj, tex
0390: 74 2c 20 76 61 6c 75 65 29 20 7b 5c 0a 20 20 20  t, value) {\.   
03a0: 20 69 66 20 28 74 65 78 74 20 21 3d 20 4e 55 4c   if (text != NUL
03b0: 4c 29 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70  L) Tcl_ListObjAp
03c0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
03d0: 72 70 2c 20 6f 62 6a 2c 20 54 63 6c 5f 4e 65 77  rp, obj, Tcl_New
03e0: 53 74 72 69 6e 67 4f 62 6a 28 74 65 78 74 2c 20  StringObj(text, 
03f0: 2d 31 29 29 3b 20 5c 0a 20 20 20 20 54 63 6c 5f  -1)); \.    Tcl_
0400: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
0410: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6f 62 6a  ment(interp, obj
0420: 2c 20 54 63 6c 5f 4e 65 77 4c 6f 6e 67 4f 62 6a  , Tcl_NewLongObj
0430: 28 76 61 6c 75 65 29 29 3b 20 5c 0a 7d 0a 23 64  (value)); \.}.#d
0440: 65 66 69 6e 65 20 4c 41 50 50 45 4e 44 5f 42 4f  efine LAPPEND_BO
0450: 4f 4c 28 69 6e 74 65 72 70 2c 20 6f 62 6a 2c 20  OL(interp, obj, 
0460: 74 65 78 74 2c 20 76 61 6c 75 65 29 20 7b 5c 0a  text, value) {\.
0470: 20 20 20 20 69 66 20 28 74 65 78 74 20 21 3d 20      if (text != 
0480: 4e 55 4c 4c 29 20 54 63 6c 5f 4c 69 73 74 4f 62  NULL) Tcl_ListOb
0490: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69  jAppendElement(i
04a0: 6e 74 65 72 70 2c 20 6f 62 6a 2c 20 54 63 6c 5f  nterp, obj, Tcl_
04b0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 74 65 78  NewStringObj(tex
04c0: 74 2c 20 2d 31 29 29 3b 20 5c 0a 20 20 20 20 54  t, -1)); \.    T
04d0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
04e0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20  Element(interp, 
04f0: 6f 62 6a 2c 20 54 63 6c 5f 4e 65 77 42 6f 6f 6c  obj, Tcl_NewBool
0500: 65 61 6e 4f 62 6a 28 76 61 6c 75 65 29 29 3b 20  eanObj(value)); 
0510: 5c 0a 7d 0a 23 64 65 66 69 6e 65 20 4c 41 50 50  \.}.#define LAPP
0520: 45 4e 44 5f 4c 49 53 54 28 69 6e 74 65 72 70 2c  END_LIST(interp,
0530: 20 6f 62 6a 2c 20 74 65 78 74 2c 20 6c 69 73 74   obj, text, list
0540: 4f 62 6a 29 20 7b 5c 0a 20 20 20 20 69 66 20 28  Obj) {\.    if (
0550: 74 65 78 74 20 21 3d 20 4e 55 4c 4c 29 20 54 63  text != NULL) Tc
0560: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
0570: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6f  lement(interp, o
0580: 62 6a 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e  bj, Tcl_NewStrin
0590: 67 4f 62 6a 28 74 65 78 74 2c 20 2d 31 29 29 3b  gObj(text, -1));
05a0: 20 5c 0a 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f   \.    Tcl_ListO
05b0: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28  bjAppendElement(
05c0: 69 6e 74 65 72 70 2c 20 6f 62 6a 2c 20 6c 69 73  interp, obj, lis
05d0: 74 4f 62 6a 29 3b 20 5c 0a 7d 0a 0a 2f 2a 0a 20  tObj); \.}../*. 
05e0: 2a 20 42 69 6e 61 72 79 20 73 74 72 69 6e 67 20  * Binary string 
05f0: 74 6f 20 68 65 78 20 73 74 72 69 6e 67 0a 20 2a  to hex string. *
0600: 2f 0a 69 6e 74 20 53 74 72 69 6e 67 5f 74 6f 5f  /.int String_to_
0610: 48 65 78 28 63 68 61 72 2a 20 69 6e 70 75 74 2c  Hex(char* input,
0620: 20 69 6e 74 20 6c 65 6e 2c 20 63 68 61 72 20 2a   int len, char *
0630: 6f 75 74 70 75 74 2c 20 69 6e 74 20 73 69 7a 65  output, int size
0640: 29 20 7b 0a 20 20 20 20 69 6e 74 20 63 6f 75 6e  ) {.    int coun
0650: 74 20 3d 20 30 3b 0a 0a 20 20 20 20 66 6f 72 20  t = 0;..    for 
0660: 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20  (int i = 0; i < 
0670: 6c 65 6e 20 26 26 20 63 6f 75 6e 74 20 3c 20 73  len && count < s
0680: 69 7a 65 20 2d 20 31 3b 20 69 2b 2b 2c 20 63 6f  ize - 1; i++, co
0690: 75 6e 74 20 2b 3d 20 32 29 20 7b 0a 09 73 70 72  unt += 2) {..spr
06a0: 69 6e 74 66 28 6f 75 74 70 75 74 20 2b 20 63 6f  intf(output + co
06b0: 75 6e 74 2c 20 22 25 30 32 58 22 2c 20 69 6e 70  unt, "%02X", inp
06c0: 75 74 5b 69 5d 20 26 20 30 78 66 66 29 3b 0a 20  ut[i] & 0xff);. 
06d0: 20 20 20 7d 0a 20 20 20 20 6f 75 74 70 75 74 5b     }.    output[
06e0: 63 6f 75 6e 74 5d 20 3d 20 30 3b 0a 20 20 20 20  count] = 0;.    
06f0: 72 65 74 75 72 6e 20 63 6f 75 6e 74 3b 0a 7d 0a  return count;.}.
0700: 0a 2f 2a 0a 20 2a 20 42 49 4f 20 74 6f 20 42 75  ./*. * BIO to Bu
0710: 66 66 65 72 0a 20 2a 2f 0a 69 6e 74 20 42 49 4f  ffer. */.int BIO
0720: 5f 74 6f 5f 42 75 66 66 65 72 28 69 6e 74 20 72  _to_Buffer(int r
0730: 65 73 75 6c 74 2c 20 42 49 4f 20 2a 62 69 6f 2c  esult, BIO *bio,
0740: 20 76 6f 69 64 20 2a 62 75 66 66 65 72 2c 20 69   void *buffer, i
0750: 6e 74 20 73 69 7a 65 29 20 7b 0a 20 20 20 20 69  nt size) {.    i
0760: 6e 74 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20 20  nt len = 0;.    
0770: 69 6e 74 20 70 65 6e 64 69 6e 67 20 3d 20 42 49  int pending = BI
0780: 4f 5f 70 65 6e 64 69 6e 67 28 62 69 6f 29 3b 0a  O_pending(bio);.
0790: 0a 20 20 20 20 69 66 20 28 72 65 73 75 6c 74 29  .    if (result)
07a0: 20 7b 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 72 65   {..len = BIO_re
07b0: 61 64 28 62 69 6f 2c 20 62 75 66 66 65 72 2c 20  ad(bio, buffer, 
07c0: 28 70 65 6e 64 69 6e 67 20 3c 20 73 69 7a 65 29  (pending < size)
07d0: 20 3f 20 70 65 6e 64 69 6e 67 20 3a 20 73 69 7a   ? pending : siz
07e0: 65 29 3b 0a 09 28 76 6f 69 64 29 42 49 4f 5f 66  e);..(void)BIO_f
07f0: 6c 75 73 68 28 62 69 6f 29 3b 0a 09 69 66 20 28  lush(bio);..if (
0800: 6c 65 6e 20 3c 20 30 29 20 7b 0a 09 20 20 20 20  len < 0) {..    
0810: 6c 65 6e 20 3d 20 30 3b 0a 09 7d 0a 20 20 20 20  len = 0;..}.    
0820: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 65 6e  }.    return len
0830: 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 2a 2d 2d 2d 2d 2d  ;.}.../*. *-----
0840: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0850: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0860: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0870: 2d 2a 0a 20 2a 0a 20 2a 09 54 6c 73 5f 4e 65 77  -*. *. *.Tls_New
0880: 58 35 30 39 4f 62 6a 20 2d 2d 0a 20 2a 0a 20 2a  X509Obj --. *. *
0890: 09 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  .---------------
08a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
08b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
08c0: 2d 2a 0a 20 2a 09 43 6f 6e 76 65 72 74 73 20 61  -*. *.Converts a
08d0: 20 58 35 30 39 20 63 65 72 74 69 66 69 63 61 74   X509 certificat
08e0: 65 20 69 6e 74 6f 20 61 20 54 63 6c 5f 4f 62 6a  e into a Tcl_Obj
08f0: 0a 20 2a 09 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  . *.------------
0900: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0910: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
0920: 2d 2d 2d 2d 2a 0a 20 2a 0a 20 2a 09 53 69 64 65  ----*. *. *.Side
0930: 20 65 66 66 65 63 74 73 3a 0a 20 2a 09 09 4e 6f   effects:. *..No
0940: 6e 65 0a 20 2a 0a 20 2a 09 52 65 73 75 6c 74 3a  ne. *. *.Result:
0950: 0a 20 2a 09 09 41 20 54 63 6c 20 4c 69 73 74 20  . *..A Tcl List 
0960: 4f 62 6a 65 63 74 20 72 65 70 72 65 73 65 6e 74  Object represent
0970: 69 6e 67 20 74 68 65 20 70 72 6f 76 69 64 65 64  ing the provided
0980: 0a 20 2a 09 09 58 35 30 39 20 63 65 72 74 69 66  . *..X509 certif
0990: 69 63 61 74 65 2e 0a 20 2a 0a 20 2a 2d 2d 2d 2d  icate.. *. *----
09a0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d  ----------------
09d0: 2d 2d 2a 0a 20 2a 2f 0a 0a 54 63 6c 5f 4f 62 6a  --*. */..Tcl_Obj
09e0: 2a 0a 54 6c 73 5f 4e 65 77 58 35 30 39 4f 62 6a  *.Tls_NewX509Obj
09f0: 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74  (Tcl_Interp *int
0a00: 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29  erp, X509 *cert)
0a10: 20 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a   {.    Tcl_Obj *
0a20: 63 65 72 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65  certPtr = Tcl_Ne
0a30: 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c  wListObj(0, NULL
0a40: 29 2c 20 2a 6c 69 73 74 50 74 72 3b 0a 20 20 20  ), *listPtr;.   
0a50: 20 42 49 4f 20 2a 62 69 6f 20 3d 20 42 49 4f 5f   BIO *bio = BIO_
0a60: 6e 65 77 28 42 49 4f 5f 73 5f 6d 65 6d 28 29 29  new(BIO_s_mem())
0a70: 3b 0a 20 20 20 20 69 6e 74 20 6d 64 6e 69 64 2c  ;.    int mdnid,
0a80: 20 70 6b 6e 69 64 2c 20 62 69 74 73 2c 20 6c 65   pknid, bits, le
0a90: 6e 3b 0a 20 20 20 20 75 69 6e 74 33 32 5f 74 20  n;.    uint32_t 
0aa0: 78 66 6c 61 67 73 2c 20 75 73 61 67 65 3b 0a 20  xflags, usage;. 
0ab0: 20 20 20 63 68 61 72 20 62 75 66 66 65 72 5b 42     char buffer[B
0ac0: 55 46 53 49 5a 5d 3b 0a 20 20 20 20 75 6e 73 69  UFSIZ];.    unsi
0ad0: 67 6e 65 64 20 63 68 61 72 20 6d 64 5b 45 56 50  gned char md[EVP
0ae0: 5f 4d 41 58 5f 4d 44 5f 53 49 5a 45 5d 3b 0a 20  _MAX_MD_SIZE];. 
0af0: 20 20 20 53 54 41 43 4b 5f 4f 46 28 47 45 4e 45     STACK_OF(GENE
0b00: 52 41 4c 5f 4e 41 4d 45 29 20 2a 6e 61 6d 65 73  RAL_NAME) *names
0b10: 3b 0a 20 20 20 20 53 54 41 43 4b 5f 4f 46 28 44  ;.    STACK_OF(D
0b20: 49 53 54 5f 50 4f 49 4e 54 29 20 2a 63 72 6c 3b  IST_POINT) *crl;
0b30: 0a 20 20 20 20 53 54 41 43 4b 5f 4f 46 28 4f 50  .    STACK_OF(OP
0b40: 45 4e 53 53 4c 5f 53 54 52 49 4e 47 29 20 2a 6f  ENSSL_STRING) *o
0b50: 63 73 70 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65  csp;.    unsigne
0b60: 64 20 6c 6f 6e 67 20 66 6c 61 67 73 20 3d 20 58  d long flags = X
0b70: 4e 5f 46 4c 41 47 5f 52 46 43 32 32 35 33 20 7c  N_FLAG_RFC2253 |
0b80: 20 41 53 4e 31 5f 53 54 52 46 4c 47 53 5f 55 54   ASN1_STRFLGS_UT
0b90: 46 38 5f 43 4f 4e 56 45 52 54 3b 0a 20 20 20 20  F8_CONVERT;.    
0ba0: 66 6c 61 67 73 20 26 3d 20 7e 41 53 4e 31 5f 53  flags &= ~ASN1_S
0bb0: 54 52 46 4c 47 53 5f 45 53 43 5f 4d 53 42 3b 0a  TRFLGS_ESC_MSB;.
0bc0: 0a 20 20 20 20 69 66 20 28 62 69 6f 20 3d 3d 20  .    if (bio == 
0bd0: 4e 55 4c 4c 20 7c 7c 20 63 65 72 74 50 74 72 20  NULL || certPtr 
0be0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75  == NULL) {..retu
0bf0: 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a  rn NULL;.    }..
0c00: 20 20 20 20 2f 2a 20 53 69 67 6e 61 74 75 72 65      /* Signature
0c10: 20 61 6c 67 6f 72 69 74 68 6d 20 61 6e 64 20 76   algorithm and v
0c20: 61 6c 75 65 20 2d 20 52 46 43 20 35 32 38 30 20  alue - RFC 5280 
0c30: 73 65 63 74 69 6f 6e 20 34 2e 31 2e 31 2e 32 20  section 4.1.1.2 
0c40: 61 6e 64 20 34 2e 31 2e 31 2e 33 20 2a 2f 0a 20  and 4.1.1.3 */. 
0c50: 20 20 20 2f 2a 20 73 69 67 6e 61 74 75 72 65 41     /* signatureA
0c60: 6c 67 6f 72 69 74 68 6d 20 69 73 20 74 68 65 20  lgorithm is the 
0c70: 69 64 20 6f 66 20 74 68 65 20 63 72 79 70 74 6f  id of the crypto
0c80: 67 72 61 70 68 69 63 20 61 6c 67 6f 72 69 74 68  graphic algorith
0c90: 6d 20 75 73 65 64 20 62 79 20 74 68 65 0a 09 43  m used by the..C
0ca0: 41 20 74 6f 20 73 69 67 6e 20 74 68 69 73 20 63  A to sign this c
0cb0: 65 72 74 2e 20 73 69 67 6e 61 74 75 72 65 56 61  ert. signatureVa
0cc0: 6c 75 65 20 69 73 20 74 68 65 20 64 69 67 69 74  lue is the digit
0cd0: 61 6c 20 73 69 67 6e 61 74 75 72 65 20 63 6f 6d  al signature com
0ce0: 70 75 74 65 64 0a 09 75 70 6f 6e 20 74 68 65 20  puted..upon the 
0cf0: 41 53 4e 2e 31 20 44 45 52 20 65 6e 63 6f 64 65  ASN.1 DER encode
0d00: 64 20 74 62 73 43 65 72 74 69 66 69 63 61 74 65  d tbsCertificate
0d10: 2e 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 6f 6e 73  . */.    {..cons
0d20: 74 20 58 35 30 39 5f 41 4c 47 4f 52 20 2a 73 69  t X509_ALGOR *si
0d30: 67 5f 61 6c 67 3b 0a 09 63 6f 6e 73 74 20 41 53  g_alg;..const AS
0d40: 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a 73  N1_BIT_STRING *s
0d50: 69 67 3b 0a 09 69 6e 74 20 73 69 67 5f 6e 69 64  ig;..int sig_nid
0d60: 3b 0a 0a 09 58 35 30 39 5f 67 65 74 30 5f 73 69  ;...X509_get0_si
0d70: 67 6e 61 74 75 72 65 28 26 73 69 67 2c 20 26 73  gnature(&sig, &s
0d80: 69 67 5f 61 6c 67 2c 20 63 65 72 74 29 3b 0a 09  ig_alg, cert);..
0d90: 2f 2a 20 73 69 67 5f 6e 69 64 20 3d 20 58 35 30  /* sig_nid = X50
0da0: 39 5f 67 65 74 5f 73 69 67 6e 61 74 75 72 65 5f  9_get_signature_
0db0: 6e 69 64 28 63 65 72 74 29 20 2a 2f 0a 09 73 69  nid(cert) */..si
0dc0: 67 5f 6e 69 64 20 3d 20 4f 42 4a 5f 6f 62 6a 32  g_nid = OBJ_obj2
0dd0: 6e 69 64 28 73 69 67 5f 61 6c 67 2d 3e 61 6c 67  nid(sig_alg->alg
0de0: 6f 72 69 74 68 6d 29 3b 0a 09 4c 41 50 50 45 4e  orithm);..LAPPEN
0df0: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65  D_STR(interp, ce
0e00: 72 74 50 74 72 2c 20 22 73 69 67 6e 61 74 75 72  rtPtr, "signatur
0e10: 65 41 6c 67 6f 72 69 74 68 6d 22 2c 20 4f 42 4a  eAlgorithm", OBJ
0e20: 5f 6e 69 64 32 6c 6e 28 73 69 67 5f 6e 69 64 29  _nid2ln(sig_nid)
0e30: 2c 20 2d 31 29 3b 0a 09 6c 65 6e 20 3d 20 28 73  , -1);..len = (s
0e40: 69 67 5f 6e 69 64 20 21 3d 20 4e 49 44 5f 75 6e  ig_nid != NID_un
0e50: 64 65 66 29 20 3f 20 53 74 72 69 6e 67 5f 74 6f  def) ? String_to
0e60: 5f 48 65 78 28 73 69 67 2d 3e 64 61 74 61 2c 20  _Hex(sig->data, 
0e70: 73 69 67 2d 3e 6c 65 6e 67 74 68 2c 20 62 75 66  sig->length, buf
0e80: 66 65 72 2c 20 42 55 46 53 49 5a 29 20 3a 20 30  fer, BUFSIZ) : 0
0e90: 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69  ;..LAPPEND_STR(i
0ea0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
0eb0: 22 73 69 67 6e 61 74 75 72 65 56 61 6c 75 65 22  "signatureValue"
0ec0: 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a  , buffer, len);.
0ed0: 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 56 65      }..    /* Ve
0ee0: 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 65 6e 63  rsion of the enc
0ef0: 6f 64 65 64 20 63 65 72 74 69 66 69 63 61 74 65  oded certificate
0f00: 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74   - RFC 5280 sect
0f10: 69 6f 6e 20 34 2e 31 2e 32 2e 31 20 2a 2f 0a 20  ion 4.1.2.1 */. 
0f20: 20 20 20 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 28     LAPPEND_LONG(
0f30: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
0f40: 20 22 76 65 72 73 69 6f 6e 22 2c 20 58 35 30 39   "version", X509
0f50: 5f 67 65 74 5f 76 65 72 73 69 6f 6e 28 63 65 72  _get_version(cer
0f60: 74 29 2b 31 29 3b 0a 0a 20 20 20 20 2f 2a 20 55  t)+1);..    /* U
0f70: 6e 69 71 75 65 20 6e 75 6d 62 65 72 20 61 73 73  nique number ass
0f80: 69 67 6e 65 64 20 62 79 20 43 41 20 74 6f 20 63  igned by CA to c
0f90: 65 72 74 69 66 69 63 61 74 65 20 2d 20 52 46 43  ertificate - RFC
0fa0: 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e   5280 section 4.
0fb0: 31 2e 32 2e 32 20 2a 2f 0a 20 20 20 20 6c 65 6e  1.2.2 */.    len
0fc0: 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72   = BIO_to_Buffer
0fd0: 28 69 32 61 5f 41 53 4e 31 5f 49 4e 54 45 47 45  (i2a_ASN1_INTEGE
0fe0: 52 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 30  R(bio, X509_get0
0ff0: 5f 73 65 72 69 61 6c 4e 75 6d 62 65 72 28 63 65  _serialNumber(ce
1000: 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66 66 65  rt)), bio, buffe
1010: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 20  r, BUFSIZ);.    
1020: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
1030: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65  rp, certPtr, "se
1040: 72 69 61 6c 4e 75 6d 62 65 72 22 2c 20 62 75 66  rialNumber", buf
1050: 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20  fer, len);..    
1060: 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61 6c 67  /* Signature alg
1070: 6f 72 69 74 68 6d 20 75 73 65 64 20 62 79 20 74  orithm used by t
1080: 68 65 20 43 41 20 74 6f 20 73 69 67 6e 20 74 68  he CA to sign th
1090: 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 4d  e certificate. M
10a0: 75 73 74 20 6d 61 74 63 68 0a 09 73 69 67 6e 61  ust match..signa
10b0: 74 75 72 65 41 6c 67 6f 72 69 74 68 6d 2e 20 52  tureAlgorithm. R
10c0: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
10d0: 34 2e 31 2e 32 2e 33 20 2a 2f 0a 20 20 20 20 4c  4.1.2.3 */.    L
10e0: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
10f0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 67  p, certPtr, "sig
1100: 6e 61 74 75 72 65 22 2c 20 4f 42 4a 5f 6e 69 64  nature", OBJ_nid
1110: 32 6c 6e 28 58 35 30 39 5f 67 65 74 5f 73 69 67  2ln(X509_get_sig
1120: 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 72 74 29  nature_nid(cert)
1130: 29 2c 20 2d 31 29 3b 0a 0a 20 20 20 20 2f 2a 20  ), -1);..    /* 
1140: 49 73 73 75 65 72 20 69 64 65 6e 74 69 66 69 65  Issuer identifie
1150: 73 20 74 68 65 20 65 6e 74 69 74 79 20 74 68 61  s the entity tha
1160: 74 20 73 69 67 6e 65 64 20 61 6e 64 20 69 73 73  t signed and iss
1170: 75 65 64 20 74 68 65 20 63 65 72 74 2e 20 52 46  ued the cert. RF
1180: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34  C 5280 section 4
1190: 2e 31 2e 32 2e 34 20 2a 2f 0a 20 20 20 20 6c 65  .1.2.4 */.    le
11a0: 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65  n = BIO_to_Buffe
11b0: 72 28 58 35 30 39 5f 4e 41 4d 45 5f 70 72 69 6e  r(X509_NAME_prin
11c0: 74 5f 65 78 28 62 69 6f 2c 20 58 35 30 39 5f 67  t_ex(bio, X509_g
11d0: 65 74 5f 69 73 73 75 65 72 5f 6e 61 6d 65 28 63  et_issuer_name(c
11e0: 65 72 74 29 2c 20 30 2c 20 66 6c 61 67 73 29 2c  ert), 0, flags),
11f0: 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 55   bio, buffer, BU
1200: 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 45  FSIZ);.    LAPPE
1210: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
1220: 65 72 74 50 74 72 2c 20 22 69 73 73 75 65 72 22  ertPtr, "issuer"
1230: 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a  , buffer, len);.
1240: 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69 63  .    /* Certific
1250: 61 74 65 20 76 61 6c 69 64 69 74 79 20 70 65 72  ate validity per
1260: 69 6f 64 20 69 73 20 74 68 65 20 69 6e 74 65 72  iod is the inter
1270: 76 61 6c 20 74 68 65 20 43 41 20 77 61 72 72 61  val the CA warra
1280: 6e 74 73 20 74 68 61 74 20 69 74 20 77 69 6c 6c  nts that it will
1290: 0a 09 6d 61 69 6e 74 61 69 6e 20 69 6e 66 6f 20  ..maintain info 
12a0: 6f 6e 20 74 68 65 20 73 74 61 74 75 73 20 6f 66  on the status of
12b0: 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65   the certificate
12c0: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69  . RFC 5280 secti
12d0: 6f 6e 20 34 2e 31 2e 32 2e 35 20 2a 2f 0a 20 20  on 4.1.2.5 */.  
12e0: 20 20 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 74    /* Get Validit
12f0: 79 20 2d 20 4e 6f 74 20 42 65 66 6f 72 65 20 2a  y - Not Before *
1300: 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f  /.    len = BIO_
1310: 74 6f 5f 42 75 66 66 65 72 28 41 53 4e 31 5f 54  to_Buffer(ASN1_T
1320: 49 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58  IME_print(bio, X
1330: 35 30 39 5f 67 65 74 30 5f 6e 6f 74 42 65 66 6f  509_get0_notBefo
1340: 72 65 28 63 65 72 74 29 29 2c 20 62 69 6f 2c 20  re(cert)), bio, 
1350: 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b  buffer, BUFSIZ);
1360: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52  .    LAPPEND_STR
1370: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
1380: 2c 20 22 6e 6f 74 42 65 66 6f 72 65 22 2c 20 62  , "notBefore", b
1390: 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20  uffer, len);..  
13a0: 20 20 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 74    /* Get Validit
13b0: 79 20 2d 20 4e 6f 74 20 41 66 74 65 72 20 2a 2f  y - Not After */
13c0: 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f 74  .    len = BIO_t
13d0: 6f 5f 42 75 66 66 65 72 28 41 53 4e 31 5f 54 49  o_Buffer(ASN1_TI
13e0: 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 35  ME_print(bio, X5
13f0: 30 39 5f 67 65 74 30 5f 6e 6f 74 41 66 74 65 72  09_get0_notAfter
1400: 28 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75  (cert)), bio, bu
1410: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20  ffer, BUFSIZ);. 
1420: 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69     LAPPEND_STR(i
1430: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
1440: 22 6e 6f 74 41 66 74 65 72 22 2c 20 62 75 66 66  "notAfter", buff
1450: 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f  er, len);..    /
1460: 2a 20 53 75 62 6a 65 63 74 20 69 64 65 6e 74 69  * Subject identi
1470: 66 69 65 73 20 74 68 65 20 65 6e 74 69 74 79 20  fies the entity 
1480: 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 20  associated with 
1490: 74 68 65 20 70 75 62 6c 69 63 20 6b 65 79 20 73  the public key s
14a0: 74 6f 72 65 64 20 69 6e 0a 09 74 68 65 20 73 75  tored in..the su
14b0: 62 6a 65 63 74 20 70 75 62 6c 69 63 20 6b 65 79  bject public key
14c0: 20 66 69 65 6c 64 2e 20 52 46 43 20 35 32 38 30   field. RFC 5280
14d0: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 36   section 4.1.2.6
14e0: 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49   */.    len = BI
14f0: 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39  O_to_Buffer(X509
1500: 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f 65 78 28 62  _NAME_print_ex(b
1510: 69 6f 2c 20 58 35 30 39 5f 67 65 74 5f 73 75 62  io, X509_get_sub
1520: 6a 65 63 74 5f 6e 61 6d 65 28 63 65 72 74 29 2c  ject_name(cert),
1530: 20 30 2c 20 66 6c 61 67 73 29 2c 20 62 69 6f 2c   0, flags), bio,
1540: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29   buffer, BUFSIZ)
1550: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54  ;.    LAPPEND_ST
1560: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  R(interp, certPt
1570: 72 2c 20 22 73 75 62 6a 65 63 74 22 2c 20 62 75  r, "subject", bu
1580: 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20  ffer, len);..   
1590: 20 2f 2a 20 53 48 41 31 20 46 69 6e 67 65 72 70   /* SHA1 Fingerp
15a0: 72 69 6e 74 20 6f 66 20 63 65 72 74 20 2d 20 44  rint of cert - D
15b0: 45 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f  ER representatio
15c0: 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30  n */.    if (X50
15d0: 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45  9_digest(cert, E
15e0: 56 50 5f 73 68 61 31 28 29 2c 20 6d 64 2c 20 26  VP_sha1(), md, &
15f0: 6c 65 6e 29 29 20 7b 0a 20 20 20 20 6c 65 6e 20  len)) {.    len 
1600: 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28  = String_to_Hex(
1610: 6d 64 2c 20 6c 65 6e 2c 20 62 75 66 66 65 72 2c  md, len, buffer,
1620: 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50 45   BUFSIZ);..LAPPE
1630: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63  ND_STR(interp, c
1640: 65 72 74 50 74 72 2c 20 22 73 68 61 31 5f 68 61  ertPtr, "sha1_ha
1650: 73 68 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e  sh", buffer, len
1660: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a  );.    }..    /*
1670: 20 53 48 41 32 35 36 20 46 69 6e 67 65 72 70 72   SHA256 Fingerpr
1680: 69 6e 74 20 6f 66 20 63 65 72 74 20 2d 20 44 45  int of cert - DE
1690: 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f 6e  R representation
16a0: 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30 39   */.    if (X509
16b0: 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45 56  _digest(cert, EV
16c0: 50 5f 73 68 61 32 35 36 28 29 2c 20 6d 64 2c 20  P_sha256(), md, 
16d0: 26 6c 65 6e 29 29 20 7b 0a 20 20 20 20 6c 65 6e  &len)) {.    len
16e0: 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78   = String_to_Hex
16f0: 28 6d 64 2c 20 6c 65 6e 2c 20 62 75 66 66 65 72  (md, len, buffer
1700: 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50  , BUFSIZ);..LAPP
1710: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20  END_STR(interp, 
1720: 63 65 72 74 50 74 72 2c 20 22 73 68 61 32 35 36  certPtr, "sha256
1730: 5f 68 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20  _hash", buffer, 
1740: 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20  len);.    }..   
1750: 20 2f 2a 20 53 75 62 6a 65 63 74 20 50 75 62 6c   /* Subject Publ
1760: 69 63 20 4b 65 79 20 49 6e 66 6f 20 73 70 65 63  ic Key Info spec
1770: 69 66 69 65 73 20 74 68 65 20 70 75 62 6c 69 63  ifies the public
1780: 20 6b 65 79 20 61 6e 64 20 69 64 65 6e 74 69 66   key and identif
1790: 69 65 73 20 74 68 65 0a 09 61 6c 67 6f 72 69 74  ies the..algorit
17a0: 68 6d 20 77 69 74 68 20 77 68 69 63 68 20 74 68  hm with which th
17b0: 65 20 6b 65 79 20 69 73 20 75 73 65 64 2e 20 52  e key is used. R
17c0: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20  FC 5280 section 
17d0: 34 2e 31 2e 32 2e 37 20 2a 2f 0a 20 20 20 20 69  4.1.2.7 */.    i
17e0: 66 20 28 58 35 30 39 5f 67 65 74 5f 73 69 67 6e  f (X509_get_sign
17f0: 61 74 75 72 65 5f 69 6e 66 6f 28 63 65 72 74 2c  ature_info(cert,
1800: 20 26 6d 64 6e 69 64 2c 20 26 70 6b 6e 69 64 2c   &mdnid, &pknid,
1810: 20 26 62 69 74 73 2c 20 26 78 66 6c 61 67 73 29   &bits, &xflags)
1820: 29 20 7b 0a 09 41 53 4e 31 5f 42 49 54 5f 53 54  ) {..ASN1_BIT_ST
1830: 52 49 4e 47 20 2a 6b 65 79 3b 0a 09 75 6e 73 69  RING *key;..unsi
1840: 67 6e 65 64 20 69 6e 74 20 6e 3b 0a 0a 09 4c 41  gned int n;...LA
1850: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70  PPEND_STR(interp
1860: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 67 6e  , certPtr, "sign
1870: 69 6e 67 44 69 67 65 73 74 22 2c 20 4f 42 4a 5f  ingDigest", OBJ_
1880: 6e 69 64 32 6c 6e 28 6d 64 6e 69 64 29 2c 20 2d  nid2ln(mdnid), -
1890: 31 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52  1);..LAPPEND_STR
18a0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
18b0: 2c 20 22 70 75 62 6c 69 63 4b 65 79 41 6c 67 6f  , "publicKeyAlgo
18c0: 72 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e 69 64 32  rithm", OBJ_nid2
18d0: 6c 6e 28 70 6b 6e 69 64 29 2c 20 2d 31 29 3b 0a  ln(pknid), -1);.
18e0: 09 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e 74  .LAPPEND_INT(int
18f0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 62  erp, certPtr, "b
1900: 69 74 73 22 2c 20 62 69 74 73 29 3b 20 2f 2a 20  its", bits); /* 
1910: 45 66 66 65 63 74 69 76 65 20 73 65 63 75 72 69  Effective securi
1920: 74 79 20 62 69 74 73 20 2a 2f 0a 0a 09 6b 65 79  ty bits */...key
1930: 20 3d 20 58 35 30 39 5f 67 65 74 30 5f 70 75 62   = X509_get0_pub
1940: 6b 65 79 5f 62 69 74 73 74 72 28 63 65 72 74 29  key_bitstr(cert)
1950: 3b 0a 09 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f  ;..len = String_
1960: 74 6f 5f 48 65 78 28 6b 65 79 2d 3e 64 61 74 61  to_Hex(key->data
1970: 2c 20 6b 65 79 2d 3e 6c 65 6e 67 74 68 2c 20 62  , key->length, b
1980: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a  uffer, BUFSIZ);.
1990: 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74  .LAPPEND_STR(int
19a0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70  erp, certPtr, "p
19b0: 75 62 6c 69 63 4b 65 79 22 2c 20 62 75 66 66 65  ublicKey", buffe
19c0: 72 2c 20 6c 65 6e 29 3b 0a 0a 09 6c 65 6e 20 3d  r, len);...len =
19d0: 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f 70 75   0;..if (X509_pu
19e0: 62 6b 65 79 5f 64 69 67 65 73 74 28 63 65 72 74  bkey_digest(cert
19f0: 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65 73 74  , EVP_get_digest
1a00: 62 79 6e 69 64 28 70 6b 6e 69 64 29 2c 20 6d 64  bynid(pknid), md
1a10: 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20 6c 65  , &n)) {..    le
1a20: 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65  n = String_to_He
1a30: 78 28 6d 64 2c 20 28 69 6e 74 29 6e 2c 20 62 75  x(md, (int)n, bu
1a40: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09  ffer, BUFSIZ);..
1a50: 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69  }..LAPPEND_STR(i
1a60: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
1a70: 22 70 75 62 6c 69 63 4b 65 79 48 61 73 68 22 2c  "publicKeyHash",
1a80: 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a   buffer, len);..
1a90: 09 6c 65 6e 20 3d 20 30 3b 0a 09 69 66 20 28 58  .len = 0;..if (X
1aa0: 35 30 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c  509_digest(cert,
1ab0: 20 45 56 50 5f 67 65 74 5f 64 69 67 65 73 74 62   EVP_get_digestb
1ac0: 79 6e 69 64 28 6d 64 6e 69 64 29 2c 20 6d 64 2c  ynid(mdnid), md,
1ad0: 20 26 6e 29 29 20 7b 0a 09 20 20 20 20 6c 65 6e   &n)) {..    len
1ae0: 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78   = String_to_Hex
1af0: 28 6d 64 2c 20 28 69 6e 74 29 6e 2c 20 62 75 66  (md, (int)n, buf
1b00: 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 7d  fer, BUFSIZ);..}
1b10: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e  ..LAPPEND_STR(in
1b20: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
1b30: 73 69 67 6e 61 74 75 72 65 48 61 73 68 22 2c 20  signatureHash", 
1b40: 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 20 20  buffer, len);.  
1b50: 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 47 65 74 20    }..    /* Get 
1b60: 65 78 74 65 6e 73 69 6f 6e 73 20 66 6c 61 67 73  extensions flags
1b70: 20 2a 2f 0a 20 20 20 20 78 66 6c 61 67 73 20 3d   */.    xflags =
1b80: 20 58 35 30 39 5f 67 65 74 5f 65 78 74 65 6e 73   X509_get_extens
1b90: 69 6f 6e 5f 66 6c 61 67 73 28 63 65 72 74 29 3b  ion_flags(cert);
1ba0: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 49 4e 54  .    LAPPEND_INT
1bb0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72  (interp, certPtr
1bc0: 2c 20 22 65 78 74 46 6c 61 67 73 22 2c 20 78 66  , "extFlags", xf
1bd0: 6c 61 67 73 29 3b 0a 0a 09 2f 2a 20 43 68 65 63  lags);.../* Chec
1be0: 6b 20 69 66 20 63 65 72 74 20 77 61 73 20 69 73  k if cert was is
1bf0: 73 75 65 64 20 62 79 20 43 41 20 63 65 72 74 20  sued by CA cert 
1c00: 69 73 73 75 65 72 20 6f 72 20 73 65 6c 66 20 73  issuer or self s
1c10: 69 67 6e 65 64 20 2a 2f 0a 20 20 20 20 4c 41 50  igned */.    LAP
1c20: 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70  PEND_BOOL(interp
1c30: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65 6c 66  , certPtr, "self
1c40: 49 73 73 75 65 64 22 2c 20 78 66 6c 61 67 73 20  Issued", xflags 
1c50: 26 20 45 58 46 4c 41 47 5f 53 49 29 3b 0a 20 20  & EXFLAG_SI);.  
1c60: 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69    LAPPEND_BOOL(i
1c70: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
1c80: 22 73 65 6c 66 53 69 67 6e 65 64 22 2c 20 78 66  "selfSigned", xf
1c90: 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 53 53  lags & EXFLAG_SS
1ca0: 29 3b 0a 0a 20 20 20 20 2f 2a 20 54 68 65 20 55  );..    /* The U
1cb0: 6e 69 71 75 65 20 49 64 73 20 61 72 65 20 75 73  nique Ids are us
1cc0: 65 64 20 74 6f 20 68 61 6e 64 6c 65 20 74 68 65  ed to handle the
1cd0: 20 70 6f 73 73 69 62 69 6c 69 74 79 20 6f 66 20   possibility of 
1ce0: 72 65 75 73 65 20 6f 66 20 73 75 62 6a 65 63 74  reuse of subject
1cf0: 0a 09 61 6e 64 2f 6f 72 20 69 73 73 75 65 72 20  ..and/or issuer 
1d00: 6e 61 6d 65 73 20 6f 76 65 72 20 74 69 6d 65 2e  names over time.
1d10: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
1d20: 6e 20 34 2e 31 2e 32 2e 38 20 2a 2f 0a 20 20 20  n 4.1.2.8 */.   
1d30: 20 7b 0a 09 63 6f 6e 73 74 20 41 53 4e 31 5f 42   {..const ASN1_B
1d40: 49 54 5f 53 54 52 49 4e 47 20 2a 69 75 69 64 2c  IT_STRING *iuid,
1d50: 20 2a 73 75 69 64 3b 0a 20 20 20 20 20 20 20 20   *suid;.        
1d60: 58 35 30 39 5f 67 65 74 30 5f 75 69 64 73 28 63  X509_get0_uids(c
1d70: 65 72 74 2c 20 26 69 75 69 64 2c 20 26 73 75 69  ert, &iuid, &sui
1d80: 64 29 3b 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f 62  d);...Tcl_ListOb
1d90: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69  jAppendElement(i
1da0: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20  nterp, certPtr, 
1db0: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a  Tcl_NewStringObj
1dc0: 28 22 69 73 73 75 65 72 55 6e 69 71 75 65 49 64  ("issuerUniqueId
1dd0: 22 2c 20 2d 31 29 29 3b 0a 09 69 66 20 28 69 75  ", -1));..if (iu
1de0: 69 64 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20  id != NULL) {.. 
1df0: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70     Tcl_ListObjAp
1e00: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
1e10: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 6c  rp, certPtr, Tcl
1e20: 5f 4e 65 77 42 79 74 65 41 72 72 61 79 4f 62 6a  _NewByteArrayObj
1e30: 28 28 63 68 61 72 20 2a 29 69 75 69 64 2d 3e 64  ((char *)iuid->d
1e40: 61 74 61 2c 20 69 75 69 64 2d 3e 6c 65 6e 67 74  ata, iuid->lengt
1e50: 68 29 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a 09  h));..} else {..
1e60: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
1e70: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
1e80: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63  erp, certPtr, Tc
1e90: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
1ea0: 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 0a 09 54 63  ", -1));..}...Tc
1eb0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
1ec0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63  lement(interp, c
1ed0: 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  ertPtr, Tcl_NewS
1ee0: 74 72 69 6e 67 4f 62 6a 28 22 73 75 62 6a 65 63  tringObj("subjec
1ef0: 74 55 6e 69 71 75 65 49 64 22 2c 20 2d 31 29 29  tUniqueId", -1))
1f00: 3b 0a 09 69 66 20 28 73 75 69 64 20 21 3d 20 4e  ;..if (suid != N
1f10: 55 4c 4c 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f  ULL) {..    Tcl_
1f20: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
1f30: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 72  ment(interp, cer
1f40: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 42 79 74  tPtr, Tcl_NewByt
1f50: 65 41 72 72 61 79 4f 62 6a 28 28 63 68 61 72 20  eArrayObj((char 
1f60: 2a 29 73 75 69 64 2d 3e 64 61 74 61 2c 20 73 75  *)suid->data, su
1f70: 69 64 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 7d  id->length));..}
1f80: 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 6c   else {..    Tcl
1f90: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
1fa0: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65  ement(interp, ce
1fb0: 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  rtPtr, Tcl_NewSt
1fc0: 72 69 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 29  ringObj("", -1))
1fd0: 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 20  ;..}.    }..    
1fe0: 2f 2a 20 58 35 30 39 20 76 33 20 45 78 74 65 6e  /* X509 v3 Exten
1ff0: 73 69 6f 6e 73 20 2d 20 52 46 43 20 35 32 38 30  sions - RFC 5280
2000: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 39   section 4.1.2.9
2010: 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 58 35   */.    len = X5
2020: 30 39 5f 67 65 74 5f 65 78 74 5f 63 6f 75 6e 74  09_get_ext_count
2030: 28 63 65 72 74 29 3b 0a 20 20 20 20 6c 69 73 74  (cert);.    list
2040: 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73  Ptr = Tcl_NewLis
2050: 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20  tObj(0, NULL);. 
2060: 20 20 20 69 66 20 28 6c 65 6e 20 3e 20 30 29 20     if (len > 0) 
2070: 7b 0a 09 63 6f 6e 73 74 20 53 54 41 43 4b 5f 4f  {..const STACK_O
2080: 46 28 58 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e  F(X509_EXTENSION
2090: 29 20 2a 65 78 74 73 20 3d 20 58 35 30 39 5f 67  ) *exts = X509_g
20a0: 65 74 30 5f 65 78 74 65 6e 73 69 6f 6e 73 28 63  et0_extensions(c
20b0: 65 72 74 29 3b 0a 0a 09 66 6f 72 20 28 69 6e 74  ert);...for (int
20c0: 20 69 3d 30 3b 20 69 20 3c 20 6c 65 6e 3b 20 69   i=0; i < len; i
20d0: 2b 2b 29 20 7b 0a 09 20 20 20 20 58 35 30 39 5f  ++) {..    X509_
20e0: 45 58 54 45 4e 53 49 4f 4e 20 2a 65 78 20 3d 20  EXTENSION *ex = 
20f0: 73 6b 5f 58 35 30 39 5f 45 58 54 45 4e 53 49 4f  sk_X509_EXTENSIO
2100: 4e 5f 76 61 6c 75 65 28 65 78 74 73 2c 20 69 29  N_value(exts, i)
2110: 3b 0a 09 20 20 20 20 41 53 4e 31 5f 4f 42 4a 45  ;..    ASN1_OBJE
2120: 43 54 20 2a 6f 62 6a 20 3d 20 58 35 30 39 5f 45  CT *obj = X509_E
2130: 58 54 45 4e 53 49 4f 4e 5f 67 65 74 5f 6f 62 6a  XTENSION_get_obj
2140: 65 63 74 28 65 78 29 3b 0a 0a 09 20 20 20 20 54  ect(ex);...    T
2150: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64  cl_ListObjAppend
2160: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20  Element(interp, 
2170: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77  listPtr, Tcl_New
2180: 53 74 72 69 6e 67 4f 62 6a 28 4f 42 4a 5f 6e 69  StringObj(OBJ_ni
2190: 64 32 6c 6e 28 4f 42 4a 5f 6f 62 6a 32 6e 69 64  d2ln(OBJ_obj2nid
21a0: 28 6f 62 6a 29 29 2c 20 2d 31 29 29 3b 0a 09 7d  (obj)), -1));..}
21b0: 0a 20 20 20 20 7d 0a 20 20 20 20 4c 41 50 50 45  .    }.    LAPPE
21c0: 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20 63  ND_INT(interp, c
21d0: 65 72 74 50 74 72 2c 20 22 65 78 74 43 6f 75 6e  ertPtr, "extCoun
21e0: 74 22 2c 20 6c 65 6e 29 3b 0a 20 20 20 20 4c 41  t", len);.    LA
21f0: 50 50 45 4e 44 5f 4c 49 53 54 28 69 6e 74 65 72  PPEND_LIST(inter
2200: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 74  p, certPtr, "ext
2210: 65 6e 73 69 6f 6e 73 22 2c 20 6c 69 73 74 50 74  ensions", listPt
2220: 72 29 3b 0a 0a 20 20 20 20 2f 2a 20 41 75 74 68  r);..    /* Auth
2230: 6f 72 69 74 79 20 4b 65 79 20 49 64 65 6e 74 69  ority Key Identi
2240: 66 69 65 72 20 28 41 4b 49 29 20 69 73 20 74 68  fier (AKI) is th
2250: 65 20 53 75 62 6a 65 63 74 20 4b 65 79 20 49 64  e Subject Key Id
2260: 65 6e 74 69 66 69 65 72 20 28 53 4b 49 29 20 6f  entifier (SKI) o
2270: 66 0a 09 69 74 73 20 73 69 67 6e 65 72 20 28 74  f..its signer (t
2280: 68 65 20 43 41 29 2e 20 52 46 43 20 35 32 38 30  he CA). RFC 5280
2290: 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31   section 4.2.1.1
22a0: 2c 20 4e 49 44 5f 61 75 74 68 6f 72 69 74 79 5f  , NID_authority_
22b0: 6b 65 79 5f 69 64 65 6e 74 69 66 69 65 72 20 2a  key_identifier *
22c0: 2f 0a 20 20 20 20 7b 0a 09 41 53 4e 31 5f 4f 43  /.    {..ASN1_OC
22d0: 54 45 54 5f 53 54 52 49 4e 47 20 2a 61 73 74 72  TET_STRING *astr
22e0: 69 6e 67 20 3d 20 58 35 30 39 5f 67 65 74 30 5f  ing = X509_get0_
22f0: 61 75 74 68 6f 72 69 74 79 5f 6b 65 79 5f 69 64  authority_key_id
2300: 28 63 65 72 74 29 3b 0a 09 6c 65 6e 20 3d 20 30  (cert);..len = 0
2310: 3b 0a 09 69 66 20 28 61 73 74 72 69 6e 67 20 21  ;..if (astring !
2320: 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 6c  = NULL) {..    l
2330: 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48  en = String_to_H
2340: 65 78 28 28 63 68 61 72 20 2a 29 41 53 4e 31 5f  ex((char *)ASN1_
2350: 53 54 52 49 4e 47 5f 67 65 74 30 5f 64 61 74 61  STRING_get0_data
2360: 28 61 73 74 72 69 6e 67 29 2c 0a 09 09 41 53 4e  (astring),...ASN
2370: 31 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28  1_STRING_length(
2380: 61 73 74 72 69 6e 67 29 2c 20 62 75 66 66 65 72  astring), buffer
2390: 2c 20 42 55 46 53 49 5a 29 3b 0a 09 7d 0a 09 4c  , BUFSIZ);..}..L
23a0: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
23b0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 61 75 74  p, certPtr, "aut
23c0: 68 6f 72 69 74 79 4b 65 79 49 64 65 6e 74 69 66  horityKeyIdentif
23d0: 69 65 72 22 2c 20 62 75 66 66 65 72 2c 20 6c 65  ier", buffer, le
23e0: 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f  n);.    }..    /
23f0: 2a 20 53 75 62 6a 65 63 74 20 4b 65 79 20 49 64  * Subject Key Id
2400: 65 6e 74 69 66 69 65 72 20 28 53 4b 49 29 20 69  entifier (SKI) i
2410: 73 20 75 73 65 64 20 74 6f 20 64 65 6e 74 69 66  s used to dentif
2420: 79 20 63 65 72 74 69 66 69 63 61 74 65 73 20 74  y certificates t
2430: 68 61 74 20 63 6f 6e 74 61 69 6e 0a 09 61 20 70  hat contain..a p
2440: 61 72 74 69 63 75 6c 61 72 20 70 75 62 6c 69 63  articular public
2450: 20 6b 65 79 2e 20 52 46 43 20 35 32 38 30 20 73   key. RFC 5280 s
2460: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 32 2c 20  ection 4.2.1.2, 
2470: 4e 49 44 5f 73 75 62 6a 65 63 74 5f 6b 65 79 5f  NID_subject_key_
2480: 69 64 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20  identifier */.  
2490: 20 20 7b 0a 09 41 53 4e 31 5f 4f 43 54 45 54 5f    {..ASN1_OCTET_
24a0: 53 54 52 49 4e 47 20 2a 61 73 74 72 69 6e 67 20  STRING *astring 
24b0: 3d 20 58 35 30 39 5f 67 65 74 30 5f 73 75 62 6a  = X509_get0_subj
24c0: 65 63 74 5f 6b 65 79 5f 69 64 28 63 65 72 74 29  ect_key_id(cert)
24d0: 3b 0a 09 6c 65 6e 20 3d 20 30 3b 0a 09 69 66 20  ;..len = 0;..if 
24e0: 28 61 73 74 72 69 6e 67 20 21 3d 20 4e 55 4c 4c  (astring != NULL
24f0: 29 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d 20 53  ) {..    len = S
2500: 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 28 63 68  tring_to_Hex((ch
2510: 61 72 20 2a 29 41 53 4e 31 5f 53 54 52 49 4e 47  ar *)ASN1_STRING
2520: 5f 67 65 74 30 5f 64 61 74 61 28 61 73 74 72 69  _get0_data(astri
2530: 6e 67 29 2c 0a 09 09 41 53 4e 31 5f 53 54 52 49  ng),...ASN1_STRI
2540: 4e 47 5f 6c 65 6e 67 74 68 28 61 73 74 72 69 6e  NG_length(astrin
2550: 67 29 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53  g), buffer, BUFS
2560: 49 5a 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e 44  IZ);..}..LAPPEND
2570: 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72  _STR(interp, cer
2580: 74 50 74 72 2c 20 22 73 75 62 6a 65 63 74 4b 65  tPtr, "subjectKe
2590: 79 49 64 65 6e 74 69 66 69 65 72 22 2c 20 62 75  yIdentifier", bu
25a0: 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 20 20 20 20  ffer, len);.    
25b0: 7d 0a 0a 20 20 20 20 2f 2a 20 4b 65 79 20 75 73  }..    /* Key us
25c0: 61 67 65 20 65 78 74 65 6e 73 69 6f 6e 20 64 65  age extension de
25d0: 66 69 6e 65 73 20 74 68 65 20 70 75 72 70 6f 73  fines the purpos
25e0: 65 20 28 65 2e 67 2e 2c 20 65 6e 63 69 70 68 65  e (e.g., enciphe
25f0: 72 6d 65 6e 74 2c 20 73 69 67 6e 61 74 75 72 65  rment, signature
2600: 2c 20 63 65 72 74 69 66 69 63 61 74 65 0a 09 73  , certificate..s
2610: 69 67 6e 69 6e 67 29 20 6f 66 20 74 68 65 20 6b  igning) of the k
2620: 65 79 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e 20  ey contained in 
2630: 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e  the certificate.
2640: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
2650: 6e 20 34 2e 32 2e 31 2e 33 2c 20 4e 49 44 5f 6b  n 4.2.1.3, NID_k
2660: 65 79 5f 75 73 61 67 65 20 2a 2f 0a 20 20 20 20  ey_usage */.    
2670: 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65  listPtr = Tcl_Ne
2680: 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c  wListObj(0, NULL
2690: 29 3b 0a 20 20 20 20 75 73 61 67 65 20 3d 20 58  );.    usage = X
26a0: 35 30 39 5f 67 65 74 5f 6b 65 79 5f 75 73 61 67  509_get_key_usag
26b0: 65 28 63 65 72 74 29 3b 0a 20 20 20 20 69 66 20  e(cert);.    if 
26c0: 28 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41  ((xflags & EXFLA
26d0: 47 5f 4b 55 53 41 47 45 29 20 26 26 20 75 73 61  G_KUSAGE) && usa
26e0: 67 65 20 3c 20 30 78 66 66 66 66 66 66 29 20 7b  ge < 0xffffff) {
26f0: 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 4b 55  ..if (usage & KU
2700: 5f 44 49 47 49 54 41 4c 5f 53 49 47 4e 41 54 55  _DIGITAL_SIGNATU
2710: 52 45 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  RE) {..    Tcl_L
2720: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
2730: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74  ent(interp, list
2740: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
2750: 6e 67 4f 62 6a 28 22 44 69 67 69 74 61 6c 20 53  ngObj("Digital S
2760: 69 67 6e 61 74 75 72 65 22 2c 20 2d 31 29 29 3b  ignature", -1));
2770: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26  ..}..if (usage &
2780: 20 4b 55 5f 4e 4f 4e 5f 52 45 50 55 44 49 41 54   KU_NON_REPUDIAT
2790: 49 4f 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f  ION) {..    Tcl_
27a0: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
27b0: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73  ment(interp, lis
27c0: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
27d0: 69 6e 67 4f 62 6a 28 22 4e 6f 6e 2d 52 65 70 75  ingObj("Non-Repu
27e0: 64 69 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a  diation", -1));.
27f0: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20  .}..if (usage & 
2800: 4b 55 5f 4b 45 59 5f 45 4e 43 49 50 48 45 52 4d  KU_KEY_ENCIPHERM
2810: 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f  ENT) {..    Tcl_
2820: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65  ListObjAppendEle
2830: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73  ment(interp, lis
2840: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  tPtr, Tcl_NewStr
2850: 69 6e 67 4f 62 6a 28 22 4b 65 79 20 45 6e 63 69  ingObj("Key Enci
2860: 70 68 65 72 6d 65 6e 74 22 2c 20 2d 31 29 29 3b  pherment", -1));
2870: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26  ..}..if (usage &
2880: 20 4b 55 5f 44 41 54 41 5f 45 4e 43 49 50 48 45   KU_DATA_ENCIPHE
2890: 52 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63  RMENT) {..    Tc
28a0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
28b0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
28c0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
28d0: 74 72 69 6e 67 4f 62 6a 28 22 44 61 74 61 20 45  tringObj("Data E
28e0: 6e 63 69 70 68 65 72 6d 65 6e 74 22 2c 20 2d 31  ncipherment", -1
28f0: 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67  ));..}..if (usag
2900: 65 20 26 20 4b 55 5f 4b 45 59 5f 41 47 52 45 45  e & KU_KEY_AGREE
2910: 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 6c  MENT) {..    Tcl
2920: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
2930: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69  ement(interp, li
2940: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  stPtr, Tcl_NewSt
2950: 72 69 6e 67 4f 62 6a 28 22 4b 65 79 20 41 67 72  ringObj("Key Agr
2960: 65 65 6d 65 6e 74 22 2c 20 2d 31 29 29 3b 0a 09  eement", -1));..
2970: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 4b  }..if (usage & K
2980: 55 5f 4b 45 59 5f 43 45 52 54 5f 53 49 47 4e 29  U_KEY_CERT_SIGN)
2990: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
29a0: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
29b0: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
29c0: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
29d0: 62 6a 28 22 43 65 72 74 69 66 69 63 61 74 65 20  bj("Certificate 
29e0: 53 69 67 6e 69 6e 67 22 2c 20 2d 31 29 29 3b 0a  Signing", -1));.
29f0: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20  .}..if (usage & 
2a00: 4b 55 5f 43 52 4c 5f 53 49 47 4e 29 20 7b 0a 09  KU_CRL_SIGN) {..
2a10: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41      Tcl_ListObjA
2a20: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74  ppendElement(int
2a30: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63  erp, listPtr, Tc
2a40: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22  l_NewStringObj("
2a50: 43 52 4c 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31  CRL Signing", -1
2a60: 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67  ));..}..if (usag
2a70: 65 20 26 20 4b 55 5f 45 4e 43 49 50 48 45 52 5f  e & KU_ENCIPHER_
2a80: 4f 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 63 6c  ONLY) {..    Tcl
2a90: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
2aa0: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69  ement(interp, li
2ab0: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  stPtr, Tcl_NewSt
2ac0: 72 69 6e 67 4f 62 6a 28 22 45 6e 63 69 70 68 65  ringObj("Enciphe
2ad0: 72 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b 0a 09  r Only", -1));..
2ae0: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 4b  }..if (usage & K
2af0: 55 5f 44 45 43 49 50 48 45 52 5f 4f 4e 4c 59 29  U_DECIPHER_ONLY)
2b00: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
2b10: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
2b20: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
2b30: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
2b40: 62 6a 28 22 44 65 63 69 70 68 65 72 20 4f 6e 6c  bj("Decipher Onl
2b50: 79 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 20  y", -1));..}.   
2b60: 20 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c   }.    LAPPEND_L
2b70: 49 53 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74  IST(interp, cert
2b80: 50 74 72 2c 20 22 6b 65 79 55 73 61 67 65 22 2c  Ptr, "keyUsage",
2b90: 20 6c 69 73 74 50 74 72 29 3b 0a 0a 20 20 20 20   listPtr);..    
2ba0: 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65 20 50  /* Certificate P
2bb0: 75 72 70 6f 73 65 20 2a 2f 0a 20 20 20 20 7b 0a  urpose */.    {.
2bc0: 09 63 68 61 72 20 2a 70 75 72 70 6f 73 65 20 3d  .char *purpose =
2bd0: 20 4e 55 4c 4c 3b 0a 0a 09 69 66 20 28 58 35 30   NULL;...if (X50
2be0: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28  9_check_purpose(
2bf0: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f  cert, X509_PURPO
2c00: 53 45 5f 53 53 4c 5f 43 4c 49 45 4e 54 2c 20 30  SE_SSL_CLIENT, 0
2c10: 29 20 3e 20 30 29 20 7b 0a 09 20 20 20 20 70 75  ) > 0) {..    pu
2c20: 72 70 6f 73 65 20 3d 20 22 53 53 4c 20 43 6c 69  rpose = "SSL Cli
2c30: 65 6e 74 22 3b 0a 09 7d 20 65 6c 73 65 20 69 66  ent";..} else if
2c40: 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72   (X509_check_pur
2c50: 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f  pose(cert, X509_
2c60: 50 55 52 50 4f 53 45 5f 53 53 4c 5f 53 45 52 56  PURPOSE_SSL_SERV
2c70: 45 52 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 20  ER, 0) > 0) {.. 
2c80: 20 20 20 70 75 72 70 6f 73 65 20 3d 20 22 53 53     purpose = "SS
2c90: 4c 20 53 65 72 76 65 72 22 3b 0a 09 7d 20 65 6c  L Server";..} el
2ca0: 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63  se if (X509_chec
2cb0: 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20  k_purpose(cert, 
2cc0: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 4e 53 5f  X509_PURPOSE_NS_
2cd0: 53 53 4c 5f 53 45 52 56 45 52 2c 20 30 29 20 3e  SSL_SERVER, 0) >
2ce0: 20 30 29 20 7b 0a 09 20 20 20 20 70 75 72 70 6f   0) {..    purpo
2cf0: 73 65 20 3d 20 22 4d 53 53 20 53 53 4c 20 53 65  se = "MSS SSL Se
2d00: 72 76 65 72 22 3b 0a 09 7d 20 65 6c 73 65 20 69  rver";..} else i
2d10: 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75  f (X509_check_pu
2d20: 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39  rpose(cert, X509
2d30: 5f 50 55 52 50 4f 53 45 5f 53 4d 49 4d 45 5f 53  _PURPOSE_SMIME_S
2d40: 49 47 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09  IGN, 0) > 0) {..
2d50: 20 20 20 20 70 75 72 70 6f 73 65 20 3d 20 22 53      purpose = "S
2d60: 4d 49 4d 45 20 53 69 67 6e 69 6e 67 22 3b 0a 09  MIME Signing";..
2d70: 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 5f  } else if (X509_
2d80: 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65  check_purpose(ce
2d90: 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45  rt, X509_PURPOSE
2da0: 5f 53 4d 49 4d 45 5f 45 4e 43 52 59 50 54 2c 20  _SMIME_ENCRYPT, 
2db0: 30 29 20 3e 20 30 29 20 7b 0a 09 20 20 20 20 70  0) > 0) {..    p
2dc0: 75 72 70 6f 73 65 20 3d 20 22 53 4d 49 4d 45 20  urpose = "SMIME 
2dd0: 45 6e 63 72 79 70 74 69 6f 6e 22 3b 0a 09 7d 20  Encryption";..} 
2de0: 65 6c 73 65 20 69 66 20 28 58 35 30 39 5f 63 68  else if (X509_ch
2df0: 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74  eck_purpose(cert
2e00: 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 43  , X509_PURPOSE_C
2e10: 52 4c 5f 53 49 47 4e 2c 20 30 29 20 3e 20 30 29  RL_SIGN, 0) > 0)
2e20: 20 7b 0a 09 20 20 20 20 70 75 72 70 6f 73 65 20   {..    purpose 
2e30: 3d 20 22 43 52 4c 20 53 69 67 6e 69 6e 67 22 3b  = "CRL Signing";
2e40: 0a 09 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30  ..} else if (X50
2e50: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28  9_check_purpose(
2e60: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f  cert, X509_PURPO
2e70: 53 45 5f 41 4e 59 2c 20 30 29 20 3e 20 30 29 20  SE_ANY, 0) > 0) 
2e80: 7b 0a 09 20 20 20 20 70 75 72 70 6f 73 65 20 3d  {..    purpose =
2e90: 20 22 41 6e 79 22 3b 0a 09 7d 20 65 6c 73 65 20   "Any";..} else 
2ea0: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70  if (X509_check_p
2eb0: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30  urpose(cert, X50
2ec0: 39 5f 50 55 52 50 4f 53 45 5f 4f 43 53 50 5f 48  9_PURPOSE_OCSP_H
2ed0: 45 4c 50 45 52 2c 20 30 29 20 3e 20 30 29 20 7b  ELPER, 0) > 0) {
2ee0: 0a 09 20 20 20 20 70 75 72 70 6f 73 65 20 3d 20  ..    purpose = 
2ef0: 22 4f 43 53 50 20 48 65 6c 70 65 72 22 3b 0a 09  "OCSP Helper";..
2f00: 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 5f  } else if (X509_
2f10: 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65  check_purpose(ce
2f20: 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45  rt, X509_PURPOSE
2f30: 5f 54 49 4d 45 53 54 41 4d 50 5f 53 49 47 4e 2c  _TIMESTAMP_SIGN,
2f40: 20 30 29 20 3e 20 30 29 20 7b 0a 09 20 20 20 20   0) > 0) {..    
2f50: 70 75 72 70 6f 73 65 20 3d 20 22 54 69 6d 65 73  purpose = "Times
2f60: 74 61 6d 70 20 53 69 67 6e 69 6e 67 22 3b 0a 09  tamp Signing";..
2f70: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 70 75  } else {..    pu
2f80: 72 70 6f 73 65 20 3d 20 22 22 3b 0a 09 7d 0a 09  rpose = "";..}..
2f90: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
2fa0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 75  rp, certPtr, "pu
2fb0: 72 70 6f 73 65 22 2c 20 70 75 72 70 6f 73 65 2c  rpose", purpose,
2fc0: 20 2d 31 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20   -1);.    }..   
2fd0: 20 2f 2a 20 47 65 74 20 70 75 72 70 6f 73 65 73   /* Get purposes
2fe0: 20 2a 2f 0a 20 20 20 20 6c 69 73 74 50 74 72 20   */.    listPtr 
2ff0: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a  = Tcl_NewListObj
3000: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 09 66 6f 72 20  (0, NULL);..for 
3010: 28 69 6e 74 20 6a 20 3d 20 30 3b 20 6a 20 3c 20  (int j = 0; j < 
3020: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 74  X509_PURPOSE_get
3030: 5f 63 6f 75 6e 74 28 29 3b 20 6a 2b 2b 29 20 7b  _count(); j++) {
3040: 0a 09 20 20 20 20 58 35 30 39 5f 50 55 52 50 4f  ..    X509_PURPO
3050: 53 45 20 2a 70 74 6d 70 20 3d 20 58 35 30 39 5f  SE *ptmp = X509_
3060: 50 55 52 50 4f 53 45 5f 67 65 74 30 28 6a 29 3b  PURPOSE_get0(j);
3070: 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 74  ..    Tcl_Obj *t
3080: 6d 70 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c  mpPtr = Tcl_NewL
3090: 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b  istObj(0, NULL);
30a0: 0a 0a 09 20 20 20 20 66 6f 72 20 28 69 6e 74 20  ...    for (int 
30b0: 69 20 3d 20 30 3b 20 69 20 3c 20 32 3b 20 69 2b  i = 0; i < 2; i+
30c0: 2b 29 20 7b 0a 09 09 69 6e 74 20 69 64 72 65 74  +) {...int idret
30d0: 20 3d 20 58 35 30 39 5f 63 68 65 63 6b 5f 70 75   = X509_check_pu
30e0: 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39  rpose(cert, X509
30f0: 5f 50 55 52 50 4f 53 45 5f 67 65 74 5f 69 64 28  _PURPOSE_get_id(
3100: 70 74 6d 70 29 2c 20 69 29 3b 0a 09 09 54 63 6c  ptmp), i);...Tcl
3110: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
3120: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 74 6d  ement(interp, tm
3130: 70 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72  pPtr, Tcl_NewStr
3140: 69 6e 67 4f 62 6a 28 69 20 3f 20 22 43 41 22 20  ingObj(i ? "CA" 
3150: 3a 20 22 6e 6f 6e 43 41 22 2c 20 2d 31 29 29 3b  : "nonCA", -1));
3160: 0a 09 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70  ...Tcl_ListObjAp
3170: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65  pendElement(inte
3180: 72 70 2c 20 74 6d 70 50 74 72 2c 20 54 63 6c 5f  rp, tmpPtr, Tcl_
3190: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 69 64 72  NewStringObj(idr
31a0: 65 74 20 3d 3d 20 31 20 3f 20 22 59 65 73 22 20  et == 1 ? "Yes" 
31b0: 3a 20 22 4e 6f 22 2c 20 2d 31 29 29 3b 0a 09 20  : "No", -1));.. 
31c0: 20 20 20 7d 0a 09 4c 41 50 50 45 4e 44 5f 4c 49     }..LAPPEND_LI
31d0: 53 54 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50  ST(interp, listP
31e0: 74 72 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45  tr, X509_PURPOSE
31f0: 5f 67 65 74 30 5f 6e 61 6d 65 28 70 74 6d 70 29  _get0_name(ptmp)
3200: 2c 20 74 6d 70 50 74 72 29 3b 0a 20 20 20 20 7d  , tmpPtr);.    }
3210: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 49 53  .    LAPPEND_LIS
3220: 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  T(interp, certPt
3230: 72 2c 20 22 63 65 72 74 69 66 69 63 61 74 65 50  r, "certificateP
3240: 75 72 70 6f 73 65 22 2c 20 6c 69 73 74 50 74 72  urpose", listPtr
3250: 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69  );..    /* Certi
3260: 66 69 63 61 74 65 20 50 6f 6c 69 63 69 65 73 20  ficate Policies 
3270: 2d 20 69 6e 64 69 63 61 74 65 73 20 74 68 65 20  - indicates the 
3280: 69 73 73 75 69 6e 67 20 43 41 20 63 6f 6e 73 69  issuing CA consi
3290: 64 65 72 73 20 69 74 73 20 69 73 73 75 65 72 44  ders its issuerD
32a0: 6f 6d 61 69 6e 50 6f 6c 69 63 79 0a 09 65 71 75  omainPolicy..equ
32b0: 69 76 61 6c 65 6e 74 20 74 6f 20 74 68 65 20 73  ivalent to the s
32c0: 75 62 6a 65 63 74 20 43 41 27 73 20 73 75 62 6a  ubject CA's subj
32d0: 65 63 74 44 6f 6d 61 69 6e 50 6f 6c 69 63 79 2e  ectDomainPolicy.
32e0: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
32f0: 6e 20 34 2e 32 2e 31 2e 34 2c 20 4e 49 44 5f 63  n 4.2.1.4, NID_c
3300: 65 72 74 69 66 69 63 61 74 65 5f 70 6f 6c 69 63  ertificate_polic
3310: 69 65 73 20 2a 2f 0a 20 20 20 20 69 66 20 28 78  ies */.    if (x
3320: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 49  flags & EXFLAG_I
3330: 4e 56 41 4c 49 44 5f 50 4f 4c 49 43 59 29 20 7b  NVALID_POLICY) {
3340: 0a 09 2f 2a 20 52 65 6a 65 63 74 20 63 65 72 74  ../* Reject cert
3350: 20 2a 2f 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f   */.    }..    /
3360: 2a 20 50 6f 6c 69 63 79 20 4d 61 70 70 69 6e 67  * Policy Mapping
3370: 73 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63  s - RFC 5280 sec
3380: 74 69 6f 6e 20 34 2e 32 2e 31 2e 35 2c 20 4e 49  tion 4.2.1.5, NI
3390: 44 5f 70 6f 6c 69 63 79 5f 6d 61 70 70 69 6e 67  D_policy_mapping
33a0: 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 53 75 62  s */..    /* Sub
33b0: 6a 65 63 74 20 41 6c 74 65 72 6e 61 74 69 76 65  ject Alternative
33c0: 20 4e 61 6d 65 20 28 53 41 4e 29 20 63 6f 6e 74   Name (SAN) cont
33d0: 61 69 6e 73 20 61 64 64 69 74 69 6f 6e 61 6c 20  ains additional 
33e0: 55 52 4c 73 2c 20 44 4e 53 20 6e 61 6d 65 73 2c  URLs, DNS names,
33f0: 20 6f 72 20 49 50 0a 09 61 64 64 72 65 73 73 65   or IP..addresse
3400: 73 20 62 6f 75 6e 64 20 74 6f 20 63 65 72 74 69  s bound to certi
3410: 66 69 63 61 74 65 2e 20 52 46 43 20 35 32 38 30  ficate. RFC 5280
3420: 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 36   section 4.2.1.6
3430: 2c 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f 61 6c  , NID_subject_al
3440: 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 6c 69  t_name */.    li
3450: 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c  stPtr = Tcl_NewL
3460: 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b  istObj(0, NULL);
3470: 0a 20 20 20 20 69 66 20 28 6e 61 6d 65 73 20 3d  .    if (names =
3480: 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32   X509_get_ext_d2
3490: 69 28 63 65 72 74 2c 20 4e 49 44 5f 73 75 62 6a  i(cert, NID_subj
34a0: 65 63 74 5f 61 6c 74 5f 6e 61 6d 65 2c 20 4e 55  ect_alt_name, NU
34b0: 4c 4c 2c 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f  LL, NULL)) {..fo
34c0: 72 20 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20  r (int i=0; i < 
34d0: 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f  sk_GENERAL_NAME_
34e0: 6e 75 6d 28 6e 61 6d 65 73 29 3b 20 69 2b 2b 29  num(names); i++)
34f0: 20 7b 0a 09 20 20 20 20 63 6f 6e 73 74 20 47 45   {..    const GE
3500: 4e 45 52 41 4c 5f 4e 41 4d 45 20 2a 6e 61 6d 65  NERAL_NAME *name
3510: 20 3d 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41   = sk_GENERAL_NA
3520: 4d 45 5f 76 61 6c 75 65 28 6e 61 6d 65 73 2c 20  ME_value(names, 
3530: 69 29 3b 0a 0a 09 20 20 20 20 6c 65 6e 20 3d 20  i);...    len = 
3540: 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 6e 61  BIO_to_Buffer(na
3550: 6d 65 20 26 26 20 47 45 4e 45 52 41 4c 5f 4e 41  me && GENERAL_NA
3560: 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 6e 61  ME_print(bio, na
3570: 6d 65 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72  me), bio, buffer
3580: 2c 20 42 55 46 53 49 5a 29 3b 0a 09 20 20 20 20  , BUFSIZ);..    
3590: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
35a0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 4c  rp, listPtr, NUL
35b0: 4c 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b  L, buffer, len);
35c0: 0a 09 7d 0a 09 73 6b 5f 47 45 4e 45 52 41 4c 5f  ..}..sk_GENERAL_
35d0: 4e 41 4d 45 5f 70 6f 70 5f 66 72 65 65 28 6e 61  NAME_pop_free(na
35e0: 6d 65 73 2c 20 47 45 4e 45 52 41 4c 5f 4e 41 4d  mes, GENERAL_NAM
35f0: 45 5f 66 72 65 65 29 3b 0a 20 20 20 20 7d 0a 20  E_free);.    }. 
3600: 20 20 20 4c 41 50 50 45 4e 44 5f 4c 49 53 54 28     LAPPEND_LIST(
3610: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
3620: 20 22 73 75 62 6a 65 63 74 41 6c 74 4e 61 6d 65   "subjectAltName
3630: 22 2c 20 6c 69 73 74 50 74 72 29 3b 0a 0a 20 20  ", listPtr);..  
3640: 20 20 2f 2a 20 49 73 73 75 65 72 20 41 6c 74 65    /* Issuer Alte
3650: 72 6e 61 74 69 76 65 20 4e 61 6d 65 20 69 73 20  rnative Name is 
3660: 75 73 65 64 20 74 6f 20 61 73 73 6f 63 69 61 74  used to associat
3670: 65 20 49 6e 74 65 72 6e 65 74 20 73 74 79 6c 65  e Internet style
3680: 20 69 64 65 6e 74 69 74 69 65 73 0a 09 77 69 74   identities..wit
3690: 68 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74  h the certificat
36a0: 65 20 69 73 73 75 65 72 2e 20 52 46 43 20 35 32  e issuer. RFC 52
36b0: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31  80 section 4.2.1
36c0: 2e 37 2c 20 4e 49 44 5f 69 73 73 75 65 72 5f 61  .7, NID_issuer_a
36d0: 6c 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 6c  lt_name */.    l
36e0: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77  istPtr = Tcl_New
36f0: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29  ListObj(0, NULL)
3700: 3b 0a 20 20 20 20 69 66 20 28 6e 61 6d 65 73 20  ;.    if (names 
3710: 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64  = X509_get_ext_d
3720: 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 69 73 73  2i(cert, NID_iss
3730: 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 2c 20 4e 55  uer_alt_name, NU
3740: 4c 4c 2c 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f  LL, NULL)) {..fo
3750: 72 20 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20  r (int i=0; i < 
3760: 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f  sk_GENERAL_NAME_
3770: 6e 75 6d 28 6e 61 6d 65 73 29 3b 20 69 2b 2b 29  num(names); i++)
3780: 20 7b 0a 09 20 20 20 20 63 6f 6e 73 74 20 47 45   {..    const GE
3790: 4e 45 52 41 4c 5f 4e 41 4d 45 20 2a 6e 61 6d 65  NERAL_NAME *name
37a0: 20 3d 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41   = sk_GENERAL_NA
37b0: 4d 45 5f 76 61 6c 75 65 28 6e 61 6d 65 73 2c 20  ME_value(names, 
37c0: 69 29 3b 0a 0a 09 20 20 20 20 6c 65 6e 20 3d 20  i);...    len = 
37d0: 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 6e 61  BIO_to_Buffer(na
37e0: 6d 65 20 26 26 20 47 45 4e 45 52 41 4c 5f 4e 41  me && GENERAL_NA
37f0: 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 6e 61  ME_print(bio, na
3800: 6d 65 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72  me), bio, buffer
3810: 2c 20 42 55 46 53 49 5a 29 3b 0a 09 20 20 20 20  , BUFSIZ);..    
3820: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
3830: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 4c  rp, listPtr, NUL
3840: 4c 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b  L, buffer, len);
3850: 0a 09 7d 0a 09 73 6b 5f 47 45 4e 45 52 41 4c 5f  ..}..sk_GENERAL_
3860: 4e 41 4d 45 5f 70 6f 70 5f 66 72 65 65 28 6e 61  NAME_pop_free(na
3870: 6d 65 73 2c 20 47 45 4e 45 52 41 4c 5f 4e 41 4d  mes, GENERAL_NAM
3880: 45 5f 66 72 65 65 29 3b 0a 20 20 20 20 7d 0a 20  E_free);.    }. 
3890: 20 20 20 4c 41 50 50 45 4e 44 5f 4c 49 53 54 28     LAPPEND_LIST(
38a0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
38b0: 20 22 69 73 73 75 65 72 41 6c 74 4e 61 6d 65 22   "issuerAltName"
38c0: 2c 20 6c 69 73 74 50 74 72 29 3b 0a 0a 20 20 20  , listPtr);..   
38d0: 20 2f 2a 20 53 75 62 6a 65 63 74 20 44 69 72 65   /* Subject Dire
38e0: 63 74 6f 72 79 20 41 74 74 72 69 62 75 74 65 73  ctory Attributes
38f0: 20 70 72 6f 76 69 64 65 73 20 69 64 65 6e 74 69   provides identi
3900: 66 69 63 61 74 69 6f 6e 20 61 74 74 72 69 62 75  fication attribu
3910: 74 65 73 20 28 65 2e 67 2e 2c 20 6e 61 74 69 6f  tes (e.g., natio
3920: 6e 61 6c 69 74 79 29 0a 09 6f 66 20 74 68 65 20  nality)..of the 
3930: 73 75 62 6a 65 63 74 2e 20 52 46 43 20 35 32 38  subject. RFC 528
3940: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e  0 section 4.2.1.
3950: 38 20 28 73 75 62 6a 65 63 74 44 69 72 65 63 74  8 (subjectDirect
3960: 6f 72 79 41 74 74 72 69 62 75 74 65 73 29 20 2a  oryAttributes) *
3970: 2f 0a 0a 20 20 20 20 2f 2a 20 42 61 73 69 63 20  /..    /* Basic 
3980: 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 64 65 6e  Constraints iden
3990: 74 69 66 69 65 73 20 77 68 65 74 68 65 72 20 74  tifies whether t
39a0: 68 65 20 73 75 62 6a 65 63 74 20 6f 66 20 74 68  he subject of th
39b0: 65 20 63 65 72 74 20 69 73 20 61 20 43 41 20 61  e cert is a CA a
39c0: 6e 64 0a 09 74 68 65 20 6d 61 78 20 64 65 70 74  nd..the max dept
39d0: 68 20 6f 66 20 76 61 6c 69 64 20 63 65 72 74 20  h of valid cert 
39e0: 70 61 74 68 73 20 66 6f 72 20 74 68 69 73 20 63  paths for this c
39f0: 65 72 74 2e 20 52 46 43 20 35 32 38 30 20 73 65  ert. RFC 5280 se
3a00: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 39 2c 20 4e  ction 4.2.1.9, N
3a10: 49 44 5f 62 61 73 69 63 5f 63 6f 6e 73 74 72 61  ID_basic_constra
3a20: 69 6e 74 73 20 2a 2f 0a 20 20 20 20 69 66 20 28  ints */.    if (
3a30: 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f  xflags & EXFLAG_
3a40: 42 43 4f 4e 53 29 20 7b 0a 09 4c 41 50 50 45 4e  BCONS) {..LAPPEN
3a50: 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 63  D_LONG(interp, c
3a60: 65 72 74 50 74 72 2c 20 22 70 61 74 68 4c 65 6e  ertPtr, "pathLen
3a70: 22 2c 20 58 35 30 39 5f 67 65 74 5f 70 61 74 68  ", X509_get_path
3a80: 6c 65 6e 28 63 65 72 74 29 29 3b 0a 20 20 20 20  len(cert));.    
3a90: 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f  }.    LAPPEND_BO
3aa0: 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50  OL(interp, certP
3ab0: 74 72 2c 20 22 62 61 73 69 63 43 6f 6e 73 74 72  tr, "basicConstr
3ac0: 61 69 6e 74 73 43 41 22 2c 20 78 66 6c 61 67 73  aintsCA", xflags
3ad0: 20 26 20 45 58 46 4c 41 47 5f 43 41 29 3b 0a 20   & EXFLAG_CA);. 
3ae0: 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28     LAPPEND_BOOL(
3af0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c  interp, certPtr,
3b00: 20 22 62 61 73 69 63 43 6f 6e 73 74 72 61 69 6e   "basicConstrain
3b10: 74 73 43 72 69 74 69 63 61 6c 22 2c 20 78 66 6c  tsCritical", xfl
3b20: 61 67 73 20 26 20 45 58 46 4c 41 47 5f 43 52 49  ags & EXFLAG_CRI
3b30: 54 49 43 41 4c 29 3b 0a 0a 20 20 20 20 2f 2a 20  TICAL);..    /* 
3b40: 4e 61 6d 65 20 43 6f 6e 73 74 72 61 69 6e 74 73  Name Constraints
3b50: 20 69 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e   is only used in
3b60: 20 43 41 20 63 65 72 74 73 20 74 6f 20 69 6e 64   CA certs to ind
3b70: 69 63 61 74 65 20 74 68 65 20 6e 61 6d 65 20 73  icate the name s
3b80: 70 61 63 65 20 66 6f 72 0a 09 61 6c 6c 20 73 75  pace for..all su
3b90: 62 6a 65 63 74 20 6e 61 6d 65 73 20 69 6e 20 73  bject names in s
3ba0: 75 62 73 65 71 75 65 6e 74 20 63 65 72 74 69 66  ubsequent certif
3bb0: 69 63 61 74 65 73 20 69 6e 20 61 20 63 65 72 74  icates in a cert
3bc0: 69 66 69 63 61 74 69 6f 6e 20 70 61 74 68 0a 09  ification path..
3bd0: 4d 55 53 54 20 62 65 20 6c 6f 63 61 74 65 64 2e  MUST be located.
3be0: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
3bf0: 6e 20 34 2e 32 2e 31 2e 31 30 2c 20 4e 49 44 5f  n 4.2.1.10, NID_
3c00: 6e 61 6d 65 5f 63 6f 6e 73 74 72 61 69 6e 74 73  name_constraints
3c10: 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c 69   */..    /* Poli
3c20: 63 79 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69  cy Constraints i
3c30: 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 43  s only used in C
3c40: 41 20 63 65 72 74 73 20 74 6f 20 6c 69 6d 69 74  A certs to limit
3c50: 20 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 61   the length of a
3c60: 0a 09 63 65 72 74 20 63 68 61 69 6e 20 66 6f 72  ..cert chain for
3c70: 20 74 68 61 74 20 43 41 2e 20 52 46 43 20 35 32   that CA. RFC 52
3c80: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31  80 section 4.2.1
3c90: 2e 31 31 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 5f  .11, NID_policy_
3ca0: 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a 0a  constraints */..
3cb0: 20 20 20 20 2f 2a 20 45 78 74 65 6e 64 65 64 20      /* Extended 
3cc0: 4b 65 79 20 55 73 61 67 65 20 69 6e 64 69 63 61  Key Usage indica
3cd0: 74 65 73 20 74 68 65 20 70 75 72 70 6f 73 65 73  tes the purposes
3ce0: 20 74 68 65 20 63 65 72 74 69 66 69 65 64 20 70   the certified p
3cf0: 75 62 6c 69 63 20 6b 65 79 20 6d 61 79 20 62 65  ublic key may be
3d00: 0a 09 75 73 65 64 2c 20 62 65 79 6f 6e 64 20 74  ..used, beyond t
3d10: 68 65 20 62 61 73 69 63 20 70 75 72 70 6f 73 65  he basic purpose
3d20: 73 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74  s. RFC 5280 sect
3d30: 69 6f 6e 20 34 2e 32 2e 31 2e 31 32 2c 20 4e 49  ion 4.2.1.12, NI
3d40: 44 5f 65 78 74 5f 6b 65 79 5f 75 73 61 67 65 20  D_ext_key_usage 
3d50: 2a 2f 0a 20 20 20 20 6c 69 73 74 50 74 72 20 3d  */.    listPtr =
3d60: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28   Tcl_NewListObj(
3d70: 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 69 66  0, NULL);.    if
3d80: 20 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41   (xflags & EXFLA
3d90: 47 5f 58 4b 55 53 41 47 45 29 20 7b 0a 09 75 73  G_XKUSAGE) {..us
3da0: 61 67 65 20 3d 20 58 35 30 39 5f 67 65 74 5f 65  age = X509_get_e
3db0: 78 74 65 6e 64 65 64 5f 6b 65 79 5f 75 73 61 67  xtended_key_usag
3dc0: 65 28 63 65 72 74 29 3b 0a 0a 09 69 66 20 28 75  e(cert);...if (u
3dd0: 73 61 67 65 20 26 20 58 4b 55 5f 53 53 4c 5f 53  sage & XKU_SSL_S
3de0: 45 52 56 45 52 29 20 7b 0a 09 20 20 20 20 54 63  ERVER) {..    Tc
3df0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45  l_ListObjAppendE
3e00: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c  lement(interp, l
3e10: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53  istPtr, Tcl_NewS
3e20: 74 72 69 6e 67 4f 62 6a 28 22 54 4c 53 20 57 65  tringObj("TLS We
3e30: 62 20 53 65 72 76 65 72 20 41 75 74 68 65 6e 74  b Server Authent
3e40: 69 63 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b 0a  ication", -1));.
3e50: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20  .}..if (usage & 
3e60: 58 4b 55 5f 53 53 4c 5f 43 4c 49 45 4e 54 29 20  XKU_SSL_CLIENT) 
3e70: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f  {..    Tcl_ListO
3e80: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28  bjAppendElement(
3e90: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c  interp, listPtr,
3ea0: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62   Tcl_NewStringOb
3eb0: 6a 28 22 54 4c 53 20 57 65 62 20 43 6c 69 65 6e  j("TLS Web Clien
3ec0: 74 20 41 75 74 68 65 6e 74 69 63 61 74 69 6f 6e  t Authentication
3ed0: 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20  ", -1));..}..if 
3ee0: 28 75 73 61 67 65 20 26 20 58 4b 55 5f 53 4d 49  (usage & XKU_SMI
3ef0: 4d 45 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c  ME) {..    Tcl_L
3f00: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d  istObjAppendElem
3f10: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74  ent(interp, list
3f20: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69  Ptr, Tcl_NewStri
3f30: 6e 67 4f 62 6a 28 22 45 2d 6d 61 69 6c 20 50 72  ngObj("E-mail Pr
3f40: 6f 74 65 63 74 69 6f 6e 22 2c 20 2d 31 29 29 3b  otection", -1));
3f50: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26  ..}..if (usage &
3f60: 20 58 4b 55 5f 43 4f 44 45 5f 53 49 47 4e 29 20   XKU_CODE_SIGN) 
3f70: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f  {..    Tcl_ListO
3f80: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28  bjAppendElement(
3f90: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c  interp, listPtr,
3fa0: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62   Tcl_NewStringOb
3fb0: 6a 28 22 43 6f 64 65 20 53 69 67 6e 69 6e 67 22  j("Code Signing"
3fc0: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28  , -1));..}..if (
3fd0: 75 73 61 67 65 20 26 20 58 4b 55 5f 53 47 43 29  usage & XKU_SGC)
3fe0: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74   {..    Tcl_List
3ff0: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
4000: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
4010: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f  , Tcl_NewStringO
4020: 62 6a 28 22 53 47 43 22 2c 20 2d 31 29 29 3b 0a  bj("SGC", -1));.
4030: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20  .}..if (usage & 
4040: 58 4b 55 5f 4f 43 53 50 5f 53 49 47 4e 29 20 7b  XKU_OCSP_SIGN) {
4050: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62  ..    Tcl_ListOb
4060: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69  jAppendElement(i
4070: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20  nterp, listPtr, 
4080: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a  Tcl_NewStringObj
4090: 28 22 4f 43 53 50 20 53 69 67 6e 69 6e 67 22 2c  ("OCSP Signing",
40a0: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75   -1));..}..if (u
40b0: 73 61 67 65 20 26 20 58 4b 55 5f 54 49 4d 45 53  sage & XKU_TIMES
40c0: 54 41 4d 50 29 20 7b 0a 09 20 20 20 20 54 63 6c  TAMP) {..    Tcl
40d0: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
40e0: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69  ement(interp, li
40f0: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  stPtr, Tcl_NewSt
4100: 72 69 6e 67 4f 62 6a 28 22 54 69 6d 65 20 53 74  ringObj("Time St
4110: 61 6d 70 69 6e 67 22 2c 20 2d 31 29 29 3b 0a 09  amping", -1));..
4120: 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 58  }..if (usage & X
4130: 4b 55 5f 44 56 43 53 20 29 20 7b 0a 09 20 20 20  KU_DVCS ) {..   
4140: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
4150: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
4160: 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e  , listPtr, Tcl_N
4170: 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 56 43  ewStringObj("DVC
4180: 53 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66  S", -1));..}..if
4190: 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 41 4e   (usage & XKU_AN
41a0: 59 45 4b 55 29 20 7b 0a 09 20 20 20 20 54 63 6c  YEKU) {..    Tcl
41b0: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c  _ListObjAppendEl
41c0: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69  ement(interp, li
41d0: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74  stPtr, Tcl_NewSt
41e0: 72 69 6e 67 4f 62 6a 28 22 41 6e 79 20 45 78 74  ringObj("Any Ext
41f0: 65 6e 64 65 64 20 4b 65 79 20 55 73 61 67 65 22  ended Key Usage"
4200: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 20 20 7d  , -1));..}.    }
4210: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 49 53  .    LAPPEND_LIS
4220: 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74  T(interp, certPt
4230: 72 2c 20 22 65 78 74 65 6e 64 65 64 4b 65 79 55  r, "extendedKeyU
4240: 73 61 67 65 22 2c 20 6c 69 73 74 50 74 72 29 3b  sage", listPtr);
4250: 0a 0a 20 20 20 20 2f 2a 20 43 52 4c 20 44 69 73  ..    /* CRL Dis
4260: 74 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e 74 73  tribution Points
4270: 20 69 64 65 6e 74 69 66 69 65 73 20 77 68 65 72   identifies wher
4280: 65 20 43 52 4c 20 69 6e 66 6f 72 6d 61 74 69 6f  e CRL informatio
4290: 6e 20 63 61 6e 20 62 65 20 6f 62 74 61 69 6e 65  n can be obtaine
42a0: 64 2e 0a 09 52 46 43 20 35 32 38 30 20 73 65 63  d...RFC 5280 sec
42b0: 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 33 2a 2f 0a  tion 4.2.1.13*/.
42c0: 20 20 20 20 6c 69 73 74 50 74 72 20 3d 20 54 63      listPtr = Tc
42d0: 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20  l_NewListObj(0, 
42e0: 4e 55 4c 4c 29 3b 0a 20 20 20 20 69 66 20 28 63  NULL);.    if (c
42f0: 72 6c 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78  rl = X509_get_ex
4300: 74 5f 64 32 69 28 63 65 72 74 2c 20 4e 49 44 5f  t_d2i(cert, NID_
4310: 63 72 6c 5f 64 69 73 74 72 69 62 75 74 69 6f 6e  crl_distribution
4320: 5f 70 6f 69 6e 74 73 2c 20 4e 55 4c 4c 2c 20 4e  _points, NULL, N
4330: 55 4c 4c 29 29 20 7b 0a 09 54 63 6c 5f 4f 62 6a  ULL)) {..Tcl_Obj
4340: 20 2a 6e 61 6d 65 73 50 74 72 20 3d 20 54 63 6c   *namesPtr = Tcl
4350: 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e  _NewListObj(0, N
4360: 55 4c 4c 29 3b 0a 0a 09 66 6f 72 20 28 69 6e 74  ULL);...for (int
4370: 20 69 3d 30 3b 20 69 20 3c 20 73 6b 5f 44 49 53   i=0; i < sk_DIS
4380: 54 5f 50 4f 49 4e 54 5f 6e 75 6d 28 63 72 6c 29  T_POINT_num(crl)
4390: 3b 20 69 2b 2b 29 20 7b 0a 09 20 20 20 20 44 49  ; i++) {..    DI
43a0: 53 54 5f 50 4f 49 4e 54 20 2a 64 70 20 3d 20 73  ST_POINT *dp = s
43b0: 6b 5f 44 49 53 54 5f 50 4f 49 4e 54 5f 76 61 6c  k_DIST_POINT_val
43c0: 75 65 28 63 72 6c 2c 20 69 29 3b 0a 09 20 20 20  ue(crl, i);..   
43d0: 20 44 49 53 54 5f 50 4f 49 4e 54 5f 4e 41 4d 45   DIST_POINT_NAME
43e0: 20 2a 64 69 73 74 70 6f 69 6e 74 20 3d 20 64 70   *distpoint = dp
43f0: 2d 3e 64 69 73 74 70 6f 69 6e 74 3b 0a 0a 09 20  ->distpoint;... 
4400: 20 20 20 69 66 20 28 64 69 73 74 70 6f 69 6e 74     if (distpoint
4410: 2d 3e 74 79 70 65 20 3d 3d 20 30 29 20 7b 0a 09  ->type == 0) {..
4420: 09 2f 2a 20 66 75 6c 6c 6e 61 6d 65 20 47 45 4e  ./* fullname GEN
4430: 45 52 41 4c 49 5a 45 44 4e 41 4d 45 20 2a 2f 0a  ERALIZEDNAME */.
4440: 09 09 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30  ..for (int j = 0
4450: 3b 20 6a 20 3c 20 73 6b 5f 47 45 4e 45 52 41 4c  ; j < sk_GENERAL
4460: 5f 4e 41 4d 45 5f 6e 75 6d 28 64 69 73 74 70 6f  _NAME_num(distpo
4470: 69 6e 74 2d 3e 6e 61 6d 65 2e 66 75 6c 6c 6e 61  int->name.fullna
4480: 6d 65 29 3b 20 6a 2b 2b 29 20 7b 0a 09 09 20 20  me); j++) {...  
4490: 20 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 20 2a    GENERAL_NAME *
44a0: 67 65 6e 20 3d 20 73 6b 5f 47 45 4e 45 52 41 4c  gen = sk_GENERAL
44b0: 5f 4e 41 4d 45 5f 76 61 6c 75 65 28 64 69 73 74  _NAME_value(dist
44c0: 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66 75 6c 6c  point->name.full
44d0: 6e 61 6d 65 2c 20 6a 29 3b 0a 09 09 20 20 20 20  name, j);...    
44e0: 69 6e 74 20 74 79 70 65 3b 0a 09 09 20 20 20 20  int type;...    
44f0: 41 53 4e 31 5f 53 54 52 49 4e 47 20 2a 75 72 69  ASN1_STRING *uri
4500: 20 3d 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f   = GENERAL_NAME_
4510: 67 65 74 30 5f 76 61 6c 75 65 28 67 65 6e 2c 20  get0_value(gen, 
4520: 26 74 79 70 65 29 3b 0a 09 09 20 20 20 20 69 66  &type);...    if
4530: 20 28 74 79 70 65 20 3d 3d 20 47 45 4e 5f 55 52   (type == GEN_UR
4540: 49 29 20 7b 0a 09 09 09 54 63 6c 5f 4c 69 73 74  I) {....Tcl_List
4550: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74  ObjAppendElement
4560: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72  (interp, listPtr
4570: 2c 0a 09 09 09 20 20 20 20 54 63 6c 5f 4e 65 77  ,....    Tcl_New
4580: 53 74 72 69 6e 67 4f 62 6a 28 28 63 68 61 72 2a  StringObj((char*
4590: 29 41 53 4e 31 5f 53 54 52 49 4e 47 5f 67 65 74  )ASN1_STRING_get
45a0: 30 5f 64 61 74 61 28 75 72 69 29 2c 20 41 53 4e  0_data(uri), ASN
45b0: 31 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28  1_STRING_length(
45c0: 75 72 69 29 29 29 3b 0a 09 09 20 20 20 20 7d 0a  uri)));...    }.
45d0: 09 09 7d 0a 09 20 20 20 20 7d 20 65 6c 73 65 20  ..}..    } else 
45e0: 69 66 20 28 64 69 73 74 70 6f 69 6e 74 2d 3e 74  if (distpoint->t
45f0: 79 70 65 20 3d 3d 20 31 29 20 7b 0a 09 09 2f 2a  ype == 1) {.../*
4600: 20 72 65 6c 61 74 69 76 65 6e 61 6d 65 20 58 35   relativename X5
4610: 30 39 4e 41 4d 45 20 2a 2f 0a 09 09 53 54 41 43  09NAME */...STAC
4620: 4b 5f 4f 46 28 58 35 30 39 5f 4e 41 4d 45 5f 45  K_OF(X509_NAME_E
4630: 4e 54 52 59 29 20 2a 73 6b 5f 72 65 6c 6e 61 6d  NTRY) *sk_relnam
4640: 65 20 3d 20 64 69 73 74 70 6f 69 6e 74 2d 3e 6e  e = distpoint->n
4650: 61 6d 65 2e 72 65 6c 61 74 69 76 65 6e 61 6d 65  ame.relativename
4660: 3b 0a 09 09 66 6f 72 20 28 69 6e 74 20 6a 20 3d  ;...for (int j =
4670: 20 30 3b 20 6a 20 3c 20 73 6b 5f 58 35 30 39 5f   0; j < sk_X509_
4680: 4e 41 4d 45 5f 45 4e 54 52 59 5f 6e 75 6d 28 73  NAME_ENTRY_num(s
4690: 6b 5f 72 65 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29  k_relname); j++)
46a0: 20 7b 0a 09 09 20 20 20 20 58 35 30 39 5f 4e 41   {...    X509_NA
46b0: 4d 45 5f 45 4e 54 52 59 20 2a 65 20 3d 20 73 6b  ME_ENTRY *e = sk
46c0: 5f 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59  _X509_NAME_ENTRY
46d0: 5f 76 61 6c 75 65 28 73 6b 5f 72 65 6c 6e 61 6d  _value(sk_relnam
46e0: 65 2c 20 6a 29 3b 0a 09 09 20 20 20 20 41 53 4e  e, j);...    ASN
46f0: 31 5f 53 54 52 49 4e 47 20 2a 64 20 3d 20 58 35  1_STRING *d = X5
4700: 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 67 65  09_NAME_ENTRY_ge
4710: 74 5f 64 61 74 61 28 65 29 3b 0a 09 09 20 20 20  t_data(e);...   
4720: 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65   Tcl_ListObjAppe
4730: 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70  ndElement(interp
4740: 2c 20 6c 69 73 74 50 74 72 2c 0a 09 09 09 54 63  , listPtr,....Tc
4750: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 28  l_NewStringObj((
4760: 63 68 61 72 2a 29 41 53 4e 31 5f 53 54 52 49 4e  char*)ASN1_STRIN
4770: 47 5f 64 61 74 61 28 64 29 2c 20 41 53 4e 31 5f  G_data(d), ASN1_
4780: 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 64 29  STRING_length(d)
4790: 29 29 3b 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09  ));...}..    }..
47a0: 7d 0a 09 43 52 4c 5f 44 49 53 54 5f 50 4f 49 4e  }..CRL_DIST_POIN
47b0: 54 53 5f 66 72 65 65 28 63 72 6c 29 3b 0a 20 20  TS_free(crl);.  
47c0: 20 20 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f    }.    LAPPEND_
47d0: 4c 49 53 54 28 69 6e 74 65 72 70 2c 20 63 65 72  LIST(interp, cer
47e0: 74 50 74 72 2c 20 22 63 72 6c 44 69 73 74 72 69  tPtr, "crlDistri
47f0: 62 75 74 69 6f 6e 50 6f 69 6e 74 73 22 2c 20 6c  butionPoints", l
4800: 69 73 74 50 74 72 29 3b 0a 0a 20 20 20 20 2f 2a  istPtr);..    /*
4810: 20 46 72 65 73 68 65 73 74 20 43 52 4c 20 65 78   Freshest CRL ex
4820: 74 65 6e 73 69 6f 6e 20 2a 2f 0a 20 20 20 20 69  tension */.    i
4830: 66 20 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c  f (xflags & EXFL
4840: 41 47 5f 46 52 45 53 48 45 53 54 29 20 7b 0a 20  AG_FRESHEST) {. 
4850: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 41 75 74     }..    /* Aut
4860: 68 6f 72 69 74 79 20 49 6e 66 6f 72 6d 61 74 69  hority Informati
4870: 6f 6e 20 41 63 63 65 73 73 20 69 6e 64 69 63 61  on Access indica
4880: 74 65 73 20 68 6f 77 20 74 6f 20 61 63 63 65 73  tes how to acces
4890: 73 20 69 6e 66 6f 20 61 6e 64 20 73 65 72 76 69  s info and servi
48a0: 63 65 73 0a 09 66 6f 72 20 74 68 65 20 63 65 72  ces..for the cer
48b0: 74 69 66 69 63 61 74 65 20 69 73 73 75 65 72 2e  tificate issuer.
48c0: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f   RFC 5280 sectio
48d0: 6e 20 34 2e 32 2e 32 2e 31 2c 20 4e 49 44 5f 69  n 4.2.2.1, NID_i
48e0: 6e 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 20 20  nfo_access */.  
48f0: 20 20 2f 2a 20 47 65 74 20 4f 6e 2d 6c 69 6e 65    /* Get On-line
4900: 20 43 65 72 74 69 66 69 63 61 74 65 20 53 74 61   Certificate Sta
4910: 74 75 73 20 50 72 6f 74 6f 63 6f 6c 20 28 4f 53  tus Protocol (OS
4920: 43 50 29 20 55 52 4c 20 2a 2f 0a 20 20 20 20 6c  CP) URL */.    l
4930: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77  istPtr = Tcl_New
4940: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29  ListObj(0, NULL)
4950: 3b 0a 20 20 20 20 69 66 20 28 6f 63 73 70 20 3d  ;.    if (ocsp =
4960: 20 58 35 30 39 5f 67 65 74 31 5f 6f 63 73 70 28   X509_get1_ocsp(
4970: 63 65 72 74 29 29 20 7b 0a 09 66 6f 72 20 28 69  cert)) {..for (i
4980: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b  nt i = 0; i < sk
4990: 5f 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e 47 5f  _OPENSSL_STRING_
49a0: 6e 75 6d 28 6f 63 73 70 29 3b 20 69 2b 2b 29 20  num(ocsp); i++) 
49b0: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f  {..    Tcl_ListO
49c0: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28  bjAppendElement(
49d0: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c  interp, listPtr,
49e0: 0a 09 09 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67  ...Tcl_NewString
49f0: 4f 62 6a 28 73 6b 5f 4f 50 45 4e 53 53 4c 5f 53  Obj(sk_OPENSSL_S
4a00: 54 52 49 4e 47 5f 76 61 6c 75 65 28 6f 63 73 70  TRING_value(ocsp
4a10: 2c 20 69 29 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09  , i), -1));..}..
4a20: 58 35 30 39 5f 65 6d 61 69 6c 5f 66 72 65 65 28  X509_email_free(
4a30: 6f 63 73 70 29 3b 0a 20 20 20 20 7d 0a 20 20 20  ocsp);.    }.   
4a40: 20 4c 41 50 50 45 4e 44 5f 4c 49 53 54 28 69 6e   LAPPEND_LIST(in
4a50: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22  terp, certPtr, "
4a60: 6f 63 73 70 22 2c 20 6c 69 73 74 50 74 72 29 3b  ocsp", listPtr);
4a70: 0a 0a 20 20 20 20 2f 2a 20 43 41 20 49 73 73 75  ..    /* CA Issu
4a80: 65 72 73 20 55 52 4c 20 63 61 49 73 73 75 65 72  ers URL caIssuer
4a90: 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 53 75 62  s */..    /* Sub
4aa0: 6a 65 63 74 20 49 6e 66 6f 72 6d 61 74 69 6f 6e  ject Information
4ab0: 20 41 63 63 65 73 73 20 2d 20 52 46 43 20 35 32   Access - RFC 52
4ac0: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 32  80 section 4.2.2
4ad0: 2e 32 2c 20 4e 49 44 5f 73 69 6e 66 6f 5f 61 63  .2, NID_sinfo_ac
4ae0: 63 65 73 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20  cess */..    /* 
4af0: 43 65 72 74 69 66 69 63 61 74 65 20 41 6c 69 61  Certificate Alia
4b00: 73 2e 20 49 66 20 75 73 65 73 20 61 20 50 4b 43  s. If uses a PKC
4b10: 53 23 31 32 20 73 74 72 75 63 74 75 72 65 2c 20  S#12 structure, 
4b20: 61 6c 69 61 73 20 77 69 6c 6c 20 72 65 66 6c 65  alias will refle
4b30: 63 74 20 74 68 65 0a 09 66 72 69 65 6e 64 6c 79  ct the..friendly
4b40: 4e 61 6d 65 20 61 74 74 72 69 62 75 74 65 20 28  Name attribute (
4b50: 52 46 43 20 32 39 38 35 29 2e 20 2a 2f 0a 20 20  RFC 2985). */.  
4b60: 20 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20 20 4c    len = 0;.    L
4b70: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72  APPEND_STR(inter
4b80: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 61 6c 69  p, certPtr, "ali
4b90: 61 73 22 2c 20 58 35 30 39 5f 61 6c 69 61 73 5f  as", X509_alias_
4ba0: 67 65 74 30 28 63 65 72 74 2c 20 26 6c 65 6e 29  get0(cert, &len)
4bb0: 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 2f 2a 20  , len);..    /* 
4bc0: 43 65 72 74 69 66 69 63 61 74 65 20 61 6e 64 20  Certificate and 
4bd0: 64 75 6d 70 20 61 6c 6c 20 64 61 74 61 20 2a 2f  dump all data */
4be0: 0a 20 20 20 20 7b 0a 09 63 68 61 72 20 63 65 72  .    {..char cer
4bf0: 74 53 74 72 5b 43 45 52 54 5f 53 54 52 5f 53 49  tStr[CERT_STR_SI
4c00: 5a 45 5d 3b 0a 0a 09 2f 2a 20 47 65 74 20 63 65  ZE];.../* Get ce
4c10: 72 74 69 66 69 63 61 74 65 20 2a 2f 0a 09 6c 65  rtificate */..le
4c20: 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65  n = BIO_to_Buffe
4c30: 72 28 50 45 4d 5f 77 72 69 74 65 5f 62 69 6f 5f  r(PEM_write_bio_
4c40: 58 35 30 39 28 62 69 6f 2c 20 63 65 72 74 29 2c  X509(bio, cert),
4c50: 20 62 69 6f 2c 20 63 65 72 74 53 74 72 2c 20 43   bio, certStr, C
4c60: 45 52 54 5f 53 54 52 5f 53 49 5a 45 29 3b 0a 09  ERT_STR_SIZE);..
4c70: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65  LAPPEND_STR(inte
4c80: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 65  rp, certPtr, "ce
4c90: 72 74 69 66 69 63 61 74 65 22 2c 20 63 65 72 74  rtificate", cert
4ca0: 53 74 72 2c 20 6c 65 6e 29 3b 0a 0a 09 2f 2a 20  Str, len);.../* 
4cb0: 47 65 74 20 61 6c 6c 20 63 65 72 74 20 69 6e 66  Get all cert inf
4cc0: 6f 20 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f  o */..len = BIO_
4cd0: 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39 5f 70  to_Buffer(X509_p
4ce0: 72 69 6e 74 5f 65 78 28 62 69 6f 2c 20 63 65 72  rint_ex(bio, cer
4cf0: 74 2c 20 66 6c 61 67 73 2c 20 30 29 2c 20 62 69  t, flags, 0), bi
4d00: 6f 2c 20 63 65 72 74 53 74 72 2c 20 43 45 52 54  o, certStr, CERT
4d10: 5f 53 54 52 5f 53 49 5a 45 29 3b 0a 09 4c 41 50  _STR_SIZE);..LAP
4d20: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c  PEND_STR(interp,
4d30: 20 63 65 72 74 50 74 72 2c 20 22 61 6c 6c 22 2c   certPtr, "all",
4d40: 20 63 65 72 74 53 74 72 2c 20 6c 65 6e 29 3b 0a   certStr, len);.
4d50: 20 20 20 20 7d 0a 0a 20 20 20 20 42 49 4f 5f 66      }..    BIO_f
4d60: 72 65 65 28 62 69 6f 29 3b 0a 20 20 20 20 72 65  ree(bio);.    re
4d70: 74 75 72 6e 20 63 65 72 74 50 74 72 3b 0a 7d 0a  turn certPtr;.}.