Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Jun 25, 2016
0 parents commit 3ddeaa5
Show file tree
Hide file tree
Showing 1,360 changed files with 229,174 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# editorconfig.org

# top-most EditorConfig file
root = true

# Default settings:
# A newline ending every file
# Use 4 spaces as indentation
[*]
insert_final_newline = true
indent_style = space
indent_size = 4

# Xml project files
[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
indent_size = 2

# Xml files
[*.{xml,stylecop,resx,ruleset}]
indent_size = 2

# Xml config files
[*.{props,targets,config,nuspec}]
indent_size = 2

# Shell scripts
[*.sh]
end_of_line = lf
[*.{cmd, bat}]
end_of_line = crlf
22 changes: 22 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
build/
*.suo
*.user
_ReSharper*
*.csproj.user
*.resharper.user
*.userprefs
*.suo
*.cache
*.trx
*.pidb
Thumbs.db
[Bb]in
[Dd]ebug
[Oo]bj
[Rr]elease
[Tt]est[Rr]esult*
_UpgradeReport_Files
*[Pp]ublish.xml
*.project
*.metadata
logs
*.generated.cs
T4MVC.cs
/SharpSnmpLib/sharpsnmplib.snk
/packages
/lib/sharpsnmplib.snk
/gendarme
/lib/Activelock3.6.NET/ActiveLock3_6NET.xml
/lib/Activelock3.6.NET/SharpSnmpLib.Optional.dll
/lib/NBug.dll

/SharpSnmpLib.Mib/Help

/NDependOut
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "lib/ExpandCollapsePanel"]
path = lib/ExpandCollapsePanel
url = [email protected]:lextm/ExpandCollapsePanel.git
[submodule "mwa"]
path = mwa
url = [email protected]:jexuswebserver/Microsoft.Web.Administration.git
Binary file added .nuget/NuGet.exe
Binary file not shown.
6 changes: 6 additions & 0 deletions CertificateInstaller/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
78 changes: 78 additions & 0 deletions CertificateInstaller/CertificateInstaller.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{54BEC09A-B32F-4A66-A871-749E0621D822}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CertificateInstaller</RootNamespace>
<AssemblyName>CertificateInstaller</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>..\JexusManager\JexusManager.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Options, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Mono.Options.4.4.0.0\lib\net4-client\Mono.Options.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\mwa\Microsoft.Web.Administration\NativeMethods.cs">
<Link>NativeMethods.cs</Link>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest">
<SubType>Designer</SubType>
</None>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
146 changes: 146 additions & 0 deletions CertificateInstaller/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// Copyright (c) Lex Li. All rights reserved.
//
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;

namespace CertificateInstaller
{
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;

using Microsoft.Web.Administration;

using Mono.Options;

internal class Program
{
private static int Main(string[] args)
{
string p12File = null;
string p12Pwd = null;
string friendlyName = null;
string store = null;
string hash = null;
string address = null;
string port = null;
string id = null;
string host = null;

OptionSet p =
new OptionSet().Add("f:", "File name", delegate (string v) { if (v != null) p12File = v; })
.Add("p:", "Password", delegate (string v) { if (v != null) p12Pwd = v; })
.Add("n:", "Friendly name", delegate (string v) { if (v != null) friendlyName = v; })
.Add("s:", "Store name", delegate (string v) { if (v != null) store = v; })
.Add("h:", "Certificate hash (not required when adding certificates)", delegate (string v) { if (v != null) hash = v; })
.Add("a:", "IP address", delegate (string v) { if (v != null) address = v; })
.Add("o:", "Port number", delegate (string v) { if (v != null) port = v; })
.Add("i:", "Application ID", delegate (string v) { if (v != null) id = v; })
.Add("x:", "SNI host name (not required when managing IP based bindings)", delegate (string v) { if (v != null) host = v; });

if (args.Length == 0)
{
ShowHelp(p);
return -1;
}

List<string> extra;
try
{
extra = p.Parse(args);
}
catch (OptionException ex)
{
Console.WriteLine(ex.Message);
return -1;
}

if (extra.Count > 0)
{
ShowHelp(p);
return -1;
}

try
{
X509Store personal = new X509Store(store, StoreLocation.LocalMachine);
personal.Open(OpenFlags.ReadWrite);
if (hash == null)
{
// add certificate
// http://paulstovell.com/blog/x509certificate2
var x509 = new X509Certificate2(
p12File,
p12Pwd,
X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet
| X509KeyStorageFlags.MachineKeySet);
x509.FriendlyName = friendlyName;
personal.Add(x509);
personal.Close();
return 0;
}

var selectedItem = personal.Certificates.Find(X509FindType.FindByThumbprint, hash, false);
if (address == null)
{
if (host == null)
{
// remove certificate and mapping
var mappings = NativeMethods.QuerySslCertificateInfo();
foreach (var mapping in mappings)
{
if (mapping.Hash.SequenceEqual(selectedItem[0].GetCertHash()))
{
NativeMethods.DeleteCertificateBinding(mapping.IpPort);
}
}

personal.Remove(selectedItem[0]);
}
else
{
var mappings = NativeMethods.QuerySslSniInfo();
foreach (var mapping in mappings)
{
if (mapping.Hash.SequenceEqual(selectedItem[0].GetCertHash()))
{
NativeMethods.DeleteSniBinding(new Tuple<string, int>(mapping.Host, mapping.Port));
}
}
}

personal.Close();
return 0;
}

if (host == null)
{
// register mapping
var endpoint = new IPEndPoint(IPAddress.Parse(address), int.Parse(port));
NativeMethods.BindCertificate(endpoint, selectedItem[0].GetCertHash(), store, Guid.Parse(id));
}
else
{
NativeMethods.BindSni(new Tuple<string, int>(host, int.Parse(port)), selectedItem[0].GetCertHash(), store, Guid.Parse(id));
}

return 0;
}
catch (Exception ex)
{
Console.WriteLine(ex);
return -1;
}
}

private static void ShowHelp(OptionSet optionSet)
{
Console.WriteLine("Jexus Manager is available at https://jexus.codeplex.com");
Console.WriteLine("CertificateInstaller.exe [Options]");
Console.WriteLine("Options:");
optionSet.WriteOptionDescriptions(Console.Out);
}
}
}
40 changes: 40 additions & 0 deletions CertificateInstaller/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Lex Li. All rights reserved.
//
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CertificateInstaller")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CertificateInstaller")]
[assembly: AssemblyCopyright("Copyright \u00A9 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("54bec09a-b32f-4a66-a871-749e0621d822")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit 3ddeaa5

Please sign in to comment.