Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ end_of_line = crlf

[*.cs]

[*.generated.cs]
generated_code = true

# IDE0063: Use simple 'using' statement
csharp_prefer_simple_using_statement = true:silent

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ bld/

# Visual Studio 2015 cache/options directory
.vs/
# Visual Studio Code directory
.vscode/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

Expand Down Expand Up @@ -285,4 +287,4 @@ __pycache__/
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
*.xsd.cs
23 changes: 19 additions & 4 deletions Bruce/Bruce.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<TargetFramework>net8.0-windows</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Kerberos.NET.CommandLine</RootNamespace>

<RollForward>Major</RollForward>
Expand Down Expand Up @@ -33,13 +40,21 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DnsClient" Version="1.7.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Kerberos.NET.PortableDns\Kerberos.NET.PortableDns.csproj" />
<ProjectReference Include="..\Kerberos.NET\Kerberos.NET.csproj" />
<ProjectReference Include="..\Samples\KerbDumpCore\KerbDumpCore.csproj" />
<ProjectReference Include="..\Samples\KerbDumpCore\KerbDumpCore.csproj"
Condition="'$(OS)' == 'Windows_NT'" />
</ItemGroup>

<Target Name="NETSDK1146Workaround" BeforeTargets="_PackToolValidation">
<PropertyGroup>
<TargetPlatformIdentifier></TargetPlatformIdentifier>
<TargetPlatformMoniker></TargetPlatformMoniker>
</PropertyGroup>
</Target>

</Project>
14 changes: 9 additions & 5 deletions Bruce/CommandLine/KerberosDumpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
// -----------------------------------------------------------------------

using System.Threading.Tasks;
#if WINDOWS
using System.Windows.Forms;
using KerbDump;
#endif

