Skip to content

Commit b8fd19c

Browse files
Merge pull request #366 from nvisionative/develop
Merge `develop` into `main` for `2.3.0` release
2 parents 21b2e50 + 581205d commit b8fd19c

9 files changed

+169
-14
lines changed

nvQuickSite/Controllers/IISController.cs

+52-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace nvQuickSite.Controllers
2222
using System.Globalization;
2323
using System.Linq;
2424
using System.Runtime.InteropServices;
25+
using System.Security.Cryptography.X509Certificates;
2526

2627
using Microsoft.Web.Administration;
2728
using nvQuickSite.Controllers.Exceptions;
@@ -39,7 +40,8 @@ public static class IISController
3940
/// <param name="installFolder">The path to the hosting folder for the site.</param>
4041
/// <param name="useSiteSpecificAppPool">A value indicating whether to use a site specific App Pool.</param>
4142
/// <param name="deleteSiteIfExists">If true will delete and recreate the site.</param>
42-
internal static void CreateSite(string siteName, string installFolder, bool useSiteSpecificAppPool, bool deleteSiteIfExists)
43+
/// <param name="certificate">The certificate to use for the site.</param>
44+
internal static void CreateSite(string siteName, string installFolder, bool useSiteSpecificAppPool, bool deleteSiteIfExists, X509Certificate2 certificate = null)
4345
{
4446
Log.Logger.Information("Creating site {siteName} in {installFolder}", siteName, installFolder);
4547
if (SiteExists(siteName, deleteSiteIfExists))
@@ -51,10 +53,18 @@ internal static void CreateSite(string siteName, string installFolder, bool useS
5153
try
5254
{
5355
var bindingInfo = "*:80:" + siteName;
56+
var protocol = "http";
5457

5558
using (ServerManager iisManager = new ServerManager())
5659
{
57-
Site site = iisManager.Sites.Add(siteName, "http", bindingInfo, installFolder + "\\Website");
60+
Site site = iisManager.Sites.Add(siteName, protocol, bindingInfo, installFolder + "\\Website");
61+
if (certificate != null)
62+
{
63+
bindingInfo = "*:443:" + siteName;
64+
protocol = "https";
65+
}
66+
67+
site.Bindings.Add(bindingInfo, protocol);
5868
site.TraceFailedRequestsLogging.Enabled = true;
5969
site.TraceFailedRequestsLogging.Directory = installFolder + "\\Logs";
6070
site.LogFile.Directory = installFolder + "\\Logs" + "\\W3svc" + site.Id.ToString(CultureInfo.InvariantCulture);
@@ -152,6 +162,46 @@ internal static void DeleteAppPool(string appPoolName, IProgress<int> progress)
152162
}
153163
}
154164

165+
/// <summary>
166+
/// Gets a list of SSL certificates available for use within IIS.
167+
/// </summary>
168+
/// <returns>An enumeration of SSL certificates.</returns>
169+
internal static List<X509Certificate2> GetSslCertificates()
170+
{
171+
Log.Logger.Information("Getting a list of SSL certificates");
172+
var certificates = new List<X509Certificate2>();
173+
174+
var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
175+
try
176+
{
177+
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
178+
179+
foreach (var certificate in store.Certificates)
180+
{
181+
foreach (var extension in certificate.Extensions)
182+
{
183+
if (extension.Oid.FriendlyName == "Enhanced Key Usage" && extension is X509EnhancedKeyUsageExtension enhancedKeyUsageExtension)
184+
{
185+
foreach (var item in enhancedKeyUsageExtension.EnhancedKeyUsages)
186+
{
187+
if (item.FriendlyName == "Server Authentication")
188+
{
189+
certificates.Add(certificate);
190+
}
191+
}
192+
}
193+
}
194+
}
195+
196+
Log.Logger.Debug("Found the following SSL certificates {@certicates}", certificates);
197+
return certificates;
198+
}
199+
finally
200+
{
201+
store.Close();
202+
}
203+
}
204+
155205
/// <summary>
156206
/// Gets a list of IIS sites.
157207
/// </summary>

nvQuickSite/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@
4949
// You can specify all the values or you can default the Build and Revision Numbers
5050
// by using the '*' as shown below:
5151
// [assembly: AssemblyVersion("1.0.*")]
52-
[assembly: AssemblyVersion("2.2.0")]
53-
[assembly: AssemblyFileVersion("2.2.0")]
52+
[assembly: AssemblyVersion("2.3.0")]
53+
[assembly: AssemblyFileVersion("2.3.0")]
5454
[assembly: NeutralResourcesLanguage("en")]

nvQuickSite/Properties/Settings.Designer.cs

+25-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nvQuickSite/Properties/Settings.settings

+6
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,11 @@
4747
<Setting Name="EnableLocalPackageInstall" Type="System.Boolean" Scope="User">
4848
<Value Profile="(Default)">False</Value>
4949
</Setting>
50+
<Setting Name="EnableSsl" Type="System.Boolean" Scope="User">
51+
<Value Profile="(Default)">False</Value>
52+
</Setting>
53+
<Setting Name="CertificateFriendlyName" Type="System.String" Scope="User">
54+
<Value Profile="(Default)" />
55+
</Setting>
5056
</Settings>
5157
</SettingsFile>

nvQuickSite/Start.Designer.cs

+31-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nvQuickSite/Start.cs

+43-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace nvQuickSite
2626
using System.IO;
2727
using System.Linq;
2828
using System.Net;
29+
using System.Security.Cryptography.X509Certificates;
2930
using System.Windows.Forms;
3031

3132
using Ionic.Zip;
@@ -52,6 +53,7 @@ public partial class Start : MetroUserControl
5253
private long total;
5354
private long lastVal;
5455
private long sum;
56+
private List<X509Certificate2> certificates;
5557

5658
/// <summary>
5759
/// Initializes a new instance of the <see cref="Start"/> class.
@@ -128,6 +130,12 @@ private void ReadUserSettings()
128130
this.txtSiteNameSuffix.Text = Properties.Settings.Default.SiteNameSuffixRecent;
129131
this.chkSiteSpecificAppPool.Checked = Properties.Settings.Default.AppPoolRecent;
130132
this.chkDeleteSiteIfExists.Checked = Properties.Settings.Default.DeleteSiteInIISRecent;
133+
this.chkEnableSsl.Checked = Properties.Settings.Default.EnableSsl;
134+
if (Properties.Settings.Default.CertificateFriendlyName != string.Empty)
135+
{
136+
this.cboCertificates.SelectedItem = Properties.Settings.Default.CertificateFriendlyName;
137+
}
138+
131139
this.txtInstallBaseFolder.Text = Properties.Settings.Default.InstallBaseFolderRecent;
132140

133141
this.txtDBServerName.Text = Properties.Settings.Default.DatabaseServerNameRecent;
@@ -144,6 +152,12 @@ private void SaveUserSettings()
144152
Properties.Settings.Default.SiteNameSuffixRecent = this.txtSiteNameSuffix.Text;
145153
Properties.Settings.Default.AppPoolRecent = this.chkSiteSpecificAppPool.Checked;
146154
Properties.Settings.Default.DeleteSiteInIISRecent = this.chkDeleteSiteIfExists.Checked;
155+
Properties.Settings.Default.EnableSsl = this.chkEnableSsl.Checked;
156+
if (this.cboCertificates.SelectedItem != null)
157+
{
158+
Properties.Settings.Default.CertificateFriendlyName = this.cboCertificates.SelectedItem.ToString();
159+
}
160+
147161
Properties.Settings.Default.InstallBaseFolderRecent = this.txtInstallBaseFolder.Text;
148162

149163
Properties.Settings.Default.DatabaseServerNameRecent = this.txtDBServerName.Text;
@@ -412,6 +426,31 @@ private void txtSiteNamePrefix_TextChanged(object sender, EventArgs e)
412426
this.txtDBName.Text = this.txtSiteNamePrefix.Text;
413427
}
414428

429+
private void chkEnableSsl_CheckedChanged(object sender, EventArgs e)
430+
{
431+
this.cboCertificates.Visible = false;
432+
if (this.chkEnableSsl.Checked)
433+
{
434+
this.LoadSslCertificates();
435+
this.cboCertificates.Visible = true;
436+
}
437+
}
438+
439+
private void LoadSslCertificates()
440+
{
441+
this.cboCertificates.Items.Clear();
442+
this.certificates = IISController.GetSslCertificates();
443+
this.certificates.ForEach(c => this.cboCertificates.Items.Add(c.FriendlyName != string.Empty ? c.FriendlyName : c.Subject.Split(',')[0].Split('=')[1]));
444+
if (this.cboCertificates.Items.Count > 0)
445+
{
446+
this.cboCertificates.SelectedIndex = 0;
447+
if (Properties.Settings.Default.CertificateFriendlyName != string.Empty)
448+
{
449+
this.cboCertificates.SelectedItem = Properties.Settings.Default.CertificateFriendlyName;
450+
}
451+
}
452+
}
453+
415454
private void btnSiteInfoNext_Click(object sender, EventArgs e)
416455
{
417456
bool proceed;
@@ -549,7 +588,8 @@ private void btnDatabaseInfoNext_Click(object sender, EventArgs e)
549588
this.SiteName,
550589
this.InstallFolder,
551590
this.chkSiteSpecificAppPool.Checked,
552-
this.chkDeleteSiteIfExists.Checked);
591+
this.chkDeleteSiteIfExists.Checked,
592+
this.certificates[this.cboCertificates.SelectedIndex]);
553593

554594
FileSystemController.UpdateHostsFile(this.SiteName);
555595

@@ -668,7 +708,8 @@ private void myZip_ExtractProgress(object sender, ExtractProgressEventArgs e)
668708

669709
private void btnVisitSite_Click(object sender, EventArgs e)
670710
{
671-
var url = "http://" + this.SiteName;
711+
var protocol = this.chkEnableSsl.Checked ? "https://" : "http://";
712+
var url = protocol + this.SiteName;
672713
Log.Logger.Information("Visiting {url}", url);
673714
Process.Start(url);
674715
Log.Logger.Information("Closing application");

nvQuickSite/app.config

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,20 @@
5252
<setting name="EnableLocalPackageInstall" serializeAs="String">
5353
<value>False</value>
5454
</setting>
55+
<setting name="EnableSsl" serializeAs="String">
56+
<value>False</value>
57+
</setting>
58+
<setting name="CertificateFriendlyName" serializeAs="String">
59+
<value />
60+
</setting>
5561
</nvQuickSite.Properties.Settings>
5662
</userSettings>
5763
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup>
5864
<runtime>
5965
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
6066
<dependentAssembly>
6167
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
62-
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0" />
68+
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
6369
</dependentAssembly>
6470
</assemblyBinding>
6571
</runtime>

nvQuickSite/data/latestVersion.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"latestVersion": "2.2.0"
2+
"latestVersion": "2.3.0"
33
}

nvQuickSite/nvQuickSite.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
5-
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
5+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
77
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
88
<ProjectGuid>{3D661BAD-45EB-4524-9650-78805CD31682}</ProjectGuid>
@@ -279,7 +279,7 @@
279279
<PrivateAssets>all</PrivateAssets>
280280
</PackageReference>
281281
<PackageReference Include="Newtonsoft.Json">
282-
<Version>13.0.1</Version>
282+
<Version>13.0.2</Version>
283283
</PackageReference>
284284
<PackageReference Include="Octokit">
285285
<Version>0.32.0</Version>

0 commit comments

Comments
 (0)