Bug 1536097 - Part 4 - convert UserVerificationRequirement to use ParamTraits for deserialization; r=jcj
authorAlex Gaynor <agaynor@mozilla.com>
Tue, 19 Mar 2019 23:25:47 +0000
changeset 465256 e516a5f9e905add224dc3bba0efd39448758ddf4
parent 465255 a41f369384368b0863dded39fb9f308ad35f1df6
child 465257 6937e95afc2e74a90282ae709040ef90b879533d
push id112496
push usershindli@mozilla.com
push dateThu, 21 Mar 2019 04:37:39 +0000
treeherdermozilla-inbound@29476d3ca61d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcj
bugs1536097
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1536097 - Part 4 - convert UserVerificationRequirement to use ParamTraits for deserialization; r=jcj Depends on D24064 Differential Revision: https://phabricator.services.mozilla.com/D24065
dom/webauthn/PWebAuthnTransaction.ipdl
dom/webauthn/U2FHIDTokenManager.cpp
dom/webauthn/U2FSoftTokenManager.cpp
dom/webauthn/WebAuthnManager.cpp
dom/webauthn/WebAuthnUtil.h
dom/webauthn/WinWebAuthnManager.cpp
--- a/dom/webauthn/PWebAuthnTransaction.ipdl
+++ b/dom/webauthn/PWebAuthnTransaction.ipdl
@@ -12,23 +12,24 @@
  * content process). Similarly, the content process can also request a cancel,
  * either triggered explicitly by the user/script or due to UI events like
  * selecting a different tab.
  */
 
 include protocol PBackground;
 
 using mozilla::dom::AuthenticatorAttachment from "mozilla/dom/WebAuthnUtil.h";
