00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef CONEXUSNSPRSOCKET_H
00020 #define CONEXUSNSPRSOCKET_H
00021
00022 #include <sys/types.h>
00023
00024 #include <iostream>
00025
00026 #include <utility>
00027
00028 #include <conexus/nspr_filedescriptor.h>
00029 #include <conexus/ipv4_address.h>
00030 #include <conexus/except.h>
00031
00032 #include <pk11func.h>
00033 #include <secitem.h>
00034 #include <ssl.h>
00035 #include <certt.h>
00036 #include <nss.h>
00037 #include <secder.h>
00038 #include <key.h>
00039 #include <sslproto.h>
00040
00045 namespace Conexus
00046 {
00047
00048 namespace NSPR
00049 {
00050
00063 class Socket: public FileDescriptor
00064 {
00065 protected:
00066
00070 Socket( ) throw ();
00071
00072 public:
00073 IDIOSKOPOS_OBJECT( Conexus::NSPR::Socket );
00074
00075 typedef ConexusPointer<Socket> pointer;
00076
00077 virtual ~Socket() throw ();
00078
00083 virtual void close( bool force = false ) throw ( close_exception );
00084
00090 virtual void bind() throw ( bind_exception );
00091
00099 virtual void bind( Conexus::Address& a ) throw ( bind_exception );
00100
00106 virtual void connect() throw ( connect_exception );
00107
00115 virtual void connect( Address& a ) throw ( connect_exception );
00116
00124 virtual void listen( int backlog = 0 );
00125
00126 virtual ssize_t writeto(Address& a, Data::const_pointer data) throw (write_exception);
00127
00128 virtual void set_option( PRSocketOptionData& option );
00129
00130 virtual void change_state( long states ) throw ( state_exception );
00131
00132 sigc::signal<void> signal_bound();
00133
00134 sigc::signal<void> signal_connected();
00135
00136 sigc::signal<void> signal_listening();
00137
00138 bool is_bound();
00139
00140 bool is_connected();
00141
00142 bool is_listening();
00143
00144 bool is_accepted();
00145
00146 void enable_ssl( bool as_server );
00147
00148 void set_ssl_url( const std::string& url );
00149
00150 std::string ssl_get_url();
00151
00152 void ssl_force_handshake();
00153
00154 void ssl_rehandshake( bool flush_cache );
00155
00156 void ssl_reset_handshake();
00157
00158 void ssl_invalidate_session();
00159
00160 int ssl_input_available();
00161
00168 int ssl_security_status();
00169
00170 std::string ssl_cipher();
00171
00172 int ssl_session_key_size();
00173
00174 int ssl_secret_key_size();
00175
00176 std::string ssl_issuer();
00177
00178 std::string ssl_subject();
00179
00180 virtual Conexus::IPv4::Address& local_interface();
00181
00182 virtual Conexus::IPv4::Address& remote_address();
00183
00184 virtual void set_remote_address( Conexus::IPv4::Address addr );
00185
00186 virtual void unset_remote_address();
00187
00188 virtual void set_local_interface( Conexus::IPv4::Address addr );
00189
00190 protected:
00191 Conexus::IPv4::Address m_local_interface;
00192 Conexus::IPv4::Address m_remote_address;
00193 bool m_ssl_enabled;
00194 bool m_ssl_server;
00195 bool m_remote_address_set;
00196
00197 virtual ssize_t write_data( long int timeout, Data::const_pointer data ) throw ( write_exception );
00198
00199 virtual Data::pointer read_data( long int timeout, size_t s = 0 ) throw ( read_exception );
00200
00201 virtual void set_state_closed();
00202 virtual void set_state_bound();
00203 virtual void set_state_connected();
00204 virtual void set_state_listening();
00205
00206 sigc::signal<void> m_signal_bound;
00207 sigc::signal<void> m_signal_connected;
00208 sigc::signal<void> m_signal_listening;
00209
00210 virtual void on_local_interface_changed( );
00211 virtual void on_remote_address_changed( );
00212
00213 void on_local_interface_changed_proxy( );
00214 void on_remote_address_changed_proxy( );
00215
00216 char * on_ssl_pkcs11_password( PK11SlotInfo *info, PRBool retry );
00217
00218 virtual SECStatus on_ssl_certificate_authenticate( PRBool checksig, PRBool isServer );
00219
00220 virtual SECStatus on_ssl_bad_certificate();
00221
00222 virtual SECStatus on_ssl_handshake();
00223
00224 virtual SECStatus on_ssl_client_authenticate( struct CERTDistNamesStr *caNames,
00225 struct CERTCertificateStr **pRetCert,
00226 struct SECKEYPrivateKeyStr **pRetKey );
00227
00228 private:
00229 static char * SSL_SetPKCS11PinArg_proxy( PK11SlotInfo *info, PRBool retry, void *arg );
00230
00231 static SECStatus SSL_AuthCertificateHook_proxy( void *arg, PRFileDesc *socket,
00232 PRBool checksig, PRBool isServer );
00233
00234 static SECStatus SSL_BadCertHook_proxy( void *arg, PRFileDesc *socket );
00235
00236 static SECStatus SSL_HandshakeCallback_proxy( PRFileDesc *socket, void *arg );
00237
00238 static SECStatus SSL_GetClientAuthDataHook_proxy( void *arg, PRFileDesc *socket,
00239 struct CERTDistNamesStr *caNames,
00240 struct CERTCertificateStr **pRetCert,
00241 struct SECKEYPrivateKeyStr **pRetKey );
00242
00243 };
00244
00245 }
00246 }
00247
00248 #endif