示例#1
0
        public bool Reset(string key, string thumbprint)
        {
            Logger.Info("Resetting Server Key");
            var entropy = new byte[16];

            new RNGCryptoServiceProvider().GetBytes(entropy);
            var serverKeyBytes = Encoding.ASCII.GetBytes(key);
            var encryptedKey   = ServiceDP.EncryptData(serverKeyBytes, true, entropy);

            var serviceSetting   = new ServiceSetting();
            var serverKeyEntropy = serviceSetting.GetSetting("server_key_entropy");

            serverKeyEntropy.Value = Convert.ToBase64String(entropy);
            serviceSetting.UpdateSettingValue(serverKeyEntropy);

            var serverKey = serviceSetting.GetSetting("server_key");

            serverKey.Value = Convert.ToBase64String(encryptedKey);
            serviceSetting.UpdateSettingValue(serverKey);


            var caThumbprint = serviceSetting.GetSetting("ca_thumbprint");

            caThumbprint.Value = thumbprint;
            serviceSetting.UpdateSettingValue(caThumbprint);

            Logger.Info("Resetting Server Key Finished");
            return(true);
        }
示例#2
0
        private void UpdateComServers(List <DtoClientComServers> comServers)
        {
            var settingService = new ServiceSetting();
            var activeString   = "";

            foreach (var server in comServers.Where(x => x.Role.Equals("Active")))
            {
                activeString += server.Url + ",";
            }
            var trimmedActive = activeString.Trim(',');

            var passiveString = "";

            foreach (var server in comServers.Where(x => x.Role.Equals("Passive")))
            {
                passiveString += server.Url + ",";
            }
            var trimmedPassive = passiveString.Trim(',');

            if (!string.IsNullOrEmpty(trimmedActive))
            {
                var currentActive = settingService.GetSetting("active_com_servers");
                currentActive.Value = trimmedActive;
                settingService.UpdateSettingValue(currentActive);
            }

            if (!string.IsNullOrEmpty(trimmedPassive))
            {
                var currentPassive = settingService.GetSetting("passive_com_servers");
                currentPassive.Value = trimmedPassive;
                settingService.UpdateSettingValue(currentPassive);
            }
        }
示例#3
0
        public bool Update(string comServers)
        {
            Logger.Info("Updating Com Servers");


            var serviceSetting   = new ServiceSetting();
            var activeComServers = new ServiceSetting().GetSetting("active_com_servers");

            activeComServers.Value = comServers;
            serviceSetting.UpdateSettingValue(activeComServers);

            var initialComServers = new ServiceSetting().GetSetting("initial_com_servers");

            initialComServers.Value = comServers;
            serviceSetting.UpdateSettingValue(initialComServers);

            Logger.Info("Updating Com Server Finished");
            return(true);
        }
示例#4
0
        public bool HardReset(string type)
        {
            Logger.Info("Resetting Toec: " + type);
            ServiceCertificate.DeleteAllDeviceCertificates();
            ServiceCertificate.DeleteIntermediate();

            var serviceSetting  = new ServiceSetting();
            var provisionStatus = serviceSetting.GetSetting("provision_status");

            provisionStatus.Value = "0";
            serviceSetting.UpdateSettingValue(provisionStatus);

            if (type.Equals("Full"))
            {
                var installationId = serviceSetting.GetSetting("installation_id");
                installationId.Value = Guid.NewGuid().ToString();
                serviceSetting.UpdateSettingValue(installationId);
            }

            var encryptionKey = serviceSetting.GetSetting("encryption_key");

            encryptionKey.Value = null;
            serviceSetting.UpdateSettingValue(encryptionKey);

            var entropy = serviceSetting.GetSetting("entropy");

            entropy.Value = null;
            serviceSetting.UpdateSettingValue(entropy);

            var computerIdentifier = serviceSetting.GetSetting("computer_identifier");

            computerIdentifier.Value = null;
            serviceSetting.UpdateSettingValue(computerIdentifier);

            var deviceThumbprint = serviceSetting.GetSetting("device_thumbprint");

            deviceThumbprint.Value = null;
            serviceSetting.UpdateSettingValue(deviceThumbprint);

            var intermediateThumbprint = serviceSetting.GetSetting("intermediate_thumbprint");

            intermediateThumbprint.Value = null;
            serviceSetting.UpdateSettingValue(intermediateThumbprint);

            if (type.Equals("Full"))
            {
                new PolicyHistoryServices().DeleteAll();
                new ServiceUserTracker().DeleteAll();
                new ServiceAppMonitor().DeleteAll();
            }

            Logger.Info("Resetting Toec Finished");
            return(true);
        }
