Bug 1536097 - Part 5 - convert AttestationConveyancePreference to use ParamTraits for deserialization; r=jcj
authorAlex Gaynor <agaynor@mozilla.com>
Tue, 19 Mar 2019 23:25:35 +0000
changeset 465257 6937e95afc2e74a90282ae709040ef90b879533d
parent 465256 e516a5f9e905add224dc3bba0efd39448758ddf4
child 465258 9bf015225ed48cb1abeae414923f817f795aa0c0
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 5 - convert AttestationConveyancePreference to use ParamTraits for deserialization; r=jcj Depends on D24065 Differential Revision: https://phabricator.services.mozilla.com/D24066
dom/webauthn/PWebAuthnTransaction.ipdl
dom/webauthn/U2FTokenManager.cpp
dom/webauthn/WebAuthnManager.cpp
dom/webauthn/WebAuthnUtil.h
dom/webauthn/WinWebAuthnManager.cpp
--- a/dom/webauthn/PWebAuthnTransaction.ipdl
+++ b/dom/webauthn/PWebAuthnTransaction.ipdl
@@ -11,16 +11,17 @@
  * keys, etc) or interruption (another transaction was started in another
  * 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::AttestationConveyancePreference from "mozilla/dom/WebAuthnUtil.h";
 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;
@@ -67,17 +68,17 @@ struct CoseAlg {
 };
 
 struct WebAuthnMakeCredentialExtraInfo {
   WebAuthnMakeCredentialRpInfo Rp;
   WebAuthnMakeCredentialUserInfo User;
   CoseAlg[] coseAlgs;
   WebAuthnExtension[] Extensions;
   WebAuthnAuthenticatorSelection AuthenticatorSelection;
-  uint8_t attestationConveyancePreference;
+  AttestationConveyancePreference attestationConveyancePreference;
 };
 
 struct WebAuthnMakeCredentialInfo {
   nsString Origin;
   nsString RpId;
   uint8_t[] Challenge;
   nsCString ClientDataJSON;
   uint32_t TimeoutMS;
--- a/dom/webauthn/U2FTokenManager.cpp
+++ b/dom/webauthn/U2FTokenManager.cpp
@@ -280,18 +280,17 @@ void U2FTokenManager::Register(
   mLastTransactionId = aTransactionId;
 
   // Determine whether direct attestation was requested.
   bool directAttestationRequested = false;
   if (aTransactionInfo.Extra().isSome()) {
     const auto& extra = aTransactionInfo.Extra().ref();
 
     AttestationConveyancePreference attestation =
-        static_cast<AttestationConveyancePreference>(
-            extra.attestationConveyancePreference());
+        extra.attestationConveyancePreference();
 
     directAttestationRequested =
         attestation == AttestationConveyancePreference::Direct;
   }
 
   // Start a register request immediately if direct attestation
   // wasn't requested or the test pref is set.
   if (!directAttestationRequested ||
--- a/dom/webauthn/WebAuthnManager.cpp
+++ b/dom/webauthn/WebAuthnManager.cpp
@@ -347,37 +347,33 @@ already_AddRefed<Promise> WebAuthnManage
     authenticatorAttachment.emplace(attachment.Value());
   }
 
   // Create and forward authenticator selection criteria.
   WebAuthnAuthenticatorSelection authSelection(selection.mRequireResidentKey,
                                                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();
   }
 
   nsString userIcon;
   if (aOptions.mUser.mIcon.WasPassed()) {
     userIcon = aOptions.mUser.mIcon.Value();
   }
 
   WebAuthnMakeCredentialRpInfo rpInfo(aOptions.mRp.mName, rpIcon);
 
   WebAuthnMakeCredentialUserInfo userInfo(
       userId, aOptions.mUser.mName, userIcon, aOptions.mUser.mDisplayName);
 
   WebAuthnMakeCredentialExtraInfo extra(rpInfo, userInfo, coseAlgos, extensions,
-                                        authSelection,
-                                        attestationConveyancePreference);
+                                        authSelection, attestation);
 
   WebAuthnMakeCredentialInfo info(origin, NS_ConvertUTF8toUTF16(rpId),
                                   challenge, clientDataJSON, adjustedTimeout,
                                   excludeList, Some(extra));
 
 #ifdef OS_WIN
   if (!WinWebAuthnManager::AreWebAuthNApisAvailable()) {
     ListenForVisibilityEvents();
--- a/dom/webauthn/WebAuthnUtil.h
+++ b/dom/webauthn/WebAuthnUtil.h
@@ -73,11 +73,18 @@ struct ParamTraits<mozilla::dom::Authent
 
 template <>
 struct ParamTraits<mozilla::dom::UserVerificationRequirement>
     : public ContiguousEnumSerializer<
           mozilla::dom::UserVerificationRequirement,
           mozilla::dom::UserVerificationRequirement::Required,
           mozilla::dom::UserVerificationRequirement::EndGuard_> {};
 
+template <>
+struct ParamTraits<mozilla::dom::AttestationConveyancePreference>
+    : public ContiguousEnumSerializer<
+          mozilla::dom::AttestationConveyancePreference,
+          mozilla::dom::AttestationConveyancePreference::None,
+          mozilla::dom::AttestationConveyancePreference::EndGuard_> {};
+
 }  // namespace IPC
 
 #endif  // mozilla_dom_WebAuthnUtil_h
--- a/dom/webauthn/WinWebAuthnManager.cpp
+++ b/dom/webauthn/WinWebAuthnManager.cpp
@@ -262,18 +262,17 @@ void WinWebAuthnManager::Register(
           break;
       }
     }
 
     winRequireResidentKey = sel.requireResidentKey();
 
     // AttestationConveyance
     AttestationConveyancePreference attestation =
-        static_cast<AttestationConveyancePreference>(
-            extra.attestationConveyancePreference());
+        extra.attestationConveyancePreference();
     DWORD winAttestation = WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_ANY;
     switch (attestation) {
       case AttestationConveyancePreference::Direct:
         winAttestation = WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_DIRECT;
         break;
       case AttestationConveyancePreference::Indirect:
         winAttestation = WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_INDIRECT;
         break;