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
#ifndef mozilla_dom_U2FSoftTokenManager_h
8
#define mozilla_dom_U2FSoftTokenManager_h
9
10
#include "mozilla/dom/U2FTokenTransport.h"
11
#include "ScopedNSSTypes.h"
12
13
/*
14
* U2FSoftTokenManager is a software implementation of a secure token manager
15
* for the U2F and WebAuthn APIs.
16
*/
17
18
namespace mozilla {
19
namespace dom {
20
21
class U2FSoftTokenManager final : public U2FTokenTransport {
22
public:
23
explicit U2FSoftTokenManager(uint32_t aCounter);
24
25
RefPtr<U2FRegisterPromise> Register(const WebAuthnMakeCredentialInfo& aInfo,
26
bool aForceNoneAttestation) override;
27
28
RefPtr<U2FSignPromise> Sign(const WebAuthnGetAssertionInfo& aInfo) override;
29
30
void Cancel() override;
31
32
private:
33
~U2FSoftTokenManager() {}
34
nsresult Init();
35
36
nsresult IsRegistered(const nsTArray<uint8_t>& aKeyHandle,
37
const nsTArray<uint8_t>& aAppParam, bool& aResult);
38
39
bool FindRegisteredKeyHandle(
40
const nsTArray<nsTArray<uint8_t>>& aAppIds,
41
const nsTArray<WebAuthnScopedCredential>& aCredentials,
42
/*out*/ nsTArray<uint8_t>& aKeyHandle,
43
/*out*/ nsTArray<uint8_t>& aAppId);
44
45
bool mInitialized;
46
mozilla::UniquePK11SymKey mWrappingKey;
47
48
static const nsCString mSecretNickname;
49
50
nsresult GetOrCreateWrappingKey(const mozilla::UniquePK11SlotInfo& aSlot);
51
uint32_t mCounter;
52
};
53
54
} // namespace dom
55
} // namespace mozilla
56
57
#endif // mozilla_dom_U2FSoftTokenManager_h