Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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_U2FTokenTransport_h
8 : #define mozilla_dom_U2FTokenTransport_h
9 :
10 : #include "mozilla/dom/PWebAuthnTransaction.h"
11 :
12 : /*
13 : * Abstract class representing a transport manager for U2F Keys (software,
14 : * bluetooth, usb, etc.). Hides the implementation details for specific key
15 : * transport types.
16 : */
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 0 : class U2FRegisterResult {
22 : public:
23 0 : explicit U2FRegisterResult(nsTArray<uint8_t>&& aRegistration)
24 0 : : mRegistration(aRegistration)
25 0 : { }
26 :
27 0 : void ConsumeRegistration(nsTArray<uint8_t>& aBuffer) {
28 0 : aBuffer = Move(mRegistration);
29 0 : }
30 :
31 : private:
32 : nsTArray<uint8_t> mRegistration;
33 : };
34 :
35 0 : class U2FSignResult {
36 : public:
37 0 : explicit U2FSignResult(nsTArray<uint8_t>&& aKeyHandle,
38 : nsTArray<uint8_t>&& aSignature)
39 0 : : mKeyHandle(aKeyHandle)
40 0 : , mSignature(aSignature)
41 0 : { }
42 :
43 0 : void ConsumeKeyHandle(nsTArray<uint8_t>& aBuffer) {
44 0 : aBuffer = Move(mKeyHandle);
45 0 : }
46 :
47 0 : void ConsumeSignature(nsTArray<uint8_t>& aBuffer) {
48 0 : aBuffer = Move(mSignature);
49 0 : }
50 :
51 : private:
52 : nsTArray<uint8_t> mKeyHandle;
53 : nsTArray<uint8_t> mSignature;
54 : };
55 :
56 : typedef MozPromise<U2FRegisterResult, nsresult, true> U2FRegisterPromise;
57 : typedef MozPromise<U2FSignResult, nsresult, true> U2FSignPromise;
58 :
59 : class U2FTokenTransport
60 : {
61 : public:
62 0 : NS_INLINE_DECL_REFCOUNTING(U2FTokenTransport);
63 0 : U2FTokenTransport() {}
64 :
65 : virtual RefPtr<U2FRegisterPromise>
66 : Register(const nsTArray<WebAuthnScopedCredentialDescriptor>& aDescriptors,
67 : const nsTArray<uint8_t>& aApplication,
68 : const nsTArray<uint8_t>& aChallenge) = 0;
69 :
70 : virtual RefPtr<U2FSignPromise>
71 : Sign(const nsTArray<WebAuthnScopedCredentialDescriptor>& aDescriptors,
72 : const nsTArray<uint8_t>& aApplication,
73 : const nsTArray<uint8_t>& aChallenge) = 0;
74 :
75 : virtual void Cancel() = 0;
76 :
77 : protected:
78 0 : virtual ~U2FTokenTransport() = default;
79 : };
80 :
81 : } // namespace dom
82 : } // namespace mozilla
83 :
84 : #endif // mozilla_dom_U2FTokenTransport_h
|