~ubuntu-branches/ubuntu/hoary/tcltls/hoary

« back to all changes in this revision

Viewing changes to tlsInt.h

  • Committer: Bazaar Package Importer
  • Author(s): Søren Boll Overgaard
  • Date: 2004-06-16 19:22:30 UTC
  • Revision ID: james.westby@ubuntu.com-20040616192230-tv159811lsnerauf
Tags: upstream-1.5.0
Import upstream version 1.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 1997-2000 Matt Newman <matt@novadigm.com>
 
3
 *
 
4
 * $Header: /cvsroot/tls/tls/tlsInt.h,v 1.11 2004/02/04 04:02:19 razzell Exp $
 
5
 *
 
6
 * TLS (aka SSL) Channel - can be layered on any bi-directional
 
7
 * Tcl_Channel (Note: Requires Trf Core Patch)
 
8
 *
 
9
 * This was built from scratch based upon observation of OpenSSL 0.9.2B
 
10
 *
 
11
 * Addition credit is due for Andreas Kupries (a.kupries@westend.com), for
 
12
 * providing the Tcl_ReplaceChannel mechanism and working closely with me
 
13
 * to enhance it to support full fileevent semantics.
 
14
 *
 
15
 * Also work done by the follow people provided the impetus to do this "right":-
 
16
 *      tclSSL (Colin McCormack, Shared Technology)
 
17
 *      SSLtcl (Peter Antman)
 
18
 *
 
19
 */
 
20
#ifndef _TSLINT_H
 
21
#define _TLSINT_H
 
22
 
 
23
#include "tls.h"
 
24
#include <errno.h>
 
25
#include <string.h>
 
26
 
 
27
#ifdef NO_PATENTS
 
28
#define NO_IDEA
 
29
#define NO_RC2
 
30
#define NO_RC4
 
31
#define NO_RC5
 
32
#define NO_RSA
 
33
#define NO_SSL2
 
34
#endif
 
35
 
 
36
#ifdef BSAFE
 
37
#include <ssl.h>
 
38
#include <err.h>
 
39
#include <rand.h>
 
40
#else
 
41
#include <openssl/ssl.h>
 
42
#include <openssl/err.h>
 
43
#include <openssl/rand.h>
 
44
#endif
 
45
 
 
46
#ifdef TCL_STORAGE_CLASS
 
47
# undef TCL_STORAGE_CLASS
 
48
#endif
 
49
#ifdef BUILD_tls
 
50
# define TCL_STORAGE_CLASS DLLEXPORT
 
51
#else
 
52
# define TCL_STORAGE_CLASS DLLIMPORT
 
53
#endif
 
54
 
 
55
#ifndef ECONNABORTED
 
56
#define ECONNABORTED    130     /* Software caused connection abort */
 
57
#endif
 
58
#ifndef ECONNRESET
 
59
#define ECONNRESET      131     /* Connection reset by peer */
 
60
#endif
 
61
 
 
62
#ifdef DEBUG
 
63
#define dprintf fprintf
 
64
#else
 
65
#define dprintf if (0) fprintf
 
66
#endif
 
67
 
 
68
#define SSL_ERROR(ssl,err)      \
 
69
            ((char*)ERR_reason_error_string(SSL_get_error((ssl),(err))))
 
70
/*
 
71
 * OpenSSL BIO Routines
 
72
 */
 
73
#define BIO_TYPE_TCL    (19|0x0400)
 
74
 
 
75
/*
 
76
 * Defines for State.flags
 
77
 */
 
78
#define TLS_TCL_ASYNC   (1<<0)  /* non-blocking mode */
 
79
#define TLS_TCL_SERVER  (1<<1)  /* Server-Side */
 
80
#define TLS_TCL_INIT    (1<<2)  /* Initializing connection */
 
81
#define TLS_TCL_DEBUG   (1<<3)  /* Show debug tracing */
 
82
 
 
83
#define TLS_TCL_DELAY (5)
 
84
 
 
85
/*
 
86
 * This structure describes the per-instance state
 
87
 * of an ssl channel.
 
88
 *
 
89
 * The SSL processing context is maintained here, in the ClientData
 
90
 */
 
