Check-in [e7ef654f47]
Bounty program for improvements to Tcl and certain Tcl packages.
Overview
Comment: * tlsInt.h: * tls.c: * tlsIO.c: corrected structure initialization to work when compiling with 8.2. Now compiles with 8.2+ and tested to work with 8.2+ and dynamically adjust to the version of Tcl it was loaded into. TLS will fail the test suite with Tcl 8.2-8.3.1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e7ef654f47612caaffca97b9803cea15f6b168d2
User & Date: hobbs on 2000-08-15 18:49:30
Other Links: manifest | tags
Context
2000-08-16
17:44
* tls.c (Tls_Init): corrected interpretation of version number (patchlevel and release/serial were swapped). check-in: 090741a97a user: hobbs tags: trunk
2000-08-15
18:49
* tlsInt.h: * tls.c: * tlsIO.c: corrected structure initialization to work when compiling with 8.2. Now compiles with 8.2+ and tested to work with 8.2+ and dynamically adjust to the version of Tcl it was loaded into. TLS will fail the test suite with Tcl 8.2-8.3.1. check-in: e7ef654f47 user: hobbs tags: trunk
18:49
* README.txt: added notes about need to use 8.2.0+. check-in: 74804ed748 user: hobbs tags: trunk
Changes

Modified ChangeLog from [00d4c60b28] to [1bd81afa71].

     1      1   2000-08-15  Jeff Hobbs  <[email protected]>
            2  +
            3  +	* README.txt: added notes about need to use 8.2.0+.
            4  +
            5  +	* tlsInt.h:
            6  +	* tls.c:
            7  +	* tlsIO.c: corrected structure initialization to work when
            8  +	compiling with 8.2.  Now compiles with 8.2+ and tested to work
            9  +	with 8.2+ and dynamically adjust to the version of Tcl it was
           10  +	loaded into.  TLS will fail the test suite with Tcl 8.2-8.3.1.
           11  +
           12  +	* tests/all.tcl: added catch around ::tcltest::normalizePath
           13  +	because it doesn't exist in pre-8.3 tcltest.
     2     14   
     3     15   	* tests/simpleClient.tcl: 
     4     16   	* tests/simpleServer.tcl: added simple client/server test scripts
     5     17   	that use test certs and can do simple stress tests.
     6     18   
     7     19   2000-08-14  Jeff Hobbs  <[email protected]>
     8     20   

