Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "mozilla/dom/WebAuthnTransactionParent.h"
8
#include "mozilla/dom/U2FTokenManager.h"
9
#include "mozilla/ipc/PBackgroundParent.h"
10
#include "mozilla/ipc/BackgroundParent.h"
11
12
#ifdef OS_WIN
13
# include "WinWebAuthnManager.h"
14
#endif
15
16
namespace mozilla {
17
namespace dom {
18
19
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestRegister(
20
const uint64_t& aTransactionId,
21
const WebAuthnMakeCredentialInfo& aTransactionInfo) {
22
AssertIsOnBackgroundThread();
23
24
#ifdef OS_WIN
25
if (WinWebAuthnManager::AreWebAuthNApisAvailable()) {
26
WinWebAuthnManager* mgr = WinWebAuthnManager::Get();
27
mgr->Register(this, aTransactionId, aTransactionInfo);
28
} else {
29
U2FTokenManager* mgr = U2FTokenManager::Get();
30
mgr->Register(this, aTransactionId, aTransactionInfo);
31
}
32
#else
33
U2FTokenManager* mgr = U2FTokenManager::Get();
34
mgr->Register(this, aTransactionId, aTransactionInfo);
35
#endif
36
37
return IPC_OK();
38
}
39
40
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestSign(
41
const uint64_t& aTransactionId,
42
const WebAuthnGetAssertionInfo& aTransactionInfo) {
43
AssertIsOnBackgroundThread();
44
45
#ifdef OS_WIN
46
if (WinWebAuthnManager::AreWebAuthNApisAvailable()) {
47
WinWebAuthnManager* mgr = WinWebAuthnManager::Get();
48
mgr->Sign(this, aTransactionId, aTransactionInfo);
49
} else {
50
U2FTokenManager* mgr = U2FTokenManager::Get();
51
mgr->Sign(this, aTransactionId, aTransactionInfo);
52
}
53
#else
54
U2FTokenManager* mgr = U2FTokenManager::Get();
55
mgr->Sign(this, aTransactionId, aTransactionInfo);
56
#endif
57
58
return IPC_OK();
59
}
60
61
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvRequestCancel(
62
const uint64_t& aTransactionId) {
63
AssertIsOnBackgroundThread();
64
65
#ifdef OS_WIN
66
if (WinWebAuthnManager::AreWebAuthNApisAvailable()) {
67
WinWebAuthnManager* mgr = WinWebAuthnManager::Get();
68
mgr->Cancel(this, aTransactionId);
69
} else {
70
U2FTokenManager* mgr = U2FTokenManager::Get();
71
mgr->Cancel(this, aTransactionId);
72
}
73
#else
74
U2FTokenManager* mgr = U2FTokenManager::Get();
75
mgr->Cancel(this, aTransactionId);
76
#endif
77
78
return IPC_OK();
79
}
80
81
mozilla::ipc::IPCResult WebAuthnTransactionParent::RecvDestroyMe() {
82
AssertIsOnBackgroundThread();
83
84
// The child was disconnected from the WebAuthnManager instance and will send
85
// no further messages. It is kept alive until we delete it explicitly.
86
87
// The child should have cancelled any active transaction. This means
88
// we expect no more messages to the child. We'll crash otherwise.
89
90
// The IPC roundtrip is complete. No more messages, hopefully.
91
IProtocol* mgr = Manager();
92
if (!Send__delete__(this)) {
93
return IPC_FAIL_NO_REASON(mgr);
94
}
95
96
return IPC_OK();
97
}
98
99
void WebAuthnTransactionParent::ActorDestroy(ActorDestroyReason aWhy) {
100
AssertIsOnBackgroundThread();
101
102
// Called either by Send__delete__() in RecvDestroyMe() above, or when
103
// the channel disconnects. Ensure the token manager forgets about us.
104
105
#ifdef OS_WIN
106
if (WinWebAuthnManager::AreWebAuthNApisAvailable()) {
107
WinWebAuthnManager* mgr = WinWebAuthnManager::Get();
108
if (mgr) {
109
mgr->MaybeClearTransaction(this);
110
}
111
} else {
112
U2FTokenManager* mgr = U2FTokenManager::Get();
113
if (mgr) {
114
mgr->MaybeClearTransaction(this);
115
}
116
}
117
#else
118
U2FTokenManager* mgr = U2FTokenManager::Get();
119
if (mgr) {
120
mgr->MaybeClearTransaction(this);
121
}
122
#endif
123
}
124
125
} // namespace dom
126
} // namespace mozilla