Skip to content

Commit 7f5a552

Browse files
JackHowgateCCasurdej-comcast
authored andcommitted
Implemented authenticationCallback in WebKitImplementation in order to call webkit_authenticate with a pk12 certificate instead of a nullptr placeholder.
Reverts back to previous functionality if Glib version is less than 2.72 or if a certificate cannot be obtained.
1 parent 51f7ebe commit 7f5a552

File tree

1 file changed

+83
-2
lines changed

1 file changed

+83
-2
lines changed

WebKitBrowser/WebKitImplementation.cpp

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,9 +2719,90 @@ static GSourceFuncs _handlerIntervention =
27192719
}
27202720
browser->OnLoadFailed(failingURI);
27212721
}
2722-
static bool authenticationCallback(WebKitWebView*, WebKitAuthenticationRequest* request)
2722+
static bool authenticationCallback(WebKitWebView*, WebKitAuthenticationRequest* request, WebKitImplementation* browser)
27232723
{
2724+
TRACE(Trace::Information, ("AUTHENTICATION: Started Authentication callback"));
2725+
//Need to check Glib version >= 2.72, otherwise return nullptr
2726+
#if GLIB_CHECK_VERSION (2, 72, 0)
2727+
GError *error = NULL;
2728+
GTlsCertificate *cert = NULL;
2729+
std::string clientCertStr, clientCertKeyStr;
2730+
const gchar *certPath = NULL, *keyPath = NULL;
2731+
2732+
if (browser->_config.ClientCert.IsSet() == true && browser->_config.ClientCert.Value().empty() == false)
2733+
{
2734+
clientCertStr = browser->_config.ClientCert.Value().c_str();
2735+
certPath = clientCertStr.c_str();
2736+
}
2737+
2738+
if (!certPath)
2739+
goto out;
2740+
2741+
if (browser->_config.ClientCertKey.IsSet() == true && browser->_config.ClientCertKey.Value().empty() == false)
2742+
{
2743+
clientCertKeyStr = browser->_config.ClientCertKey.Value().c_str();
2744+
keyPath = clientCertKeyStr.c_str();
2745+
}
2746+
2747+
if (g_str_has_suffix(certPath, ".pk12"))
2748+
{
2749+
TRACE(Trace::Information, ("AUTHENTICATION: Cert Path accepted as pk12"));
2750+
gchar *certData, *keyData = NULL;
2751+
gsize certLen, keyLen;
2752+
if (keyPath)
2753+
{
2754+
gsize i;
2755+
if (!g_file_get_contents(keyPath, &keyData, &keyLen, &error))
2756+
goto out;
2757+
for (i = keyLen - 1; i >= 0 && g_ascii_isspace(keyData[i]); --i)
2758+
keyData[i] = '\0';
2759+
}
2760+
2761+
if (!g_file_get_contents(certPath, &certData, &certLen, &error))
2762+
{
2763+
g_free(keyData);
2764+
goto out;
2765+
}
2766+
2767+
cert = g_tls_certificate_new_from_pkcs12((guint8 *)certData, certLen, keyData, &error);
2768+
g_free(certData);
2769+
g_free(keyData);
2770+
}
2771+
else if (keyPath)
2772+
{
2773+
TRACE(Trace::Information, ("AUTHENTICATION: Certificate not pk12"));
2774+
cert = g_tls_certificate_new_from_files(certPath, keyPath, &error);
2775+
}
2776+
else
2777+
{
2778+
TRACE(Trace::Information, ("AUTHENTICATION: No key path set"));
2779+
cert = g_tls_certificate_new_from_file(certPath, &error);
2780+
}
2781+
2782+
out:
2783+
if (error)
2784+
{
2785+
TRACE(Trace::Information, ("AUTHENTICATION: Cert load failed. %s", error ? error->message : "unknown"));
2786+
g_error_free(error);
2787+
webkit_authentication_request_authenticate(request, nullptr);
2788+
}
2789+
else if(!cert)
2790+
{
2791+
TRACE(Trace::Information, ("AUTHENTICATION: No certificate provided"));
2792+
webkit_authentication_request_authenticate(request, nullptr);
2793+
}
2794+
else
2795+
{
2796+
TRACE(Trace::Information, ("AUTHENTICATION: Sending cert to webkit"));
2797+
auto *credential = webkit_credential_new_for_certificate(cert, WEBKIT_CREDENTIAL_PERSISTENCE_NONE);
2798+
webkit_authentication_request_authenticate(request, credential);
2799+
g_object_unref(cert);
2800+
webkit_credential_free(credential);
2801+
}
2802+
#else
2803+
TRACE(Trace::Information, ("AUTHENTICATION: Glib version check failed- Detected as not 2.7.2 or greater."));
27242804
webkit_authentication_request_authenticate(request, nullptr);
2805+
#endif
27252806
return TRUE;
27262807
}
27272808
static void postExitJob()
@@ -3099,7 +3180,7 @@ static GSourceFuncs _handlerIntervention =
30993180
g_signal_connect(_view, "user-message-received", reinterpret_cast<GCallback>(userMessageReceivedCallback), this);
31003181
g_signal_connect(_view, "notify::is-web-process-responsive", reinterpret_cast<GCallback>(isWebProcessResponsiveCallback), this);
31013182
g_signal_connect(_view, "load-failed", reinterpret_cast<GCallback>(loadFailedCallback), this);
3102-
g_signal_connect(_view, "authenticate", reinterpret_cast<GCallback>(authenticationCallback), nullptr);
3183+
g_signal_connect(_view, "authenticate", reinterpret_cast<GCallback>(authenticationCallback), this);
31033184

31043185
_configurationCompleted.SetState(true);
31053186

0 commit comments

Comments
 (0)