15 #include "tlsgnutlsbase.h"
28 :
TLSBase( th, server ), m_session( new gnutls_session_t ), m_buf( 0 ), m_bufsize( 17000 )
30 m_buf = (
char*)calloc( m_bufsize + 1,
sizeof(
char ) );
54 std::string::size_type sum = 0;
57 ret = gnutls_record_send( *m_session, data.c_str() + sum, data.length() - sum );
60 while( ( ret == GNUTLS_E_AGAIN ) || ( ret == GNUTLS_E_INTERRUPTED ) || sum < data.length() );
71 return static_cast<int>( data.length() );
78 ret =
static_cast<int>( gnutls_record_recv( *m_session, m_buf, m_bufsize ) );
80 if( ret > 0 && m_handler )
98 gnutls_bye( *m_session, GNUTLS_SHUT_RDWR );
99 gnutls_db_remove_session( *m_session );
100 gnutls_credentials_clear( *m_session );
102 gnutls_deinit( *m_session );
109 m_session =
new gnutls_session_t;
120 int ret = gnutls_handshake( *m_session );
121 if( ret < 0 && gnutls_error_is_fatal( ret ) )
123 gnutls_perror( ret );
124 gnutls_db_remove_session( *m_session );
125 gnutls_deinit( *m_session );
131 else if( ret == GNUTLS_E_AGAIN )
146 #ifdef HAVE_GNUTLS_SESSION_CHANNEL_BINDING
155 #ifdef HAVE_GNUTLS_SESSION_CHANNEL_BINDING
158 rc = gnutls_session_channel_binding( *m_session, GNUTLS_CB_TLS_UNIQUE, &cb );
160 return std::string( (
char*)cb.data, cb.size );
166 ssize_t GnuTLSBase::pullFunc(
void* data,
size_t len )
168 ssize_t cpy = ( len > m_recvBuffer.length() ) ? ( m_recvBuffer.length() ) : ( len );
171 memcpy( data, (
const void*)m_recvBuffer.c_str(), cpy );
172 m_recvBuffer.erase( 0, cpy );
178 return GNUTLS_E_AGAIN;
182 ssize_t GnuTLSBase::pullFunc( gnutls_transport_ptr_t ptr,
void* data,
size_t len )
184 return static_cast<GnuTLSBase*
>( ptr )->pullFunc( data, len );
187 ssize_t GnuTLSBase::pushFunc(
const void* data,
size_t len )
195 ssize_t GnuTLSBase::pushFunc( gnutls_transport_ptr_t ptr,
const void* data,
size_t len )
197 return static_cast<GnuTLSBase*
>( ptr )->pushFunc( data, len );
202 #endif // HAVE_GNUTLS