Commit fdc7f1b6 authored by jan.koester's avatar jan.koester
Browse files

new raead function cert

parent b7cf3efc
Loading
Loading
Loading
Loading
+10 −17
Changes for src/httpd.cpp: 10 added lines, 17 removed lines.
Original line number Diff line number Diff line
@@ -128,27 +128,20 @@ libhttppp::HttpD::HttpD(const char *httpaddr, int port,int maxconnections,const
    try {
        if (sslcertpath && sslkeypath) {

            auto readFile = [] (const char *file,unsigned char **out,size_t &outlen){
                size_t read=0,readed=0;
                std::ifstream myfile(file);
                myfile.seekg(std::ios_base::end);
                outlen=myfile.tellg();
                myfile.seekg(std::ios_base::beg);
                *out = new unsigned char[outlen];
                do{
                    myfile.read((char*)*out+readed,(outlen-readed));
                    readed = myfile.tellg();
            std::string cert,key;

                }while(read<0);
            };
            std::ifstream certfile(sslcertpath);

            unsigned char *cert,*key;
            size_t certlen,keylen;
            if(certfile.is_open())
                certfile >> cert;

            readFile(sslcertpath,&cert,certlen);
            readFile(sslkeypath,&key,keylen);
            std::ifstream keyfile(sslkeypath);

            _ServerSocket = new netplus::ssl(httpaddr, port, maxconnections,-1,cert,certlen,key,keylen);
            if(keyfile.is_open())
                keyfile >> key;

            _ServerSocket = new netplus::ssl(httpaddr, port, maxconnections,-1,(const unsigned char*)cert.c_str(),
                                             cert.length(),(const unsigned char*)key.c_str(),key.length());
        }else{
            #ifndef Windows
            if (port != -1)