gnutls-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: old gnutlsxx defect still not fixed?


From: Nikos Mavrogiannopoulos
Subject: Re: old gnutlsxx defect still not fixed?
Date: Sat, 17 May 2008 09:05:43 +0300
User-agent: Thunderbird 2.0.0.14 (X11/20080505)

Benjamin Herr wrote:
> Hi,

> as described in [0], the C++ bindings to gnutlsxx still invoke undefined
> behaviour because the pure virtual function gnutls::credentials::set_ptr
> cannot be called virtually in the constructor of gnutls::credentials.
> The result for me is a linker error whenever any subclass of
> gnutls::credentials is instantiated, or when the library is built for
> Windows using mingw32 as win32 shared libraries cannot have unresolved
> symbols.

Would the attached patch solve this issue? It is a port of the old patch
to newer gnutls.

> Does anyone actually use the gnutlsxx bindings? The patches provided in
> [0] look somewhat sane, is there any reason they have not been applied yet?
> 
> Thanks for your time,
> 
> Benjamin Herr
> 
> [0]: http://lists.gnu.org/archive/html/gnutls-devel/2007-02/msg00017.html
diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am
index 0370a2c..b30f828 100644
--- a/doc/examples/Makefile.am
+++ b/doc/examples/Makefile.am
@@ -28,8 +28,20 @@ LDADD = libexamples.la \
        ../../lib/libgnutls.la  \
        ../../libextra/libgnutls-extra.la
 
+CXX_LDADD = libexamples.la \
+       ../../gl/libgnu.la \
+       ../../lib/libgnutls.la  \
+       ../../lib/libgnutlsxx.la        \
+       ../../libextra/libgnutls-extra.la
+
 noinst_PROGRAMS = ex-cert-select ex-client2 ex-client-resume   \
-       ex-crq ex-serv1 ex-serv-export
+       ex-crq ex-serv1 ex-serv-export 
+
+if ENABLE_CXX
+excxx_SOURCES = ex-cxx.cpp
+excxx_LDADD = $(CXX_LDADD)
+noinst_PROGRAMS += excxx
+endif
 
 if ENABLE_ANON
 noinst_PROGRAMS += ex-client1 ex-serv-anon
diff --git a/doc/examples/ex-cxx.cpp b/doc/examples/ex-cxx.cpp
new file mode 100644
index 0000000..b43aba6
--- /dev/null
+++ b/doc/examples/ex-cxx.cpp
@@ -0,0 +1,100 @@
+#if HAVE_CONFIG_H
+# include <config.h>
+#else
+#endif
+#include <iostream>
+#include <stdexcept>
+#include <gnutls/gnutls.h>
+#include <gnutls/gnutlsxx.h>
+
+/* A very basic TLS client, with anonymous authentication.
+ * written by Eduardo Villanueva Che.
+ */
+
+#define MAX_BUF 1024
+#define SA struct sockaddr
+
+#define CAFILE "ca.pem"
+#define MSG "GET / HTTP/1.0\r\n\r\n"
+
+extern "C"
+{
+    int tcp_connect(void);
+    void tcp_close(int sd);
+}
+
+
+int main(void)
+{
+    int sd = -1;
+    gnutls_global_init();
+
+    try
+    {
+
+        /* Allow connections to servers that have OpenPGP keys as well.
+         */
+        gnutls::client_session session;
+
+        /* X509 stuff */
+        gnutls::certificate_credentials credentials;
+
+
+        /* sets the trusted cas file
+         */
+        credentials.set_x509_trust_file(CAFILE, GNUTLS_X509_FMT_PEM);
+        /* put the x509 credentials to the current session
+         */
+        session.set_credentials(credentials);
+
+        /* Use default priorities */
+        session.set_priority ("NORMAL", NULL);
+
+        /* connect to the peer
+         */
+        sd = tcp_connect();
+        session.set_transport_ptr((gnutls_transport_ptr_t) sd);
+
+        /* Perform the TLS handshake
+         */
+        int ret = session.handshake();
+        if (ret < 0)
+        {
+//             gnutls_perror(ret);
+            throw std::runtime_error("Handshake failed");
+        }
+        else
+        {
+            std::cout << "- Handshake was completed" << std::endl;
+        }
+
+        session.send(MSG, strlen(MSG));
+        char buffer[MAX_BUF + 1];
+        ret = session.recv(buffer, MAX_BUF);
+        if (ret == 0)
+        {
+            throw std::runtime_error("Peer has closed the TLS connection");
+        }
+        else if (ret < 0)
+        {
+            throw std::runtime_error(gnutls_strerror(ret));
+        }
+
+        std::cout << "- Received " << ret << " bytes:" << std::endl;
+        std::cout.write(buffer, ret);
+        std::cout << std::endl;
+
+        session.bye(GNUTLS_SHUT_RDWR);
+    }
+    catch (std::exception &ex)
+    {
+        std::cerr << "Exception caught: " << ex.what() << std::endl;
+    }
+
+    if (sd != -1)
+        tcp_close(sd);
+
+    gnutls_global_deinit();
+
+    return 0;
+}
diff --git a/doc/gnutls.texi b/doc/gnutls.texi
index 4fa519d..d242f52 100644
--- a/doc/gnutls.texi
+++ b/doc/gnutls.texi
@@ -2297,6 +2297,14 @@ The following client is a simple client which uses the
 
 @verbatiminclude examples/ex-client-tlsia.c
 
address@hidden Simple client example in @acronym{C++}
address@hidden Simple Client Example using the @acronym{C++} API
+
+The following client is a simple example of a client
+client utilizing the GnuTLS @acronym{C++} API. 
+
address@hidden examples/ex-cxx.c
+
 @node Helper function for TCP connections
 @subsection Helper Function for TCP Connections
 
