Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

wvsslstream.h

Go to the documentation of this file.
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * SSL (Socket Security Layer) communications via WvStreams.
00006  */ 
00007 #ifndef __WVSSLSTREAM_H
00008 #define __WVSSLSTREAM_H
00009 
00010 #include "wvstreamclone.h"
00011 #include "wvfdstream.h"
00012 #include "wvlog.h"
00013  
00014 struct ssl_st;
00015 struct ssl_ctx_st;
00016 struct ssl_method_st;
00017 
00018 typedef struct ssl_ctx_st SSL_CTX;
00019 typedef struct ssl_st SSL;
00020 typedef struct ssl_method_st SSL_METHOD;
00021 
00022 class WvX509Mgr;
00023 
00024 /**
00025  * SSL Stream, handles SSLv2, SSLv3, and TLS
00026  * Methods - If you want it to be a server, then you must feed the constructor
00027  * a WvX509Mgr object
00028  */
00029 class WvSSLStream : public WvStreamClone
00030 {
00031 public:
00032     /**  
00033      * Start an SSL connection on the stream _slave.  The x509 structure
00034      * is optional for a client, and mandatory for a server.
00035      */
00036     WvSSLStream(IWvStream *_slave, WvX509Mgr *x509 = NULL, 
00037                 bool _verify = false, bool _is_server = false);
00038     
00039     /** Cleans up everything (calls close + frees up the SSL Objects used) */
00040     virtual ~WvSSLStream();
00041     
00042     virtual bool pre_select(SelectInfo &si);
00043     virtual bool post_select(SelectInfo &si);
00044     
00045     virtual void close();
00046     
00047     virtual bool isok() const;
00048     
00049 protected:
00050     /** SSL Context - used to create SSL Object */
00051     SSL_CTX *ctx;
00052     
00053     /**
00054      * Main SSL Object - after SSL_set_fd() we make all calls through the connection
00055      * through here
00056      */
00057     SSL *ssl;
00058     
00059     /**
00060      * Again, used to setup the SSL Object - The Method is set so that this client can
00061      * Connect to, and understand SSLv2, SSLv3, and TLS servers
00062      */
00063     SSL_METHOD *meth;
00064     
00065     /**
00066      * Overrides the standard write function, and use
00067      * SSL_write() instead...
00068      */
00069     virtual size_t uwrite(const void *buf, size_t len);
00070     
00071     /**
00072      * Overrides for the standard read function, so that SSL_read() will
00073      * get called...
00074      */
00075     virtual size_t uread(void *buf, size_t len);
00076     
00077 private:
00078     /**
00079      * Connection Status Flag, since SSL takes a few seconds to
00080      * initialize itself.
00081      */
00082     volatile bool sslconnected;
00083 
00084     /** Set the connected flag and flush the unconnected_buf */
00085     void setconnected(bool conn);
00086     
00087     /** Keep track of whether we are a client or a server */
00088     bool is_server;
00089     
00090     /** Keep track of whether we want to check the peer who connects to us */
00091     bool verify;
00092     
00093     /** Internal Log Object */
00094     WvLog debug;
00095 
00096     /**
00097      * SSL_write() may return an SSL_ERROR_WANT_WRITE code which
00098      * indicates that the function should be called again with
00099      * precisely the same arguments as the last time.  To ensure that
00100      * this can happen, we must unfortunately copy data into a bounce
00101      * buffer and remeber the fact.  We use a WvBuf here to allow
00102      * an arbitrary amount of data to be set aside.
00103      */
00104     WvInPlaceBuf write_bouncebuf;
00105     size_t write_eat;
00106 
00107     /** Similar nastiness happens with SSL_read() */
00108     WvInPlaceBuf read_bouncebuf;
00109     bool read_pending;
00110 
00111     /** Need to buffer writes until sslconnected */
00112     WvDynBuf unconnected_buf;
00113 
00114     /** Prints out the entire SSL error queue */
00115     void printerr(WvStringParm func);
00116 };
00117 
00118 #endif // __WVSSLSTREAM_H
00119 

Generated on Sat Feb 21 21:05:32 2004 for WvStreams by doxygen 1.3.5