00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00032 #ifndef S3_SOCKET_TCP_SSL_H
00033 #define S3_SOCKET_TCP_SSL_H
00034
00035 #include <string>
00036 #include <iostream>
00037 #define PERL5 //prevent crypt in des.h from being defined
00038 #include <openssl/ssl.h>
00039 #undef PERL5
00040 #include <openssl/err.h>
00041
00042 #include <s3fc/s3_macros.h>
00043
00044 #ifdef _WIN32
00045
00046 #define NOMINMAX
00047 #include <winsock.h>
00048 #else
00049 #include <sys/types.h>
00050 #include <sys/socket.h>
00051 #include <netinet/in.h>
00052 #include <arpa/inet.h>
00053 #include <errno.h>
00054 #include <unistd.h>
00055 #include <netdb.h>
00056 #endif
00057
00058 #include <s3fc/s3_semaphore.h>
00059 #include <s3fc/s3_exception.h>
00060 #include <s3fc/s3_socket_tcp.h>
00061
00062 class s3_socket_tcp_ssl : public s3_socket_tcp
00063 {
00064 private:
00065 bool setup_ssl();
00066 protected:
00067 static bool ssl_init_done;
00068 unsigned long ssl_error;
00069 SSL_CTX* ctx;
00070 SSL* ssl;
00071 std::string keyfile, password, CAfile, CApath;
00072 void set_errnos(unsigned long new_ssl_error=ERR_LIB_NONE);
00073 public:
00075 s3_socket_tcp_ssl(int newsock=INVALID_SOCKET, bool new_set_reuseaddr=true);
00076
00077 s3_socket_tcp_ssl(const s3_socket_tcp_ssl& template_sock);
00078
00079 ~s3_socket_tcp_ssl();
00080
00082 bool accept(s3_socket_tcp_ssl& newsock, sockaddr_in* clientname=0);
00083
00085 bool connect(const std::string& IP_address, in_port_t port);
00086
00088 bool close(bool reinit=true);
00089
00091 std::string get_error() const;
00092
00093 bool set_keyfile_password(std::string newkey, std::string newpass);
00094
00095 bool set_verify_locations_file(std::string new_CAfile);
00096
00097 bool set_verify_locations_path(std::string new_CApath);
00098
00099 bool read(void *data, int size, s3_semaphore *term=0);
00100
00101 bool write(void *data, int size, int max_packet=-1, s3_semaphore *term=0);
00102
00103 static int password_cb(char *buf, int num, int rwflag, void *userdata);
00104
00105 friend bool accept(s3_socket_tcp_ssl& newsock, sockaddr_in* clientname);
00106 };
00107
00108 #endif