S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_socket_tcp_ssl.h

Go to the documentation of this file.
00001 /*
00002  * Stone Three Foundation Class (s3fc) provides a number of utility classes.
00003  * Copyright (C) 2001 by Stone Three Signal Processing (Pty) Ltd.
00004  *
00005  * Authored by Stone Three Signal Processing (Pty) Ltd.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  * 
00021  * Please see the file 'COPYING' in the source root directory.
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 // Define NOMINMAX to prevent the definition of min and max macros in windef.h
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

Send comments to: s3fc@stonethree.com SourceForge Logo