public bool RunAllServers(EntityComputer computer, EntityImageProfile imageProfile) { _uow = new UnitOfWork(); var comServers = new Workflows.GetCompTftpServers().Run(computer.Id); if (comServers == null) { log.Error("Could Not Determine Tftp Com Servers For Computer: " + computer.Name); return(false); } if (comServers.Count == 0) { log.Error("Could Not Determine Tftp Com Servers For Computer: " + computer.Name); return(false); } var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var NoErrors = true; var dtoTaskBootFile = new DtoTaskBootFile(); dtoTaskBootFile.Computer = computer; dtoTaskBootFile.ImageProfile = imageProfile; foreach (var com in comServers) { if (!new APICall().ClientComServerApi.CreateTaskBootFiles(com.Url, "", decryptedKey, dtoTaskBootFile)) { NoErrors = false; } } return(NoErrors); }
public bool DeleteModuleDirectory(string moduleGuid) { if (string.IsNullOrEmpty(moduleGuid) || moduleGuid == Path.DirectorySeparatorChar.ToString()) { return(false); } var basePath = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads"); var fullPath = Path.Combine(basePath, moduleGuid); using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { if (!Directory.Exists(fullPath)) { return(true); } try { Directory.Delete(fullPath, true); return(true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } else { log.Error("Could Not Reach Storage Path"); return(false); } } }
public bool TestBind() { try { _basePath = "LDAP://" + ServiceSetting.GetSettingValue(SettingStrings.LdapServer) + ":" + ServiceSetting.GetSettingValue(SettingStrings.LdapPort) + "/"; _username = ServiceSetting.GetSettingValue(SettingStrings.LdapBindUsername); _password = new EncryptionServices().DecryptText(ServiceSetting.GetSettingValue(SettingStrings.LdapBindPassword)); _baseDn = ServiceSetting.GetSettingValue(SettingStrings.LdapBaseDN); var entry = InitializeEntry(); var searcher = new DirectorySearcher(entry); searcher.Filter = "(objectCategory=organizationalUnit)"; searcher.PropertiesToLoad.Add("ou"); searcher.PropertiesToLoad.Add("distinguishedName"); searcher.SizeLimit = 0; searcher.PageSize = 500; searcher.FindOne(); return(true); } catch (Exception ex) { Logger.Debug("Active Directory Bind Failed."); Logger.Error(ex.Message); return(false); } }
public byte [] RunAllServers(DtoIsoGenOptions isoOptions) { var uow = new UnitOfWork(); var tftpComServers = uow.ClientComServerRepository.Get(x => x.IsTftpServer); EntityClientComServer tftpInfoServer; if (tftpComServers.Count == 0) { Logger.Error("No Tftp Servers Are Currently Enabled To Generate ISO"); return(null); } if (tftpComServers.Count > 1) { tftpInfoServer = tftpComServers.Where(x => x.IsTftpInfoServer).FirstOrDefault(); if (tftpInfoServer == null) { Logger.Error("No Tftp Servers Are Currently Set As The Information Server. Unable To Generate ISO"); return(null); } } else { tftpInfoServer = tftpComServers.First(); } //Connect To Client Com Server var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var result = new APICall().ClientComServerApi.GenerateISO(tftpInfoServer.Url, "", decryptedKey, isoOptions); return(result); }
public List <string> Run() { var uow = new UnitOfWork(); var tftpComServers = uow.ClientComServerRepository.Get(x => x.IsTftpServer); EntityClientComServer tftpInfoServer; if (tftpComServers.Count == 0) { Logger.Error("No Tftp Servers Are Currently Enabled To Retrieve Kernel Listing"); return(null); } if (tftpComServers.Count > 1) { tftpInfoServer = tftpComServers.Where(x => x.IsTftpInfoServer).FirstOrDefault(); if (tftpInfoServer == null) { Logger.Error("No Tftp Servers Are Currently Set As The Information Server. Unable To Retrieve Kernel Listing"); return(null); } } else { tftpInfoServer = tftpComServers.First(); } //Connect To Client Com Server var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.GetKernels(tftpInfoServer.Url, "", decryptedKey)); }
public string GetHdFileSize(string imageName, string hd) { var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { try { var imagePath = basePath + "images" + Path.DirectorySeparatorChar + imageName + Path.DirectorySeparatorChar + "hd" + hd; var size = GetDirectorySize(new DirectoryInfo(imagePath)) / 1024f / 1024f / 1024f; return(Math.Abs(size) < 0.1f ? "< 100M" : size.ToString("#.##") + " GB"); } catch { return("N/A"); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return("N/A"); } } }
public bool Copy() { var guid = ConfigurationManager.AppSettings["ComServerUniqueId"]; _thisComServer = new ServiceClientComServer().GetServerByGuid(guid); if (_thisComServer == null) { Logger.Error($"Com Server With Guid {guid} Not Found"); return(false); } if (string.IsNullOrEmpty(_thisComServer.TftpPath)) { Logger.Error($"Com Server With Guid {guid} Does Not Have A Valid Tftp Path"); return(false); } _sourceRootPath = _thisComServer.TftpPath + "static" + Path.DirectorySeparatorChar; var copyResult = ServiceSetting.GetSettingValue(SettingStrings.ProxyDhcpEnabled) == "Yes" ? CopyFilesForProxy() : CopyFilesForNonProxy(); return(copyResult); }
public bool RenameImageFolder(string oldName, string newName) { //Check again if (string.IsNullOrEmpty(oldName) || string.IsNullOrEmpty(newName)) { return(false); } var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { try { var imagePath = basePath + @"\images\"; Directory.Move(imagePath + oldName, imagePath + newName); return(true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return(false); } } }
public string ReadSchemaFile(string imageName) { var schemaText = ""; var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); var path = basePath + "images" + Path.DirectorySeparatorChar + imageName + Path.DirectorySeparatorChar + "schema"; using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { try { using (var reader = new StreamReader(path)) { schemaText = reader.ReadLine() ?? ""; } } catch (Exception ex) { log.Error("Could Not Read Schema File."); log.Error(ex.Message); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return(null); } } return(schemaText); }
public UploadController() { Context = HttpContext.Current; Request = HttpContext.Current.Request; Response = HttpContext.Current.Response; _basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); }
public bool RebootComputer(int computerId) { Logger.Debug("Starting Reboot Task"); var shutdownDelay = ServiceSetting.GetSettingValue(SettingStrings.ShutdownDelay); return(Reboot(computerId, shutdownDelay)); }
private bool GetMsiArgs() { var certEntity = _uow.CertificateRepository.GetFirstOrDefault(x => x.Type == EnumCertificate.CertificateType.Authority); if (certEntity == null) { return(false); } var pfx = new X509Certificate2(certEntity.PfxBlob, new EncryptionServices().DecryptText(certEntity.Password), X509KeyStorageFlags.Exportable); _thumbprint = pfx.Thumbprint; var provisionKeyEncrypted = ServiceSetting.GetSettingValue(SettingStrings.ProvisionKeyEncrypted); _serverKey = new EncryptionServices().DecryptText(provisionKeyEncrypted); var defaultCluster = _uow.ComServerClusterRepository.GetFirstOrDefault(x => x.IsDefault); var clusterServers = _uow.ComServerClusterServerRepository.Get(x => x.ComServerClusterId == defaultCluster.Id); _comServers = ""; foreach (var s in clusterServers) { var comServer = _uow.ClientComServerRepository.GetById(s.ComServerId); _comServers += comServer.Url + ","; } _comServers = _comServers.Trim(','); return(true); }
public bool Sync() { if (!ServiceSetting.GetSettingValue(SettingStrings.StorageType).Equals("SMB")) { return(true); } using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { RoboCommand backup = new RoboCommand(); // events backup.OnFileProcessed += backup_OnFileProcessed; backup.OnCommandCompleted += backup_OnCommandCompleted; // copy options backup.CopyOptions.Source = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); backup.CopyOptions.Destination = ConfigurationManager.AppSettings["LocalStoragePath"].Trim('\\'); backup.CopyOptions.CopySubdirectories = true; backup.CopyOptions.UseUnbufferedIo = true; // select options //backup.SelectionOptions.OnlyCopyArchiveFilesAndResetArchiveFlag = true; backup.CopyOptions.Mirror = true; backup.CopyOptions.Purge = false; backup.SelectionOptions.ExcludeOlder = true; backup.LoggingOptions.VerboseOutput = true; // retry options backup.RetryOptions.RetryCount = 1; backup.RetryOptions.RetryWaitTime = 2; backup.Start(); return(true); } return(false); } }
private void AddComputerToToemsGroup(EntityComputer computer) { if (string.IsNullOrEmpty(ServiceSetting.GetSettingValue(SettingStrings.NewProvisionDefaultGroup))) { Logger.Debug("New Provision default group is not enabled. Skipping"); return; } var group = _groupService.GetGroupByName(ServiceSetting.GetSettingValue(SettingStrings.NewProvisionDefaultGroup)); if (group == null) { return; } if (group.Type.Equals("Dynamic")) { return; } var groupMembership = new EntityGroupMembership(); groupMembership.ComputerId = computer.Id; groupMembership.GroupId = group.Id; _groupMemberships.Add(groupMembership); _groupMembershipService.AddMembership(_groupMemberships); }
public bool Run() { Logger.Debug("Starting Active Directory Sync"); if (ServiceSetting.GetSettingValue(SettingStrings.LdapEnabled) != "1") { Logger.Debug("LDAP integration is not enabled. Skipping"); return(true); } if (string.IsNullOrEmpty(ServiceSetting.GetSettingValue(SettingStrings.LdapServer))) { Logger.Debug("LDAP values not populated. Skipping"); return(true); } _basePath = "LDAP://" + ServiceSetting.GetSettingValue(SettingStrings.LdapServer) + ":" + ServiceSetting.GetSettingValue(SettingStrings.LdapPort) + "/"; _username = ServiceSetting.GetSettingValue(SettingStrings.LdapBindUsername); _password = new EncryptionServices().DecryptText(ServiceSetting.GetSettingValue(SettingStrings.LdapBindPassword)); _baseDn = ServiceSetting.GetSettingValue(SettingStrings.LdapBaseDN); var ous = GetOUs(); var parents = GetParentOU(ous); CreateOuGroups(ous, parents); SyncComputers(); UpdateMemberships(); Logger.Debug("Finished Active Directory Sync"); return(true); }
private bool Shutdown(int computerId, string delay) { var computer = _uow.ComputerRepository.GetById(computerId); if (computer == null) { return(false); } if (computer.CertificateId == -1) { return(false); } var compPreventShutdownGroups = _uow.ComputerRepository.GetComputerPreventShutdownGroups(computerId); if (compPreventShutdownGroups.Count > 0) { return(true); //computer is in a prevent shutdown group continue on } var socket = _uow.ActiveSocketRepository.GetFirstOrDefault(x => x.ComputerId == computer.Id); if (socket != null) { var deviceCertEntity = _uow.CertificateRepository.GetById(computer.CertificateId); var deviceCert = new X509Certificate2(deviceCertEntity.PfxBlob, new EncryptionServices().DecryptText(deviceCertEntity.Password), X509KeyStorageFlags.Exportable); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var socketRequest = new DtoSocketRequest(); socketRequest.connectionIds.Add(socket.ConnectionId); socketRequest.action = "Shutdown"; socketRequest.message = delay; new APICall().ClientComServerApi.SendAction(socket.ComServer, "", decryptedKey, socketRequest); } return(true); }
private void SendMailAsync() { try { var message = new MailMessage(ServiceSetting.GetSettingValue(SettingStrings.SmtpMailFrom), MailTo) { Subject = "Toems " + "(" + Subject + ")", Body = Body }; var client = new SmtpClient(ServiceSetting.GetSettingValue(SettingStrings.SmtpServer), Convert.ToInt32(ServiceSetting.GetSettingValue(SettingStrings.SmtpPort))) { Credentials = new NetworkCredential(ServiceSetting.GetSettingValue(SettingStrings.SmtpUsername), new EncryptionServices().DecryptText( ServiceSetting.GetSettingValue(SettingStrings.SmtpPassword))), EnableSsl = ServiceSetting.GetSettingValue(SettingStrings.SmtpSsl) == "Yes" }; client.Send(message); } catch (Exception ex) { log.Error(ex.Message); } }
public bool DeleteImageFolders(string imageName) { //Check again if (string.IsNullOrEmpty(imageName)) { return(false); } var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { try { Directory.Delete(basePath + @"\images" + @"\" + imageName, true); return(true); } catch (Exception ex) { log.Error(ex.Message); return(false); } } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); return(false); } } }
public async Task DownloadFile() { EntityDownload.DateDownloaded = DateTime.Now; EntityDownload.Status = EnumFileDownloader.DownloadStatus.Downloading; if (EntityDownload.Id == 0) { _serviceExternalDownload.Add(EntityDownload); } else { _serviceExternalDownload.Update(EntityDownload); } _destinationDir = Path.Combine(ServiceSetting.GetSettingValue(SettingStrings.StoragePath), "software_uploads", EntityDownload.ModuleGuid); var dirResult = CreateDirectory(); if (dirResult != null) { EntityDownload.Status = EnumFileDownloader.DownloadStatus.Error; EntityDownload.ErrorMessage = dirResult; _serviceExternalDownload.Update(EntityDownload); return; } using (_webClient = new WebClient()) { _webClient.DownloadProgressChanged += wc_DownloadProgressChanged; _webClient.DownloadFileCompleted += wc_DownloadFileCompleted; await _webClient.DownloadFileTaskAsync(new Uri(EntityDownload.Url), Path.Combine(_destinationDir, EntityDownload.FileName)); } }
public DtoApiBoolResponse IsStorageRemote() { var response = new DtoApiBoolResponse(); var storageValue = ServiceSetting.GetSettingValue(SettingStrings.StorageType); response.Value = storageValue.Equals("SMB"); return(response); }
public static List <string> GetComServerLogs(int comServerId) { var comServer = new ServiceClientComServer().GetServer(comServerId); var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); return(new APICall().ClientComServerApi.GetComServerLogs(comServer.Url, "", decryptedKey)); }
public bool Authenticate(string username, string pwd, string ldapGroup = null) { if (ServiceSetting.GetSettingValue(SettingStrings.LdapEnabled) != "1") { return(false); } var path = "LDAP://" + ServiceSetting.GetSettingValue(SettingStrings.LdapServer) + ":" + ServiceSetting.GetSettingValue(SettingStrings.LdapPort) + "/" + ServiceSetting.GetSettingValue(SettingStrings.LdapBaseDN); string _filterAttribute = null; var entry = new DirectoryEntry(path, username, pwd); if (ServiceSetting.GetSettingValue(SettingStrings.LdapAuthType) == "Basic") { entry.AuthenticationType = AuthenticationTypes.None; } else if (ServiceSetting.GetSettingValue(SettingStrings.LdapAuthType) == "Secure") { entry.AuthenticationType = AuthenticationTypes.Secure; } else if (ServiceSetting.GetSettingValue(SettingStrings.LdapAuthType) == "SSL") { entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer; } try { // Bind to the native AdsObject to force authentication. var obj = entry.NativeObject; var search = new DirectorySearcher(entry); search.Filter = "(" + ServiceSetting.GetSettingValue(SettingStrings.LdapAuthAttribute) + "=" + username + ")"; search.PropertiesToLoad.Add("cn"); search.PropertiesToLoad.Add("memberOf"); var result = search.FindOne(); if (null == result) { return(false); } // Update the new path to the user in the directory path = result.Path; _filterAttribute = (string)result.Properties["cn"][0]; } catch (Exception ex) { log.Error("Could Not Authenticate User: "******" " + ex.Message); return(false); } if (ldapGroup != null) { return(GetGroups(_filterAttribute, path, ldapGroup)); } return(true); }
public int RunOnComServer(DtoMulticastArgs mArgs, EntityClientComServer comServer) { var intercomKey = ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted); var decryptedKey = new EncryptionServices().DecryptText(intercomKey); var pid = new APICall().ClientComServerApi.StartUdpSender(comServer.Url, "", decryptedKey, mArgs); return(pid); }
public bool Sync() { if (!ServiceSetting.GetSettingValue(SettingStrings.StorageType).Equals("SMB")) { return(true); } var guid = ConfigurationManager.AppSettings["ComServerUniqueId"]; var thisComServer = new ServiceClientComServer().GetServerByGuid(guid); if (thisComServer == null) { Logger.Error($"Com Server With Guid {guid} Not Found"); return(false); } using (var unc = new UncServices()) { if (unc.NetUseWithCredentials() || unc.LastError == 1219) { foreach (var folder in new [] { "client_versions", "software_uploads" }) { RoboCommand backup = new RoboCommand(); // events backup.OnError += Backup_OnError; // copy options backup.CopyOptions.Source = ServiceSetting.GetSettingValue(SettingStrings.StoragePath) + folder; backup.CopyOptions.Destination = thisComServer.LocalStoragePath + folder.Trim('\\'); backup.CopyOptions.CopySubdirectories = true; backup.CopyOptions.UseUnbufferedIo = true; if (thisComServer.ReplicationRateIpg != 0) { backup.CopyOptions.InterPacketGap = thisComServer.ReplicationRateIpg; } else { backup.CopyOptions.InterPacketGap = 0; } // select options backup.CopyOptions.Mirror = true; backup.CopyOptions.Purge = true; backup.LoggingOptions.VerboseOutput = false; // retry options backup.RetryOptions.RetryCount = 3; backup.RetryOptions.RetryWaitTime = 10; backup.Start().Wait(); } return(true); } return(false); } }
public DtoApiBoolResponse SendEmailTest() { var mail = new MailServices { Subject = "Test Message", Body = "Email Notifications Are Working!", MailTo = ServiceSetting.GetSettingValue(SettingStrings.SmtpMailTo) }; mail.Send(); return(new DtoApiBoolResponse { Value = true }); }
public DtoFreeSpace GetSMBFreeSpace() { var storageType = ServiceSetting.GetSettingValue(SettingStrings.StorageType); if (storageType.Equals("Local")) { return(null); //no smb share setup } var dpFreeSpace = new DtoFreeSpace(); var basePath = ServiceSetting.GetSettingValue(SettingStrings.StoragePath); using (var unc = new UncServices()) { if ( unc.NetUseWithCredentials() || unc.LastError == 1219) { ulong freespace = 0; ulong total = 0; var success = DriveFreeBytes(basePath, out freespace, out total); if (!success) { return(null); } var freePercent = 0; var usedPercent = 0; if (total > 0 && freespace > 0) { freePercent = (int)(0.5f + 100f * Convert.ToInt64(freespace) / Convert.ToInt64(total)); usedPercent = (int)(0.5f + 100f * Convert.ToInt64(total - freespace) / Convert.ToInt64(total)); } dpFreeSpace.freespace = freespace; dpFreeSpace.total = total; dpFreeSpace.freePercent = freePercent; dpFreeSpace.usedPercent = usedPercent; dpFreeSpace.dPPath = basePath; } else { log.Error("Failed to connect to " + basePath + "\r\nLastError = " + unc.LastError); } } return(dpFreeSpace); }
private async Task <bool> isValidRequest(HttpRequestMessage req, string APPId, string incomingBase64Signature, string nonce, string requestTimeStamp) { string requestContentBase64String = ""; string requestUri = HttpUtility.UrlEncode(req.RequestUri.AbsoluteUri.ToLower()); string requestHttpMethod = req.Method.Method; var serverKeyBytes = Encoding.ASCII.GetBytes( new EncryptionServices().DecryptText( ServiceSetting.GetSettingValue(SettingStrings.IntercomKeyEncrypted))); var sharedKey = Convert.ToBase64String(serverKeyBytes); if (isReplayRequest(nonce, requestTimeStamp)) { Logger.Debug($"ID: {logId} - Request appears to be a replay, denying {nonce} {requestTimeStamp}"); return(false); } byte[] hash = await ComputeHash(req.Content); if (hash != null) { requestContentBase64String = Convert.ToBase64String(hash); } string data = String.Format("{0}{1}{2}{3}{4}{5}", APPId, requestHttpMethod, requestUri, requestTimeStamp, nonce, requestContentBase64String); Logger.Debug($"ID: {logId} - Expected Signature Data " + data); var secretKeyBytes = Convert.FromBase64String(sharedKey); byte[] signature = Encoding.UTF8.GetBytes(data); using (HMACSHA256 hmac = new HMACSHA256(secretKeyBytes)) { byte[] signatureBytes = hmac.ComputeHash(signature); var result = (incomingBase64Signature.Equals(Convert.ToBase64String(signatureBytes), StringComparison.Ordinal)); if (!result) { Logger.Debug($"ID: {logId} - Signature mismatch"); } Logger.Debug($"ID: {logId} - Expected Signature: " + Convert.ToBase64String(signatureBytes)); return(result); } }
private DirectoryEntry InitializeEntry() { var entry = new DirectoryEntry(_basePath + _baseDn, _username, _password); var ldapAuth = ServiceSetting.GetSettingValue(SettingStrings.LdapAuthType); if (ldapAuth == "Basic") { entry.AuthenticationType = AuthenticationTypes.None; } else if (ldapAuth == "Secure") { entry.AuthenticationType = AuthenticationTypes.Secure; } //else if (ldapAuth == "SSL") // entry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer; return(entry); }
private byte[] GenerateDeviceCert(string symmKey, EntityComputer computer) { var iCert = new ServiceCertificate().GetIntermediate(); byte[] symmetricKey; using (RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)iCert.PrivateKey) { var encryptedKey = Convert.FromBase64String(symmKey); symmetricKey = rsa.Decrypt(encryptedKey, true); } var intermediateEntity = new ServiceCertificate().GetIntermediateEntity(); var pass = new EncryptionServices().DecryptText(intermediateEntity.Password); var intermediateCert = new X509Certificate2(intermediateEntity.PfxBlob, pass, X509KeyStorageFlags.Exportable); var certRequest = new CertificateRequest(); var organization = ServiceSetting.GetSettingValue(SettingStrings.CertificateOrganization); certRequest.SubjectName = string.Format("O={0},CN={1}", organization, computer.Guid); certRequest.NotBefore = DateTime.UtcNow; certRequest.NotAfter = certRequest.NotBefore.AddYears(10); var certificate = new ServiceGenerateCertificate(certRequest).IssueCertificate(intermediateCert, false, false); var c = new EntityCertificate(); c.NotAfter = certificate.NotAfter; c.NotBefore = certificate.NotBefore; c.Serial = certificate.SerialNumber; var pfxPass = Membership.GeneratePassword(10, 0); c.Password = new EncryptionServices().EncryptText(pfxPass); c.PfxBlob = certificate.Export(X509ContentType.Pfx, pfxPass); c.SubjectName = certificate.Subject; c.Type = EnumCertificate.CertificateType.Device; var base64DeviceCert = Convert.ToBase64String(certificate.RawData); var encryptedCert = new ServiceSymmetricEncryption().EncryptData(symmetricKey, base64DeviceCert); new ServiceCertificate().AddCertificate(c); computer.CertificateId = c.Id; computer.ProvisionStatus = EnumProvisionStatus.Status.PendingConfirmation; computer.SymmKeyEncrypted = new EncryptionServices().EncryptText(Convert.ToBase64String(symmetricKey)); return(encryptedCert); }
public bool Run() { Logger.Debug("Starting Active Directory Sync"); _basePath = "LDAP://" + ServiceSetting.GetSettingValue(SettingStrings.LdapServer) + ":" + ServiceSetting.GetSettingValue(SettingStrings.LdapPort) + "/"; _username = ServiceSetting.GetSettingValue(SettingStrings.LdapBindUsername); _password = new EncryptionServices().DecryptText(ServiceSetting.GetSettingValue(SettingStrings.LdapBindPassword)); _baseDn = ServiceSetting.GetSettingValue(SettingStrings.LdapBaseDN); var ous = GetOUs(); var parents = GetParentOU(ous); CreateOuGroups(ous, parents); SyncComputers(); UpdateMemberships(); Logger.Debug("Finished Active Directory Sync"); return(true); }