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

test

parent 2234157d
Loading
Loading
Loading
Loading
+7 −6
Changes for src/http.cpp: 7 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -206,9 +206,9 @@ const std::string & libhttppp::HttpUrl::getPath() const{
libhttppp::HttpClient::HttpClient(const HttpUrl& desturl)
: _url(desturl){
    try {
        netplus::x509cert cert;
        if (_url.getProtocol() == HttpUrl::HTTPS) {
            _cltsock = std::make_unique<netplus::ssl>(cert,-1);
            std::map<std::string, netplus::ssl::CertificateBundle> certs;
            _cltsock = std::make_unique<netplus::ssl>(certs,-1);
        } else {
            _cltsock = std::make_unique<netplus::tcp>(-1);
        }
@@ -1765,14 +1765,15 @@ void libhttppp::HttpRequest::send(const HttpUrl &dest,
    std::string full = header + _Request;
    size_t off = 0;

    netplus::x509cert cert;
    if(!sock || sock->fd()<0){
        if(!sock){
            if(dest.getProtocol()==HttpUrl::HTTPS)
                sock=std::make_unique<netplus::ssl>(cert,-1);
            else
            if(dest.getProtocol()==HttpUrl::HTTPS) {
                std::map<std::string, netplus::ssl::CertificateBundle> certs;
                sock=std::make_unique<netplus::ssl>(certs,-1);
            } else {
                sock=std::make_unique<netplus::tcp>(-1);
            }
        }
        sock->connect(dest.getHost(),dest.getPort(),true);
    }
    netplus::buffer buf(full.c_str(),full.length());
+49 −6
Changes for src/httpd.cpp: 49 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -192,10 +192,31 @@ libhttppp::HttpD::HttpD(int argc, char** argv) {
                    throw _httpexception;
                }

                auto ss = std::make_unique<netplus::ssl>(x509,httpaddr, port, maxconnections, -1);
                // Load private key from DER file
                std::ifstream keyfile(keyder, std::ios::binary | std::ios::ate);
                if (!keyfile) {
                    _httpexception[HTTPException::Critical] << "cannot open private key file: " << keyder;
                    throw _httpexception;
                }
                size_t keysize = keyfile.tellg();
                keyfile.seekg(0, std::ios::beg);
                std::vector<uint8_t> keydata(keysize);
                keyfile.read(reinterpret_cast<char*>(keydata.data()), keysize);
                keyfile.close();
                
                netplus::ssl::CertificateBundle bundle;
                bundle.cert = x509;
                bundle.privateKeyDer = keydata;
                
                // Load RSA key from DER data
                if (!netplus::rsa::loadRsaFromDerFile(keydata, bundle.rsa_key)) {
                    _httpexception[HTTPException::Critical] << "failed to load RSA private key from: " << keyder;
                    throw _httpexception;
                }
                
                // IMPORTANT: load private key to fill ss->_rsa.n/e/d
                ss->loadServerPrivateKeyDer(keyder);
                std::map<std::string, netplus::ssl::CertificateBundle> certs;
                certs[httpaddr] = bundle;
                auto ss = std::make_unique<netplus::ssl>(certs, httpaddr, port, maxconnections, -1);

                _ServerSocket = std::move(ss);
        }else{
@@ -235,10 +256,32 @@ libhttppp::HttpD::HttpD(const std::string& httpaddr, int port,int maxconnections
                    throw _httpexception;
                }

                auto ss = std::make_unique<netplus::ssl>(x509,httpaddr, port, maxconnections, -1);
                netplus::ssl::CertificateBundle bundle;
                bundle.cert = x509;
                
                // Load private key from DER file
                std::ifstream keyfile(sslkeypath, std::ios::binary | std::ios::ate);
                if (!keyfile) {
                    _httpexception[HTTPException::Critical] << "cannot open private key file: " << sslkeypath;
                    throw _httpexception;
                }
                size_t keysize = keyfile.tellg();
                keyfile.seekg(0, std::ios::beg);
                std::vector<uint8_t> keydata(keysize);
                keyfile.read(reinterpret_cast<char*>(keydata.data()), keysize);
                keyfile.close();
                
                bundle.privateKeyDer = keydata;
                
                // Load RSA key from DER data
                if (!netplus::rsa::loadRsaFromDerFile(keydata, bundle.rsa_key)) {
                    _httpexception[HTTPException::Critical] << "failed to load RSA private key from: " << sslkeypath;
                    throw _httpexception;
                }
                
                // IMPORTANT: load private key to fill ss->_rsa.n/e/d
                ss->loadServerPrivateKeyDer(sslkeypath);
                std::map<std::string, netplus::ssl::CertificateBundle> certs;
                certs[httpaddr] = bundle;
                auto ss = std::make_unique<netplus::ssl>(certs, httpaddr, port, maxconnections, -1);

                _ServerSocket = std::move(ss);
        }else{