2017-10-26 22:08:41 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2017-05-05 00:48:34 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/WebAuthnTransactionParent.h"
|
|
|
|
#include "mozilla/dom/U2FTokenManager.h"
|
2017-12-05 18:05:06 +00:00
|
|
|
#include "mozilla/ipc/PBackgroundParent.h"
|
2017-10-10 16:31:30 +00:00
|
|
|
#include "mozilla/ipc/BackgroundParent.h"
|
2017-05-05 00:48:34 +00:00
|
|
|
|
2019-01-21 01:10:44 +00:00
|
|
|
#ifdef OS_WIN
|
|
|
|
# include "WinWebAuthnManager.h"
|
|
|
|
#endif
|
|
|
|
|
2017-05-05 00:48:34 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-10-25 13:59:53 +00:00
|
|
|
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestRegister(
|
|
|
|
const uint64_t& aTransactionId,
|
2017-11-29 12:58:33 +00:00
|
|
|
const WebAuthnMakeCredentialInfo& aTransactionInfo) {
|
2017-10-10 16:31:30 +00:00
|
|
|
AssertIsOnBackgroundThread();
|
2019-01-21 01:10:44 +00:00
|
|
|
|
|
|
|
#ifdef OS_WIN
|
|
|
|
if (WinWebAuthnManager::AreWebAuthNApisAvailable()) {
|
|
|
|
WinWebAuthnManager* mgr = WinWebAuthnManager::Get();
|
|
|
|
mgr->Register(this, aTransactionId, aTransactionInfo);
|
|
|
|
} else {
|
|
|
|
U2FTokenManager* mgr = U2FTokenManager::Get();
|
|
|
|
mgr->Register(this, aTransactionId, aTransactionInfo);
|
|
|
|
}
|
|
|
|
#else
|
2017-05-05 00:48:34 +00:00
|
|
|
U2FTokenManager* mgr = U2FTokenManager::Get();
|
2017-10-25 13:59:53 +00:00
|
|
|
mgr->Register(this, aTransactionId, aTransactionInfo);
|
2019-01-21 01:10:44 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-05 00:48:34 +00:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-10-25 13:59:53 +00:00
|
|
|
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestSign(
|
|
|
|
const uint64_t& aTransactionId,
|
2017-11-29 12:58:33 +00:00
|
|
|
const WebAuthnGetAssertionInfo& aTransactionInfo) {
|
2017-10-10 16:31:30 +00:00
|
|
|
AssertIsOnBackgroundThread();
|
2019-01-21 01:10:44 +00:00
|
|
|
|
|
|
|
#ifdef OS_WIN
|
|
|
|
if (WinWebAuthnManager::AreWebAuthNApisAvailable()) {
|
|
|
|
WinWebAuthnManager* mgr = WinWebAuthnManager::Get();
|
|
|
|
mgr->Sign(this, aTransactionId, aTransactionInfo);
|
|
|
|
} else {
|
|
|
|
U2FTokenManager* mgr = U2FTokenManager::Get();
|
|
|
|
mgr->Sign(this, aTransactionId, aTransactionInfo);
|
|
|
|
}
|
|
|
|
#else
|
2017-05-05 00:48:34 +00:00
|
|
|
U2FTokenManager* mgr = U2FTokenManager::Get();
|
2017-10-25 13:59:53 +00:00
|
|
|
mgr->Sign(this, aTransactionId, aTransactionInfo);
|
2019-01-21 01:10:44 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-05 00:48:34 +00:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-10-25 13:59:53 +00:00
|
|
|
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestCancel(
|
|
|
|
const uint64_t& aTransactionId) {
|
2017-10-10 16:31:30 +00:00
|
|
|
AssertIsOnBackgroundThread();
|
2019-01-21 01:10:44 +00:00
|
|
|
|
|
|
|
#ifdef OS_WIN
|
|
|
|
if (WinWebAuthnManager::AreWebAuthNApisAvailable()) {
|
|
|
|
WinWebAuthnManager* mgr = WinWebAuthnManager::Get();
|
|
|
|
mgr->Cancel(this, aTransactionId);
|
|
|
|
} else {
|
|
|
|
U2FTokenManager* mgr = U2FTokenManager::Get();
|
|
|
|
mgr->Cancel(this, aTransactionId);
|
|
|
|
}
|
|
|
|
#else
|
2017-05-05 00:48:34 +00:00
|
|
|
U2FTokenManager* mgr = U2FTokenManager::Get();
|
2017-10-25 13:59:53 +00:00
|
|
|
mgr->Cancel(this, aTransactionId);
|
2019-01-21 01:10:44 +00:00
|
|
|
#endif
|
|
|
|
|
2017-05-05 00:48:34 +00:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-12-05 18:05:06 +00:00
|
|
|
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvDestroyMe() {
|
|
|
|
AssertIsOnBackgroundThread();
|
|
|
|
|
|
|
|
// The child was disconnected from the WebAuthnManager instance and will send
|
|
|
|
// no further messages. It is kept alive until we delete it explicitly.
|
|
|
|
|
|
|
|
// The child should have cancelled any active transaction. This means
|
|
|
|
// we expect no more messages to the child. We'll crash otherwise.
|
|
|
|
|
|
|
|
// The IPC roundtrip is complete. No more messages, hopefully.
|
|
|
|
IProtocol* mgr = Manager();
|
|
|
|
if (!Send__delete__(this)) {
|
|
|
|
return IPC_FAIL_NO_REASON(mgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-05-05 00:48:34 +00:00
|
|
|
void WebAuthnTransactionParent::ActorDestroy(ActorDestroyReason aWhy) {
|
2017-10-10 16:31:30 +00:00
|
|
|
AssertIsOnBackgroundThread();
|
2017-12-05 18:05:06 +00:00
|
|
|
|
|
|
|
// Called either by Send__delete__() in RecvDestroyMe() above, or when
|
|
|
|
// the channel disconnects. Ensure the token manager forgets about us.
|
|
|
|
|
2019-01-21 01:10:44 +00:00
|
|
|
#ifdef OS_WIN
|
|
|
|
if (WinWebAuthnManager::AreWebAuthNApisAvailable()) {
|
|
|
|
WinWebAuthnManager* mgr = WinWebAuthnManager::Get();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->MaybeClearTransaction(this);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
U2FTokenManager* mgr = U2FTokenManager::Get();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->MaybeClearTransaction(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
U2FTokenManager* mgr = U2FTokenManager::Get();
|
2017-12-05 18:05:06 +00:00
|
|
|
if (mgr) {
|
|
|
|
mgr->MaybeClearTransaction(this);
|
|
|
|
}
|
2019-01-21 01:10:44 +00:00
|
|
|
#endif
|
2017-05-05 00:48:34 +00:00
|
|
|
}
|
2017-12-05 18:05:06 +00:00
|
|
|
|
2017-05-05 00:48:34 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|