Source/WebCore/ChangeLog

 12013-11-20 Robert Sipka <sipka@inf.u-szeged.hu>
 2
 3 [curl] Improve detecting and handling of SSL related errors
 4 https://bugs.webkit.org/show_bug.cgi?id=119436
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Set the exact SSL verification error on CURL
 9 and store the enabled domain with certificate.
 10
 11 * WebCore.vcxproj/WebCore.vcxproj:
 12 * WebCore.vcxproj/WebCore.vcxproj.filters:
 13 * platform/network/ResourceHandle.h:
 14 * platform/network/ResourceHandleInternal.h:
 15 (WebCore::ResourceHandleInternal::ResourceHandleInternal):
 16 * platform/network/curl/ResourceError.h:
 17 (WebCore::ResourceError::ResourceError):
 18 (WebCore::ResourceError::sslErrors):
 19 (WebCore::ResourceError::setSSLErrors):
 20 * platform/network/curl/ResourceHandleCurl.cpp:
 21 (WebCore::ResourceHandle::setHostAllowsAnyHTTPSCertificate):
 22 * platform/network/curl/ResourceHandleManager.cpp:
 23 (WebCore::ResourceHandleManager::downloadTimerCallback):
 24 (WebCore::ResourceHandleManager::initializeHandle):
 25 * platform/network/curl/SSLHandle.cpp: Added.
 26 (WebCore::allowsAnyHTTPSCertificateHosts):
 27 (WebCore::sslIgnoreHTTPSCertificate):
 28 (WebCore::sslCertificateFlag):
 29 (WebCore::pemData):
 30 (WebCore::certVerifyCallback):
 31 (WebCore::sslctxfun):
 32 (WebCore::setSSLVerifyOptions):
 33 * platform/network/curl/SSLHandle.h: Added.
 34
1352013-11-20 Andrei Bucur <abucur@adobe.com>
236
337 [CSSRegions] Move region styling code into RenderNamedFlowFragment
438 https://bugs.webkit.org/show_bug.cgi?id=122957
539
640 Reviewed by Mihnea Ovidenie.
741
842 The patch moves all the region styling functionality outside of RenderRegion
943 to RenderNamedFlowFragment and outside of RenderFlowThread to RenderNamedFlowThread.
1044 This generates a couple of undesired casts that will be removed in later patches
1145 when everything CSS Regions specific will be located inside RenderNamedFlowThread
1246 and RenderNamedFlowFragment (e.g. the move of the isValid flag, the auto-height
1347 code etc.).
1448
1549 The painting function was also moved from RenderRegion to RenderNamedFlowFragment. It

Source/WebCore/WebCore.vcxproj/WebCore.vcxproj

83928392 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
83938393 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
83948394 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
83958395 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
83968396 </ClCompile>
83978397 <ClCompile Include="..\platform\network\curl\SocketStreamHandleCurl.cpp">
83988398 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
83998399 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
84008400 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
84018401 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
84028402 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
84038403 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
84048404 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
84058405 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
84068406 </ClCompile>
 8407 <ClCompile Include="..\platform\network\curl\SSLHandle.cpp">
 8408 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
 8409 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
 8410 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
 8411 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
 8412 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
 8413 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
 8414 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
 8415 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
 8416 </ClCompile>
84078417 <ClCompile Include="..\platform\sql\SQLiteAuthorizer.cpp" />
84088418 <ClCompile Include="..\platform\sql\SQLiteDatabase.cpp" />
84098419 <ClCompile Include="..\platform\sql\SQLiteFileSystem.cpp" />
84108420 <ClCompile Include="..\platform\sql\SQLiteStatement.cpp" />
84118421 <ClCompile Include="..\platform\sql\SQLiteTransaction.cpp" />
84128422 <ClCompile Include="..\platform\sql\SQLValue.cpp" />
84138423 <ClCompile Include="..\platform\text\BidiContext.cpp" />
84148424 <ClCompile Include="..\platform\text\DateTimeFormat.cpp" />
84158425 <ClCompile Include="..\platform\text\LineEnding.cpp" />
84168426 <ClCompile Include="..\platform\text\LocaleNone.cpp" />
84178427 <ClCompile Include="..\platform\text\LocaleToScriptMappingDefault.cpp" />
84188428 <ClCompile Include="..\platform\text\PlatformLocale.cpp" />
84198429 <ClCompile Include="..\platform\text\QuotedPrintable.cpp" />
84208430 <ClCompile Include="..\platform\text\RegularExpression.cpp" />
84218431 <ClCompile Include="..\platform\text\SegmentedString.cpp" />

