示例#1
0
        /// <summary>
        /// Processes login response from the FxA API and adds a new Account device.
        /// </summary>
        /// <param name="fxaJson">JSON string received from FxA containing login data.</param>
        /// <returns>True on successful processing of the login response.</returns>
        public bool ProcessLogin(string fxaJson)
        {
            // Initialize a new login session configuration
            Manager.Account.Config = new FxA.Config(fxaJson);

            // Generate a new WireGuard keypair in preparation for adding a new Account device
            var keys = WireGuard.Keypair.Generate();

            Manager.Account.Config.FxALogin.PublicKey = keys.Public;

            // Save login session to user's appdata folder
            Manager.Account.Config.SaveFxAToken();
            Manager.Account.Config.WriteFxAUserToFile(ProductConstants.FxAUserFile);

            // Set the account login state to logged in
            Manager.Account.LoginState = FxA.LoginState.LoggedIn;

            // Added a new account device through the FxA API, using the newly generated keypair
            var devices           = new FxA.Devices();
            var deviceName        = string.Format("{0} ({1} {2})", System.Environment.MachineName, System.Environment.OSVersion.Platform, System.Environment.OSVersion.Version);
            var deviceAddResponse = devices.AddDevice(deviceName, keys.Public);

            // Upon successful addition of a new device, save the device interface to the WireGuard configuration file
            if (deviceAddResponse != null)
            {
                var conf = new WireGuard.Config(keys.Private, deviceAddResponse.IPv4Address + "," + deviceAddResponse.IPv6Address, string.Empty);
                conf.WriteToFile(ProductConstants.FirefoxPrivateNetworkConfFile);

                return(true);
            }

            return(false);
        }
示例#2
0
 /// <summary>
 /// Add device.
 /// </summary>
 /// <param name="req">WCF device request.</param>
 /// <returns>WCF response.</returns>
 public Response AddDevice(DeviceRequest req)
 {
     try
     {
         var devices           = new FxA.Devices();
         var addDeviceResponse = devices.AddDevice(req.DeviceName, req.PublicKey);
         return(new Response(200, "Success"));
     }
     catch (Exception ex)
     {
         return(new Response(500, ex.Message));
     }
 }