namespace Kerberos.NET.CommandLine
{
Expand All @@ -14,8 +16,10 @@ public class KerberosDumpCommand : BaseCommand
{
static KerberosDumpCommand()
{
#if WINDOWS
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
#endif
}

public KerberosDumpCommand(CommandLineParameters parameters)
Expand All @@ -29,11 +33,7 @@ public KerberosDumpCommand(CommandLineParameters parameters)

public override Task<bool> Execute()
{
if (!OSPlatform.IsWindows)
{
return Task.FromResult(false);
}

#if WINDOWS
using (var form = new DecoderForm()
{
Ticket = this.Ticket,
Expand All @@ -44,6 +44,10 @@ public override Task<bool> Execute()
}

return Task.FromResult(true);
#else
return Task.FromResult(false);
#endif
}
}
}

4 changes: 2 additions & 2 deletions Bruce/CommandLine/KerberosHelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ private void WriteCommandLabel(Type type, int max = 0)

if (string.Equals(descName, desc, StringComparison.OrdinalIgnoreCase))
{
this.WriteLine(string.Format(format, label), attr.Description, commands.Skip(1));
this.WriteLine(string.Format(format, label), attr.Description, string.Join(", ", commands.Skip(1)));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this. It's been mildly bugging me for a while now.

}
else
{
this.WriteLine(string.Format(format, label), desc, commands.Skip(1));
this.WriteLine(string.Format(format, label), desc, string.Join(", ", commands.Skip(1)));
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions Bruce/CommandLine/KerberosPasswordCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// -----------------------------------------------------------------------

using Kerberos.NET.Configuration;
using Kerberos.NET.Credentials;
using Kerberos.NET.Crypto;
using Kerberos.NET.Entities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Kerberos.NET.CommandLine
{
Expand Down
10 changes: 6 additions & 4 deletions Bruce/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using Kerberos.NET.PortableDns;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Kerberos.NET.CommandLine.Dns;
using Kerberos.NET.Dns;

namespace Kerberos.NET.CommandLine
{
Expand All @@ -12,7 +11,10 @@ class Program
[STAThread]
static void Main(string[] args)
{
DnsQuery.RegisterImplementation(new PlatformIndependentDnsClient());
if (!OSPlatform.IsWindows)
{
PortableDnsClient.Configure();
}

var assembly = Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName);

Expand Down
15 changes: 15 additions & 0 deletions Kerberos.NET.PortableDns/Kerberos.NET.PortableDns.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DnsClient" Version="1.8.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Kerberos.NET\Kerberos.NET.csproj" />
</ItemGroup>

</Project>
51 changes: 51 additions & 0 deletions Kerberos.NET.PortableDns/PortableDnsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using DnsClient;
using System.Linq;
using System.Net;

namespace Kerberos.NET.PortableDns
{
public static class PortableDnsClient
{
public static void Configure()
{
PortableDnsImplementation.Options = new LookupClientOptions();
}

public static void Configure(params NameServer[] nameServers)
{
PortableDnsImplementation.Options = new LookupClientOptions(nameServers);
}

public static void Configure(params IPEndPoint[] nameServers)
{
PortableDnsImplementation.Options = new LookupClientOptions(nameServers);
}

public static void Configure(params IPAddress[] nameServers)
{
PortableDnsImplementation.Options = new LookupClientOptions(nameServers);
}

public static void Configure(params string[] nameServers)
{
PortableDnsImplementation.Options = new LookupClientOptions(nameServers.Select(n => {
var parts = n.Split(':');
IPAddress address;
switch (parts.Length)
{
case 1:
address = IPAddress.Parse(parts[0]);
return new IPEndPoint(address, 53);
case 2:
address = IPAddress.Parse(parts[0]);
var port = int.Parse(parts[1]);
return new IPEndPoint(address, port);
default:
throw new System.FormatException($"{n} is not in the correct format 'IPaddress:Port'");
}
}).ToArray());
}

public static LookupClientOptions Options => PortableDnsImplementation.Options;
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
using System;
using DnsClient;
using Kerberos.NET.Dns;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DnsClient;
using Kerberos.NET.Dns;

namespace Kerberos.NET.CommandLine.Dns
namespace Kerberos.NET.PortableDns
{
internal class PlatformIndependentDnsClient : IKerberosDnsQuery
internal class PortableDnsImplementation : IKerberosDnsQuery
{
private static readonly WindowsDnsQuery WindowsDns = new WindowsDnsQuery();

public async Task<IReadOnlyCollection<DnsRecord>> Query(string query, DnsRecordType type)
static PortableDnsImplementation()
{
if (WindowsDns.IsSupported)
{
return await WindowsDns.Query(query, type);
}
DnsQuery.RegisterImplementation(new PortableDnsImplementation());
}

var client = new LookupClient();
public static LookupClientOptions Options { get; set; } = new LookupClientOptions();

var response = await client.QueryAsync(query, (QueryType)type);
private static LookupClient Create()
{
return new LookupClient(Options);
}

public async Task<IReadOnlyCollection<DnsRecord>> Query(string query, DnsRecordType type)
{
var client = Create();
var response = await client.QueryAsync(query, (QueryType)type);
var srvRecords = response.Answers.SrvRecords().Select(a => new DnsRecord
{
Name = a.DomainName,
Expand All @@ -38,9 +41,7 @@ public async Task<IReadOnlyCollection<DnsRecord>> Query(string query, DnsRecordT
foreach (var srv in srvRecords)
{
var c1 = merged.Where(m => m.Key.Equals(srv.Target, StringComparison.InvariantCultureIgnoreCase));

var canon = c1.SelectMany(r => r);

srv.Canonical = canon.ToList();
}

Expand Down
11 changes: 9 additions & 2 deletions Kerberos.NET.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29006.145
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kerberos.NET", "Kerberos.NET\Kerberos.NET.csproj", "{3066D890-0544-4E13-95FD-1DDCC72FEDA1}"
EndProject
Expand Down Expand Up @@ -29,6 +29,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Client Tools", "Client Tool
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bruce", "Bruce\Bruce.csproj", "{D12B0644-0D57-45ED-AA0A-AB18D593CCA3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Kerberos.NET.PortableDns", "Kerberos.NET.PortableDns\Kerberos.NET.PortableDns.csproj", "{3085F7D7-B384-4EB6-B5F4-CAEDC7C1C0E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -55,6 +57,10 @@ Global
{D12B0644-0D57-45ED-AA0A-AB18D593CCA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D12B0644-0D57-45ED-AA0A-AB18D593CCA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D12B0644-0D57-45ED-AA0A-AB18D593CCA3}.Release|Any CPU.Build.0 = Release|Any CPU
{3085F7D7-B384-4EB6-B5F4-CAEDC7C1C0E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3085F7D7-B384-4EB6-B5F4-CAEDC7C1C0E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3085F7D7-B384-4EB6-B5F4-CAEDC7C1C0E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3085F7D7-B384-4EB6-B5F4-CAEDC7C1C0E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -65,6 +71,7 @@ Global
{046122A3-9C6F-42E8-A21E-E4F2CD4DBCF8} = {8BD43321-3C92-4D6F-B965-783F2CC4CEE1}
{5115DFE1-AD08-4AF5-B88C-F436744D7A3A} = {8F0C1D56-CBBB-4B8B-81D1-5D1544AD5C72}
{D12B0644-0D57-45ED-AA0A-AB18D593CCA3} = {8BD43321-3C92-4D6F-B965-783F2CC4CEE1}
{3085F7D7-B384-4EB6-B5F4-CAEDC7C1C0E6} = {E3EE549C-8245-45E7-A964-E38C78DC9FD3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {17150968-CFF9-4183-989D-C93E19033096}
Expand Down
10 changes: 8 additions & 2 deletions Kerberos.NET/Asn1/AsnXml.targets
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
</None>
</ItemGroup>

<!-- MSBuild for .NET Core doesn't support XslTransform at this time -->
<Target Name="CompileAsn" BeforeTargets="CoreCompile"
Inputs="@(AsnXml);$(MSBuildThisFileDirectory)asn.xslt"
Outputs="%(Identity).cs">
Expand All @@ -32,11 +31,18 @@
<Output TaskParameter="ExitCode" ItemName="_AsnXmlDiffCode" />
</Exec>

<Exec Condition="'$(OS)'=='Unix'"
IgnoreExitCode="true"
StandardOutputImportance="Low"
Command="/usr/bin/diff -w @(AsnXml -> '$(IntermediateOutputPath)asnxml\%(filename).cs') @(AsnXml -> '%(RelativeDir)%(filename).generated.cs')">
<Output TaskParameter="ExitCode" ItemName="_AsnXmlDiffCode" />
</Exec>

<Copy
Condition="'@(_AsnXmlDiffCode)' != '0'"
SourceFiles="@(AsnXml -> '$(IntermediateOutputPath)asnxml\%(filename).cs')"
DestinationFiles="@(AsnXml -> '%(RelativeDir)%(filename).generated.cs')" />

<Warning Condition="'@(_AsnXmlDiffCode)' != '0'" Text="AsnXml regenerated files, be sure to check them in: @(AsnXml -> '%(RelativeDir)%(filename).generated.cs')" />
</Target>
</Project>
</Project>
10 changes: 8 additions & 2 deletions Kerberos.NET/Cache/FileHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ internal class FileHandle : IDisposable
private readonly FileMode mode;
private readonly FileAccess access;
private readonly FileShare share;
#nullable enable
private static readonly MethodInfo? SetUnixFileMode = TryGetSetUnixFileMode();

#nullable disable
private static readonly TimeSpan LockWaitTimeout = TimeSpan.FromMilliseconds(5000);

public FileHandle(string file, FileMode mode, FileAccess access, FileShare share)
Expand Down Expand Up @@ -78,6 +79,7 @@ private static string GetObjectName(string file, string type)
.Replace(Path.VolumeSeparatorChar, '_');
}

#nullable enable
private static MethodInfo? TryGetSetUnixFileMode()
{
MethodInfo? mi = null;
Expand All @@ -90,11 +92,15 @@ private static string GetObjectName(string file, string type)
{
mi = typeof(File).GetMethod("SetUnixFileMode", new Type[] { typeof(SafeFileHandle), Type.GetType("System.IO.UnixFileMode") });
}
catch { }
catch
{
// ignored
}
}

return mi;
}
#nullable disable

private class FileLock : IDisposable
{
Expand Down
Loading
Loading