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 
15 struct ssl_st;
16 struct ssl_ctx_st;
17 struct ssl_method_st;
18 
19 typedef struct ssl_ctx_st SSL_CTX;
20 typedef struct ssl_st SSL;
21 typedef struct ssl_method_st SSL_METHOD;
22 
23 class WvX509;
24 class WvX509Mgr;
25 class WvSSLStream;
26 
27 typedef wv::function<bool(WvX509*)> WvSSLValidateCallback;
28 typedef wv::function<bool(WvX509*, WvSSLStream *)> WvSSLGlobalValidateCallback;
29 
35 class WvSSLStream : public WvStreamClone
36 {
37 public:
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 
68 protected:
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 
83 private:
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 
127 public:
128  const char *wstype() const { return "WvSSLStream"; }
129 };
130 
131 #endif // __WVSSLSTREAM_H
132 
WvSSLStream::uwrite
virtual size_t uwrite(const void *buf, size_t len)
unbuffered I/O functions; these ignore the buffer, which is handled by write().
Definition: wvsslstream.cc:430
WvSSLStream::pre_select
virtual void pre_select(SelectInfo &si)
pre_select() sets up for eventually calling ::select().
Definition: wvsslstream.cc:611
WvX509
X509 Class to handle certificates and their related functions.
Definition: wvx509.h:41
WvSSLStream
SSL Stream, handles SSLv2, SSLv3, and TLS Methods - If you want it to be a server,...
Definition: wvsslstream.h:35
IWvStream
Definition: iwvstream.h:24
WvSSLStream::WvSSLStream
WvSSLStream(IWvStream *_slave, WvX509Mgr *_x509=NULL, WvSSLValidateCallback _vcb=0, bool _is_server=false)
Start an SSL connection on the stream _slave.
Definition: wvsslstream.cc:169
WvInPlaceBuf
The in place raw memory buffer type.
Definition: wvbuf.h:164
WvLog
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:56
IWvStream::SelectInfo
the data structure used by pre_select()/post_select() and internally by select().
Definition: iwvstream.h:50
WvSSLStream::nowrite
virtual void nowrite()
Shuts down the writing side of the stream.
Definition: wvsslstream.cc:599
WvStreamClone
WvStreamClone simply forwards all requests to the "cloned" stream.
Definition: wvstreamclone.h:23
WvSSLStream::uread
virtual size_t uread(void *buf, size_t len)
unbuffered I/O functions; these ignore the buffer, which is handled by read().
Definition: wvsslstream.cc:310
WvX509Mgr
Definition: wvx509mgr.h:14
WvDynBufBase< unsigned char >
WvSSLStream::post_select
virtual bool post_select(SelectInfo &si)
post_select() is called after ::select(), and returns true if this object is now ready.
Definition: wvsslstream.cc:638
WvSSLStream::noread
virtual void noread()
Shuts down the reading side of the stream.
Definition: wvsslstream.cc:583
WvSSLStream::ctx
SSL_CTX * ctx
SSL Context - used to create SSL Object.
Definition: wvsslstream.h:72
WvSSLStream::isok
virtual bool isok() const
return true if the stream is actually usable right now
Definition: wvsslstream.cc:577
WvSSLStream::close
virtual void close()
Close this stream.
Definition: wvsslstream.cc:553
WvSSLStream::~WvSSLStream
virtual ~WvSSLStream()
Cleans up everything (calls close + frees up the SSL Objects used)
Definition: wvsslstream.cc:283
WvSSLStream::ssl
SSL * ssl
Main SSL Object - after SSL_set_fd() we make all calls through the connection through here.
Definition: wvsslstream.h:78