1954219552 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
1954319553 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
1954419554 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
1954519555 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
1954619556 </CustomBuildStep>
1954719557 <CustomBuildStep Include="..\platform\network\curl\ResourceResponse.h">
1954819558 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
1954919559 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
1955019560 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
1955119561 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
1955219562 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
1955319563 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
1955419564 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
1955519565 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
1955619566 </CustomBuildStep>
 19567 <CustomBuildStep Include="..\platform\network\curl\SSLHandle.h">
 19568 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
 19569 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
 19570 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
 19571 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
 19572 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
 19573 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
 19574 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
 19575 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
 19576 </CustomBuildStep>
1955719577 <ClInclude Include="..\platform\sql\SQLiteDatabase.h" />
1955819578 <ClInclude Include="..\platform\sql\SQLiteFileSystem.h" />
1955919579 <ClInclude Include="..\platform\sql\SQLiteStatement.h" />
1956019580 <ClInclude Include="..\platform\sql\SQLiteTransaction.h" />
1956119581 <ClInclude Include="..\platform\sql\SQLValue.h" />
1956219582 <ClInclude Include="..\platform\text\BidiContext.h" />
1956319583 <ClInclude Include="..\platform\text\BidiResolver.h" />
1956419584 <ClInclude Include="..\platform\text\BidiRunList.h" />
1956519585 <ClInclude Include="..\platform\text\DateTimeFormat.h" />
1956619586 <ClInclude Include="..\platform\text\DecodeEscapeSequences.h" />
1956719587 <ClInclude Include="..\platform\text\Hyphenation.h" />
1956819588 <ClInclude Include="..\platform\graphics\Latin1TextIterator.h" />
1956919589 <ClInclude Include="..\platform\text\LineBreakIteratorPoolICU.h" />
1957019590 <ClInclude Include="..\platform\text\LineEnding.h" />
1957119591 <ClInclude Include="..\platform\text\LocaleToScriptMapping.h" />

Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters

19141914 <ClCompile Include="..\platform\network\curl\MultipartHandle.cpp">
19151915 <Filter>platform\network\curl</Filter>
19161916 </ClCompile>
19171917 <ClCompile Include="..\platform\network\curl\ProxyServerCurl.cpp">
19181918 <Filter>platform\network\curl</Filter>
19191919 </ClCompile>
19201920 <ClCompile Include="..\platform\network\curl\ResourceHandleCurl.cpp">
19211921 <Filter>platform\network\curl</Filter>
19221922 </ClCompile>
19231923 <ClCompile Include="..\platform\network\curl\ResourceHandleManager.cpp">
19241924 <Filter>platform\network\curl</Filter>
19251925 </ClCompile>
19261926 <ClCompile Include="..\platform\network\curl\SocketStreamHandleCurl.cpp">
19271927 <Filter>platform\network\curl</Filter>
19281928 </ClCompile>
 1929 <ClCompile Include="..\platform\network\curl\SSLHandle.cpp">
 1930 <Filter>platform\network\curl</Filter>
 1931 </ClCompile>
19291932 <ClCompile Include="..\platform\sql\SQLiteAuthorizer.cpp">
19301933 <Filter>platform\sql</Filter>
19311934 </ClCompile>
19321935 <ClCompile Include="..\platform\sql\SQLiteDatabase.cpp">
19331936 <Filter>platform\sql</Filter>
19341937 </ClCompile>
19351938 <ClCompile Include="..\platform\sql\SQLiteFileSystem.cpp">
19361939 <Filter>platform\sql</Filter>
19371940 </ClCompile>
19381941 <ClCompile Include="..\platform\sql\SQLiteStatement.cpp">
19391942 <Filter>platform\sql</Filter>
19401943 </ClCompile>
19411944 <ClCompile Include="..\platform\sql\SQLiteTransaction.cpp">
19421945 <Filter>platform\sql</Filter>
19431946 </ClCompile>

1507415077 <CustomBuildStep Include="..\platform\network\curl\MultipartHandle.h">
1507515078 <Filter>platform\network\curl</Filter>
1507615079 </CustomBuildStep>
1507715080 <CustomBuildStep Include="..\platform\network\curl\ResourceError.h">
1507815081 <Filter>platform\network\curl</Filter>
1507915082 </CustomBuildStep>
1508015083 <CustomBuildStep Include="..\platform\network\curl\ResourceHandleManager.h">
1508115084 <Filter>platform\network\curl</Filter>
1508215085 </CustomBuildStep>
1508315086 <CustomBuildStep Include="..\platform\network\curl\ResourceRequest.h">
1508415087 <Filter>platform\network\curl</Filter>
1508515088 </CustomBuildStep>
1508615089 <CustomBuildStep Include="..\platform\network\curl\ResourceResponse.h">
1508715090 <Filter>platform\network\curl</Filter>
1508815091 </CustomBuildStep>
 15092 <CustomBuildStep Include="..\platform\network\curl\SSLHandle.h">
 15093 <Filter>platform\network\curl</Filter>
 15094 </CustomBuildStep>
