Thread: [Opalvoip-svn] SF.net SVN: opalvoip:[32446] ptlib/trunk/src/ptclib/shttpsvc.cxx
Brought to you by:
csoutheren,
rjongbloed
From: <rjo...@us...> - 2014-08-07 08:05:53
|
Revision: 32446 http://sourceforge.net/p/opalvoip/code/32446 Author: rjongbloed Date: 2014-08-07 08:05:44 +0000 (Thu, 07 Aug 2014) Log Message: ----------- Fix compiler compatibility. Modified Paths: -------------- ptlib/trunk/src/ptclib/shttpsvc.cxx Modified: ptlib/trunk/src/ptclib/shttpsvc.cxx =================================================================== --- ptlib/trunk/src/ptclib/shttpsvc.cxx 2014-08-07 07:11:23 UTC (rev 32445) +++ ptlib/trunk/src/ptclib/shttpsvc.cxx 2014-08-07 08:05:44 UTC (rev 32446) @@ -238,7 +238,7 @@ } // copy some bytes to the returned buffer, but no more than the buffer will allow - len = PMIN(len, preReadLen); + len = std::min(len, (int)preReadLen); memcpy(buf, preRead, len); preReadLen -= len; return len; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rjo...@us...> - 2016-07-28 11:44:55
|
Revision: 34887 http://sourceforge.net/p/opalvoip/code/34887 Author: rjongbloed Date: 2016-07-28 11:44:53 +0000 (Thu, 28 Jul 2016) Log Message: ----------- Fixed crash in PSecureHTTPServiceProcess if get SSL level error during web page access. Modified Paths: -------------- ptlib/trunk/src/ptclib/shttpsvc.cxx Modified: ptlib/trunk/src/ptclib/shttpsvc.cxx =================================================================== --- ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-07-28 10:00:20 UTC (rev 34886) +++ ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-07-28 11:44:53 UTC (rev 34887) @@ -130,6 +130,7 @@ return ssl; PSYSTEMLOG(Error, "Accept failed: " << ssl->GetErrorText()); + ssl->Detach(); delete ssl; return NULL; } @@ -175,7 +176,7 @@ bool PSecureHTTPServiceProcess::SetServerCertificates(const PString & cert, const PString & key, const PString & ca) { if (m_sslContext == NULL) - m_sslContext = new PSSLContext; + m_sslContext = new PSSLContext(PSSLContext::TLSv1); return m_sslContext->SetCredentials(ca, cert, key); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rjo...@us...> - 2016-07-28 11:49:54
|
Revision: 34888 http://sourceforge.net/p/opalvoip/code/34888 Author: rjongbloed Date: 2016-07-28 11:49:52 +0000 (Thu, 28 Jul 2016) Log Message: ----------- Make sure SSL disabled in PSecureHTTPServiceProcess if could not set credentials. Modified Paths: -------------- ptlib/trunk/src/ptclib/shttpsvc.cxx Modified: ptlib/trunk/src/ptclib/shttpsvc.cxx =================================================================== --- ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-07-28 11:44:53 UTC (rev 34887) +++ ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-07-28 11:49:52 UTC (rev 34888) @@ -75,6 +75,7 @@ void PSecureHTTPServiceProcess::DisableSSL() { + PSYSTEMLOG(Info, "SSL disabled"); delete m_sslContext; m_sslContext = NULL; } @@ -165,11 +166,7 @@ key.Save(certificateFile, true); } - if (SetServerCertificates(certificateFile, certificateFile, PString::Empty())) - return true; - - DisableSSL(); - return false; + return SetServerCertificates(certificateFile, certificateFile, PString::Empty()); } @@ -178,7 +175,11 @@ if (m_sslContext == NULL) m_sslContext = new PSSLContext(PSSLContext::TLSv1); - return m_sslContext->SetCredentials(ca, cert, key); + if (m_sslContext->SetCredentials(ca, cert, key)) + return true; + + DisableSSL(); + return false; } PBoolean PSecureHTTPServiceProcess::OnDetectedNonSSLConnection(PChannel * chan, const PString & line) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rjo...@us...> - 2016-08-01 12:32:30
|
Revision: 34899 http://sourceforge.net/p/opalvoip/code/34899 Author: rjongbloed Date: 2016-08-01 12:32:27 +0000 (Mon, 01 Aug 2016) Log Message: ----------- Added extra logging for when PSecureHTTPServiceProcess redirects http to https Modified Paths: -------------- ptlib/trunk/src/ptclib/shttpsvc.cxx Modified: ptlib/trunk/src/ptclib/shttpsvc.cxx =================================================================== --- ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-08-01 09:30:56 UTC (rev 34898) +++ ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-08-01 12:32:27 UTC (rev 34899) @@ -183,7 +183,7 @@ } PBoolean PSecureHTTPServiceProcess::OnDetectedNonSSLConnection(PChannel * chan, const PString & line) -{ +{ // get the MIME info PMIMEInfo mime(*chan); @@ -214,7 +214,10 @@ } } - PString str = CreateNonSSLMessage(PString("http://") + url); + url.Splice("http://", 0); + PSYSTEMLOG(Info, "Detected non-SSL connection, redirecting to " << url); + + PString str = CreateNonSSLMessage(url); chan->WriteString(str); chan->Close(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rjo...@us...> - 2016-08-02 12:59:46
|
Revision: 34902 http://sourceforge.net/p/opalvoip/code/34902 Author: rjongbloed Date: 2016-08-02 12:59:43 +0000 (Tue, 02 Aug 2016) Log Message: ----------- Fixed URL scheme in PSecureHTTPServiceProcess auto-upgrade from http to https. Modified Paths: -------------- ptlib/trunk/src/ptclib/shttpsvc.cxx Modified: ptlib/trunk/src/ptclib/shttpsvc.cxx =================================================================== --- ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-08-01 13:00:48 UTC (rev 34901) +++ ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-08-02 12:59:43 UTC (rev 34902) @@ -214,8 +214,8 @@ } } - url.Splice("http://", 0); - PSYSTEMLOG(Info, "Detected non-SSL connection, redirecting to " << url); + url.Splice("https://", 0); + PSYSTEMLOG(Info, "Detected non-SSL connection, host=\"" << host << "\", redirecting to " << url); PString str = CreateNonSSLMessage(url); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rjo...@us...> - 2016-08-02 15:55:29
|
Revision: 34904 http://sourceforge.net/p/opalvoip/code/34904 Author: rjongbloed Date: 2016-08-02 15:55:27 +0000 (Tue, 02 Aug 2016) Log Message: ----------- Make sure content length included in PSecureHTTPServiceProcess redirect http response to upgrade to https. Modified Paths: -------------- ptlib/trunk/src/ptclib/shttpsvc.cxx Modified: ptlib/trunk/src/ptclib/shttpsvc.cxx =================================================================== --- ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-08-02 13:54:37 UTC (rev 34903) +++ ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-08-02 15:55:27 UTC (rev 34904) @@ -235,9 +235,11 @@ PString PSecureHTTPServiceProcess::CreateRedirectMessage(const PString & url) { - return PString("HTTP/1.1 301 Moved Permanently\r\n") + - "Location: " + url + "\r\n" + - "\r\n"; + static const char * CRLF = "\r\n"; + return PSTRSTRM("HTTP/1.1 301 Moved Permanently" << CRLF << + PHTTP::LocationTag() << ": " << url << CRLF << + PHTTP::ContentLengthTag() << ": 0" << CRLF << + CRLF); } HTTP_PSSLChannel::HTTP_PSSLChannel(PSecureHTTPServiceProcess * _svc, PSSLContext * context) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <rjo...@us...> - 2016-08-03 09:31:36
|
Revision: 34906 http://sourceforge.net/p/opalvoip/code/34906 Author: rjongbloed Date: 2016-08-03 09:31:34 +0000 (Wed, 03 Aug 2016) Log Message: ----------- Made the auto upgrade for PSecureHTTPServiceProcess more flexible, working with any HTTP command, not just GET and POST. Modified Paths: -------------- ptlib/trunk/src/ptclib/shttpsvc.cxx Modified: ptlib/trunk/src/ptclib/shttpsvc.cxx =================================================================== --- ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-08-02 18:26:23 UTC (rev 34905) +++ ptlib/trunk/src/ptclib/shttpsvc.cxx 2016-08-03 09:31:34 UTC (rev 34906) @@ -50,11 +50,13 @@ virtual int BioRead(char * out, int outl); protected: - enum { PreRead_Size = 4 }; - - PSecureHTTPServiceProcess * svc; - PINDEX preReadLen; - char preRead[PreRead_Size]; + PSecureHTTPServiceProcess * m_serviceProcess; + PCaselessString m_preReadData; + enum { + e_Starting, + e_IsSSL, + e_Finished } + m_preReadState; }; #define new PNEW @@ -242,51 +244,61 @@ CRLF); } -HTTP_PSSLChannel::HTTP_PSSLChannel(PSecureHTTPServiceProcess * _svc, PSSLContext * context) - : PSSLChannel(context), svc(_svc) +HTTP_PSSLChannel::HTTP_PSSLChannel(PSecureHTTPServiceProcess * svc, PSSLContext * context) + : PSSLChannel(context) + , m_serviceProcess(svc) + , m_preReadState(e_Starting) { - preReadLen = P_MAX_INDEX; } int HTTP_PSSLChannel::BioRead(char * buf, int len) -{ - if (preReadLen == 0) - return PSSLChannel::BioRead(buf, len); +{ + if (m_preReadState == e_Finished) + return PSSLChannel::BioRead(buf, len); - if (preReadLen == P_MAX_INDEX) { + if (m_preReadState == e_Starting) { PChannel * chan = GetReadChannel(); - // read some bytes from the channel - preReadLen = 0; - while (preReadLen < PreRead_Size) { - PBoolean b = chan->Read(preRead + preReadLen, PreRead_Size - preReadLen); - if (!b) - break; - preReadLen += chan->GetLastReadCount(); - } + // read first line from the channel + for (;;) { + int c = chan->ReadChar(); + if (c < 0) + return -1; - // see if these bytes correspond to a GET or POST - if ( - (preReadLen == PreRead_Size) && - ((strncmp(preRead, "GET", 3) == 0) || (strncmp(preRead, "POST", 4) == 0)) - ) { + m_preReadData += (char)c; - // read in the rest of the line - PString line(preRead, 4); - int ch; - while (((ch = chan->ReadChar()) > 0) && (ch != '\n')) - line += (char)ch; + if (c == '\n' && m_preReadData.Find("HTTP/1") != P_MAX_INDEX) { + if (m_serviceProcess->OnDetectedNonSSLConnection(chan, m_preReadData)) + chan->Close(); + return -1; + } - if (!svc->OnDetectedNonSSLConnection(chan, line)) - return -1; + if (c == '\r' || !iscntrl(c)) + continue; + + if (!m_preReadData.IsEmpty()) { + m_preReadState = e_IsSSL; + break; + } + + m_preReadState = e_Finished; + *buf = (char)c; + len = 1; + return len; } } - // copy some bytes to the returned buffer, but no more than the buffer will allow - len = std::min(len, (int)preReadLen); - memcpy(buf, preRead, len); - preReadLen -= len; + // copy pre-read bytes to the supplied buffer, but no more than the buffer will allow + if (len < (int)m_preReadData.GetLength()) { + memcpy(buf, m_preReadData.GetPointer(), len); + m_preReadData.Delete(0, len); + } + else { + len = m_preReadData.GetLength(); + memcpy(buf, m_preReadData.GetPointer(), len); + m_preReadState = e_Finished; + } return len; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |