public void TestThatFilePathForResourceIsValid()
        {
            var path = ConDepResourceFiles.GetFilePath(Assembly.GetExecutingAssembly(), GetType().Namespace, "ResourceTestFile.txt");

            Assert.That(File.Exists(path));
            File.Delete(path);
        }
        private string ExtractPowerShellFileFromResource(Assembly assembly, string localTargetPath, string resource)
        {
            var regex = new Regex(@".+\.(.+\.ps1)");
            var match = regex.Match(resource);

            if (match.Success)
            {
                var resourceName = match.Groups[1].Value;
                if (!string.IsNullOrWhiteSpace(resourceName))
                {
                    var resourceNamespace = resource.Replace("." + resourceName, "");
                    return(ConDepResourceFiles.GetFilePath(assembly, resourceNamespace, resourceName, localTargetPath, true));
                }
            }
            return(null);
        }
        private string GetFilePathForConDepScriptModule(string resource)
        {
            var regex = new Regex(@".+\.(.+\.(ps1|psm1))");
            var match = regex.Match(resource);

            if (match.Success)
            {
                var resourceName = match.Groups[1].Value;
                if (!string.IsNullOrWhiteSpace(resourceName))
                {
                    var resourceNamespace = resource.Replace("." + resourceName, "");
                    return(ConDepResourceFiles.GetFilePath(GetType().Assembly, resourceNamespace, resourceName, keepOriginalFileName: true));
                }
            }
            return(null);
        }
        private void SaveConDepScriptModuleResourceToFolder(string localTargetPath)
        {
            var resource = ConDepResources.ConDepModule;

            var regex = new Regex(@".+\.(.+\.(ps1|psm1))");
            var match = regex.Match(resource);

            if (match.Success)
            {
                var resourceName = match.Groups[1].Value;
                if (!string.IsNullOrWhiteSpace(resourceName))
                {
                    var resourceNamespace = resource.Replace("." + resourceName, "");
                    ConDepResourceFiles.GetFilePath(GetType().Assembly, resourceNamespace, resourceName, localTargetPath, true);
                }
            }
        }
Exemple #5
0
        private void ConfigureSsl(ServerConfig server)
        {
            var resource = PfxInstallerResource.PfxInstallerScript;
            var script   = ConDepResourceFiles.GetResourceText(GetType().Assembly, resource);

            var dstPathDos = Path.Combine(server.GetServerInfo().TempFolderDos, "node.con-dep.net.pfx");
            var dstPathPs  = Path.Combine(server.GetServerInfo().TempFolderPowerShell, "node.con-dep.net.pfx");

            var certBytes = ConDepResourceFiles.GetResourceBytes(GetType().Assembly,
                                                                 new ConDepResource
            {
                Resource  = "node.con-dep.net.pfx",
                Namespace = typeof(ConDepResourceFiles).Namespace
            });

            var executor = new PowerShellExecutor(server)
            {
                LoadConDepModule = false
            };

            var scriptResult = executor.Execute(string.Format(@"
$conDepReturnValues = New-Object PSObject -Property @{{         
    ConDepResult    = $false 
}}     

$cert = Get-ChildItem Cert:\LocalMachine\My\{0} -ErrorAction SilentlyContinue
$conDepReturnValues.ConDepResult = !($cert -eq $null)
return $conDepReturnValues
", CERT_THUMBPRINT), logOutput: false);

            var certExist = false;

            foreach (var psObject in scriptResult)
            {
                if (psObject.ConDepResult == null)
                {
                    continue;
                }

                if (psObject.ConDepResult)
                {
                    certExist = true;
                }
            }

            if (!certExist)
            {
                Logger.Info("No SSL cert for ConDepNode found. Publishing now.");
                PublishFile(certBytes, dstPathPs, server);

                executor.Execute(script, new List <CommandParameter>
                {
                    new CommandParameter("filePath", dstPathDos),
                    new CommandParameter("password", CERT_PASS),
                });
                var cmd = string.Format(@"
$certThumbprint = ""{1}""
$appId = ""{2}""
netsh http add sslcert ipport=0.0.0.0:{0} certhash=$certThumbprint appid=$appId", _url.Port, CERT_THUMBPRINT, APP_ID);
                executor.Execute(cmd, logOutput: false);
                Logger.Info("SSL cert for ConDepNode published.");
            }
        }