1508915095 <CustomBuildStep Include="..\platform\image-decoders\gif\GIFImageDecoder.h">
1509015096 <Filter>platform\image-decoders\gif</Filter>
1509115097 </CustomBuildStep>
1509215098 <CustomBuildStep Include="..\platform\image-decoders\gif\GIFImageReader.h">
1509315099 <Filter>platform\image-decoders\gif</Filter>
1509415100 </CustomBuildStep>
1509515101 <CustomBuildStep Include="..\platform\image-decoders\jpeg\JPEGImageDecoder.h">
1509615102 <Filter>platform\image-decoders\jpeg</Filter>
1509715103 </CustomBuildStep>
1509815104 <CustomBuildStep Include="..\platform\image-decoders\png\PNGImageDecoder.h">
1509915105 <Filter>platform\image-decoders\png</Filter>
1510015106 </CustomBuildStep>
1510115107 <CustomBuildStep Include="..\platform\image-decoders\bmp\BMPImageDecoder.h">
1510215108 <Filter>platform\image-decoders\bmp</Filter>
1510315109 </CustomBuildStep>

Source/WebCore/platform/network/ResourceHandle.h

@@public:
139139 CFURLStorageSessionRef storageSession() const;
140140 CFURLConnectionRef connection() const;
141141 CFURLConnectionRef releaseConnectionForDownload();
142142 const ResourceRequest& currentRequest() const;
143143 static void setHostAllowsAnyHTTPSCertificate(const String&);
144144 static void setClientCertificate(const String& host, CFDataRef);
145145 static CFURLConnectionClient_V6* connectionClientCallbacks();
146146
147147#if USE(QUICK_LOOK)
148148 QuickLookHandle* quickLookHandle() { return m_quickLook.get(); }
149149 void setQuickLookHandle(PassOwnPtr<QuickLookHandle> handle) { m_quickLook = handle; }
150150#endif // USE(QUICK_LOOK)
151151
152152#endif // USE(CFNETWORK)
153153
154 #if PLATFORM(WIN) && USE(CURL)
 154#if (PLATFORM(WIN) || PLATFORM(NIX)) && USE(CURL)
155155 static void setHostAllowsAnyHTTPSCertificate(const String&);
156156#endif
157157#if PLATFORM(WIN) && USE(CURL) && USE(CF)
158158 static void setClientCertificate(const String& host, CFDataRef);
159159#endif
160160
161161 bool shouldContentSniff() const;
162162 static bool shouldContentSniffURL(const URL&);
163163
164164 static void forceContentSniffing();
165165
166166#if USE(WININET)
167167 void setSynchronousInternetHandle(HINTERNET);
168168 void fileLoadTimer(Timer<ResourceHandle>*);
169169 void onRedirect();

Source/WebCore/platform/network/ResourceHandleInternal.h

