context.h
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 #ifndef CONEXUS_SSLCONTEXT_H
00020 #define CONEXUS_SSLCONTEXT_H
00021 
00022 #include <string>
00023 
00024 #include <openssl/ssl.h>
00025 
00026 #include <sigc++/sigc++.h>
00027 
00028 #include <conexus/pointer.h>
00029 #include <conexus-ssl/enums.h>
00030 
00031 namespace Conexus
00032 {
00033 
00034   namespace SSL
00035   {
00036 
00040     class Context
00041     {
00042       protected:
00043         Context ( Method m );
00044 
00045       public:
00046         typedef ConexusPointer<Context> pointer;
00047 
00048         static pointer create ( Method m=SSLV23 );
00049 
00050         virtual ~Context();
00051 
00052         Method method();
00053 
00060         bool use_certificate ( X509 *x );
00061 
00066         bool use_certificate_asn1 ( int len, unsigned char *d );
00067 
00074         bool use_certificate_file ( const std::string& file, FileType type );
00075 
00084         bool use_certificate_chain_file ( const std::string& file );
00085 
00094         bool use_private_key ( EVP_PKEY *pkey );
00095 
00099         bool use_private_key_asn1 ( int pk, unsigned char *d, long len );
00100 
00107         bool use_private_key_file ( const std::string& file, FileType type );
00108 
00117         bool use_rsa_private_key ( RSA *rsa );
00118 
00122         bool use_rsa_private_key_asn1 ( unsigned char *d, long len );
00123 
00130         bool use_rsa_private_key_file ( const std::string& file, FileType type );
00131 
00141         bool check_private_key() const;
00142 
00152         typedef sigc::slot<void,std::string&,EncDecFlag> PasswordSlot;
00153 
00158         void set_default_password_slot ( PasswordSlot slot=PasswordSlot() );
00159 
00161         bool load_verify_locations ( const std::string& ca_file, const std::string& ca_path=std::string() );
00162 
00167         void set_verify_depth ( int depth );
00168 
00173         void set_read_ahead( bool set=true );
00174 
00176         SSL_CTX* cobj();
00177 
00178       protected:
00180         Method m_method;
00181 
00183         SSL_CTX* m_cobj;
00184 
00186         PasswordSlot m_default_password_slot;
00187 
00189         static int passwd_cb_proxy ( char* buf, int size, int rwflag, void* userdata );
00190 
00191     };
00192 
00193   }
00194 
00195 }
00196 
00197 #endif