Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

SSLSocket.h

Go to the documentation of this file.
00001 /* ====================================================================
00002  *              The CBITS Software License, Version 1.0
00003  *
00004  *               Copyright (c) 2002-2003 Bruce Lowery
00005  *                       All rights reserved
00006  *
00007  * Redistribution and use of this software, in source and binary forms, 
00008  * with or without modification, are permitted provided that the above 
00009  * copyright notice, this paragraph, and the following paragraph are 
00010  * retained in each source code file.
00011  *
00012  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00013  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00014  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00015  * DISCLAIMED.  IN NO EVENT SHALL BRUCE LOWERY OR OTHER CONTRIBUTORS 
00016  * TO THE CBITS LIBRARY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00017  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00018  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00019  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00020  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00021  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00022  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00023  * SUCH DAMAGE.
00024  * ====================================================================
00025  */
00026 #ifndef __SSLSOCKET_H__
00027 #define __SSLSOCKET_H__
00028 
00052 // CBits Socket
00053 #include <cbits/Socket.h>
00054 #include <cbits/SSLContext.h>
00055 #include <cbits/SocketException.h>
00056 #include <cbits/SocketException.h>
00057 
00058 // OpenSSL
00059 #include <openssl/bio.h>
00060 #include <openssl/err.h>
00061 #include <openssl/rand.h>
00062 #include <openssl/ssl.h>
00063 
00064 
00065 namespace cbits {
00066 
00067 class SSLPeer;
00068 
00101 class EXPORT SSLSocket : public virtual Socket
00102 {
00103 
00104 public:
00105 
00114     SSLSocket
00115     ( 
00116         const std::string& host, 
00118         const int port,          
00120         SSLContext* const ctxt=0, 
00126         const bool now=true      
00127     )
00128         throw( SocketException );
00129 
00130 
00139     SSLSocket
00140     ( 
00141         const char *host,         
00143         const int port,           
00145         SSLContext* const ctxt=0, 
00151         const bool now=true       
00152     )
00153         throw( SocketException );
00154 
00155 
00162     virtual ~SSLSocket();
00163 
00164 
00165     virtual void  connect()  throw(SocketException);
00166 
00167     virtual const ssize_t read
00168     ( 
00169         char * const buffer,
00170         const int buflen, 
00171         int * const error=0, 
00172         const long int msec=0 
00173     )
00174         throw( SocketException );
00175 
00176 
00177     virtual const ssize_t receive
00178     ( 
00179         char * const buffer, 
00180         const int buflen, 
00181         const long int msec=0, 
00182         int * const error=0
00183     )
00184         throw( SocketException );
00185 
00186 
00187     virtual const ssize_t readLine
00188     (
00189         std::string& buffer, 
00190         const std::string& delim, 
00191         int * const error=0, 
00192         const long int msec=0 
00193     )
00194             throw( SocketException );
00195 
00196 
00197     virtual  const  ssize_t  write
00198     (
00199         const char * buffer, 
00200         const long buflen,
00201         int * const error=0, 
00202         const long int msec=0 
00203     )
00204         throw( SocketException );
00205 
00206 
00207     virtual  const  ssize_t  send
00208     (
00209         const char * buffer, 
00210         const long buflen,
00211         int * const error=0, 
00212         const long int msec=0 
00213     )
00214         throw( SocketException );
00215 
00216 
00227     static SSLSocket* create
00228     (
00229         const socket_t fd,        
00230         SSLContext* const ctxt=0  
00235     )
00236         throw( SocketException );
00237 
00238 
00249     static void setGlobalContext
00250     (
00251         SSLContext* gctx  
00252     )
00253         throw( SSLContextException );
00254 
00255 
00256 
00263     const SSLPeer& getPeer() const
00264         throw( SocketException );
00265 
00266 
00273     typedef SSL* SSL_PTR;
00274 
00275 
00282     inline operator SSL_PTR() { return _ssl; }
00283 
00284 
00285 protected:
00286 
00291     SSLSocket
00292     ( 
00293         const socket_t fd,        
00294         SSLContext* const ctxt=0  
00299     )
00300         throw( SocketException );
00301 
00305     // FIXME SSLSocket.h remove unused get_bio() declaration
00306     // BIO* get_bio();
00307 
00308 
00314     bool _ssl_is_connected;
00315 
00316 
00317 private:
00318 
00323     void set_bio
00324     ( 
00325         const socket_t fd  
00326     )
00327         throw( SocketException );
00328 
00335     BIO*        _bio;
00336 
00337 
00341     SSLContext* _ctxt;
00342 
00343 
00347     SSL*        _ssl;
00348 
00349 
00353     SSLPeer*    _peer;
00354 
00355 
00360     mutable CriticalSection _csect;
00361 
00362 
00368     mutable CriticalSection _read_csect;
00369 
00370 
00376     mutable CriticalSection _write_csect;
00377 
00378 
00382     static SSLContext* _global_ctxt;
00383 };
00384 
00385 // TO DO:
00386 // 1.  Certificate Revocation List handling
00387 // 2.  Post Connection Assertions
00388 // 3.  x
00389 };
00390 #endif
00391 
00392 
00393 /*
00394  * $Id: SSLSocket.h,v 1.5 2002/10/16 22:32:44 brulow Exp $
00395  * 
00396  * History: (Add nothing manually below)
00397  * -----------------------------------------------------------------------
00398  *
00399  * $Log: SSLSocket.h,v $
00400  * Revision 1.5  2002/10/16 22:32:44  brulow
00401  * Improve doc, misc
00402  *
00403  * Revision 1.4  2002/10/10 01:16:22  brulow
00404  * Improve documentation
00405  *
00406  * Revision 1.3  2002/10/09 22:43:03  brulow
00407  * Improve documentation
00408  *
00409  * Revision 1.2  2002/09/27 22:04:16  brulow
00410  * Add history footer to all .h .cpp files
00411  *
00412  *
00413  */

Generated by
doxygen
Hosted by
SourceForge