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