WvStreams
wvsslstream.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * SSL (Socket Security Layer) communications via WvStreams.
6 */
7#ifndef __WVSSLSTREAM_H
8#define __WVSSLSTREAM_H
9
10#include "wvfdstream.h"
11#include "wvlog.h"
12#include "wvstreamclone.h"
13#include "wvtr1.h"
14
15struct ssl_st;
16struct ssl_ctx_st;
17struct ssl_method_st;
18
19typedef struct ssl_ctx_st SSL_CTX;
20typedef struct ssl_st SSL;
21typedef struct ssl_method_st SSL_METHOD;
22
23class WvX509;
24class WvX509Mgr;
25class WvSSLStream;
26
27typedef wv::function<bool(WvX509*)> WvSSLValidateCallback;
28typedef wv::function<bool(WvX509*, WvSSLStream *)> WvSSLGlobalValidateCallback;
29
36{
37public:
38 /* This ValidateCallback is purely more convenient to set (not passed in
39 * via constructor) than its local cousin. It is used when you want an
40 * easy way to assign a validation function to any WvSSLStream you might
41 * be using. NOTE: It should be assigned before you instantiate a stream,
42 * and should never be changed while WvSSLStreams still linger.
43 *
44 * NOTE: Using wv::bind can effectively bind an object with a particular
45 * function for this callback, so you can do all sorts of interesting stuff
46 * with it.
47 */
48 static WvSSLGlobalValidateCallback global_vcb;
54 WvSSLStream(IWvStream *_slave, WvX509Mgr *_x509 = NULL,
55 WvSSLValidateCallback _vcb = 0, bool _is_server = false);
56
58 virtual ~WvSSLStream();
59
60 virtual void pre_select(SelectInfo &si);
61 virtual bool post_select(SelectInfo &si);
62
63 virtual void close();
64 virtual bool isok() const;
65 virtual void noread();
66 virtual void nowrite();
67
68protected:
69 WvX509Mgr *x509;
70
72 SSL_CTX *ctx;
73
78 SSL *ssl;
79
80 virtual size_t uwrite(const void *buf, size_t len);
81 virtual size_t uread(void *buf, size_t len);
82
83private:
88 bool sslconnected;
89 SelectRequest connect_wants;
90
92 void setconnected(bool conn);
93
95 bool is_server;
96
98 bool ssl_stop_read, ssl_stop_write;
99
101 WvSSLValidateCallback vcb;
102
104 WvLog debug;
105
114 WvInPlaceBuf write_bouncebuf;
115 size_t write_eat;
116
118 WvInPlaceBuf read_bouncebuf;
119 bool read_pending;
120
122 WvDynBuf unconnected_buf;
123
125 void printerr(WvStringParm func);
126
127public:
128 const char *wstype() const { return "WvSSLStream"; }
129};
130
131#endif // __WVSSLSTREAM_H
132
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
Definition wvstring.h:94
The in place raw memory buffer type.
Definition wvbuf.h:165
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition wvlog.h:57
SSL Stream, handles SSLv2, SSLv3, and TLS Methods - If you want it to be a server,...
Definition wvsslstream.h:36
virtual void close()
Close this stream.
SSL_CTX * ctx
SSL Context - used to create SSL Object.
Definition wvsslstream.h:72
virtual bool isok() const
return true if the stream is actually usable right now
virtual size_t uwrite(const void *buf, size_t len)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
virtual ~WvSSLStream()
Cleans up everything (calls close + frees up the SSL Objects used)
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling select().
virtual void nowrite()
Shuts down the writing side of the stream.
SSL * ssl
Main SSL Object - after SSL_set_fd() we make all calls through the connection through here.
Definition wvsslstream.h:78
virtual size_t uread(void *buf, size_t len)
unbuffered I/O functions; these ignore the buffer, which is handled by read().
virtual void noread()
Shuts down the reading side of the stream.
virtual bool post_select(SelectInfo &si)
post_select() is called after select(), and returns true if this object is now ready.
WvStreamClone simply forwards all requests to the "cloned" stream.
X509 Class to handle certificates and their related functions.
Definition wvx509.h:42
the data structure used by pre_select()/post_select() and internally by select().
Definition iwvstream.h:50
A SelectRequest is a convenient way to remember what we want to do to a particular stream: read from ...
Definition iwvstream.h:34