diff --git a/includes/gnutls/gnutlsxx.h b/includes/gnutls/gnutlsxx.h
index 932f494..455fa24 100644
--- a/includes/gnutls/gnutlsxx.h
+++ b/includes/gnutls/gnutlsxx.h
@@ -7,6 +7,19 @@
 
 namespace gnutls {
 
+class noncopyable
+{
+    protected:
+        noncopyable() { }
+        ~noncopyable() { }
+
+    private:
+        // These are non-implemented.
+        noncopyable(const noncopyable &);
+       noncopyable &operator=(const noncopyable &);
+};
+
+
 class exception: public std::exception
 {
     public:
@@ -17,7 +30,8 @@ class exception: public std::exception
         int retcode;
 };
 
-class dh_params
+
+class dh_params : private noncopyable
 {
     public:
         dh_params();
@@ -27,7 +41,7 @@ class dh_params
         void import_pkcs3( const gnutls_datum_t & pkcs3_params,
                            gnutls_x509_crt_fmt_t format);
         void generate( unsigned int bits);
-        
+
         void export_pkcs3( gnutls_x509_crt_fmt_t format, unsigned char 
*params_data, size_t * params_data_size);
         void export_raw( gnutls_datum_t& prime, gnutls_datum_t &generator);
 
@@ -36,9 +50,9 @@ class dh_params
     protected:
         gnutls_dh_params_t params;
 };
-  
-  
-class rsa_params
+
+
+class rsa_params : private noncopyable
 {
     public:
         rsa_params();
@@ -52,7 +66,7 @@ class rsa_params
         void import_pkcs1( const gnutls_datum_t & pkcs1_params,
                            gnutls_x509_crt_fmt_t format);
         void generate( unsigned int bits);
-        
+
         void export_pkcs1( gnutls_x509_crt_fmt_t format, unsigned char 
*params_data, size_t * params_data_size);
         void export_raw(  gnutls_datum_t & m, gnutls_datum_t & e,
                       gnutls_datum_t & d, gnutls_datum_t & p,
@@ -64,18 +78,17 @@ class rsa_params
         gnutls_rsa_params_t params;
 };
 
-class session
+class session : private noncopyable
 {
     protected:
         gnutls_session_t s;
     public:
         session( gnutls_connection_end_t);
-        session( session& s);
         virtual ~session();
 
         int bye( gnutls_close_request_t how);
         int handshake ();
-        
+
         gnutls_alert_description_t get_alert() const;
 
         int send_alert ( gnutls_alert_level_t level,
@@ -121,8 +134,8 @@ class session
         void set_protocol_priority (const int *list);
         void set_certificate_type_priority (const int *list);
 
-/* if you just want some defaults, use the following.
- */
+       /* if you just want some defaults, use the following.
+        */
         void set_priority (const char* prio, const char** err_pos);
         void set_priority (gnutls_priority_t p);
 
@@ -173,7 +186,7 @@ class session
         void get_dh_pubkey( gnutls_datum_t & raw_key) const;
         void get_rsa_export_pubkey( gnutls_datum_t& exponent, gnutls_datum_t& 
modulus) const;
         unsigned int get_rsa_export_modulus_bits() const;
-        
+
         void get_our_certificate(gnutls_datum_t & cert) const;
         bool get_peers_certificate(std::vector<gnutls_datum_t> &out_certs) 
const;
         bool get_peers_certificate(const gnutls_datum_t** certs, unsigned int 
*certs_size) const;
@@ -185,7 +198,7 @@ class session
 };
 
 // interface for databases
-class DB
+class DB  : private noncopyable
 {
     public:
         virtual ~DB()=0;
@@ -198,15 +211,16 @@ class server_session: public session
 {
     public:
         server_session();
+        ~server_session();
         void db_remove() const;
-        
+
         void set_db_cache_expiration (unsigned int seconds);
         void set_db( const DB& db);
-        
+
         // returns true if session is expired
         bool db_check_entry ( gnutls_datum_t &session_data) const;
-    
-    // server side only
+
+        // server side only
         const char *get_srp_username() const;
         const char *get_psk_username() const;
 
@@ -221,35 +235,28 @@ class client_session: public session
 {
     public:
         client_session();
+        ~client_session();
+
         void set_server_name (gnutls_server_name_type_t type,
                           const void *name, size_t name_length);
-    
+
         bool get_request_status();
 };
 
 
-class credentials
+class credentials  : private noncopyable
 {
     public:
-        credentials(gnutls_credentials_type_t t);
-#if defined(__APPLE__) || defined(__MACOS__)
-       /* FIXME: This #if is due to a compile bug in Mac OS X.  Give
-          it some time and then remove this cruft.  See also
-          lib/gnutlsxx.cpp. */
-       credentials( credentials& c) {
-         type = c.type;
-         set_ptr( c.ptr());
-       }
-#else
-       credentials( credentials& c);
-#endif
         virtual ~credentials() { }
         gnutls_credentials_type_t get_type() const;
     protected:
         friend class session;
-        virtual void* ptr() const=0;
-        virtual void set_ptr(void* ptr)=0;
+        credentials(gnutls_credentials_type_t t);
+        void* ptr() const;
+        void set_ptr(void* ptr);
         gnutls_credentials_type_t type;
+    private:
+        void *cred;
 };
 
 class certificate_credentials: public credentials
@@ -288,14 +295,11 @@ class certificate_credentials: public credentials
                  gnutls_x509_crt_fmt_t type, const char *password);
         
     protected:
-        void* ptr() const;
-        void set_ptr(void* p);
         gnutls_certificate_credentials_t cred;
 };
 
 class certificate_server_credentials: public certificate_credentials
 {
-    certificate_server_credentials() { }
     public:
         void set_retrieve_function( 
gnutls_certificate_server_retrieve_function* func);
         void set_params_function( gnutls_params_function* func);
@@ -304,7 +308,6 @@ class certificate_server_credentials: public 
certificate_credentials
 class certificate_client_credentials: public certificate_credentials
 {
     public:
-        certificate_client_credentials() { }
         void set_retrieve_function( 
gnutls_certificate_client_retrieve_function* func);
 };
 
@@ -340,8 +343,6 @@ class srp_server_credentials: public credentials
         void set_credentials_file (const char *password_file, const char 
*password_conf_file);
         void set_credentials_function( gnutls_srp_server_credentials_function 
*func);
     protected:
-        void* ptr() const;
-        void set_ptr(void* p);
         gnutls_srp_server_credentials_t cred;
 };
 
@@ -353,8 +354,6 @@ class srp_client_credentials: public credentials
         void set_credentials (const char *username, const char *password);
         void set_credentials_function( gnutls_srp_client_credentials_function* 
func);
     protected:
-        void* ptr() const;
-        void set_ptr(void* p);
         gnutls_srp_client_credentials_t cred;
 };
 
@@ -369,8 +368,6 @@ class psk_server_credentials: public credentials
         void set_dh_params ( const dh_params &params);
         void set_params_function (gnutls_params_function * func);
     protected:
-        void* ptr() const;
-        void set_ptr(void* p);
         gnutls_psk_server_credentials_t cred;
 };
 
@@ -382,12 +379,10 @@ class psk_client_credentials: public credentials
         void set_credentials (const char *username, const gnutls_datum_t& key, 
gnutls_psk_key_flags flags);
         void set_credentials_function( gnutls_psk_client_credentials_function* 
func);
     protected:
-        void* ptr() const;
-        void set_ptr(void* p);
         gnutls_psk_client_credentials_t cred;
 };
 
 
