Skip to content

Commit

Permalink
Bug 1813982 - XPCOM interface to authenticator-rs. r=keeler,geckoview…
Browse files Browse the repository at this point in the history
…-reviewers,m_kato

Differential Revision: https://phabricator.services.mozilla.com/D171269
  • Loading branch information
jschanck committed Mar 16, 2023
1 parent cb4b57f commit 0a0369f
Show file tree
Hide file tree
Showing 38 changed files with 3,783 additions and 1,533 deletions.
16 changes: 15 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7550,14 +7550,14 @@ var WebAuthnPromptHelper = {
},

observe(aSubject, aTopic, aData) {
let mgr = aSubject.QueryInterface(Ci.nsIU2FTokenManager);
let data = JSON.parse(aData);

// If we receive a cancel, it might be a WebAuthn prompt starting in another
// window, and the other window's browsing context will send out the
// cancellations, so any cancel action we get should prompt us to cancel.
if (data.action == "cancel") {
this.cancel(data);
return;
}

if (
Expand All @@ -7567,6 +7567,10 @@ var WebAuthnPromptHelper = {
return;
}

let mgr = aSubject.QueryInterface(
data.is_ctap2 ? Ci.nsIWebAuthnController : Ci.nsIU2FTokenManager
);

if (data.action == "register") {
this.register(mgr, data);
} else if (data.action == "register-direct") {
Expand Down Expand Up @@ -7631,7 +7635,7 @@ var WebAuthnPromptHelper = {
label: unescape(decodeURIComponent(usernames[i])),
accessKey: i.toString(),
callback(aState) {
mgr.resumeWithSelectedSignResult(tid, i);
mgr.signatureSelectionCallback(tid, i);
},
});
}
Expand All @@ -7657,7 +7661,7 @@ var WebAuthnPromptHelper = {
aPassword
);
if (res) {
mgr.pinCallback(aPassword.value);
mgr.pinCallback(tid, aPassword.value);
} else {
mgr.cancel(tid);
}
Expand Down
6 changes: 2 additions & 4 deletions dom/webauthn/AndroidWebAuthnTokenManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ void AndroidWebAuthnTokenManager::Drop() {
}

RefPtr<U2FRegisterPromise> AndroidWebAuthnTokenManager::Register(
const WebAuthnMakeCredentialInfo& aInfo, bool aForceNoneAttestation,
void _status_callback(rust_ctap2_status_update_res*)) {
const WebAuthnMakeCredentialInfo& aInfo, bool aForceNoneAttestation) {
AssertIsOnOwningThread();

ClearPromises();
Expand Down Expand Up @@ -276,8 +275,7 @@ void AndroidWebAuthnTokenManager::HandleRegisterResult(
}

RefPtr<U2FSignPromise> AndroidWebAuthnTokenManager::Sign(
const WebAuthnGetAssertionInfo& aInfo,
void _status_callback(rust_ctap2_status_update_res*)) {
const WebAuthnGetAssertionInfo& aInfo) {
AssertIsOnOwningThread();

ClearPromises();
Expand Down
7 changes: 3 additions & 4 deletions dom/webauthn/AndroidWebAuthnTokenManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ class AndroidWebAuthnTokenManager final : public U2FTokenTransport {
~AndroidWebAuthnTokenManager() {}

virtual RefPtr<U2FRegisterPromise> Register(
const WebAuthnMakeCredentialInfo& aInfo, bool aForceNoneAttestation,
void status_callback(rust_ctap2_status_update_res*)) override;
const WebAuthnMakeCredentialInfo& aInfo,
bool aForceNoneAttestation) override;

virtual RefPtr<U2FSignPromise> Sign(
const WebAuthnGetAssertionInfo& aInfo,
void status_callback(rust_ctap2_status_update_res*)) override;
const WebAuthnGetAssertionInfo& aInfo) override;

void Cancel() override;

Expand Down
29 changes: 29 additions & 0 deletions dom/webauthn/AuthrsTransport.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* 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 "AuthrsTransport.h"
#include "nsIWebAuthnController.h"
#include "nsCOMPtr.h"

namespace {
extern "C" {

// Implemented in Rust
nsresult authrs_transport_constructor(nsIWebAuthnTransport** result);

} // extern "C"
} // namespace

namespace mozilla::dom {

already_AddRefed<nsIWebAuthnTransport> NewAuthrsTransport() {
nsCOMPtr<nsIWebAuthnTransport> transport;
nsresult rv = authrs_transport_constructor(getter_AddRefs(transport));
if (NS_WARN_IF(NS_FAILED(rv))) {
return nullptr;
}
return transport.forget();
}

} // namespace mozilla::dom
17 changes: 17 additions & 0 deletions dom/webauthn/AuthrsTransport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* 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/. */

#ifndef DOM_WEBAUTHN_AUTHRS_BRIDGE_H_
#define DOM_WEBAUTHN_AUTHRS_BRIDGE_H_

#include "mozilla/AlreadyAddRefed.h"
#include "nsIWebAuthnController.h"

namespace mozilla::dom {

already_AddRefed<nsIWebAuthnTransport> NewAuthrsTransport();

} // namespace mozilla::dom

#endif // DOM_WEBAUTHN_AUTHRS_BRIDGE_H_
Loading

0 comments on commit 0a0369f

Please sign in to comment.