Modified tls.c from [468d0efc89] to [bc1abaf8b3].

     1      1   /*
     2      2    * Copyright (C) 1997-1999 Matt Newman <[email protected]>
            3  + * Copyright (C) 2000 Ajuba Solutions
     3      4    *
     4         - * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tls.c,v 1.9 2000/08/15 00:02:08 hobbs Exp $
            5  + * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tls.c,v 1.10 2000/08/15 18:49:30 hobbs Exp $
     5      6    *
     6      7    * TLS (aka SSL) Channel - can be layered on any bi-directional
     7      8    * Tcl_Channel (Note: Requires Trf Core Patch)
     8      9    *
     9     10    * This was built (almost) from scratch based upon observation of
    10     11    * OpenSSL 0.9.2B
    11     12    *

Modified tlsIO.c from [7f2f9df19f] to [76eadcab80].

     1      1   /*
     2      2    * Copyright (C) 1997-2000 Matt Newman <[email protected]>
            3  + * Copyright (C) 2000 Ajuba Solutions
     3      4    *
     4         - * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tlsIO.c,v 1.9 2000/08/15 00:02:08 hobbs Exp $
            5  + * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tlsIO.c,v 1.10 2000/08/15 18:49:30 hobbs Exp $
     5      6    *
     6      7    * TLS (aka SSL) Channel - can be layered on any bi-directional
     7      8    * Tcl_Channel (Note: Requires Trf Core Patch)
     8      9    *
     9     10    * This was built from scratch based upon observation of OpenSSL 0.9.2B
    10     11    *
    11     12    * Addition credit is due for Andreas Kupries ([email protected]), for
................................................................................
    16     17    *	tclSSL (Colin McCormack, Shared Technology)
    17     18    *	SSLtcl (Peter Antman)
    18     19    *
    19     20    */
    20     21   
    21     22   #include "tlsInt.h"
    22     23   
    23         -/*
    24         - * External functions
    25         - */
    26         -
    27         -/*
    28         - * Local Defines
    29         - */
    30         -
    31     24   /*
    32     25    * Forward declarations
    33     26    */
    34     27   
    35     28   static int	TlsBlockModeProc _ANSI_ARGS_((ClientData instanceData,
    36     29   			int mode));
    37     30   static int	TlsCloseProc _ANSI_ARGS_ ((ClientData instanceData,
................................................................................
    50     43   			int mask));
    51     44   static void	TlsChannelHandler _ANSI_ARGS_ ((ClientData clientData,
    52     45   			int mask));
    53     46   static void	TlsChannelHandlerTimer _ANSI_ARGS_ ((ClientData clientData));
    54     47   
    55     48   /*
    56     49    * This structure describes the channel type structure for TCP socket
    57         - * based IO:
           50  + * based IO.  These are what the structures should look like, but we
           51  + * have to build them up at runtime to be correct depending on whether
           52  + * we are loaded into an 8.2.0-8.3.1 or 8.3.2+ Tcl interpreter.
    58     53    */
           54  +#ifdef TLS_STATIC_STRUCTURES_NOT_USED
    59     55   static Tcl_ChannelType tlsChannelType2 = {
    60     56       "tls",		/* Type name. */
    61         -#ifndef TCL_CHANNEL_VERSION_2
    62         -    /*
    63         -     * Avoids warning in Windows compiler when compiling with 8.3.1-.
    64         -     */
    65         -    (Tcl_DriverBlockModeProc *)
    66         -#endif
    67     57       TCL_CHANNEL_VERSION_2,	/* A v2 channel (8.3.2+) */
    68     58       TlsCloseProc,	/* Close proc. */
    69     59       TlsInputProc,	/* Input proc. */
    70     60       TlsOutputProc,	/* Output proc. */
    71     61       NULL,		/* Seek proc. */
    72     62       NULL,		/* Set option proc. */
    73     63       TlsGetOptionProc,	/* Get option proc. */
................................................................................
    77     67       TlsBlockModeProc,	/* Set blocking/nonblocking mode.*/
    78     68       NULL,		/* FlushProc. */
    79     69       TlsNotifyProc,	/* handlerProc. */
    80     70   };
    81     71   
    82     72   static Tcl_ChannelType tlsChannelType1 = {
    83     73       "tls",		/* Type name. */
    84         -#ifdef TCL_CHANNEL_VERSION_2
    85         -    /*
    86         -     * Avoids warning in Windows compiler when compiling with 8.3.2+.
    87         -     */
    88         -    (Tcl_ChannelTypeVersion)
    89         -#endif
    90     74       TlsBlockModeProc,	/* Set blocking/nonblocking mode.*/
    91     75       TlsCloseProc,	/* Close proc. */
    92     76       TlsInputProc,	/* Input proc. */
    93     77       TlsOutputProc,	/* Output proc. */
    94     78       NULL,		/* Seek proc. */
    95     79       NULL,		/* Set option proc. */
    96     80       TlsGetOptionProc,	/* Get option proc. */
    97     81       TlsWatchProc,	/* Initialize notifier. */
    98     82       TlsGetHandleProc,	/* Get file handle out of channel. */
    99     83   };
           84  +#else
           85  +static Tcl_ChannelType *tlsChannelType = NULL;
           86  +#endif
   100     87   
           88  +/*
           89  + *-------------------------------------------------------------------
           90  + *
           91  + * Tls_ChannelType --
           92  + *
           93  + *	Return the correct TLS channel driver info
           94  + *
           95  + * Results:
           96  + *	The correct channel driver for the current version of Tcl.
           97  + *
           98  + * Side effects:
           99  + *	None.
          100  + *
          101  + *-------------------------------------------------------------------
          102  + */
   101    103   Tcl_ChannelType *Tls_ChannelType()
   102    104   {
   103         -    if (channelTypeVersion == TLS_CHANNEL_VERSION_2) {
   104         -	return &tlsChannelType2;
   105         -    } else {
   106         -	return &tlsChannelType1;
   107         -    }
          105  +    /*
          106  +     * Initialize the channel type if necessary
          107  +     */
          108  +    if (tlsChannelType == NULL) {
          109  +	/*
          110  +	 * Allocation of a new channeltype structure is not easy, because of
          111  +	 * the various verson of the core and subsequent changes to the
          112  +	 * structure. The main challenge is to allocate enough memory for
          113  +	 * odern versions even if this extyension is compiled against one
          114  +	 * of the older variant!
          115  +	 *
          116  +	 * (1) Versions before stubs (8.0.x) are simple, because they are
          117  +	 *     supported only if the extension is compiled against exactly
          118  +	 *     that version of the core.
          119  +	 *
          120  +	 * (2) With stubs we just determine the difference between the older
          121  +	 *     and modern variant and overallocate accordingly if compiled
          122  +	 *     against an older variant.
          123  +	 */
          124  +
          125  +	int size = sizeof(Tcl_ChannelType); /* Base size */
          126  +
          127  +	/*
          128  +	 * Size of a procedure pointer. We assume that all procedure
          129  +	 * pointers are of the same size, regardless of exact type
          130  +	 * (arguments and return values).
          131  +	 *
          132  +	 * 8.2.   First version containing close2proc. Baseline.
          133  +	 * 8.3.2  Three additional vectors. Moved blockMode, new flush- and
          134  +	 *        handlerProc's.
          135  +	 *
          136  +	 * => Compilation against earlier version has to overallocate three
          137  +	 *    procedure pointers.
          138  +	 */
          139  +
          140  +#ifdef EMULATE_CHANNEL_VERSION_2
          141  +	size += 3 * procPtrSize;
          142  +#endif
          143  +
          144  +	tlsChannelType = (Tcl_ChannelType *) ckalloc(size);
          145  +	memset((VOID *) tlsChannelType, 0, size);
          146  +
          147  +	/*
          148  +	 * Common elements of the structure (no changes in location or name)
          149  +	 * close2Proc, seekProc, setOptionProc stay NULL.
          150  +	 */
          151  +
          152  +	tlsChannelType->closeProc        = TlsCloseProc;
          153  +	tlsChannelType->inputProc        = TlsInputProc;
          154  +	tlsChannelType->outputProc       = TlsOutputProc;
          155  +	tlsChannelType->getOptionProc    = TlsGetOptionProc;
          156  +	tlsChannelType->watchProc        = TlsWatchProc;
          157  +	tlsChannelType->getHandleProc    = TlsGetHandleProc;
          158  +
          159  +	/*
          160  +	 * blockModeProc is a twister.  We have to make some runtime-choices,
          161  +	 * depending on the version we compiled against.
          162  +	 */
          163  +
          164  +#ifdef EMULATE_CHANNEL_VERSION_2
          165  +	/*
          166  +	 * We are compiling against an 8.3.1- core.  We have to create some
          167  +	 * definitions for the new elements as the compiler does not know them
          168  +	 * by name.
          169  +	 */
          170  +
          171  +	if (channelTypeVersion == TLS_CHANNEL_VERSION_1) {
          172  +	    /*
          173  +	     * The 'version' element of 8.3.2 is in the the place of the
          174  +	     * blockModeProc. For 8.2.0-8.3.1 we have to set our blockModeProc
          175  +	     * into this place.
          176  +	     */
          177  +	    tlsChannelType->blockModeProc = TlsBlockModeProc;
          178  +	} else /* channelTypeVersion == TLS_CHANNEL_VERSION_2 */ {
          179  +	    /*
          180  +	     * For the 8.3.2 core we present ourselves as a version 2
          181  +	     * driver. This means a special value in version (ex
          182  +	     * blockModeProc), blockModeProc in a different place and of
          183  +	     * course usage of the handlerProc.  The last two have to
          184  +	     * referenced with pointer magic because they aren't defined
          185  +	     * otherwise.
          186  +	     */
          187  +
          188  +	    tlsChannelType->blockModeProc =
          189  +		(Tcl_DriverBlockModeProc*) TLS_CHANNEL_VERSION_2;
          190  +	    (*((Tcl_DriverBlockModeProc**)(&(tlsChannelType->close2Proc)+1)))
          191  +		= TlsBlockModeProc;
          192  +	    (*((TlsDriverHandlerProc**)(&(tlsChannelType->close2Proc)+3)))
          193  +		= TlsNotifyProc;
          194  +	}
          195  +#else
          196  +	/*
          197  +	 * Compiled against 8.3.2+. Direct access to all elements possible. Use
          198  +	 * channelTypeVersion information to select the values to use.
          199  +	 */
          200  +
          201  +	if (channelTypeVersion == TLS_CHANNEL_VERSION_1) {
          202  +	    /*
          203  +	     * The 'version' element of 8.3.2 is in the the place of the
          204  +	     * blockModeProc. For the original patch in 8.1.x and the firstly
          205  +	     * included (8.2) we have to set our blockModeProc into this
          206  +	     * place.
          207  +	     */
          208  +	    tlsChannelType->version = (Tcl_ChannelTypeVersion)TlsBlockModeProc;
          209  +	} else /* channelTypeVersion == TLS_CHANNEL_VERSION_2 */ {
          210  +	    /*
          211  +	     * For the 8.3.2 core we present ourselves as a version 2
          212  +	     * driver. This means a special value in version (ex
          213  +	     * blockModeProc), blockModeProc in a different place and of
          214  +	     * course usage of the handlerProc.
          215  +	     */
          216  +
          217  +	    tlsChannelType->version       = TCL_CHANNEL_VERSION_2;
          218  +	    tlsChannelType->blockModeProc = TlsBlockModeProc;
          219  +	    tlsChannelType->handlerProc   = TlsNotifyProc;
          220  +	}
          221  +#endif
          222  +    }
          223  +    return tlsChannelType;
   108    224   }
   109    225   
   110    226   /*
   111    227    *-------------------------------------------------------------------
   112    228    *
   113    229    * TlsBlockModeProc --
   114    230    *

Modified tlsInt.h from [b040f94bfd] to [45743e25af].

     1      1   /*
     2      2    * Copyright (C) 1997-2000 Matt Newman <[email protected]>
     3      3    *
     4         - * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tlsInt.h,v 1.6 2000/08/15 00:02:08 hobbs Exp $
            4  + * $Header: /home/rkeene/tmp/cvs2fossil/../tcltls/tls/tls/tlsInt.h,v 1.7 2000/08/15 18:49:31 hobbs Exp $
     5      5    *
     6      6    * TLS (aka SSL) Channel - can be layered on any bi-directional
     7      7    * Tcl_Channel (Note: Requires Trf Core Patch)
     8      8    *
     9      9    * This was built from scratch based upon observation of OpenSSL 0.9.2B
    10     10    *
    11     11    * Addition credit is due for Andreas Kupries ([email protected]), for
................................................................................
   100    100       BIO *bio;		/* Struct for SSL processing */
   101    101       BIO *p_bio;		/* Parent BIO (that is layered on Tcl_Channel) */
   102    102   
   103    103       char *err;
   104    104   } State;
   105    105   
   106    106   /*
   107         - * The following definitions have to be usable for 8.0.x, 8.1.x, 8.2.x,
   108         - * 8.3.[01], 8.3.2 and beyond. The differences between these versions:
          107  + * The following definitions have to be usable for 8.2.0-8.3.1 and 8.3.2+.
          108  + * The differences between these versions:
   109    109    *
   110    110    * 8.0-8.1:	There is no support for these in TLS 1.4 (get 1.3).  This
   111    111    *		was the version with the original patch.
   112    112    *
   113    113    * 8.2.0-	Changed semantics for Tcl_StackChannel (Tcl_ReplaceChannel).
   114    114    * 8.3.1:	Check at runtime to switch the behaviour. The patch is part
   115    115    *		of the core from now on.
   116    116    *
   117    117    * 8.3.2+:	Stacked channels rewritten for better behaviour in some
   118    118    *		situations (closing). Some new API's, semantic changes.
   119    119    *
   120         - * The following magic was taken from Trf 2.1 (Kupries).
          120  + * The following magic was adapted from Trf 2.1 (Kupries).
   121    121    */
   122    122   
   123    123   #define TLS_CHANNEL_VERSION_1	0x1
   124    124   #define TLS_CHANNEL_VERSION_2	0x2
   125    125   extern int channelTypeVersion;
   126    126   
   127    127   #ifdef USE_TCL_STUBS
