00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef FUNTIK_SSL_CONNECTION_H
00031 #define FUNTIK_SSL_CONNECTION_H
00032
00033 #include <ulxmlrpcpp/ulxmlrpcpp.h>
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
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
00112
00113
00114
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 }
00398
00399
00400 #endif // ULXR_INCLUDE_SSL_STUFF
00401
00402
00403 #endif // FUNTIK_SSL_CONNECTION_H
00404