示例#5
0
        public bool Update(string logLevel)
        {
            Logger.Info("Updating Log Level");


            var serviceSetting = new ServiceSetting();
            var logLevelEntity = new ServiceSetting().GetSetting("log_level");

            logLevelEntity.Value = logLevel;
            serviceSetting.UpdateSettingValue(logLevelEntity);

            Logger.Info("Updating Log Level Finished");
            return(true);
        }
示例#6
0
        private EnumProvisionStatus.Status ProvisionStage1()
        {
            var response = new APICall().ProvisionApi.GetIntermediateCert(DtoGobalSettings.ClientIdentity.Name);

            if (response == null)
            {
                return(EnumProvisionStatus.Status.Error);
            }
            if (response.ProvisionStatus != EnumProvisionStatus.Status.IntermediateInstalled)
            {
                Logger.Error(response.Message);
                return(response.ProvisionStatus);
            }
            var bytes            = Convert.FromBase64String(response.Certificate);
            var intermediateCert = new X509Certificate2(bytes);

            if (!ServiceCertificate.ValidateCert(intermediateCert))
            {
                return(EnumProvisionStatus.Status.Error);
            }

            if (ServiceCertificate.StoreLocalMachine(intermediateCert, StoreName.CertificateAuthority))
            {
                var settingProvisionStatus = _serviceSetting.GetSetting("provision_status");
                settingProvisionStatus.Value =
                    Convert.ToInt16(EnumProvisionStatus.Status.IntermediateInstalled).ToString();
                _serviceSetting.UpdateSettingValue(settingProvisionStatus);
                var intermediateThumbprint = _serviceSetting.GetSetting("intermediate_thumbprint");
                intermediateThumbprint.Value = intermediateCert.Thumbprint;
                _serviceSetting.UpdateSettingValue(intermediateThumbprint);

                return(EnumProvisionStatus.Status.IntermediateInstalled);
            }

            return(EnumProvisionStatus.Status.Error);
        }
示例#7
0
        private void VerifyInstallationId()
        {
            var serviceSetting = new ServiceSetting();

            Logger.Info("Verifying Installation ID");
            var status    = serviceSetting.GetSetting("provision_status");
            var installID = serviceSetting.GetSetting("installation_id");

            Logger.Info("Provision Status: " + status.Value);
            Logger.Info("Installation ID: " + installID.Value);
            if (string.IsNullOrEmpty(installID.Value) && status.Value.Equals("0"))
            {
                //from prepare image arg, generate new id
                Logger.Info("Generating New Installation ID");
                installID.Value = Guid.NewGuid().ToString();
                serviceSetting.UpdateSettingValue(installID);
            }
            Logger.Info("Verification Complete");
        }