-}; /* namespace */
+} /* namespace */
 
 #endif                          /* GNUTLSXX_H */
diff --git a/lib/gnutlsxx.cpp b/lib/gnutlsxx.cpp
index 815dae1..9d38f23 100644
--- a/lib/gnutlsxx.cpp
+++ b/lib/gnutlsxx.cpp
@@ -1,14 +1,15 @@
 #include <gnutls/gnutlsxx.h>
 
-using namespace gnutls;
+namespace gnutls
+{
 
-inline int RETWRAP_NET(int ret) 
+inline static int RETWRAP_NET(int ret) 
 {
     if (gnutls_error_is_fatal(ret)) throw(exception(ret));
     else return ret;
 }
 
-inline int RETWRAP(int ret) 
+inline static int RETWRAP(int ret) 
 {
     if (ret < 0) throw(exception(ret));
     return ret;
@@ -16,27 +17,22 @@ inline int RETWRAP(int ret)
 
 session::session( gnutls_connection_end_t end)
 {
-    RETWRAP(gnutls_init( &this->s, end));
-}
-
-session::session( session& s)
-{
-    this->s = s.s;
+    RETWRAP(gnutls_init( &s, end));
 }
 
 session::~session()
 {
-    gnutls_deinit( this->s);
+    gnutls_deinit( s);
 }
 
 int session::bye( gnutls_close_request_t how)
 {
-    return RETWRAP_NET( gnutls_bye( this->s, how));
+    return RETWRAP_NET( gnutls_bye( s, how));
 }
 
 int session::handshake ()
 {
-    return RETWRAP_NET( gnutls_handshake( this->s));
+    return RETWRAP_NET( gnutls_handshake( s));
 }
 
 
@@ -44,96 +40,100 @@ server_session::server_session() : session( GNUTLS_SERVER)
 {
 }
 
+server_session::~server_session()
+{
+}
+
 int server_session::rehandshake()
 {
-    return RETWRAP_NET( gnutls_rehandshake( this->s));
+    return RETWRAP_NET( gnutls_rehandshake( s));
 }
 
 gnutls_alert_description_t session::get_alert() const
 {
-    return gnutls_alert_get( this->s);
+    return gnutls_alert_get( s);
 }
 
 int session::send_alert ( gnutls_alert_level_t level,
                           gnutls_alert_description_t desc)
 {
-    return RETWRAP_NET(gnutls_alert_send( this->s, level, desc));
+    return RETWRAP_NET(gnutls_alert_send( s, level, desc));
 }
 
 int session::send_appropriate_alert (int err)
 {
-    return RETWRAP_NET(gnutls_alert_send_appropriate( this->s, err));
+    return RETWRAP_NET(gnutls_alert_send_appropriate( s, err));
 }
 
 gnutls_cipher_algorithm_t session::get_cipher() const
 {
-    return gnutls_cipher_get( this->s);
+    return gnutls_cipher_get( s);
 }
 
 gnutls_kx_algorithm_t session::get_kx () const
 {
-    return gnutls_kx_get( this->s);
+    return gnutls_kx_get( s);
 }
 
 gnutls_mac_algorithm_t session::get_mac () const
 {
-    return gnutls_mac_get( this->s);
+    return gnutls_mac_get( s);
 }
 
 gnutls_compression_method_t session::get_compression() const
 {
-    return gnutls_compression_get( this->s);
+    return gnutls_compression_get( s);
 }
 
 gnutls_certificate_type_t session::get_certificate_type() const
 {
-    return gnutls_certificate_type_get( this->s);
+    return gnutls_certificate_type_get( s);
 }
 
 void session::set_private_extensions ( bool allow)
 {
-    gnutls_handshake_set_private_extensions( this->s, (int)allow);
+    gnutls_handshake_set_private_extensions( s, (int)allow);
 }
 
 gnutls_handshake_description_t session::get_handshake_last_out() const
 {
-    return gnutls_handshake_get_last_out( this->s);
+    return gnutls_handshake_get_last_out( s);
 }
 
 gnutls_handshake_description_t session::get_handshake_last_in() const
 {
-    return gnutls_handshake_get_last_in( this->s);
+    return gnutls_handshake_get_last_in( s);
 }
 
 ssize_t session::send (const void *data, size_t sizeofdata)
 {
-    return RETWRAP_NET(gnutls_record_send( this->s, data, sizeofdata));
+    return RETWRAP_NET(gnutls_record_send( s, data, sizeofdata));
 }
 
 ssize_t session::recv (void *data, size_t sizeofdata)
 {
-    return RETWRAP_NET(gnutls_record_recv( this->s, data, sizeofdata));
+    return RETWRAP_NET(gnutls_record_recv( s, data, sizeofdata));
 }
 
 bool session::get_record_direction() const
 {
-    return gnutls_record_get_direction(this->s);
+    return gnutls_record_get_direction(s);
 }
 
         // maximum packet size
 size_t session::get_max_size () const
 {
-    return gnutls_record_get_max_size( this->s);
+    return gnutls_record_get_max_size( s);
 }
 
 void session::set_max_size(size_t size)
 {
-    RETWRAP( gnutls_record_set_max_size( this->s, size));
+    RETWRAP( gnutls_record_set_max_size( s, size));
 }
 
 size_t session::check_pending () const
 {
-    return gnutls_record_check_pending( this->s);
+    return gnutls_record_check_pending( s);
 }
 
 
@@ -142,7 +142,7 @@ void session::prf (size_t label_size, const char *label,
                  size_t extra_size, const char *extra,
                  size_t outsize, char *out)
 {
-    RETWRAP(gnutls_prf( this->s, label_size, label, server_random_first,
+    RETWRAP(gnutls_prf( s, label_size, label, server_random_first,
             extra_size, extra, outsize, out));
 }
 
@@ -150,38 +150,38 @@ void session::prf_raw ( size_t label_size, const char 
*label,
                       size_t seed_size, const char *seed,
                       size_t outsize, char *out)
 {
-    RETWRAP( gnutls_prf_raw( this->s, label_size, label, seed_size, seed, 
outsize, out));
+    RETWRAP( gnutls_prf_raw( s, label_size, label, seed_size, seed, outsize, 
out));
 }
 
 
 void session::set_cipher_priority (const int *list)
 {
-    RETWRAP( gnutls_cipher_set_priority( this->s, list));
+    RETWRAP( gnutls_cipher_set_priority( s, list));
 }
 
 void session::set_mac_priority (const int *list)
 {
-    RETWRAP( gnutls_mac_set_priority( this->s, list));
+    RETWRAP( gnutls_mac_set_priority( s, list));
 }
 
 void session::set_compression_priority (const int *list)
 {
-    RETWRAP( gnutls_compression_set_priority( this->s, list));
+    RETWRAP( gnutls_compression_set_priority( s, list));
 }
 
 void session::set_kx_priority (const int *list)
 {
-    RETWRAP( gnutls_kx_set_priority( this->s, list));
+    RETWRAP( gnutls_kx_set_priority( s, list));
 }
 
 void session::set_protocol_priority (const int *list)
 {
-    RETWRAP( gnutls_protocol_set_priority( this->s, list));
+    RETWRAP( gnutls_protocol_set_priority( s, list));
 }
 
 void session::set_certificate_type_priority (const int *list)
 {
-    RETWRAP( gnutls_certificate_type_set_priority( this->s, list));
+    RETWRAP( gnutls_certificate_type_set_priority( s, list));
 }
 
 
@@ -189,50 +189,49 @@ void session::set_certificate_type_priority (const int 
*list)
  */
 void session::set_priority(const char* prio, const char** err_pos)
 {
-    RETWRAP(gnutls_priority_set_direct( this->s, prio, err_pos));
+    RETWRAP(gnutls_priority_set_direct( s, prio, err_pos));
 }
 
 void session::set_priority(gnutls_priority_t p)
 {
-    RETWRAP(gnutls_priority_set( this->s, p));
+    RETWRAP(gnutls_priority_set( s, p));
 }
 
 gnutls_protocol_t session::get_protocol_version() const
 {
-    return gnutls_protocol_get_version( this->s);
+    return gnutls_protocol_get_version( s);
 }
 
 void session::set_data ( const void *session_data,
                         size_t session_data_size)
 {
-    RETWRAP(gnutls_session_set_data( this->s, session_data, 
session_data_size));
+    RETWRAP(gnutls_session_set_data( s, session_data, session_data_size));
 }
 
 void session::get_data (void *session_data,
                         size_t * session_data_size) const
 {
-    RETWRAP(gnutls_session_get_data( this->s, session_data, 
session_data_size));
+    RETWRAP(gnutls_session_get_data( s, session_data, session_data_size));
 }
 
 void session::get_data(gnutls_session_t session,
                        gnutls_datum_t & data) const
 {
-    RETWRAP(gnutls_session_get_data2( this->s, &data));
+    RETWRAP(gnutls_session_get_data2( s, &data));
 
 }
 
 void session::get_id ( void *session_id,
                        size_t * session_id_size) const
 {
-    RETWRAP( gnutls_session_get_id( this->s, session_id, session_id_size));
+    RETWRAP( gnutls_session_get_id( s, session_id, session_id_size));
 }
 
 bool session::is_resumed() const
 {
-    int ret = gnutls_session_is_resumed( this->s);
-    
-    if (ret != 0) return true;
-    return false;
+    int ret = gnutls_session_is_resumed( s);
+
+    return (ret != 0);
 }
 
 
@@ -241,7 +240,7 @@ bool 
session::get_peers_certificate(std::vector<gnutls_datum_t> &out_certs) cons
     const gnutls_datum_t *certs;
     unsigned int certs_size;
     
-    certs = gnutls_certificate_get_peers (this->s, &certs_size);
+    certs = gnutls_certificate_get_peers (s, &certs_size);
     
     if (certs==NULL) return false;
     
@@ -253,7 +252,7 @@ bool 
session::get_peers_certificate(std::vector<gnutls_datum_t> &out_certs) cons
 
 bool session::get_peers_certificate(const gnutls_datum_t** certs, unsigned int 
*certs_size) const
 {
-    *certs = gnutls_certificate_get_peers (this->s, certs_size);
+    *certs = gnutls_certificate_get_peers (s, certs_size);
     
     if (*certs==NULL) return false;
     return true;
@@ -263,7 +262,7 @@ void session::get_our_certificate(gnutls_datum_t& cert) 
const
 {
 const gnutls_datum_t *d;
     
-    d = gnutls_certificate_get_ours(this->s);
+    d = gnutls_certificate_get_ours(s);
     if (d==NULL)
         throw(exception( GNUTLS_E_INVALID_REQUEST));
     cert = *d;
@@ -271,16 +270,16 @@ const gnutls_datum_t *d;
           
 time_t session::get_peers_certificate_activation_time() const
 {
-    return gnutls_certificate_activation_time_peers( this->s);
+    return gnutls_certificate_activation_time_peers( s);
 }
 
 time_t session::get_peers_certificate_expiration_time() const
 {
-    return gnutls_certificate_expiration_time_peers( this->s);
+    return gnutls_certificate_expiration_time_peers( s);
 }
 void session::verify_peers_certificate( unsigned int& status) const
 {
-    RETWRAP( gnutls_certificate_verify_peers2( this->s, &status));
+    RETWRAP( gnutls_certificate_verify_peers2( s, &status));
 }
 
 
@@ -288,23 +287,27 @@ client_session::client_session() : session( GNUTLS_CLIENT)
 {
 }
 
+client_session::~client_session()
+{
+}
+
 // client session
 void client_session::set_server_name (gnutls_server_name_type_t type,
                                       const void *name, size_t name_length)
 {
-    RETWRAP( gnutls_server_name_set( this->s, type, name, name_length));
+    RETWRAP( gnutls_server_name_set( s, type, name, name_length));
 }
 
 bool client_session::get_request_status()
 {
-    return RETWRAP(gnutls_certificate_client_get_request_status (this->s));
+    return RETWRAP(gnutls_certificate_client_get_request_status (s));
 }
 
 // server_session
 void server_session::get_server_name (void *data, size_t * data_length,
                                       unsigned int *type, unsigned int indx) 
const
 {
-    RETWRAP( gnutls_server_name_get( this->s, data, data_length, type, indx));
+    RETWRAP( gnutls_server_name_get( s, data, data_length, type, indx));
 }
 
 // internal DB stuff
@@ -354,25 +357,25 @@ static int remove_function(void *_db, gnutls_datum_t key)
 
 void server_session::set_db( const DB& db)
 {
-    gnutls_db_set_ptr( this->s, const_cast<DB*>(&db));
-    gnutls_db_set_store_function( this->s, store_function);
-    gnutls_db_set_retrieve_function( this->s, retrieve_function);
-    gnutls_db_set_remove_function( this->s, remove_function);
+    gnutls_db_set_ptr( s, const_cast<DB*>(&db));
+    gnutls_db_set_store_function( s, store_function);
+    gnutls_db_set_retrieve_function( s, retrieve_function);
+    gnutls_db_set_remove_function( s, remove_function);
 }
 
 void server_session::set_db_cache_expiration (unsigned int seconds)
 {
-    gnutls_db_set_cache_expiration( this->s, seconds);
+    gnutls_db_set_cache_expiration( s, seconds);
 }
 
 void server_session::db_remove () const
 {
-    gnutls_db_remove_session( this->s);
+    gnutls_db_remove_session( s);
 }
 
 bool server_session::db_check_entry ( gnutls_datum_t &session_data) const
 {
-    int ret = gnutls_db_check_entry( this->s, session_data);
+    int ret = gnutls_db_check_entry( s, session_data);
 
     if (ret != 0) return true;
     return false;
@@ -380,126 +383,126 @@ bool server_session::db_check_entry ( gnutls_datum_t 
&session_data) const
 
 void session::set_max_handshake_packet_length ( size_t max)
 {
-    gnutls_handshake_set_max_packet_length( this->s, max);
+    gnutls_handshake_set_max_packet_length( s, max);
 }
 
 void session::clear_credentials()
 {
-    gnutls_credentials_clear( this->s);
+    gnutls_credentials_clear( s);
 }
 
 void session::set_credentials( credentials &cred)
 {
-    RETWRAP(gnutls_credentials_set( this->s, cred.get_type(), cred.ptr()));
+    RETWRAP(gnutls_credentials_set( s, cred.get_type(), cred.ptr()));
 }
 
 const char* server_session::get_srp_username() const
 {
-    return gnutls_srp_server_get_username( this->s);
+    return gnutls_srp_server_get_username( s);
 }
 
 const char* server_session::get_psk_username() const
 {
-    return gnutls_psk_server_get_username( this->s);
+    return gnutls_psk_server_get_username( s);
 }
 
 
 void session::set_transport_ptr( gnutls_transport_ptr_t ptr)
 {
-    gnutls_transport_set_ptr( this->s, ptr);
+    gnutls_transport_set_ptr( s, ptr);
 }
   
 void session::set_transport_ptr( gnutls_transport_ptr_t recv_ptr, 
gnutls_transport_ptr_t send_ptr)
 {
-    gnutls_transport_set_ptr2( this->s, recv_ptr, send_ptr);
+    gnutls_transport_set_ptr2( s, recv_ptr, send_ptr);
 }
 
 
 gnutls_transport_ptr_t session::get_transport_ptr () const
 {
-    return gnutls_transport_get_ptr (this->s);
+    return gnutls_transport_get_ptr (s);
 }
   
 void session::get_transport_ptr( gnutls_transport_ptr_t & recv_ptr,
                                  gnutls_transport_ptr_t & send_ptr) const
 {
-    gnutls_transport_get_ptr2 (this->s, &recv_ptr, &send_ptr);
+    gnutls_transport_get_ptr2 (s, &recv_ptr, &send_ptr);
 }
 
 void session::set_transport_lowat( size_t num)
 {
-    gnutls_transport_set_lowat (this->s, num);
+    gnutls_transport_set_lowat (s, num);
 }
 
 void session::set_transport_push_function( gnutls_push_func push_func)
 {
-    gnutls_transport_set_push_function ( this->s,  push_func);
+    gnutls_transport_set_push_function ( s,  push_func);
 }
   
 void session::set_transport_pull_function( gnutls_pull_func pull_func)
 {
-    gnutls_transport_set_pull_function ( this->s,  pull_func);
+    gnutls_transport_set_pull_function ( s,  pull_func);
 }
 
 void session::set_user_ptr( void* ptr)
 {
-    gnutls_session_set_ptr( this->s, ptr);
+    gnutls_session_set_ptr( s, ptr);
 }
 
 void* session::get_user_ptr( ) const
 {
-    return gnutls_session_get_ptr(this->s);
+    return gnutls_session_get_ptr(s);
 }
   
 void session::send_openpgp_cert( gnutls_openpgp_crt_status_t status)
 {
-    gnutls_openpgp_send_cert(this->s, status);
+    gnutls_openpgp_send_cert(s, status);
 }
 
 
 void session::set_dh_prime_bits( unsigned int bits)
 {
-    gnutls_dh_set_prime_bits( this->s, bits);
+    gnutls_dh_set_prime_bits( s, bits);
 }
 
 unsigned int session::get_dh_secret_bits() const
 {
-    return RETWRAP( gnutls_dh_get_secret_bits( this->s));
+    return RETWRAP( gnutls_dh_get_secret_bits( s));
 }
 
 unsigned int session::get_dh_peers_public_bits() const
 {
-    return RETWRAP(gnutls_dh_get_peers_public_bits( this->s));
+    return RETWRAP(gnutls_dh_get_peers_public_bits( s));
 }
 
 unsigned int session::get_dh_prime_bits() const
 {
-    return RETWRAP( gnutls_dh_get_prime_bits( this->s));
+    return RETWRAP( gnutls_dh_get_prime_bits( s));
 }
 
 void session::get_dh_group( gnutls_datum_t & gen, gnutls_datum_t & prime) const
 {
-    RETWRAP( gnutls_dh_get_group( this->s, &gen, &prime));
+    RETWRAP( gnutls_dh_get_group( s, &gen, &prime));
 }
 
 void session::get_dh_pubkey( gnutls_datum_t & raw_key) const
 {
-    RETWRAP(gnutls_dh_get_pubkey( this->s, &raw_key));
+    RETWRAP(gnutls_dh_get_pubkey( s, &raw_key));
 }
 
 void session::get_rsa_export_pubkey( gnutls_datum_t& exponent, gnutls_datum_t& 
modulus) const
 {
-    RETWRAP( gnutls_rsa_export_get_pubkey( this->s, &exponent, &modulus));
+    RETWRAP( gnutls_rsa_export_get_pubkey( s, &exponent, &modulus));
 }
 
 unsigned int session::get_rsa_export_modulus_bits() const
 {
-    return RETWRAP(gnutls_rsa_export_get_modulus_bits( this->s));
+    return RETWRAP(gnutls_rsa_export_get_modulus_bits( s));
 }
 
 void server_session::set_certificate_request( gnutls_certificate_request_t req)
 {
-    gnutls_certificate_server_set_request (this->s, req);
+    gnutls_certificate_server_set_request (s, req);
 }
 
 
@@ -507,342 +510,297 @@ void server_session::set_certificate_request( 
gnutls_certificate_request_t req)
 
 gnutls_credentials_type_t session::get_auth_type() const
 {
-    return gnutls_auth_get_type( this->s);
+    return gnutls_auth_get_type( s);
 }
 
 gnutls_credentials_type_t session::get_server_auth_type() const
 {
-    return gnutls_auth_server_get_type( this->s);
+    return gnutls_auth_server_get_type( s);
 }
 
 gnutls_credentials_type_t session::get_client_auth_type() const
 {
-    return gnutls_auth_client_get_type( this->s);
+    return gnutls_auth_client_get_type( s);
 }
 
 
-void* certificate_credentials::ptr() const
-{
-    return this->cred;
-}
-
-void certificate_credentials::set_ptr(void* p)
-{
-    this->cred = static_cast<gnutls_certificate_credentials_t> (p);
-}
-
 certificate_credentials::~certificate_credentials()
 {
-    gnutls_certificate_free_credentials (this->cred); 
+    gnutls_certificate_free_credentials (cred); 
 }
 
 certificate_credentials::certificate_credentials() : 
credentials(GNUTLS_CRD_CERTIFICATE)
 {
-    RETWRAP(gnutls_certificate_allocate_credentials ( &this->cred));
+    RETWRAP(gnutls_certificate_allocate_credentials ( &cred));
+    set_ptr(cred);
 }
 
 void certificate_server_credentials::set_params_function( 
gnutls_params_function* func)
 {
-    gnutls_certificate_set_params_function( this->cred, func);
+    gnutls_certificate_set_params_function( cred, func);
 }
 
 anon_server_credentials::anon_server_credentials() : 
credentials(GNUTLS_CRD_ANON)
 { 
-    RETWRAP(gnutls_anon_allocate_server_credentials( &this->cred));
+    RETWRAP(gnutls_anon_allocate_server_credentials( &cred));
+    set_ptr(cred);
 }
         
 anon_server_credentials::~anon_server_credentials() 
 { 
-    gnutls_anon_free_server_credentials( this->cred); 
+    gnutls_anon_free_server_credentials( cred); 
 }
 
 void anon_server_credentials::set_dh_params( const dh_params& params) 
 {
-    gnutls_anon_set_server_dh_params (this->cred, params.get_params_t());
+    gnutls_anon_set_server_dh_params (cred, params.get_params_t());
 }
 
 void anon_server_credentials::set_params_function ( gnutls_params_function * 
func)
 {
-    gnutls_anon_set_server_params_function ( this->cred, func); 
+    gnutls_anon_set_server_params_function ( cred, func); 
 }
 
 anon_client_credentials::anon_client_credentials() : 
credentials(GNUTLS_CRD_ANON)
 { 
-    RETWRAP(gnutls_anon_allocate_client_credentials( &this->cred));
+    RETWRAP(gnutls_anon_allocate_client_credentials( &cred));
+    set_ptr(cred);
 }
         
 anon_client_credentials::~anon_client_credentials() 
 { 
-    gnutls_anon_free_client_credentials( this->cred); 
+    gnutls_anon_free_client_credentials( cred); 
 }
 
 void certificate_credentials::free_keys ()
 {
-    gnutls_certificate_free_keys( this->cred);
+    gnutls_certificate_free_keys( cred);
 }
 
 void certificate_credentials::free_cas ()
 {
-    gnutls_certificate_free_cas( this->cred);
+    gnutls_certificate_free_cas( cred);
 }
 
 void certificate_credentials::free_ca_names ()
 {
-    gnutls_certificate_free_ca_names( this->cred);
+    gnutls_certificate_free_ca_names( cred);
 }
 
 void certificate_credentials::free_crls ()
 {
-    gnutls_certificate_free_crls( this->cred);
+    gnutls_certificate_free_crls( cred);
 }
 
 
 void certificate_credentials::set_dh_params ( const dh_params& params)
 {
-    gnutls_certificate_set_dh_params( this->cred, params.get_params_t());
+    gnutls_certificate_set_dh_params( cred, params.get_params_t());
 }
 
 void certificate_credentials::set_rsa_export_params ( const rsa_params & 
params)
 {
-    gnutls_certificate_set_rsa_export_params( this->cred, 
params.get_params_t());
+    gnutls_certificate_set_rsa_export_params( cred, params.get_params_t());
 }
 
 void certificate_credentials::set_verify_flags ( unsigned int flags)
 {
-    gnutls_certificate_set_verify_flags( this->cred, flags);
+    gnutls_certificate_set_verify_flags( cred, flags);
 }
 
 void certificate_credentials::set_verify_limits ( unsigned int max_bits, 
unsigned int max_depth)
 {
-    gnutls_certificate_set_verify_limits( this->cred, max_bits, max_depth);
+    gnutls_certificate_set_verify_limits( cred, max_bits, max_depth);
 }
 
 void certificate_credentials::set_x509_trust_file(const char *cafile, 
gnutls_x509_crt_fmt_t type)
 {
-    RETWRAP( gnutls_certificate_set_x509_trust_file( this->cred, cafile, 
type));
+    RETWRAP( gnutls_certificate_set_x509_trust_file( cred, cafile, type));
 }
 
 void certificate_credentials::set_x509_trust(const gnutls_datum_t & CA, 
gnutls_x509_crt_fmt_t type)
 {
-    RETWRAP( gnutls_certificate_set_x509_trust_mem( this->cred, &CA, type));
+    RETWRAP( gnutls_certificate_set_x509_trust_mem( cred, &CA, type));
 }
 
 
 void certificate_credentials::set_x509_crl_file( const char *crlfile, 
gnutls_x509_crt_fmt_t type)
 {
-    RETWRAP( gnutls_certificate_set_x509_crl_file( this->cred, crlfile, type));
+    RETWRAP( gnutls_certificate_set_x509_crl_file( cred, crlfile, type));
 }
 
 void certificate_credentials::set_x509_crl(const gnutls_datum_t & CRL, 
gnutls_x509_crt_fmt_t type)
 {
-    RETWRAP( gnutls_certificate_set_x509_crl_mem( this->cred, &CRL, type));
+    RETWRAP( gnutls_certificate_set_x509_crl_mem( cred, &CRL, type));
 }
 
 void certificate_credentials::set_x509_key_file(const char *certfile, const 
char *keyfile, gnutls_x509_crt_fmt_t type)
 {
-    RETWRAP( gnutls_certificate_set_x509_key_file( this->cred, certfile, 
keyfile, type));
+    RETWRAP( gnutls_certificate_set_x509_key_file( cred, certfile, keyfile, 
type));
 }
 
 void certificate_credentials::set_x509_key(const gnutls_datum_t & CERT, const 
gnutls_datum_t & KEY, gnutls_x509_crt_fmt_t type)
 {
-    RETWRAP( gnutls_certificate_set_x509_key_mem( this->cred, &CERT, &KEY, 
type));
+    RETWRAP( gnutls_certificate_set_x509_key_mem( cred, &CERT, &KEY, type));
 }
 
 void certificate_credentials::set_simple_pkcs12_file( const char *pkcs12file,
                                      gnutls_x509_crt_fmt_t type, const char 
*password)
 {
-    RETWRAP( gnutls_certificate_set_x509_simple_pkcs12_file( this->cred, 
pkcs12file, type, password));
+    RETWRAP( gnutls_certificate_set_x509_simple_pkcs12_file( cred, pkcs12file, 
type, password));
 }
 
 void certificate_credentials::set_x509_key ( gnutls_x509_crt_t * cert_list, 
int cert_list_size,
                             gnutls_x509_privkey_t key)
 {
-    RETWRAP( gnutls_certificate_set_x509_key( this->cred, cert_list, 
cert_list_size, key));
+    RETWRAP( gnutls_certificate_set_x509_key( cred, cert_list, cert_list_size, 
key));
 }
 
 void certificate_credentials::set_x509_trust ( gnutls_x509_crt_t * ca_list, 
int ca_list_size)
 {
-    RETWRAP( gnutls_certificate_set_x509_trust( this->cred, ca_list, 
ca_list_size));
+    RETWRAP( gnutls_certificate_set_x509_trust( cred, ca_list, ca_list_size));
 }
 
 void certificate_credentials::set_x509_crl ( gnutls_x509_crl_t * crl_list, int 
crl_list_size)
 {
-    RETWRAP( gnutls_certificate_set_x509_crl( this->cred, crl_list, 
crl_list_size));
+    RETWRAP( gnutls_certificate_set_x509_crl( cred, crl_list, crl_list_size));
 }
 
 void certificate_server_credentials::set_retrieve_function( 
gnutls_certificate_server_retrieve_function* func)
 {
-    gnutls_certificate_server_set_retrieve_function( this->cred, func);
+    gnutls_certificate_server_set_retrieve_function( cred, func);
 }
 
 void certificate_client_credentials::set_retrieve_function( 
gnutls_certificate_client_retrieve_function* func)
 {
-    gnutls_certificate_client_set_retrieve_function( this->cred, func);
+    gnutls_certificate_client_set_retrieve_function( cred, func);
 }
 
 // SRP
 
 srp_server_credentials::srp_server_credentials() : credentials(GNUTLS_CRD_SRP)
 { 
-    RETWRAP(gnutls_srp_allocate_server_credentials( &this->cred));
+    RETWRAP(gnutls_srp_allocate_server_credentials( &cred));
+    set_ptr(cred);
 }
         
 srp_server_credentials::~srp_server_credentials() 
 { 
-    gnutls_srp_free_server_credentials( this->cred); 
-}
-
-void* srp_server_credentials::ptr() const
-{
-    return this->cred;
-}
-
-void srp_server_credentials::set_ptr(void* p)
-{
-    this->cred = static_cast<gnutls_srp_server_credentials_t> (p);
+    gnutls_srp_free_server_credentials( cred); 
 }
 
 srp_client_credentials::srp_client_credentials() : credentials(GNUTLS_CRD_SRP)
 { 
-    RETWRAP(gnutls_srp_allocate_client_credentials( &this->cred));
+    RETWRAP(gnutls_srp_allocate_client_credentials( &cred));
+    set_ptr(cred);
 }
         
 srp_client_credentials::~srp_client_credentials() 
 { 
-    gnutls_srp_free_client_credentials( this->cred); 
-}
-
-void* srp_client_credentials::ptr() const
-{
-    return this->cred;
-}
-
-void srp_client_credentials::set_ptr(void* p)
-{
-    this->cred = static_cast<gnutls_srp_client_credentials_t> (p);
+    gnutls_srp_free_client_credentials( cred); 
 }
 
 void srp_client_credentials::set_credentials( const char* username, const 
char* password)
 {
-    RETWRAP(gnutls_srp_set_client_credentials (this->cred, username, 
password));
+    RETWRAP(gnutls_srp_set_client_credentials (cred, username, password));
 }
 
 void srp_server_credentials::set_credentials_file (
     const char *password_file, const char *password_conf_file)
 {
-    RETWRAP( gnutls_srp_set_server_credentials_file( this->cred, 
password_file, password_conf_file));
+    RETWRAP( gnutls_srp_set_server_credentials_file( cred, password_file, 
password_conf_file));
 }
 
 
 void 
srp_server_credentials::set_credentials_function(gnutls_srp_server_credentials_function
 * func)
 {
-    gnutls_srp_set_server_credentials_function( this->cred, func);
+    gnutls_srp_set_server_credentials_function( cred, func);
 }
 
 void 
srp_client_credentials::set_credentials_function(gnutls_srp_client_credentials_function
 * func)
 {
-    gnutls_srp_set_client_credentials_function( this->cred, func);
+    gnutls_srp_set_client_credentials_function( cred, func);
 }
 
 // PSK
 
 psk_server_credentials::psk_server_credentials() : credentials(GNUTLS_CRD_PSK)
 { 
-    RETWRAP(gnutls_psk_allocate_server_credentials( &this->cred));
+    RETWRAP(gnutls_psk_allocate_server_credentials( &cred));
+    set_ptr(cred);
 }
         
 psk_server_credentials::~psk_server_credentials() 
 { 
-    gnutls_psk_free_server_credentials( this->cred); 
-}
-
-void* psk_server_credentials::ptr() const
-{
-    return this->cred;
-}
-
-void psk_server_credentials::set_ptr(void* p)
-{
-    this->cred = static_cast<gnutls_psk_server_credentials_t> (p);
+    gnutls_psk_free_server_credentials( cred); 
 }
 
 void psk_server_credentials::set_credentials_file(const char* password_file)
 { 
-    RETWRAP(gnutls_psk_set_server_credentials_file( this->cred, 
password_file));
+    RETWRAP(gnutls_psk_set_server_credentials_file( cred, password_file));
 }
 
 void 
psk_server_credentials::set_credentials_function(gnutls_psk_server_credentials_function
 * func)
 {
-    gnutls_psk_set_server_credentials_function( this->cred, func);
+    gnutls_psk_set_server_credentials_function( cred, func);
 }
 
 void psk_server_credentials::set_dh_params( const dh_params &params)
 {
-    gnutls_psk_set_server_dh_params( this->cred, params.get_params_t());
+    gnutls_psk_set_server_dh_params( cred, params.get_params_t());
 }
 
 void psk_server_credentials::set_params_function(gnutls_params_function * func)
 {
-    gnutls_psk_set_server_params_function (this->cred, func);
+    gnutls_psk_set_server_params_function (cred, func);
 }
 
 
 
 psk_client_credentials::psk_client_credentials() : credentials(GNUTLS_CRD_PSK)
 { 
-    RETWRAP(gnutls_psk_allocate_client_credentials( &this->cred));
+    RETWRAP(gnutls_psk_allocate_client_credentials( &cred));
+    set_ptr(cred);
 }
         
 psk_client_credentials::~psk_client_credentials() 
 { 
-    gnutls_psk_free_client_credentials( this->cred); 
-}
-
-void* psk_client_credentials::ptr() const
-{
-    return this->cred;
-}
-
-void psk_client_credentials::set_ptr(void* p)
-{
-    this->cred = static_cast<gnutls_psk_client_credentials_t> (p);
+    gnutls_psk_free_client_credentials( cred); 
 }
 
 void psk_client_credentials::set_credentials(const char* username,
         const gnutls_datum_t& key, gnutls_psk_key_flags flags) 
 { 
-    RETWRAP(gnutls_psk_set_client_credentials( this->cred, username, &key, 
flags));
+    RETWRAP(gnutls_psk_set_client_credentials( cred, username, &key, flags));
 }
 
 void 
psk_client_credentials::set_credentials_function(gnutls_psk_client_credentials_function
 * func)
 {
-    gnutls_psk_set_client_credentials_function( this->cred, func);
+    gnutls_psk_set_client_credentials_function( cred, func);
 }
 
 
-credentials::credentials(gnutls_credentials_type_t t) : type(t) 
+credentials::credentials(gnutls_credentials_type_t t) : type(t), cred(NULL)
 { 
 }
 
-#if !(defined(__APPLE__) || defined(__MACOS__))
-/* FIXME: This #if is due to a compile bug in Mac OS X.  Give it some
-   time and then remove this cruft.  See also
-   includes/gnutls/gnutlsxx.h. */
-credentials::credentials( credentials& c)
-{
-    this->type = c.type;
-    this->set_ptr( c.ptr());
-}
-#endif
-
 gnutls_credentials_type_t credentials::get_type() const
 { 
     return type; 
 }
-        
+
+void* credentials::ptr() const
+{
+    return cred;
+}
+
+
+void credentials::set_ptr(void* ptr)
+{
+    cred = ptr;
+}
 
 
-          
 
 exception::exception( int x) 
 { 
@@ -985,3 +943,5 @@ void rsa_params::export_raw( gnutls_datum_t & m, 
gnutls_datum_t & e,
 {
     RETWRAP( gnutls_rsa_params_export_raw ( params, &m, &e, &d, &p, &q, &u, 
NULL));
 }
+
+}  // namespace gnutls

reply via email to

[Prev in Thread] Current Thread [Next in Thread]