@@namespace WebCore {
9090 , m_internetHandle(0)
9191 , m_connectHandle(0)
9292 , m_requestHandle(0)
9393 , m_sentEndRequest(false)
9494 , m_bytesRemainingToWrite(0)
9595 , m_loadSynchronously(false)
9696 , m_hasReceivedResponse(false)
9797#endif
9898#if USE(CURL)
9999 , m_handle(0)
100100 , m_url(0)
101101 , m_customHeaders(0)
102102 , m_cancelled(false)
103103 , m_authFailureCount(0)
104104 , m_formDataStream(loader)
 105 , m_sslErrors(0)
105106#endif
106107#if USE(SOUP)
107108 , m_cancelled(false)
108109 , m_readBufferPtr(0)
109110 , m_readBufferSize(0)
110111 , m_bodySize(0)
111112 , m_bodyDataSent(0)
112113 , m_redirectCount(0)
113114#endif
114115#if PLATFORM(MAC)
115116 , m_startWhenScheduled(false)
116117 , m_needsSiteSpecificQuirks(false)
117118 , m_currentMacChallenge(nil)
118119#endif
119120 , m_scheduledFailureType(ResourceHandle::NoFailure)

@@namespace WebCore {
168169 Vector<char> m_formData;
169170 size_t m_bytesRemainingToWrite;
170171 bool m_loadSynchronously;
171172 bool m_hasReceivedResponse;
172173 String m_redirectUrl;
173174#endif
174175#if USE(CURL)
175176 CURL* m_handle;
176177 char* m_url;
177178 struct curl_slist* m_customHeaders;
178179 ResourceResponse m_response;
179180 bool m_cancelled;
180181 unsigned short m_authFailureCount;
181182
182183 FormDataStream m_formDataStream;
 184 unsigned m_sslErrors;
183185 Vector<char> m_postBytes;
184186
185187 OwnPtr<MultipartHandle> m_multipartHandle;
186188#endif
187189#if USE(SOUP)
188190 GRefPtr<SoupMessage> m_soupMessage;
189191 ResourceResponse m_response;
190192 bool m_cancelled;
191193 GRefPtr<SoupRequest> m_soupRequest;
192194 GRefPtr<GInputStream> m_inputStream;
193195 GRefPtr<SoupMultipartInputStream> m_multipartInputStream;
194196 GRefPtr<GCancellable> m_cancellable;
195197 GRefPtr<GAsyncResult> m_deferredResult;
196198 GRefPtr<GSource> m_timeoutSource;
197199 GOwnPtr<char> m_defaultReadBuffer;

Source/WebCore/platform/network/curl/ResourceError.h

2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2323 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2424 */
2525
2626#ifndef ResourceError_h
2727#define ResourceError_h
2828
2929#include "ResourceErrorBase.h"
3030
3131namespace WebCore {
3232
3333class ResourceError : public ResourceErrorBase
3434{
3535public:
36  ResourceError()
 36 ResourceError() : m_sslErrors(0)
3737 {
3838 }
3939
4040 ResourceError(const String& domain, int errorCode, const String& failingURL, const String& localizedDescription)
41  : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription)
 41 : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription), m_sslErrors(0)
4242 {
4343 }
 44
 45 unsigned sslErrors() const { return m_sslErrors; }
 46 void setSSLErrors(unsigned sslVerifyResult) { m_sslErrors = sslVerifyResult; }
 47
 48private:
 49 unsigned m_sslErrors;
4450};
4551
4652}
4753
4854#endif // ResourceError_h_

Source/WebCore/platform/network/curl/ResourceHandleCurl.cpp

2222 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
2323 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2424 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2525 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626 */
2727
2828#include "config.h"
2929#include "ResourceHandle.h"
3030
3131#include "CachedResourceLoader.h"
3232#include "CredentialStorage.h"
3333#include "NetworkingContext.h"
3434#include "NotImplemented.h"
3535#include "ResourceHandleInternal.h"
3636#include "ResourceHandleManager.h"
 37#include "SSLHandle.h"
