mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-20 08:05:53 +02:00
Added IGSSMechanism interface
This commit is contained in:
parent
45dc792558
commit
d4acf5900e
3 changed files with 75 additions and 1 deletions
35
SMBLibrary/Authentication/GSSAPI/IGSSMechanism.cs
Normal file
35
SMBLibrary/Authentication/GSSAPI/IGSSMechanism.cs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
|
||||||
|
*
|
||||||
|
* You can redistribute this program and/or modify it under the terms of
|
||||||
|
* the GNU Lesser Public License as published by the Free Software Foundation,
|
||||||
|
* either version 3 of the License, or (at your option) any later version.
|
||||||
|
*/
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SMBLibrary.Authentication.GSSAPI
|
||||||
|
{
|
||||||
|
public interface IGSSMechanism
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Equivalent to GSS_Accept_sec_context
|
||||||
|
/// </summary>
|
||||||
|
NTStatus AcceptSecurityContext(ref object context, byte[] inputToken, out byte[] outputToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Equivalent to GSS_Delete_sec_context
|
||||||
|
/// Obtains information about a given security context (even an incomplete one)
|
||||||
|
/// </summary>
|
||||||
|
void DeleteSecurityContext(ref object context);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Equivalent to GSS_Inquire_context
|
||||||
|
/// </summary>
|
||||||
|
object GetContextAttribute(object context, GSSAttributeName attributeName);
|
||||||
|
|
||||||
|
byte[] Identifier
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,8 +10,38 @@ using SMBLibrary.Authentication.GSSAPI;
|
||||||
|
|
||||||
namespace SMBLibrary.Authentication.NTLM
|
namespace SMBLibrary.Authentication.NTLM
|
||||||
{
|
{
|
||||||
public abstract class NTLMAuthenticationProviderBase
|
public abstract class NTLMAuthenticationProviderBase : IGSSMechanism
|
||||||
{
|
{
|
||||||
|
public static readonly byte[] NTLMSSPIdentifier = new byte[] { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x02, 0x02, 0x0a };
|
||||||
|
|
||||||
|
public NTStatus AcceptSecurityContext(ref object context, byte[] inputToken, out byte[] outputToken)
|
||||||
|
{
|
||||||
|
outputToken = null;
|
||||||
|
if (!AuthenticationMessageUtils.IsSignatureValid(inputToken))
|
||||||
|
{
|
||||||
|
return NTStatus.SEC_E_INVALID_TOKEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageTypeName messageType = AuthenticationMessageUtils.GetMessageType(inputToken);
|
||||||
|
if (messageType == MessageTypeName.Negotiate)
|
||||||
|
{
|
||||||
|
NegotiateMessage input = new NegotiateMessage(inputToken);
|
||||||
|
ChallengeMessage output;
|
||||||
|
NTStatus status = GetChallengeMessage(out context, input, out output);
|
||||||
|
outputToken = output.GetBytes();
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
else if (messageType == MessageTypeName.Authenticate)
|
||||||
|
{
|
||||||
|
AuthenticateMessage message = new AuthenticateMessage(inputToken);
|
||||||
|
return Authenticate(context, message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NTStatus.SEC_E_INVALID_TOKEN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public abstract NTStatus GetChallengeMessage(out object context, NegotiateMessage negotiateMessage, out ChallengeMessage challengeMessage);
|
public abstract NTStatus GetChallengeMessage(out object context, NegotiateMessage negotiateMessage, out ChallengeMessage challengeMessage);
|
||||||
|
|
||||||
public abstract NTStatus Authenticate(object context, AuthenticateMessage authenticateMessage);
|
public abstract NTStatus Authenticate(object context, AuthenticateMessage authenticateMessage);
|
||||||
|
@ -19,5 +49,13 @@ namespace SMBLibrary.Authentication.NTLM
|
||||||
public abstract void DeleteSecurityContext(ref object context);
|
public abstract void DeleteSecurityContext(ref object context);
|
||||||
|
|
||||||
public abstract object GetContextAttribute(object context, GSSAttributeName attributeName);
|
public abstract object GetContextAttribute(object context, GSSAttributeName attributeName);
|
||||||
|
|
||||||
|
public byte[] Identifier
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return NTLMSSPIdentifier;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Authentication\GSSAPI\Enums\GSSAttributeName.cs" />
|
<Compile Include="Authentication\GSSAPI\Enums\GSSAttributeName.cs" />
|
||||||
<Compile Include="Authentication\GSSAPI\GSSAPIHelper.cs" />
|
<Compile Include="Authentication\GSSAPI\GSSAPIHelper.cs" />
|
||||||
|
<Compile Include="Authentication\GSSAPI\IGSSMechanism.cs" />
|
||||||
<Compile Include="Authentication\GSSAPI\SPNEGO\DerEncodingHelper.cs" />
|
<Compile Include="Authentication\GSSAPI\SPNEGO\DerEncodingHelper.cs" />
|
||||||
<Compile Include="Authentication\GSSAPI\SPNEGO\SimpleProtectedNegotiationToken.cs" />
|
<Compile Include="Authentication\GSSAPI\SPNEGO\SimpleProtectedNegotiationToken.cs" />
|
||||||
<Compile Include="Authentication\GSSAPI\SPNEGO\SimpleProtectedNegotiationTokenInit.cs" />
|
<Compile Include="Authentication\GSSAPI\SPNEGO\SimpleProtectedNegotiationTokenInit.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue