void trust_user_certs(WebKitWebContext *wc) { GTlsCertificate *cert; const gchar *basedir, *file, *absfile; GDir *dir; basedir = g_build_filename(g_get_user_config_dir(), __NAME__, "certs", NULL); dir = g_dir_open(basedir, 0, NULL); if (dir != NULL) { file = g_dir_read_name(dir); while (file != NULL) { absfile = g_build_filename(g_get_user_config_dir(), __NAME__, "certs", file, NULL); cert = g_tls_certificate_new_from_file(absfile, NULL); if (cert == NULL) fprintf(stderr, __NAME__": Could not load trusted cert '%s'\n", file); else webkit_web_context_allow_tls_certificate_for_host(wc, cert, file); file = g_dir_read_name(dir); } g_dir_close(dir); } }
static void testLoadFailedWithTLSErrors(TLSErrorsTest* test, gconstpointer) { WebKitWebContext* context = webkit_web_view_get_context(test->m_webView); WebKitTLSErrorsPolicy originalPolicy = webkit_web_context_get_tls_errors_policy(context); webkit_web_context_set_tls_errors_policy(context, WEBKIT_TLS_ERRORS_POLICY_FAIL); // The load-failed-with-tls-errors signal should be emitted when there is a TLS failure. test->loadURI(kHttpsServer->getURIForPath("/test-tls/").data()); test->waitUntilLoadFinished(); g_assert(G_IS_TLS_CERTIFICATE(test->certificate())); g_assert_cmpuint(test->tlsErrors(), ==, G_TLS_CERTIFICATE_UNKNOWN_CA); g_assert_cmpstr(test->host(), ==, soup_uri_get_host(kHttpsServer->baseURI())); g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadFailedWithTLSErrors); g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); // Test allowing an exception for this certificate on this host. webkit_web_context_allow_tls_certificate_for_host(context, test->certificate(), test->host()); // The page should now load without errors. test->loadURI(kHttpsServer->getURIForPath("/test-tls/").data()); test->waitUntilLoadFinished(); g_assert_cmpint(test->m_loadEvents[0], ==, LoadTrackingTest::ProvisionalLoadStarted); g_assert_cmpint(test->m_loadEvents[1], ==, LoadTrackingTest::LoadCommitted); g_assert_cmpint(test->m_loadEvents[2], ==, LoadTrackingTest::LoadFinished); g_assert_cmpstr(webkit_web_view_get_title(test->m_webView), ==, TLSExpectedSuccessTitle); webkit_web_context_set_tls_errors_policy(context, originalPolicy); }