3738
3839#if PLATFORM(WIN) && USE(CF)
3940#include <wtf/PassRefPtr.h>
4041#include <wtf/RetainPtr.h>
4142#endif
4243
4344namespace WebCore {
4445
4546class WebCoreSynchronousLoader : public ResourceHandleClient {
4647public:
4748 WebCoreSynchronousLoader();
4849
4950 virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
5051 virtual void didReceiveData(ResourceHandle*, const char*, int, int encodedDataLength);
5152 virtual void didFinishLoading(ResourceHandle*, double /*finishTime*/);

@@bool ResourceHandle::start()
103104 // If the frame is not null but the page is null this must be an attempted
104105 // load from an unload handler, so let's just block it.
105106 // If both the frame and the page are not null the context is valid.
106107 if (d->m_context && !d->m_context->isValid())
107108 return false;
108109
109110 ResourceHandleManager::sharedInstance()->add(this);
110111 return true;
111112}
112113
113114void ResourceHandle::cancel()
114115{
115116 ResourceHandleManager::sharedInstance()->cancel(this);
116117}
117118
118 #if PLATFORM(WIN) && USE(CF)
119 static HashSet<String>& allowsAnyHTTPSCertificateHosts()
120 {
121  static HashSet<String> hosts;
122 
123  return hosts;
124 }
125 
126119void ResourceHandle::setHostAllowsAnyHTTPSCertificate(const String& host)
127120{
128  allowsAnyHTTPSCertificateHosts().add(host.lower());
 121 allowsAnyHTTPSCertificateHosts(host.lower());
129122}
130 #endif
131123
132124#if PLATFORM(WIN) && USE(CF)
133125// FIXME: The CFDataRef will need to be something else when
134126// building without
135127static HashMap<String, RetainPtr<CFDataRef> >& clientCerts()
136128{
137129 static HashMap<String, RetainPtr<CFDataRef> > certs;
138130 return certs;
139131}
140132
141133void ResourceHandle::setClientCertificate(const String& host, CFDataRef cert)
142134{
143135 clientCerts().set(host.lower(), cert);
144136}
145137#endif

Source/WebCore/platform/network/curl/ResourceHandleManager.cpp

3434 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535 */
3636
3737#include "config.h"
3838#include "ResourceHandleManager.h"
3939
4040#include "CredentialStorage.h"
4141#include "CurlCacheManager.h"
4242#include "DataURL.h"
4343#include "HTTPParsers.h"
4444#include "MIMETypeRegistry.h"
4545#include "MultipartHandle.h"
4646#include "ResourceError.h"
4747#include "ResourceHandle.h"
4848#include "ResourceHandleInternal.h"
 49#include "SSLHandle.h"
4950
5051#if OS(WINDOWS)
5152#include "WebCoreBundleWin.h"
5253#include <shlobj.h>
5354#include <shlwapi.h>
5455#else
5556#include <sys/param.h>
5657#define MAX_PATH MAXPATHLEN
5758#endif
5859
5960#include <errno.h>
6061#include <stdio.h>
6162#if USE(CF)
6263#include <wtf/RetainPtr.h>
6364#endif

@@void ResourceHandleManager::downloadTimerCallback(Timer<ResourceHandleManager>*
610611
611612 if (d->m_multipartHandle)
612613 d->m_multipartHandle->contentEnded();
613614
614615 if (d->client()) {
615616 d->client()->didFinishLoading(job, 0);
616617 CurlCacheManager::getInstance().didFinishLoading(job->firstRequest().url().string());
617618 }
618619 } else {
619620 char* url = 0;
620621 curl_easy_getinfo(d->m_handle, CURLINFO_EFFECTIVE_URL, &url);
621622#ifndef NDEBUG
622623 fprintf(stderr, "Curl ERROR for url='%s', error: '%s'\n", url, curl_easy_strerror(msg->data.result));
623624#endif
624625 if (d->client()) {
625  d->client()->didFail(job, ResourceError(String(), msg->data.result, String(url), String(curl_easy_strerror(msg->data.result))));
 626 ResourceError resourceError(String(), msg->data.result, String(url), String(curl_easy_strerror(msg->data.result)));
 627 resourceError.setSSLErrors(d->m_sslErrors);
 628 d->client()->didFail(job, resourceError);
626629 CurlCacheManager::getInstance().didFail(job->firstRequest().url().string());
627630 }
628631 }
629632
630633 removeFromCurl(job);
631634 }
632635
633636 bool started = startScheduledJobs(); // new jobs might have been added in the meantime
634637
635638 if (!m_downloadTimer.isActive() && (started || (runningHandles > 0)))
636639 m_downloadTimer.startOneShot(pollTimeSeconds);
637640}
638641
639642void ResourceHandleManager::setProxyInfo(const String& host,
640643 unsigned long port,

@@void ResourceHandleManager::initializeHandle(ResourceHandle* job)
930933 d->m_response.setMimeType(MIMETypeRegistry::getMIMETypeForPath(url));
931934 }
932935
933936 d->m_handle = curl_easy_init();
934937
935938 if (d->m_defersLoading) {
936939 CURLcode error = curl_easy_pause(d->m_handle, CURLPAUSE_ALL);
937940 // If we did not pause the handle, we would ASSERT in the
938941 // header callback. So just assert here.
939942 ASSERT_UNUSED(error, error == CURLE_OK);
940943 }
941944#ifndef NDEBUG
942945 if (getenv("DEBUG_CURL"))
943946 curl_easy_setopt(d->m_handle, CURLOPT_VERBOSE, 1);
944947#endif
 948 curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYPEER, 1L);
 949 curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYHOST, 2L);
