public async Task <GetEnterpriseDataResponse> GetEnterpriseData(params string[] includes) { var rq = new GetEnterpriseDataCommand { include = includes }; var rs = await Auth.ExecuteAuthCommand <GetEnterpriseDataCommand, GetEnterpriseDataResponse>(rq); EnterpriseName = rs.EnterpriseName; if (TreeKey == null) { var encTreeKey = rs.TreeKey.Base64UrlDecode(); switch (rs.KeyTypeId) { case 1: TreeKey = CryptoUtils.DecryptAesV1(encTreeKey, Auth.AuthContext.DataKey); break; case 2: if (encTreeKey.Length > 60) { TreeKey = CryptoUtils.DecryptRsa(encTreeKey, Auth.AuthContext.PrivateKey); } break; default: throw new Exception("cannot decrypt tree key"); } } return(rs); }
public static async Task GetEnterpriseData(this IEnterpriseContext context, params string[] includes) { var requested = new HashSet <string>(includes); var rq = new GetEnterpriseDataCommand { include = requested.ToArray() }; var rs = await context.Enterprise.Auth.ExecuteAuthCommand <GetEnterpriseDataCommand, GetEnterpriseDataResponse>(rq); if (requested.Contains("devices_request_for_admin_approval")) { context.DeviceForAdminApprovals = rs.DeviceRequestForApproval != null?rs.DeviceRequestForApproval.ToArray() : new GetDeviceForAdminApproval[0]; } }
private void CheckIfEnterpriseAdmin() { if (_auth.AuthContext.IsEnterpriseAdmin) { Enterprise = new EnterpriseData(_auth); _auth.PushNotifications?.RegisterCallback(EnterpriseNotificationCallback); Task.Run(async() => { try { await Enterprise.PopulateEnterprise(); await this.AppendEnterpriseCommands(this); var entRq = new GetEnterpriseDataCommand { include = new[] { "licenses", "managed_companies" } }; var entRs = await _auth.ExecuteAuthCommand <GetEnterpriseDataCommand, GetEnterpriseDataResponse>(entRq); if (entRs.ManagedCompanies?.Count > 0) { _managedCompanies.AddRange(entRs.ManagedCompanies); Commands.Add("mc-list", new SimpleCommand { Order = 70, Description = "List managed companies", Action = ListManagedCompanies, }); Commands.Add("mc-login", new ParsableCommand <EnterpriseMcLoginOptions> { Order = 71, Description = "Login to managed company", Action = LoginToManagedCompany, }); } } catch (Exception e) { Debug.WriteLine(e); } }); } }
internal static async Task AppendEnterpriseCommands(this IEnterpriseContext context, CliCommands cli) { cli.Commands.Add("enterprise-sync-down", new SimpleCommand { Order = 60, Description = "Retrieve enterprise data", Action = async _ => { await context.Enterprise.PopulateEnterprise(); }, }); cli.Commands.Add("enterprise-node", new ParsableCommand <EnterpriseNodeOptions> { Order = 61, Description = "Display node structure", Action = async options => { await context.EnterpriseNodeCommand(options); }, }); cli.Commands.Add("enterprise-user", new ParsableCommand <EnterpriseUserOptions> { Order = 62, Description = "List Enterprise Users", Action = async options => { await context.EnterpriseUserCommand(options); }, }); cli.Commands.Add("enterprise-team", new ParsableCommand <EnterpriseTeamOptions> { Order = 63, Description = "List Enterprise Teams", Action = async options => { await context.EnterpriseTeamCommand(options); }, }); cli.Commands.Add("enterprise-device", new ParsableCommand <EnterpriseDeviceOptions> { Order = 64, Description = "Manage User Devices", Action = async options => { await context.EnterpriseDeviceCommand(options); }, }); cli.Commands.Add("audit-report", new ParsableCommand <AuditReportOptions> { Order = 64, Description = "Run an audit trail report.", Action = async options => { await context.RunAuditEventsReport(options); }, }); cli.CommandAliases["esd"] = "enterprise-sync-down"; cli.CommandAliases["en"] = "enterprise-node"; cli.CommandAliases["eu"] = "enterprise-user"; cli.CommandAliases["et"] = "enterprise-team"; cli.CommandAliases["ed"] = "enterprise-device"; var entRq = new GetEnterpriseDataCommand { include = new[] { "keys" } }; var entRs = await context.Enterprise.Auth.ExecuteAuthCommand <GetEnterpriseDataCommand, GetEnterpriseDataResponse>(entRq); if (string.IsNullOrEmpty(entRs.Keys?.EccEncryptedPrivateKey)) { cli.Commands.Add("enterprise-add-key", new SimpleCommand { Order = 63, Description = "Register ECC key pair", Action = async options => { await context.EnterpriseRegisterEcKey(cli); }, }); } else { var privateKeyData = CryptoUtils.DecryptAesV2( entRs.Keys.EccEncryptedPrivateKey.Base64UrlDecode(), context.Enterprise.TreeKey); context.EnterprisePrivateKey = CryptoUtils.LoadPrivateEcKey(privateKeyData); } }