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 4f ;. STACK_OF(O
0b20: 50 45 4e 53 53 4c 5f 53 54 52 49 4e 47 29 20 2a PENSSL_STRING) *
0b30: 6f 63 73 70 3b 0a 20 20 20 20 75 6e 73 69 67 6e ocsp;. unsign
0b40: 65 64 20 6c 6f 6e 67 20 66 6c 61 67 73 20 3d 20 ed long flags =
0b50: 58 4e 5f 46 4c 41 47 5f 52 46 43 32 32 35 33 20 XN_FLAG_RFC2253
0b60: 7c 20 41 53 4e 31 5f 53 54 52 46 4c 47 53 5f 55 | ASN1_STRFLGS_U
0b70: 54 46 38 5f 43 4f 4e 56 45 52 54 3b 0a 20 20 20 TF8_CONVERT;.
0b80: 20 66 6c 61 67 73 20 26 3d 20 7e 41 53 4e 31 5f flags &= ~ASN1_
0b90: 53 54 52 46 4c 47 53 5f 45 53 43 5f 4d 53 42 3b STRFLGS_ESC_MSB;
0ba0: 0a 0a 20 20 20 20 69 66 20 28 62 69 6f 20 3d 3d .. if (bio ==
0bb0: 20 4e 55 4c 4c 20 7c 7c 20 63 65 72 74 50 74 72 NULL || certPtr
0bc0: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 == NULL) {..ret
0bd0: 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a urn NULL;. }.
0be0: 0a 20 20 20 20 2f 2a 20 53 69 67 6e 61 74 75 72 . /* Signatur
0bf0: 65 20 61 6c 67 6f 72 69 74 68 6d 20 61 6e 64 20 e algorithm and
0c00: 76 61 6c 75 65 20 2d 20 52 46 43 20 35 32 38 30 value - RFC 5280
0c10: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 31 2e 32 section 4.1.1.2
0c20: 20 61 6e 64 20 34 2e 31 2e 31 2e 33 20 2a 2f 0a and 4.1.1.3 */.
0c30: 20 20 20 20 2f 2a 20 73 69 67 6e 61 74 75 72 65 /* signature
0c40: 41 6c 67 6f 72 69 74 68 6d 20 69 73 20 74 68 65 Algorithm is the
0c50: 20 69 64 20 6f 66 20 74 68 65 20 63 72 79 70 74 id of the crypt
0c60: 6f 67 72 61 70 68 69 63 20 61 6c 67 6f 72 69 74 ographic algorit
0c70: 68 6d 20 75 73 65 64 20 62 79 20 74 68 65 0a 09 hm used by the..
0c80: 43 41 20 74 6f 20 73 69 67 6e 20 74 68 69 73 20 CA to sign this
0c90: 63 65 72 74 2e 20 73 69 67 6e 61 74 75 72 65 56 cert. signatureV
0ca0: 61 6c 75 65 20 69 73 20 74 68 65 20 64 69 67 69 alue is the digi
0cb0: 74 61 6c 20 73 69 67 6e 61 74 75 72 65 20 63 6f tal signature co
0cc0: 6d 70 75 74 65 64 0a 09 75 70 6f 6e 20 74 68 65 mputed..upon the
0cd0: 20 41 53 4e 2e 31 20 44 45 52 20 65 6e 63 6f 64 ASN.1 DER encod
0ce0: 65 64 20 74 62 73 43 65 72 74 69 66 69 63 61 74 ed tbsCertificat
0cf0: 65 2e 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 6f 6e e. */. {..con
0d00: 73 74 20 58 35 30 39 5f 41 4c 47 4f 52 20 2a 73 st X509_ALGOR *s
0d10: 69 67 5f 61 6c 67 3b 0a 09 63 6f 6e 73 74 20 41 ig_alg;..const A
0d20: 53 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a SN1_BIT_STRING *
0d30: 73 69 67 3b 0a 09 69 6e 74 20 73 69 67 5f 6e 69 sig;..int sig_ni
0d40: 64 3b 0a 0a 09 58 35 30 39 5f 67 65 74 30 5f 73 d;...X509_get0_s
0d50: 69 67 6e 61 74 75 72 65 28 26 73 69 67 2c 20 26 ignature(&sig, &
0d60: 73 69 67 5f 61 6c 67 2c 20 63 65 72 74 29 3b 0a sig_alg, cert);.
0d70: 09 2f 2a 20 73 69 67 5f 6e 69 64 20 3d 20 58 35 ./* sig_nid = X5
0d80: 30 39 5f 67 65 74 5f 73 69 67 6e 61 74 75 72 65 09_get_signature
0d90: 5f 6e 69 64 28 63 65 72 74 29 20 2a 2f 0a 09 73 _nid(cert) */..s
0da0: 69 67 5f 6e 69 64 20 3d 20 4f 42 4a 5f 6f 62 6a ig_nid = OBJ_obj
0db0: 32 6e 69 64 28 73 69 67 5f 61 6c 67 2d 3e 61 6c 2nid(sig_alg->al
0dc0: 67 6f 72 69 74 68 6d 29 3b 0a 09 4c 41 50 50 45 gorithm);..LAPPE
0dd0: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 ND_STR(interp, c
0de0: 65 72 74 50 74 72 2c 20 22 73 69 67 6e 61 74 75 ertPtr, "signatu
0df0: 72 65 41 6c 67 6f 72 69 74 68 6d 22 2c 20 4f 42 reAlgorithm", OB
0e00: 4a 5f 6e 69 64 32 6c 6e 28 73 69 67 5f 6e 69 64 J_nid2ln(sig_nid
0e10: 29 2c 20 2d 31 29 3b 0a 09 6c 65 6e 20 3d 20 28 ), -1);..len = (
0e20: 73 69 67 5f 6e 69 64 20 21 3d 20 4e 49 44 5f 75 sig_nid != NID_u
0e30: 6e 64 65 66 29 20 3f 20 53 74 72 69 6e 67 5f 74 ndef) ? String_t
0e40: 6f 5f 48 65 78 28 73 69 67 2d 3e 64 61 74 61 2c o_Hex(sig->data,
0e50: 20 73 69 67 2d 3e 6c 65 6e 67 74 68 2c 20 62 75 sig->length, bu
0e60: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 20 3a 20 ffer, BUFSIZ) :
0e70: 30 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 0;..LAPPEND_STR(
0e80: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
0e90: 20 22 73 69 67 6e 61 74 75 72 65 56 61 6c 75 65 "signatureValue
0ea0: 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b ", buffer, len);
0eb0: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 56 . }.. /* V
0ec0: 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 65 6e ersion of the en
0ed0: 63 6f 64 65 64 20 63 65 72 74 69 66 69 63 61 74 coded certificat
0ee0: 65 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 e - RFC 5280 sec
0ef0: 74 69 6f 6e 20 34 2e 31 2e 32 2e 31 20 2a 2f 0a tion 4.1.2.1 */.
0f00: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 LAPPEND_LONG
0f10: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
0f20: 2c 20 22 76 65 72 73 69 6f 6e 22 2c 20 58 35 30 , "version", X50
0f30: 39 5f 67 65 74 5f 76 65 72 73 69 6f 6e 28 63 65 9_get_version(ce
0f40: 72 74 29 2b 31 29 3b 0a 0a 20 20 20 20 2f 2a 20 rt)+1);.. /*
0f50: 55 6e 69 71 75 65 20 6e 75 6d 62 65 72 20 61 73 Unique number as
0f60: 73 69 67 6e 65 64 20 62 79 20 43 41 20 74 6f 20 signed by CA to
0f70: 63 65 72 74 69 66 69 63 61 74 65 20 2d 20 52 46 certificate - RF
0f80: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 C 5280 section 4
0f90: 2e 31 2e 32 2e 32 20 2a 2f 0a 20 20 20 20 6c 65 .1.2.2 */. le
0fa0: 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 n = BIO_to_Buffe
0fb0: 72 28 69 32 61 5f 41 53 4e 31 5f 49 4e 54 45 47 r(i2a_ASN1_INTEG
0fc0: 45 52 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 ER(bio, X509_get
0fd0: 30 5f 73 65 72 69 61 6c 4e 75 6d 62 65 72 28 63 0_serialNumber(c
0fe0: 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66 66 ert)), bio, buff
0ff0: 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 er, BUFSIZ);.
1000: 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 LAPPEND_STR(int
1010: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 erp, certPtr, "s
1020: 65 72 69 61 6c 4e 75 6d 62 65 72 22 2c 20 62 75 erialNumber", bu
1030: 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 ffer, len);..
1040: 20 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61 6c /* Signature al
1050: 67 6f 72 69 74 68 6d 20 75 73 65 64 20 62 79 20 gorithm used by
1060: 74 68 65 20 43 41 20 74 6f 20 73 69 67 6e 20 74 the CA to sign t
1070: 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 he certificate.
1080: 4d 75 73 74 20 6d 61 74 63 68 0a 09 73 69 67 6e Must match..sign
1090: 61 74 75 72 65 41 6c 67 6f 72 69 74 68 6d 2e 20 atureAlgorithm.
10a0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
10b0: 20 34 2e 31 2e 32 2e 33 20 2a 2f 0a 20 20 20 20 4.1.2.3 */.
10c0: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
10d0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 rp, certPtr, "si
10e0: 67 6e 61 74 75 72 65 22 2c 20 4f 42 4a 5f 6e 69 gnature", OBJ_ni
10f0: 64 32 6c 6e 28 58 35 30 39 5f 67 65 74 5f 73 69 d2ln(X509_get_si
1100: 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 72 74 gnature_nid(cert
1110: 29 29 2c 20 2d 31 29 3b 0a 0a 20 20 20 20 2f 2a )), -1);.. /*
1120: 20 49 73 73 75 65 72 20 69 64 65 6e 74 69 66 69 Issuer identifi
1130: 65 73 20 74 68 65 20 65 6e 74 69 74 79 20 74 68 es the entity th
1140: 61 74 20 73 69 67 6e 65 64 20 61 6e 64 20 69 73 at signed and is
1150: 73 75 65 64 20 74 68 65 20 63 65 72 74 2e 20 52 sued the cert. R
1160: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 FC 5280 section
1170: 34 2e 31 2e 32 2e 34 20 2a 2f 0a 20 20 20 20 6c 4.1.2.4 */. l
1180: 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 en = BIO_to_Buff
1190: 65 72 28 58 35 30 39 5f 4e 41 4d 45 5f 70 72 69 er(X509_NAME_pri
11a0: 6e 74 5f 65 78 28 62 69 6f 2c 20 58 35 30 39 5f nt_ex(bio, X509_
11b0: 67 65 74 5f 69 73 73 75 65 72 5f 6e 61 6d 65 28 get_issuer_name(
11c0: 63 65 72 74 29 2c 20 30 2c 20 66 6c 61 67 73 29 cert), 0, flags)
11d0: 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 , bio, buffer, B
11e0: 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 UFSIZ);. LAPP
11f0: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 END_STR(interp,
1200: 63 65 72 74 50 74 72 2c 20 22 69 73 73 75 65 72 certPtr, "issuer
1210: 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b ", buffer, len);
1220: 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69 .. /* Certifi
1230: 63 61 74 65 20 76 61 6c 69 64 69 74 79 20 70 65 cate validity pe
1240: 72 69 6f 64 20 69 73 20 74 68 65 20 69 6e 74 65 riod is the inte
1250: 72 76 61 6c 20 74 68 65 20 43 41 20 77 61 72 72 rval the CA warr
1260: 61 6e 74 73 20 74 68 61 74 20 69 74 20 77 69 6c ants that it wil
1270: 6c 0a 09 6d 61 69 6e 74 61 69 6e 20 69 6e 66 6f l..maintain info
1280: 20 6f 6e 20 74 68 65 20 73 74 61 74 75 73 20 6f on the status o
1290: 66 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 f the certificat
12a0: 65 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 e. RFC 5280 sect
12b0: 69 6f 6e 20 34 2e 31 2e 32 2e 35 20 2a 2f 0a 20 ion 4.1.2.5 */.
12c0: 20 20 20 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 /* Get Validi
12d0: 74 79 20 2d 20 4e 6f 74 20 42 65 66 6f 72 65 20 ty - Not Before
12e0: 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f */. len = BIO
12f0: 5f 74 6f 5f 42 75 66 66 65 72 28 41 53 4e 31 5f _to_Buffer(ASN1_
1300: 54 49 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 TIME_print(bio,
1310: 58 35 30 39 5f 67 65 74 30 5f 6e 6f 74 42 65 66 X509_get0_notBef
1320: 6f 72 65 28 63 65 72 74 29 29 2c 20 62 69 6f 2c ore(cert)), bio,
1330: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 buffer, BUFSIZ)
1340: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 ;. LAPPEND_ST
1350: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 R(interp, certPt
1360: 72 2c 20 22 6e 6f 74 42 65 66 6f 72 65 22 2c 20 r, "notBefore",
1370: 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 buffer, len);..
1380: 20 20 20 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 /* Get Validi
1390: 74 79 20 2d 20 4e 6f 74 20 41 66 74 65 72 20 2a ty - Not After *
13a0: 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f /. len = BIO_
13b0: 74 6f 5f 42 75 66 66 65 72 28 41 53 4e 31 5f 54 to_Buffer(ASN1_T
13c0: 49 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 IME_print(bio, X
13d0: 35 30 39 5f 67 65 74 30 5f 6e 6f 74 41 66 74 65 509_get0_notAfte
13e0: 72 28 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 r(cert)), bio, b
13f0: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a uffer, BUFSIZ);.
1400: 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 LAPPEND_STR(
1410: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
1420: 20 22 6e 6f 74 41 66 74 65 72 22 2c 20 62 75 66 "notAfter", buf
1430: 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 fer, len);..
1440: 2f 2a 20 53 75 62 6a 65 63 74 20 69 64 65 6e 74 /* Subject ident
1450: 69 66 69 65 73 20 74 68 65 20 65 6e 74 69 74 79 ifies the entity
1460: 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
1470: 20 74 68 65 20 70 75 62 6c 69 63 20 6b 65 79 20 the public key
1480: 73 74 6f 72 65 64 20 69 6e 0a 09 74 68 65 20 73 stored in..the s
1490: 75 62 6a 65 63 74 20 70 75 62 6c 69 63 20 6b 65 ubject public ke
14a0: 79 20 66 69 65 6c 64 2e 20 52 46 43 20 35 32 38 y field. RFC 528
14b0: 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 0 section 4.1.2.
14c0: 36 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 6 */. len = B
14d0: 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 IO_to_Buffer(X50
14e0: 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f 65 78 28 9_NAME_print_ex(
14f0: 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 5f 73 75 bio, X509_get_su
1500: 62 6a 65 63 74 5f 6e 61 6d 65 28 63 65 72 74 29 bject_name(cert)
1510: 2c 20 30 2c 20 66 6c 61 67 73 29 2c 20 62 69 6f , 0, flags), bio
1520: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a , buffer, BUFSIZ
1530: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 );. LAPPEND_S
1540: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 TR(interp, certP
1550: 74 72 2c 20 22 73 75 62 6a 65 63 74 22 2c 20 62 tr, "subject", b
1560: 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 uffer, len);..
1570: 20 20 2f 2a 20 53 48 41 31 20 46 69 6e 67 65 72 /* SHA1 Finger
1580: 70 72 69 6e 74 20 6f 66 20 63 65 72 74 20 2d 20 print of cert -
1590: 44 45 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 DER representati
15a0: 6f 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 on */. if (X5
15b0: 30 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 09_digest(cert,
15c0: 45 56 50 5f 73 68 61 31 28 29 2c 20 6d 64 2c 20 EVP_sha1(), md,
15d0: 26 6c 65 6e 29 29 20 7b 0a 20 20 20 20 6c 65 6e &len)) {. len
15e0: 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 = String_to_Hex
15f0: 28 6d 64 2c 20 6c 65 6e 2c 20 62 75 66 66 65 72 (md, len, buffer
1600: 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 50 , BUFSIZ);..LAPP
1610: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 END_STR(interp,
1620: 63 65 72 74 50 74 72 2c 20 22 73 68 61 31 5f 68 certPtr, "sha1_h
1630: 61 73 68 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 ash", buffer, le
1640: 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f n);. }.. /
1650: 2a 20 53 48 41 32 35 36 20 46 69 6e 67 65 72 70 * SHA256 Fingerp
1660: 72 69 6e 74 20 6f 66 20 63 65 72 74 20 2d 20 44 rint of cert - D
1670: 45 52 20 72 65 70 72 65 73 65 6e 74 61 74 69 6f ER representatio
1680: 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 35 30 n */. if (X50
1690: 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45 9_digest(cert, E
16a0: 56 50 5f 73 68 61 32 35 36 28 29 2c 20 6d 64 2c VP_sha256(), md,
16b0: 20 26 6c 65 6e 29 29 20 7b 0a 20 20 20 20 6c 65 &len)) {. le
16c0: 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 n = String_to_He
16d0: 78 28 6d 64 2c 20 6c 65 6e 2c 20 62 75 66 66 65 x(md, len, buffe
16e0: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c 41 50 r, BUFSIZ);..LAP
16f0: 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c PEND_STR(interp,
1700: 20 63 65 72 74 50 74 72 2c 20 22 73 68 61 32 35 certPtr, "sha25
1710: 36 5f 68 61 73 68 22 2c 20 62 75 66 66 65 72 2c 6_hash", buffer,
1720: 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 len);. }..
1730: 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 50 75 62 /* Subject Pub
1740: 6c 69 63 20 4b 65 79 20 49 6e 66 6f 20 73 70 65 lic Key Info spe
1750: 63 69 66 69 65 73 20 74 68 65 20 70 75 62 6c 69 cifies the publi
1760: 63 20 6b 65 79 20 61 6e 64 20 69 64 65 6e 74 69 c key and identi
1770: 66 69 65 73 20 74 68 65 0a 09 61 6c 67 6f 72 69 fies the..algori
1780: 74 68 6d 20 77 69 74 68 20 77 68 69 63 68 20 74 thm with which t
1790: 68 65 20 6b 65 79 20 69 73 20 75 73 65 64 2e 20 he key is used.
17a0: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
17b0: 20 34 2e 31 2e 32 2e 37 20 2a 2f 0a 20 20 20 20 4.1.2.7 */.
17c0: 69 66 20 28 58 35 30 39 5f 67 65 74 5f 73 69 67 if (X509_get_sig
17d0: 6e 61 74 75 72 65 5f 69 6e 66 6f 28 63 65 72 74 nature_info(cert
17e0: 2c 20 26 6d 64 6e 69 64 2c 20 26 70 6b 6e 69 64 , &mdnid, &pknid
17f0: 2c 20 26 62 69 74 73 2c 20 26 78 66 6c 61 67 73 , &bits, &xflags
1800: 29 29 20 7b 0a 09 41 53 4e 31 5f 42 49 54 5f 53 )) {..ASN1_BIT_S
1810: 54 52 49 4e 47 20 2a 6b 65 79 3b 0a 09 75 6e 73 TRING *key;..uns
1820: 69 67 6e 65 64 20 69 6e 74 20 6e 3b 0a 0a 09 4c igned int n;...L
1830: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 APPEND_STR(inter
1840: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 67 p, certPtr, "sig
1850: 6e 69 6e 67 44 69 67 65 73 74 22 2c 20 4f 42 4a ningDigest", OBJ
1860: 5f 6e 69 64 32 6c 6e 28 6d 64 6e 69 64 29 2c 20 _nid2ln(mdnid),
1870: 2d 31 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 -1);..LAPPEND_ST
1880: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 R(interp, certPt
1890: 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 41 6c 67 r, "publicKeyAlg
18a0: 6f 72 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e 69 64 orithm", OBJ_nid
18b0: 32 6c 6e 28 70 6b 6e 69 64 29 2c 20 2d 31 29 3b 2ln(pknid), -1);
18c0: 0a 09 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e ..LAPPEND_INT(in
18d0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
18e0: 62 69 74 73 22 2c 20 62 69 74 73 29 3b 20 2f 2a bits", bits); /*
18f0: 20 45 66 66 65 63 74 69 76 65 20 73 65 63 75 72 Effective secur
1900: 69 74 79 20 62 69 74 73 20 2a 2f 0a 0a 09 6b 65 ity bits */...ke
1910: 79 20 3d 20 58 35 30 39 5f 67 65 74 30 5f 70 75 y = X509_get0_pu
1920: 62 6b 65 79 5f 62 69 74 73 74 72 28 63 65 72 74 bkey_bitstr(cert
1930: 29 3b 0a 09 6c 65 6e 20 3d 20 53 74 72 69 6e 67 );..len = String
1940: 5f 74 6f 5f 48 65 78 28 6b 65 79 2d 3e 64 61 74 _to_Hex(key->dat
1950: 61 2c 20 6b 65 79 2d 3e 6c 65 6e 67 74 68 2c 20 a, key->length,
1960: 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b buffer, BUFSIZ);
1970: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e ..LAPPEND_STR(in
1980: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
1990: 70 75 62 6c 69 63 4b 65 79 22 2c 20 62 75 66 66 publicKey", buff
19a0: 65 72 2c 20 6c 65 6e 29 3b 0a 0a 09 6c 65 6e 20 er, len);...len
19b0: 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 39 5f 70 = 0;..if (X509_p
19c0: 75 62 6b 65 79 5f 64 69 67 65 73 74 28 63 65 72 ubkey_digest(cer
19d0: 74 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65 73 t, EVP_get_diges
19e0: 74 62 79 6e 69 64 28 70 6b 6e 69 64 29 2c 20 6d tbynid(pknid), m
19f0: 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20 6c d, &n)) {.. l
1a00: 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 en = String_to_H
1a10: 65 78 28 6d 64 2c 20 28 69 6e 74 29 6e 2c 20 62 ex(md, (int)n, b
1a20: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a uffer, BUFSIZ);.
1a30: 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 .}..LAPPEND_STR(
1a40: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
1a50: 20 22 70 75 62 6c 69 63 4b 65 79 48 61 73 68 22 "publicKeyHash"
1a60: 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a , buffer, len);.
1a70: 0a 09 6c 65 6e 20 3d 20 30 3b 0a 09 69 66 20 28 ..len = 0;..if (
1a80: 58 35 30 39 5f 64 69 67 65 73 74 28 63 65 72 74 X509_digest(cert
1a90: 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 65 73 74 , EVP_get_digest
1aa0: 62 79 6e 69 64 28 6d 64 6e 69 64 29 2c 20 6d 64 bynid(mdnid), md
1ab0: 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 20 6c 65 , &n)) {.. le
1ac0: 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 n = String_to_He
1ad0: 78 28 6d 64 2c 20 28 69 6e 74 29 6e 2c 20 62 75 x(md, (int)n, bu
1ae0: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 ffer, BUFSIZ);..
1af0: 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 }..LAPPEND_STR(i
1b00: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
1b10: 22 73 69 67 6e 61 74 75 72 65 48 61 73 68 22 2c "signatureHash",
1b20: 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 20 buffer, len);.
1b30: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 47 65 74 }.. /* Get
1b40: 20 65 78 74 65 6e 73 69 6f 6e 73 20 66 6c 61 67 extensions flag
1b50: 73 20 2a 2f 0a 20 20 20 20 78 66 6c 61 67 73 20 s */. xflags
1b60: 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 65 6e = X509_get_exten
1b70: 73 69 6f 6e 5f 66 6c 61 67 73 28 63 65 72 74 29 sion_flags(cert)
1b80: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 49 4e ;. LAPPEND_IN
1b90: 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 T(interp, certPt
1ba0: 72 2c 20 22 65 78 74 46 6c 61 67 73 22 2c 20 78 r, "extFlags", x
1bb0: 66 6c 61 67 73 29 3b 0a 0a 09 2f 2a 20 43 68 65 flags);.../* Che
1bc0: 63 6b 20 69 66 20 63 65 72 74 20 77 61 73 20 69 ck if cert was i
1bd0: 73 73 75 65 64 20 62 79 20 43 41 20 63 65 72 74 ssued by CA cert
1be0: 20 69 73 73 75 65 72 20 6f 72 20 73 65 6c 66 20 issuer or self
1bf0: 73 69 67 6e 65 64 20 2a 2f 0a 20 20 20 20 4c 41 signed */. LA
1c00: 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 PPEND_BOOL(inter
1c10: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 65 6c p, certPtr, "sel
1c20: 66 49 73 73 75 65 64 22 2c 20 78 66 6c 61 67 73 fIssued", xflags
1c30: 20 26 20 45 58 46 4c 41 47 5f 53 49 29 3b 0a 20 & EXFLAG_SI);.
1c40: 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 LAPPEND_BOOL(
1c50: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
1c60: 20 22 73 65 6c 66 53 69 67 6e 65 64 22 2c 20 78 "selfSigned", x
1c70: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 53 flags & EXFLAG_S
1c80: 53 29 3b 0a 0a 20 20 20 20 2f 2a 20 54 68 65 20 S);.. /* The
1c90: 55 6e 69 71 75 65 20 49 64 73 20 61 72 65 20 75 Unique Ids are u
1ca0: 73 65 64 20 74 6f 20 68 61 6e 64 6c 65 20 74 68 sed to handle th
1cb0: 65 20 70 6f 73 73 69 62 69 6c 69 74 79 20 6f 66 e possibility of
1cc0: 20 72 65 75 73 65 20 6f 66 20 73 75 62 6a 65 63 reuse of subjec
1cd0: 74 0a 09 61 6e 64 2f 6f 72 20 69 73 73 75 65 72 t..and/or issuer
1ce0: 20 6e 61 6d 65 73 20 6f 76 65 72 20 74 69 6d 65 names over time
1cf0: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
1d00: 6f 6e 20 34 2e 31 2e 32 2e 38 20 2a 2f 0a 20 20 on 4.1.2.8 */.
1d10: 20 20 7b 0a 09 63 6f 6e 73 74 20 41 53 4e 31 5f {..const ASN1_
1d20: 42 49 54 5f 53 54 52 49 4e 47 20 2a 69 75 69 64 BIT_STRING *iuid
1d30: 2c 20 2a 73 75 69 64 3b 0a 20 20 20 20 20 20 20 , *suid;.
1d40: 20 58 35 30 39 5f 67 65 74 30 5f 75 69 64 73 28 X509_get0_uids(
1d50: 63 65 72 74 2c 20 26 69 75 69 64 2c 20 26 73 75 cert, &iuid, &su
1d60: 69 64 29 3b 0a 0a 09 54 63 6c 5f 4c 69 73 74 4f id);...Tcl_ListO
1d70: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 bjAppendElement(
1d80: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
1d90: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
1da0: 6a 28 22 69 73 73 75 65 72 55 6e 69 71 75 65 49 j("issuerUniqueI
1db0: 64 22 2c 20 2d 31 29 29 3b 0a 09 69 66 20 28 69 d", -1));..if (i
1dc0: 75 69 64 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 uid != NULL) {..
1dd0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
1de0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
1df0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 63 erp, certPtr, Tc
1e00: 6c 5f 4e 65 77 42 79 74 65 41 72 72 61 79 4f 62 l_NewByteArrayOb
1e10: 6a 28 28 63 68 61 72 20 2a 29 69 75 69 64 2d 3e j((char *)iuid->
1e20: 64 61 74 61 2c 20 69 75 69 64 2d 3e 6c 65 6e 67 data, iuid->leng
1e30: 74 68 29 29 3b 0a 09 7d 20 65 6c 73 65 20 7b 0a th));..} else {.
1e40: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
1e50: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
1e60: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 54 terp, certPtr, T
1e70: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
1e80: 22 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 0a 09 54 "", -1));..}...T
1e90: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
1ea0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
1eb0: 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 certPtr, Tcl_New
1ec0: 53 74 72 69 6e 67 4f 62 6a 28 22 73 75 62 6a 65 StringObj("subje
1ed0: 63 74 55 6e 69 71 75 65 49 64 22 2c 20 2d 31 29 ctUniqueId", -1)
1ee0: 29 3b 0a 09 69 66 20 28 73 75 69 64 20 21 3d 20 );..if (suid !=
1ef0: 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 54 63 6c NULL) {.. Tcl
1f00: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
1f10: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 ement(interp, ce
1f20: 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 42 79 rtPtr, Tcl_NewBy
1f30: 74 65 41 72 72 61 79 4f 62 6a 28 28 63 68 61 72 teArrayObj((char
1f40: 20 2a 29 73 75 69 64 2d 3e 64 61 74 61 2c 20 73 *)suid->data, s
1f50: 75 69 64 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 uid->length));..
1f60: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 } else {.. Tc
1f70: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
1f80: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 lement(interp, c
1f90: 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 ertPtr, Tcl_NewS
1fa0: 74 72 69 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 tringObj("", -1)
1fb0: 29 3b 0a 09 7d 0a 20 20 20 20 7d 0a 0a 20 20 20 );..}. }..
1fc0: 20 2f 2a 20 58 35 30 39 20 76 33 20 45 78 74 65 /* X509 v3 Exte
1fd0: 6e 73 69 6f 6e 73 20 2d 20 52 46 43 20 35 32 38 nsions - RFC 528
1fe0: 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 0 section 4.1.2.
1ff0: 39 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 58 9 */. len = X
2000: 35 30 39 5f 67 65 74 5f 65 78 74 5f 63 6f 75 6e 509_get_ext_coun
2010: 74 28 63 65 72 74 29 3b 0a 20 20 20 20 6c 69 73 t(cert);. lis
2020: 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 tPtr = Tcl_NewLi
2030: 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a stObj(0, NULL);.
2040: 20 20 20 20 69 66 20 28 6c 65 6e 20 3e 20 30 29 if (len > 0)
2050: 20 7b 0a 09 63 6f 6e 73 74 20 53 54 41 43 4b 5f {..const STACK_
2060: 4f 46 28 58 35 30 39 5f 45 58 54 45 4e 53 49 4f OF(X509_EXTENSIO
2070: 4e 29 20 2a 65 78 74 73 20 3d 20 58 35 30 39 5f N) *exts = X509_
2080: 67 65 74 30 5f 65 78 74 65 6e 73 69 6f 6e 73 28 get0_extensions(
2090: 63 65 72 74 29 3b 0a 0a 09 66 6f 72 20 28 69 6e cert);...for (in
20a0: 74 20 69 3d 30 3b 20 69 20 3c 20 6c 65 6e 3b 20 t i=0; i < len;
20b0: 69 2b 2b 29 20 7b 0a 09 20 20 20 20 58 35 30 39 i++) {.. X509
20c0: 5f 45 58 54 45 4e 53 49 4f 4e 20 2a 65 78 20 3d _EXTENSION *ex =
20d0: 20 73 6b 5f 58 35 30 39 5f 45 58 54 45 4e 53 49 sk_X509_EXTENSI
20e0: 4f 4e 5f 76 61 6c 75 65 28 65 78 74 73 2c 20 69 ON_value(exts, i
20f0: 29 3b 0a 09 20 20 20 20 41 53 4e 31 5f 4f 42 4a );.. ASN1_OBJ
2100: 45 43 54 20 2a 6f 62 6a 20 3d 20 58 35 30 39 5f ECT *obj = X509_
2110: 45 58 54 45 4e 53 49 4f 4e 5f 67 65 74 5f 6f 62 EXTENSION_get_ob
2120: 6a 65 63 74 28 65 78 29 3b 0a 0a 09 20 20 20 20 ject(ex);...
2130: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e Tcl_ListObjAppen
2140: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c dElement(interp,
2150: 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 listPtr, Tcl_Ne
2160: 77 53 74 72 69 6e 67 4f 62 6a 28 4f 42 4a 5f 6e wStringObj(OBJ_n
2170: 69 64 32 6c 6e 28 4f 42 4a 5f 6f 62 6a 32 6e 69 id2ln(OBJ_obj2ni
2180: 64 28 6f 62 6a 29 29 2c 20 2d 31 29 29 3b 0a 09 d(obj)), -1));..
2190: 7d 0a 20 20 20 20 7d 0a 20 20 20 20 4c 41 50 50 }. }. LAPP
21a0: 45 4e 44 5f 49 4e 54 28 69 6e 74 65 72 70 2c 20 END_INT(interp,
21b0: 63 65 72 74 50 74 72 2c 20 22 65 78 74 43 6f 75 certPtr, "extCou
21c0: 6e 74 22 2c 20 6c 65 6e 29 3b 0a 20 20 20 20 4c nt", len);. L
21d0: 41 50 50 45 4e 44 5f 4c 49 53 54 28 69 6e 74 65 APPEND_LIST(inte
21e0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 65 78 rp, certPtr, "ex
21f0: 74 65 6e 73 69 6f 6e 73 22 2c 20 6c 69 73 74 50 tensions", listP
2200: 74 72 29 3b 0a 0a 20 20 20 20 2f 2a 20 41 75 74 tr);.. /* Aut
2210: 68 6f 72 69 74 79 20 4b 65 79 20 49 64 65 6e 74 hority Key Ident
2220: 69 66 69 65 72 20 28 41 4b 49 29 20 69 73 20 74 ifier (AKI) is t
2230: 68 65 20 53 75 62 6a 65 63 74 20 4b 65 79 20 49 he Subject Key I
2240: 64 65 6e 74 69 66 69 65 72 20 28 53 4b 49 29 20 dentifier (SKI)
2250: 6f 66 0a 09 69 74 73 20 73 69 67 6e 65 72 20 28 of..its signer (
2260: 74 68 65 20 43 41 29 2e 20 52 46 43 20 35 32 38 the CA). RFC 528
2270: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 0 section 4.2.1.
2280: 31 2c 20 4e 49 44 5f 61 75 74 68 6f 72 69 74 79 1, NID_authority
2290: 5f 6b 65 79 5f 69 64 65 6e 74 69 66 69 65 72 20 _key_identifier
22a0: 2a 2f 0a 20 20 20 20 7b 0a 09 41 53 4e 31 5f 4f */. {..ASN1_O
22b0: 43 54 45 54 5f 53 54 52 49 4e 47 20 2a 61 73 74 CTET_STRING *ast
22c0: 72 69 6e 67 20 3d 20 58 35 30 39 5f 67 65 74 30 ring = X509_get0
22d0: 5f 61 75 74 68 6f 72 69 74 79 5f 6b 65 79 5f 69 _authority_key_i
22e0: 64 28 63 65 72 74 29 3b 0a 09 6c 65 6e 20 3d 20 d(cert);..len =
22f0: 30 3b 0a 09 69 66 20 28 61 73 74 72 69 6e 67 20 0;..if (astring
2300: 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 != NULL) {..
2310: 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f len = String_to_
2320: 48 65 78 28 28 63 68 61 72 20 2a 29 41 53 4e 31 Hex((char *)ASN1
2330: 5f 53 54 52 49 4e 47 5f 67 65 74 30 5f 64 61 74 _STRING_get0_dat
2340: 61 28 61 73 74 72 69 6e 67 29 2c 0a 09 09 41 53 a(astring),...AS
2350: 4e 31 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 N1_STRING_length
2360: 28 61 73 74 72 69 6e 67 29 2c 20 62 75 66 66 65 (astring), buffe
2370: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 7d 0a 09 r, BUFSIZ);..}..
2380: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
2390: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 61 75 rp, certPtr, "au
23a0: 74 68 6f 72 69 74 79 4b 65 79 49 64 65 6e 74 69 thorityKeyIdenti
23b0: 66 69 65 72 22 2c 20 62 75 66 66 65 72 2c 20 6c fier", buffer, l
23c0: 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 en);. }..
23d0: 2f 2a 20 53 75 62 6a 65 63 74 20 4b 65 79 20 49 /* Subject Key I
23e0: 64 65 6e 74 69 66 69 65 72 20 28 53 4b 49 29 20 dentifier (SKI)
23f0: 69 73 20 75 73 65 64 20 74 6f 20 64 65 6e 74 69 is used to denti
2400: 66 79 20 63 65 72 74 69 66 69 63 61 74 65 73 20 fy certificates
2410: 74 68 61 74 20 63 6f 6e 74 61 69 6e 0a 09 61 20 that contain..a
2420: 70 61 72 74 69 63 75 6c 61 72 20 70 75 62 6c 69 particular publi
2430: 63 20 6b 65 79 2e 20 52 46 43 20 35 32 38 30 20 c key. RFC 5280
2440: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 32 2c section 4.2.1.2,
2450: 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f 6b 65 79 NID_subject_key
2460: 5f 69 64 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 _identifier */.
2470: 20 20 20 7b 0a 09 41 53 4e 31 5f 4f 43 54 45 54 {..ASN1_OCTET
2480: 5f 53 54 52 49 4e 47 20 2a 61 73 74 72 69 6e 67 _STRING *astring
2490: 20 3d 20 58 35 30 39 5f 67 65 74 30 5f 73 75 62 = X509_get0_sub
24a0: 6a 65 63 74 5f 6b 65 79 5f 69 64 28 63 65 72 74 ject_key_id(cert
24b0: 29 3b 0a 09 6c 65 6e 20 3d 20 30 3b 0a 09 69 66 );..len = 0;..if
24c0: 20 28 61 73 74 72 69 6e 67 20 21 3d 20 4e 55 4c (astring != NUL
24d0: 4c 29 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d 20 L) {.. len =
24e0: 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 28 63 String_to_Hex((c
24f0: 68 61 72 20 2a 29 41 53 4e 31 5f 53 54 52 49 4e har *)ASN1_STRIN
2500: 47 5f 67 65 74 30 5f 64 61 74 61 28 61 73 74 72 G_get0_data(astr
2510: 69 6e 67 29 2c 0a 09 09 41 53 4e 31 5f 53 54 52 ing),...ASN1_STR
2520: 49 4e 47 5f 6c 65 6e 67 74 68 28 61 73 74 72 69 ING_length(astri
2530: 6e 67 29 2c 20 62 75 66 66 65 72 2c 20 42 55 46 ng), buffer, BUF
2540: 53 49 5a 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e SIZ);..}..LAPPEN
2550: 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 D_STR(interp, ce
2560: 72 74 50 74 72 2c 20 22 73 75 62 6a 65 63 74 4b rtPtr, "subjectK
2570: 65 79 49 64 65 6e 74 69 66 69 65 72 22 2c 20 62 eyIdentifier", b
2580: 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 20 20 20 uffer, len);.
2590: 20 7d 0a 0a 20 20 20 20 2f 2a 20 4b 65 79 20 75 }.. /* Key u
25a0: 73 61 67 65 20 65 78 74 65 6e 73 69 6f 6e 20 64 sage extension d
25b0: 65 66 69 6e 65 73 20 74 68 65 20 70 75 72 70 6f efines the purpo
25c0: 73 65 20 28 65 2e 67 2e 2c 20 65 6e 63 69 70 68 se (e.g., enciph
25d0: 65 72 6d 65 6e 74 2c 20 73 69 67 6e 61 74 75 72 erment, signatur
25e0: 65 2c 20 63 65 72 74 69 66 69 63 61 74 65 0a 09 e, certificate..
25f0: 73 69 67 6e 69 6e 67 29 20 6f 66 20 74 68 65 20 signing) of the
2600: 6b 65 79 20 63 6f 6e 74 61 69 6e 65 64 20 69 6e key contained in
2610: 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 the certificate
2620: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
2630: 6f 6e 20 34 2e 32 2e 31 2e 33 2c 20 4e 49 44 5f on 4.2.1.3, NID_
2640: 6b 65 79 5f 75 73 61 67 65 20 2a 2f 0a 20 20 20 key_usage */.
2650: 20 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e listPtr = Tcl_N
2660: 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c ewListObj(0, NUL
2670: 4c 29 3b 0a 20 20 20 20 75 73 61 67 65 20 3d 20 L);. usage =
2680: 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f 75 73 61 X509_get_key_usa
2690: 67 65 28 63 65 72 74 29 3b 0a 20 20 20 20 69 66 ge(cert);. if
26a0: 20 28 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c ((xflags & EXFL
26b0: 41 47 5f 4b 55 53 41 47 45 29 20 26 26 20 75 73 AG_KUSAGE) && us
26c0: 61 67 65 20 3c 20 30 78 66 66 66 66 66 66 29 20 age < 0xffffff)
26d0: 7b 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 4b {..if (usage & K
26e0: 55 5f 44 49 47 49 54 41 4c 5f 53 49 47 4e 41 54 U_DIGITAL_SIGNAT
26f0: 55 52 45 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f URE) {.. Tcl_
2700: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
2710: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 ment(interp, lis
2720: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 tPtr, Tcl_NewStr
2730: 69 6e 67 4f 62 6a 28 22 44 69 67 69 74 61 6c 20 ingObj("Digital
2740: 53 69 67 6e 61 74 75 72 65 22 2c 20 2d 31 29 29 Signature", -1))
2750: 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 ;..}..if (usage
2760: 26 20 4b 55 5f 4e 4f 4e 5f 52 45 50 55 44 49 41 & KU_NON_REPUDIA
2770: 54 49 4f 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c TION) {.. Tcl
2780: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
2790: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 ement(interp, li
27a0: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 stPtr, Tcl_NewSt
27b0: 72 69 6e 67 4f 62 6a 28 22 4e 6f 6e 2d 52 65 70 ringObj("Non-Rep
27c0: 75 64 69 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b udiation", -1));
27d0: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
27e0: 20 4b 55 5f 4b 45 59 5f 45 4e 43 49 50 48 45 52 KU_KEY_ENCIPHER
27f0: 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 6c MENT) {.. Tcl
2800: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
2810: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 ement(interp, li
2820: 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 stPtr, Tcl_NewSt
2830: 72 69 6e 67 4f 62 6a 28 22 4b 65 79 20 45 6e 63 ringObj("Key Enc
2840: 69 70 68 65 72 6d 65 6e 74 22 2c 20 2d 31 29 29 ipherment", -1))
2850: 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 ;..}..if (usage
2860: 26 20 4b 55 5f 44 41 54 41 5f 45 4e 43 49 50 48 & KU_DATA_ENCIPH
2870: 45 52 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 ERMENT) {.. T
2880: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
2890: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
28a0: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
28b0: 53 74 72 69 6e 67 4f 62 6a 28 22 44 61 74 61 20 StringObj("Data
28c0: 45 6e 63 69 70 68 65 72 6d 65 6e 74 22 2c 20 2d Encipherment", -
28d0: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 1));..}..if (usa
28e0: 67 65 20 26 20 4b 55 5f 4b 45 59 5f 41 47 52 45 ge & KU_KEY_AGRE
28f0: 45 4d 45 4e 54 29 20 7b 0a 09 20 20 20 20 54 63 EMENT) {.. Tc
2900: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
2910: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
2920: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
2930: 74 72 69 6e 67 4f 62 6a 28 22 4b 65 79 20 41 67 tringObj("Key Ag
2940: 72 65 65 6d 65 6e 74 22 2c 20 2d 31 29 29 3b 0a reement", -1));.
2950: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 .}..if (usage &
2960: 4b 55 5f 4b 45 59 5f 43 45 52 54 5f 53 49 47 4e KU_KEY_CERT_SIGN
2970: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 ) {.. Tcl_Lis
2980: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e tObjAppendElemen
2990: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 t(interp, listPt
29a0: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 r, Tcl_NewString
29b0: 4f 62 6a 28 22 43 65 72 74 69 66 69 63 61 74 65 Obj("Certificate
29c0: 20 53 69 67 6e 69 6e 67 22 2c 20 2d 31 29 29 3b Signing", -1));
29d0: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
29e0: 20 4b 55 5f 43 52 4c 5f 53 49 47 4e 29 20 7b 0a KU_CRL_SIGN) {.
29f0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
2a00: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
2a10: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 terp, listPtr, T
2a20: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
2a30: 22 43 52 4c 20 53 69 67 6e 69 6e 67 22 2c 20 2d "CRL Signing", -
2a40: 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 1));..}..if (usa
2a50: 67 65 20 26 20 4b 55 5f 45 4e 43 49 50 48 45 52 ge & KU_ENCIPHER
2a60: 5f 4f 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 63 _ONLY) {.. Tc
2a70: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
2a80: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
2a90: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
2aa0: 74 72 69 6e 67 4f 62 6a 28 22 45 6e 63 69 70 68 tringObj("Enciph
2ab0: 65 72 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b 0a er Only", -1));.
2ac0: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 .}..if (usage &
2ad0: 4b 55 5f 44 45 43 49 50 48 45 52 5f 4f 4e 4c 59 KU_DECIPHER_ONLY
2ae0: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 ) {.. Tcl_Lis
2af0: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e tObjAppendElemen
2b00: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 t(interp, listPt
2b10: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 r, Tcl_NewString
2b20: 4f 62 6a 28 22 44 65 63 69 70 68 65 72 20 4f 6e Obj("Decipher On
2b30: 6c 79 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 ly", -1));..}.
2b40: 20 20 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f }. LAPPEND_
2b50: 4c 49 53 54 28 69 6e 74 65 72 70 2c 20 63 65 72 LIST(interp, cer
2b60: 74 50 74 72 2c 20 22 6b 65 79 55 73 61 67 65 22 tPtr, "keyUsage"
2b70: 2c 20 6c 69 73 74 50 74 72 29 3b 0a 0a 20 20 20 , listPtr);..
2b80: 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65 20 /* Certificate
2b90: 50 75 72 70 6f 73 65 20 2a 2f 0a 20 20 20 20 7b Purpose */. {
2ba0: 0a 09 63 68 61 72 20 2a 70 75 72 70 6f 73 65 20 ..char *purpose
2bb0: 3d 20 4e 55 4c 4c 3b 0a 0a 09 69 66 20 28 58 35 = NULL;...if (X5
2bc0: 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 09_check_purpose
2bd0: 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 (cert, X509_PURP
2be0: 4f 53 45 5f 53 53 4c 5f 43 4c 49 45 4e 54 2c 20 OSE_SSL_CLIENT,
2bf0: 30 29 20 3e 20 30 29 20 7b 0a 09 20 20 20 20 70 0) > 0) {.. p
2c00: 75 72 70 6f 73 65 20 3d 20 22 53 53 4c 20 43 6c urpose = "SSL Cl
2c10: 69 65 6e 74 22 3b 0a 09 7d 20 65 6c 73 65 20 69 ient";..} else i
2c20: 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 f (X509_check_pu
2c30: 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 rpose(cert, X509
2c40: 5f 50 55 52 50 4f 53 45 5f 53 53 4c 5f 53 45 52 _PURPOSE_SSL_SER
2c50: 56 45 52 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 VER, 0) > 0) {..
2c60: 20 20 20 20 70 75 72 70 6f 73 65 20 3d 20 22 53 purpose = "S
2c70: 53 4c 20 53 65 72 76 65 72 22 3b 0a 09 7d 20 65 SL Server";..} e
2c80: 6c 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 lse if (X509_che
2c90: 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c ck_purpose(cert,
2ca0: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 4e 53 X509_PURPOSE_NS
2cb0: 5f 53 53 4c 5f 53 45 52 56 45 52 2c 20 30 29 20 _SSL_SERVER, 0)
2cc0: 3e 20 30 29 20 7b 0a 09 20 20 20 20 70 75 72 70 > 0) {.. purp
2cd0: 6f 73 65 20 3d 20 22 4d 53 53 20 53 53 4c 20 53 ose = "MSS SSL S
2ce0: 65 72 76 65 72 22 3b 0a 09 7d 20 65 6c 73 65 20 erver";..} else
2cf0: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 if (X509_check_p
2d00: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 urpose(cert, X50
2d10: 39 5f 50 55 52 50 4f 53 45 5f 53 4d 49 4d 45 5f 9_PURPOSE_SMIME_
2d20: 53 49 47 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a SIGN, 0) > 0) {.
2d30: 09 20 20 20 20 70 75 72 70 6f 73 65 20 3d 20 22 . purpose = "
2d40: 53 4d 49 4d 45 20 53 69 67 6e 69 6e 67 22 3b 0a SMIME Signing";.
2d50: 09 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 .} else if (X509
2d60: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 _check_purpose(c
2d70: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 ert, X509_PURPOS
2d80: 45 5f 53 4d 49 4d 45 5f 45 4e 43 52 59 50 54 2c E_SMIME_ENCRYPT,
2d90: 20 30 29 20 3e 20 30 29 20 7b 0a 09 20 20 20 20 0) > 0) {..
2da0: 70 75 72 70 6f 73 65 20 3d 20 22 53 4d 49 4d 45 purpose = "SMIME
2db0: 20 45 6e 63 72 79 70 74 69 6f 6e 22 3b 0a 09 7d Encryption";..}
2dc0: 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 5f 63 else if (X509_c
2dd0: 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 heck_purpose(cer
2de0: 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f t, X509_PURPOSE_
2df0: 43 52 4c 5f 53 49 47 4e 2c 20 30 29 20 3e 20 30 CRL_SIGN, 0) > 0
2e00: 29 20 7b 0a 09 20 20 20 20 70 75 72 70 6f 73 65 ) {.. purpose
2e10: 20 3d 20 22 43 52 4c 20 53 69 67 6e 69 6e 67 22 = "CRL Signing"
2e20: 3b 0a 09 7d 20 65 6c 73 65 20 69 66 20 28 58 35 ;..} else if (X5
2e30: 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 09_check_purpose
2e40: 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 (cert, X509_PURP
2e50: 4f 53 45 5f 41 4e 59 2c 20 30 29 20 3e 20 30 29 OSE_ANY, 0) > 0)
2e60: 20 7b 0a 09 20 20 20 20 70 75 72 70 6f 73 65 20 {.. purpose
2e70: 3d 20 22 41 6e 79 22 3b 0a 09 7d 20 65 6c 73 65 = "Any";..} else
2e80: 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f if (X509_check_
2e90: 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 purpose(cert, X5
2ea0: 30 39 5f 50 55 52 50 4f 53 45 5f 4f 43 53 50 5f 09_PURPOSE_OCSP_
2eb0: 48 45 4c 50 45 52 2c 20 30 29 20 3e 20 30 29 20 HELPER, 0) > 0)
2ec0: 7b 0a 09 20 20 20 20 70 75 72 70 6f 73 65 20 3d {.. purpose =
2ed0: 20 22 4f 43 53 50 20 48 65 6c 70 65 72 22 3b 0a "OCSP Helper";.
2ee0: 09 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 39 .} else if (X509
2ef0: 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 63 _check_purpose(c
2f00: 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 ert, X509_PURPOS
2f10: 45 5f 54 49 4d 45 53 54 41 4d 50 5f 53 49 47 4e E_TIMESTAMP_SIGN
2f20: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 20 20 20 , 0) > 0) {..
2f30: 20 70 75 72 70 6f 73 65 20 3d 20 22 54 69 6d 65 purpose = "Time
2f40: 73 74 61 6d 70 20 53 69 67 6e 69 6e 67 22 3b 0a stamp Signing";.
2f50: 09 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 70 .} else {.. p
2f60: 75 72 70 6f 73 65 20 3d 20 22 22 3b 0a 09 7d 0a urpose = "";..}.
2f70: 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 .LAPPEND_STR(int
2f80: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 erp, certPtr, "p
2f90: 75 72 70 6f 73 65 22 2c 20 70 75 72 70 6f 73 65 urpose", purpose
2fa0: 2c 20 2d 31 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 , -1);. }..
2fb0: 20 20 2f 2a 20 47 65 74 20 70 75 72 70 6f 73 65 /* Get purpose
2fc0: 73 20 2a 2f 0a 20 20 20 20 6c 69 73 74 50 74 72 s */. listPtr
2fd0: 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 = Tcl_NewListOb
2fe0: 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 09 66 6f 72 j(0, NULL);..for
2ff0: 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20 6a 20 3c (int j = 0; j <
3000: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 X509_PURPOSE_ge
3010: 74 5f 63 6f 75 6e 74 28 29 3b 20 6a 2b 2b 29 20 t_count(); j++)
3020: 7b 0a 09 20 20 20 20 58 35 30 39 5f 50 55 52 50 {.. X509_PURP
3030: 4f 53 45 20 2a 70 74 6d 70 20 3d 20 58 35 30 39 OSE *ptmp = X509
3040: 5f 50 55 52 50 4f 53 45 5f 67 65 74 30 28 6a 29 _PURPOSE_get0(j)
3050: 3b 0a 09 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a ;.. Tcl_Obj *
3060: 74 6d 70 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 tmpPtr = Tcl_New
3070: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 ListObj(0, NULL)
3080: 3b 0a 0a 09 20 20 20 20 66 6f 72 20 28 69 6e 74 ;... for (int
3090: 20 69 20 3d 20 30 3b 20 69 20 3c 20 32 3b 20 69 i = 0; i < 2; i
30a0: 2b 2b 29 20 7b 0a 09 09 69 6e 74 20 69 64 72 65 ++) {...int idre
30b0: 74 20 3d 20 58 35 30 39 5f 63 68 65 63 6b 5f 70 t = X509_check_p
30c0: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 urpose(cert, X50
30d0: 39 5f 50 55 52 50 4f 53 45 5f 67 65 74 5f 69 64 9_PURPOSE_get_id
30e0: 28 70 74 6d 70 29 2c 20 69 29 3b 0a 09 09 54 63 (ptmp), i);...Tc
30f0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
3100: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 74 lement(interp, t
3110: 6d 70 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 mpPtr, Tcl_NewSt
3120: 72 69 6e 67 4f 62 6a 28 69 20 3f 20 22 43 41 22 ringObj(i ? "CA"
3130: 20 3a 20 22 6e 6f 6e 43 41 22 2c 20 2d 31 29 29 : "nonCA", -1))
3140: 3b 0a 09 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 ;...Tcl_ListObjA
3150: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
3160: 65 72 70 2c 20 74 6d 70 50 74 72 2c 20 54 63 6c erp, tmpPtr, Tcl
3170: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 69 64 _NewStringObj(id
3180: 72 65 74 20 3d 3d 20 31 20 3f 20 22 59 65 73 22 ret == 1 ? "Yes"
3190: 20 3a 20 22 4e 6f 22 2c 20 2d 31 29 29 3b 0a 09 : "No", -1));..
31a0: 20 20 20 20 7d 0a 09 4c 41 50 50 45 4e 44 5f 4c }..LAPPEND_L
31b0: 49 53 54 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 IST(interp, list
31c0: 50 74 72 2c 20 58 35 30 39 5f 50 55 52 50 4f 53 Ptr, X509_PURPOS
31d0: 45 5f 67 65 74 30 5f 6e 61 6d 65 28 70 74 6d 70 E_get0_name(ptmp
31e0: 29 2c 20 74 6d 70 50 74 72 29 3b 0a 20 20 20 20 ), tmpPtr);.
31f0: 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 49 }. LAPPEND_LI
3200: 53 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 ST(interp, certP
3210: 74 72 2c 20 22 63 65 72 74 69 66 69 63 61 74 65 tr, "certificate
3220: 50 75 72 70 6f 73 65 22 2c 20 6c 69 73 74 50 74 Purpose", listPt
3230: 72 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 r);.. /* Cert
3240: 69 66 69 63 61 74 65 20 50 6f 6c 69 63 69 65 73 ificate Policies
3250: 20 2d 20 69 6e 64 69 63 61 74 65 73 20 74 68 65 - indicates the
3260: 20 69 73 73 75 69 6e 67 20 43 41 20 63 6f 6e 73 issuing CA cons
3270: 69 64 65 72 73 20 69 74 73 20 69 73 73 75 65 72 iders its issuer
3280: 44 6f 6d 61 69 6e 50 6f 6c 69 63 79 0a 09 65 71 DomainPolicy..eq
3290: 75 69 76 61 6c 65 6e 74 20 74 6f 20 74 68 65 20 uivalent to the
32a0: 73 75 62 6a 65 63 74 20 43 41 27 73 20 73 75 62 subject CA's sub
32b0: 6a 65 63 74 44 6f 6d 61 69 6e 50 6f 6c 69 63 79 jectDomainPolicy
32c0: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
32d0: 6f 6e 20 34 2e 32 2e 31 2e 34 2c 20 4e 49 44 5f on 4.2.1.4, NID_
32e0: 63 65 72 74 69 66 69 63 61 74 65 5f 70 6f 6c 69 certificate_poli
32f0: 63 69 65 73 20 2a 2f 0a 20 20 20 20 69 66 20 28 cies */. if (
3300: 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f xflags & EXFLAG_
3310: 49 4e 56 41 4c 49 44 5f 50 4f 4c 49 43 59 29 20 INVALID_POLICY)
3320: 7b 0a 09 2f 2a 20 52 65 6a 65 63 74 20 63 65 72 {../* Reject cer
3330: 74 20 2a 2f 0a 20 20 20 20 7d 0a 0a 20 20 20 20 t */. }..
3340: 2f 2a 20 50 6f 6c 69 63 79 20 4d 61 70 70 69 6e /* Policy Mappin
3350: 67 73 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 gs - RFC 5280 se
3360: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 35 2c 20 4e ction 4.2.1.5, N
3370: 49 44 5f 70 6f 6c 69 63 79 5f 6d 61 70 70 69 6e ID_policy_mappin
3380: 67 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 53 75 gs */.. /* Su
3390: 62 6a 65 63 74 20 41 6c 74 65 72 6e 61 74 69 76 bject Alternativ
33a0: 65 20 4e 61 6d 65 20 28 53 41 4e 29 20 63 6f 6e e Name (SAN) con
33b0: 74 61 69 6e 73 20 61 64 64 69 74 69 6f 6e 61 6c tains additional
33c0: 20 55 52 4c 73 2c 20 44 4e 53 20 6e 61 6d 65 73 URLs, DNS names
33d0: 2c 20 6f 72 20 49 50 0a 09 61 64 64 72 65 73 73 , or IP..address
33e0: 65 73 20 62 6f 75 6e 64 20 74 6f 20 63 65 72 74 es bound to cert
33f0: 69 66 69 63 61 74 65 2e 20 52 46 43 20 35 32 38 ificate. RFC 528
3400: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 0 section 4.2.1.
3410: 36 2c 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f 61 6, NID_subject_a
3420: 6c 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 6c lt_name */. l
3430: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 istPtr = Tcl_New
3440: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 ListObj(0, NULL)
3450: 3b 0a 20 20 20 20 69 66 20 28 6e 61 6d 65 73 20 ;. if (names
3460: 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 = X509_get_ext_d
3470: 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 73 75 62 2i(cert, NID_sub
3480: 6a 65 63 74 5f 61 6c 74 5f 6e 61 6d 65 2c 20 4e ject_alt_name, N
3490: 55 4c 4c 2c 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 ULL, NULL)) {..f
34a0: 6f 72 20 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c or (int i=0; i <
34b0: 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 sk_GENERAL_NAME
34c0: 5f 6e 75 6d 28 6e 61 6d 65 73 29 3b 20 69 2b 2b _num(names); i++
34d0: 29 20 7b 0a 09 20 20 20 20 63 6f 6e 73 74 20 47 ) {.. const G
34e0: 45 4e 45 52 41 4c 5f 4e 41 4d 45 20 2a 6e 61 6d ENERAL_NAME *nam
34f0: 65 20 3d 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e e = sk_GENERAL_N
3500: 41 4d 45 5f 76 61 6c 75 65 28 6e 61 6d 65 73 2c AME_value(names,
3510: 20 69 29 3b 0a 0a 09 20 20 20 20 6c 65 6e 20 3d i);... len =
3520: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 6e BIO_to_Buffer(n
3530: 61 6d 65 20 26 26 20 47 45 4e 45 52 41 4c 5f 4e ame && GENERAL_N
3540: 41 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 6e AME_print(bio, n
3550: 61 6d 65 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 ame), bio, buffe
3560: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 20 20 20 r, 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 6c 69 73 74 50 74 72 2c 20 4e 55 erp, listPtr, NU
3590: 4c 4c 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 LL, buffer, len)
35a0: 3b 0a 09 7d 0a 09 73 6b 5f 47 45 4e 45 52 41 4c ;..}..sk_GENERAL
35b0: 5f 4e 41 4d 45 5f 70 6f 70 5f 66 72 65 65 28 6e _NAME_pop_free(n
35c0: 61 6d 65 73 2c 20 47 45 4e 45 52 41 4c 5f 4e 41 ames, GENERAL_NA
35d0: 4d 45 5f 66 72 65 65 29 3b 0a 20 20 20 20 7d 0a ME_free);. }.
35e0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 49 53 54 LAPPEND_LIST
35f0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3600: 2c 20 22 73 75 62 6a 65 63 74 41 6c 74 4e 61 6d , "subjectAltNam
3610: 65 22 2c 20 6c 69 73 74 50 74 72 29 3b 0a 0a 20 e", listPtr);..
3620: 20 20 20 2f 2a 20 49 73 73 75 65 72 20 41 6c 74 /* Issuer Alt
3630: 65 72 6e 61 74 69 76 65 20 4e 61 6d 65 20 69 73 ernative Name is
3640: 20 75 73 65 64 20 74 6f 20 61 73 73 6f 63 69 61 used to associa
3650: 74 65 20 49 6e 74 65 72 6e 65 74 20 73 74 79 6c te Internet styl
3660: 65 20 69 64 65 6e 74 69 74 69 65 73 0a 09 77 69 e identities..wi
3670: 74 68 20 74 68 65 20 63 65 72 74 69 66 69 63 61 th the certifica
3680: 74 65 20 69 73 73 75 65 72 2e 20 52 46 43 20 35 te issuer. RFC 5
3690: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 280 section 4.2.
36a0: 31 2e 37 2c 20 4e 49 44 5f 69 73 73 75 65 72 5f 1.7, NID_issuer_
36b0: 61 6c 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 alt_name */.
36c0: 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 listPtr = Tcl_Ne
36d0: 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c wListObj(0, NULL
36e0: 29 3b 0a 20 20 20 20 69 66 20 28 6e 61 6d 65 73 );. if (names
36f0: 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f = X509_get_ext_
3700: 64 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 69 73 d2i(cert, NID_is
3710: 73 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 2c 20 4e suer_alt_name, N
3720: 55 4c 4c 2c 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 ULL, NULL)) {..f
3730: 6f 72 20 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c or (int i=0; i <
3740: 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 sk_GENERAL_NAME
3750: 5f 6e 75 6d 28 6e 61 6d 65 73 29 3b 20 69 2b 2b _num(names); i++
3760: 29 20 7b 0a 09 20 20 20 20 63 6f 6e 73 74 20 47 ) {.. const G
3770: 45 4e 45 52 41 4c 5f 4e 41 4d 45 20 2a 6e 61 6d ENERAL_NAME *nam
3780: 65 20 3d 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e e = sk_GENERAL_N
3790: 41 4d 45 5f 76 61 6c 75 65 28 6e 61 6d 65 73 2c AME_value(names,
37a0: 20 69 29 3b 0a 0a 09 20 20 20 20 6c 65 6e 20 3d i);... len =
37b0: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 6e BIO_to_Buffer(n
37c0: 61 6d 65 20 26 26 20 47 45 4e 45 52 41 4c 5f 4e ame && GENERAL_N
37d0: 41 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 6e AME_print(bio, n
37e0: 61 6d 65 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 ame), bio, buffe
37f0: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 20 20 20 r, BUFSIZ);..
3800: 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 LAPPEND_STR(int
3810: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 erp, listPtr, NU
3820: 4c 4c 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 LL, buffer, len)
3830: 3b 0a 09 7d 0a 09 73 6b 5f 47 45 4e 45 52 41 4c ;..}..sk_GENERAL
3840: 5f 4e 41 4d 45 5f 70 6f 70 5f 66 72 65 65 28 6e _NAME_pop_free(n
3850: 61 6d 65 73 2c 20 47 45 4e 45 52 41 4c 5f 4e 41 ames, GENERAL_NA
3860: 4d 45 5f 66 72 65 65 29 3b 0a 20 20 20 20 7d 0a ME_free);. }.
3870: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 49 53 54 LAPPEND_LIST
3880: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3890: 2c 20 22 69 73 73 75 65 72 41 6c 74 4e 61 6d 65 , "issuerAltName
38a0: 22 2c 20 6c 69 73 74 50 74 72 29 3b 0a 0a 20 20 ", listPtr);..
38b0: 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 44 69 72 /* Subject Dir
38c0: 65 63 74 6f 72 79 20 41 74 74 72 69 62 75 74 65 ectory Attribute
38d0: 73 20 70 72 6f 76 69 64 65 73 20 69 64 65 6e 74 s provides ident
38e0: 69 66 69 63 61 74 69 6f 6e 20 61 74 74 72 69 62 ification attrib
38f0: 75 74 65 73 20 28 65 2e 67 2e 2c 20 6e 61 74 69 utes (e.g., nati
3900: 6f 6e 61 6c 69 74 79 29 0a 09 6f 66 20 74 68 65 onality)..of the
3910: 20 73 75 62 6a 65 63 74 2e 20 52 46 43 20 35 32 subject. RFC 52
3920: 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 80 section 4.2.1
3930: 2e 38 20 28 73 75 62 6a 65 63 74 44 69 72 65 63 .8 (subjectDirec
3940: 74 6f 72 79 41 74 74 72 69 62 75 74 65 73 29 20 toryAttributes)
3950: 2a 2f 0a 0a 20 20 20 20 2f 2a 20 42 61 73 69 63 */.. /* Basic
3960: 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 64 65 Constraints ide
3970: 6e 74 69 66 69 65 73 20 77 68 65 74 68 65 72 20 ntifies whether
3980: 74 68 65 20 73 75 62 6a 65 63 74 20 6f 66 20 74 the subject of t
3990: 68 65 20 63 65 72 74 20 69 73 20 61 20 43 41 20 he cert is a CA
39a0: 61 6e 64 0a 09 74 68 65 20 6d 61 78 20 64 65 70 and..the max dep
39b0: 74 68 20 6f 66 20 76 61 6c 69 64 20 63 65 72 74 th of valid cert
39c0: 20 70 61 74 68 73 20 66 6f 72 20 74 68 69 73 20 paths for this
39d0: 63 65 72 74 2e 20 52 46 43 20 35 32 38 30 20 73 cert. RFC 5280 s
39e0: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 39 2c 20 ection 4.2.1.9,
39f0: 4e 49 44 5f 62 61 73 69 63 5f 63 6f 6e 73 74 72 NID_basic_constr
3a00: 61 69 6e 74 73 20 2a 2f 0a 20 20 20 20 69 66 20 aints */. if
3a10: 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 (xflags & EXFLAG
3a20: 5f 42 43 4f 4e 53 29 20 7b 0a 09 4c 41 50 50 45 _BCONS) {..LAPPE
3a30: 4e 44 5f 4c 4f 4e 47 28 69 6e 74 65 72 70 2c 20 ND_LONG(interp,
3a40: 63 65 72 74 50 74 72 2c 20 22 70 61 74 68 4c 65 certPtr, "pathLe
3a50: 6e 22 2c 20 58 35 30 39 5f 67 65 74 5f 70 61 74 n", X509_get_pat
3a60: 68 6c 65 6e 28 63 65 72 74 29 29 3b 0a 20 20 20 hlen(cert));.
3a70: 20 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 }. LAPPEND_B
3a80: 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 OOL(interp, cert
3a90: 50 74 72 2c 20 22 62 61 73 69 63 43 6f 6e 73 74 Ptr, "basicConst
3aa0: 72 61 69 6e 74 73 43 41 22 2c 20 78 66 6c 61 67 raintsCA", xflag
3ab0: 73 20 26 20 45 58 46 4c 41 47 5f 43 41 29 3b 0a s & EXFLAG_CA);.
3ac0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c LAPPEND_BOOL
3ad0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3ae0: 2c 20 22 62 61 73 69 63 43 6f 6e 73 74 72 61 69 , "basicConstrai
3af0: 6e 74 73 43 72 69 74 69 63 61 6c 22 2c 20 78 66 ntsCritical", xf
3b00: 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 43 52 lags & EXFLAG_CR
3b10: 49 54 49 43 41 4c 29 3b 0a 0a 20 20 20 20 2f 2a ITICAL);.. /*
3b20: 20 4e 61 6d 65 20 43 6f 6e 73 74 72 61 69 6e 74 Name Constraint
3b30: 73 20 69 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 s is only used i
3b40: 6e 20 43 41 20 63 65 72 74 73 20 74 6f 20 69 6e n CA certs to in
3b50: 64 69 63 61 74 65 20 74 68 65 20 6e 61 6d 65 20 dicate the name
3b60: 73 70 61 63 65 20 66 6f 72 0a 09 61 6c 6c 20 73 space for..all s
3b70: 75 62 6a 65 63 74 20 6e 61 6d 65 73 20 69 6e 20 ubject names in
3b80: 73 75 62 73 65 71 75 65 6e 74 20 63 65 72 74 69 subsequent certi
3b90: 66 69 63 61 74 65 73 20 69 6e 20 61 20 63 65 72 ficates in a cer
3ba0: 74 69 66 69 63 61 74 69 6f 6e 20 70 61 74 68 0a tification path.
3bb0: 09 4d 55 53 54 20 62 65 20 6c 6f 63 61 74 65 64 .MUST be located
3bc0: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
3bd0: 6f 6e 20 34 2e 32 2e 31 2e 31 30 2c 20 4e 49 44 on 4.2.1.10, NID
3be0: 5f 6e 61 6d 65 5f 63 6f 6e 73 74 72 61 69 6e 74 _name_constraint
3bf0: 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 50 6f 6c s */.. /* Pol
3c00: 69 63 79 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 icy Constraints
3c10: 69 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e 20 is only used in
3c20: 43 41 20 63 65 72 74 73 20 74 6f 20 6c 69 6d 69 CA certs to limi
3c30: 74 20 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 20 t the length of
3c40: 61 0a 09 63 65 72 74 20 63 68 61 69 6e 20 66 6f a..cert chain fo
3c50: 72 20 74 68 61 74 20 43 41 2e 20 52 46 43 20 35 r that CA. RFC 5
3c60: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 280 section 4.2.
3c70: 31 2e 31 31 2c 20 4e 49 44 5f 70 6f 6c 69 63 79 1.11, NID_policy
3c80: 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f 0a _constraints */.
3c90: 0a 20 20 20 20 2f 2a 20 45 78 74 65 6e 64 65 64 . /* Extended
3ca0: 20 4b 65 79 20 55 73 61 67 65 20 69 6e 64 69 63 Key Usage indic
3cb0: 61 74 65 73 20 74 68 65 20 70 75 72 70 6f 73 65 ates the purpose
3cc0: 73 20 74 68 65 20 63 65 72 74 69 66 69 65 64 20 s the certified
3cd0: 70 75 62 6c 69 63 20 6b 65 79 20 6d 61 79 20 62 public key may b
3ce0: 65 0a 09 75 73 65 64 2c 20 62 65 79 6f 6e 64 20 e..used, beyond
3cf0: 74 68 65 20 62 61 73 69 63 20 70 75 72 70 6f 73 the basic purpos
3d00: 65 73 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 es. RFC 5280 sec
3d10: 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 32 2c 20 4e tion 4.2.1.12, N
3d20: 49 44 5f 65 78 74 5f 6b 65 79 5f 75 73 61 67 65 ID_ext_key_usage
3d30: 20 2a 2f 0a 20 20 20 20 6c 69 73 74 50 74 72 20 */. listPtr
3d40: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a = Tcl_NewListObj
3d50: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 69 (0, NULL);. i
3d60: 66 20 28 78 66 6c 61 67 73 20 26 20 45 58 46 4c f (xflags & EXFL
3d70: 41 47 5f 58 4b 55 53 41 47 45 29 20 7b 0a 09 75 AG_XKUSAGE) {..u
3d80: 73 61 67 65 20 3d 20 58 35 30 39 5f 67 65 74 5f sage = X509_get_
3d90: 65 78 74 65 6e 64 65 64 5f 6b 65 79 5f 75 73 61 extended_key_usa
3da0: 67 65 28 63 65 72 74 29 3b 0a 0a 09 69 66 20 28 ge(cert);...if (
3db0: 75 73 61 67 65 20 26 20 58 4b 55 5f 53 53 4c 5f usage & XKU_SSL_
3dc0: 53 45 52 56 45 52 29 20 7b 0a 09 20 20 20 20 54 SERVER) {.. T
3dd0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
3de0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
3df0: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
3e00: 53 74 72 69 6e 67 4f 62 6a 28 22 54 4c 53 20 57 StringObj("TLS W
3e10: 65 62 20 53 65 72 76 65 72 20 41 75 74 68 65 6e eb Server Authen
3e20: 74 69 63 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b tication", -1));
3e30: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
3e40: 20 58 4b 55 5f 53 53 4c 5f 43 4c 49 45 4e 54 29 XKU_SSL_CLIENT)
3e50: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 {.. Tcl_List
3e60: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 ObjAppendElement
3e70: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 (interp, listPtr
3e80: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f , Tcl_NewStringO
3e90: 62 6a 28 22 54 4c 53 20 57 65 62 20 43 6c 69 65 bj("TLS Web Clie
3ea0: 6e 74 20 41 75 74 68 65 6e 74 69 63 61 74 69 6f nt Authenticatio
3eb0: 6e 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 n", -1));..}..if
3ec0: 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 53 4d (usage & XKU_SM
3ed0: 49 4d 45 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f IME) {.. Tcl_
3ee0: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
3ef0: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 ment(interp, lis
3f00: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 tPtr, Tcl_NewStr
3f10: 69 6e 67 4f 62 6a 28 22 45 2d 6d 61 69 6c 20 50 ingObj("E-mail P
3f20: 72 6f 74 65 63 74 69 6f 6e 22 2c 20 2d 31 29 29 rotection", -1))
3f30: 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 ;..}..if (usage
3f40: 26 20 58 4b 55 5f 43 4f 44 45 5f 53 49 47 4e 29 & XKU_CODE_SIGN)
3f50: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 {.. Tcl_List
3f60: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 ObjAppendElement
3f70: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 (interp, listPtr
3f80: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f , Tcl_NewStringO
3f90: 62 6a 28 22 43 6f 64 65 20 53 69 67 6e 69 6e 67 bj("Code Signing
3fa0: 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 ", -1));..}..if
3fb0: 28 75 73 61 67 65 20 26 20 58 4b 55 5f 53 47 43 (usage & XKU_SGC
3fc0: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 ) {.. Tcl_Lis
3fd0: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e tObjAppendElemen
3fe0: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 t(interp, listPt
3ff0: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 r, Tcl_NewString
4000: 4f 62 6a 28 22 53 47 43 22 2c 20 2d 31 29 29 3b Obj("SGC", -1));
4010: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
4020: 20 58 4b 55 5f 4f 43 53 50 5f 53 49 47 4e 29 20 XKU_OCSP_SIGN)
4030: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f {.. Tcl_ListO
4040: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 bjAppendElement(
4050: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
4060: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
4070: 6a 28 22 4f 43 53 50 20 53 69 67 6e 69 6e 67 22 j("OCSP Signing"
4080: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 , -1));..}..if (
4090: 75 73 61 67 65 20 26 20 58 4b 55 5f 54 49 4d 45 usage & XKU_TIME
40a0: 53 54 41 4d 50 29 20 7b 0a 09 20 20 20 20 54 63 STAMP) {.. Tc
40b0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
40c0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
40d0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
40e0: 74 72 69 6e 67 4f 62 6a 28 22 54 69 6d 65 20 53 tringObj("Time S
40f0: 74 61 6d 70 69 6e 67 22 2c 20 2d 31 29 29 3b 0a tamping", -1));.
4100: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 .}..if (usage &
4110: 58 4b 55 5f 44 56 43 53 20 29 20 7b 0a 09 20 20 XKU_DVCS ) {..
4120: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
4130: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
4140: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f p, listPtr, Tcl_
4150: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 56 NewStringObj("DV
4160: 43 53 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 CS", -1));..}..i
4170: 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 41 f (usage & XKU_A
4180: 4e 59 45 4b 55 29 20 7b 0a 09 20 20 20 20 54 63 NYEKU) {.. Tc
4190: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
41a0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
41b0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
41c0: 74 72 69 6e 67 4f 62 6a 28 22 41 6e 79 20 45 78 tringObj("Any Ex
41d0: 74 65 6e 64 65 64 20 4b 65 79 20 55 73 61 67 65 tended Key Usage
41e0: 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 20 20 ", -1));..}.
41f0: 7d 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 49 }. LAPPEND_LI
4200: 53 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 ST(interp, certP
4210: 74 72 2c 20 22 65 78 74 65 6e 64 65 64 4b 65 79 tr, "extendedKey
4220: 55 73 61 67 65 22 2c 20 6c 69 73 74 50 74 72 29 Usage", listPtr)
4230: 3b 0a 0a 20 20 20 20 2f 2a 20 43 52 4c 20 44 69 ;.. /* CRL Di
4240: 73 74 72 69 62 75 74 69 6f 6e 20 50 6f 69 6e 74 stribution Point
4250: 73 20 69 64 65 6e 74 69 66 69 65 73 20 77 68 65 s identifies whe
4260: 72 65 20 43 52 4c 20 69 6e 66 6f 72 6d 61 74 69 re CRL informati
4270: 6f 6e 20 63 61 6e 20 62 65 20 6f 62 74 61 69 6e on can be obtain
4280: 65 64 2e 0a 09 52 46 43 20 35 32 38 30 20 73 65 ed...RFC 5280 se
4290: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 33 2a 2f ction 4.2.1.13*/
42a0: 0a 20 20 20 20 7b 0a 09 53 54 41 43 4b 5f 4f 46 . {..STACK_OF
42b0: 28 44 49 53 54 5f 50 4f 49 4e 54 29 20 2a 63 72 (DIST_POINT) *cr
42c0: 6c 3b 0a 09 6c 69 73 74 50 74 72 20 3d 20 54 63 l;..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 0a 09 69 66 20 28 63 72 6c NULL);...if (crl
42f0: 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f = X509_get_ext_
4300: 64 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 63 72 d2i(cert, NID_cr
4310: 6c 5f 64 69 73 74 72 69 62 75 74 69 6f 6e 5f 70 l_distribution_p
4320: 6f 69 6e 74 73 2c 20 4e 55 4c 4c 2c 20 4e 55 4c oints, NULL, NUL
4330: 4c 29 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4f L)) {.. Tcl_O
4340: 62 6a 20 2a 6e 61 6d 65 73 50 74 72 20 3d 20 54 bj *namesPtr = T
4350: 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 2c cl_NewListObj(0,
4360: 20 4e 55 4c 4c 29 3b 0a 0a 09 20 20 20 20 66 6f NULL);... fo
4370: 72 20 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20 r (int i=0; i <
4380: 73 6b 5f 44 49 53 54 5f 50 4f 49 4e 54 5f 6e 75 sk_DIST_POINT_nu
4390: 6d 28 63 72 6c 29 3b 20 69 2b 2b 29 20 7b 0a 09 m(crl); i++) {..
43a0: 09 44 49 53 54 5f 50 4f 49 4e 54 20 2a 64 70 20 .DIST_POINT *dp
43b0: 3d 20 73 6b 5f 44 49 53 54 5f 50 4f 49 4e 54 5f = sk_DIST_POINT_
43c0: 76 61 6c 75 65 28 63 72 6c 2c 20 69 29 3b 0a 09 value(crl, i);..
43d0: 09 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 09 ->distpoint;....
4400: 69 66 20 28 64 69 73 74 70 6f 69 6e 74 2d 3e 74 if (distpoint->t
4410: 79 70 65 20 3d 3d 20 30 29 20 7b 0a 09 09 20 20 ype == 0) {...
4420: 20 20 2f 2a 20 66 75 6c 6c 6e 61 6d 65 20 47 45 /* fullname GE
4430: 4e 45 52 41 4c 49 5a 45 44 4e 41 4d 45 20 2a 2f NERALIZEDNAME */
4440: 0a 09 09 20 20 20 20 66 6f 72 20 28 69 6e 74 20 ... for (int
4450: 6a 20 3d 20 30 3b 20 6a 20 3c 20 73 6b 5f 47 45 j = 0; j < sk_GE
4460: 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 64 NERAL_NAME_num(d
4470: 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66 istpoint->name.f
4480: 75 6c 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20 7b ullname); j++) {
4490: 0a 09 09 09 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 ....GENERAL_NAME
44a0: 20 2a 67 65 6e 20 3d 20 73 6b 5f 47 45 4e 45 52 *gen = sk_GENER
44b0: 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75 65 28 64 69 AL_NAME_value(di
44c0: 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e 66 75 stpoint->name.fu
44d0: 6c 6c 6e 61 6d 65 2c 20 6a 29 3b 0a 09 09 09 69 llname, j);....i
44e0: 6e 74 20 74 79 70 65 3b 0a 09 09 09 41 53 4e 31 nt type;....ASN1
44f0: 5f 53 54 52 49 4e 47 20 2a 75 72 69 20 3d 20 47 _STRING *uri = G
4500: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 67 65 74 30 ENERAL_NAME_get0
4510: 5f 76 61 6c 75 65 28 67 65 6e 2c 20 26 74 79 70 _value(gen, &typ
4520: 65 29 3b 0a 09 09 09 69 66 20 28 74 79 70 65 20 e);....if (type
4530: 3d 3d 20 47 45 4e 5f 55 52 49 29 20 7b 0a 09 09 == GEN_URI) {...
4540: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
4550: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
4560: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 0a 09 terp, listPtr,..
4570: 09 09 09 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 ...Tcl_NewString
4580: 4f 62 6a 28 28 63 68 61 72 2a 29 41 53 4e 31 5f Obj((char*)ASN1_
4590: 53 54 52 49 4e 47 5f 67 65 74 30 5f 64 61 74 61 STRING_get0_data
45a0: 28 75 72 69 29 2c 20 41 53 4e 31 5f 53 54 52 49 (uri), ASN1_STRI
45b0: 4e 47 5f 6c 65 6e 67 74 68 28 75 72 69 29 29 29 NG_length(uri)))
45c0: 3b 0a 09 09 09 7d 0a 09 09 20 20 20 20 7d 0a 09 ;....}... }..
45d0: 09 7d 20 65 6c 73 65 20 69 66 20 28 64 69 73 74 .} else if (dist
45e0: 70 6f 69 6e 74 2d 3e 74 79 70 65 20 3d 3d 20 31 point->type == 1
45f0: 29 20 7b 0a 09 09 20 20 20 20 2f 2a 20 72 65 6c ) {... /* rel
4600: 61 74 69 76 65 6e 61 6d 65 20 58 35 30 39 4e 41 ativename X509NA
4610: 4d 45 20 2a 2f 0a 09 09 20 20 20 20 53 54 41 43 ME */... 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 20 20 20 20 66 6f 72 20 28 69 6e 74 ;... for (int
4670: 20 6a 20 3d 20 30 3b 20 6a 20 3c 20 73 6b 5f 58 j = 0; j < sk_X
4680: 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 6e 509_NAME_ENTRY_n
4690: 75 6d 28 73 6b 5f 72 65 6c 6e 61 6d 65 29 3b 20 um(sk_relname);
46a0: 6a 2b 2b 29 20 7b 0a 09 09 09 58 35 30 39 5f 4e j++) {....X509_N
46b0: 41 4d 45 5f 45 4e 54 52 59 20 2a 65 20 3d 20 73 AME_ENTRY *e = s
46c0: 6b 5f 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 k_X509_NAME_ENTR
46d0: 59 5f 76 61 6c 75 65 28 73 6b 5f 72 65 6c 6e 61 Y_value(sk_relna
46e0: 6d 65 2c 20 6a 29 3b 0a 09 09 09 41 53 4e 31 5f me, j);....ASN1_
46f0: 53 54 52 49 4e 47 20 2a 64 20 3d 20 58 35 30 39 STRING *d = X509
4700: 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 67 65 74 5f _NAME_ENTRY_get_
4710: 64 61 74 61 28 65 29 3b 0a 09 09 09 54 63 6c 5f data(e);....Tcl_
4720: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
4730: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 ment(interp, lis
4740: 74 50 74 72 2c 0a 09 09 09 20 20 20 20 54 63 6c tPtr,.... Tcl
4750: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 28 63 _NewStringObj((c
4760: 68 61 72 2a 29 41 53 4e 31 5f 53 54 52 49 4e 47 har*)ASN1_STRING
4770: 5f 64 61 74 61 28 64 29 2c 20 41 53 4e 31 5f 53 _data(d), ASN1_S
4780: 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 64 29 29 TRING_length(d))
4790: 29 3b 0a 09 09 20 20 20 20 7d 0a 09 09 7d 0a 09 );... }...}..
47a0: 20 20 20 20 7d 0a 09 20 20 20 20 43 52 4c 5f 44 }.. CRL_D
47b0: 49 53 54 5f 50 4f 49 4e 54 53 5f 66 72 65 65 28 IST_POINTS_free(
47c0: 63 72 6c 29 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e crl);..}..LAPPEN
47d0: 44 5f 4c 49 53 54 28 69 6e 74 65 72 70 2c 20 63 D_LIST(interp, c
47e0: 65 72 74 50 74 72 2c 20 22 63 72 6c 44 69 73 74 ertPtr, "crlDist
47f0: 72 69 62 75 74 69 6f 6e 50 6f 69 6e 74 73 22 2c ributionPoints",
4800: 20 6c 69 73 74 50 74 72 29 3b 0a 20 20 20 20 7d listPtr);. }
4810: 0a 0a 20 20 20 20 2f 2a 20 46 72 65 73 68 65 73 .. /* Freshes
4820: 74 20 43 52 4c 20 65 78 74 65 6e 73 69 6f 6e 20 t CRL extension
4830: 2a 2f 0a 20 20 20 20 69 66 20 28 78 66 6c 61 67 */. if (xflag
4840: 73 20 26 20 45 58 46 4c 41 47 5f 46 52 45 53 48 s & EXFLAG_FRESH
4850: 45 53 54 29 20 7b 0a 20 20 20 20 7d 0a 0a 20 20 EST) {. }..
4860: 20 20 2f 2a 20 41 75 74 68 6f 72 69 74 79 20 49 /* Authority I
4870: 6e 66 6f 72 6d 61 74 69 6f 6e 20 41 63 63 65 73 nformation Acces
4880: 73 20 69 6e 64 69 63 61 74 65 73 20 68 6f 77 20 s indicates how
4890: 74 6f 20 61 63 63 65 73 73 20 69 6e 66 6f 20 61 to access info a
48a0: 6e 64 20 73 65 72 76 69 63 65 73 0a 09 66 6f 72 nd services..for
48b0: 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 the certificate
48c0: 20 69 73 73 75 65 72 2e 20 52 46 43 20 35 32 38 issuer. RFC 528
48d0: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 32 2e 0 section 4.2.2.
48e0: 31 2c 20 4e 49 44 5f 69 6e 66 6f 5f 61 63 63 65 1, NID_info_acce
48f0: 73 73 20 2a 2f 0a 20 20 20 20 2f 2a 20 47 65 74 ss */. /* Get
4900: 20 4f 6e 2d 6c 69 6e 65 20 43 65 72 74 69 66 69 On-line Certifi
4910: 63 61 74 65 20 53 74 61 74 75 73 20 50 72 6f 74 cate Status Prot
4920: 6f 63 6f 6c 20 28 4f 53 43 50 29 20 55 52 4c 20 ocol (OSCP) URL
4930: 2a 2f 0a 20 20 20 20 7b 0a 09 53 54 41 43 4b 5f */. {..STACK_
4940: 4f 46 28 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e OF(OPENSSL_STRIN
4950: 47 29 20 2a 6f 63 73 70 3b 0a 09 6c 69 73 74 50 G) *ocsp;..listP
4960: 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 tr = Tcl_NewList
4970: 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 Obj(0, NULL);...
4980: 69 66 20 28 6f 63 73 70 20 3d 20 58 35 30 39 5f if (ocsp = X509_
4990: 67 65 74 31 5f 6f 63 73 70 28 63 65 72 74 29 29 get1_ocsp(cert))
49a0: 20 7b 0a 09 20 20 20 20 66 6f 72 20 28 69 6e 74 {.. for (int
49b0: 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b 5f 4f i = 0; i < sk_O
49c0: 50 45 4e 53 53 4c 5f 53 54 52 49 4e 47 5f 6e 75 PENSSL_STRING_nu
49d0: 6d 28 6f 63 73 70 29 3b 20 69 2b 2b 29 20 7b 0a m(ocsp); i++) {.
49e0: 09 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 ..Tcl_ListObjApp
49f0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
4a00: 70 2c 20 6c 69 73 74 50 74 72 2c 0a 09 09 20 20 p, listPtr,...
4a10: 20 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f Tcl_NewStringO
4a20: 62 6a 28 73 6b 5f 4f 50 45 4e 53 53 4c 5f 53 54 bj(sk_OPENSSL_ST
4a30: 52 49 4e 47 5f 76 61 6c 75 65 28 6f 63 73 70 2c RING_value(ocsp,
4a40: 20 69 29 2c 20 2d 31 29 29 3b 0a 09 20 20 20 20 i), -1));..
4a50: 7d 0a 09 20 20 20 20 58 35 30 39 5f 65 6d 61 69 }.. X509_emai
4a60: 6c 5f 66 72 65 65 28 6f 63 73 70 29 3b 0a 09 20 l_free(ocsp);..
4a70: 20 20 20 2f 2a 20 73 6b 5f 4f 50 45 4e 53 53 4c /* sk_OPENSSL
4a80: 5f 53 54 52 49 4e 47 5f 66 72 65 65 28 6f 63 73 _STRING_free(ocs
4a90: 70 29 3b 20 2a 2f 0a 09 7d 0a 09 4c 41 50 50 45 p); */..}..LAPPE
4aa0: 4e 44 5f 4c 49 53 54 28 69 6e 74 65 72 70 2c 20 ND_LIST(interp,
4ab0: 63 65 72 74 50 74 72 2c 20 22 6f 63 73 70 22 2c certPtr, "ocsp",
4ac0: 20 6c 69 73 74 50 74 72 29 3b 0a 20 20 20 20 7d listPtr);. }
4ad0: 0a 0a 20 20 20 20 2f 2a 20 43 41 20 49 73 73 75 .. /* CA Issu
4ae0: 65 72 73 20 55 52 4c 2c 20 63 61 49 73 73 75 65 ers URL, caIssue
4af0: 72 73 20 2a 2f 0a 20 20 20 20 7b 0a 09 53 54 41 rs */. {..STA
4b00: 43 4b 5f 4f 46 28 41 43 43 45 53 53 5f 44 45 53 CK_OF(ACCESS_DES
4b10: 43 52 49 50 54 49 4f 4e 29 20 2a 61 64 73 3b 0a CRIPTION) *ads;.
4b20: 09 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e .listPtr = Tcl_N
4b30: 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c ewListObj(0, NUL
4b40: 4c 29 3b 0a 0a 09 69 66 20 28 61 64 73 20 3d 20 L);...if (ads =
4b50: 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 X509_get_ext_d2i
4b60: 28 63 65 72 74 2c 20 4e 49 44 5f 69 6e 66 6f 5f (cert, NID_info_
4b70: 61 63 63 65 73 73 2c 20 4e 55 4c 4c 2c 20 4e 55 access, NULL, NU
4b80: 4c 4c 29 29 20 7b 0a 09 20 20 20 20 66 6f 72 20 LL)) {.. for
4b90: 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 (int i = 0; i <
4ba0: 73 6b 5f 41 43 43 45 53 53 5f 44 45 53 43 52 49 sk_ACCESS_DESCRI
4bb0: 50 54 49 4f 4e 5f 6e 75 6d 28 61 64 73 29 3b 20 PTION_num(ads);
4bc0: 69 2b 2b 29 20 7b 0a 09 09 41 43 43 45 53 53 5f i++) {...ACCESS_
4bd0: 44 45 53 43 52 49 50 54 49 4f 4e 20 2a 61 64 20 DESCRIPTION *ad
4be0: 3d 20 73 6b 5f 41 43 43 45 53 53 5f 44 45 53 43 = sk_ACCESS_DESC
4bf0: 52 49 50 54 49 4f 4e 5f 76 61 6c 75 65 28 61 64 RIPTION_value(ad
4c00: 73 2c 20 69 29 3b 0a 09 09 69 66 20 28 4f 42 4a s, i);...if (OBJ
4c10: 5f 6f 62 6a 32 6e 69 64 28 61 64 2d 3e 6d 65 74 _obj2nid(ad->met
4c20: 68 6f 64 29 20 3d 3d 20 4e 49 44 5f 61 64 5f 63 hod) == NID_ad_c
4c30: 61 5f 69 73 73 75 65 72 73 20 26 26 20 61 64 2d a_issuers && ad-
4c40: 3e 6c 6f 63 61 74 69 6f 6e 29 20 7b 0a 09 09 20 >location) {...
4c50: 20 20 20 69 66 20 28 61 64 2d 3e 6c 6f 63 61 74 if (ad->locat
4c60: 69 6f 6e 2d 3e 74 79 70 65 20 3d 3d 20 47 45 4e ion->type == GEN
4c70: 5f 55 52 49 29 20 7b 0a 09 09 09 75 6e 73 69 67 _URI) {....unsig
4c80: 6e 65 64 20 63 68 61 72 20 2a 62 75 66 3b 0a 0a ned char *buf;..
4c90: 09 09 09 6c 65 6e 20 3d 20 41 53 4e 31 5f 53 54 ...len = ASN1_ST
4ca0: 52 49 4e 47 5f 74 6f 5f 55 54 46 38 28 26 62 75 RING_to_UTF8(&bu
4cb0: 66 2c 20 61 64 2d 3e 6c 6f 63 61 74 69 6f 6e 2d f, ad->location-
4cc0: 3e 64 2e 75 6e 69 66 6f 72 6d 52 65 73 6f 75 72 >d.uniformResour
4cd0: 63 65 49 64 65 6e 74 69 66 69 65 72 29 3b 0a 09 ceIdentifier);..
4ce0: 09 09 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 ..Tcl_ListObjApp
4cf0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
4d00: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f p, listPtr, Tcl_
4d10: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 62 75 66 NewStringObj(buf
4d20: 2c 20 6c 65 6e 29 29 3b 0a 09 09 09 4f 50 45 4e , len));....OPEN
4d30: 53 53 4c 5f 66 72 65 65 28 62 75 66 29 3b 0a 09 SSL_free(buf);..
4d40: 09 09 62 72 65 61 6b 3b 0a 09 09 20 20 20 20 7d ..break;... }
4d50: 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 20 20 20 ...}.. }..
4d60: 20 2f 2a 20 73 6b 5f 41 43 43 45 53 53 5f 44 45 /* sk_ACCESS_DE
4d70: 53 43 52 49 50 54 49 4f 4e 5f 70 6f 70 5f 66 72 SCRIPTION_pop_fr
4d80: 65 65 28 61 64 73 2c 20 41 43 43 45 53 53 5f 44 ee(ads, ACCESS_D
4d90: 45 53 43 52 49 50 54 49 4f 4e 5f 66 72 65 65 29 ESCRIPTION_free)
4da0: 3b 20 2a 2f 0a 09 20 20 20 20 41 55 54 48 4f 52 ; */.. AUTHOR
4db0: 49 54 59 5f 49 4e 46 4f 5f 41 43 43 45 53 53 5f ITY_INFO_ACCESS_
4dc0: 66 72 65 65 28 61 64 73 29 3b 0a 09 7d 0a 09 4c free(ads);..}..L
4dd0: 41 50 50 45 4e 44 5f 4c 49 53 54 28 69 6e 74 65 APPEND_LIST(inte
4de0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 61 rp, certPtr, "ca
4df0: 49 73 73 75 65 72 73 22 2c 20 6c 69 73 74 50 74 Issuers", listPt
4e00: 72 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f r);. }.. /
4e10: 2a 20 53 75 62 6a 65 63 74 20 49 6e 66 6f 72 6d * Subject Inform
4e20: 61 74 69 6f 6e 20 41 63 63 65 73 73 20 2d 20 52 ation Access - R
4e30: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 FC 5280 section
4e40: 34 2e 32 2e 32 2e 32 2c 20 4e 49 44 5f 73 69 6e 4.2.2.2, NID_sin
4e50: 66 6f 5f 61 63 63 65 73 73 20 2a 2f 0a 0a 20 20 fo_access */..
4e60: 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65 /* Certificate
4e70: 20 41 6c 69 61 73 2e 20 49 66 20 75 73 65 73 20 Alias. If uses
4e80: 61 20 50 4b 43 53 23 31 32 20 73 74 72 75 63 74 a PKCS#12 struct
4e90: 75 72 65 2c 20 61 6c 69 61 73 20 77 69 6c 6c 20 ure, alias will
4ea0: 72 65 66 6c 65 63 74 20 74 68 65 0a 09 66 72 69 reflect the..fri
4eb0: 65 6e 64 6c 79 4e 61 6d 65 20 61 74 74 72 69 62 endlyName attrib
4ec0: 75 74 65 20 28 52 46 43 20 32 39 38 35 29 2e 20 ute (RFC 2985).
4ed0: 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 30 3b 0a */. len = 0;.
4ee0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 LAPPEND_STR(
4ef0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
4f00: 20 22 61 6c 69 61 73 22 2c 20 58 35 30 39 5f 61 "alias", X509_a
4f10: 6c 69 61 73 5f 67 65 74 30 28 63 65 72 74 2c 20 lias_get0(cert,
4f20: 26 6c 65 6e 29 2c 20 6c 65 6e 29 3b 0a 0a 20 20 &len), len);..
4f30: 20 20 2f 2a 20 43 65 72 74 69 66 69 63 61 74 65 /* Certificate
4f40: 20 61 6e 64 20 64 75 6d 70 20 61 6c 6c 20 64 61 and dump all da
4f50: 74 61 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 68 61 ta */. {..cha
4f60: 72 20 63 65 72 74 53 74 72 5b 43 45 52 54 5f 53 r certStr[CERT_S
4f70: 54 52 5f 53 49 5a 45 5d 3b 0a 0a 09 2f 2a 20 47 TR_SIZE];.../* G
4f80: 65 74 20 63 65 72 74 69 66 69 63 61 74 65 20 2a et certificate *
4f90: 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f /..len = BIO_to_
4fa0: 42 75 66 66 65 72 28 50 45 4d 5f 77 72 69 74 65 Buffer(PEM_write
4fb0: 5f 62 69 6f 5f 58 35 30 39 28 62 69 6f 2c 20 63 _bio_X509(bio, c
4fc0: 65 72 74 29 2c 20 62 69 6f 2c 20 63 65 72 74 53 ert), bio, certS
4fd0: 74 72 2c 20 43 45 52 54 5f 53 54 52 5f 53 49 5a tr, CERT_STR_SIZ
4fe0: 45 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 E);..LAPPEND_STR
4ff0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
5000: 2c 20 22 63 65 72 74 69 66 69 63 61 74 65 22 2c , "certificate",
5010: 20 63 65 72 74 53 74 72 2c 20 6c 65 6e 29 3b 0a certStr, len);.
5020: 0a 09 2f 2a 20 47 65 74 20 61 6c 6c 20 63 65 72 ../* Get all cer
5030: 74 20 69 6e 66 6f 20 2a 2f 0a 09 6c 65 6e 20 3d t info */..len =
5040: 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58 BIO_to_Buffer(X
5050: 35 30 39 5f 70 72 69 6e 74 5f 65 78 28 62 69 6f 509_print_ex(bio
5060: 2c 20 63 65 72 74 2c 20 66 6c 61 67 73 2c 20 30 , cert, flags, 0
5070: 29 2c 20 62 69 6f 2c 20 63 65 72 74 53 74 72 2c ), bio, certStr,
5080: 20 43 45 52 54 5f 53 54 52 5f 53 49 5a 45 29 3b CERT_STR_SIZE);
5090: 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e ..LAPPEND_STR(in
50a0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
50b0: 61 6c 6c 22 2c 20 63 65 72 74 53 74 72 2c 20 6c all", certStr, l
50c0: 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 en);. }..
50d0: 42 49 4f 5f 66 72 65 65 28 62 69 6f 29 3b 0a 20 BIO_free(bio);.
50e0: 20 20 20 72 65 74 75 72 6e 20 63 65 72 74 50 74 return certPt
50f0: 72 3b 0a 7d 0a r;.}.