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

SSLSocket.h

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: SSLSocket.h,v 1.3 2004/05/19 15:56:57 mmarsh Exp $
00008 //
00009 // $Log: SSLSocket.h,v $
00010 // Revision 1.3  2004/05/19 15:56:57  mmarsh
00011 // *** empty log message ***
00012 //
00013 // Revision 1.2  2003/11/04 22:20:38  mmarsh
00014 // General code cleanup, including the addition of a few new exception
00015 // classes.
00016 //
00017 //
00018 
00019 #ifndef __CODEX_SSL_SSLSOCKET_H__
00020 #define __CODEX_SSL_SSLSOCKET_H__
00021 
00022 #include <openssl/ssl.h>
00023 
00024 #include "CODEX_Quorum/Socket.h"
00025 #include "CODEX_Quorum/SocketBuilder.h"
00026 
00033 namespace CODEX_SSL
00034 {
00042    class SSLSocket : public CODEX_Quorum::SocketBase
00043    {
00044       public :
00058          SSLSocket( SSL_CTX*  ctx              ,
00059                     int       domain=PF_INET   ,
00060                     int       type=SOCK_STREAM ,
00061                     int       protocol=0       ,
00062                     bool      blocking=false   );
00064          SSLSocket(const SSLSocket& aOther);
00066          virtual ~SSLSocket();
00067 
00085          int set_fd( fd_set* fd_bitmap, StateType s ) const;
00086 
00107          bool isset_fd( const fd_set* fd_bitmap, StateType s ) const;
00108 
00113          size_t readFrom( void* output, size_t maxSize=1024 ) const;
00114 
00115       protected :
00116          CODEX_Quorum::SocketBase* clone();
00117 
00122          void connect( const CODEX_Quorum::RemoteServer& server );
00123 
00128          void finish_accept();
00129 
00134          int internal_write( const unsigned char* output,
00135                              size_t maxSize ) const;
00136 
00137       private :
00138          SSL_CTX*      m_ctx;
00139          SSL*          m_ssl_con;
00140          mutable bool  m_needRead;
00141          mutable bool  m_needWrite;
00142    };
00143 
00147    class SSLSocketBuilder : public CODEX_Quorum::SocketBuilder
00148    {
00149       public :
00164          SSLSocketBuilder( SSL_METHOD*  meth,
00165                            const X509*  cert,
00166                            const RSA*   privKey,
00167                            const char*  ciphers,
00168                            const char*  caCertFile,
00169                            const char*  hostCertFile,
00170                            int          verify,
00171                            int          domain=PF_INET   ,
00172                            int          type=SOCK_STREAM ,
00173                            int          protocol=0       ,
00174                            bool         blocking=false   );
00175 
00177          virtual ~SSLSocketBuilder();
00178 
00179          CODEX_Quorum::SocketBase* operator()() const;
00180 
00181       protected :
00183          SSL_CTX*  m_ctx;
00184    };
00185 
00186 
00187    //------ Exceptions ------//
00188 
00192    class QSESSLSocket : public CODEX_Quorum::QSESocketBase
00193    {
00194       public :
00196          QSESSLSocket( const string& fname, int line, int error ) :
00197             CODEX_Quorum::QSESocketBase( fname, line, error )
00198          {}
00199 
00200       protected :
00201          void errMsg() const;
00202    };
00203 
00207    class SSLExceptionBase : public CODEX_Exceptions::ExceptionBase
00208    {
00209       public :
00211          SSLExceptionBase( const string& fname, int line ) :
00212             CODEX_Exceptions::ExceptionBase( fname, line )
00213          {}
00214 
00215          void report() const;
00216 
00217       protected :
00222          virtual void derivedMsg() const = 0;
00223    };
00224 
00228    class SSLNullContextException : public SSLExceptionBase
00229    {
00230       public :
00232          SSLNullContextException( const string& fname, int line ) :
00233             SSLExceptionBase( fname, line )
00234          {}
00235 
00236       protected :
00237          void derivedMsg() const;
00238    };
00239 
00243    class SSLNullCiphersException : public SSLExceptionBase
00244    {
00245       public :
00247          SSLNullCiphersException( const string& fname, int line ) :
00248             SSLExceptionBase( fname, line )
00249          {}
00250 
00251       protected :
00252          void derivedMsg() const;
00253    };
00254 
00258    class SSLVerificationFlagsException : public SSLExceptionBase
00259    {
00260       public :
00262          SSLVerificationFlagsException( const string& fname, int line ) :
00263             SSLExceptionBase( fname, line )
00264          {}
00265 
00266       protected :
00267          void derivedMsg() const;
00268    };
00269 
00270 }
00271 
00272 #endif /* __CODEX_SSL_SSLSOCKET_H__ */

Generated on Fri May 6 17:41:16 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1