................................................................................
   160    160   typedef Tcl_Channel (tls_GetStackedChannel) _ANSI_ARGS_((Tcl_Channel chan));
   161    161   
   162    162   #define Tcl_GetStackedChannel ((tls_GetStackedChannel*) tclStubsPtr->reserved283)
   163    163   
   164    164   #endif /* Tcl_GetStackedChannel */
   165    165   
   166    166   
   167         -#ifndef Tcl_WriteRaw
          167  +#ifndef TCL_CHANNEL_VERSION_2
   168    168   /*
   169    169    * Core is older than 8.3.2.  Supply the missing definitions for
   170    170    * the new API's in 8.3.2.
   171    171    */
          172  +#define EMULATE_CHANNEL_VERSION_2
          173  +
          174  +typedef struct TlsChannelTypeVersion_* TlsChannelTypeVersion;
          175  +#define TCL_CHANNEL_VERSION_2	((TlsChannelTypeVersion) 0x2)
   172    176   
          177  +typedef int (TlsDriverHandlerProc) _ANSI_ARGS_((ClientData instanceData,
          178  +					int interestMask));
   173    179   /* 394 */
   174    180   typedef int (tls_ReadRaw)  _ANSI_ARGS_((Tcl_Channel chan, char *dst,
   175    181   					int bytesToRead));
   176    182   /* 395 */
   177    183   typedef int (tls_WriteRaw) _ANSI_ARGS_((Tcl_Channel chan, char *src,
   178    184   					int srcLen));
   179    185   /* 397 */
................................................................................
   193    199   #define IDX(n)      (((n)-370) * procPtrSize)
   194    200   #define SLOT(n)     (STUB_BASE + IDX(n))
   195    201   
   196    202   #define Tcl_ReadRaw		(*((tls_ReadRaw**)	(SLOT(394))))
   197    203   #define Tcl_WriteRaw		(*((tls_WriteRaw**)	(SLOT(395))))
   198    204   #define Tcl_GetTopChannel	(*((tls_GetTopChannel**)(SLOT(396))))
   199    205   
   200         -typedef struct TlsChannelTypeVersion_* TlsChannelTypeVersion;
   201         -#define TCL_CHANNEL_VERSION_2	((TlsChannelTypeVersion) 0x2)
   202         -
   203    206   /*
   204    207    * Required, easy emulation.
   205    208    */
   206    209   #define Tcl_ChannelGetOptionProc(chanDriver) ((chanDriver)->getOptionProc)
   207    210   
   208         -#endif /* Tcl_WriteRaw */
          211  +#endif /* TCL_CHANNEL_VERSION_2 */
   209    212   
   210    213   #endif /* USE_TCL_STUBS */
   211    214   
   212    215   /*
   213    216    * Forward declarations
   214    217    */
   215    218