Bug 1400066 - Only build u2f-hid-rs on Tier1 platforms, it's not supported elsewhere. r?ttaubert draft
authorJan Beich <jbeich@FreeBSD.org>
Fri, 15 Sep 2017 00:00:53 +0000
changeset 665180 b8198220ff87fe4758044fb74ed36984855dbdb8
parent 665179 97d8a2caa657aeea81413433f9ea9700ff17a5c2
child 731672 08cbe5c327b9008804fabed3fb4f41b7edb8d6f8
push id79949
push userbmo:jbeich@FreeBSD.org
push dateFri, 15 Sep 2017 00:31:58 +0000
reviewersttaubert
bugs1400066
milestone57.0a1
Bug 1400066 - Only build u2f-hid-rs on Tier1 platforms, it's not supported elsewhere. r?ttaubert MozReview-Commit-ID: HWxObw1E2XF
dom/webauthn/U2FHIDTokenManager.cpp
toolkit/library/rust/shared/Cargo.toml
toolkit/library/rust/shared/lib.rs
--- a/dom/webauthn/U2FHIDTokenManager.cpp
+++ b/dom/webauthn/U2FHIDTokenManager.cpp
@@ -5,16 +5,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/U2FHIDTokenManager.h"
 #include "mozilla/StaticMutex.h"
 
 namespace mozilla {
 namespace dom {
 
+#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN)
 static StaticMutex gInstanceMutex;
 static U2FHIDTokenManager* gInstance;
 static nsIThread* gPBackgroundThread;
 
 static void
 u2f_register_callback(uint64_t aTransactionId, rust_u2f_result* aResult)
 {
   StaticMutexAutoLock lock(gInstanceMutex);
@@ -42,41 +43,46 @@ u2f_sign_callback(uint64_t aTransactionI
   UniquePtr<U2FResult> rv = MakeUnique<U2FResult>(aTransactionId, aResult);
   nsCOMPtr<nsIRunnable> r(NewNonOwningRunnableMethod<UniquePtr<U2FResult>&&>(
       "U2FHIDTokenManager::HandleSignResult", gInstance,
       &U2FHIDTokenManager::HandleSignResult, Move(rv)));
 
   MOZ_ALWAYS_SUCCEEDS(gPBackgroundThread->Dispatch(r.forget(),
                                                    NS_DISPATCH_NORMAL));
 }
+#endif
 
 U2FHIDTokenManager::U2FHIDTokenManager() : mTransactionId(0)
 {
+#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN)
   StaticMutexAutoLock lock(gInstanceMutex);
   MOZ_ASSERT(XRE_IsParentProcess());
   MOZ_ASSERT(!NS_IsMainThread());
   MOZ_ASSERT(!gInstance);
 
   mU2FManager = rust_u2f_mgr_new();
   gPBackgroundThread = NS_GetCurrentThread();
   MOZ_ASSERT(gPBackgroundThread, "This should never be null!");
   gInstance = this;
+#endif
 }
 
 U2FHIDTokenManager::~U2FHIDTokenManager()
 {
+#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN)
   StaticMutexAutoLock lock(gInstanceMutex);
   MOZ_ASSERT(NS_GetCurrentThread() == gPBackgroundThread);
 
   mRegisterPromise.RejectIfExists(NS_ERROR_DOM_UNKNOWN_ERR, __func__);
   mSignPromise.RejectIfExists(NS_ERROR_DOM_UNKNOWN_ERR, __func__);
 
   rust_u2f_mgr_free(mU2FManager);
   mU2FManager = nullptr;
   gInstance = nullptr;
+#endif
 }
 
 // A U2F Register operation causes a new key pair to be generated by the token.
 // The token then returns the public key of the key pair, and a handle to the
 // private key, which is a fancy way of saying "key wrapped private key", as
 // well as the generated attestation certificate and a signature using that
 // certificate's private key.
 //
@@ -94,32 +100,36 @@ U2FHIDTokenManager::~U2FHIDTokenManager(
 // *      attestation signature
 //
 RefPtr<U2FRegisterPromise>
 U2FHIDTokenManager::Register(const nsTArray<WebAuthnScopedCredentialDescriptor>& aDescriptors,
                              const nsTArray<uint8_t>& aApplication,
                              const nsTArray<uint8_t>& aChallenge,
                              uint32_t aTimeoutMS)
 {
+#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN)
   MOZ_ASSERT(NS_GetCurrentThread() == gPBackgroundThread);
 
   ClearPromises();
   mTransactionId = rust_u2f_mgr_register(mU2FManager,
                                          (uint64_t)aTimeoutMS,
                                          u2f_register_callback,
                                          aChallenge.Elements(),
                                          aChallenge.Length(),
                                          aApplication.Elements(),
                                          aApplication.Length());
 
   if (mTransactionId == 0) {
     return U2FRegisterPromise::CreateAndReject(NS_ERROR_DOM_UNKNOWN_ERR, __func__);
   }
 
   return mRegisterPromise.Ensure(__func__);
+#else
+  return U2FRegisterPromise::CreateAndReject(NS_ERROR_NOT_IMPLEMENTED, __func__);
+#endif
 }
 
 // A U2F Sign operation creates a signature over the "param" arguments (plus
 // some other stuff) using the private key indicated in the key handle argument.
 //
 // The format of the signed data is as follows:
 //
 //  32    Application parameter
@@ -134,43 +144,50 @@ U2FHIDTokenManager::Register(const nsTAr
 //  *     Signature
 //
 RefPtr<U2FSignPromise>
 U2FHIDTokenManager::Sign(const nsTArray<WebAuthnScopedCredentialDescriptor>& aDescriptors,
                          const nsTArray<uint8_t>& aApplication,
                          const nsTArray<uint8_t>& aChallenge,
                          uint32_t aTimeoutMS)
 {
+#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN)
   MOZ_ASSERT(NS_GetCurrentThread() == gPBackgroundThread);
 
   ClearPromises();
   mTransactionId = rust_u2f_mgr_sign(mU2FManager,
                                      (uint64_t)aTimeoutMS,
                                      u2f_sign_callback,
                                      aChallenge.Elements(),
                                      aChallenge.Length(),
                                      aApplication.Elements(),
                                      aApplication.Length(),
                                      U2FKeyHandles(aDescriptors).Get());
   if (mTransactionId == 0) {
     return U2FSignPromise::CreateAndReject(NS_ERROR_DOM_UNKNOWN_ERR, __func__);
   }
 
   return mSignPromise.Ensure(__func__);
+#else
+  return U2FSignPromise::CreateAndReject(NS_ERROR_NOT_IMPLEMENTED, __func__);
+#endif
 }
 
 void
 U2FHIDTokenManager::Cancel()
 {
+#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN)
   MOZ_ASSERT(NS_GetCurrentThread() == gPBackgroundThread);
 
   ClearPromises();
   mTransactionId = rust_u2f_mgr_cancel(mU2FManager);
+#endif
 }
 
+#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(XP_WIN)
 void
 U2FHIDTokenManager::HandleRegisterResult(UniquePtr<U2FResult>&& aResult)
 {
   MOZ_ASSERT(NS_GetCurrentThread() == gPBackgroundThread);
 
   if (aResult->GetTransactionId() != mTransactionId) {
     return;
   }
@@ -208,11 +225,12 @@ U2FHIDTokenManager::HandleSignResult(Uni
   if (!aResult->CopySignature(signature)) {
     mSignPromise.Reject(NS_ERROR_DOM_UNKNOWN_ERR, __func__);
     return;
   }
 
   U2FSignResult result(Move(keyHandle), Move(signature));
   mSignPromise.Resolve(Move(result), __func__);
 }
+#endif
 
 }
 }
--- a/toolkit/library/rust/shared/Cargo.toml
+++ b/toolkit/library/rust/shared/Cargo.toml
@@ -15,16 +15,18 @@ webrender_bindings = { path = "../../../
 cubeb-pulse = { path = "../../../../media/libcubeb/cubeb-pulse-rs", optional = true, features=["pulse-dlopen"] }
 cubeb-core = { path = "../../../../media/cubeb-rs/cubeb-core", optional = true }
 cubeb = { path = "../../../../media/cubeb-rs/cubeb-api", optional = true }
 cubeb-backend = { path = "../../../../media/cubeb-rs/cubeb-backend", optional = true }
 encoding_c = "0.8.0"
 encoding_glue = { path = "../../../../intl/encoding_glue" }
 audioipc-client = { path = "../../../../media/audioipc/client", optional = true }
 audioipc-server = { path = "../../../../media/audioipc/server", optional = true }
+
+[target.'cfg(any(target_os = "android", target_os = "linux", target_os = "macos", target_os = "windows"))'.dependencies]
 u2fhid = { path = "../../../../dom/webauthn/u2f-hid-rs" }
 
 [features]
 default = []
 bindgen = ["geckoservo/bindgen"]
 servo = ["geckoservo"]
 quantum_render = ["webrender_bindings"]
 cubeb-remoting = ["cubeb-core", "cubeb", "cubeb-backend", "audioipc-client", "audioipc-server"]
--- a/toolkit/library/rust/shared/lib.rs
+++ b/toolkit/library/rust/shared/lib.rs
@@ -14,16 +14,17 @@ extern crate webrender_bindings;
 #[cfg(feature = "cubeb_pulse_rust")]
 extern crate cubeb_pulse;
 extern crate encoding_c;
 extern crate encoding_glue;
 #[cfg(feature = "cubeb-remoting")]
 extern crate audioipc_client;
 #[cfg(feature = "cubeb-remoting")]
 extern crate audioipc_server;
+#[cfg(any(target_os = "android", target_os = "linux", target_os = "macos", target_os = "windows"))]
 extern crate u2fhid;
 
 use std::boxed::Box;
 use std::ffi::CStr;
 use std::os::raw::c_char;
 use std::panic;