945950 curl_easy_setopt(d->m_handle, CURLOPT_PRIVATE, job);
946951 curl_easy_setopt(d->m_handle, CURLOPT_ERRORBUFFER, m_curlErrorBuffer);
947952 curl_easy_setopt(d->m_handle, CURLOPT_WRITEFUNCTION, writeCallback);
948953 curl_easy_setopt(d->m_handle, CURLOPT_WRITEDATA, job);
949954 curl_easy_setopt(d->m_handle, CURLOPT_HEADERFUNCTION, headerCallback);
950955 curl_easy_setopt(d->m_handle, CURLOPT_WRITEHEADER, job);
951956 curl_easy_setopt(d->m_handle, CURLOPT_AUTOREFERER, 1);
952957 curl_easy_setopt(d->m_handle, CURLOPT_FOLLOWLOCATION, 1);
953958 curl_easy_setopt(d->m_handle, CURLOPT_MAXREDIRS, 10);
954959 curl_easy_setopt(d->m_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
955960 curl_easy_setopt(d->m_handle, CURLOPT_SHARE, m_curlShareHandle);
956961 curl_easy_setopt(d->m_handle, CURLOPT_DNS_CACHE_TIMEOUT, 60 * 5); // 5 minutes
957962 curl_easy_setopt(d->m_handle, CURLOPT_PROTOCOLS, allowedProtocols);
958963 curl_easy_setopt(d->m_handle, CURLOPT_REDIR_PROTOCOLS, allowedProtocols);
959  // FIXME: Enable SSL verification when we have a way of shipping certs
960  // and/or reporting SSL errors to the user.
 964
961965 if (ignoreSSLErrors)
962966 curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYPEER, false);
 967 else
 968 setSSLVerifyOptions(job);
963969
964970 if (!m_certificatePath.isNull())
965971 curl_easy_setopt(d->m_handle, CURLOPT_CAINFO, m_certificatePath.data());
966972
967973 // enable gzip and deflate through Accept-Encoding:
968974 curl_easy_setopt(d->m_handle, CURLOPT_ENCODING, "");
969975
970976 // url must remain valid through the request
971977 ASSERT(!d->m_url);
972978
973979 // url is in ASCII so latin1() will only convert it to char* without character translation.
974980 d->m_url = fastStrDup(urlString.latin1().data());
975981 curl_easy_setopt(d->m_handle, CURLOPT_URL, d->m_url);
976982
977983 if (m_cookieJarFileName)