91
typedef struct State {
 
92
    Tcl_Channel self;   /* this socket channel */
 
93
    Tcl_TimerToken timer;
 
94
 
 
95
    int flags;          /* currently only CHANNEL_ASYNC */
 
96
    int watchMask;      /* current WatchProc mask */
 
97
    int mode;           /* current mode of parent channel */
 
98
 
 
99
    Tcl_Interp *interp; /* interpreter in which this resides */
 
100
    Tcl_Obj *callback;  /* script called for tracing, verifying and errors */
 
101
    Tcl_Obj *password;  /* script called for certificate password */ 
 
102
 
 
103
    int vflags;         /* verify flags */
 
104
    SSL *ssl;           /* Struct for SSL processing */
 
105
    SSL_CTX *ctx;       /* SSL Context */
 
106
    BIO *bio;           /* Struct for SSL processing */
 
107
    BIO *p_bio;         /* Parent BIO (that is layered on Tcl_Channel) */
 
108
 
 
109
    char *err;
 
110
} State;
 
111
 
 
112
/*
 
113
 * The following definitions have to be usable for 8.2.0-8.3.1 and 8.3.2+.
 
114
 * The differences between these versions:
 
115
 *
 
116
 * 8.0-8.1:     There is no support for these in TLS 1.4 (get 1.3).  This
 
117
 *              was the version with the original patch.
 
118
 *
 
119
 * 8.2.0-       Changed semantics for Tcl_StackChannel (Tcl_ReplaceChannel).
 
120
 * 8.3.1:       Check at runtime to switch the behaviour. The patch is part
 
121
 *              of the core from now on.
 
122
 *
 
123
 * 8.3.2+:      Stacked channels rewritten for better behaviour in some
 
124
 *              situations (closing). Some new API's, semantic changes.
 
125
 *
 
126
 * The following magic was adapted from Trf 2.1 (Kupries).
 
127
 */
 
128
 
 
129
#define TLS_CHANNEL_VERSION_1   0x1
 
130
#define TLS_CHANNEL_VERSION_2   0x2
 
131
extern int channelTypeVersion;
 
132
 
 
133
#ifdef USE_TCL_STUBS
 
134
#ifndef Tcl_StackChannel
 
135
/*
 
136
 * The core we are compiling against is not patched, so supply the
 
137
 * necesssary definitions here by ourselves. The form chosen for
 
138
 * the procedure macros (reservedXXX) will notify us if the core
 
139
 * does not have these reserved locations anymore.
 
140
 *
 
141
 * !! Synchronize the procedure indices in their definitions with
 
142
 *    the patch to tcl.decls, as they have to be the same.
 
143
 */
 
144
 
 
145
/* 281 */
 
146
typedef Tcl_Channel (tls_StackChannel) _ANSI_ARGS_((Tcl_Interp* interp,
 
147
                                                    Tcl_ChannelType* typePtr,
 
148
                                                    ClientData instanceData,
 
149
                                                    int mask,
 
150
                                                    Tcl_Channel prevChan));
 
151
/* 282 */
 
152
typedef void (tls_UnstackChannel) _ANSI_ARGS_((Tcl_Interp* interp,
 
153
                                               Tcl_Channel chan));
 
154
 
 
155
#define Tcl_StackChannel     ((tls_StackChannel*) tclStubsPtr->reserved281)
 
156
#define Tcl_UnstackChannel ((tls_UnstackChannel*) tclStubsPtr->reserved282)
 
157
 
 
158
#endif /* Tcl_StackChannel */
 
159
 
 
160
#ifndef Tcl_GetStackedChannel
 
161
/*
 
162
 * Separate definition, available in 8.2, but not 8.1 and before !
 
163
 */
 
164
 
 
165
/* 283 */
 
166
typedef Tcl_Channel (tls_GetStackedChannel) _ANSI_ARGS_((Tcl_Channel chan));
 
167
 
 
168
#define Tcl_GetStackedChannel ((tls_GetStackedChannel*) tclStubsPtr->reserved283)
 
