Source/WebCore/ChangeLog

 12018-11-16 Basuke Suzuki <basuke.suzuki@sony.com>
 2
 3 [Curl] Add API for CertificateInfo.
 4 https://bugs.webkit.org/show_bug.cgi?id=191647
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Minor changes for WebKit API.
 9
 10 Tests: TestWebKitAPI/Tests/WebKit/curl/Certificates.cpp
 11
 12 * platform/network/curl/CertificateInfo.h:
 13 * platform/network/curl/CertificateInfoCurl.cpp:
 14 (WebCore::CertificateInfo::CertificateInfo):
 15 (WebCore::CertificateInfo::makeCertificate):
 16 * platform/network/curl/CurlSSLVerifier.cpp:
 17 (WebCore::BIOHolder::asCertificate):
 18
1192018-11-14 Timothy Hatcher <timothy@apple.com>
220
321 Update prefers-color-scheme media query matching based on GitHub issue #3278.

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

@@namespace WebCore {
3434class CertificateInfo : public CertificateInfoBase {
3535public:
3636 using Certificate = Vector<uint8_t>;
 37 using CertificateChain = Vector<Certificate>;
3738
3839 CertificateInfo() = default;
39  WEBCORE_EXPORT CertificateInfo(int verificationError, Vector<Certificate>&&);
 40 WEBCORE_EXPORT CertificateInfo(int verificationError, CertificateChain&&);
4041
4142 WEBCORE_EXPORT CertificateInfo isolatedCopy() const;
4243

@@public:
4950
5051 bool isEmpty() const { return m_certificateChain.isEmpty(); }
5152
52  static Certificate makeCertificate(const char*, size_t);
 53 static Certificate makeCertificate(const uint8_t*, size_t);
5354
5455private:
5556 int m_verificationError { 0 };
56  Vector<Certificate> m_certificateChain;
 57 CertificateChain m_certificateChain;
5758};
5859
5960inline bool operator==(const CertificateInfo& a, const CertificateInfo& b)

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

3232
3333namespace WebCore {
3434
35 CertificateInfo::CertificateInfo(int verificationError, Vector<Certificate>&& certificateChain)
 35CertificateInfo::CertificateInfo(int verificationError, CertificateChain&& certificateChain)
3636 : m_verificationError(verificationError)
3737 , m_certificateChain(WTFMove(certificateChain))
3838{

@@CertificateInfo CertificateInfo::isolatedCopy() const
4343 return { m_verificationError, crossThreadCopy(m_certificateChain) };
4444}
4545
46 CertificateInfo::Certificate CertificateInfo::makeCertificate(const char* buffer, size_t size)
 46CertificateInfo::Certificate CertificateInfo::makeCertificate(const uint8_t* buffer, size_t size)
4747{
4848 Certificate certificate;
4949 certificate.append(buffer, size);

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

@@public:
117117 bool write(X509* data) { return PEM_write_bio_X509(m_bio, data); }
118118 CertificateInfo::Certificate asCertificate()
119119 {
120  char* data;
 120 uint8_t* data;
121121 long length = BIO_get_mem_data(m_bio, &data);
122122 if (length < 0)
123123 return CertificateInfo::Certificate();

Source/WebKit/ChangeLog

 12018-11-16 Basuke Suzuki <basuke.suzuki@sony.com>
 2
 3 [Curl] Add API for CertificateInfo.
 4 https://bugs.webkit.org/show_bug.cgi?id=191647
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Added API for CertificateInfo to create, fetch contents.
 9
 10 Tests: TestWebKitAPI/Tests/WebKit/curl/Certificates.cpp
 11
 12 * PlatformWin.cmake:
 13 * Shared/API/c/curl/WKCertificateInfoCurl.cpp: Added.
 14 (WKCertificateInfoCreateWithCertficateChain):
 15 (WKCertificateInfoGetVerificationError):
 16 (WKCertificateInfoGetCertificateChainSize):
 17 (WKCertificateInfoCopyCertificateAtIndex):
 18 * Shared/API/c/curl/WKCertificateInfoCurl.h: Copied from Source/WebCore/platform/network/curl/CertificateInfoCurl.cpp.
 19 * Shared/curl/WebCoreArgumentCodersCurl.cpp:
 20 (IPC::ArgumentCoder<CertificateInfo>::encode):
 21 (IPC::ArgumentCoder<CertificateInfo>::decode):
 22
1232018-11-14 Joseph Pecoraro <pecoraro@apple.com>
224
325 Unreviewed attempted wincairo build fix after 238192.

Source/WebKit/PlatformWin.cmake

@@list(APPEND WebKit_SOURCES
1919 Platform/win/ModuleWin.cpp
2020 Platform/win/SharedMemoryWin.cpp
2121
 22 Shared/API/c/curl/WKCertificateInfoCurl.cpp
 23
2224 Shared/Plugins/Netscape/NetscapePluginModuleNone.cpp
2325
2426 Shared/win/ChildProcessMainWin.cpp

@@set(WebKit_FORWARDING_HEADERS_DIRECTORIES
202204 UIProcess/API/C
203205 UIProcess/API/cpp
204206
205  UIProcess/API/C/curl
206207 UIProcess/API/C/win
207208
208209 WebProcess/InjectedBundle/API/c
209210)
210211
 212if (${WTF_PLATFORM_WIN_CAIRO})
 213 list(APPEND WebKit_FORWARDING_HEADERS_DIRECTORIES
 214 Shared/API/c/curl
 215
 216 UIProcess/API/C/curl
 217 )
 218endif ()
 219
211220WEBKIT_MAKE_FORWARDING_HEADERS(WebKit
212221 DIRECTORIES ${WebKit_FORWARDING_HEADERS_DIRECTORIES}
213222 FLATTENED

Source/WebKit/Shared/API/c/curl/WKCertificateInfoCurl.cpp

 1/*
 2 * Copyright (C) 2018 Sony Interactive Entertainment Inc.
 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 APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "WKCertificateInfoCurl.h"
 28
 29#include "APIData.h"
 30#include "WKAPICast.h"
 31#include "WKArray.h"
 32#include "WKData.h"
 33#include "WebCertificateInfo.h"
 34
 35#include <WebCore/CertificateInfo.h>
 36
 37using namespace WebKit;
 38
 39using Certificate = Vector<uint8_t>;
 40using CertificateChain = Vector<Certificate>;
 41
 42WKCertificateInfoRef WKCertificateInfoCreateWithCertficateChain(WKArrayRef certificateChainRef)
 43{
 44 CertificateChain certificateChain;
 45 for (int i = 0, count = WKArrayGetSize(certificateChainRef); i < count; i++) {
 46 auto data = reinterpret_cast<WKDataRef>(WKArrayGetItemAtIndex(certificateChainRef, i));
 47 auto certificate = WebCore::CertificateInfo::makeCertificate(WKDataGetBytes(data), WKDataGetSize(data));
 48 certificateChain.append(WTFMove(certificate));
 49 }
 50
 51 WebCore::CertificateInfo certificateInfo { 0, WTFMove(certificateChain) };
 52 RefPtr<WebKit::WebCertificateInfo> certificateInfoRef = WebKit::WebCertificateInfo::create(certificateInfo);
 53 return WebKit::toAPI(certificateInfoRef.leakRef());
 54}
 55
 56int WKCertificateInfoGetVerificationError(WKCertificateInfoRef certificateInfoRef)
 57{
 58 return toImpl(certificateInfoRef)->certificateInfo().verificationError();
 59}
 60
 61size_t WKCertificateInfoGetCertificateChainSize(WKCertificateInfoRef certificateInfoRef)
 62{
 63 return toImpl(certificateInfoRef)->certificateInfo().certificateChain().size();
 64}
 65
 66WKDataRef WKCertificateInfoCopyCertificateAtIndex(WKCertificateInfoRef certificateInfoRef, size_t index)
 67{
 68 if (toImpl(certificateInfoRef)->certificateInfo().certificateChain().size() <= index)
 69 return WebKit::toAPI(&API::Data::create(nullptr, 0).leakRef());
 70
 71 const auto& certificate = toImpl(certificateInfoRef)->certificateInfo().certificateChain().at(index);
 72 return WebKit::toAPI(&API::Data::create(reinterpret_cast<const unsigned char*>(certificate.data()), certificate.size()).leakRef());
 73}

Source/WebKit/Shared/API/c/curl/WKCertificateInfoCurl.h

 1/*
 2 * Copyright (C) 2018 Sony Interactive Entertainment Inc.
 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 APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#pragma once
 27
 28#include <WebKit/WKBase.h>
 29
 30#ifdef __cplusplus
 31extern "C" {
 32#endif
 33
 34WK_EXPORT WKCertificateInfoRef WKCertificateInfoCreateWithCertficateChain(WKArrayRef);
 35
 36WK_EXPORT int WKCertificateInfoGetVerificationError(WKCertificateInfoRef);
 37WK_EXPORT size_t WKCertificateInfoGetCertificateChainSize(WKCertificateInfoRef);
 38WK_EXPORT WKDataRef WKCertificateInfoCopyCertificateAtIndex(WKCertificateInfoRef, size_t);
 39
 40#ifdef __cplusplus
 41}
 42#endif

Source/WebKit/Shared/curl/WebCoreArgumentCodersCurl.cpp

@@bool ArgumentCoder<ResourceRequest>::decodePlatformData(Decoder& decoder, Resour
4848 return resourceRequest.decodeWithPlatformData(decoder);
4949}
5050
51 void ArgumentCoder<CertificateInfo>::encode(Encoder&, const CertificateInfo&)
 51void ArgumentCoder<CertificateInfo>::encode(Encoder& encoder, const CertificateInfo& certificateInfo)
5252{
 53 encoder << certificateInfo.verificationError();
 54 encoder << certificateInfo.certificateChain().size();
 55
 56 for (auto certificate : certificateInfo.certificateChain())
 57 encoder << certificate;
5358}
5459
55 bool ArgumentCoder<CertificateInfo>::decode(Decoder&, CertificateInfo&)
 60bool ArgumentCoder<CertificateInfo>::decode(Decoder& decoder, CertificateInfo& certificateInfo)
5661{
 62 int verificationError;
 63 if (!decoder.decode(verificationError))
 64 return false;
 65
 66 size_t certificateChainSize;
 67 if (!decoder.decode(certificateChainSize))
 68 return false;
 69
 70 CertificateInfo::CertificateChain certificateChain;
 71 for (size_t i = 0; i < certificateChainSize; i++) {
 72 CertificateInfo::Certificate certificate;
 73 if (!decoder.decode(certificate))
 74 return false;
 75
 76 certificateChain.append(certificate);
 77 }
 78
 79 certificateInfo = CertificateInfo { verificationError, WTFMove(certificateChain) };
 80
5781 return true;
5882}
5983

Tools/ChangeLog

 12018-11-16 Basuke Suzuki <basuke.suzuki@sony.com>
 2
 3 [Curl] Add API for CertificateInfo.
 4 https://bugs.webkit.org/show_bug.cgi?id=191647
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Added test for new WKCertificateInfo API.
 9
 10 * TestWebKitAPI/PlatformWin.cmake:
 11 * TestWebKitAPI/Tests/WebKit/curl/Certificates.cpp: Added.
 12 (TestWebKitAPI::Curl::makeCertificateInfo):
 13 (TestWebKitAPI::Curl::isSamePEM):
 14 (TestWebKitAPI::Curl::TEST):
 15
1162018-11-14 Alex Christensen <achristensen@webkit.org>
217
318 Add SPI to show a safe browsing warning

Tools/TestWebKitAPI/PlatformWin.cmake

@@if (ENABLE_WEBKIT)
189189 ${TESTWEBKITAPI_DIR}/win/UtilitiesWin.cpp
190190 )
191191
 192 if (${WTF_PLATFORM_WIN_CAIRO})
 193 list(APPEND test_webkit_api_SOURCES
 194 ${TESTWEBKITAPI_DIR}/Tests/WebKit/curl/Certificates.cpp
 195 )
 196 endif ()
 197
192198 add_library(TestWebKitLib SHARED
193199 ${TESTWEBKITAPI_DIR}/win/main.cpp
194200 ${test_webkit_api_SOURCES}

Tools/TestWebKitAPI/Tests/WebKit/curl/Certificates.cpp

 1/*
 2 * Copyright (C) 2018 Sony Interactive Entertainment Inc.
 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 APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#if USE(CURL)
 29
 30#include "WTFStringUtilities.h"
 31#include <WebKit/WKCertificateInfo.h>
 32#include <WebKit/WKCertificateInfoCurl.h>
 33#include <WebKit/WKRetainPtr.h>
 34#include <WebKit/WKSharedAPICast.h>
 35
 36using namespace WebCore;
 37
 38namespace TestWebKitAPI {
 39
 40namespace Curl {
 41
 42static const char* PEM1 =
 43 "-----BEGIN CERTIFICATE-----\n"
 44 "MIIBsjCCAVygAwIBAgIJALO5qdAF7ldHMA0GCSqGSIb3DQEBCwUAMDMxCzAJBgNV\n"
 45 "BAYTAlVTMRMwEQYDVQQIDApDYWxpZm9ybmlhMQ8wDQYDVQQKDAZXZWJLaXQwHhcN\n"
 46 "MTgxMTE2MDEwMDM4WhcNMjgwODE1MDEwMDM4WjAzMQswCQYDVQQGEwJVUzETMBEG\n"
 47 "A1UECAwKQ2FsaWZvcm5pYTEPMA0GA1UECgwGV2ViS2l0MFwwDQYJKoZIhvcNAQEB\n"
 48 "BQADSwAwSAJBAOfoq7BspXakZ1EFEIkw+PqcX0KkichT0DK/6ghxdbcS5TDGnUOM\n"
 49 "rfYhnI/vzKMcrvOXmqyYRGj7FwthWkX9FfMCAwEAAaNTMFEwHQYDVR0OBBYEFArX\n"
 50 "jKITLym24m6IwYv6F5Gg5yw3MB8GA1UdIwQYMBaAFArXjKITLym24m6IwYv6F5Gg\n"
 51 "5yw3MA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQELBQADQQC8pO97bNmeMb0P\n"
 52 "m+Yvc7eI6Vu2eXpNUIUSHHn7f+Hj584ZeG7gMgCeJqlEeFs9zM3uQMhn4+Nd7pDa\n"
 53 "GdGdcOzA\n"
 54 "-----END CERTIFICATE-----\n";
 55
 56static const char* PEM2 =
 57 "-----BEGIN CERTIFICATE-----\n"
 58 "MIIBVDCB/wIJAPATaMb5RLofMA0GCSqGSIb3DQEBCwUAMDMxCzAJBgNVBAYTAlVT\n"
 59 "MRMwEQYDVQQIDApDYWxpZm9ybmlhMQ8wDQYDVQQKDAZXZWJLaXQwHhcNMTgxMTE2\n"
 60 "MDEwNDAxWhcNMjgxMTEzMDEwNDAxWjAwMQswCQYDVQQGEwJKUDEOMAwGA1UECAwF\n"
 61 "VG9reW8xETAPBgNVBAoMCFdlYktpdEpQMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJB\n"
 62 "AK9SYK8fewlFAFU9EMnE6zQSNlqVMhaKiaxBFK8qdoK5iFdEffC+4may1sdSujNr\n"
 63 "m4uOGBpgTMcjeDWjorItMMECAwEAATANBgkqhkiG9w0BAQsFAANBACsY4D8ieDvJ\n"
 64 "gdTpbzgAqF0YyNGbWAWQ75ELVhZS3RJgwV5jTe+wc7zB12BIyzexoHzzlWpqU6Y5\n"
 65 "iA28XceqQR0=\n"
 66 "-----END CERTIFICATE-----\n";
 67
 68static auto makeCertificateInfo(std::vector<const char*> pems)
 69{
 70 auto certificateChain = adoptWK(WKMutableArrayCreate());
 71
 72 for (auto pem : pems) {
 73 auto data = adoptWK(WKDataCreate(reinterpret_cast<const uint8_t*>(pem), std::strlen(pem)));
 74 WKArrayAppendItem(certificateChain.get(), data.get());
 75 }
 76
 77 return WKCertificateInfoCreateWithCertficateChain(certificateChain.get());
 78}
 79
 80static bool isSamePEM(WKDataRef data, const char* pem)
 81{
 82 size_t size = std::strlen(pem);
 83 if (size != WKDataGetSize(data))
 84 return false;
 85
 86 return !std::memcmp(WKDataGetBytes(data), pem, size);
 87}
 88
 89TEST(Curl, CertificateAPI)
 90{
 91 auto certificateInfo = adoptWK(makeCertificateInfo({ PEM1, PEM2 }));
 92
 93 auto size = WKCertificateInfoGetCertificateChainSize(certificateInfo.get());
 94 ASSERT_EQ(size, 2);
 95 ASSERT_TRUE(isSamePEM(WKCertificateInfoCopyCertificateAtIndex(certificateInfo.get(), 0), PEM1));
 96 ASSERT_TRUE(isSamePEM(WKCertificateInfoCopyCertificateAtIndex(certificateInfo.get(), 1), PEM2));
 97}
 98
 99}
 100
 101} // namespace TestWebKitAPI
 102
 103#endif // USE(CURL)