0000: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 /*. * Copyright
0010: 28 43 29 20 31 39 39 37 2d 32 30 30 30 20 53 65 (C) 1997-2000 Se
0020: 6e 73 75 73 20 43 6f 6e 73 75 6c 74 69 6e 67 20 nsus Consulting
0030: 4c 74 64 2e 0a 20 2a 20 4d 61 74 74 20 4e 65 77 Ltd.. * Matt New
0040: 6d 61 6e 20 3c 6d 61 74 74 40 73 65 6e 73 75 73 man <matt@sensus
0050: 2e 6f 72 67 3e 0a 20 2a 20 43 6f 70 79 72 69 67 .org>. * Copyrig
0060: 68 74 20 28 43 29 20 32 30 32 33 20 42 72 69 61 ht (C) 2023 Bria
0070: 6e 20 4f 27 48 61 67 61 6e 0a 20 2a 2f 0a 23 69 n O'Hagan. */.#i
0080: 6e 63 6c 75 64 65 20 3c 74 63 6c 2e 68 3e 0a 23 nclude <tcl.h>.#
0090: 69 6e 63 6c 75 64 65 20 3c 73 74 64 69 6f 2e 68 include <stdio.h
00a0: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e >.#include <open
00b0: 73 73 6c 2f 62 69 6f 2e 68 3e 0a 23 69 6e 63 6c ssl/bio.h>.#incl
00c0: 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 73 68 61 ude <openssl/sha
00d0: 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 .h>.#include <op
00e0: 65 6e 73 73 6c 2f 78 35 30 39 2e 68 3e 0a 23 69 enssl/x509.h>.#i
00f0: 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c 2f nclude <openssl/
0100: 78 35 30 39 76 33 2e 68 3e 0a 23 69 6e 63 6c 75 x509v3.h>.#inclu
0110: 64 65 20 3c 6f 70 65 6e 73 73 6c 2f 78 35 30 39 de <openssl/x509
0120: 5f 76 66 79 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 _vfy.h>.#include
0130: 20 3c 6f 70 65 6e 73 73 6c 2f 61 73 6e 31 2e 68 <openssl/asn1.h
0140: 3e 0a 23 69 6e 63 6c 75 64 65 20 22 74 6c 73 49 >.#include "tlsI
0150: 6e 74 2e 68 22 0a 0a 2f 2a 20 44 65 66 69 6e 65 nt.h"../* Define
0160: 20 6d 61 78 69 6d 75 6d 20 63 65 72 74 69 66 69 maximum certifi
0170: 63 61 74 65 20 73 69 7a 65 2e 20 4d 61 78 20 50 cate size. Max P
0180: 45 4d 20 73 69 7a 65 20 31 30 30 6b 42 20 61 6e EM size 100kB an
0190: 64 20 44 45 52 20 73 69 7a 65 20 69 73 20 32 34 d DER size is 24
01a0: 6b 42 2e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 43 kB. */.#define C
01b0: 45 52 54 5f 53 54 52 5f 53 49 5a 45 20 33 32 37 ERT_STR_SIZE 327
01c0: 36 38 0a 0a 0c 0a 2f 2a 0a 20 2a 20 42 69 6e 61 68..../*. * Bina
01d0: 72 79 20 73 74 72 69 6e 67 20 74 6f 20 68 65 78 ry string to hex
01e0: 20 73 74 72 69 6e 67 0a 20 2a 2f 0a 69 6e 74 20 string. */.int
01f0: 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 63 68 String_to_Hex(ch
0200: 61 72 2a 20 69 6e 70 75 74 2c 20 69 6e 74 20 69 ar* input, int i
0210: 6c 65 6e 2c 20 63 68 61 72 20 2a 6f 75 74 70 75 len, char *outpu
0220: 74 2c 20 69 6e 74 20 6f 6c 65 6e 29 20 7b 0a 20 t, int olen) {.
0230: 20 20 20 69 6e 74 20 63 6f 75 6e 74 20 3d 20 30 int count = 0
0240: 3b 0a 0a 20 20 20 20 66 6f 72 20 28 69 6e 74 20 ;.. for (int
0250: 69 20 3d 20 30 3b 20 69 20 3c 20 69 6c 65 6e 20 i = 0; i < ilen
0260: 26 26 20 63 6f 75 6e 74 20 3c 20 6f 6c 65 6e 20 && count < olen
0270: 2d 20 31 3b 20 69 2b 2b 2c 20 63 6f 75 6e 74 20 - 1; i++, count
0280: 2b 3d 20 32 29 20 7b 0a 09 73 70 72 69 6e 74 66 += 2) {..sprintf
0290: 28 6f 75 74 70 75 74 20 2b 20 63 6f 75 6e 74 2c (output + count,
02a0: 20 22 25 30 32 58 22 2c 20 69 6e 70 75 74 5b 69 "%02X", input[i
02b0: 5d 20 26 20 30 78 66 66 29 3b 0a 20 20 20 20 7d ] & 0xff);. }
02c0: 0a 20 20 20 20 6f 75 74 70 75 74 5b 63 6f 75 6e . output[coun
02d0: 74 5d 20 3d 20 30 3b 0a 20 20 20 20 72 65 74 75 t] = 0;. retu
02e0: 72 6e 20 63 6f 75 6e 74 3b 0a 7d 0a 0a 2f 2a 0a rn count;.}../*.
02f0: 20 2a 20 42 49 4f 20 74 6f 20 42 75 66 66 65 72 * BIO to Buffer
0300: 0a 20 2a 2f 0a 69 6e 74 20 42 49 4f 5f 74 6f 5f . */.int BIO_to_
0310: 42 75 66 66 65 72 28 69 6e 74 20 72 65 73 75 6c Buffer(int resul
0320: 74 2c 20 42 49 4f 20 2a 62 69 6f 2c 20 76 6f 69 t, BIO *bio, voi
0330: 64 20 2a 62 75 66 66 65 72 2c 20 69 6e 74 20 73 d *buffer, int s
0340: 69 7a 65 29 20 7b 0a 20 20 20 20 69 6e 74 20 6c ize) {. int l
0350: 65 6e 20 3d 20 30 3b 0a 20 20 20 20 69 6e 74 20 en = 0;. int
0360: 70 65 6e 64 69 6e 67 20 3d 20 42 49 4f 5f 70 65 pending = BIO_pe
0370: 6e 64 69 6e 67 28 62 69 6f 29 3b 0a 0a 20 20 20 nding(bio);..
0380: 20 69 66 20 28 72 65 73 75 6c 74 29 20 7b 0a 09 if (result) {..
0390: 6c 65 6e 20 3d 20 42 49 4f 5f 72 65 61 64 28 62 len = BIO_read(b
03a0: 69 6f 2c 20 62 75 66 66 65 72 2c 20 28 70 65 6e io, buffer, (pen
03b0: 64 69 6e 67 20 3c 20 73 69 7a 65 29 20 3f 20 70 ding < size) ? p
03c0: 65 6e 64 69 6e 67 20 3a 20 73 69 7a 65 29 3b 0a ending : size);.
03d0: 09 28 76 6f 69 64 29 42 49 4f 5f 66 6c 75 73 68 .(void)BIO_flush
03e0: 28 62 69 6f 29 3b 0a 09 69 66 20 28 6c 65 6e 20 (bio);..if (len
03f0: 3c 20 30 29 20 7b 0a 09 20 20 20 20 6c 65 6e 20 < 0) {.. len
0400: 3d 20 30 3b 0a 09 7d 0a 20 20 20 20 7d 0a 20 20 = 0;..}. }.
0410: 20 20 72 65 74 75 72 6e 20 6c 65 6e 3b 0a 7d 0a return len;.}.
0420: 0c 0a 2f 2a 0a 20 2a 20 47 65 74 20 58 35 30 39 ../*. * Get X509
0430: 20 43 65 72 74 69 66 69 63 61 74 65 20 45 78 74 Certificate Ext
0440: 65 6e 73 69 6f 6e 73 0a 20 2a 2f 0a 54 63 6c 5f ensions. */.Tcl_
0450: 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 45 78 74 Obj *Tls_x509Ext
0460: 65 6e 73 69 6f 6e 73 28 54 63 6c 5f 49 6e 74 65 ensions(Tcl_Inte
0470: 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 rp *interp, X509
0480: 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 63 6f *cert) {. co
0490: 6e 73 74 20 53 54 41 43 4b 5f 4f 46 28 58 35 30 nst STACK_OF(X50
04a0: 39 5f 45 58 54 45 4e 53 49 4f 4e 29 20 2a 65 78 9_EXTENSION) *ex
04b0: 74 73 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 ts;. Tcl_Obj
04c0: 2a 6c 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e *listPtr = Tcl_N
04d0: 65 77 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c ewListObj(0, NUL
04e0: 4c 29 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 73 L);.. if (lis
04f0: 74 50 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a tPtr == NULL) {.
0500: 09 72 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 .return NULL;.
0510: 20 20 7d 0a 0a 20 20 20 20 69 66 20 28 65 78 74 }.. if (ext
0520: 73 20 3d 20 58 35 30 39 5f 67 65 74 30 5f 65 78 s = X509_get0_ex
0530: 74 65 6e 73 69 6f 6e 73 28 63 65 72 74 29 29 20 tensions(cert))
0540: 7b 0a 09 66 6f 72 20 28 69 6e 74 20 69 3d 30 3b {..for (int i=0;
0550: 20 69 20 3c 20 58 35 30 39 5f 67 65 74 5f 65 78 i < X509_get_ex
0560: 74 5f 63 6f 75 6e 74 28 63 65 72 74 29 3b 20 69 t_count(cert); i
0570: 2b 2b 29 20 7b 0a 09 20 20 20 20 58 35 30 39 5f ++) {.. X509_
0580: 45 58 54 45 4e 53 49 4f 4e 20 2a 65 78 20 3d 20 EXTENSION *ex =
0590: 73 6b 5f 58 35 30 39 5f 45 58 54 45 4e 53 49 4f sk_X509_EXTENSIO
05a0: 4e 5f 76 61 6c 75 65 28 65 78 74 73 2c 20 69 29 N_value(exts, i)
05b0: 3b 0a 09 20 20 20 20 41 53 4e 31 5f 4f 42 4a 45 ;.. ASN1_OBJE
05c0: 43 54 20 2a 6f 62 6a 20 3d 20 58 35 30 39 5f 45 CT *obj = X509_E
05d0: 58 54 45 4e 53 49 4f 4e 5f 67 65 74 5f 6f 62 6a XTENSION_get_obj
05e0: 65 63 74 28 65 78 29 3b 0a 09 20 20 20 20 2f 2a ect(ex);.. /*
05f0: 20 41 53 4e 31 5f 4f 43 54 45 54 5f 53 54 52 49 ASN1_OCTET_STRI
0600: 4e 47 20 2a 64 61 74 61 20 3d 20 58 35 30 39 5f NG *data = X509_
0610: 45 58 54 45 4e 53 49 4f 4e 5f 67 65 74 5f 64 61 EXTENSION_get_da
0620: 74 61 28 65 78 29 3b 20 2a 2f 0a 09 20 20 20 20 ta(ex); */..
0630: 69 6e 74 20 63 72 69 74 69 63 61 6c 20 3d 20 58 int critical = X
0640: 35 30 39 5f 45 58 54 45 4e 53 49 4f 4e 5f 67 65 509_EXTENSION_ge
0650: 74 5f 63 72 69 74 69 63 61 6c 28 65 78 29 3b 0a t_critical(ex);.
0660: 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f . LAPPEND_BOO
0670: 4c 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 L(interp, listPt
0680: 72 2c 20 4f 42 4a 5f 6e 69 64 32 6c 6e 28 4f 42 r, OBJ_nid2ln(OB
0690: 4a 5f 6f 62 6a 32 6e 69 64 28 6f 62 6a 29 29 2c J_obj2nid(obj)),
06a0: 20 63 72 69 74 69 63 61 6c 29 3b 0a 09 7d 0a 20 critical);..}.
06b0: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
06c0: 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 listPtr;.}../*.
06d0: 2a 20 47 65 74 20 41 75 74 68 6f 72 69 74 79 20 * Get Authority
06e0: 61 6e 64 20 53 75 62 6a 65 63 74 20 4b 65 79 20 and Subject Key
06f0: 49 64 65 6e 74 69 66 69 65 72 73 0a 20 2a 2f 0a Identifiers. */.
0700: 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 Tcl_Obj *Tls_x50
0710: 39 49 64 65 6e 74 69 66 69 65 72 28 41 53 4e 31 9Identifier(ASN1
0720: 5f 4f 43 54 45 54 5f 53 54 52 49 4e 47 20 2a 61 _OCTET_STRING *a
0730: 73 74 72 69 6e 67 29 20 7b 0a 20 20 20 20 54 63 string) {. Tc
0740: 6c 5f 4f 62 6a 20 2a 72 65 73 75 6c 74 50 74 72 l_Obj *resultPtr
0750: 20 3d 20 4e 55 4c 4c 3b 0a 20 20 20 20 69 6e 74 = NULL;. int
0760: 20 6c 65 6e 20 3d 20 30 3b 0a 20 20 20 20 63 68 len = 0;. ch
0770: 61 72 20 62 75 66 66 65 72 5b 31 30 32 34 5d 3b ar buffer[1024];
0780: 0a 0a 20 20 20 20 69 66 20 28 61 73 74 72 69 6e .. if (astrin
0790: 67 20 21 3d 20 4e 55 4c 4c 29 20 7b 0a 09 6c 65 g != NULL) {..le
07a0: 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 n = String_to_He
07b0: 78 28 28 63 68 61 72 20 2a 29 41 53 4e 31 5f 53 x((char *)ASN1_S
07c0: 54 52 49 4e 47 5f 67 65 74 30 5f 64 61 74 61 28 TRING_get0_data(
07d0: 61 73 74 72 69 6e 67 29 2c 0a 09 20 20 20 20 41 astring),.. A
07e0: 53 4e 31 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 SN1_STRING_lengt
07f0: 68 28 61 73 74 72 69 6e 67 29 2c 20 62 75 66 66 h(astring), buff
0800: 65 72 2c 20 31 30 32 34 29 3b 0a 20 20 20 20 7d er, 1024);. }
0810: 0a 20 20 20 20 72 65 73 75 6c 74 50 74 72 20 3d . resultPtr =
0820: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
0830: 6a 28 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a j(buffer, len);.
0840: 20 20 20 20 72 65 74 75 72 6e 20 72 65 73 75 6c return resul
0850: 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 tPtr;.}../*. * G
0860: 65 74 20 4b 65 79 20 55 73 61 67 65 0a 20 2a 2f et Key Usage. */
0870: 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 .Tcl_Obj *Tls_x5
0880: 30 39 4b 65 79 55 73 61 67 65 28 54 63 6c 5f 49 09KeyUsage(Tcl_I
0890: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 nterp *interp, X
08a0: 35 30 39 20 2a 63 65 72 74 2c 20 75 69 6e 74 33 509 *cert, uint3
08b0: 32 5f 74 20 78 66 6c 61 67 73 29 20 7b 0a 20 20 2_t xflags) {.
08c0: 20 20 75 69 6e 74 33 32 5f 74 20 75 73 61 67 65 uint32_t usage
08d0: 20 3d 20 58 35 30 39 5f 67 65 74 5f 6b 65 79 5f = X509_get_key_
08e0: 75 73 61 67 65 28 63 65 72 74 29 3b 0a 20 20 20 usage(cert);.
08f0: 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 Tcl_Obj *listPt
0900: 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f r = Tcl_NewListO
0910: 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 bj(0, NULL);..
0920: 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 3d 3d if (listPtr ==
0930: 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e NULL) {..return
0940: 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 NULL;. }..
0950: 20 20 69 66 20 28 28 78 66 6c 61 67 73 20 26 20 if ((xflags &
0960: 45 58 46 4c 41 47 5f 4b 55 53 41 47 45 29 20 26 EXFLAG_KUSAGE) &
0970: 26 20 75 73 61 67 65 20 3c 20 55 49 4e 54 33 32 & usage < UINT32
0980: 5f 4d 41 58 29 20 7b 0a 09 69 66 20 28 75 73 61 _MAX) {..if (usa
0990: 67 65 20 26 20 4b 55 5f 44 49 47 49 54 41 4c 5f ge & KU_DIGITAL_
09a0: 53 49 47 4e 41 54 55 52 45 29 20 7b 0a 09 20 20 SIGNATURE) {..
09b0: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
09c0: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
09d0: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f p, listPtr, Tcl_
09e0: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 69 NewStringObj("Di
09f0: 67 69 74 61 6c 20 53 69 67 6e 61 74 75 72 65 22 gital Signature"
0a00: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 , -1));..}..if (
0a10: 75 73 61 67 65 20 26 20 4b 55 5f 4e 4f 4e 5f 52 usage & KU_NON_R
0a20: 45 50 55 44 49 41 54 49 4f 4e 29 20 7b 0a 09 20 EPUDIATION) {..
0a30: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 Tcl_ListObjAp
0a40: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
0a50: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c rp, listPtr, Tcl
0a60: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4e _NewStringObj("N
0a70: 6f 6e 2d 52 65 70 75 64 69 61 74 69 6f 6e 22 2c on-Repudiation",
0a80: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 -1));..}..if (u
0a90: 73 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 45 4e sage & KU_KEY_EN
0aa0: 43 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a 09 20 CIPHERMENT) {..
0ab0: 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 Tcl_ListObjAp
0ac0: 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 pendElement(inte
0ad0: 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c rp, listPtr, Tcl
0ae0: 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 4b _NewStringObj("K
0af0: 65 79 20 45 6e 63 69 70 68 65 72 6d 65 6e 74 22 ey Encipherment"
0b00: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 , -1));..}..if (
0b10: 75 73 61 67 65 20 26 20 4b 55 5f 44 41 54 41 5f usage & KU_DATA_
0b20: 45 4e 43 49 50 48 45 52 4d 45 4e 54 29 20 7b 0a ENCIPHERMENT) {.
0b30: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
0b40: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
0b50: 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 terp, listPtr, T
0b60: 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 cl_NewStringObj(
0b70: 22 44 61 74 61 20 45 6e 63 69 70 68 65 72 6d 65 "Data Encipherme
0b80: 6e 74 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 nt", -1));..}..i
0b90: 66 20 28 75 73 61 67 65 20 26 20 4b 55 5f 4b 45 f (usage & KU_KE
0ba0: 59 5f 41 47 52 45 45 4d 45 4e 54 29 20 7b 0a 09 Y_AGREEMENT) {..
0bb0: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
0bc0: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
0bd0: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 erp, listPtr, Tc
0be0: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
0bf0: 4b 65 79 20 41 67 72 65 65 6d 65 6e 74 22 2c 20 Key Agreement",
0c00: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 -1));..}..if (us
0c10: 61 67 65 20 26 20 4b 55 5f 4b 45 59 5f 43 45 52 age & KU_KEY_CER
0c20: 54 5f 53 49 47 4e 29 20 7b 0a 09 20 20 20 20 54 T_SIGN) {.. T
0c30: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
0c40: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
0c50: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
0c60: 53 74 72 69 6e 67 4f 62 6a 28 22 43 65 72 74 69 StringObj("Certi
0c70: 66 69 63 61 74 65 20 53 69 67 6e 69 6e 67 22 2c ficate Signing",
0c80: 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 -1));..}..if (u
0c90: 73 61 67 65 20 26 20 4b 55 5f 43 52 4c 5f 53 49 sage & KU_CRL_SI
0ca0: 47 4e 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c GN) {.. Tcl_L
0cb0: 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d istObjAppendElem
0cc0: 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 ent(interp, list
0cd0: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 Ptr, Tcl_NewStri
0ce0: 6e 67 4f 62 6a 28 22 43 52 4c 20 53 69 67 6e 69 ngObj("CRL Signi
0cf0: 6e 67 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 ng", -1));..}..i
0d00: 66 20 28 75 73 61 67 65 20 26 20 4b 55 5f 45 4e f (usage & KU_EN
0d10: 43 49 50 48 45 52 5f 4f 4e 4c 59 29 20 7b 0a 09 CIPHER_ONLY) {..
0d20: 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 Tcl_ListObjA
0d30: 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 ppendElement(int
0d40: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 erp, listPtr, Tc
0d50: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 l_NewStringObj("
0d60: 45 6e 63 69 70 68 65 72 20 4f 6e 6c 79 22 2c 20 Encipher Only",
0d70: 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 75 73 -1));..}..if (us
0d80: 61 67 65 20 26 20 4b 55 5f 44 45 43 49 50 48 45 age & KU_DECIPHE
0d90: 52 5f 4f 4e 4c 59 29 20 7b 0a 09 20 20 20 20 54 R_ONLY) {.. T
0da0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
0db0: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
0dc0: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
0dd0: 53 74 72 69 6e 67 4f 62 6a 28 22 44 65 63 69 70 StringObj("Decip
0de0: 68 65 72 20 4f 6e 6c 79 22 2c 20 2d 31 29 29 3b her Only", -1));
0df0: 0a 09 7d 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b ..}. } else {
0e00: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 .. Tcl_ListOb
0e10: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 jAppendElement(i
0e20: 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 nterp, listPtr,
0e30: 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a Tcl_NewStringObj
0e40: 28 22 75 6e 72 65 73 74 72 69 63 74 65 64 22 2c ("unrestricted",
0e50: 20 2d 31 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 -1));. }.
0e60: 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b return listPtr;
0e70: 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 43 65 .}../*. * Get Ce
0e80: 72 74 69 66 69 63 61 74 65 20 50 75 72 70 6f 73 rtificate Purpos
0e90: 65 0a 20 2a 2f 0a 63 68 61 72 20 2a 54 6c 73 5f e. */.char *Tls_
0ea0: 78 35 30 39 50 75 72 70 6f 73 65 28 58 35 30 39 x509Purpose(X509
0eb0: 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 63 68 *cert) {. ch
0ec0: 61 72 20 2a 70 75 72 70 6f 73 65 20 3d 20 4e 55 ar *purpose = NU
0ed0: 4c 4c 3b 0a 0a 20 20 20 20 69 66 20 28 58 35 30 LL;.. if (X50
0ee0: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 9_check_purpose(
0ef0: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f cert, X509_PURPO
0f00: 53 45 5f 53 53 4c 5f 43 4c 49 45 4e 54 2c 20 30 SE_SSL_CLIENT, 0
0f10: 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 ) > 0) {..purpos
0f20: 65 20 3d 20 22 53 53 4c 20 43 6c 69 65 6e 74 22 e = "SSL Client"
0f30: 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 ;. } else if
0f40: 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 (X509_check_purp
0f50: 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 ose(cert, X509_P
0f60: 55 52 50 4f 53 45 5f 53 53 4c 5f 53 45 52 56 45 URPOSE_SSL_SERVE
0f70: 52 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 R, 0) > 0) {..pu
0f80: 72 70 6f 73 65 20 3d 20 22 53 53 4c 20 53 65 72 rpose = "SSL Ser
0f90: 76 65 72 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 ver";. } else
0fa0: 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f if (X509_check_
0fb0: 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 purpose(cert, X5
0fc0: 30 39 5f 50 55 52 50 4f 53 45 5f 4e 53 5f 53 53 09_PURPOSE_NS_SS
0fd0: 4c 5f 53 45 52 56 45 52 2c 20 30 29 20 3e 20 30 L_SERVER, 0) > 0
0fe0: 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 ) {..purpose = "
0ff0: 4d 53 53 20 53 53 4c 20 53 65 72 76 65 72 22 3b MSS SSL Server";
1000: 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 66 20 28 . } else if (
1010: 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f X509_check_purpo
1020: 73 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 se(cert, X509_PU
1030: 52 50 4f 53 45 5f 53 4d 49 4d 45 5f 53 49 47 4e RPOSE_SMIME_SIGN
1040: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 , 0) > 0) {..pur
1050: 70 6f 73 65 20 3d 20 22 53 4d 49 4d 45 20 53 69 pose = "SMIME Si
1060: 67 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c gning";. } el
1070: 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 se if (X509_chec
1080: 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 k_purpose(cert,
1090: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 53 4d 49 X509_PURPOSE_SMI
10a0: 4d 45 5f 45 4e 43 52 59 50 54 2c 20 30 29 20 3e ME_ENCRYPT, 0) >
10b0: 20 30 29 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 0) {..purpose =
10c0: 20 22 53 4d 49 4d 45 20 45 6e 63 72 79 70 74 69 "SMIME Encrypti
10d0: 6f 6e 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 on";. } else
10e0: 69 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 if (X509_check_p
10f0: 75 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 urpose(cert, X50
1100: 39 5f 50 55 52 50 4f 53 45 5f 43 52 4c 5f 53 49 9_PURPOSE_CRL_SI
1110: 47 4e 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 GN, 0) > 0) {..p
1120: 75 72 70 6f 73 65 20 3d 20 22 43 52 4c 20 53 69 urpose = "CRL Si
1130: 67 6e 69 6e 67 22 3b 0a 20 20 20 20 7d 20 65 6c gning";. } el
1140: 73 65 20 69 66 20 28 58 35 30 39 5f 63 68 65 63 se if (X509_chec
1150: 6b 5f 70 75 72 70 6f 73 65 28 63 65 72 74 2c 20 k_purpose(cert,
1160: 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 41 4e 59 X509_PURPOSE_ANY
1170: 2c 20 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 , 0) > 0) {..pur
1180: 70 6f 73 65 20 3d 20 22 41 6e 79 22 3b 0a 20 20 pose = "Any";.
1190: 20 20 7d 20 65 6c 73 65 20 69 66 20 28 58 35 30 } else if (X50
11a0: 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 65 28 9_check_purpose(
11b0: 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 50 4f cert, X509_PURPO
11c0: 53 45 5f 4f 43 53 50 5f 48 45 4c 50 45 52 2c 20 SE_OCSP_HELPER,
11d0: 30 29 20 3e 20 30 29 20 7b 0a 09 70 75 72 70 6f 0) > 0) {..purpo
11e0: 73 65 20 3d 20 22 4f 43 53 50 20 48 65 6c 70 65 se = "OCSP Helpe
11f0: 72 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 69 r";. } else i
1200: 66 20 28 58 35 30 39 5f 63 68 65 63 6b 5f 70 75 f (X509_check_pu
1210: 72 70 6f 73 65 28 63 65 72 74 2c 20 58 35 30 39 rpose(cert, X509
1220: 5f 50 55 52 50 4f 53 45 5f 54 49 4d 45 53 54 41 _PURPOSE_TIMESTA
1230: 4d 50 5f 53 49 47 4e 2c 20 30 29 20 3e 20 30 29 MP_SIGN, 0) > 0)
1240: 20 7b 0a 09 70 75 72 70 6f 73 65 20 3d 20 22 54 {..purpose = "T
1250: 69 6d 65 73 74 61 6d 70 20 53 69 67 6e 69 6e 67 imestamp Signing
1260: 22 3b 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a ";. } else {.
1270: 09 70 75 72 70 6f 73 65 20 3d 20 22 22 3b 0a 20 .purpose = "";.
1280: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
1290: 70 75 72 70 6f 73 65 3b 0a 7d 0a 0a 2f 2a 0a 20 purpose;.}../*.
12a0: 2a 20 46 6f 72 20 65 61 63 68 20 70 75 72 70 6f * For each purpo
12b0: 73 65 2c 20 67 65 74 20 63 65 72 74 69 66 69 63 se, get certific
12c0: 61 74 65 20 61 70 70 6c 69 63 61 62 69 6c 69 74 ate applicabilit
12d0: 79 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 y. */.Tcl_Obj *T
12e0: 6c 73 5f 78 35 30 39 50 75 72 70 6f 73 65 73 28 ls_x509Purposes(
12f0: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
1300: 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74 29 20 rp, X509 *cert)
1310: 7b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c {. Tcl_Obj *l
1320: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 istPtr = Tcl_New
1330: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 ListObj(0, NULL)
1340: 3b 0a 20 20 20 20 58 35 30 39 5f 50 55 52 50 4f ;. X509_PURPO
1350: 53 45 20 2a 70 74 6d 70 3b 0a 0a 20 20 20 20 69 SE *ptmp;.. i
1360: 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 f (listPtr == NU
1370: 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 LL) {..return NU
1380: 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 66 LL;. }.. f
1390: 6f 72 20 28 69 6e 74 20 69 20 3d 20 30 3b 20 69 or (int i = 0; i
13a0: 20 3c 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f < X509_PURPOSE_
13b0: 67 65 74 5f 63 6f 75 6e 74 28 29 3b 20 69 2b 2b get_count(); i++
13c0: 29 20 7b 0a 09 70 74 6d 70 20 3d 20 58 35 30 39 ) {..ptmp = X509
13d0: 5f 50 55 52 50 4f 53 45 5f 67 65 74 30 28 69 29 _PURPOSE_get0(i)
13e0: 3b 0a 09 54 63 6c 5f 4f 62 6a 20 2a 74 6d 70 50 ;..Tcl_Obj *tmpP
13f0: 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 tr = Tcl_NewList
1400: 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 09 Obj(0, NULL);...
1410: 66 6f 72 20 28 69 6e 74 20 6a 20 3d 20 30 3b 20 for (int j = 0;
1420: 6a 20 3c 20 32 3b 20 6a 2b 2b 29 20 7b 0a 09 20 j < 2; j++) {..
1430: 20 20 20 69 6e 74 20 69 64 72 65 74 20 3d 20 58 int idret = X
1440: 35 30 39 5f 63 68 65 63 6b 5f 70 75 72 70 6f 73 509_check_purpos
1450: 65 28 63 65 72 74 2c 20 58 35 30 39 5f 50 55 52 e(cert, X509_PUR
1460: 50 4f 53 45 5f 67 65 74 5f 69 64 28 70 74 6d 70 POSE_get_id(ptmp
1470: 29 2c 20 6a 29 3b 0a 09 20 20 20 20 54 63 6c 5f ), j);.. Tcl_
1480: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
1490: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 74 6d 70 ment(interp, tmp
14a0: 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 Ptr, Tcl_NewStri
14b0: 6e 67 4f 62 6a 28 6a 20 3f 20 22 43 41 22 20 3a ngObj(j ? "CA" :
14c0: 20 22 6e 6f 6e 43 41 22 2c 20 2d 31 29 29 3b 0a "nonCA", -1));.
14d0: 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a . Tcl_ListObj
14e0: 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e AppendElement(in
14f0: 74 65 72 70 2c 20 74 6d 70 50 74 72 2c 20 54 63 terp, tmpPtr, Tc
1500: 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 69 l_NewStringObj(i
1510: 64 72 65 74 20 3d 3d 20 31 20 3f 20 22 59 65 73 dret == 1 ? "Yes
1520: 22 20 3a 20 22 4e 6f 22 2c 20 2d 31 29 29 3b 0a " : "No", -1));.
1530: 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 .}..LAPPEND_OBJ(
1540: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
1550: 20 58 35 30 39 5f 50 55 52 50 4f 53 45 5f 67 65 X509_PURPOSE_ge
1560: 74 30 5f 6e 61 6d 65 28 70 74 6d 70 29 2c 20 74 t0_name(ptmp), t
1570: 6d 70 50 74 72 29 3b 0a 20 20 20 20 7d 0a 20 20 mpPtr);. }.
1580: 20 20 72 65 74 75 72 6e 20 6c 69 73 74 50 74 72 return listPtr
1590: 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 53 ;.}../*. * Get S
15a0: 75 62 6a 65 63 74 20 41 6c 74 65 72 6e 61 74 65 ubject Alternate
15b0: 20 4e 61 6d 65 73 20 28 53 41 4e 29 20 61 6e 64 Names (SAN) and
15c0: 20 49 73 73 75 65 72 20 41 6c 74 65 72 6e 61 74 Issuer Alternat
15d0: 65 20 4e 61 6d 65 73 0a 20 2a 2f 0a 54 63 6c 5f e Names. */.Tcl_
15e0: 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 4e 61 6d Obj *Tls_x509Nam
15f0: 65 73 28 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 es(Tcl_Interp *i
1600: 6e 74 65 72 70 2c 20 58 35 30 39 20 2a 63 65 72 nterp, X509 *cer
1610: 74 2c 20 69 6e 74 20 6e 69 64 2c 20 42 49 4f 20 t, int nid, BIO
1620: 2a 62 69 6f 29 20 7b 0a 20 20 20 20 53 54 41 43 *bio) {. STAC
1630: 4b 5f 4f 46 28 47 45 4e 45 52 41 4c 5f 4e 41 4d K_OF(GENERAL_NAM
1640: 45 29 20 2a 6e 61 6d 65 73 3b 0a 20 20 20 20 54 E) *names;. T
1650: 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 cl_Obj *listPtr
1660: 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a = Tcl_NewListObj
1670: 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 69 (0, NULL);. i
1680: 6e 74 20 6c 65 6e 3b 0a 20 20 20 20 63 68 61 72 nt len;. char
1690: 20 62 75 66 66 65 72 5b 31 30 32 34 5d 3b 0a 0a buffer[1024];..
16a0: 20 20 20 20 69 66 20 28 6c 69 73 74 50 74 72 20 if (listPtr
16b0: 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 75 == NULL) {..retu
16c0: 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a 0a rn NULL;. }..
16d0: 20 20 20 20 69 66 20 28 6e 61 6d 65 73 20 3d 20 if (names =
16e0: 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 32 69 X509_get_ext_d2i
16f0: 28 63 65 72 74 2c 20 6e 69 64 2c 20 4e 55 4c 4c (cert, nid, NULL
1700: 2c 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 , NULL)) {..for
1710: 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20 73 6b (int i=0; i < sk
1720: 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e 75 _GENERAL_NAME_nu
1730: 6d 28 6e 61 6d 65 73 29 3b 20 69 2b 2b 29 20 7b m(names); i++) {
1740: 0a 09 20 20 20 20 63 6f 6e 73 74 20 47 45 4e 45 .. const GENE
1750: 52 41 4c 5f 4e 41 4d 45 20 2a 6e 61 6d 65 20 3d RAL_NAME *name =
1760: 20 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 sk_GENERAL_NAME
1770: 5f 76 61 6c 75 65 28 6e 61 6d 65 73 2c 20 69 29 _value(names, i)
1780: 3b 0a 0a 09 20 20 20 20 6c 65 6e 20 3d 20 42 49 ;... len = BI
1790: 4f 5f 74 6f 5f 42 75 66 66 65 72 28 6e 61 6d 65 O_to_Buffer(name
17a0: 20 26 26 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 && GENERAL_NAME
17b0: 5f 70 72 69 6e 74 28 62 69 6f 2c 20 6e 61 6d 65 _print(bio, name
17c0: 29 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 ), bio, buffer,
17d0: 31 30 32 34 29 3b 0a 09 20 20 20 20 4c 41 50 50 1024);.. LAPP
17e0: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 END_STR(interp,
17f0: 6c 69 73 74 50 74 72 2c 20 4e 55 4c 4c 2c 20 62 listPtr, NULL, b
1800: 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 09 7d 0a uffer, len);..}.
1810: 09 73 6b 5f 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 .sk_GENERAL_NAME
1820: 5f 70 6f 70 5f 66 72 65 65 28 6e 61 6d 65 73 2c _pop_free(names,
1830: 20 47 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 66 72 GENERAL_NAME_fr
1840: 65 65 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 72 ee);. }. r
1850: 65 74 75 72 6e 20 6c 69 73 74 50 74 72 3b 0a 7d eturn listPtr;.}
1860: 0a 0a 2f 2a 0a 20 2a 20 47 65 74 20 45 58 74 65 ../*. * Get EXte
1870: 6e 64 65 64 20 4b 65 79 20 55 73 61 67 65 0a 20 nded Key Usage.
1880: 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f */.Tcl_Obj *Tls_
1890: 78 35 30 39 45 78 74 4b 65 79 55 73 61 67 65 28 x509ExtKeyUsage(
18a0: 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69 6e 74 65 Tcl_Interp *inte
18b0: 72 70 2c 20 58 35 30 39 20 2a 63 65 72 74 2c 20 rp, X509 *cert,
18c0: 75 69 6e 74 33 32 5f 74 20 78 66 6c 61 67 73 29 uint32_t xflags)
18d0: 20 7b 0a 20 20 20 20 75 69 6e 74 33 32 5f 74 20 {. uint32_t
18e0: 75 73 61 67 65 20 3d 20 58 35 30 39 5f 67 65 74 usage = X509_get
18f0: 5f 6b 65 79 5f 75 73 61 67 65 28 63 65 72 74 29 _key_usage(cert)
1900: 3b 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c ;. Tcl_Obj *l
1910: 69 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 istPtr = Tcl_New
1920: 4c 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 ListObj(0, NULL)
1930: 3b 0a 0a 20 20 20 20 69 66 20 28 6c 69 73 74 50 ;.. if (listP
1940: 74 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 tr == NULL) {..r
1950: 65 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 eturn NULL;.
1960: 7d 0a 0a 20 20 20 20 69 66 20 28 28 78 66 6c 61 }.. if ((xfla
1970: 67 73 20 26 20 45 58 46 4c 41 47 5f 58 4b 55 53 gs & EXFLAG_XKUS
1980: 41 47 45 29 20 26 26 20 75 73 61 67 65 20 3c 20 AGE) && usage <
1990: 55 49 4e 54 33 32 5f 4d 41 58 29 20 7b 0a 09 75 UINT32_MAX) {..u
19a0: 73 61 67 65 20 3d 20 58 35 30 39 5f 67 65 74 5f sage = X509_get_
19b0: 65 78 74 65 6e 64 65 64 5f 6b 65 79 5f 75 73 61 extended_key_usa
19c0: 67 65 28 63 65 72 74 29 3b 0a 0a 09 69 66 20 28 ge(cert);...if (
19d0: 75 73 61 67 65 20 26 20 58 4b 55 5f 53 53 4c 5f usage & XKU_SSL_
19e0: 53 45 52 56 45 52 29 20 7b 0a 09 20 20 20 20 54 SERVER) {.. T
19f0: 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 cl_ListObjAppend
1a00: 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 Element(interp,
1a10: 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 listPtr, Tcl_New
1a20: 53 74 72 69 6e 67 4f 62 6a 28 22 54 4c 53 20 57 StringObj("TLS W
1a30: 65 62 20 53 65 72 76 65 72 20 41 75 74 68 65 6e eb Server Authen
1a40: 74 69 63 61 74 69 6f 6e 22 2c 20 2d 31 29 29 3b tication", -1));
1a50: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
1a60: 20 58 4b 55 5f 53 53 4c 5f 43 4c 49 45 4e 54 29 XKU_SSL_CLIENT)
1a70: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 {.. Tcl_List
1a80: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 ObjAppendElement
1a90: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 (interp, listPtr
1aa0: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f , Tcl_NewStringO
1ab0: 62 6a 28 22 54 4c 53 20 57 65 62 20 43 6c 69 65 bj("TLS Web Clie
1ac0: 6e 74 20 41 75 74 68 65 6e 74 69 63 61 74 69 6f nt Authenticatio
1ad0: 6e 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 n", -1));..}..if
1ae0: 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 53 4d (usage & XKU_SM
1af0: 49 4d 45 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f IME) {.. Tcl_
1b00: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
1b10: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 ment(interp, lis
1b20: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 tPtr, Tcl_NewStr
1b30: 69 6e 67 4f 62 6a 28 22 45 2d 6d 61 69 6c 20 50 ingObj("E-mail P
1b40: 72 6f 74 65 63 74 69 6f 6e 22 2c 20 2d 31 29 29 rotection", -1))
1b50: 3b 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 ;..}..if (usage
1b60: 26 20 58 4b 55 5f 43 4f 44 45 5f 53 49 47 4e 29 & XKU_CODE_SIGN)
1b70: 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 {.. Tcl_List
1b80: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 ObjAppendElement
1b90: 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 (interp, listPtr
1ba0: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f , Tcl_NewStringO
1bb0: 62 6a 28 22 43 6f 64 65 20 53 69 67 6e 69 6e 67 bj("Code Signing
1bc0: 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 ", -1));..}..if
1bd0: 28 75 73 61 67 65 20 26 20 58 4b 55 5f 53 47 43 (usage & XKU_SGC
1be0: 29 20 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 ) {.. Tcl_Lis
1bf0: 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e tObjAppendElemen
1c00: 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 t(interp, listPt
1c10: 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 r, Tcl_NewString
1c20: 4f 62 6a 28 22 53 47 43 22 2c 20 2d 31 29 29 3b Obj("SGC", -1));
1c30: 0a 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 ..}..if (usage &
1c40: 20 58 4b 55 5f 4f 43 53 50 5f 53 49 47 4e 29 20 XKU_OCSP_SIGN)
1c50: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f {.. Tcl_ListO
1c60: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 bjAppendElement(
1c70: 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 74 72 2c interp, listPtr,
1c80: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
1c90: 6a 28 22 4f 43 53 50 20 53 69 67 6e 69 6e 67 22 j("OCSP Signing"
1ca0: 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 66 20 28 , -1));..}..if (
1cb0: 75 73 61 67 65 20 26 20 58 4b 55 5f 54 49 4d 45 usage & XKU_TIME
1cc0: 53 54 41 4d 50 29 20 7b 0a 09 20 20 20 20 54 63 STAMP) {.. Tc
1cd0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
1ce0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
1cf0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
1d00: 74 72 69 6e 67 4f 62 6a 28 22 54 69 6d 65 20 53 tringObj("Time S
1d10: 74 61 6d 70 69 6e 67 22 2c 20 2d 31 29 29 3b 0a tamping", -1));.
1d20: 09 7d 0a 09 69 66 20 28 75 73 61 67 65 20 26 20 .}..if (usage &
1d30: 58 4b 55 5f 44 56 43 53 20 29 20 7b 0a 09 20 20 XKU_DVCS ) {..
1d40: 20 20 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 Tcl_ListObjApp
1d50: 65 6e 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 endElement(inter
1d60: 70 2c 20 6c 69 73 74 50 74 72 2c 20 54 63 6c 5f p, listPtr, Tcl_
1d70: 4e 65 77 53 74 72 69 6e 67 4f 62 6a 28 22 44 56 NewStringObj("DV
1d80: 43 53 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 09 69 CS", -1));..}..i
1d90: 66 20 28 75 73 61 67 65 20 26 20 58 4b 55 5f 41 f (usage & XKU_A
1da0: 4e 59 45 4b 55 29 20 7b 0a 09 20 20 20 20 54 63 NYEKU) {.. Tc
1db0: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
1dc0: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
1dd0: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
1de0: 74 72 69 6e 67 4f 62 6a 28 22 41 6e 79 20 45 78 tringObj("Any Ex
1df0: 74 65 6e 64 65 64 20 4b 65 79 20 55 73 61 67 65 tended Key Usage
1e00: 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 20 20 20 ", -1));..}.
1e10: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 } else {.. Tc
1e20: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
1e30: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c lement(interp, l
1e40: 69 73 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 istPtr, Tcl_NewS
1e50: 74 72 69 6e 67 4f 62 6a 28 22 75 6e 72 65 73 74 tringObj("unrest
1e60: 72 69 63 74 65 64 22 2c 20 2d 31 29 29 3b 0a 20 ricted", -1));.
1e70: 20 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 }. return
1e80: 6c 69 73 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 listPtr;.}../*.
1e90: 2a 20 47 65 74 20 43 52 4c 20 44 69 73 74 72 69 * Get CRL Distri
1ea0: 62 75 74 69 6f 6e 20 50 6f 69 6e 74 73 0a 20 2a bution Points. *
1eb0: 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 /.Tcl_Obj *Tls_x
1ec0: 35 30 39 43 72 6c 44 70 28 54 63 6c 5f 49 6e 74 509CrlDp(Tcl_Int
1ed0: 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 erp *interp, X50
1ee0: 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 53 9 *cert) {. S
1ef0: 54 41 43 4b 5f 4f 46 28 44 49 53 54 5f 50 4f 49 TACK_OF(DIST_POI
1f00: 4e 54 29 20 2a 63 72 6c 3b 0a 20 20 20 20 54 63 NT) *crl;. Tc
1f10: 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 74 72 20 3d l_Obj *listPtr =
1f20: 20 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 Tcl_NewListObj(
1f30: 30 2c 20 4e 55 4c 4c 29 3b 0a 0a 20 20 20 20 69 0, NULL);.. i
1f40: 66 20 28 6c 69 73 74 50 74 72 20 3d 3d 20 4e 55 f (listPtr == NU
1f50: 4c 4c 29 20 7b 0a 09 72 65 74 75 72 6e 20 4e 55 LL) {..return NU
1f60: 4c 4c 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 69 LL;. }.. i
1f70: 66 20 28 63 72 6c 20 3d 20 58 35 30 39 5f 67 65 f (crl = X509_ge
1f80: 74 5f 65 78 74 5f 64 32 69 28 63 65 72 74 2c 20 t_ext_d2i(cert,
1f90: 4e 49 44 5f 63 72 6c 5f 64 69 73 74 72 69 62 75 NID_crl_distribu
1fa0: 74 69 6f 6e 5f 70 6f 69 6e 74 73 2c 20 4e 55 4c tion_points, NUL
1fb0: 4c 2c 20 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 L, NULL)) {..for
1fc0: 20 28 69 6e 74 20 69 3d 30 3b 20 69 20 3c 20 73 (int i=0; i < s
1fd0: 6b 5f 44 49 53 54 5f 50 4f 49 4e 54 5f 6e 75 6d k_DIST_POINT_num
1fe0: 28 63 72 6c 29 3b 20 69 2b 2b 29 20 7b 0a 09 20 (crl); i++) {..
1ff0: 20 20 20 44 49 53 54 5f 50 4f 49 4e 54 20 2a 64 DIST_POINT *d
2000: 70 20 3d 20 73 6b 5f 44 49 53 54 5f 50 4f 49 4e p = sk_DIST_POIN
2010: 54 5f 76 61 6c 75 65 28 63 72 6c 2c 20 69 29 3b T_value(crl, i);
2020: 0a 09 20 20 20 20 44 49 53 54 5f 50 4f 49 4e 54 .. DIST_POINT
2030: 5f 4e 41 4d 45 20 2a 64 69 73 74 70 6f 69 6e 74 _NAME *distpoint
2040: 20 3d 20 64 70 2d 3e 64 69 73 74 70 6f 69 6e 74 = dp->distpoint
2050: 3b 0a 0a 09 20 20 20 20 69 66 20 28 64 69 73 74 ;... if (dist
2060: 70 6f 69 6e 74 2d 3e 74 79 70 65 20 3d 3d 20 30 point->type == 0
2070: 29 20 7b 0a 09 09 2f 2a 20 66 75 6c 6c 2d 6e 61 ) {.../* full-na
2080: 6d 65 20 47 45 4e 45 52 41 4c 49 5a 45 44 4e 41 me GENERALIZEDNA
2090: 4d 45 20 2a 2f 0a 09 09 66 6f 72 20 28 69 6e 74 ME */...for (int
20a0: 20 6a 20 3d 20 30 3b 20 6a 20 3c 20 73 6b 5f 47 j = 0; j < sk_G
20b0: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 6e 75 6d 28 ENERAL_NAME_num(
20c0: 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d 65 2e distpoint->name.
20d0: 66 75 6c 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 20 fullname); j++)
20e0: 7b 0a 09 09 20 20 20 20 47 45 4e 45 52 41 4c 5f {... GENERAL_
20f0: 4e 41 4d 45 20 2a 67 65 6e 20 3d 20 73 6b 5f 47 NAME *gen = sk_G
2100: 45 4e 45 52 41 4c 5f 4e 41 4d 45 5f 76 61 6c 75 ENERAL_NAME_valu
2110: 65 28 64 69 73 74 70 6f 69 6e 74 2d 3e 6e 61 6d e(distpoint->nam
2120: 65 2e 66 75 6c 6c 6e 61 6d 65 2c 20 6a 29 3b 0a e.fullname, j);.
2130: 09 09 20 20 20 20 69 6e 74 20 74 79 70 65 3b 0a .. int type;.
2140: 09 09 20 20 20 20 41 53 4e 31 5f 53 54 52 49 4e .. ASN1_STRIN
2150: 47 20 2a 75 72 69 20 3d 20 47 45 4e 45 52 41 4c G *uri = GENERAL
2160: 5f 4e 41 4d 45 5f 67 65 74 30 5f 76 61 6c 75 65 _NAME_get0_value
2170: 28 67 65 6e 2c 20 26 74 79 70 65 29 3b 0a 09 09 (gen, &type);...
2180: 20 20 20 20 69 66 20 28 74 79 70 65 20 3d 3d 20 if (type ==
2190: 47 45 4e 5f 55 52 49 29 20 7b 0a 09 09 09 4c 41 GEN_URI) {....LA
21a0: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 PPEND_STR(interp
21b0: 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 4c 4c 2c , listPtr, NULL,
21c0: 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f 67 65 74 ASN1_STRING_get
21d0: 30 5f 64 61 74 61 28 75 72 69 29 2c 20 41 53 4e 0_data(uri), ASN
21e0: 31 5f 53 54 52 49 4e 47 5f 6c 65 6e 67 74 68 28 1_STRING_length(
21f0: 75 72 69 29 29 3b 0a 09 09 20 20 20 20 7d 0a 09 uri));... }..
2200: 09 7d 0a 09 20 20 20 20 7d 20 65 6c 73 65 20 69 .}.. } else i
2210: 66 20 28 64 69 73 74 70 6f 69 6e 74 2d 3e 74 79 f (distpoint->ty
2220: 70 65 20 3d 3d 20 31 29 20 7b 0a 09 09 2f 2a 20 pe == 1) {.../*
2230: 72 65 6c 61 74 69 76 65 2d 6e 61 6d 65 20 58 35 relative-name X5
2240: 30 39 4e 41 4d 45 20 2a 2f 0a 09 09 53 54 41 43 09NAME */...STAC
2250: 4b 5f 4f 46 28 58 35 30 39 5f 4e 41 4d 45 5f 45 K_OF(X509_NAME_E
2260: 4e 54 52 59 29 20 2a 73 6b 5f 72 65 6c 6e 61 6d NTRY) *sk_relnam
2270: 65 20 3d 20 64 69 73 74 70 6f 69 6e 74 2d 3e 6e e = distpoint->n
2280: 61 6d 65 2e 72 65 6c 61 74 69 76 65 6e 61 6d 65 ame.relativename
2290: 3b 0a 09 09 66 6f 72 20 28 69 6e 74 20 6a 20 3d ;...for (int j =
22a0: 20 30 3b 20 6a 20 3c 20 73 6b 5f 58 35 30 39 5f 0; j < sk_X509_
22b0: 4e 41 4d 45 5f 45 4e 54 52 59 5f 6e 75 6d 28 73 NAME_ENTRY_num(s
22c0: 6b 5f 72 65 6c 6e 61 6d 65 29 3b 20 6a 2b 2b 29 k_relname); j++)
22d0: 20 7b 0a 09 09 20 20 20 20 58 35 30 39 5f 4e 41 {... X509_NA
22e0: 4d 45 5f 45 4e 54 52 59 20 2a 65 20 3d 20 73 6b ME_ENTRY *e = sk
22f0: 5f 58 35 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 _X509_NAME_ENTRY
2300: 5f 76 61 6c 75 65 28 73 6b 5f 72 65 6c 6e 61 6d _value(sk_relnam
2310: 65 2c 20 6a 29 3b 0a 09 09 20 20 20 20 41 53 4e e, j);... ASN
2320: 31 5f 53 54 52 49 4e 47 20 2a 64 20 3d 20 58 35 1_STRING *d = X5
2330: 30 39 5f 4e 41 4d 45 5f 45 4e 54 52 59 5f 67 65 09_NAME_ENTRY_ge
2340: 74 5f 64 61 74 61 28 65 29 3b 0a 09 09 20 20 20 t_data(e);...
2350: 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 LAPPEND_STR(int
2360: 65 72 70 2c 20 6c 69 73 74 50 74 72 2c 20 4e 55 erp, listPtr, NU
2370: 4c 4c 2c 20 41 53 4e 31 5f 53 54 52 49 4e 47 5f LL, ASN1_STRING_
2380: 64 61 74 61 28 64 29 2c 20 41 53 4e 31 5f 53 54 data(d), ASN1_ST
2390: 52 49 4e 47 5f 6c 65 6e 67 74 68 28 64 29 29 3b RING_length(d));
23a0: 0a 09 09 7d 0a 09 20 20 20 20 7d 0a 09 7d 0a 09 ...}.. }..}..
23b0: 43 52 4c 5f 44 49 53 54 5f 50 4f 49 4e 54 53 5f CRL_DIST_POINTS_
23c0: 66 72 65 65 28 63 72 6c 29 3b 0a 20 20 20 20 7d free(crl);. }
23d0: 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 74 . return list
23e0: 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 65 Ptr;.}../*. * Ge
23f0: 74 20 4f 6e 2d 6c 69 6e 65 20 43 65 72 74 69 66 t On-line Certif
2400: 69 63 61 74 65 20 53 74 61 74 75 73 20 50 72 6f icate Status Pro
2410: 74 6f 63 6f 6c 20 28 4f 53 43 50 29 20 55 52 4c tocol (OSCP) URL
2420: 0a 20 2a 2f 0a 54 63 6c 5f 4f 62 6a 20 2a 54 6c . */.Tcl_Obj *Tl
2430: 73 5f 78 35 30 39 4f 73 63 70 28 54 63 6c 5f 49 s_x509Oscp(Tcl_I
2440: 6e 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 nterp *interp, X
2450: 35 30 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 509 *cert) {.
2460: 20 53 54 41 43 4b 5f 4f 46 28 4f 50 45 4e 53 53 STACK_OF(OPENSS
2470: 4c 5f 53 54 52 49 4e 47 29 20 2a 6f 63 73 70 3b L_STRING) *ocsp;
2480: 0a 20 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 . Tcl_Obj *li
2490: 73 74 50 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c stPtr = Tcl_NewL
24a0: 69 73 74 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b istObj(0, NULL);
24b0: 0a 0a 20 20 20 20 69 66 20 28 6c 69 73 74 50 74 .. if (listPt
24c0: 72 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 r == NULL) {..re
24d0: 74 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d turn NULL;. }
24e0: 0a 0a 20 20 20 20 69 66 20 28 6f 63 73 70 20 3d .. if (ocsp =
24f0: 20 58 35 30 39 5f 67 65 74 31 5f 6f 63 73 70 28 X509_get1_ocsp(
2500: 63 65 72 74 29 29 20 7b 0a 09 66 6f 72 20 28 69 cert)) {..for (i
2510: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b nt i = 0; i < sk
2520: 5f 4f 50 45 4e 53 53 4c 5f 53 54 52 49 4e 47 5f _OPENSSL_STRING_
2530: 6e 75 6d 28 6f 63 73 70 29 3b 20 69 2b 2b 29 20 num(ocsp); i++)
2540: 7b 0a 09 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 {.. LAPPEND_S
2550: 54 52 28 69 6e 74 65 72 70 2c 20 6c 69 73 74 50 TR(interp, listP
2560: 74 72 2c 20 4e 55 4c 4c 2c 20 73 6b 5f 4f 50 45 tr, NULL, sk_OPE
2570: 4e 53 53 4c 5f 53 54 52 49 4e 47 5f 76 61 6c 75 NSSL_STRING_valu
2580: 65 28 6f 63 73 70 2c 20 69 29 2c 20 2d 31 29 3b e(ocsp, i), -1);
2590: 0a 09 7d 0a 09 58 35 30 39 5f 65 6d 61 69 6c 5f ..}..X509_email_
25a0: 66 72 65 65 28 6f 63 73 70 29 3b 0a 20 20 20 20 free(ocsp);.
25b0: 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c 69 73 }. return lis
25c0: 74 50 74 72 3b 0a 7d 0a 0a 2f 2a 0a 20 2a 20 47 tPtr;.}../*. * G
25d0: 65 74 20 43 65 72 74 69 66 69 63 61 74 65 20 41 et Certificate A
25e0: 75 74 68 6f 72 69 74 79 20 28 43 41 29 20 49 73 uthority (CA) Is
25f0: 73 75 65 72 73 20 55 52 4c 0a 20 2a 2f 0a 54 63 suers URL. */.Tc
2600: 6c 5f 4f 62 6a 20 2a 54 6c 73 5f 78 35 30 39 43 l_Obj *Tls_x509C
2610: 61 49 73 73 75 65 72 73 28 54 63 6c 5f 49 6e 74 aIssuers(Tcl_Int
2620: 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 erp *interp, X50
2630: 39 20 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 53 9 *cert) {. S
2640: 54 41 43 4b 5f 4f 46 28 41 43 43 45 53 53 5f 44 TACK_OF(ACCESS_D
2650: 45 53 43 52 49 50 54 49 4f 4e 29 20 2a 61 64 73 ESCRIPTION) *ads
2660: 3b 0a 20 20 20 20 41 43 43 45 53 53 5f 44 45 53 ;. ACCESS_DES
2670: 43 52 49 50 54 49 4f 4e 20 2a 61 64 3b 0a 20 20 CRIPTION *ad;.
2680: 20 20 54 63 6c 5f 4f 62 6a 20 2a 6c 69 73 74 50 Tcl_Obj *listP
2690: 74 72 20 3d 20 54 63 6c 5f 4e 65 77 4c 69 73 74 tr = Tcl_NewList
26a0: 4f 62 6a 28 30 2c 20 4e 55 4c 4c 29 3b 0a 20 20 Obj(0, NULL);.
26b0: 20 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 unsigned char
26c0: 2a 62 75 66 3b 0a 20 20 20 20 69 6e 74 20 6c 65 *buf;. int le
26d0: 6e 3b 0a 0a 20 20 20 20 69 66 20 28 61 64 73 20 n;.. if (ads
26e0: 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 5f 64 = X509_get_ext_d
26f0: 32 69 28 63 65 72 74 2c 20 4e 49 44 5f 69 6e 66 2i(cert, NID_inf
2700: 6f 5f 61 63 63 65 73 73 2c 20 4e 55 4c 4c 2c 20 o_access, NULL,
2710: 4e 55 4c 4c 29 29 20 7b 0a 09 66 6f 72 20 28 69 NULL)) {..for (i
2720: 6e 74 20 69 20 3d 20 30 3b 20 69 20 3c 20 73 6b nt i = 0; i < sk
2730: 5f 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 _ACCESS_DESCRIPT
2740: 49 4f 4e 5f 6e 75 6d 28 61 64 73 29 3b 20 69 2b ION_num(ads); i+
2750: 2b 29 20 7b 0a 09 20 20 20 20 61 64 20 3d 20 73 +) {.. ad = s
2760: 6b 5f 41 43 43 45 53 53 5f 44 45 53 43 52 49 50 k_ACCESS_DESCRIP
2770: 54 49 4f 4e 5f 76 61 6c 75 65 28 61 64 73 2c 20 TION_value(ads,
2780: 69 29 3b 0a 09 20 20 20 20 69 66 20 28 4f 42 4a i);.. if (OBJ
2790: 5f 6f 62 6a 32 6e 69 64 28 61 64 2d 3e 6d 65 74 _obj2nid(ad->met
27a0: 68 6f 64 29 20 3d 3d 20 4e 49 44 5f 61 64 5f 63 hod) == NID_ad_c
27b0: 61 5f 69 73 73 75 65 72 73 20 26 26 20 61 64 2d a_issuers && ad-
27c0: 3e 6c 6f 63 61 74 69 6f 6e 29 20 7b 0a 09 09 69 >location) {...i
27d0: 66 20 28 61 64 2d 3e 6c 6f 63 61 74 69 6f 6e 2d f (ad->location-
27e0: 3e 74 79 70 65 20 3d 3d 20 47 45 4e 5f 55 52 49 >type == GEN_URI
27f0: 29 20 7b 0a 09 09 20 20 20 20 6c 65 6e 20 3d 20 ) {... len =
2800: 41 53 4e 31 5f 53 54 52 49 4e 47 5f 74 6f 5f 55 ASN1_STRING_to_U
2810: 54 46 38 28 26 62 75 66 2c 20 61 64 2d 3e 6c 6f TF8(&buf, ad->lo
2820: 63 61 74 69 6f 6e 2d 3e 64 2e 75 6e 69 66 6f 72 cation->d.unifor
2830: 6d 52 65 73 6f 75 72 63 65 49 64 65 6e 74 69 66 mResourceIdentif
2840: 69 65 72 29 3b 0a 09 09 20 20 20 20 54 63 6c 5f ier);... Tcl_
2850: 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c 65 ListObjAppendEle
2860: 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 6c 69 73 ment(interp, lis
2870: 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 74 72 tPtr, Tcl_NewStr
2880: 69 6e 67 4f 62 6a 28 62 75 66 2c 20 6c 65 6e 29 ingObj(buf, len)
2890: 29 3b 0a 09 09 20 20 20 20 4f 50 45 4e 53 53 4c );... OPENSSL
28a0: 5f 66 72 65 65 28 62 75 66 29 3b 0a 09 09 20 20 _free(buf);...
28b0: 20 20 62 72 65 61 6b 3b 0a 09 09 7d 0a 09 20 20 break;...}..
28c0: 20 20 7d 0a 09 7d 0a 09 2f 2a 20 73 6b 5f 41 43 }..}../* sk_AC
28d0: 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f 4e CESS_DESCRIPTION
28e0: 5f 70 6f 70 5f 66 72 65 65 28 61 64 73 2c 20 41 _pop_free(ads, A
28f0: 43 43 45 53 53 5f 44 45 53 43 52 49 50 54 49 4f CCESS_DESCRIPTIO
2900: 4e 5f 66 72 65 65 29 3b 20 2a 2f 0a 09 41 55 54 N_free); */..AUT
2910: 48 4f 52 49 54 59 5f 49 4e 46 4f 5f 41 43 43 45 HORITY_INFO_ACCE
2920: 53 53 5f 66 72 65 65 28 61 64 73 29 3b 0a 20 20 SS_free(ads);.
2930: 20 20 7d 0a 20 20 20 20 72 65 74 75 72 6e 20 6c }. return l
2940: 69 73 74 50 74 72 3b 0a 7d 0a 0c 0a 2f 2a 0a 20 istPtr;.}.../*.
2950: 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *---------------
2960: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2970: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2980: 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 0a 20 2a 09 54 -------*. *. *.T
2990: 6c 73 5f 4e 65 77 58 35 30 39 4f 62 6a 20 2d 2d ls_NewX509Obj --
29a0: 0a 20 2a 0a 20 2a 09 2d 2d 2d 2d 2d 2d 2d 2d 2d . *. *.---------
29b0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
29c0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
29d0: 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 09 43 6f 6e 76 -------*. *.Conv
29e0: 65 72 74 73 20 61 20 58 35 30 39 20 63 65 72 74 erts a X509 cert
29f0: 69 66 69 63 61 74 65 20 69 6e 74 6f 20 61 20 54 ificate into a T
2a00: 63 6c 5f 4f 62 6a 0a 20 2a 09 2d 2d 2d 2d 2d 2d cl_Obj. *.------
2a10: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a20: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2a30: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 0a 20 ----------*. *.
2a40: 2a 09 53 69 64 65 20 65 66 66 65 63 74 73 3a 0a *.Side effects:.
2a50: 20 2a 09 09 4e 6f 6e 65 0a 20 2a 0a 20 2a 09 52 *..None. *. *.R
2a60: 65 73 75 6c 74 3a 0a 20 2a 09 09 41 20 54 63 6c esult:. *..A Tcl
2a70: 20 4c 69 73 74 20 4f 62 6a 65 63 74 20 72 65 70 List Object rep
2a80: 72 65 73 65 6e 74 69 6e 67 20 74 68 65 20 70 72 resenting the pr
2a90: 6f 76 69 64 65 64 0a 20 2a 09 09 58 35 30 39 20 ovided. *..X509
2aa0: 63 65 72 74 69 66 69 63 61 74 65 2e 0a 20 2a 0a certificate.. *.
2ab0: 20 2a 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d *--------------
2ac0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2ad0: 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d ----------------
2ae0: 2d 2d 2d 2d 2d 2d 2d 2d 2a 0a 20 2a 2f 0a 0a 54 --------*. */..T
2af0: 63 6c 5f 4f 62 6a 2a 0a 54 6c 73 5f 4e 65 77 58 cl_Obj*.Tls_NewX
2b00: 35 30 39 4f 62 6a 28 54 63 6c 5f 49 6e 74 65 72 509Obj(Tcl_Inter
2b10: 70 20 2a 69 6e 74 65 72 70 2c 20 58 35 30 39 20 p *interp, X509
2b20: 2a 63 65 72 74 29 20 7b 0a 20 20 20 20 54 63 6c *cert) {. Tcl
2b30: 5f 4f 62 6a 20 2a 63 65 72 74 50 74 72 20 3d 20 _Obj *certPtr =
2b40: 54 63 6c 5f 4e 65 77 4c 69 73 74 4f 62 6a 28 30 Tcl_NewListObj(0
2b50: 2c 20 4e 55 4c 4c 29 3b 0a 20 20 20 20 42 49 4f , NULL);. BIO
2b60: 20 2a 62 69 6f 20 3d 20 42 49 4f 5f 6e 65 77 28 *bio = BIO_new(
2b70: 42 49 4f 5f 73 5f 6d 65 6d 28 29 29 3b 0a 20 20 BIO_s_mem());.
2b80: 20 20 69 6e 74 20 6d 64 6e 69 64 2c 20 70 6b 6e int mdnid, pkn
2b90: 69 64 2c 20 62 69 74 73 2c 20 6c 65 6e 3b 0a 20 id, bits, len;.
2ba0: 20 20 20 75 69 6e 74 33 32 5f 74 20 78 66 6c 61 uint32_t xfla
2bb0: 67 73 3b 0a 20 20 20 20 63 68 61 72 20 62 75 66 gs;. char buf
2bc0: 66 65 72 5b 42 55 46 53 49 5a 5d 3b 0a 20 20 20 fer[BUFSIZ];.
2bd0: 20 75 6e 73 69 67 6e 65 64 20 63 68 61 72 20 6d unsigned char m
2be0: 64 5b 45 56 50 5f 4d 41 58 5f 4d 44 5f 53 49 5a d[EVP_MAX_MD_SIZ
2bf0: 45 5d 3b 0a 20 20 20 20 75 6e 73 69 67 6e 65 64 E];. unsigned
2c00: 20 6c 6f 6e 67 20 66 6c 61 67 73 20 3d 20 58 4e long flags = XN
2c10: 5f 46 4c 41 47 5f 52 46 43 32 32 35 33 20 7c 20 _FLAG_RFC2253 |
2c20: 41 53 4e 31 5f 53 54 52 46 4c 47 53 5f 55 54 46 ASN1_STRFLGS_UTF
2c30: 38 5f 43 4f 4e 56 45 52 54 3b 0a 20 20 20 20 66 8_CONVERT;. f
2c40: 6c 61 67 73 20 26 3d 20 7e 41 53 4e 31 5f 53 54 lags &= ~ASN1_ST
2c50: 52 46 4c 47 53 5f 45 53 43 5f 4d 53 42 3b 0a 0a RFLGS_ESC_MSB;..
2c60: 20 20 20 20 69 66 20 28 69 6e 74 65 72 70 20 3d if (interp =
2c70: 3d 20 4e 55 4c 4c 20 7c 7c 20 63 65 72 74 20 3d = NULL || cert =
2c80: 3d 20 4e 55 4c 4c 20 7c 7c 20 62 69 6f 20 3d 3d = NULL || bio ==
2c90: 20 4e 55 4c 4c 20 7c 7c 20 63 65 72 74 50 74 72 NULL || certPtr
2ca0: 20 3d 3d 20 4e 55 4c 4c 29 20 7b 0a 09 72 65 74 == NULL) {..ret
2cb0: 75 72 6e 20 4e 55 4c 4c 3b 0a 20 20 20 20 7d 0a urn NULL;. }.
2cc0: 0a 20 20 20 20 2f 2a 20 53 69 67 6e 61 74 75 72 . /* Signatur
2cd0: 65 20 61 6c 67 6f 72 69 74 68 6d 20 61 6e 64 20 e algorithm and
2ce0: 76 61 6c 75 65 20 2d 20 52 46 43 20 35 32 38 30 value - RFC 5280
2cf0: 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 31 2e 32 section 4.1.1.2
2d00: 20 61 6e 64 20 34 2e 31 2e 31 2e 33 20 2a 2f 0a and 4.1.1.3 */.
2d10: 20 20 20 20 2f 2a 20 73 69 67 6e 61 74 75 72 65 /* signature
2d20: 41 6c 67 6f 72 69 74 68 6d 20 69 73 20 74 68 65 Algorithm is the
2d30: 20 69 64 20 6f 66 20 74 68 65 20 63 72 79 70 74 id of the crypt
2d40: 6f 67 72 61 70 68 69 63 20 61 6c 67 6f 72 69 74 ographic algorit
2d50: 68 6d 20 75 73 65 64 20 62 79 20 74 68 65 0a 09 hm used by the..
2d60: 43 41 20 74 6f 20 73 69 67 6e 20 74 68 69 73 20 CA to sign this
2d70: 63 65 72 74 2e 20 73 69 67 6e 61 74 75 72 65 56 cert. signatureV
2d80: 61 6c 75 65 20 69 73 20 74 68 65 20 64 69 67 69 alue is the digi
2d90: 74 61 6c 20 73 69 67 6e 61 74 75 72 65 20 63 6f tal signature co
2da0: 6d 70 75 74 65 64 0a 09 75 70 6f 6e 20 74 68 65 mputed..upon the
2db0: 20 41 53 4e 2e 31 20 44 45 52 20 65 6e 63 6f 64 ASN.1 DER encod
2dc0: 65 64 20 74 62 73 43 65 72 74 69 66 69 63 61 74 ed tbsCertificat
2dd0: 65 2e 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 6f 6e e. */. {..con
2de0: 73 74 20 58 35 30 39 5f 41 4c 47 4f 52 20 2a 73 st X509_ALGOR *s
2df0: 69 67 5f 61 6c 67 3b 0a 09 63 6f 6e 73 74 20 41 ig_alg;..const A
2e00: 53 4e 31 5f 42 49 54 5f 53 54 52 49 4e 47 20 2a SN1_BIT_STRING *
2e10: 73 69 67 3b 0a 09 69 6e 74 20 73 69 67 5f 6e 69 sig;..int sig_ni
2e20: 64 3b 0a 0a 09 58 35 30 39 5f 67 65 74 30 5f 73 d;...X509_get0_s
2e30: 69 67 6e 61 74 75 72 65 28 26 73 69 67 2c 20 26 ignature(&sig, &
2e40: 73 69 67 5f 61 6c 67 2c 20 63 65 72 74 29 3b 0a sig_alg, cert);.
2e50: 09 2f 2a 20 73 69 67 5f 6e 69 64 20 3d 20 58 35 ./* sig_nid = X5
2e60: 30 39 5f 67 65 74 5f 73 69 67 6e 61 74 75 72 65 09_get_signature
2e70: 5f 6e 69 64 28 63 65 72 74 29 20 2a 2f 0a 09 73 _nid(cert) */..s
2e80: 69 67 5f 6e 69 64 20 3d 20 4f 42 4a 5f 6f 62 6a ig_nid = OBJ_obj
2e90: 32 6e 69 64 28 73 69 67 5f 61 6c 67 2d 3e 61 6c 2nid(sig_alg->al
2ea0: 67 6f 72 69 74 68 6d 29 3b 0a 09 4c 41 50 50 45 gorithm);..LAPPE
2eb0: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 ND_STR(interp, c
2ec0: 65 72 74 50 74 72 2c 20 22 73 69 67 6e 61 74 75 ertPtr, "signatu
2ed0: 72 65 41 6c 67 6f 72 69 74 68 6d 22 2c 20 4f 42 reAlgorithm", OB
2ee0: 4a 5f 6e 69 64 32 6c 6e 28 73 69 67 5f 6e 69 64 J_nid2ln(sig_nid
2ef0: 29 2c 20 2d 31 29 3b 0a 09 6c 65 6e 20 3d 20 28 ), -1);..len = (
2f00: 73 69 67 5f 6e 69 64 20 21 3d 20 4e 49 44 5f 75 sig_nid != NID_u
2f10: 6e 64 65 66 29 20 3f 20 53 74 72 69 6e 67 5f 74 ndef) ? String_t
2f20: 6f 5f 48 65 78 28 73 69 67 2d 3e 64 61 74 61 2c o_Hex(sig->data,
2f30: 20 73 69 67 2d 3e 6c 65 6e 67 74 68 2c 20 62 75 sig->length, bu
2f40: 66 66 65 72 2c 20 42 55 46 53 49 5a 29 20 3a 20 ffer, BUFSIZ) :
2f50: 30 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 0;..LAPPEND_STR(
2f60: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
2f70: 20 22 73 69 67 6e 61 74 75 72 65 56 61 6c 75 65 "signatureValue
2f80: 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b ", buffer, len);
2f90: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 56 . }.. /* V
2fa0: 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 65 6e ersion of the en
2fb0: 63 6f 64 65 64 20 63 65 72 74 69 66 69 63 61 74 coded certificat
2fc0: 65 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 e - RFC 5280 sec
2fd0: 74 69 6f 6e 20 34 2e 31 2e 32 2e 31 20 2a 2f 0a tion 4.1.2.1 */.
2fe0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 4c 4f 4e 47 LAPPEND_LONG
2ff0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3000: 2c 20 22 76 65 72 73 69 6f 6e 22 2c 20 58 35 30 , "version", X50
3010: 39 5f 67 65 74 5f 76 65 72 73 69 6f 6e 28 63 65 9_get_version(ce
3020: 72 74 29 2b 31 29 3b 0a 0a 20 20 20 20 2f 2a 20 rt)+1);.. /*
3030: 55 6e 69 71 75 65 20 6e 75 6d 62 65 72 20 61 73 Unique number as
3040: 73 69 67 6e 65 64 20 62 79 20 43 41 20 74 6f 20 signed by CA to
3050: 63 65 72 74 69 66 69 63 61 74 65 20 2d 20 52 46 certificate - RF
3060: 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 C 5280 section 4
3070: 2e 31 2e 32 2e 32 20 2a 2f 0a 20 20 20 20 6c 65 .1.2.2 */. le
3080: 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 65 n = BIO_to_Buffe
3090: 72 28 69 32 61 5f 41 53 4e 31 5f 49 4e 54 45 47 r(i2a_ASN1_INTEG
30a0: 45 52 28 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 ER(bio, X509_get
30b0: 30 5f 73 65 72 69 61 6c 4e 75 6d 62 65 72 28 63 0_serialNumber(c
30c0: 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 75 66 66 ert)), bio, buff
30d0: 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 20 20 20 er, BUFSIZ);.
30e0: 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 LAPPEND_STR(int
30f0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 erp, certPtr, "s
3100: 65 72 69 61 6c 4e 75 6d 62 65 72 22 2c 20 62 75 erialNumber", bu
3110: 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 ffer, len);..
3120: 20 2f 2a 20 53 69 67 6e 61 74 75 72 65 20 61 6c /* Signature al
3130: 67 6f 72 69 74 68 6d 20 75 73 65 64 20 62 79 20 gorithm used by
3140: 74 68 65 20 43 41 20 74 6f 20 73 69 67 6e 20 74 the CA to sign t
3150: 68 65 20 63 65 72 74 69 66 69 63 61 74 65 2e 20 he certificate.
3160: 4d 75 73 74 20 6d 61 74 63 68 0a 09 73 69 67 6e Must match..sign
3170: 61 74 75 72 65 41 6c 67 6f 72 69 74 68 6d 2e 20 atureAlgorithm.
3180: 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e RFC 5280 section
3190: 20 34 2e 31 2e 32 2e 33 20 2a 2f 0a 20 20 20 20 4.1.2.3 */.
31a0: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
31b0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 rp, certPtr, "si
31c0: 67 6e 61 74 75 72 65 22 2c 20 4f 42 4a 5f 6e 69 gnature", OBJ_ni
31d0: 64 32 6c 6e 28 58 35 30 39 5f 67 65 74 5f 73 69 d2ln(X509_get_si
31e0: 67 6e 61 74 75 72 65 5f 6e 69 64 28 63 65 72 74 gnature_nid(cert
31f0: 29 29 2c 20 2d 31 29 3b 0a 0a 20 20 20 20 2f 2a )), -1);.. /*
3200: 20 49 73 73 75 65 72 20 69 64 65 6e 74 69 66 69 Issuer identifi
3210: 65 73 20 74 68 65 20 65 6e 74 69 74 79 20 74 68 es the entity th
3220: 61 74 20 73 69 67 6e 65 64 20 61 6e 64 20 69 73 at signed and is
3230: 73 75 65 64 20 74 68 65 20 63 65 72 74 2e 20 52 sued the cert. R
3240: 46 43 20 35 32 38 30 20 73 65 63 74 69 6f 6e 20 FC 5280 section
3250: 34 2e 31 2e 32 2e 34 20 2a 2f 0a 20 20 20 20 6c 4.1.2.4 */. l
3260: 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 en = BIO_to_Buff
3270: 65 72 28 58 35 30 39 5f 4e 41 4d 45 5f 70 72 69 er(X509_NAME_pri
3280: 6e 74 5f 65 78 28 62 69 6f 2c 20 58 35 30 39 5f nt_ex(bio, X509_
3290: 67 65 74 5f 69 73 73 75 65 72 5f 6e 61 6d 65 28 get_issuer_name(
32a0: 63 65 72 74 29 2c 20 30 2c 20 66 6c 61 67 73 29 cert), 0, flags)
32b0: 2c 20 62 69 6f 2c 20 62 75 66 66 65 72 2c 20 42 , bio, buffer, B
32c0: 55 46 53 49 5a 29 3b 0a 20 20 20 20 4c 41 50 50 UFSIZ);. LAPP
32d0: 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 END_STR(interp,
32e0: 63 65 72 74 50 74 72 2c 20 22 69 73 73 75 65 72 certPtr, "issuer
32f0: 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b ", buffer, len);
3300: 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 69 .. /* Certifi
3310: 63 61 74 65 20 76 61 6c 69 64 69 74 79 20 70 65 cate validity pe
3320: 72 69 6f 64 20 69 73 20 74 68 65 20 69 6e 74 65 riod is the inte
3330: 72 76 61 6c 20 74 68 65 20 43 41 20 77 61 72 72 rval the CA warr
3340: 61 6e 74 73 20 74 68 61 74 20 69 74 20 77 69 6c ants that it wil
3350: 6c 0a 09 6d 61 69 6e 74 61 69 6e 20 69 6e 66 6f l..maintain info
3360: 20 6f 6e 20 74 68 65 20 73 74 61 74 75 73 20 6f on the status o
3370: 66 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 f the certificat
3380: 65 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 e. RFC 5280 sect
3390: 69 6f 6e 20 34 2e 31 2e 32 2e 35 20 2a 2f 0a 20 ion 4.1.2.5 */.
33a0: 20 20 20 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 /* Get Validi
33b0: 74 79 20 2d 20 4e 6f 74 20 42 65 66 6f 72 65 20 ty - Not Before
33c0: 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f */. len = BIO
33d0: 5f 74 6f 5f 42 75 66 66 65 72 28 41 53 4e 31 5f _to_Buffer(ASN1_
33e0: 54 49 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 TIME_print(bio,
33f0: 58 35 30 39 5f 67 65 74 30 5f 6e 6f 74 42 65 66 X509_get0_notBef
3400: 6f 72 65 28 63 65 72 74 29 29 2c 20 62 69 6f 2c ore(cert)), bio,
3410: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 buffer, BUFSIZ)
3420: 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 ;. LAPPEND_ST
3430: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 R(interp, certPt
3440: 72 2c 20 22 6e 6f 74 42 65 66 6f 72 65 22 2c 20 r, "notBefore",
3450: 62 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 buffer, len);..
3460: 20 20 20 2f 2a 20 47 65 74 20 56 61 6c 69 64 69 /* Get Validi
3470: 74 79 20 2d 20 4e 6f 74 20 41 66 74 65 72 20 2a ty - Not After *
3480: 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 49 4f 5f /. len = BIO_
3490: 74 6f 5f 42 75 66 66 65 72 28 41 53 4e 31 5f 54 to_Buffer(ASN1_T
34a0: 49 4d 45 5f 70 72 69 6e 74 28 62 69 6f 2c 20 58 IME_print(bio, X
34b0: 35 30 39 5f 67 65 74 30 5f 6e 6f 74 41 66 74 65 509_get0_notAfte
34c0: 72 28 63 65 72 74 29 29 2c 20 62 69 6f 2c 20 62 r(cert)), bio, b
34d0: 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a uffer, BUFSIZ);.
34e0: 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 54 52 28 LAPPEND_STR(
34f0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
3500: 20 22 6e 6f 74 41 66 74 65 72 22 2c 20 62 75 66 "notAfter", buf
3510: 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 20 20 fer, len);..
3520: 2f 2a 20 53 75 62 6a 65 63 74 20 69 64 65 6e 74 /* Subject ident
3530: 69 66 69 65 73 20 74 68 65 20 65 6e 74 69 74 79 ifies the entity
3540: 20 61 73 73 6f 63 69 61 74 65 64 20 77 69 74 68 associated with
3550: 20 74 68 65 20 70 75 62 6c 69 63 20 6b 65 79 20 the public key
3560: 73 74 6f 72 65 64 20 69 6e 0a 09 74 68 65 20 73 stored in..the s
3570: 75 62 6a 65 63 74 20 70 75 62 6c 69 63 20 6b 65 ubject public ke
3580: 79 20 66 69 65 6c 64 2e 20 52 46 43 20 35 32 38 y field. RFC 528
3590: 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 32 2e 0 section 4.1.2.
35a0: 36 20 2a 2f 0a 20 20 20 20 6c 65 6e 20 3d 20 42 6 */. len = B
35b0: 49 4f 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 IO_to_Buffer(X50
35c0: 39 5f 4e 41 4d 45 5f 70 72 69 6e 74 5f 65 78 28 9_NAME_print_ex(
35d0: 62 69 6f 2c 20 58 35 30 39 5f 67 65 74 5f 73 75 bio, X509_get_su
35e0: 62 6a 65 63 74 5f 6e 61 6d 65 28 63 65 72 74 29 bject_name(cert)
35f0: 2c 20 30 2c 20 66 6c 61 67 73 29 2c 20 62 69 6f , 0, flags), bio
3600: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a , buffer, BUFSIZ
3610: 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 53 );. LAPPEND_S
3620: 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 TR(interp, certP
3630: 74 72 2c 20 22 73 75 62 6a 65 63 74 22 2c 20 62 tr, "subject", b
3640: 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 20 20 uffer, len);..
3650: 20 20 2f 2a 20 53 48 41 31 20 44 69 67 65 73 74 /* SHA1 Digest
3660: 20 28 46 69 6e 67 65 72 70 72 69 6e 74 29 20 6f (Fingerprint) o
3670: 66 20 63 65 72 74 20 2d 20 44 45 52 20 72 65 70 f cert - DER rep
3680: 72 65 73 65 6e 74 61 74 69 6f 6e 20 2a 2f 0a 20 resentation */.
3690: 20 20 20 69 66 20 28 58 35 30 39 5f 64 69 67 65 if (X509_dige
36a0: 73 74 28 63 65 72 74 2c 20 45 56 50 5f 73 68 61 st(cert, EVP_sha
36b0: 31 28 29 2c 20 6d 64 2c 20 26 6c 65 6e 29 29 20 1(), md, &len))
36c0: 7b 0a 20 20 20 20 6c 65 6e 20 3d 20 53 74 72 69 {. len = Stri
36d0: 6e 67 5f 74 6f 5f 48 65 78 28 6d 64 2c 20 6c 65 ng_to_Hex(md, le
36e0: 6e 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 n, buffer, BUFSI
36f0: 5a 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 Z);..LAPPEND_STR
3700: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
3710: 2c 20 22 73 68 61 31 5f 68 61 73 68 22 2c 20 62 , "sha1_hash", b
3720: 75 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 20 20 20 uffer, len);.
3730: 20 7d 0a 0a 20 20 20 20 2f 2a 20 53 48 41 32 35 }.. /* SHA25
3740: 36 20 44 69 67 65 73 74 20 28 46 69 6e 67 65 72 6 Digest (Finger
3750: 70 72 69 6e 74 29 20 6f 66 20 63 65 72 74 20 2d print) of cert -
3760: 20 44 45 52 20 72 65 70 72 65 73 65 6e 74 61 74 DER representat
3770: 69 6f 6e 20 2a 2f 0a 20 20 20 20 69 66 20 28 58 ion */. if (X
3780: 35 30 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c 509_digest(cert,
3790: 20 45 56 50 5f 73 68 61 32 35 36 28 29 2c 20 6d EVP_sha256(), m
37a0: 64 2c 20 26 6c 65 6e 29 29 20 7b 0a 20 20 20 20 d, &len)) {.
37b0: 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f 5f len = String_to_
37c0: 48 65 78 28 6d 64 2c 20 6c 65 6e 2c 20 62 75 66 Hex(md, len, buf
37d0: 66 65 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 4c fer, BUFSIZ);..L
37e0: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 APPEND_STR(inter
37f0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 68 61 p, certPtr, "sha
3800: 32 35 36 5f 68 61 73 68 22 2c 20 62 75 66 66 65 256_hash", buffe
3810: 72 2c 20 6c 65 6e 29 3b 0a 20 20 20 20 7d 0a 0a r, len);. }..
3820: 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 50 /* Subject P
3830: 75 62 6c 69 63 20 4b 65 79 20 49 6e 66 6f 20 73 ublic Key Info s
3840: 70 65 63 69 66 69 65 73 20 74 68 65 20 70 75 62 pecifies the pub
3850: 6c 69 63 20 6b 65 79 20 61 6e 64 20 69 64 65 6e lic key and iden
3860: 74 69 66 69 65 73 20 74 68 65 0a 09 61 6c 67 6f tifies the..algo
3870: 72 69 74 68 6d 20 77 69 74 68 20 77 68 69 63 68 rithm with which
3880: 20 74 68 65 20 6b 65 79 20 69 73 20 75 73 65 64 the key is used
3890: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
38a0: 6f 6e 20 34 2e 31 2e 32 2e 37 20 2a 2f 0a 20 20 on 4.1.2.7 */.
38b0: 20 20 69 66 20 28 58 35 30 39 5f 67 65 74 5f 73 if (X509_get_s
38c0: 69 67 6e 61 74 75 72 65 5f 69 6e 66 6f 28 63 65 ignature_info(ce
38d0: 72 74 2c 20 26 6d 64 6e 69 64 2c 20 26 70 6b 6e rt, &mdnid, &pkn
38e0: 69 64 2c 20 26 62 69 74 73 2c 20 26 78 66 6c 61 id, &bits, &xfla
38f0: 67 73 29 29 20 7b 0a 09 41 53 4e 31 5f 42 49 54 gs)) {..ASN1_BIT
3900: 5f 53 54 52 49 4e 47 20 2a 6b 65 79 3b 0a 09 75 _STRING *key;..u
3910: 6e 73 69 67 6e 65 64 20 69 6e 74 20 6e 3b 0a 0a nsigned int n;..
3920: 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 .LAPPEND_STR(int
3930: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 erp, certPtr, "s
3940: 69 67 6e 69 6e 67 44 69 67 65 73 74 22 2c 20 4f igningDigest", O
3950: 42 4a 5f 6e 69 64 32 6c 6e 28 6d 64 6e 69 64 29 BJ_nid2ln(mdnid)
3960: 2c 20 2d 31 29 3b 0a 09 4c 41 50 50 45 4e 44 5f , -1);..LAPPEND_
3970: 53 54 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 STR(interp, cert
3980: 50 74 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 41 Ptr, "publicKeyA
3990: 6c 67 6f 72 69 74 68 6d 22 2c 20 4f 42 4a 5f 6e lgorithm", OBJ_n
39a0: 69 64 32 6c 6e 28 70 6b 6e 69 64 29 2c 20 2d 31 id2ln(pknid), -1
39b0: 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 49 4e 54 28 );..LAPPEND_INT(
39c0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
39d0: 20 22 62 69 74 73 22 2c 20 62 69 74 73 29 3b 20 "bits", bits);
39e0: 2f 2a 20 45 66 66 65 63 74 69 76 65 20 73 65 63 /* Effective sec
39f0: 75 72 69 74 79 20 62 69 74 73 20 2a 2f 0a 0a 09 urity bits */...
3a00: 6b 65 79 20 3d 20 58 35 30 39 5f 67 65 74 30 5f key = X509_get0_
3a10: 70 75 62 6b 65 79 5f 62 69 74 73 74 72 28 63 65 pubkey_bitstr(ce
3a20: 72 74 29 3b 0a 09 6c 65 6e 20 3d 20 53 74 72 69 rt);..len = Stri
3a30: 6e 67 5f 74 6f 5f 48 65 78 28 6b 65 79 2d 3e 64 ng_to_Hex(key->d
3a40: 61 74 61 2c 20 6b 65 79 2d 3e 6c 65 6e 67 74 68 ata, key->length
3a50: 2c 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a , buffer, BUFSIZ
3a60: 29 3b 0a 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 );..LAPPEND_STR(
3a70: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
3a80: 20 22 70 75 62 6c 69 63 4b 65 79 22 2c 20 62 75 "publicKey", bu
3a90: 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 0a 09 6c 65 ffer, len);...le
3aa0: 6e 20 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 39 n = 0;..if (X509
3ab0: 5f 70 75 62 6b 65 79 5f 64 69 67 65 73 74 28 63 _pubkey_digest(c
3ac0: 65 72 74 2c 20 45 56 50 5f 67 65 74 5f 64 69 67 ert, EVP_get_dig
3ad0: 65 73 74 62 79 6e 69 64 28 70 6b 6e 69 64 29 2c estbynid(pknid),
3ae0: 20 6d 64 2c 20 26 6e 29 29 20 7b 0a 09 20 20 20 md, &n)) {..
3af0: 20 6c 65 6e 20 3d 20 53 74 72 69 6e 67 5f 74 6f len = String_to
3b00: 5f 48 65 78 28 6d 64 2c 20 28 69 6e 74 29 6e 2c _Hex(md, (int)n,
3b10: 20 62 75 66 66 65 72 2c 20 42 55 46 53 49 5a 29 buffer, BUFSIZ)
3b20: 3b 0a 09 7d 0a 09 4c 41 50 50 45 4e 44 5f 53 54 ;..}..LAPPEND_ST
3b30: 52 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 R(interp, certPt
3b40: 72 2c 20 22 70 75 62 6c 69 63 4b 65 79 48 61 73 r, "publicKeyHas
3b50: 68 22 2c 20 62 75 66 66 65 72 2c 20 6c 65 6e 29 h", buffer, len)
3b60: 3b 0a 0a 09 2f 2a 20 64 69 67 65 73 74 20 6f 66 ;.../* digest of
3b70: 20 74 68 65 20 44 45 52 20 72 65 70 72 65 73 65 the DER represe
3b80: 6e 74 61 74 69 6f 6e 20 6f 66 20 74 68 65 20 63 ntation of the c
3b90: 65 72 74 69 66 69 63 61 74 65 20 2a 2f 0a 09 6c ertificate */..l
3ba0: 65 6e 20 3d 20 30 3b 0a 09 69 66 20 28 58 35 30 en = 0;..if (X50
3bb0: 39 5f 64 69 67 65 73 74 28 63 65 72 74 2c 20 45 9_digest(cert, E
3bc0: 56 50 5f 67 65 74 5f 64 69 67 65 73 74 62 79 6e VP_get_digestbyn
3bd0: 69 64 28 6d 64 6e 69 64 29 2c 20 6d 64 2c 20 26 id(mdnid), md, &
3be0: 6e 29 29 20 7b 0a 09 20 20 20 20 6c 65 6e 20 3d n)) {.. len =
3bf0: 20 53 74 72 69 6e 67 5f 74 6f 5f 48 65 78 28 6d String_to_Hex(m
3c00: 64 2c 20 28 69 6e 74 29 6e 2c 20 62 75 66 66 65 d, (int)n, buffe
3c10: 72 2c 20 42 55 46 53 49 5a 29 3b 0a 09 7d 0a 09 r, BUFSIZ);..}..
3c20: 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 LAPPEND_STR(inte
3c30: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 69 rp, certPtr, "si
3c40: 67 6e 61 74 75 72 65 48 61 73 68 22 2c 20 62 75 gnatureHash", bu
3c50: 66 66 65 72 2c 20 6c 65 6e 29 3b 0a 20 20 20 20 ffer, len);.
3c60: 7d 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 66 }.. /* Certif
3c70: 69 63 61 74 65 20 50 75 72 70 6f 73 65 2e 20 43 icate Purpose. C
3c80: 61 6c 6c 20 62 65 66 6f 72 65 20 63 68 65 63 6b all before check
3c90: 69 6e 67 20 66 6f 72 20 65 78 74 65 6e 73 69 6f ing for extensio
3ca0: 6e 73 2e 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 ns. */. LAPPE
3cb0: 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 2c 20 63 ND_STR(interp, c
3cc0: 65 72 74 50 74 72 2c 20 22 70 75 72 70 6f 73 65 ertPtr, "purpose
3cd0: 22 2c 20 54 6c 73 5f 78 35 30 39 50 75 72 70 6f ", Tls_x509Purpo
3ce0: 73 65 28 63 65 72 74 29 2c 20 2d 31 29 3b 0a 20 se(cert), -1);.
3cf0: 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 LAPPEND_OBJ(i
3d00: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
3d10: 22 63 65 72 74 69 66 69 63 61 74 65 50 75 72 70 "certificatePurp
3d20: 6f 73 65 22 2c 20 54 6c 73 5f 78 35 30 39 50 75 ose", Tls_x509Pu
3d30: 72 70 6f 73 65 73 28 69 6e 74 65 72 70 2c 20 63 rposes(interp, c
3d40: 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 47 ert));.. /* G
3d50: 65 74 20 65 78 74 65 6e 73 69 6f 6e 73 20 66 6c et extensions fl
3d60: 61 67 73 20 2a 2f 0a 20 20 20 20 78 66 6c 61 67 ags */. xflag
3d70: 73 20 3d 20 58 35 30 39 5f 67 65 74 5f 65 78 74 s = X509_get_ext
3d80: 65 6e 73 69 6f 6e 5f 66 6c 61 67 73 28 63 65 72 ension_flags(cer
3d90: 74 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f t);. LAPPEND_
3da0: 49 4e 54 28 69 6e 74 65 72 70 2c 20 63 65 72 74 INT(interp, cert
3db0: 50 74 72 2c 20 22 65 78 74 46 6c 61 67 73 22 2c Ptr, "extFlags",
3dc0: 20 78 66 6c 61 67 73 29 3b 0a 0a 09 2f 2a 20 43 xflags);.../* C
3dd0: 68 65 63 6b 20 69 66 20 63 65 72 74 20 77 61 73 heck if cert was
3de0: 20 69 73 73 75 65 64 20 62 79 20 43 41 20 63 65 issued by CA ce
3df0: 72 74 20 69 73 73 75 65 72 20 6f 72 20 73 65 6c rt issuer or sel
3e00: 66 20 73 69 67 6e 65 64 20 2a 2f 0a 20 20 20 20 f signed */.
3e10: 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 LAPPEND_BOOL(int
3e20: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 73 erp, certPtr, "s
3e30: 65 6c 66 49 73 73 75 65 64 22 2c 20 78 66 6c 61 elfIssued", xfla
3e40: 67 73 20 26 20 45 58 46 4c 41 47 5f 53 49 29 3b gs & EXFLAG_SI);
3e50: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f . LAPPEND_BOO
3e60: 4c 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 L(interp, certPt
3e70: 72 2c 20 22 73 65 6c 66 53 69 67 6e 65 64 22 2c r, "selfSigned",
3e80: 20 78 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 xflags & EXFLAG
3e90: 5f 53 53 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e _SS);. LAPPEN
3ea0: 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 2c 20 63 D_BOOL(interp, c
3eb0: 65 72 74 50 74 72 2c 20 22 69 73 50 72 6f 78 79 ertPtr, "isProxy
3ec0: 43 65 72 74 22 2c 20 78 66 6c 61 67 73 20 26 20 Cert", xflags &
3ed0: 45 58 46 4c 41 47 5f 50 52 4f 58 59 29 3b 0a 20 EXFLAG_PROXY);.
3ee0: 20 20 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 LAPPEND_BOOL(
3ef0: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
3f00: 20 22 65 78 74 49 6e 76 61 6c 69 64 22 2c 20 78 "extInvalid", x
3f10: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 49 flags & EXFLAG_I
3f20: 4e 56 41 4c 49 44 29 3b 0a 20 20 20 20 4c 41 50 NVALID);. LAP
3f30: 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e 74 65 72 70 PEND_BOOL(interp
3f40: 2c 20 63 65 72 74 50 74 72 2c 20 22 69 73 43 41 , certPtr, "isCA
3f50: 43 65 72 74 22 2c 20 58 35 30 39 5f 63 68 65 63 Cert", X509_chec
3f60: 6b 5f 63 61 28 63 65 72 74 29 29 3b 0a 0a 20 20 k_ca(cert));..
3f70: 20 20 2f 2a 20 54 68 65 20 55 6e 69 71 75 65 20 /* The Unique
3f80: 49 64 73 20 61 72 65 20 75 73 65 64 20 74 6f 20 Ids are used to
3f90: 68 61 6e 64 6c 65 20 74 68 65 20 70 6f 73 73 69 handle the possi
3fa0: 62 69 6c 69 74 79 20 6f 66 20 72 65 75 73 65 20 bility of reuse
3fb0: 6f 66 20 73 75 62 6a 65 63 74 0a 09 61 6e 64 2f of subject..and/
3fc0: 6f 72 20 69 73 73 75 65 72 20 6e 61 6d 65 73 20 or issuer names
3fd0: 6f 76 65 72 20 74 69 6d 65 2e 20 52 46 43 20 35 over time. RFC 5
3fe0: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 31 2e 280 section 4.1.
3ff0: 32 2e 38 20 2a 2f 0a 20 20 20 20 7b 0a 09 63 6f 2.8 */. {..co
4000: 6e 73 74 20 41 53 4e 31 5f 42 49 54 5f 53 54 52 nst ASN1_BIT_STR
4010: 49 4e 47 20 2a 69 75 69 64 2c 20 2a 73 75 69 64 ING *iuid, *suid
4020: 3b 0a 20 20 20 20 20 20 20 20 58 35 30 39 5f 67 ;. X509_g
4030: 65 74 30 5f 75 69 64 73 28 63 65 72 74 2c 20 26 et0_uids(cert, &
4040: 69 75 69 64 2c 20 26 73 75 69 64 29 3b 0a 0a 09 iuid, &suid);...
4050: 54 63 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e Tcl_ListObjAppen
4060: 64 45 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c dElement(interp,
4070: 20 63 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 certPtr, Tcl_Ne
4080: 77 53 74 72 69 6e 67 4f 62 6a 28 22 69 73 73 75 wStringObj("issu
4090: 65 72 55 6e 69 71 75 65 49 64 22 2c 20 2d 31 29 erUniqueId", -1)
40a0: 29 3b 0a 09 69 66 20 28 69 75 69 64 20 21 3d 20 );..if (iuid !=
40b0: 4e 55 4c 4c 29 20 7b 0a 09 20 20 20 20 54 63 6c NULL) {.. Tcl
40c0: 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 6c _ListObjAppendEl
40d0: 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 65 ement(interp, ce
40e0: 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 42 79 rtPtr, Tcl_NewBy
40f0: 74 65 41 72 72 61 79 4f 62 6a 28 28 63 68 61 72 teArrayObj((char
4100: 20 2a 29 69 75 69 64 2d 3e 64 61 74 61 2c 20 69 *)iuid->data, i
4110: 75 69 64 2d 3e 6c 65 6e 67 74 68 29 29 3b 0a 09 uid->length));..
4120: 7d 20 65 6c 73 65 20 7b 0a 09 20 20 20 20 54 63 } else {.. Tc
4130: 6c 5f 4c 69 73 74 4f 62 6a 41 70 70 65 6e 64 45 l_ListObjAppendE
4140: 6c 65 6d 65 6e 74 28 69 6e 74 65 72 70 2c 20 63 lement(interp, c
4150: 65 72 74 50 74 72 2c 20 54 63 6c 5f 4e 65 77 53 ertPtr, Tcl_NewS
4160: 74 72 69 6e 67 4f 62 6a 28 22 22 2c 20 2d 31 29 tringObj("", -1)
4170: 29 3b 0a 09 7d 0a 0a 09 54 63 6c 5f 4c 69 73 74 );..}...Tcl_List
4180: 4f 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 ObjAppendElement
4190: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
41a0: 2c 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f , Tcl_NewStringO
41b0: 62 6a 28 22 73 75 62 6a 65 63 74 55 6e 69 71 75 bj("subjectUniqu
41c0: 65 49 64 22 2c 20 2d 31 29 29 3b 0a 09 69 66 20 eId", -1));..if
41d0: 28 73 75 69 64 20 21 3d 20 4e 55 4c 4c 29 20 7b (suid != NULL) {
41e0: 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f 62 .. Tcl_ListOb
41f0: 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 69 jAppendElement(i
4200: 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 nterp, certPtr,
4210: 54 63 6c 5f 4e 65 77 42 79 74 65 41 72 72 61 79 Tcl_NewByteArray
4220: 4f 62 6a 28 28 63 68 61 72 20 2a 29 73 75 69 64 Obj((char *)suid
4230: 2d 3e 64 61 74 61 2c 20 73 75 69 64 2d 3e 6c 65 ->data, suid->le
4240: 6e 67 74 68 29 29 3b 0a 09 7d 20 65 6c 73 65 20 ngth));..} else
4250: 7b 0a 09 20 20 20 20 54 63 6c 5f 4c 69 73 74 4f {.. Tcl_ListO
4260: 62 6a 41 70 70 65 6e 64 45 6c 65 6d 65 6e 74 28 bjAppendElement(
4270: 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c interp, certPtr,
4280: 20 54 63 6c 5f 4e 65 77 53 74 72 69 6e 67 4f 62 Tcl_NewStringOb
4290: 6a 28 22 22 2c 20 2d 31 29 29 3b 0a 09 7d 0a 20 j("", -1));..}.
42a0: 20 20 20 7d 0a 0a 20 20 20 20 2f 2a 20 58 35 30 }.. /* X50
42b0: 39 20 76 33 20 45 78 74 65 6e 73 69 6f 6e 73 20 9 v3 Extensions
42c0: 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 - RFC 5280 secti
42d0: 6f 6e 20 34 2e 31 2e 32 2e 39 20 2a 2f 0a 20 20 on 4.1.2.9 */.
42e0: 20 20 4c 41 50 50 45 4e 44 5f 49 4e 54 28 69 6e LAPPEND_INT(in
42f0: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
4300: 65 78 74 43 6f 75 6e 74 22 2c 20 58 35 30 39 5f extCount", X509_
4310: 67 65 74 5f 65 78 74 5f 63 6f 75 6e 74 28 63 65 get_ext_count(ce
4320: 72 74 29 29 3b 0a 20 20 20 20 4c 41 50 50 45 4e rt));. LAPPEN
4330: 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 D_OBJ(interp, ce
4340: 72 74 50 74 72 2c 20 22 65 78 74 65 6e 73 69 6f rtPtr, "extensio
4350: 6e 73 22 2c 20 54 6c 73 5f 78 35 30 39 45 78 74 ns", Tls_x509Ext
4360: 65 6e 73 69 6f 6e 73 28 69 6e 74 65 72 70 2c 20 ensions(interp,
4370: 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 cert));.. /*
4380: 41 75 74 68 6f 72 69 74 79 20 4b 65 79 20 49 64 Authority Key Id
4390: 65 6e 74 69 66 69 65 72 20 28 41 4b 49 29 20 69 entifier (AKI) i
43a0: 73 20 74 68 65 20 53 75 62 6a 65 63 74 20 4b 65 s the Subject Ke
43b0: 79 20 49 64 65 6e 74 69 66 69 65 72 20 28 53 4b y Identifier (SK
43c0: 49 29 20 6f 66 0a 09 69 74 73 20 73 69 67 6e 65 I) of..its signe
43d0: 72 20 28 74 68 65 20 43 41 29 2e 20 52 46 43 20 r (the CA). RFC
43e0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 5280 section 4.2
43f0: 2e 31 2e 31 2c 20 4e 49 44 5f 61 75 74 68 6f 72 .1.1, NID_author
4400: 69 74 79 5f 6b 65 79 5f 69 64 65 6e 74 69 66 69 ity_key_identifi
4410: 65 72 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e er */. LAPPEN
4420: 44 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 D_OBJ(interp, ce
4430: 72 74 50 74 72 2c 20 22 61 75 74 68 6f 72 69 74 rtPtr, "authorit
4440: 79 4b 65 79 49 64 65 6e 74 69 66 69 65 72 22 2c yKeyIdentifier",
4450: 0a 09 54 6c 73 5f 78 35 30 39 49 64 65 6e 74 69 ..Tls_x509Identi
4460: 66 69 65 72 28 58 35 30 39 5f 67 65 74 30 5f 61 fier(X509_get0_a
4470: 75 74 68 6f 72 69 74 79 5f 6b 65 79 5f 69 64 28 uthority_key_id(
4480: 63 65 72 74 29 29 29 3b 0a 0a 20 20 20 20 2f 2a cert)));.. /*
4490: 20 53 75 62 6a 65 63 74 20 4b 65 79 20 49 64 65 Subject Key Ide
44a0: 6e 74 69 66 69 65 72 20 28 53 4b 49 29 20 69 73 ntifier (SKI) is
44b0: 20 75 73 65 64 20 74 6f 20 69 64 65 6e 74 69 66 used to identif
44c0: 79 20 63 65 72 74 69 66 69 63 61 74 65 73 20 74 y certificates t
44d0: 68 61 74 20 63 6f 6e 74 61 69 6e 0a 09 61 20 70 hat contain..a p
44e0: 61 72 74 69 63 75 6c 61 72 20 70 75 62 6c 69 63 articular public
44f0: 20 6b 65 79 2e 20 52 46 43 20 35 32 38 30 20 73 key. RFC 5280 s
4500: 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 32 2c 20 ection 4.2.1.2,
4510: 4e 49 44 5f 73 75 62 6a 65 63 74 5f 6b 65 79 5f NID_subject_key_
4520: 69 64 65 6e 74 69 66 69 65 72 20 2a 2f 0a 20 20 identifier */.
4530: 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e LAPPEND_OBJ(in
4540: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
4550: 73 75 62 6a 65 63 74 4b 65 79 49 64 65 6e 74 69 subjectKeyIdenti
4560: 66 69 65 72 22 2c 0a 09 54 6c 73 5f 78 35 30 39 fier",..Tls_x509
4570: 49 64 65 6e 74 69 66 69 65 72 28 58 35 30 39 5f Identifier(X509_
4580: 67 65 74 30 5f 73 75 62 6a 65 63 74 5f 6b 65 79 get0_subject_key
4590: 5f 69 64 28 63 65 72 74 29 29 29 3b 0a 0a 20 20 _id(cert)));..
45a0: 20 20 2f 2a 20 4b 65 79 20 75 73 61 67 65 20 65 /* Key usage e
45b0: 78 74 65 6e 73 69 6f 6e 20 64 65 66 69 6e 65 73 xtension defines
45c0: 20 74 68 65 20 70 75 72 70 6f 73 65 20 28 65 2e the purpose (e.
45d0: 67 2e 2c 20 65 6e 63 69 70 68 65 72 6d 65 6e 74 g., encipherment
45e0: 2c 20 73 69 67 6e 61 74 75 72 65 2c 20 63 65 72 , signature, cer
45f0: 74 69 66 69 63 61 74 65 0a 09 73 69 67 6e 69 6e tificate..signin
4600: 67 29 20 6f 66 20 74 68 65 20 6b 65 79 20 69 6e g) of the key in
4610: 20 74 68 65 20 63 65 72 74 69 66 69 63 61 74 65 the certificate
4620: 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 . RFC 5280 secti
4630: 6f 6e 20 34 2e 32 2e 31 2e 33 2c 20 4e 49 44 5f on 4.2.1.3, NID_
4640: 6b 65 79 5f 75 73 61 67 65 20 2a 2f 0a 20 20 20 key_usage */.
4650: 20 4c 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 LAPPEND_OBJ(int
4660: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 6b erp, certPtr, "k
4670: 65 79 55 73 61 67 65 22 2c 20 54 6c 73 5f 78 35 eyUsage", Tls_x5
4680: 30 39 4b 65 79 55 73 61 67 65 28 69 6e 74 65 72 09KeyUsage(inter
4690: 70 2c 20 63 65 72 74 2c 20 78 66 6c 61 67 73 29 p, cert, xflags)
46a0: 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 69 );.. /* Certi
46b0: 66 69 63 61 74 65 20 50 6f 6c 69 63 69 65 73 20 ficate Policies
46c0: 2d 20 69 6e 64 69 63 61 74 65 73 20 74 68 65 20 - indicates the
46d0: 69 73 73 75 69 6e 67 20 43 41 20 63 6f 6e 73 69 issuing CA consi
46e0: 64 65 72 73 20 69 74 73 20 69 73 73 75 65 72 44 ders its issuerD
46f0: 6f 6d 61 69 6e 50 6f 6c 69 63 79 0a 09 65 71 75 omainPolicy..equ
4700: 69 76 61 6c 65 6e 74 20 74 6f 20 74 68 65 20 73 ivalent to the s
4710: 75 62 6a 65 63 74 20 43 41 27 73 20 73 75 62 6a ubject CA's subj
4720: 65 63 74 44 6f 6d 61 69 6e 50 6f 6c 69 63 79 2e ectDomainPolicy.
4730: 20 52 46 43 20 35 32 38 30 20 73 65 63 74 69 6f RFC 5280 sectio
4740: 6e 20 34 2e 32 2e 31 2e 34 2c 20 4e 49 44 5f 63 n 4.2.1.4, NID_c
4750: 65 72 74 69 66 69 63 61 74 65 5f 70 6f 6c 69 63 ertificate_polic
4760: 69 65 73 20 2a 2f 0a 20 20 20 20 69 66 20 28 78 ies */. if (x
4770: 66 6c 61 67 73 20 26 20 45 58 46 4c 41 47 5f 49 flags & EXFLAG_I
4780: 4e 56 41 4c 49 44 5f 50 4f 4c 49 43 59 29 20 7b NVALID_POLICY) {
4790: 0a 09 2f 2a 20 52 65 6a 65 63 74 20 63 65 72 74 ../* Reject cert
47a0: 20 2a 2f 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f */. }.. /
47b0: 2a 20 50 6f 6c 69 63 79 20 4d 61 70 70 69 6e 67 * Policy Mapping
47c0: 73 20 2d 20 52 46 43 20 35 32 38 30 20 73 65 63 s - RFC 5280 sec
47d0: 74 69 6f 6e 20 34 2e 32 2e 31 2e 35 2c 20 4e 49 tion 4.2.1.5, NI
47e0: 44 5f 70 6f 6c 69 63 79 5f 6d 61 70 70 69 6e 67 D_policy_mapping
47f0: 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 53 75 62 s */.. /* Sub
4800: 6a 65 63 74 20 41 6c 74 65 72 6e 61 74 69 76 65 ject Alternative
4810: 20 4e 61 6d 65 20 28 53 41 4e 29 20 63 6f 6e 74 Name (SAN) cont
4820: 61 69 6e 73 20 61 64 64 69 74 69 6f 6e 61 6c 20 ains additional
4830: 55 52 4c 73 2c 20 44 4e 53 20 6e 61 6d 65 73 2c URLs, DNS names,
4840: 20 6f 72 20 49 50 0a 09 61 64 64 72 65 73 73 65 or IP..addresse
4850: 73 20 62 6f 75 6e 64 20 74 6f 20 63 65 72 74 69 s bound to certi
4860: 66 69 63 61 74 65 2e 20 52 46 43 20 35 32 38 30 ficate. RFC 5280
4870: 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 36 section 4.2.1.6
4880: 2c 20 4e 49 44 5f 73 75 62 6a 65 63 74 5f 61 6c , NID_subject_al
4890: 74 5f 6e 61 6d 65 20 2a 2f 0a 20 20 20 20 4c 41 t_name */. LA
48a0: 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 70 PPEND_OBJ(interp
48b0: 2c 20 63 65 72 74 50 74 72 2c 20 22 73 75 62 6a , certPtr, "subj
48c0: 65 63 74 41 6c 74 4e 61 6d 65 22 2c 20 54 6c 73 ectAltName", Tls
48d0: 5f 78 35 30 39 4e 61 6d 65 73 28 69 6e 74 65 72 _x509Names(inter
48e0: 70 2c 20 63 65 72 74 2c 20 4e 49 44 5f 73 75 62 p, cert, NID_sub
48f0: 6a 65 63 74 5f 61 6c 74 5f 6e 61 6d 65 2c 20 62 ject_alt_name, b
4900: 69 6f 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 49 73 io));.. /* Is
4910: 73 75 65 72 20 41 6c 74 65 72 6e 61 74 69 76 65 suer Alternative
4920: 20 4e 61 6d 65 20 69 73 20 75 73 65 64 20 74 6f Name is used to
4930: 20 61 73 73 6f 63 69 61 74 65 20 49 6e 74 65 72 associate Inter
4940: 6e 65 74 20 73 74 79 6c 65 20 69 64 65 6e 74 69 net style identi
4950: 74 69 65 73 0a 09 77 69 74 68 20 74 68 65 20 63 ties..with the c
4960: 65 72 74 69 66 69 63 61 74 65 20 69 73 73 75 65 ertificate issue
4970: 72 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 r. RFC 5280 sect
4980: 69 6f 6e 20 34 2e 32 2e 31 2e 37 2c 20 4e 49 44 ion 4.2.1.7, NID
4990: 5f 69 73 73 75 65 72 5f 61 6c 74 5f 6e 61 6d 65 _issuer_alt_name
49a0: 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f */. LAPPEND_
49b0: 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 74 OBJ(interp, cert
49c0: 50 74 72 2c 20 22 69 73 73 75 65 72 41 6c 74 4e Ptr, "issuerAltN
49d0: 61 6d 65 22 2c 20 54 6c 73 5f 78 35 30 39 4e 61 ame", Tls_x509Na
49e0: 6d 65 73 28 69 6e 74 65 72 70 2c 20 63 65 72 74 mes(interp, cert
49f0: 2c 20 4e 49 44 5f 69 73 73 75 65 72 5f 61 6c 74 , NID_issuer_alt
4a00: 5f 6e 61 6d 65 2c 20 62 69 6f 29 29 3b 0a 0a 20 _name, bio));..
4a10: 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 20 44 69 /* Subject Di
4a20: 72 65 63 74 6f 72 79 20 41 74 74 72 69 62 75 74 rectory Attribut
4a30: 65 73 20 70 72 6f 76 69 64 65 73 20 69 64 65 6e es provides iden
4a40: 74 69 66 69 63 61 74 69 6f 6e 20 61 74 74 72 69 tification attri
4a50: 62 75 74 65 73 20 28 65 2e 67 2e 2c 20 6e 61 74 butes (e.g., nat
4a60: 69 6f 6e 61 6c 69 74 79 29 0a 09 6f 66 20 74 68 ionality)..of th
4a70: 65 20 73 75 62 6a 65 63 74 2e 20 52 46 43 20 35 e subject. RFC 5
4a80: 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 280 section 4.2.
4a90: 31 2e 38 20 28 73 75 62 6a 65 63 74 44 69 72 65 1.8 (subjectDire
4aa0: 63 74 6f 72 79 41 74 74 72 69 62 75 74 65 73 29 ctoryAttributes)
4ab0: 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 42 61 73 69 */.. /* Basi
4ac0: 63 20 43 6f 6e 73 74 72 61 69 6e 74 73 20 69 64 c Constraints id
4ad0: 65 6e 74 69 66 69 65 73 20 77 68 65 74 68 65 72 entifies whether
4ae0: 20 74 68 65 20 73 75 62 6a 65 63 74 20 6f 66 20 the subject of
4af0: 74 68 65 20 63 65 72 74 20 69 73 20 61 20 43 41 the cert is a CA
4b00: 20 61 6e 64 0a 09 74 68 65 20 6d 61 78 20 64 65 and..the max de
4b10: 70 74 68 20 6f 66 20 76 61 6c 69 64 20 63 65 72 pth of valid cer
4b20: 74 20 70 61 74 68 73 20 66 6f 72 20 74 68 69 73 t paths for this
4b30: 20 63 65 72 74 2e 20 52 46 43 20 35 32 38 30 20 cert. RFC 5280
4b40: 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 39 2c section 4.2.1.9,
4b50: 20 4e 49 44 5f 62 61 73 69 63 5f 63 6f 6e 73 74 NID_basic_const
4b60: 72 61 69 6e 74 73 20 2a 2f 0a 20 20 20 20 69 66 raints */. if
4b70: 20 28 21 28 78 66 6c 61 67 73 20 26 20 45 58 46 (!(xflags & EXF
4b80: 4c 41 47 5f 50 52 4f 58 59 29 29 20 7b 0a 09 4c LAG_PROXY)) {..L
4b90: 41 50 50 45 4e 44 5f 4c 4f 4e 47 28 69 6e 74 65 APPEND_LONG(inte
4ba0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 61 rp, certPtr, "pa
4bb0: 74 68 4c 65 6e 22 2c 20 58 35 30 39 5f 67 65 74 thLen", X509_get
4bc0: 5f 70 61 74 68 6c 65 6e 28 63 65 72 74 29 29 3b _pathlen(cert));
4bd0: 0a 20 20 20 20 7d 20 65 6c 73 65 20 7b 0a 09 4c . } else {..L
4be0: 41 50 50 45 4e 44 5f 4c 4f 4e 47 28 69 6e 74 65 APPEND_LONG(inte
4bf0: 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 70 61 rp, certPtr, "pa
4c00: 74 68 4c 65 6e 22 2c 20 58 35 30 39 5f 67 65 74 thLen", X509_get
4c10: 5f 70 72 6f 78 79 5f 70 61 74 68 6c 65 6e 28 63 _proxy_pathlen(c
4c20: 65 72 74 29 29 3b 0a 20 20 20 20 7d 0a 20 20 20 ert));. }.
4c30: 20 4c 41 50 50 45 4e 44 5f 42 4f 4f 4c 28 69 6e LAPPEND_BOOL(in
4c40: 74 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 terp, certPtr, "
4c50: 62 61 73 69 63 43 6f 6e 73 74 72 61 69 6e 74 73 basicConstraints
4c60: 43 41 22 2c 20 78 66 6c 61 67 73 20 26 20 45 58 CA", xflags & EX
4c70: 46 4c 41 47 5f 43 41 29 3b 0a 0a 20 20 20 20 2f FLAG_CA);.. /
4c80: 2a 20 4e 61 6d 65 20 43 6f 6e 73 74 72 61 69 6e * Name Constrain
4c90: 74 73 20 69 73 20 6f 6e 6c 79 20 75 73 65 64 20 ts is only used
4ca0: 69 6e 20 43 41 20 63 65 72 74 73 20 74 6f 20 69 in CA certs to i
4cb0: 6e 64 69 63 61 74 65 20 74 68 65 20 6e 61 6d 65 ndicate the name
4cc0: 20 73 70 61 63 65 20 66 6f 72 0a 09 61 6c 6c 20 space for..all
4cd0: 73 75 62 6a 65 63 74 20 6e 61 6d 65 73 20 69 6e subject names in
4ce0: 20 73 75 62 73 65 71 75 65 6e 74 20 63 65 72 74 subsequent cert
4cf0: 69 66 69 63 61 74 65 73 20 69 6e 20 61 20 63 65 ificates in a ce
4d00: 72 74 69 66 69 63 61 74 69 6f 6e 20 70 61 74 68 rtification path
4d10: 0a 09 4d 55 53 54 20 62 65 20 6c 6f 63 61 74 65 ..MUST be locate
4d20: 64 2e 20 52 46 43 20 35 32 38 30 20 73 65 63 74 d. RFC 5280 sect
4d30: 69 6f 6e 20 34 2e 32 2e 31 2e 31 30 2c 20 4e 49 ion 4.2.1.10, NI
4d40: 44 5f 6e 61 6d 65 5f 63 6f 6e 73 74 72 61 69 6e D_name_constrain
4d50: 74 73 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 50 6f ts */.. /* Po
4d60: 6c 69 63 79 20 43 6f 6e 73 74 72 61 69 6e 74 73 licy Constraints
4d70: 20 69 73 20 6f 6e 6c 79 20 75 73 65 64 20 69 6e is only used in
4d80: 20 43 41 20 63 65 72 74 73 20 74 6f 20 6c 69 6d CA certs to lim
4d90: 69 74 20 74 68 65 20 6c 65 6e 67 74 68 20 6f 66 it the length of
4da0: 20 61 0a 09 63 65 72 74 20 63 68 61 69 6e 20 66 a..cert chain f
4db0: 6f 72 20 74 68 61 74 20 43 41 2e 20 52 46 43 20 or that CA. RFC
4dc0: 35 32 38 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 5280 section 4.2
4dd0: 2e 31 2e 31 31 2c 20 4e 49 44 5f 70 6f 6c 69 63 .1.11, NID_polic
4de0: 79 5f 63 6f 6e 73 74 72 61 69 6e 74 73 20 2a 2f y_constraints */
4df0: 0a 0a 20 20 20 20 2f 2a 20 45 78 74 65 6e 64 65 .. /* Extende
4e00: 64 20 4b 65 79 20 55 73 61 67 65 20 69 6e 64 69 d Key Usage indi
4e10: 63 61 74 65 73 20 74 68 65 20 70 75 72 70 6f 73 cates the purpos
4e20: 65 73 20 74 68 65 20 63 65 72 74 69 66 69 65 64 es the certified
4e30: 20 70 75 62 6c 69 63 20 6b 65 79 20 6d 61 79 20 public key may
4e40: 62 65 0a 09 75 73 65 64 2c 20 62 65 79 6f 6e 64 be..used, beyond
4e50: 20 74 68 65 20 62 61 73 69 63 20 70 75 72 70 6f the basic purpo
4e60: 73 65 73 2e 20 52 46 43 20 35 32 38 30 20 73 65 ses. RFC 5280 se
4e70: 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 31 32 2c 20 ction 4.2.1.12,
4e80: 4e 49 44 5f 65 78 74 5f 6b 65 79 5f 75 73 61 67 NID_ext_key_usag
4e90: 65 20 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 e */. LAPPEND
4ea0: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 _OBJ(interp, cer
4eb0: 74 50 74 72 2c 20 22 65 78 74 65 6e 64 65 64 4b tPtr, "extendedK
4ec0: 65 79 55 73 61 67 65 22 2c 20 54 6c 73 5f 78 35 eyUsage", Tls_x5
4ed0: 30 39 45 78 74 4b 65 79 55 73 61 67 65 28 69 6e 09ExtKeyUsage(in
4ee0: 74 65 72 70 2c 20 63 65 72 74 2c 20 78 66 6c 61 terp, cert, xfla
4ef0: 67 73 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 52 gs));.. /* CR
4f00: 4c 20 44 69 73 74 72 69 62 75 74 69 6f 6e 20 50 L Distribution P
4f10: 6f 69 6e 74 73 20 69 64 65 6e 74 69 66 69 65 73 oints identifies
4f20: 20 77 68 65 72 65 20 43 52 4c 20 69 6e 66 6f 72 where CRL infor
4f30: 6d 61 74 69 6f 6e 20 63 61 6e 20 62 65 20 6f 62 mation can be ob
4f40: 74 61 69 6e 65 64 2e 0a 09 52 46 43 20 35 32 38 tained...RFC 528
4f50: 30 20 73 65 63 74 69 6f 6e 20 34 2e 32 2e 31 2e 0 section 4.2.1.
4f60: 31 33 2a 2f 0a 20 20 20 20 4c 41 50 50 45 4e 44 13*/. LAPPEND
4f70: 5f 4f 42 4a 28 69 6e 74 65 72 70 2c 20 63 65 72 _OBJ(interp, cer
4f80: 74 50 74 72 2c 20 22 63 72 6c 44 69 73 74 72 69 tPtr, "crlDistri
4f90: 62 75 74 69 6f 6e 50 6f 69 6e 74 73 22 2c 20 54 butionPoints", T
4fa0: 6c 73 5f 78 35 30 39 43 72 6c 44 70 28 69 6e 74 ls_x509CrlDp(int
4fb0: 65 72 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 erp, cert));..
4fc0: 20 20 2f 2a 20 46 72 65 73 68 65 73 74 20 43 52 /* Freshest CR
4fd0: 4c 20 65 78 74 65 6e 73 69 6f 6e 20 2a 2f 0a 20 L extension */.
4fe0: 20 20 20 69 66 20 28 78 66 6c 61 67 73 20 26 20 if (xflags &
4ff0: 45 58 46 4c 41 47 5f 46 52 45 53 48 45 53 54 29 EXFLAG_FRESHEST)
5000: 20 7b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a {. }.. /*
5010: 20 41 75 74 68 6f 72 69 74 79 20 49 6e 66 6f 72 Authority Infor
5020: 6d 61 74 69 6f 6e 20 41 63 63 65 73 73 20 69 6e mation Access in
5030: 64 69 63 61 74 65 73 20 68 6f 77 20 74 6f 20 61 dicates how to a
5040: 63 63 65 73 73 20 69 6e 66 6f 20 61 6e 64 20 73 ccess info and s
5050: 65 72 76 69 63 65 73 0a 09 66 6f 72 20 74 68 65 ervices..for the
5060: 20 63 65 72 74 69 66 69 63 61 74 65 20 69 73 73 certificate iss
5070: 75 65 72 2e 20 52 46 43 20 35 32 38 30 20 73 65 uer. RFC 5280 se
5080: 63 74 69 6f 6e 20 34 2e 32 2e 32 2e 31 2c 20 4e ction 4.2.2.1, N
5090: 49 44 5f 69 6e 66 6f 5f 61 63 63 65 73 73 20 2a ID_info_access *
50a0: 2f 0a 0a 20 20 20 20 2f 2a 20 47 65 74 20 4f 6e /.. /* Get On
50b0: 2d 6c 69 6e 65 20 43 65 72 74 69 66 69 63 61 74 -line Certificat
50c0: 65 20 53 74 61 74 75 73 20 50 72 6f 74 6f 63 6f e Status Protoco
50d0: 6c 20 28 4f 53 43 50 29 20 52 65 73 70 6f 6e 64 l (OSCP) Respond
50e0: 65 72 73 20 55 52 4c 20 2a 2f 0a 20 20 20 20 4c ers URL */. L
50f0: 41 50 50 45 4e 44 5f 4f 42 4a 28 69 6e 74 65 72 APPEND_OBJ(inter
5100: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 6f 63 73 p, certPtr, "ocs
5110: 70 52 65 73 70 6f 6e 64 65 72 73 22 2c 20 54 6c pResponders", Tl
5120: 73 5f 78 35 30 39 4f 73 63 70 28 69 6e 74 65 72 s_x509Oscp(inter
5130: 70 2c 20 63 65 72 74 29 29 3b 0a 0a 20 20 20 20 p, cert));..
5140: 2f 2a 20 47 65 74 20 43 65 72 74 69 66 69 63 61 /* Get Certifica
5150: 74 65 20 41 75 74 68 6f 72 69 74 79 20 28 43 41 te Authority (CA
5160: 29 20 49 73 73 75 65 72 73 20 55 52 4c 20 2a 2f ) Issuers URL */
5170: 0a 20 20 20 20 4c 41 50 50 45 4e 44 5f 4f 42 4a . LAPPEND_OBJ
5180: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 50 74 72 (interp, certPtr
5190: 2c 20 22 63 61 49 73 73 75 65 72 73 22 2c 20 54 , "caIssuers", T
51a0: 6c 73 5f 78 35 30 39 43 61 49 73 73 75 65 72 73 ls_x509CaIssuers
51b0: 28 69 6e 74 65 72 70 2c 20 63 65 72 74 29 29 3b (interp, cert));
51c0: 0a 0a 20 20 20 20 2f 2a 20 53 75 62 6a 65 63 74 .. /* Subject
51d0: 20 49 6e 66 6f 72 6d 61 74 69 6f 6e 20 41 63 63 Information Acc
51e0: 65 73 73 20 2d 20 52 46 43 20 35 32 38 30 20 73 ess - RFC 5280 s
51f0: 65 63 74 69 6f 6e 20 34 2e 32 2e 32 2e 32 2c 20 ection 4.2.2.2,
5200: 4e 49 44 5f 73 69 6e 66 6f 5f 61 63 63 65 73 73 NID_sinfo_access
5210: 20 2a 2f 0a 0a 20 20 20 20 2f 2a 20 43 65 72 74 */.. /* Cert
5220: 69 66 69 63 61 74 65 20 41 6c 69 61 73 2e 20 49 ificate Alias. I
5230: 66 20 75 73 65 73 20 61 20 50 4b 43 53 23 31 32 f uses a PKCS#12
5240: 20 73 74 72 75 63 74 75 72 65 2c 20 61 6c 69 61 structure, alia
5250: 73 20 77 69 6c 6c 20 72 65 66 6c 65 63 74 20 74 s will reflect t
5260: 68 65 0a 09 66 72 69 65 6e 64 6c 79 4e 61 6d 65 he..friendlyName
5270: 20 61 74 74 72 69 62 75 74 65 20 28 52 46 43 20 attribute (RFC
5280: 32 39 38 35 29 2e 20 2a 2f 0a 20 20 20 20 7b 0a 2985). */. {.
5290: 09 6c 65 6e 20 3d 20 30 3b 0a 20 20 20 20 20 20 .len = 0;.
52a0: 20 20 63 68 61 72 20 2a 73 74 72 69 6e 67 20 3d char *string =
52b0: 20 58 35 30 39 5f 61 6c 69 61 73 5f 67 65 74 30 X509_alias_get0
52c0: 28 63 65 72 74 2c 20 26 6c 65 6e 29 3b 0a 09 4c (cert, &len);..L
52d0: 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 APPEND_STR(inter
52e0: 70 2c 20 63 65 72 74 50 74 72 2c 20 22 61 6c 69 p, certPtr, "ali
52f0: 61 73 22 2c 20 73 74 72 69 6e 67 2c 20 6c 65 6e as", string, len
5300: 29 3b 0a 20 20 20 20 7d 0a 0a 20 20 20 20 2f 2a );. }.. /*
5310: 20 43 65 72 74 69 66 69 63 61 74 65 20 61 6e 64 Certificate and
5320: 20 64 75 6d 70 20 61 6c 6c 20 64 61 74 61 20 2a dump all data *
5330: 2f 0a 20 20 20 20 7b 0a 09 63 68 61 72 20 63 65 /. {..char ce
5340: 72 74 53 74 72 5b 43 45 52 54 5f 53 54 52 5f 53 rtStr[CERT_STR_S
5350: 49 5a 45 5d 3b 0a 0a 09 2f 2a 20 47 65 74 20 63 IZE];.../* Get c
5360: 65 72 74 69 66 69 63 61 74 65 20 2a 2f 0a 09 6c ertificate */..l
5370: 65 6e 20 3d 20 42 49 4f 5f 74 6f 5f 42 75 66 66 en = BIO_to_Buff
5380: 65 72 28 50 45 4d 5f 77 72 69 74 65 5f 62 69 6f er(PEM_write_bio
5390: 5f 58 35 30 39 28 62 69 6f 2c 20 63 65 72 74 29 _X509(bio, cert)
53a0: 2c 20 62 69 6f 2c 20 63 65 72 74 53 74 72 2c 20 , bio, certStr,
53b0: 43 45 52 54 5f 53 54 52 5f 53 49 5a 45 29 3b 0a CERT_STR_SIZE);.
53c0: 09 4c 41 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 .LAPPEND_STR(int
53d0: 65 72 70 2c 20 63 65 72 74 50 74 72 2c 20 22 63 erp, certPtr, "c
53e0: 65 72 74 69 66 69 63 61 74 65 22 2c 20 63 65 72 ertificate", cer
53f0: 74 53 74 72 2c 20 6c 65 6e 29 3b 0a 0a 09 2f 2a tStr, len);.../*
5400: 20 47 65 74 20 61 6c 6c 20 63 65 72 74 20 69 6e Get all cert in
5410: 66 6f 20 2a 2f 0a 09 6c 65 6e 20 3d 20 42 49 4f fo */..len = BIO
5420: 5f 74 6f 5f 42 75 66 66 65 72 28 58 35 30 39 5f _to_Buffer(X509_
5430: 70 72 69 6e 74 5f 65 78 28 62 69 6f 2c 20 63 65 print_ex(bio, ce
5440: 72 74 2c 20 66 6c 61 67 73 2c 20 30 29 2c 20 62 rt, flags, 0), b
5450: 69 6f 2c 20 63 65 72 74 53 74 72 2c 20 43 45 52 io, certStr, CER
5460: 54 5f 53 54 52 5f 53 49 5a 45 29 3b 0a 09 4c 41 T_STR_SIZE);..LA
5470: 50 50 45 4e 44 5f 53 54 52 28 69 6e 74 65 72 70 PPEND_STR(interp
5480: 2c 20 63 65 72 74 50 74 72 2c 20 22 61 6c 6c 22 , certPtr, "all"
5490: 2c 20 63 65 72 74 53 74 72 2c 20 6c 65 6e 29 3b , certStr, len);
54a0: 0a 20 20 20 20 7d 0a 0a 20 20 20 20 42 49 4f 5f . }.. BIO_
54b0: 66 72 65 65 28 62 69 6f 29 3b 0a 20 20 20 20 72 free(bio);. r
54c0: 65 74 75 72 6e 20 63 65 72 74 50 74 72 3b 0a 7d eturn certPtr;.}
54d0: 0a .