+using mozilla::dom::UserVerificationRequirement from "mozilla/dom/WebAuthnUtil.h";
 
 namespace mozilla {
 namespace dom {
 
 struct WebAuthnAuthenticatorSelection {
   bool requireResidentKey;
-  uint8_t userVerificationRequirement;
+  UserVerificationRequirement userVerificationRequirement;
   AuthenticatorAttachment? authenticatorAttachment;
 };
 
 struct WebAuthnScopedCredential {
   uint8_t[] id;
   uint8_t transports;
 };
 
@@ -89,17 +90,17 @@ struct WebAuthnMakeCredentialResult {
   uint8_t[] AttestationObject;
   uint8_t[] KeyHandle;
   /* Might be empty if the token implementation doesn't support CTAP1. */
   uint8_t[] RegistrationData;
 };
 
 struct WebAuthnGetAssertionExtraInfo {
   WebAuthnExtension[] Extensions;
-  uint8_t userVerificationRequirement;
+  UserVerificationRequirement userVerificationRequirement;
 };
 
 struct WebAuthnGetAssertionInfo {
   nsString Origin;
   nsString RpId;
   uint8_t[] Challenge;
   nsCString ClientDataJSON;
   uint32_t TimeoutMS;
--- a/dom/webauthn/U2FHIDTokenManager.cpp
+++ b/dom/webauthn/U2FHIDTokenManager.cpp
@@ -109,18 +109,17 @@ RefPtr<U2FRegisterPromise> U2FHIDTokenMa
 
   uint64_t registerFlags = 0;
 
   if (aInfo.Extra().isSome()) {
     const auto& extra = aInfo.Extra().ref();
     const WebAuthnAuthenticatorSelection& sel = extra.AuthenticatorSelection();
 
     UserVerificationRequirement userVerificaitonRequirement =
-        static_cast<UserVerificationRequirement>(
-            sel.userVerificationRequirement());
+        sel.userVerificationRequirement();
 
     bool requireUserVerification =
         userVerificaitonRequirement == UserVerificationRequirement::Required;
 
     bool requirePlatformAttachment = false;
     if (sel.authenticatorAttachment().isSome()) {
       const AuthenticatorAttachment authenticatorAttachment =
           sel.authenticatorAttachment().value();
@@ -225,18 +224,17 @@ RefPtr<U2FSignPromise> U2FHIDTokenManage
   uint64_t signFlags = 0;
   nsTArray<nsTArray<uint8_t>> appIds;
   appIds.AppendElement(rpIdHash);
 
   if (aInfo.Extra().isSome()) {
     const auto& extra = aInfo.Extra().ref();
 
     UserVerificationRequirement userVerificaitonReq =
-        static_cast<UserVerificationRequirement>(
-            extra.userVerificationRequirement());
+        extra.userVerificationRequirement();
 
     // Set flags for credential requests.
     if (userVerificaitonReq == UserVerificationRequirement::Required) {
       signFlags |= U2F_FLAG_REQUIRE_USER_VERIFICATION;
     }
 
     // Process extensions.
     for (const WebAuthnExtension& ext : extra.Extensions()) {
--- a/dom/webauthn/U2FSoftTokenManager.cpp
+++ b/dom/webauthn/U2FSoftTokenManager.cpp
@@ -574,18 +574,17 @@ RefPtr<U2FRegisterPromise> U2FSoftTokenM
     }
   }
 
   if (aInfo.Extra().isSome()) {
     const auto& extra = aInfo.Extra().ref();
     const WebAuthnAuthenticatorSelection& sel = extra.AuthenticatorSelection();
 
     UserVerificationRequirement userVerificaitonRequirement =
-        static_cast<UserVerificationRequirement>(
-            sel.userVerificationRequirement());
+        sel.userVerificationRequirement();
 
     bool requireUserVerification =
         userVerificaitonRequirement == UserVerificationRequirement::Required;
 
     bool requirePlatformAttachment = false;
     if (sel.authenticatorAttachment().isSome()) {
       const AuthenticatorAttachment authenticatorAttachment =
           sel.authenticatorAttachment().value();
@@ -813,18 +812,17 @@ RefPtr<U2FSignPromise> U2FSoftTokenManag
 
   nsTArray<nsTArray<uint8_t>> appIds;
   appIds.AppendElement(rpIdHash);
 
   if (aInfo.Extra().isSome()) {
     const auto& extra = aInfo.Extra().ref();
 
     UserVerificationRequirement userVerificaitonReq =
-        static_cast<UserVerificationRequirement>(
-            extra.userVerificationRequirement());
+        extra.userVerificationRequirement();
 
     // The U2F softtoken doesn't support user verification.
     if (userVerificaitonReq == UserVerificationRequirement::Required) {
       return U2FSignPromise::CreateAndReject(NS_ERROR_DOM_NOT_ALLOWED_ERR,
                                              __func__);
     }
 
     // Process extensions.
--- a/dom/webauthn/WebAuthnManager.cpp
+++ b/dom/webauthn/WebAuthnManager.cpp
@@ -342,23 +342,19 @@ already_AddRefed<Promise> WebAuthnManage
   const AttestationConveyancePreference& attestation = aOptions.mAttestation;
 
   // Attachment
   Maybe<AuthenticatorAttachment> authenticatorAttachment;
   if (attachment.WasPassed()) {
     authenticatorAttachment.emplace(attachment.Value());
   }
 
-  // User Verification
-  uint8_t userVerificationRequirement =
-      static_cast<uint8_t>(selection.mUserVerification);
-
   // Create and forward authenticator selection criteria.
   WebAuthnAuthenticatorSelection authSelection(selection.mRequireResidentKey,
-                                               userVerificationRequirement,
+                                               selection.mUserVerification,
                                                authenticatorAttachment);
 
   // aOptions.mAttestation
   uint8_t attestationConveyancePreference = static_cast<uint8_t>(attestation);
 
   nsString rpIcon;
   if (aOptions.mRp.mIcon.WasPassed()) {
     rpIcon = aOptions.mRp.mIcon.Value();
@@ -517,20 +513,16 @@ already_AddRefed<Promise> WebAuthnManage
     }
   }
 
   if (!MaybeCreateBackgroundActor()) {
     promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
     return promise.forget();
   }
 
-  // User Verification
-  uint8_t userVerificationRequirement =
-      static_cast<uint8_t>(aOptions.mUserVerification);
-
   // If extensions were specified, process any extensions supported by this
   // client platform, to produce the extension data that needs to be sent to the
   // authenticator. If an error is encountered while processing an extension,
   // skip that extension and do not produce any extension data for it. Call the
   // result of this processing clientExtensions.
   nsTArray<WebAuthnExtension> extensions;
 
   // <https://w3c.github.io/webauthn/#sctn-appid-extension>
@@ -555,17 +547,17 @@ already_AddRefed<Promise> WebAuthnManage
       promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
       return promise.forget();
     }
 
     // Append the hash and send it to the backend.
     extensions.AppendElement(WebAuthnExtensionAppId(appIdHash, appId));
   }
 
-  WebAuthnGetAssertionExtraInfo extra(extensions, userVerificationRequirement);
+  WebAuthnGetAssertionExtraInfo extra(extensions, aOptions.mUserVerification);
 
   WebAuthnGetAssertionInfo info(origin, NS_ConvertUTF8toUTF16(rpId), challenge,
                                 clientDataJSON, adjustedTimeout, allowList,
                                 Some(extra));
 
 #ifdef OS_WIN
   if (!WinWebAuthnManager::AreWebAuthNApisAvailable()) {
     ListenForVisibilityEvents();
--- a/dom/webauthn/WebAuthnUtil.h
+++ b/dom/webauthn/WebAuthnUtil.h
@@ -66,11 +66,18 @@ namespace IPC {
 
 template <>
 struct ParamTraits<mozilla::dom::AuthenticatorAttachment>
     : public ContiguousEnumSerializer<
           mozilla::dom::AuthenticatorAttachment,
           mozilla::dom::AuthenticatorAttachment::Platform,
           mozilla::dom::AuthenticatorAttachment::EndGuard_> {};
 
+template <>
+struct ParamTraits<mozilla::dom::UserVerificationRequirement>
+    : public ContiguousEnumSerializer<
+          mozilla::dom::UserVerificationRequirement,
+          mozilla::dom::UserVerificationRequirement::Required,
+          mozilla::dom::UserVerificationRequirement::EndGuard_> {};
+
 }  // namespace IPC
 
 #endif  // mozilla_dom_WebAuthnUtil_h
--- a/dom/webauthn/WinWebAuthnManager.cpp
+++ b/dom/webauthn/WinWebAuthnManager.cpp
@@ -224,18 +224,17 @@ void WinWebAuthnManager::Register(
           WEBAUTHN_COSE_CREDENTIAL_PARAMETER_CURRENT_VERSION,
           WEBAUTHN_CREDENTIAL_TYPE_PUBLIC_KEY, coseAlg.alg()};
       coseParams.AppendElement(coseAlgorithm);
     }
 
     const auto& sel = extra.AuthenticatorSelection();
 
     UserVerificationRequirement userVerificationReq =
-        static_cast<UserVerificationRequirement>(
-            sel.userVerificationRequirement());
+        sel.userVerificationRequirement();
     switch (userVerificationReq) {
       case UserVerificationRequirement::Required:
         winUserVerificationReq =
             WEBAUTHN_USER_VERIFICATION_REQUIREMENT_REQUIRED;
         break;
       case UserVerificationRequirement::Preferred:
         winUserVerificationReq =
             WEBAUTHN_USER_VERIFICATION_REQUIREMENT_PREFERRED;
@@ -500,18 +499,17 @@ void WinWebAuthnManager::Sign(PWebAuthnT
       }
     }
 
     // RPID
     rpID = aInfo.RpId().get();
 
     // User Verification Requirement
     UserVerificationRequirement userVerificationReq =
-        static_cast<UserVerificationRequirement>(
-            extra.userVerificationRequirement());
+        extra.userVerificationRequirement();
 
     switch (userVerificationReq) {
       case UserVerificationRequirement::Required:
         winUserVerificationReq =
             WEBAUTHN_USER_VERIFICATION_REQUIREMENT_REQUIRED;
         break;
       case UserVerificationRequirement::Preferred:
         winUserVerificationReq =