Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/webauthn/PublicKeyCredential.cpp
Line
Count
Source (jump to first uncovered line)
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/Promise.h"
8
#include "mozilla/dom/PublicKeyCredential.h"
9
#include "mozilla/dom/WebAuthenticationBinding.h"
10
#include "nsCycleCollectionParticipant.h"
11
12
namespace mozilla {
13
namespace dom {
14
15
NS_IMPL_CYCLE_COLLECTION_CLASS(PublicKeyCredential)
16
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PublicKeyCredential,
17
0
                                                Credential)
18
0
  tmp->mRawIdCachedObj = nullptr;
19
0
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
20
21
0
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(PublicKeyCredential, Credential)
22
0
  NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
23
0
  NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mRawIdCachedObj)
24
0
NS_IMPL_CYCLE_COLLECTION_TRACE_END
25
26
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PublicKeyCredential, Credential)
27
0
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
28
29
NS_IMPL_ADDREF_INHERITED(PublicKeyCredential, Credential)
30
NS_IMPL_RELEASE_INHERITED(PublicKeyCredential, Credential)
31
32
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PublicKeyCredential)
33
0
NS_INTERFACE_MAP_END_INHERITING(Credential)
34
35
PublicKeyCredential::PublicKeyCredential(nsPIDOMWindowInner* aParent)
36
  : Credential(aParent)
37
  , mRawIdCachedObj(nullptr)
38
0
{
39
0
  mozilla::HoldJSObjects(this);
40
0
}
41
42
PublicKeyCredential::~PublicKeyCredential()
43
0
{
44
0
  mozilla::DropJSObjects(this);
45
0
}
46
47
JSObject*
48
PublicKeyCredential::WrapObject(JSContext* aCx,
49
                                JS::Handle<JSObject*> aGivenProto)
50
0
{
51
0
  return PublicKeyCredential_Binding::Wrap(aCx, this, aGivenProto);
52
0
}
53
54
void
55
PublicKeyCredential::GetRawId(JSContext* aCx,
56
                              JS::MutableHandle<JSObject*> aRetVal)
57
0
{
58
0
  if (!mRawIdCachedObj) {
59
0
    mRawIdCachedObj = mRawId.ToArrayBuffer(aCx);
60
0
  }
61
0
  aRetVal.set(mRawIdCachedObj);
62
0
}
63
64
already_AddRefed<AuthenticatorResponse>
65
PublicKeyCredential::Response() const
66
0
{
67
0
  RefPtr<AuthenticatorResponse> temp(mResponse);
68
0
  return temp.forget();
69
0
}
70
71
nsresult
72
PublicKeyCredential::SetRawId(CryptoBuffer& aBuffer)
73
0
{
74
0
  if (NS_WARN_IF(!mRawId.Assign(aBuffer))) {
75
0
    return NS_ERROR_OUT_OF_MEMORY;
76
0
  }
77
0
  return NS_OK;
78
0
}
79
80
void
81
PublicKeyCredential::SetResponse(RefPtr<AuthenticatorResponse> aResponse)
82
0
{
83
0
  mResponse = aResponse;
84
0
}
85
86
/* static */ already_AddRefed<Promise>
87
PublicKeyCredential::IsUserVerifyingPlatformAuthenticatorAvailable(GlobalObject& aGlobal)
88
0
{
89
0
  nsIGlobalObject* globalObject = xpc::CurrentNativeGlobal(aGlobal.Context());
90
0
  if (NS_WARN_IF(!globalObject)) {
91
0
    return nullptr;
92
0
  }
93
0
94
0
  ErrorResult rv;
95
0
  RefPtr<Promise> promise = Promise::Create(globalObject, rv);
96
0
  if (rv.Failed()) {
97
0
    return nullptr;
98
0
  }
99
0
100
0
  // https://w3c.github.io/webauthn/#isUserVerifyingPlatformAuthenticatorAvailable
101
0
  //
102
0
  // We currently implement no platform authenticators, so this would always
103
0
  // resolve to false. For those cases, the spec recommends a resolve timeout
104
0
  // on the order of 10 minutes to avoid fingerprinting.
105
0
  //
106
0
  // A simple solution is thus to never resolve the promise, otherwise we'd
107
0
  // have to track every single call to this method along with a promise
108
0
  // and timer to resolve it after exactly X minutes.
109
0
  //
110
0
  // A Relying Party has to deal with a non-response in a timely fashion, so
111
0
  // we can keep this as-is (and not resolve) even when we support platform
112
0
  // authenticators but they're not available, or a user rejects a website's
113
0
  // request to use them.
114
0
  return promise.forget();
115
0
}
116
117
void
118
PublicKeyCredential::GetClientExtensionResults(AuthenticationExtensionsClientOutputs& aResult)
119
0
{
120
0
  aResult = mClientExtensionOutputs;
121
0
}
122
123
void
124
PublicKeyCredential::SetClientExtensionResultAppId(bool aResult)
125
0
{
126
0
  mClientExtensionOutputs.mAppid.Construct();
127
0
  mClientExtensionOutputs.mAppid.Value() = aResult;
128
0
}
129
130
131
} // namespace dom
132
} // namespace mozilla