WebCredentialsMessengerProxy.cpp [plain text]
#include "config.h"
#include "WebCredentialsMessengerProxy.h"
#if ENABLE(WEB_AUTHN)
#include "WebCredentialsMessengerMessages.h"
#include "WebCredentialsMessengerProxyMessages.h"
#include "WebPageProxy.h"
#include "WebProcessProxy.h"
#include <WebCore/ExceptionData.h>
#include <WebCore/LocalAuthenticator.h>
namespace WebKit {
WebCredentialsMessengerProxy::WebCredentialsMessengerProxy(WebPageProxy& webPageProxy)
: m_webPageProxy(webPageProxy)
{
m_webPageProxy.process().addMessageReceiver(Messages::WebCredentialsMessengerProxy::messageReceiverName(), m_webPageProxy.pageID(), *this);
m_authenticator = std::make_unique<WebCore::LocalAuthenticator>();
}
WebCredentialsMessengerProxy::~WebCredentialsMessengerProxy()
{
m_webPageProxy.process().removeMessageReceiver(Messages::WebCredentialsMessengerProxy::messageReceiverName(), m_webPageProxy.pageID());
}
void WebCredentialsMessengerProxy::makeCredential(uint64_t messageId, const Vector<uint8_t>& hash, const WebCore::PublicKeyCredentialCreationOptions& options)
{
if (!m_authenticator) {
exceptionReply(messageId, { WebCore::NotAllowedError, "No avaliable authenticators."_s });
return;
}
auto weakThis = makeWeakPtr(*this);
auto callback = [weakThis, messageId] (const Vector<uint8_t>& credentialId, const Vector<uint8_t>& attestationObject) {
if (!weakThis)
return;
weakThis->makeCredentialReply(messageId, credentialId, attestationObject);
};
auto exceptionCallback = [weakThis, messageId] (const WebCore::ExceptionData& exception) {
if (!weakThis)
return;
weakThis->exceptionReply(messageId, exception);
};
m_authenticator->makeCredential(hash, options, WTFMove(callback), WTFMove(exceptionCallback));
}
void WebCredentialsMessengerProxy::getAssertion(uint64_t messageId, const Vector<uint8_t>& hash, const WebCore::PublicKeyCredentialRequestOptions& options)
{
if (!m_authenticator)
exceptionReply(messageId, { WebCore::NotAllowedError, "No avaliable authenticators."_s });
auto weakThis = makeWeakPtr(*this);
auto callback = [weakThis, messageId] (const Vector<uint8_t>& credentialId, const Vector<uint8_t>& authenticatorData, const Vector<uint8_t>& signature, const Vector<uint8_t>& userHandle) {
if (weakThis)
weakThis->getAssertionReply(messageId, credentialId, authenticatorData, signature, userHandle);
};
auto exceptionCallback = [weakThis, messageId] (const WebCore::ExceptionData& exception) {
if (weakThis)
weakThis->exceptionReply(messageId, exception);
};
m_authenticator->getAssertion(hash, options, WTFMove(callback), WTFMove(exceptionCallback));
}
void WebCredentialsMessengerProxy::isUserVerifyingPlatformAuthenticatorAvailable(uint64_t messageId)
{
if (!m_authenticator) {
isUserVerifyingPlatformAuthenticatorAvailableReply(messageId, false);
return;
}
isUserVerifyingPlatformAuthenticatorAvailableReply(messageId, m_authenticator->isAvailable());
}
void WebCredentialsMessengerProxy::exceptionReply(uint64_t messageId, const WebCore::ExceptionData& exception)
{
m_webPageProxy.send(Messages::WebCredentialsMessenger::ExceptionReply(messageId, exception));
}
void WebCredentialsMessengerProxy::makeCredentialReply(uint64_t messageId, const Vector<uint8_t>& credentialId, const Vector<uint8_t>& attestationObject)
{
m_webPageProxy.send(Messages::WebCredentialsMessenger::MakeCredentialReply(messageId, credentialId, attestationObject));
}
void WebCredentialsMessengerProxy::getAssertionReply(uint64_t messageId, const Vector<uint8_t>& credentialId, const Vector<uint8_t>& authenticatorData, const Vector<uint8_t>& signature, const Vector<uint8_t>& userHandle)
{
m_webPageProxy.send(Messages::WebCredentialsMessenger::GetAssertionReply(messageId, credentialId, authenticatorData, signature, userHandle));
}
void WebCredentialsMessengerProxy::isUserVerifyingPlatformAuthenticatorAvailableReply(uint64_t messageId, bool result)
{
m_webPageProxy.send(Messages::WebCredentialsMessenger::IsUserVerifyingPlatformAuthenticatorAvailableReply(messageId, result));
}
}
#endif // ENABLE(WEB_AUTHN)