Hex Artifact Content

Artifact b4a76786cc07017723e1ba72706d1861543fc384:


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 4d 61  (C) 1997-2000 Ma
0020: 74 74 20 4e 65 77 6d 61 6e 20 3c 6d 61 74 74 40  tt Newman <matt@
0030: 6e 6f 76 61 64 69 67 6d 2e 63 6f 6d 3e 0a 20 2a  novadigm.com>. *
0040: 0a 20 2a 20 54 4c 53 20 28 61 6b 61 20 53 53 4c  . * TLS (aka SSL
0050: 29 20 43 68 61 6e 6e 65 6c 20 2d 20 63 61 6e 20  ) Channel - can 
0060: 62 65 20 6c 61 79 65 72 65 64 20 6f 6e 20 61 6e  be layered on an
0070: 79 20 62 69 2d 64 69 72 65 63 74 69 6f 6e 61 6c  y bi-directional
0080: 0a 20 2a 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 20  . * Tcl_Channel 
0090: 28 4e 6f 74 65 3a 20 52 65 71 75 69 72 65 73 20  (Note: Requires 
00a0: 54 72 66 20 43 6f 72 65 20 50 61 74 63 68 29 0a  Trf Core Patch).
00b0: 20 2a 0a 20 2a 20 54 68 69 73 20 77 61 73 20 62   *. * This was b
00c0: 75 69 6c 74 20 66 72 6f 6d 20 73 63 72 61 74 63  uilt from scratc
00d0: 68 20 62 61 73 65 64 20 75 70 6f 6e 20 6f 62 73  h based upon obs
00e0: 65 72 76 61 74 69 6f 6e 20 6f 66 20 4f 70 65 6e  ervation of Open
00f0: 53 53 4c 20 30 2e 39 2e 32 42 0a 20 2a 0a 20 2a  SSL 0.9.2B. *. *
0100: 20 41 64 64 69 74 69 6f 6e 20 63 72 65 64 69 74   Addition credit
0110: 20 69 73 20 64 75 65 20 66 6f 72 20 41 6e 64 72   is due for Andr
0120: 65 61 73 20 4b 75 70 72 69 65 73 20 28 61 2e 6b  eas Kupries (a.k
0130: 75 70 72 69 65 73 40 77 65 73 74 65 6e 64 2e 63  upries@westend.c
0140: 6f 6d 29 2c 20 66 6f 72 0a 20 2a 20 70 72 6f 76  om), for. * prov
0150: 69 64 69 6e 67 20 74 68 65 20 54 63 6c 5f 52 65  iding the Tcl_Re
0160: 70 6c 61 63 65 43 68 61 6e 6e 65 6c 20 6d 65 63  placeChannel mec
0170: 68 61 6e 69 73 6d 20 61 6e 64 20 77 6f 72 6b 69  hanism and worki
0180: 6e 67 20 63 6c 6f 73 65 6c 79 20 77 69 74 68 20  ng closely with 
0190: 6d 65 0a 20 2a 20 74 6f 20 65 6e 68 61 6e 63 65  me. * to enhance
01a0: 20 69 74 20 74 6f 20 73 75 70 70 6f 72 74 20 66   it to support f
01b0: 75 6c 6c 20 66 69 6c 65 65 76 65 6e 74 20 73 65  ull fileevent se
01c0: 6d 61 6e 74 69 63 73 2e 0a 20 2a 0a 20 2a 20 41  mantics.. *. * A
01d0: 6c 73 6f 20 77 6f 72 6b 20 64 6f 6e 65 20 62 79  lso work done by
01e0: 20 74 68 65 20 66 6f 6c 6c 6f 77 20 70 65 6f 70   the follow peop
01f0: 6c 65 20 70 72 6f 76 69 64 65 64 20 74 68 65 20  le provided the 
0200: 69 6d 70 65 74 75 73 20 74 6f 20 64 6f 20 74 68  impetus to do th
0210: 69 73 20 22 72 69 67 68 74 22 3a 2d 0a 20 2a 09  is "right":-. *.
0220: 74 63 6c 53 53 4c 20 28 43 6f 6c 69 6e 20 4d 63  tclSSL (Colin Mc
0230: 43 6f 72 6d 61 63 6b 2c 20 53 68 61 72 65 64 20  Cormack, Shared 
0240: 54 65 63 68 6e 6f 6c 6f 67 79 29 0a 20 2a 09 53  Technology). *.S
0250: 53 4c 74 63 6c 20 28 50 65 74 65 72 20 41 6e 74  SLtcl (Peter Ant
0260: 6d 61 6e 29 0a 20 2a 0a 20 2a 2f 0a 23 69 66 6e  man). *. */.#ifn
0270: 64 65 66 20 5f 54 4c 53 49 4e 54 5f 48 0a 23 64  def _TLSINT_H.#d
0280: 65 66 69 6e 65 20 5f 54 4c 53 49 4e 54 5f 48 0a  efine _TLSINT_H.
0290: 0a 23 69 6e 63 6c 75 64 65 20 22 74 6c 73 2e 68  .#include "tls.h
02a0: 22 0a 23 69 6e 63 6c 75 64 65 20 3c 65 72 72 6e  ".#include <errn
02b0: 6f 2e 68 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 73  o.h>.#include <s
02c0: 74 72 69 6e 67 2e 68 3e 0a 0a 23 69 66 64 65 66  tring.h>..#ifdef
02d0: 20 5f 5f 57 49 4e 33 32 5f 5f 0a 23 64 65 66 69   __WIN32__.#defi
02e0: 6e 65 20 57 49 4e 33 32 5f 4c 45 41 4e 5f 41 4e  ne WIN32_LEAN_AN
02f0: 44 5f 4d 45 41 4e 0a 23 69 6e 63 6c 75 64 65 20  D_MEAN.#include 
0300: 3c 77 69 6e 64 6f 77 73 2e 68 3e 0a 23 69 6e 63  <windows.h>.#inc
0310: 6c 75 64 65 20 3c 77 69 6e 63 72 79 70 74 2e 68  lude <wincrypt.h
0320: 3e 20 2f 2a 20 4f 70 65 6e 53 53 4c 20 6e 65 65  > /* OpenSSL nee
0330: 64 73 20 74 68 69 73 20 6f 6e 20 57 69 6e 64 6f  ds this on Windo
0340: 77 73 20 2a 2f 0a 23 65 6e 64 69 66 0a 0a 2f 2a  ws */.#endif../*
0350: 20 48 61 6e 64 6c 65 20 74 63 6c 38 2e 33 2d 3e   Handle tcl8.3->
0360: 74 63 6c 38 2e 34 20 43 4f 4e 53 54 20 63 68 61  tcl8.4 CONST cha
0370: 6e 67 65 73 20 2a 2f 0a 23 69 66 6e 64 65 66 20  nges */.#ifndef 
0380: 43 4f 4e 53 54 38 34 0a 23 64 65 66 69 6e 65 20  CONST84.#define 
0390: 43 4f 4e 53 54 38 34 0a 23 65 6e 64 69 66 0a 0a  CONST84.#endif..
03a0: 23 69 66 64 65 66 20 4e 4f 5f 50 41 54 45 4e 54  #ifdef NO_PATENT
03b0: 53 0a 23 20 20 64 65 66 69 6e 65 20 4e 4f 5f 49  S.#  define NO_I
03c0: 44 45 41 0a 23 20 20 64 65 66 69 6e 65 20 4e 4f  DEA.#  define NO
03d0: 5f 52 43 32 0a 23 20 20 64 65 66 69 6e 65 20 4e  _RC2.#  define N
03e0: 4f 5f 52 43 34 0a 23 20 20 64 65 66 69 6e 65 20  O_RC4.#  define 
03f0: 4e 4f 5f 52 43 35 0a 23 20 20 64 65 66 69 6e 65  NO_RC5.#  define
0400: 20 4e 4f 5f 52 53 41 0a 23 20 20 69 66 6e 64 65   NO_RSA.#  ifnde
0410: 66 20 4e 4f 5f 53 53 4c 32 0a 23 20 20 20 20 64  f NO_SSL2.#    d
0420: 65 66 69 6e 65 20 4e 4f 5f 53 53 4c 32 0a 23 20  efine NO_SSL2.# 
0430: 20 65 6e 64 69 66 0a 23 65 6e 64 69 66 0a 0a 23   endif.#endif..#
0440: 69 66 64 65 66 20 42 53 41 46 45 0a 23 69 6e 63  ifdef BSAFE.#inc
0450: 6c 75 64 65 20 3c 73 73 6c 2e 68 3e 0a 23 69 6e  lude <ssl.h>.#in
0460: 63 6c 75 64 65 20 3c 65 72 72 2e 68 3e 0a 23 69  clude <err.h>.#i
0470: 6e 63 6c 75 64 65 20 3c 72 61 6e 64 2e 68 3e 0a  nclude <rand.h>.
0480: 23 65 6c 73 65 0a 23 69 6e 63 6c 75 64 65 20 3c  #else.#include <
0490: 6f 70 65 6e 73 73 6c 2f 73 73 6c 2e 68 3e 0a 23  openssl/ssl.h>.#
04a0: 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e 73 73 6c  include <openssl
04b0: 2f 65 72 72 2e 68 3e 0a 23 69 6e 63 6c 75 64 65  /err.h>.#include
04c0: 20 3c 6f 70 65 6e 73 73 6c 2f 72 61 6e 64 2e 68   <openssl/rand.h
04d0: 3e 0a 23 69 6e 63 6c 75 64 65 20 3c 6f 70 65 6e  >.#include <open
04e0: 73 73 6c 2f 6f 70 65 6e 73 73 6c 76 2e 68 3e 0a  ssl/opensslv.h>.
04f0: 23 65 6e 64 69 66 0a 0a 2f 2a 0a 20 2a 20 44 65  #endif../*. * De
0500: 74 65 72 6d 69 6e 65 20 69 66 20 77 65 20 73 68  termine if we sh
0510: 6f 75 6c 64 20 75 73 65 20 74 68 65 20 70 72 65  ould use the pre
0520: 2d 4f 70 65 6e 53 53 4c 20 31 2e 31 2e 30 20 41  -OpenSSL 1.1.0 A
0530: 50 49 0a 20 2a 2f 0a 23 75 6e 64 65 66 20 54 43  PI. */.#undef TC
0540: 4c 54 4c 53 5f 4f 50 45 4e 53 53 4c 5f 50 52 45  LTLS_OPENSSL_PRE
0550: 5f 31 5f 31 0a 23 69 66 20 28 64 65 66 69 6e 65  _1_1.#if (define
0560: 64 28 4c 49 42 52 45 53 53 4c 5f 56 45 52 53 49  d(LIBRESSL_VERSI
0570: 4f 4e 5f 4e 55 4d 42 45 52 29 29 20 7c 7c 20 4f  ON_NUMBER)) || O
0580: 50 45 4e 53 53 4c 5f 56 45 52 53 49 4f 4e 5f 4e  PENSSL_VERSION_N
0590: 55 4d 42 45 52 20 3c 20 30 78 31 30 31 30 30 30  UMBER < 0x101000
05a0: 30 30 4c 0a 23 20 20 64 65 66 69 6e 65 20 54 43  00L.#  define TC
05b0: 4c 54 4c 53 5f 4f 50 45 4e 53 53 4c 5f 50 52 45  LTLS_OPENSSL_PRE
05c0: 5f 31 5f 31 5f 41 50 49 20 31 0a 23 65 6e 64 69  _1_1_API 1.#endi
05d0: 66 0a 0a 23 69 66 64 65 66 20 54 43 4c 5f 53 54  f..#ifdef TCL_ST
05e0: 4f 52 41 47 45 5f 43 4c 41 53 53 0a 23 20 75 6e  ORAGE_CLASS.# un
05f0: 64 65 66 20 54 43 4c 5f 53 54 4f 52 41 47 45 5f  def TCL_STORAGE_
0600: 43 4c 41 53 53 0a 23 65 6e 64 69 66 0a 23 69 66  CLASS.#endif.#if
0610: 64 65 66 20 42 55 49 4c 44 5f 74 6c 73 0a 23 20  def BUILD_tls.# 
0620: 64 65 66 69 6e 65 20 54 43 4c 5f 53 54 4f 52 41  define TCL_STORA
0630: 47 45 5f 43 4c 41 53 53 20 44 4c 4c 45 58 50 4f  GE_CLASS DLLEXPO
0640: 52 54 0a 23 65 6c 73 65 0a 23 20 64 65 66 69 6e  RT.#else.# defin
0650: 65 20 54 43 4c 5f 53 54 4f 52 41 47 45 5f 43 4c  e TCL_STORAGE_CL
0660: 41 53 53 20 44 4c 4c 49 4d 50 4f 52 54 0a 23 65  ASS DLLIMPORT.#e
0670: 6e 64 69 66 0a 20 0a 23 69 66 6e 64 65 66 20 45  ndif. .#ifndef E
0680: 43 4f 4e 4e 41 42 4f 52 54 45 44 0a 23 64 65 66  CONNABORTED.#def
0690: 69 6e 65 20 45 43 4f 4e 4e 41 42 4f 52 54 45 44  ine ECONNABORTED
06a0: 09 31 33 30 09 2f 2a 20 53 6f 66 74 77 61 72 65  .130./* Software
06b0: 20 63 61 75 73 65 64 20 63 6f 6e 6e 65 63 74 69   caused connecti
06c0: 6f 6e 20 61 62 6f 72 74 20 2a 2f 0a 23 65 6e 64  on abort */.#end
06d0: 69 66 0a 23 69 66 6e 64 65 66 20 45 43 4f 4e 4e  if.#ifndef ECONN
06e0: 52 45 53 45 54 0a 23 64 65 66 69 6e 65 20 45 43  RESET.#define EC
06f0: 4f 4e 4e 52 45 53 45 54 09 31 33 31 09 2f 2a 20  ONNRESET.131./* 
0700: 43 6f 6e 6e 65 63 74 69 6f 6e 20 72 65 73 65 74  Connection reset
0710: 20 62 79 20 70 65 65 72 20 2a 2f 0a 23 65 6e 64   by peer */.#end
0720: 69 66 0a 0a 23 69 66 64 65 66 20 54 43 4c 45 58  if..#ifdef TCLEX
0730: 54 5f 54 43 4c 54 4c 53 5f 44 45 42 55 47 0a 23  T_TCLTLS_DEBUG.#
0740: 64 65 66 69 6e 65 20 64 70 72 69 6e 74 66 28 2e  define dprintf(.
0750: 2e 2e 29 20 7b 20 66 70 72 69 6e 74 66 28 73 74  ..) { fprintf(st
0760: 64 65 72 72 2c 20 22 25 73 3a 25 69 3a 22 2c 20  derr, "%s:%i:", 
0770: 5f 5f 66 75 6e 63 5f 5f 2c 20 5f 5f 4c 49 4e 45  __func__, __LINE
0780: 5f 5f 29 3b 20 66 70 72 69 6e 74 66 28 73 74 64  __); fprintf(std
0790: 65 72 72 2c 20 5f 5f 56 41 5f 41 52 47 53 5f 5f  err, __VA_ARGS__
07a0: 29 3b 20 66 70 72 69 6e 74 66 28 73 74 64 65 72  ); fprintf(stder
07b0: 72 2c 20 22 5c 6e 22 29 3b 20 7d 0a 23 65 6c 73  r, "\n"); }.#els
07c0: 65 0a 23 64 65 66 69 6e 65 20 64 70 72 69 6e 74  e.#define dprint
07d0: 66 28 2e 2e 2e 29 20 69 66 20 28 30 29 20 7b 20  f(...) if (0) { 
07e0: 66 70 72 69 6e 74 66 28 73 74 64 65 72 72 2c 20  fprintf(stderr, 
07f0: 5f 5f 56 41 5f 41 52 47 53 5f 5f 29 3b 20 7d 0a  __VA_ARGS__); }.
0800: 23 65 6e 64 69 66 0a 0a 23 64 65 66 69 6e 65 20  #endif..#define 
0810: 53 53 4c 5f 45 52 52 4f 52 28 73 73 6c 2c 65 72  SSL_ERROR(ssl,er
0820: 72 29 09 5c 0a 20 20 20 20 28 28 63 68 61 72 2a  r).\.    ((char*
0830: 29 45 52 52 5f 72 65 61 73 6f 6e 5f 65 72 72 6f  )ERR_reason_erro
0840: 72 5f 73 74 72 69 6e 67 28 28 75 6e 73 69 67 6e  r_string((unsign
0850: 65 64 20 6c 6f 6e 67 29 53 53 4c 5f 67 65 74 5f  ed long)SSL_get_
0860: 65 72 72 6f 72 28 28 73 73 6c 29 2c 28 65 72 72  error((ssl),(err
0870: 29 29 29 29 0a 2f 2a 0a 20 2a 20 4f 70 65 6e 53  ))))./*. * OpenS
0880: 53 4c 20 42 49 4f 20 52 6f 75 74 69 6e 65 73 0a  SL BIO Routines.
0890: 20 2a 2f 0a 23 64 65 66 69 6e 65 20 42 49 4f 5f   */.#define BIO_
08a0: 54 59 50 45 5f 54 43 4c 09 28 31 39 7c 30 78 30  TYPE_TCL.(19|0x0
08b0: 34 30 30 29 0a 0a 2f 2a 0a 20 2a 20 44 65 66 69  400)../*. * Defi
08c0: 6e 65 73 20 66 6f 72 20 53 74 61 74 65 2e 66 6c  nes for State.fl
08d0: 61 67 73 0a 20 2a 2f 0a 23 64 65 66 69 6e 65 20  ags. */.#define 
08e0: 54 4c 53 5f 54 43 4c 5f 41 53 59 4e 43 09 28 31  TLS_TCL_ASYNC.(1
08f0: 3c 3c 30 29 09 2f 2a 20 6e 6f 6e 2d 62 6c 6f 63  <<0)./* non-bloc
0900: 6b 69 6e 67 20 6d 6f 64 65 20 2a 2f 0a 23 64 65  king mode */.#de
0910: 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 53 45 52  fine TLS_TCL_SER
0920: 56 45 52 09 28 31 3c 3c 31 29 09 2f 2a 20 53 65  VER.(1<<1)./* Se
0930: 72 76 65 72 2d 53 69 64 65 20 2a 2f 0a 23 64 65  rver-Side */.#de
0940: 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 49 4e 49  fine TLS_TCL_INI
0950: 54 09 28 31 3c 3c 32 29 09 2f 2a 20 49 6e 69 74  T.(1<<2)./* Init
0960: 69 61 6c 69 7a 69 6e 67 20 63 6f 6e 6e 65 63 74  ializing connect
0970: 69 6f 6e 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54  ion */.#define T
0980: 4c 53 5f 54 43 4c 5f 44 45 42 55 47 09 28 31 3c  LS_TCL_DEBUG.(1<
0990: 3c 33 29 09 2f 2a 20 53 68 6f 77 20 64 65 62 75  <3)./* Show debu
09a0: 67 20 74 72 61 63 69 6e 67 20 2a 2f 0a 23 64 65  g tracing */.#de
09b0: 66 69 6e 65 20 54 4c 53 5f 54 43 4c 5f 43 41 4c  fine TLS_TCL_CAL
09c0: 4c 42 41 43 4b 09 28 31 3c 3c 34 29 09 2f 2a 20  LBACK.(1<<4)./* 
09d0: 49 6e 20 61 20 63 61 6c 6c 62 61 63 6b 2c 20 70  In a callback, p
09e0: 72 65 76 65 6e 74 20 75 70 64 61 74 65 0a 09 09  revent update...
09f0: 09 09 09 20 2a 20 6c 6f 6f 70 69 6e 67 20 70 72  ... * looping pr
0a00: 6f 62 6c 65 6d 2e 20 5b 42 75 67 20 31 36 35 32  oblem. [Bug 1652
0a10: 33 38 30 5d 20 2a 2f 0a 23 64 65 66 69 6e 65 20  380] */.#define 
0a20: 54 4c 53 5f 54 43 4c 5f 48 41 4e 44 53 48 41 4b  TLS_TCL_HANDSHAK
0a30: 45 5f 46 41 49 4c 45 44 20 28 31 3c 3c 35 29 20  E_FAILED (1<<5) 
0a40: 2f 2a 20 53 65 74 20 6f 6e 20 68 61 6e 64 73 68  /* Set on handsh
0a50: 61 6b 65 20 66 61 69 6c 75 72 65 73 20 61 6e 64  ake failures and
0a60: 20 6f 6e 63 65 0a 20 20 20 20 20 20 20 20 20 20   once.          
0a70: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0a80: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2a                 *
0a90: 20 73 65 74 2c 20 61 6c 6c 20 66 75 72 74 68 65   set, all furthe
0aa0: 72 20 49 2f 4f 20 77 69 6c 6c 20 72 65 73 75 6c  r I/O will resul
0ab0: 74 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20  t.              
0ac0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
0ad0: 20 20 20 20 20 20 20 20 20 20 20 2a 20 69 6e 20             * in 
0ae0: 45 43 4f 4e 4e 41 42 4f 52 54 45 44 20 65 72 72  ECONNABORTED err
0af0: 6f 72 73 2e 20 2a 2f 0a 0a 23 64 65 66 69 6e 65  ors. */..#define
0b00: 20 54 4c 53 5f 54 43 4c 5f 44 45 4c 41 59 20 28   TLS_TCL_DELAY (
0b10: 35 29 0a 0a 2f 2a 0a 20 2a 20 54 68 69 73 20 73  5)../*. * This s
0b20: 74 72 75 63 74 75 72 65 20 64 65 73 63 72 69 62  tructure describ
0b30: 65 73 20 74 68 65 20 70 65 72 2d 69 6e 73 74 61  es the per-insta
0b40: 6e 63 65 20 73 74 61 74 65 0a 20 2a 20 6f 66 20  nce state. * of 
0b50: 61 6e 20 73 73 6c 20 63 68 61 6e 6e 65 6c 2e 0a  an ssl channel..
0b60: 20 2a 0a 20 2a 20 54 68 65 20 53 53 4c 20 70 72   *. * The SSL pr
0b70: 6f 63 65 73 73 69 6e 67 20 63 6f 6e 74 65 78 74  ocessing context
0b80: 20 69 73 20 6d 61 69 6e 74 61 69 6e 65 64 20 68   is maintained h
0b90: 65 72 65 2c 20 69 6e 20 74 68 65 20 43 6c 69 65  ere, in the Clie
0ba0: 6e 74 44 61 74 61 0a 20 2a 2f 0a 74 79 70 65 64  ntData. */.typed
0bb0: 65 66 20 73 74 72 75 63 74 20 53 74 61 74 65 20  ef struct State 
0bc0: 7b 0a 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65  {.    Tcl_Channe
0bd0: 6c 20 73 65 6c 66 3b 09 2f 2a 20 74 68 69 73 20  l self;./* this 
0be0: 73 6f 63 6b 65 74 20 63 68 61 6e 6e 65 6c 20 2a  socket channel *
0bf0: 2f 0a 20 20 20 20 54 63 6c 5f 54 69 6d 65 72 54  /.    Tcl_TimerT
0c00: 6f 6b 65 6e 20 74 69 6d 65 72 3b 0a 0a 20 20 20  oken timer;..   
0c10: 20 69 6e 74 20 66 6c 61 67 73 3b 09 09 2f 2a 20   int flags;../* 
0c20: 73 65 65 20 53 74 61 74 65 2e 66 6c 61 67 73 20  see State.flags 
0c30: 61 62 6f 76 65 20 20 2a 2f 0a 20 20 20 20 69 6e  above  */.    in
0c40: 74 20 77 61 74 63 68 4d 61 73 6b 3b 09 2f 2a 20  t watchMask;./* 
0c50: 63 75 72 72 65 6e 74 20 57 61 74 63 68 50 72 6f  current WatchPro
0c60: 63 20 6d 61 73 6b 20 2a 2f 0a 20 20 20 20 69 6e  c mask */.    in
0c70: 74 20 6d 6f 64 65 3b 09 09 2f 2a 20 63 75 72 72  t mode;../* curr
0c80: 65 6e 74 20 6d 6f 64 65 20 6f 66 20 70 61 72 65  ent mode of pare
0c90: 6e 74 20 63 68 61 6e 6e 65 6c 20 2a 2f 0a 0a 20  nt channel */.. 
0ca0: 20 20 20 54 63 6c 5f 49 6e 74 65 72 70 20 2a 69     Tcl_Interp *i
0cb0: 6e 74 65 72 70 3b 09 2f 2a 20 69 6e 74 65 72 70  nterp;./* interp
0cc0: 72 65 74 65 72 20 69 6e 20 77 68 69 63 68 20 74  reter in which t
0cd0: 68 69 73 20 72 65 73 69 64 65 73 20 2a 2f 0a 20  his resides */. 
0ce0: 20 20 20 54 63 6c 5f 4f 62 6a 20 2a 63 61 6c 6c     Tcl_Obj *call
0cf0: 62 61 63 6b 3b 09 2f 2a 20 73 63 72 69 70 74 20  back;./* script 
0d00: 63 61 6c 6c 65 64 20 66 6f 72 20 74 72 61 63 69  called for traci
0d10: 6e 67 2c 20 76 65 72 69 66 79 69 6e 67 20 61 6e  ng, verifying an
0d20: 64 20 65 72 72 6f 72 73 20 2a 2f 0a 20 20 20 20  d errors */.    
0d30: 54 63 6c 5f 4f 62 6a 20 2a 70 61 73 73 77 6f 72  Tcl_Obj *passwor
0d40: 64 3b 09 2f 2a 20 73 63 72 69 70 74 20 63 61 6c  d;./* script cal
0d50: 6c 65 64 20 66 6f 72 20 63 65 72 74 69 66 69 63  led for certific
0d60: 61 74 65 20 70 61 73 73 77 6f 72 64 20 2a 2f 20  ate password */ 
0d70: 0a 0a 20 20 20 20 69 6e 74 20 76 66 6c 61 67 73  ..    int vflags
0d80: 3b 09 09 2f 2a 20 76 65 72 69 66 79 20 66 6c 61  ;../* verify fla
0d90: 67 73 20 2a 2f 0a 20 20 20 20 53 53 4c 20 2a 73  gs */.    SSL *s
0da0: 73 6c 3b 09 09 2f 2a 20 53 74 72 75 63 74 20 66  sl;../* Struct f
0db0: 6f 72 20 53 53 4c 20 70 72 6f 63 65 73 73 69 6e  or SSL processin
0dc0: 67 20 2a 2f 0a 20 20 20 20 53 53 4c 5f 43 54 58  g */.    SSL_CTX
0dd0: 20 2a 63 74 78 3b 09 2f 2a 20 53 53 4c 20 43 6f   *ctx;./* SSL Co
0de0: 6e 74 65 78 74 20 2a 2f 0a 20 20 20 20 42 49 4f  ntext */.    BIO
0df0: 20 2a 62 69 6f 3b 09 09 2f 2a 20 53 74 72 75 63   *bio;../* Struc
0e00: 74 20 66 6f 72 20 53 53 4c 20 70 72 6f 63 65 73  t for SSL proces
0e10: 73 69 6e 67 20 2a 2f 0a 20 20 20 20 42 49 4f 20  sing */.    BIO 
0e20: 2a 70 5f 62 69 6f 3b 09 09 2f 2a 20 50 61 72 65  *p_bio;../* Pare
0e30: 6e 74 20 42 49 4f 20 28 74 68 61 74 20 69 73 20  nt BIO (that is 
0e40: 6c 61 79 65 72 65 64 20 6f 6e 20 54 63 6c 5f 43  layered on Tcl_C
0e50: 68 61 6e 6e 65 6c 29 20 2a 2f 0a 0a 20 20 20 20  hannel) */..    
0e60: 63 68 61 72 20 2a 65 72 72 3b 0a 7d 20 53 74 61  char *err;.} Sta
0e70: 74 65 3b 0a 0a 2f 2a 0a 20 2a 20 54 68 65 20 66  te;../*. * The f
0e80: 6f 6c 6c 6f 77 69 6e 67 20 64 65 66 69 6e 69 74  ollowing definit
0e90: 69 6f 6e 73 20 68 61 76 65 20 74 6f 20 62 65 20  ions have to be 
0ea0: 75 73 61 62 6c 65 20 66 6f 72 20 38 2e 32 2e 30  usable for 8.2.0
0eb0: 2d 38 2e 33 2e 31 20 61 6e 64 20 38 2e 33 2e 32  -8.3.1 and 8.3.2
0ec0: 2b 2e 0a 20 2a 20 54 68 65 20 64 69 66 66 65 72  +.. * The differ
0ed0: 65 6e 63 65 73 20 62 65 74 77 65 65 6e 20 74 68  ences between th
0ee0: 65 73 65 20 76 65 72 73 69 6f 6e 73 3a 0a 20 2a  ese versions:. *
0ef0: 0a 20 2a 20 38 2e 30 2d 38 2e 31 3a 09 54 68 65  . * 8.0-8.1:.The
0f00: 72 65 20 69 73 20 6e 6f 20 73 75 70 70 6f 72 74  re is no support
0f10: 20 66 6f 72 20 74 68 65 73 65 20 69 6e 20 54 4c   for these in TL
0f20: 53 20 31 2e 34 20 28 67 65 74 20 31 2e 33 29 2e  S 1.4 (get 1.3).
0f30: 20 20 54 68 69 73 0a 20 2a 09 09 77 61 73 20 74    This. *..was t
0f40: 68 65 20 76 65 72 73 69 6f 6e 20 77 69 74 68 20  he version with 
0f50: 74 68 65 20 6f 72 69 67 69 6e 61 6c 20 70 61 74  the original pat
0f60: 63 68 2e 0a 20 2a 0a 20 2a 20 38 2e 32 2e 30 2d  ch.. *. * 8.2.0-
0f70: 09 43 68 61 6e 67 65 64 20 73 65 6d 61 6e 74 69  .Changed semanti
0f80: 63 73 20 66 6f 72 20 54 63 6c 5f 53 74 61 63 6b  cs for Tcl_Stack
0f90: 43 68 61 6e 6e 65 6c 20 28 54 63 6c 5f 52 65 70  Channel (Tcl_Rep
0fa0: 6c 61 63 65 43 68 61 6e 6e 65 6c 29 2e 0a 20 2a  laceChannel).. *
0fb0: 20 38 2e 33 2e 31 3a 09 43 68 65 63 6b 20 61 74   8.3.1:.Check at
0fc0: 20 72 75 6e 74 69 6d 65 20 74 6f 20 73 77 69 74   runtime to swit
0fd0: 63 68 20 74 68 65 20 62 65 68 61 76 69 6f 75 72  ch the behaviour
0fe0: 2e 20 54 68 65 20 70 61 74 63 68 20 69 73 20 70  . The patch is p
0ff0: 61 72 74 0a 20 2a 09 09 6f 66 20 74 68 65 20 63  art. *..of the c
1000: 6f 72 65 20 66 72 6f 6d 20 6e 6f 77 20 6f 6e 2e  ore from now on.
1010: 0a 20 2a 0a 20 2a 20 38 2e 33 2e 32 2b 3a 09 53  . *. * 8.3.2+:.S
1020: 74 61 63 6b 65 64 20 63 68 61 6e 6e 65 6c 73 20  tacked channels 
1030: 72 65 77 72 69 74 74 65 6e 20 66 6f 72 20 62 65  rewritten for be
1040: 74 74 65 72 20 62 65 68 61 76 69 6f 75 72 20 69  tter behaviour i
1050: 6e 20 73 6f 6d 65 0a 20 2a 09 09 73 69 74 75 61  n some. *..situa
1060: 74 69 6f 6e 73 20 28 63 6c 6f 73 69 6e 67 29 2e  tions (closing).
1070: 20 53 6f 6d 65 20 6e 65 77 20 41 50 49 27 73 2c   Some new API's,
1080: 20 73 65 6d 61 6e 74 69 63 20 63 68 61 6e 67 65   semantic change
1090: 73 2e 0a 20 2a 0a 20 2a 20 54 68 65 20 66 6f 6c  s.. *. * The fol
10a0: 6c 6f 77 69 6e 67 20 6d 61 67 69 63 20 77 61 73  lowing magic was
10b0: 20 61 64 61 70 74 65 64 20 66 72 6f 6d 20 54 72   adapted from Tr
10c0: 66 20 32 2e 31 20 28 4b 75 70 72 69 65 73 29 2e  f 2.1 (Kupries).
10d0: 0a 20 2a 2f 0a 0a 23 64 65 66 69 6e 65 20 54 4c  . */..#define TL
10e0: 53 5f 43 48 41 4e 4e 45 4c 5f 56 45 52 53 49 4f  S_CHANNEL_VERSIO
10f0: 4e 5f 31 09 30 78 31 0a 23 64 65 66 69 6e 65 20  N_1.0x1.#define 
1100: 54 4c 53 5f 43 48 41 4e 4e 45 4c 5f 56 45 52 53  TLS_CHANNEL_VERS
1110: 49 4f 4e 5f 32 09 30 78 32 0a 65 78 74 65 72 6e  ION_2.0x2.extern
1120: 20 69 6e 74 20 63 68 61 6e 6e 65 6c 54 79 70 65   int channelType
1130: 56 65 72 73 69 6f 6e 3b 0a 0a 23 69 66 64 65 66  Version;..#ifdef
1140: 20 55 53 45 5f 54 43 4c 5f 53 54 55 42 53 0a 23   USE_TCL_STUBS.#
1150: 69 66 6e 64 65 66 20 54 63 6c 5f 53 74 61 63 6b  ifndef Tcl_Stack
1160: 43 68 61 6e 6e 65 6c 0a 2f 2a 0a 20 2a 20 54 68  Channel./*. * Th
1170: 65 20 63 6f 72 65 20 77 65 20 61 72 65 20 63 6f  e core we are co
1180: 6d 70 69 6c 69 6e 67 20 61 67 61 69 6e 73 74 20  mpiling against 
1190: 69 73 20 6e 6f 74 20 70 61 74 63 68 65 64 2c 20  is not patched, 
11a0: 73 6f 20 73 75 70 70 6c 79 20 74 68 65 0a 20 2a  so supply the. *
11b0: 20 6e 65 63 65 73 73 73 61 72 79 20 64 65 66 69   necesssary defi
11c0: 6e 69 74 69 6f 6e 73 20 68 65 72 65 20 62 79 20  nitions here by 
11d0: 6f 75 72 73 65 6c 76 65 73 2e 20 54 68 65 20 66  ourselves. The f
11e0: 6f 72 6d 20 63 68 6f 73 65 6e 20 66 6f 72 0a 20  orm chosen for. 
11f0: 2a 20 74 68 65 20 70 72 6f 63 65 64 75 72 65 20  * the procedure 
1200: 6d 61 63 72 6f 73 20 28 72 65 73 65 72 76 65 64  macros (reserved
1210: 58 58 58 29 20 77 69 6c 6c 20 6e 6f 74 69 66 79  XXX) will notify
1220: 20 75 73 20 69 66 20 74 68 65 20 63 6f 72 65 0a   us if the core.
1230: 20 2a 20 64 6f 65 73 20 6e 6f 74 20 68 61 76 65   * does not have
1240: 20 74 68 65 73 65 20 72 65 73 65 72 76 65 64 20   these reserved 
1250: 6c 6f 63 61 74 69 6f 6e 73 20 61 6e 79 6d 6f 72  locations anymor
1260: 65 2e 0a 20 2a 0a 20 2a 20 21 21 20 53 79 6e 63  e.. *. * !! Sync
1270: 68 72 6f 6e 69 7a 65 20 74 68 65 20 70 72 6f 63  hronize the proc
1280: 65 64 75 72 65 20 69 6e 64 69 63 65 73 20 69 6e  edure indices in
1290: 20 74 68 65 69 72 20 64 65 66 69 6e 69 74 69 6f   their definitio
12a0: 6e 73 20 77 69 74 68 0a 20 2a 20 20 20 20 74 68  ns with. *    th
12b0: 65 20 70 61 74 63 68 20 74 6f 20 74 63 6c 2e 64  e patch to tcl.d
12c0: 65 63 6c 73 2c 20 61 73 20 74 68 65 79 20 68 61  ecls, as they ha
12d0: 76 65 20 74 6f 20 62 65 20 74 68 65 20 73 61 6d  ve to be the sam
12e0: 65 2e 0a 20 2a 2f 0a 0a 2f 2a 20 32 38 31 20 2a  e.. */../* 281 *
12f0: 2f 0a 74 79 70 65 64 65 66 20 54 63 6c 5f 43 68  /.typedef Tcl_Ch
1300: 61 6e 6e 65 6c 20 28 74 6c 73 5f 53 74 61 63 6b  annel (tls_Stack
1310: 43 68 61 6e 6e 65 6c 29 20 5f 41 4e 53 49 5f 41  Channel) _ANSI_A
1320: 52 47 53 5f 28 28 54 63 6c 5f 49 6e 74 65 72 70  RGS_((Tcl_Interp
1330: 2a 20 69 6e 74 65 72 70 2c 0a 09 09 09 09 09 09  * interp,.......
1340: 20 20 20 20 54 63 6c 5f 43 68 61 6e 6e 65 6c 54      Tcl_ChannelT
1350: 79 70 65 2a 20 74 79 70 65 50 74 72 2c 0a 09 09  ype* typePtr,...
1360: 09 09 09 09 20 20 20 20 43 6c 69 65 6e 74 44 61  ....    ClientDa
1370: 74 61 20 69 6e 73 74 61 6e 63 65 44 61 74 61 2c  ta instanceData,
1380: 0a 09 09 09 09 09 09 20 20 20 20 69 6e 74 20 6d  .......    int m
1390: 61 73 6b 2c 0a 09 09 09 09 09 09 20 20 20 20 54  ask,.......    T
13a0: 63 6c 5f 43 68 61 6e 6e 65 6c 20 70 72 65 76 43  cl_Channel prevC
13b0: 68 61 6e 29 29 3b 0a 2f 2a 20 32 38 32 20 2a 2f  han));./* 282 */
13c0: 0a 74 79 70 65 64 65 66 20 76 6f 69 64 20 28 74  .typedef void (t
13d0: 6c 73 5f 55 6e 73 74 61 63 6b 43 68 61 6e 6e 65  ls_UnstackChanne
13e0: 6c 29 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28  l) _ANSI_ARGS_((
13f0: 54 63 6c 5f 49 6e 74 65 72 70 2a 20 69 6e 74 65  Tcl_Interp* inte
1400: 72 70 2c 0a 09 09 09 09 09 20 20 20 20 20 20 20  rp,......       
1410: 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e  Tcl_Channel chan
1420: 29 29 3b 0a 0a 23 64 65 66 69 6e 65 20 54 63 6c  ));..#define Tcl
1430: 5f 53 74 61 63 6b 43 68 61 6e 6e 65 6c 20 20 20  _StackChannel   
1440: 20 20 28 28 74 6c 73 5f 53 74 61 63 6b 43 68 61    ((tls_StackCha
1450: 6e 6e 65 6c 2a 29 20 74 63 6c 53 74 75 62 73 50  nnel*) tclStubsP
1460: 74 72 2d 3e 72 65 73 65 72 76 65 64 32 38 31 29  tr->reserved281)
1470: 0a 23 64 65 66 69 6e 65 20 54 63 6c 5f 55 6e 73  .#define Tcl_Uns
1480: 74 61 63 6b 43 68 61 6e 6e 65 6c 20 28 28 74 6c  tackChannel ((tl
1490: 73 5f 55 6e 73 74 61 63 6b 43 68 61 6e 6e 65 6c  s_UnstackChannel
14a0: 2a 29 20 74 63 6c 53 74 75 62 73 50 74 72 2d 3e  *) tclStubsPtr->
14b0: 72 65 73 65 72 76 65 64 32 38 32 29 0a 0a 23 65  reserved282)..#e
14c0: 6e 64 69 66 20 2f 2a 20 54 63 6c 5f 53 74 61 63  ndif /* Tcl_Stac
14d0: 6b 43 68 61 6e 6e 65 6c 20 2a 2f 0a 0a 23 69 66  kChannel */..#if
14e0: 6e 64 65 66 20 54 63 6c 5f 47 65 74 53 74 61 63  ndef Tcl_GetStac
14f0: 6b 65 64 43 68 61 6e 6e 65 6c 0a 2f 2a 0a 20 2a  kedChannel./*. *
1500: 20 53 65 70 61 72 61 74 65 20 64 65 66 69 6e 69   Separate defini
1510: 74 69 6f 6e 2c 20 61 76 61 69 6c 61 62 6c 65 20  tion, available 
1520: 69 6e 20 38 2e 32 2c 20 62 75 74 20 6e 6f 74 20  in 8.2, but not 
1530: 38 2e 31 20 61 6e 64 20 62 65 66 6f 72 65 20 21  8.1 and before !
1540: 0a 20 2a 2f 0a 0a 2f 2a 20 32 38 33 20 2a 2f 0a  . */../* 283 */.
1550: 74 79 70 65 64 65 66 20 54 63 6c 5f 43 68 61 6e  typedef Tcl_Chan
1560: 6e 65 6c 20 28 74 6c 73 5f 47 65 74 53 74 61 63  nel (tls_GetStac
1570: 6b 65 64 43 68 61 6e 6e 65 6c 29 20 5f 41 4e 53  kedChannel) _ANS
1580: 49 5f 41 52 47 53 5f 28 28 54 63 6c 5f 43 68 61  I_ARGS_((Tcl_Cha
1590: 6e 6e 65 6c 20 63 68 61 6e 29 29 3b 0a 0a 23 64  nnel chan));..#d
15a0: 65 66 69 6e 65 20 54 63 6c 5f 47 65 74 53 74 61  efine Tcl_GetSta
15b0: 63 6b 65 64 43 68 61 6e 6e 65 6c 20 28 28 74 6c  ckedChannel ((tl
15c0: 73 5f 47 65 74 53 74 61 63 6b 65 64 43 68 61 6e  s_GetStackedChan
15d0: 6e 65 6c 2a 29 20 74 63 6c 53 74 75 62 73 50 74  nel*) tclStubsPt
15e0: 72 2d 3e 72 65 73 65 72 76 65 64 32 38 33 29 0a  r->reserved283).
15f0: 0a 23 65 6e 64 69 66 20 2f 2a 20 54 63 6c 5f 47  .#endif /* Tcl_G
1600: 65 74 53 74 61 63 6b 65 64 43 68 61 6e 6e 65 6c  etStackedChannel
1610: 20 2a 2f 0a 0a 0a 23 69 66 6e 64 65 66 20 54 43   */...#ifndef TC
1620: 4c 5f 43 48 41 4e 4e 45 4c 5f 56 45 52 53 49 4f  L_CHANNEL_VERSIO
1630: 4e 5f 32 0a 2f 2a 0a 20 2a 20 43 6f 72 65 20 69  N_2./*. * Core i
1640: 73 20 6f 6c 64 65 72 20 74 68 61 6e 20 38 2e 33  s older than 8.3
1650: 2e 32 2e 20 20 53 75 70 70 6c 79 20 74 68 65 20  .2.  Supply the 
1660: 6d 69 73 73 69 6e 67 20 64 65 66 69 6e 69 74 69  missing definiti
1670: 6f 6e 73 20 66 6f 72 0a 20 2a 20 74 68 65 20 6e  ons for. * the n
1680: 65 77 20 41 50 49 27 73 20 69 6e 20 38 2e 33 2e  ew API's in 8.3.
1690: 32 2e 0a 20 2a 2f 0a 23 64 65 66 69 6e 65 20 45  2.. */.#define E
16a0: 4d 55 4c 41 54 45 5f 43 48 41 4e 4e 45 4c 5f 56  MULATE_CHANNEL_V
16b0: 45 52 53 49 4f 4e 5f 32 0a 0a 74 79 70 65 64 65  ERSION_2..typede
16c0: 66 20 73 74 72 75 63 74 20 54 6c 73 43 68 61 6e  f struct TlsChan
16d0: 6e 65 6c 54 79 70 65 56 65 72 73 69 6f 6e 5f 2a  nelTypeVersion_*
16e0: 20 54 6c 73 43 68 61 6e 6e 65 6c 54 79 70 65 56   TlsChannelTypeV
16f0: 65 72 73 69 6f 6e 3b 0a 23 64 65 66 69 6e 65 20  ersion;.#define 
1700: 54 43 4c 5f 43 48 41 4e 4e 45 4c 5f 56 45 52 53  TCL_CHANNEL_VERS
1710: 49 4f 4e 5f 32 09 28 28 54 6c 73 43 68 61 6e 6e  ION_2.((TlsChann
1720: 65 6c 54 79 70 65 56 65 72 73 69 6f 6e 29 20 30  elTypeVersion) 0
1730: 78 32 29 0a 0a 74 79 70 65 64 65 66 20 69 6e 74  x2)..typedef int
1740: 20 28 54 6c 73 44 72 69 76 65 72 48 61 6e 64 6c   (TlsDriverHandl
1750: 65 72 50 72 6f 63 29 20 5f 41 4e 53 49 5f 41 52  erProc) _ANSI_AR
1760: 47 53 5f 28 28 43 6c 69 65 6e 74 44 61 74 61 20  GS_((ClientData 
1770: 69 6e 73 74 61 6e 63 65 44 61 74 61 2c 0a 09 09  instanceData,...
1780: 09 09 09 69 6e 74 20 69 6e 74 65 72 65 73 74 4d  ...int interestM
1790: 61 73 6b 29 29 3b 0a 2f 2a 20 33 39 34 20 2a 2f  ask));./* 394 */
17a0: 0a 74 79 70 65 64 65 66 20 69 6e 74 20 28 74 6c  .typedef int (tl
17b0: 73 5f 52 65 61 64 52 61 77 29 20 20 5f 41 4e 53  s_ReadRaw)  _ANS
17c0: 49 5f 41 52 47 53 5f 28 28 54 63 6c 5f 43 68 61  I_ARGS_((Tcl_Cha
17d0: 6e 6e 65 6c 20 63 68 61 6e 2c 20 63 68 61 72 20  nnel chan, char 
17e0: 2a 64 73 74 2c 0a 09 09 09 09 09 69 6e 74 20 62  *dst,......int b
17f0: 79 74 65 73 54 6f 52 65 61 64 29 29 3b 0a 2f 2a  ytesToRead));./*
1800: 20 33 39 35 20 2a 2f 0a 74 79 70 65 64 65 66 20   395 */.typedef 
1810: 69 6e 74 20 28 74 6c 73 5f 57 72 69 74 65 52 61  int (tls_WriteRa
1820: 77 29 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28  w) _ANSI_ARGS_((
1830: 54 63 6c 5f 43 68 61 6e 6e 65 6c 20 63 68 61 6e  Tcl_Channel chan
1840: 2c 20 63 68 61 72 20 2a 73 72 63 2c 0a 09 09 09  , char *src,....
1850: 09 09 69 6e 74 20 73 72 63 4c 65 6e 29 29 3b 0a  ..int srcLen));.
1860: 2f 2a 20 33 39 37 20 2a 2f 0a 74 79 70 65 64 65  /* 397 */.typede
1870: 66 20 69 6e 74 20 28 74 6c 73 5f 47 65 74 54 6f  f int (tls_GetTo
1880: 70 43 68 61 6e 6e 65 6c 29 20 5f 41 4e 53 49 5f  pChannel) _ANSI_
1890: 41 52 47 53 5f 28 28 54 63 6c 5f 43 68 61 6e 6e  ARGS_((Tcl_Chann
18a0: 65 6c 20 63 68 61 6e 29 29 3b 0a 0a 2f 2a 0a 20  el chan));../*. 
18b0: 2a 20 47 65 6e 65 72 61 74 69 6e 67 20 63 6f 64  * Generating cod
18c0: 65 20 66 6f 72 20 61 63 63 65 73 73 69 6e 67 20  e for accessing 
18d0: 74 68 65 73 65 20 70 61 72 74 73 20 6f 66 20 74  these parts of t
18e0: 68 65 20 73 74 75 62 20 74 61 62 6c 65 20 77 68  he stub table wh
18f0: 65 6e 0a 20 2a 20 63 6f 6d 70 69 6c 69 6e 67 20  en. * compiling 
1900: 61 67 61 69 6e 73 74 20 61 20 63 6f 72 65 20 6f  against a core o
1910: 6c 64 65 72 20 74 68 61 6e 20 38 2e 33 2e 32 20  lder than 8.3.2 
1920: 69 73 20 61 20 68 61 73 73 6c 65 20 62 65 63 61  is a hassle beca
1930: 75 73 65 20 65 76 65 6e 0a 20 2a 20 74 68 65 20  use even. * the 
1940: 27 72 65 73 65 72 76 65 64 58 58 58 27 20 66 69  'reservedXXX' fi
1950: 65 6c 64 73 20 6f 66 20 74 68 65 20 73 74 72 75  elds of the stru
1960: 63 74 75 72 65 20 61 72 65 20 6e 6f 74 20 64 65  cture are not de
1970: 66 69 6e 65 64 20 79 65 74 2e 20 53 6f 0a 20 2a  fined yet. So. *
1980: 20 77 65 20 68 61 76 65 20 74 6f 20 77 72 69 74   we have to writ
1990: 65 20 75 70 20 73 6f 6d 65 20 6d 61 63 72 6f 73  e up some macros
19a0: 20 68 69 64 69 6e 67 20 73 6f 6d 65 20 76 65 72   hiding some ver
19b0: 79 20 68 61 63 6b 69 73 68 20 70 6f 69 6e 74 65  y hackish pointe
19c0: 72 0a 20 2a 20 61 72 69 74 68 6d 65 74 69 63 73  r. * arithmetics
19d0: 20 74 6f 20 67 65 74 20 61 74 20 74 68 65 73 65   to get at these
19e0: 20 66 69 65 6c 64 73 2e 20 57 65 20 61 73 73 75   fields. We assu
19f0: 6d 65 20 74 68 61 74 20 70 6f 69 6e 74 65 72 20  me that pointer 
1a00: 74 6f 0a 20 2a 20 66 75 6e 63 74 69 6f 6e 73 20  to. * functions 
1a10: 61 72 65 20 61 6c 77 61 79 73 20 6f 66 20 74 68  are always of th
1a20: 65 20 73 61 6d 65 20 73 69 7a 65 2e 0a 20 2a 2f  e same size.. */
1a30: 0a 0a 23 64 65 66 69 6e 65 20 53 54 55 42 5f 42  ..#define STUB_B
1a40: 41 53 45 20 20 20 28 28 63 68 61 72 2a 29 28 26  ASE   ((char*)(&
1a50: 28 74 63 6c 53 74 75 62 73 50 74 72 2d 3e 74 63  (tclStubsPtr->tc
1a60: 6c 5f 55 74 66 4e 63 61 73 65 63 6d 70 29 29 29  l_UtfNcasecmp)))
1a70: 20 2f 2a 20 66 69 65 6c 64 20 33 37 30 20 2a 2f   /* field 370 */
1a80: 0a 23 64 65 66 69 6e 65 20 70 72 6f 63 50 74 72  .#define procPtr
1a90: 53 69 7a 65 20 28 73 69 7a 65 6f 66 20 28 54 63  Size (sizeof (Tc
1aa0: 6c 5f 44 72 69 76 65 72 42 6c 6f 63 6b 4d 6f 64  l_DriverBlockMod
1ab0: 65 50 72 6f 63 20 2a 29 29 0a 23 64 65 66 69 6e  eProc *)).#defin
1ac0: 65 20 49 44 58 28 6e 29 20 20 20 20 20 20 28 28  e IDX(n)      ((
1ad0: 28 6e 29 2d 33 37 30 29 20 2a 20 70 72 6f 63 50  (n)-370) * procP
1ae0: 74 72 53 69 7a 65 29 0a 23 64 65 66 69 6e 65 20  trSize).#define 
1af0: 53 4c 4f 54 28 6e 29 20 20 20 20 20 28 53 54 55  SLOT(n)     (STU
1b00: 42 5f 42 41 53 45 20 2b 20 49 44 58 28 6e 29 29  B_BASE + IDX(n))
1b10: 0a 0a 23 64 65 66 69 6e 65 20 54 63 6c 5f 52 65  ..#define Tcl_Re
1b20: 61 64 52 61 77 09 09 28 2a 28 28 74 6c 73 5f 52  adRaw..(*((tls_R
1b30: 65 61 64 52 61 77 2a 2a 29 09 28 53 4c 4f 54 28  eadRaw**).(SLOT(
1b40: 33 39 34 29 29 29 29 0a 23 64 65 66 69 6e 65 20  394)))).#define 
1b50: 54 63 6c 5f 57 72 69 74 65 52 61 77 09 09 28 2a  Tcl_WriteRaw..(*
1b60: 28 28 74 6c 73 5f 57 72 69 74 65 52 61 77 2a 2a  ((tls_WriteRaw**
1b70: 29 09 28 53 4c 4f 54 28 33 39 35 29 29 29 29 0a  ).(SLOT(395)))).
1b80: 23 64 65 66 69 6e 65 20 54 63 6c 5f 47 65 74 54  #define Tcl_GetT
1b90: 6f 70 43 68 61 6e 6e 65 6c 09 28 2a 28 28 74 6c  opChannel.(*((tl
1ba0: 73 5f 47 65 74 54 6f 70 43 68 61 6e 6e 65 6c 2a  s_GetTopChannel*
1bb0: 2a 29 28 53 4c 4f 54 28 33 39 36 29 29 29 29 0a  *)(SLOT(396)))).
1bc0: 0a 2f 2a 0a 20 2a 20 52 65 71 75 69 72 65 64 2c  ./*. * Required,
1bd0: 20 65 61 73 79 20 65 6d 75 6c 61 74 69 6f 6e 2e   easy emulation.
1be0: 0a 20 2a 2f 0a 23 64 65 66 69 6e 65 20 54 63 6c  . */.#define Tcl
1bf0: 5f 43 68 61 6e 6e 65 6c 47 65 74 4f 70 74 69 6f  _ChannelGetOptio
1c00: 6e 50 72 6f 63 28 63 68 61 6e 44 72 69 76 65 72  nProc(chanDriver
1c10: 29 20 28 28 63 68 61 6e 44 72 69 76 65 72 29 2d  ) ((chanDriver)-
1c20: 3e 67 65 74 4f 70 74 69 6f 6e 50 72 6f 63 29 0a  >getOptionProc).
1c30: 0a 23 65 6e 64 69 66 20 2f 2a 20 54 43 4c 5f 43  .#endif /* TCL_C
1c40: 48 41 4e 4e 45 4c 5f 56 45 52 53 49 4f 4e 5f 32  HANNEL_VERSION_2
1c50: 20 2a 2f 0a 0a 23 65 6e 64 69 66 20 2f 2a 20 55   */..#endif /* U
1c60: 53 45 5f 54 43 4c 5f 53 54 55 42 53 20 2a 2f 0a  SE_TCL_STUBS */.
1c70: 0a 2f 2a 0a 20 2a 20 46 6f 72 77 61 72 64 20 64  ./*. * Forward d
1c80: 65 63 6c 61 72 61 74 69 6f 6e 73 0a 20 2a 2f 0a  eclarations. */.
1c90: 0a 54 63 6c 5f 43 68 61 6e 6e 65 6c 54 79 70 65  .Tcl_ChannelType
1ca0: 20 2a 54 6c 73 5f 43 68 61 6e 6e 65 6c 54 79 70   *Tls_ChannelTyp
1cb0: 65 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 76  e _ANSI_ARGS_((v
1cc0: 6f 69 64 29 29 3b 0a 54 63 6c 5f 43 68 61 6e 6e  oid));.Tcl_Chann
1cd0: 65 6c 09 54 6c 73 5f 47 65 74 50 61 72 65 6e 74  el.Tls_GetParent
1ce0: 20 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 53 74   _ANSI_ARGS_((St
1cf0: 61 74 65 20 2a 73 74 61 74 65 50 74 72 29 29 3b  ate *statePtr));
1d00: 0a 0a 54 63 6c 5f 4f 62 6a 2a 09 09 54 6c 73 5f  ..Tcl_Obj*..Tls_
1d10: 4e 65 77 58 35 30 39 4f 62 6a 20 5f 41 4e 53 49  NewX509Obj _ANSI
1d20: 5f 41 52 47 53 5f 20 28 28 20 54 63 6c 5f 49 6e  _ARGS_ (( Tcl_In
1d30: 74 65 72 70 20 2a 69 6e 74 65 72 70 2c 20 58 35  terp *interp, X5
1d40: 30 39 20 2a 63 65 72 74 29 29 3b 0a 76 6f 69 64  09 *cert));.void
1d50: 09 09 54 6c 73 5f 45 72 72 6f 72 20 5f 41 4e 53  ..Tls_Error _ANS
1d60: 49 5f 41 52 47 53 5f 20 28 28 53 74 61 74 65 20  I_ARGS_ ((State 
1d70: 2a 73 74 61 74 65 50 74 72 2c 20 63 68 61 72 20  *statePtr, char 
1d80: 2a 6d 73 67 29 29 3b 0a 76 6f 69 64 09 09 54 6c  *msg));.void..Tl
1d90: 73 5f 46 72 65 65 20 5f 41 4e 53 49 5f 41 52 47  s_Free _ANSI_ARG
1da0: 53 5f 20 28 28 63 68 61 72 20 2a 62 6c 6f 63 6b  S_ ((char *block
1db0: 50 74 72 29 29 3b 0a 76 6f 69 64 09 09 54 6c 73  Ptr));.void..Tls
1dc0: 5f 43 6c 65 61 6e 20 5f 41 4e 53 49 5f 41 52 47  _Clean _ANSI_ARG
1dd0: 53 5f 20 28 28 53 74 61 74 65 20 2a 73 74 61 74  S_ ((State *stat
1de0: 65 50 74 72 29 29 3b 0a 69 6e 74 09 09 54 6c 73  ePtr));.int..Tls
1df0: 5f 57 61 69 74 46 6f 72 43 6f 6e 6e 65 63 74 20  _WaitForConnect 
1e00: 5f 41 4e 53 49 5f 41 52 47 53 5f 28 28 20 53 74  _ANSI_ARGS_(( St
1e10: 61 74 65 20 2a 73 74 61 74 65 50 74 72 2c 0a 09  ate *statePtr,..
1e20: 09 09 09 09 09 09 69 6e 74 20 2a 65 72 72 6f 72  ......int *error
1e30: 43 6f 64 65 50 74 72 29 29 3b 0a 0a 42 49 4f 20  CodePtr));..BIO 
1e40: 2a 09 09 42 49 4f 5f 6e 65 77 5f 74 63 6c 20 5f  *..BIO_new_tcl _
1e50: 41 4e 53 49 5f 41 52 47 53 5f 28 28 53 74 61 74  ANSI_ARGS_((Stat
1e60: 65 2a 20 73 74 61 74 65 50 74 72 2c 20 69 6e 74  e* statePtr, int
1e70: 20 66 6c 61 67 73 29 29 3b 0a 0a 23 65 6e 64 69   flags));..#endi
1e80: 66 20 2f 2a 20 5f 54 4c 53 49 4e 54 5f 48 20 2a  f /* _TLSINT_H *
1e90: 2f 0a                                            /.