Updated comments.
This commit is contained in:
@@ -8,10 +8,17 @@ namespace NSspi.Contexts
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SafeContextHandle : SafeSspiHandle
|
public class SafeContextHandle : SafeSspiHandle
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SafeContextHandle"/> class.
|
||||||
|
/// </summary>
|
||||||
public SafeContextHandle()
|
public SafeContextHandle()
|
||||||
: base()
|
: base()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases the safe context handle.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||||
protected override bool ReleaseHandle()
|
protected override bool ReleaseHandle()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ namespace NSspi.Credentials
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Credential : IDisposable
|
public class Credential : IDisposable
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The name of the security package that controls the credential.
|
||||||
|
/// </summary>
|
||||||
|
private readonly string securityPackage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the Credential has been disposed.
|
/// Whether the Credential has been disposed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool disposed;
|
private bool disposed;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The name of the security package that controls the credential.
|
|
||||||
/// </summary>
|
|
||||||
private string securityPackage;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A safe handle to the credential's handle.
|
/// A safe handle to the credential's handle.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -35,11 +35,10 @@ namespace NSspi.Credentials
|
|||||||
/// <param name="package">The security package to acquire the credential from.</param>
|
/// <param name="package">The security package to acquire the credential from.</param>
|
||||||
public Credential( string package )
|
public Credential( string package )
|
||||||
{
|
{
|
||||||
this.disposed = false;
|
|
||||||
this.securityPackage = package;
|
this.securityPackage = package;
|
||||||
|
|
||||||
|
this.disposed = false;
|
||||||
this.expiry = DateTime.MinValue;
|
this.expiry = DateTime.MinValue;
|
||||||
|
|
||||||
this.PackageInfo = PackageSupport.GetPackageCapabilities( this.SecurityPackage );
|
this.PackageInfo = PackageSupport.GetPackageCapabilities( this.SecurityPackage );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,6 +177,10 @@ namespace NSspi.Credentials
|
|||||||
GC.SuppressFinalize( this );
|
GC.SuppressFinalize( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases all resources associted with the credential.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing"></param>
|
||||||
protected virtual void Dispose( bool disposing )
|
protected virtual void Dispose( bool disposing )
|
||||||
{
|
{
|
||||||
if( this.disposed == false )
|
if( this.disposed == false )
|
||||||
|
|||||||
@@ -8,10 +8,17 @@ namespace NSspi.Credentials
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SafeCredentialHandle : SafeSspiHandle
|
public class SafeCredentialHandle : SafeSspiHandle
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SafeCredentialHandle"/> class.
|
||||||
|
/// </summary>
|
||||||
public SafeCredentialHandle()
|
public SafeCredentialHandle()
|
||||||
: base()
|
: base()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Releases the resources held by the credential handle.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||||
protected override bool ReleaseHandle()
|
protected override bool ReleaseHandle()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,19 +3,38 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace NSspi
|
namespace NSspi
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Tags an enumeration member with a string that can be programmatically accessed.
|
||||||
|
/// </summary>
|
||||||
[AttributeUsage( AttributeTargets.Field )]
|
[AttributeUsage( AttributeTargets.Field )]
|
||||||
public class EnumStringAttribute : Attribute
|
public class EnumStringAttribute : Attribute
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="EnumStringAttribute"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">The string to associate with the enumeration member.</param>
|
||||||
public EnumStringAttribute( string text )
|
public EnumStringAttribute( string text )
|
||||||
{
|
{
|
||||||
this.Text = text;
|
this.Text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the string associated with the enumeration member.
|
||||||
|
/// </summary>
|
||||||
public string Text { get; private set; }
|
public string Text { get; private set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts betwen enumeration members and the strings associated to the members through the
|
||||||
|
/// <see cref="EnumStringAttribute"/> type.
|
||||||
|
/// </summary>
|
||||||
public class EnumMgr
|
public class EnumMgr
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the text associated with the given enumeration member through a <see cref="EnumStringAttribute"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static string ToText( Enum value )
|
public static string ToText( Enum value )
|
||||||
{
|
{
|
||||||
FieldInfo field = value.GetType().GetField( value.ToString() );
|
FieldInfo field = value.GetType().GetField( value.ToString() );
|
||||||
@@ -32,6 +51,12 @@ namespace NSspi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the enumeration member that is tagged with the given text using the <see cref="EnumStringAttribute"/> type.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The enumeration type to inspect.</typeparam>
|
||||||
|
/// <param name="text"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public static T FromText<T>( string text )
|
public static T FromText<T>( string text )
|
||||||
{
|
{
|
||||||
FieldInfo[] fields = typeof( T ).GetFields();
|
FieldInfo[] fields = typeof( T ).GetFields();
|
||||||
|
|||||||
@@ -56,26 +56,48 @@ namespace NSspi
|
|||||||
[EnumString( "The security context was used after its expiration time passed." )]
|
[EnumString( "The security context was used after its expiration time passed." )]
|
||||||
ContextExpired = 0x00090317,
|
ContextExpired = 0x00090317,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The credentials supplied to the security context were not fully initialized.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "The credentials supplied to the security context were not fully initialized." )]
|
[EnumString( "The credentials supplied to the security context were not fully initialized." )]
|
||||||
CredentialsNeeded = 0x00090320,
|
CredentialsNeeded = 0x00090320,
|
||||||
|
|
||||||
[EnumString( "The context data must be re-negotiated with the peer" )]
|
/// <summary>
|
||||||
|
/// The context data must be re-negotiated with the peer.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The context data must be re-negotiated with the peer." )]
|
||||||
Renegotiate = 0x00090321,
|
Renegotiate = 0x00090321,
|
||||||
|
|
||||||
// Errors
|
// -------------- Errors --------------
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The SSPI operation failed due to insufficient memory resources.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "Not enough memory." )]
|
[EnumString( "Not enough memory." )]
|
||||||
OutOfMemory = 0x80090300,
|
OutOfMemory = 0x80090300,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The handle provided to the API was invalid.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "The handle provided to the API was invalid." )]
|
[EnumString( "The handle provided to the API was invalid." )]
|
||||||
InvalidHandle = 0x80090301,
|
InvalidHandle = 0x80090301,
|
||||||
|
|
||||||
[EnumString( "The attempted operation is not supported" )]
|
/// <summary>
|
||||||
|
/// The attempted operation is not supported.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The attempted operation is not supported." )]
|
||||||
Unsupported = 0x80090302,
|
Unsupported = 0x80090302,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The specified principle is not known in the authentication system.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "The specified principle is not known in the authentication system." )]
|
[EnumString( "The specified principle is not known in the authentication system." )]
|
||||||
TargetUnknown = 0x80090303,
|
TargetUnknown = 0x80090303,
|
||||||
|
|
||||||
[EnumString( "An internal error occurred" )]
|
/// <summary>
|
||||||
|
/// An internal error occurred
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "An internal error occurred." )]
|
||||||
InternalError = 0x80090304,
|
InternalError = 0x80090304,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -84,7 +106,16 @@ namespace NSspi
|
|||||||
[EnumString( "The requested security package was not found." )]
|
[EnumString( "The requested security package was not found." )]
|
||||||
PackageNotFound = 0x80090305,
|
PackageNotFound = 0x80090305,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cannot use the provided credentials, the caller is not the owner of the credentials.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The caller is not the owner of the desired credentials." )]
|
||||||
NotOwner = 0x80090306,
|
NotOwner = 0x80090306,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The requested security package failed to initalize, and thus cannot be used.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The requested security package failed to initalize, and thus cannot be used." )]
|
||||||
CannotInstall = 0x80090307,
|
CannotInstall = 0x80090307,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -93,7 +124,16 @@ namespace NSspi
|
|||||||
[EnumString( "The provided authentication token is invalid or corrupted." )]
|
[EnumString( "The provided authentication token is invalid or corrupted." )]
|
||||||
InvalidToken = 0x80090308,
|
InvalidToken = 0x80090308,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The security package is not able to marshall the logon buffer, so the logon attempt has failed
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The security package is not able to marshall the logon buffer, so the logon attempt has failed." )]
|
||||||
CannotPack = 0x80090309,
|
CannotPack = 0x80090309,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The per-message Quality of Protection is not supported by the security package.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The per-message Quality of Protection is not supported by the security package." )]
|
||||||
QopNotSupported = 0x8009030A,
|
QopNotSupported = 0x8009030A,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -102,22 +142,41 @@ namespace NSspi
|
|||||||
[EnumString( "Impersonation is not supported with the current security package." )]
|
[EnumString( "Impersonation is not supported with the current security package." )]
|
||||||
NoImpersonation = 0x8009030B,
|
NoImpersonation = 0x8009030B,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The logon was denied, perhaps because the provided credentials were incorrect.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "The logon was denied, perhaps because the provided credentials were incorrect." )]
|
[EnumString( "The logon was denied, perhaps because the provided credentials were incorrect." )]
|
||||||
LogonDenied = 0x8009030C,
|
LogonDenied = 0x8009030C,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The credentials provided are not recognized by the selected security package.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "The credentials provided are not recognized by the selected security package." )]
|
[EnumString( "The credentials provided are not recognized by the selected security package." )]
|
||||||
UnknownCredentials = 0x8009030D,
|
UnknownCredentials = 0x8009030D,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// No credentials are available in the selected security package.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "No credentials are available in the selected security package." )]
|
[EnumString( "No credentials are available in the selected security package." )]
|
||||||
NoCredentials = 0x8009030E,
|
NoCredentials = 0x8009030E,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A message that was provided to the Decrypt or VerifySignature functions was altered after
|
||||||
|
/// it was created.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "A message that was provided to the Decrypt or VerifySignature functions was altered " +
|
[EnumString( "A message that was provided to the Decrypt or VerifySignature functions was altered " +
|
||||||
"after it was created." )]
|
"after it was created." )]
|
||||||
MessageAltered = 0x8009030F,
|
MessageAltered = 0x8009030F,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A message was received out of the expected order.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "A message was received out of the expected order." )]
|
[EnumString( "A message was received out of the expected order." )]
|
||||||
OutOfSequence = 0x80090310,
|
OutOfSequence = 0x80090310,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current security package cannot contact an authenticating authority.
|
||||||
|
/// </summary>
|
||||||
[EnumString( "The current security package cannot contact an authenticating authority." )]
|
[EnumString( "The current security package cannot contact an authenticating authority." )]
|
||||||
NoAuthenticatingAuthority = 0x80090311,
|
NoAuthenticatingAuthority = 0x80090311,
|
||||||
|
|
||||||
@@ -132,20 +191,87 @@ namespace NSspi
|
|||||||
/// will indicate success, but will save off the extra, unrelated data in a buffer of
|
/// will indicate success, but will save off the extra, unrelated data in a buffer of
|
||||||
/// type 'extra'.
|
/// type 'extra'.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
|
[EnumString( "The buffer provided to an SSPI API call contained a message that was not complete." )]
|
||||||
IncompleteMessage = 0x80090318,
|
IncompleteMessage = 0x80090318,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The credentials supplied were not complete, and could not be verified. The context could not be initialized.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The credentials supplied were not complete, and could not be verified. The context could not be initialized." )]
|
||||||
IncompleteCredentials = 0x80090320,
|
IncompleteCredentials = 0x80090320,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The buffers supplied to a security function were too small.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The buffers supplied to a security function were too small." )]
|
||||||
BufferNotEnough = 0x80090321,
|
BufferNotEnough = 0x80090321,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The target principal name is incorrect.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The target principal name is incorrect." )]
|
||||||
WrongPrincipal = 0x80090322,
|
WrongPrincipal = 0x80090322,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The clocks on the client and server machines are skewed.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The clocks on the client and server machines are skewed." )]
|
||||||
TimeSkew = 0x80090324,
|
TimeSkew = 0x80090324,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The certificate chain was issued by an authority that is not trusted.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The certificate chain was issued by an authority that is not trusted." )]
|
||||||
UntrustedRoot = 0x80090325,
|
UntrustedRoot = 0x80090325,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The message received was unexpected or badly formatted.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The message received was unexpected or badly formatted." )]
|
||||||
IllegalMessage = 0x80090326,
|
IllegalMessage = 0x80090326,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An unknown error occurred while processing the certificate.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "An unknown error occurred while processing the certificate." )]
|
||||||
CertUnknown = 0x80090327,
|
CertUnknown = 0x80090327,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The received certificate has expired.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The received certificate has expired." )]
|
||||||
CertExpired = 0x80090328,
|
CertExpired = 0x80090328,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The client and server cannot communicate, because they do not possess a common algorithm.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The client and server cannot communicate, because they do not possess a common algorithm." )]
|
||||||
AlgorithmMismatch = 0x80090331,
|
AlgorithmMismatch = 0x80090331,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The security context could not be established due to a failure in the requested quality
|
||||||
|
/// of service (e.g. mutual authentication or delegation).
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "The security context could not be established due to a failure in the requested " +
|
||||||
|
"quality of service (e.g. mutual authentication or delegation)." )]
|
||||||
SecurityQosFailed = 0x80090332,
|
SecurityQosFailed = 0x80090332,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Smartcard logon is required and was not used.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "Smartcard logon is required and was not used." )]
|
||||||
SmartcardLogonRequired = 0x8009033E,
|
SmartcardLogonRequired = 0x8009033E,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An unsupported preauthentication mechanism was presented to the Kerberos package.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "An unsupported preauthentication mechanism was presented to the Kerberos package." )]
|
||||||
UnsupportedPreauth = 0x80090343,
|
UnsupportedPreauth = 0x80090343,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Client's supplied SSPI channel bindings were incorrect.
|
||||||
|
/// </summary>
|
||||||
|
[EnumString( "Client's supplied SSPI channel bindings were incorrect." )]
|
||||||
BadBinding = 0x80090346
|
BadBinding = 0x80090346
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,17 +55,27 @@ namespace NSspi
|
|||||||
{
|
{
|
||||||
internal RawSspiHandle rawHandle;
|
internal RawSspiHandle rawHandle;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="SafeSspiHandle"/> class.
|
||||||
|
/// </summary>
|
||||||
protected SafeSspiHandle()
|
protected SafeSspiHandle()
|
||||||
: base( IntPtr.Zero, true )
|
: base( IntPtr.Zero, true )
|
||||||
{
|
{
|
||||||
this.rawHandle = new RawSspiHandle();
|
this.rawHandle = new RawSspiHandle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets whether the handle is invalid.
|
||||||
|
/// </summary>
|
||||||
public override bool IsInvalid
|
public override bool IsInvalid
|
||||||
{
|
{
|
||||||
get { return IsClosed || this.rawHandle.IsZero(); }
|
get { return IsClosed || this.rawHandle.IsZero(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks the handle as no longer being in use.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.Success )]
|
||||||
protected override bool ReleaseHandle()
|
protected override bool ReleaseHandle()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ namespace NSspi
|
|||||||
[StructLayout( LayoutKind.Sequential )]
|
[StructLayout( LayoutKind.Sequential )]
|
||||||
public struct TimeStamp
|
public struct TimeStamp
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the calendar date and time corresponding a zero timestamp.
|
||||||
|
/// </summary>
|
||||||
public static readonly DateTime Epoch = new DateTime( 1601, 1, 1, 0, 0, 0, DateTimeKind.Utc );
|
public static readonly DateTime Epoch = new DateTime( 1601, 1, 1, 0, 0, 0, DateTimeKind.Utc );
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user