169
 
 
170
#endif /* Tcl_GetStackedChannel */
 
171
 
 
172
 
 
173
#ifndef TCL_CHANNEL_VERSION_2
 
174
/*
 
175
 * Core is older than 8.3.2.  Supply the missing definitions for
 
176
 * the new API's in 8.3.2.
 
177
 */
 
178
#define EMULATE_CHANNEL_VERSION_2
 
179
 
 
180
typedef struct TlsChannelTypeVersion_* TlsChannelTypeVersion;
 
181
#define TCL_CHANNEL_VERSION_2   ((TlsChannelTypeVersion) 0x2)
 
182
 
 
183
typedef int (TlsDriverHandlerProc) _ANSI_ARGS_((ClientData instanceData,
 
184
                                        int interestMask));
 
185
/* 394 */
 
186
typedef int (tls_ReadRaw)  _ANSI_ARGS_((Tcl_Channel chan, char *dst,
 
187
                                        int bytesToRead));
 
188
/* 395 */
 
189
typedef int (tls_WriteRaw) _ANSI_ARGS_((Tcl_Channel chan, char *src,
 
190
                                        int srcLen));
 
191
/* 397 */
 
192
typedef int (tls_GetTopChannel) _ANSI_ARGS_((Tcl_Channel chan));
 
193
 
 
194
/*
 
195
 * Generating code for accessing these parts of the stub table when
 
196
 * compiling against a core older than 8.3.2 is a hassle because even
 
197
 * the 'reservedXXX' fields of the structure are not defined yet. So
 
198
 * we have to write up some macros hiding some very hackish pointer
 
199
 * arithmetics to get at these fields. We assume that pointer to
 
200
 * functions are always of the same size.
 
201
 */
 
202
 
 
203
#define STUB_BASE   ((char*)(&(tclStubsPtr->tcl_UtfNcasecmp))) /* field 370 */
 
204
#define procPtrSize (sizeof (Tcl_DriverBlockModeProc *))
 
205
#define IDX(n)      (((n)-370) * procPtrSize)
 
206
#define SLOT(n)     (STUB_BASE + IDX(n))
 
207
 
 
208
#define Tcl_ReadRaw             (*((tls_ReadRaw**)      (SLOT(394))))
 
209
#define Tcl_WriteRaw            (*((tls_WriteRaw**)     (SLOT(395))))
 
210
#define Tcl_GetTopChannel       (*((tls_GetTopChannel**)(SLOT(396))))
 
211
 
 
212
/*
 
213
 * Required, easy emulation.
 
214
 */
 
215
#define Tcl_ChannelGetOptionProc(chanDriver) ((chanDriver)->getOptionProc)
 
216
 
 
217
#endif /* TCL_CHANNEL_VERSION_2 */
 
218
 
 
219
#endif /* USE_TCL_STUBS */
 
220
 
 
221
/*
 
222
 * Forward declarations
 
223
 */
 
224
 
 
225
EXTERN Tcl_ChannelType *Tls_ChannelType _ANSI_ARGS_((void));
 
226
EXTERN Tcl_Channel      Tls_GetParent _ANSI_ARGS_((State *statePtr));
 
227
 
 
228
EXTERN Tcl_Obj*         Tls_NewX509Obj _ANSI_ARGS_ (( Tcl_Interp *interp, X509 *cert));
 
229
EXTERN void             Tls_Error _ANSI_ARGS_ ((State *statePtr, char *msg));
 
230
EXTERN void             Tls_Free _ANSI_ARGS_ ((char *blockPtr));
 
231
EXTERN void             Tls_Clean _ANSI_ARGS_ ((State *statePtr));
 
232
EXTERN int              Tls_WaitForConnect _ANSI_ARGS_(( State *statePtr,
 
233
                                                        int *errorCodePtr));
 
234
 
 
235
EXTERN BIO_METHOD *     BIO_s_tcl _ANSI_ARGS_((void));
 
236
EXTERN BIO *            BIO_new_tcl _ANSI_ARGS_((State* statePtr, int flags));
 
237
 
 
238
#endif /* _TLSINT_H */