Source/WebCore/platform/network/curl/SSLHandle.cpp

 1/*
 2 * Copyright (C) 2013 University of Szeged
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "SSLHandle.h"
 29
 30#include "ResourceHandleInternal.h"
 31
 32#include <openssl/pem.h>
 33#include <openssl/ssl.h>
 34#include <openssl/x509_vfy.h>
 35
 36namespace WebCore {
 37
 38static HashMap<String, String> allowedHosts;
 39
 40void allowsAnyHTTPSCertificateHosts(const String& host)
 41{
 42 HashMap<String, String>::iterator it = allowedHosts.find(host);
 43 if (it != allowedHosts.end())
 44 it->value = String();
 45 else
 46 allowedHosts.add(host, String());
 47}
 48
 49bool sslIgnoreHTTPSCertificate(const String& host, const String& cert)
 50{
 51 HashMap<String, String>::iterator it = allowedHosts.find(host);
 52 if (it != allowedHosts.end()) {
 53 if ((it->value).isEmpty()) {
 54 it->value = cert;
 55 return true;
 56 }
 57 if (it->value == cert)
 58 return true;
 59 }
 60 return false;
 61}
 62
 63unsigned sslCertificateFlag(const unsigned& sslError)
 64{
 65 switch (sslError) {
 66 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT : // the issuer certificate could not be found: this occurs if the issuer certificate of an untrusted certificate cannot be found.
 67 case X509_V_ERR_UNABLE_TO_GET_CRL : // the CRL of a certificate could not be found.
 68 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY : // the issuer certificate of a locally looked up certificate could not be found. This normally means the list of trusted certificates is not complete.
 69 return SSL_CERTIFICATE_UNKNOWN_CA;
 70 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE : // the certificate signature could not be decrypted. This means that the actual signature value could not be determined rather than it not matching the expected value, this is only meaningful for RSA keys.
 71 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE : // the CRL signature could not be decrypted: this means that the actual signature value could not be determined rather than it not matching the expected value. Unused.
 72 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY : // the public key in the certificate SubjectPublicKeyInfo could not be read.
 73 case X509_V_ERR_CERT_SIGNATURE_FAILURE : // the signature of the certificate is invalid.
 74 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT : // the passed certificate is self signed and the same certificate cannot be found in the list of trusted certificates.
 75 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN : // the certificate chain could be built up using the untrusted certificates but the root could not be found locally.
 76 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE : // no signatures could be verified because the chain contains only one certificate and it is not self signed.
 77 case X509_V_ERR_INVALID_PURPOSE : // the supplied certificate cannot be used for the specified purpose.
 78 case X509_V_ERR_CERT_UNTRUSTED : // the root CA is not marked as trusted for the specified purpose.
 79 case X509_V_ERR_CERT_REJECTED : // the root CA is marked to reject the specified purpose.
 80 case X509_V_ERR_NO_EXPLICIT_POLICY : // the verification flags were set to require and explicit policy but none was present.
 81 case X509_V_ERR_DIFFERENT_CRL_SCOPE : // the only CRLs that could be found did not match the scope of the certificate.
 82 return SSL_CERTIFICATE_INSECURE;
 83 case X509_V_ERR_CERT_NOT_YET_VALID : // the certificate is not yet valid: the notBefore date is after the current time.
 84 case X509_V_ERR_CRL_NOT_YET_VALID : // the CRL is not yet valid.
 85 return SSL_CERTIFICATE_NOT_ACTIVATED;
 86 case X509_V_ERR_CERT_HAS_EXPIRED : // the certificate has expired: that is the notAfter date is before the current time.
 87 case X509_V_ERR_CRL_HAS_EXPIRED : // the CRL has expired.
 88 return SSL_CERTIFICATE_EXPIRED;
 89 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD : // the certificate notBefore field contains an invalid time.
 90 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD : // the certificate notAfter field contains an invalid time.
 91 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD : // the CRL lastUpdate field contains an invalid time.
 92 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD : // the CRL nextUpdate field contains an invalid time.
 93 case X509_V_ERR_OUT_OF_MEM : // an error occurred trying to allocate memory. This should never happen.
 94 case X509_V_ERR_CERT_CHAIN_TOO_LONG : // the certificate chain length is greater than the supplied maximum depth. Unused.
 95 case X509_V_ERR_PATH_LENGTH_EXCEEDED : // the basicConstraints pathlength parameter has been exceeded.
 96 case X509_V_ERR_INVALID_EXTENSION : // a certificate extension had an invalid value (for example an incorrect encoding) or some value inconsistent with other extensions.
 97 case X509_V_ERR_INVALID_POLICY_EXTENSION : // a certificate policies extension had an invalid value (for example an incorrect encoding) or some value inconsistent with other extensions. This error only occurs if policy processing is enabled.
 98 case X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE : // some feature of a certificate extension is not supported. Unused.
 99 case X509_V_ERR_PERMITTED_VIOLATION : // a name constraint violation occured in the permitted subtrees.
 100 case X509_V_ERR_EXCLUDED_VIOLATION : // a name constraint violation occured in the excluded subtrees.
 101 case X509_V_ERR_SUBTREE_MINMAX : // a certificate name constraints extension included a minimum or maximum field: this is not supported.
 102 case X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE : // an unsupported name constraint type was encountered. OpenSSL currently only supports directory name, DNS name, email and URI types.
 103 case X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX : // the format of the name constraint is not recognised: for example an email address format of a form not mentioned in RFC3280. This could be caused by a garbage extension or some new feature not currently supported.
 104 case X509_V_ERR_CRL_PATH_VALIDATION_ERROR : // an error occured when attempting to verify the CRL path. This error can only happen if extended CRL checking is enabled.
 105 case X509_V_ERR_APPLICATION_VERIFICATION : // an application specific error. This will never be returned unless explicitly set by an application.
 106 return SSL_CERTIFICATE_GENERIC_ERROR;
 107 case X509_V_ERR_CERT_REVOKED : // the certificate has been revoked.
 108 return SSL_CERTIFICATE_REVOKED;
 109 case X509_V_ERR_INVALID_CA : // a CA certificate is invalid. Either it is not a CA or its extensions are not consistent with the supplied purpose.
 110 case X509_V_ERR_SUBJECT_ISSUER_MISMATCH : // the current candidate issuer certificate was rejected because its subject name did not match the issuer name of the current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
 111 case X509_V_ERR_AKID_SKID_MISMATCH : // the current candidate issuer certificate was rejected because its subject key identifier was present and did not match the authority key identifier current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
 112 case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH : // the current candidate issuer certificate was rejected because its issuer name and serial number was present and did not match the authority key identifier of the current certificate. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
 113 case X509_V_ERR_KEYUSAGE_NO_CERTSIGN : // the current candidate issuer certificate was rejected because its keyUsage extension does not permit certificate signing. This is only set if issuer check debugging is enabled it is used for status notification and is not in itself an error.
 114 return SSL_CERTIFICATE_BAD_IDENTITY;
 115 default :
 116 return SSL_CERTIFICATE_GENERIC_ERROR;
 117 }
 118}
 119
 120#if !PLATFORM(WIN)
 121// success of certificate extraction
 122bool pemData(X509_STORE_CTX* ctx, String& certificate)
 123{
 124 X509* errCert = X509_STORE_CTX_get_current_cert(ctx);
 125
 126 // get the cert in PEM format
 127 BIO* bio = BIO_new(BIO_s_mem());
 128
 129 int res = PEM_write_bio_X509(bio, errCert);
 130 if (!res) {
 131 BIO_free(bio);
 132 return false;
 133 }
 134
 135 unsigned char* data;
 136 long len = BIO_get_mem_data(bio, &data);
 137 if (len < 0) {
 138 BIO_free(bio);
 139 return false;
 140 }
 141
 142 data[len] = '\0';
 143 certificate = data;
 144 BIO_free(bio);
 145 return true;
 146}
 147#endif
 148
 149static int certVerifyCallback(int ok, X509_STORE_CTX* ctx)
 150{
 151 // whether the verification of the certificate in question was passed (preverify_ok=1) or not (preverify_ok=0)
 152
 153 unsigned err = X509_STORE_CTX_get_error(ctx);
 154 if (!err)
 155 return 1;
 156
 157 SSL* ssl = reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()));
 158 SSL_CTX* sslctx = SSL_get_SSL_CTX(ssl);
 159 ResourceHandle* job = reinterpret_cast<ResourceHandle*>(SSL_CTX_get_app_data(sslctx));
 160 String host = job->firstRequest().url().host();
 161 ResourceHandleInternal* d = job->getInternal();
 162
 163 d->m_sslErrors = sslCertificateFlag(err);
 164
 165#if PLATFORM(WIN)
 166 HashMap<String, String>::iterator it = allowedHosts.find(host);
 167 ok = (it != allowedHosts.end());
 168#else
 169 String certificate;
 170 if (!pemData(ctx, certificate))
 171 return 0;
 172 ok = sslIgnoreHTTPSCertificate(host.lower(), certificate);
 173#endif
 174
 175 if (ok) {
 176 // if the host and the certificate are stored for the current handle that means is enabled,
 177 // so don't need to curl verifies the authenticity of the peer's certificate
 178 curl_easy_setopt(d->m_handle, CURLOPT_SSL_VERIFYPEER, false);
 179 }
 180 return ok;
 181}
 182
 183static CURLcode sslctxfun(CURL* curl, void* sslctx, void* parm)
 184{
 185 SSL_CTX_set_app_data(reinterpret_cast<SSL_CTX*>(sslctx), parm);
 186 SSL_CTX_set_verify(reinterpret_cast<SSL_CTX*>(sslctx), SSL_VERIFY_PEER, certVerifyCallback);
 187 return CURLE_OK;
 188}
 189
 190void setSSLVerifyOptions(ResourceHandle* handle)
 191{
 192 ResourceHandleInternal* d = handle->getInternal();
 193 curl_easy_setopt(d->m_handle, CURLOPT_SSL_CTX_DATA, handle);
 194 curl_easy_setopt(d->m_handle, CURLOPT_SSL_CTX_FUNCTION, sslctxfun);
 195}
 196
 197}

Source/WebCore/platform/network/curl/SSLHandle.h

 1/*
 2 * Copyright (C) 2013 University of Szeged
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef SSLHandle_h
 27#define SSLHandle_h
 28
 29#include "ResourceHandle.h"
 30
 31#include <wtf/text/WTFString.h>
 32
 33namespace WebCore {
 34
 35typedef enum {
 36 SSL_CERTIFICATE_UNKNOWN_CA = (1 << 0), // The signing certificate authority is not known.
 37 SSL_CERTIFICATE_BAD_IDENTITY = (1 << 1), // The certificate does not match the expected identity of the site that it was retrieved from.
 38 SSL_CERTIFICATE_NOT_ACTIVATED = (1 << 2), // The certificate's activation time is still in the future
 39 SSL_CERTIFICATE_EXPIRED = (1 << 3), // The certificate has expired
 40 SSL_CERTIFICATE_REVOKED = (1 << 4), // The certificate has been revoked
 41 SSL_CERTIFICATE_INSECURE = (1 << 5), // The certificate's algorithm is considered insecure.
 42 SSL_CERTIFICATE_GENERIC_ERROR = (1 << 6) // Some other error occurred validating the certificate
 43} SSLCertificateFlags;
 44
 45
 46void allowsAnyHTTPSCertificateHosts(const String&);
 47bool sslIgnoreHTTPSCertificate(const String&, const String&);
 48void setSSLVerifyOptions(ResourceHandle*);
 49
 50}
 51
 52#endif