ssl_connection.h

Go to the documentation of this file.
00001 /***************************************************************************
00002        ssl_connection.h  -  ssl connection with certificate support
00003                              -------------------
00004     begin                : Sun May 29 2005
00005     copyright            : (C) 2005 Dmitry Nizovtsev <funt@alarit.com>
00006                                     Olexander Shtepa <isk@alarit.com>
00007 
00008     $Id: ssl_connection.h 945 2007-01-03 13:05:48Z ewald-arnold $
00009 
00010  ***************************************************************************/
00011 
00012 /**************************************************************************
00013  *
00014  * This program is free software; you can redistribute it and/or modify
00015  * it under the terms of the GNU Lesser General Public License as
00016  * published by the Free Software Foundation; either version 2 of the License,
00017  * or (at your option) any later version.
00018  *
00019  * This program is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License
00025  * along with this program; if not, write to the Free Software
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00027  *
00028  ***************************************************************************/
00029 
00030 #ifndef FUNTIK_SSL_CONNECTION_H
00031 #define FUNTIK_SSL_CONNECTION_H
00032 
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>  // always first header
00034 
00035 #ifdef ULXR_INCLUDE_SSL_STUFF
00036 
00037 #include <ulxmlrpcpp/ulxr_value.h>
00038 #include <ulxmlrpcpp/ulxr_tcpip_connection.h>
00039 #include <ulxmlrpcpp/ulxr_except.h>
00040 
00041 #include <openssl/ssl.h>
00042 
00043 //STL
00044 #include <string>
00045 
00046 
00047 #define     FINGERPRINT_MAX_LEN 1024
00048 
00049 namespace funtik {
00050 
00051 class ULXR_API_DECL0 SSLConnectionException : public ulxr::ConnectionException
00052 {
00053 public:
00054 
00055     SSLConnectionException();
00056     SSLConnectionException(ulxr::CppString strPhrase,int stat);
00057     SSLConnectionException(SSL *ssl, int ret_code);
00058     virtual ~SSLConnectionException() throw() { };
00059 
00060 
00064     virtual ulxr::CppString why() const;
00065 
00066 
00067 
00071     virtual const char *what() const throw();
00072 protected:
00073     std::string _what;
00074 
00075     std::string get_error_queue();
00076 };
00077 
00078 
00088 class ULXR_API_DECL0 SSLConnection : public ulxr::TcpIpConnection
00089 {
00090  public:
00091 
00099    SSLConnection(bool server, const ulxr::CppString &domain, unsigned port = 80);
00100 
00108   SSLConnection(bool server, long adr = INADDR_ANY, unsigned port = 0);
00109 
00110 
00111   // Specifies a pathname for the file containing the trusted certificates,
00112   // which are stored sequentially in PEM format. In most applications,
00113   // the client uses this function to authenticate the server. If client authentication is desired,
00114   // the server also calls this function to authenticate the client.
00115 
00116 
00120    virtual ~SSLConnection ();
00121 
00124    virtual void close();
00125 
00130    virtual ulxr::Connection *detach();
00131 
00134    virtual void open();
00135 
00139    virtual void accept();
00140 
00144    virtual ulxr::CppString getInterfaceName();
00145 
00150    virtual void cut();
00151 
00152 
00158    void setCryptographyData (const std::string &password,
00159                              const std::string &certfile,
00160                              const std::string &keyfile);
00161 
00166     void setPassword(const std::string &strPassword);
00167 
00175     std::string getPassword() const;
00176 
00185     void setCertFile(const std::string &strCertFile);
00186 
00194     std::string getCertFileName() const;
00195 
00196     void setKeyFile(const std::string &strCertFileName);
00197 
00198 
00206     std::string getKeyFileName() const;
00207 
00208 
00214     void setCAFile(const std::string &strCAFile);
00215 
00229     void enableAuth(int iType);
00230 
00238     void disableAuth(int iType=0);
00239 
00240 
00241     enum AuthType{
00242         CA_AUTH=1,
00243         FINGERPRINT_AUTH=2,
00244         MANDATORY_CLIENTCERT=4,
00245         CHECK_REVOCATIONCERT=8
00246     };
00247 
00254     void addFingerprintData(const std::string  &strFingerprint);
00255 
00260     void resetFingerprintData();
00261 
00267     void addRevocationData(const std::string &strRevocation);
00268 
00273     void resetRevocationData();
00274 
00281     bool checkFingerprint(std::string strFingerprint) const;
00282 
00283 
00290     bool checkRevocationFingerprint(std::string strFingerprint) const;
00291 
00296   std::string calculateFingerprint(X509 * poCertificate) const;
00297 
00298  protected:
00299 
00304     int         m_iAuthType;
00305     std::string m_strCAFileName;
00306 
00307     std::map<std::string,int>   m_mapFingerpintData;
00308     std::map<std::string,int>   m_mapRevocationData;
00309 
00310     std::string m_strPassword;
00311     std::string m_strKeyFileName;
00312     std::string m_strCertFileName;
00313 
00314 
00321     bool checkAccess(X509 * poCertificate);
00322 
00323 
00324 
00332     void activateAuth();
00333 
00334 
00339    SSL *getSslObject() const;
00340 
00341 
00346    SSL_CTX *getSslContextObject() const;
00347 
00352    SSL_SESSION *getSslSessionObject() const;
00353 
00358    virtual bool hasPendingInput() const;
00359 
00360    SSL          *ssl;
00361    SSL_CTX      *ssl_ctx;
00362    SSL_SESSION  *session;
00363 
00364    static bool ssl_initialized;
00365 
00368    void createSSL();
00369 
00372    void initializeCTX();
00373 
00380    ssize_t virtual low_level_write(char const *buff, long len);
00381 
00388    ssize_t virtual low_level_read(char *buff, long len);
00389 
00393    void init();
00394 };
00395 
00396 
00397 } // namespace funtik
00398 
00399 
00400 #endif // ULXR_INCLUDE_SSL_STUFF
00401 
00402 
00403 #endif // FUNTIK_SSL_CONNECTION_H
00404 

Generated on Sun Aug 19 20:08:57 2007 for ulxmlrpcpp by  doxygen 1.5.1