示例#8
0
        private void ResetToec()
        {
            if (!_imagePrepOptions.ResetToec)
            {
                return;
            }
            Logger.Info("Resetting Toec");

            ServiceCertificate.DeleteAllDeviceCertificates();
            ServiceCertificate.DeleteIntermediate();

            var serviceSetting = new ServiceSetting();

            var installationId = serviceSetting.GetSetting("installation_id");

            installationId.Value = null;
            serviceSetting.UpdateSettingValue(installationId);


            var encryptionKey = serviceSetting.GetSetting("encryption_key");

            encryptionKey.Value = null;
            serviceSetting.UpdateSettingValue(encryptionKey);

            var entropy = serviceSetting.GetSetting("entropy");

            entropy.Value = null;
            serviceSetting.UpdateSettingValue(entropy);

            var computerIdentifier = serviceSetting.GetSetting("computer_identifier");

            computerIdentifier.Value = null;
            serviceSetting.UpdateSettingValue(computerIdentifier);

            var deviceThumbprint = serviceSetting.GetSetting("device_thumbprint");

            deviceThumbprint.Value = null;
            serviceSetting.UpdateSettingValue(deviceThumbprint);

            var intermediateThumbprint = serviceSetting.GetSetting("intermediate_thumbprint");

            intermediateThumbprint.Value = null;
            serviceSetting.UpdateSettingValue(intermediateThumbprint);

            new PolicyHistoryServices().DeleteAll();
            new ServiceUserTracker().DeleteAll();
            new ServiceAppMonitor().DeleteAll();

            var provisionStatus = serviceSetting.GetSetting("provision_status");

            provisionStatus.Value = "0";
            serviceSetting.UpdateSettingValue(provisionStatus);


            var updatedStatus = serviceSetting.GetSetting("provision_status");
            var updatedId     = installationId = serviceSetting.GetSetting("installation_id");

            if (!updatedStatus.Value.Equals("0") && !string.IsNullOrEmpty(updatedId.Value))
            {
                Logger.Error("Prepare Image Failed.  Could Not Reset ID's");
            }

            Logger.Info("Finished Resetting Toec");
        }
示例#9
0
        public bool Run()
        {
            Logger.Info("Preparing Toec For Image: ");
            Logger.Info("Checking Toec Service");
            var servResult = new ServiceSystemService().StopToec();

            if (!servResult)
            {
                Logger.Error("Toec Service Must Be Stopped Before Preparing Image.");
                return(false);
            }

            //Wait another 30 secs for anything to finish
            Logger.Info("Resetting Toec ...");
            System.Threading.Thread.Sleep(30000);

            ServiceCertificate.DeleteAllDeviceCertificates();
            ServiceCertificate.DeleteIntermediate();

            var serviceSetting = new ServiceSetting();

            var installationId = serviceSetting.GetSetting("installation_id");

            installationId.Value = null;
            serviceSetting.UpdateSettingValue(installationId);


            var encryptionKey = serviceSetting.GetSetting("encryption_key");

            encryptionKey.Value = null;
            serviceSetting.UpdateSettingValue(encryptionKey);

            var entropy = serviceSetting.GetSetting("entropy");

            entropy.Value = null;
            serviceSetting.UpdateSettingValue(entropy);

            var computerIdentifier = serviceSetting.GetSetting("computer_identifier");

            computerIdentifier.Value = null;
            serviceSetting.UpdateSettingValue(computerIdentifier);

            var deviceThumbprint = serviceSetting.GetSetting("device_thumbprint");

            deviceThumbprint.Value = null;
            serviceSetting.UpdateSettingValue(deviceThumbprint);

            var intermediateThumbprint = serviceSetting.GetSetting("intermediate_thumbprint");

            intermediateThumbprint.Value = null;
            serviceSetting.UpdateSettingValue(intermediateThumbprint);

            new PolicyHistoryServices().DeleteAll();
            new ServiceUserTracker().DeleteAll();
            new ServiceAppMonitor().DeleteAll();

            var provisionStatus = serviceSetting.GetSetting("provision_status");

            provisionStatus.Value = "0";
            serviceSetting.UpdateSettingValue(provisionStatus);


            var updatedStatus = serviceSetting.GetSetting("provision_status");
            var updatedId     = installationId = serviceSetting.GetSetting("installation_id");

            if (!updatedStatus.Value.Equals("0") && !string.IsNullOrEmpty(updatedId.Value))
            {
                Logger.Error("Prepare Image Failed.  Could Not Reset ID's");
                return(false);
            }


            Logger.Info("Toec Prepare Image Finished");
            return(true);
        }