Updated comments.

This commit is contained in:
antiduh
2014-07-01 19:17:56 +00:00
parent ce64bf9d9a
commit 7503d37770
9 changed files with 92 additions and 37 deletions

View File

@@ -7,8 +7,15 @@ using System.Threading.Tasks;
namespace NSspi.Credentials namespace NSspi.Credentials
{ {
/// <summary>
/// Represents the credentials of the user running the current process, for use as an SSPI client.
/// </summary>
public class ClientCredential : CurrentCredential public class ClientCredential : CurrentCredential
{ {
/// <summary>
/// Initializes a new instance of the ClientCredential class.
/// </summary>
/// <param name="package">The security package to acquire the credential handle from.</param>
public ClientCredential( string package ) public ClientCredential( string package )
: base( package, CredentialUse.Outbound ) : base( package, CredentialUse.Outbound )
{ {

View File

@@ -12,16 +12,35 @@ using NSspi.Credentials.Credentials;
namespace NSspi.Credentials namespace NSspi.Credentials
{ {
/// <summary>
/// Provides access to the pre-existing credentials of a security principle.
/// </summary>
public class Credential : IDisposable public class Credential : IDisposable
{ {
/// <summary>
/// Whether the Credential has been disposed.
/// </summary>
private bool disposed; private bool disposed;
/// <summary>
/// The name of the security package that controls the credential.
/// </summary>
private string securityPackage; private string securityPackage;
/// <summary>
/// A safe handle to the credential's handle.
/// </summary>
private SafeCredentialHandle safeCredHandle; private SafeCredentialHandle safeCredHandle;
/// <summary>
/// The UTC time the credentials expire.
/// </summary>
private DateTime expiry; private DateTime expiry;
/// <summary>
/// Initializes a new instance of the Credential class.
/// </summary>
/// <param name="package">The security package to acquire the credential from.</param>
public Credential( string package ) public Credential( string package )
{ {
this.disposed = false; this.disposed = false;
@@ -32,8 +51,14 @@ namespace NSspi.Credentials
this.PackageInfo = PackageSupport.GetPackageCapabilities( this.SecurityPackage ); this.PackageInfo = PackageSupport.GetPackageCapabilities( this.SecurityPackage );
} }
/// <summary>
/// Gets metadata for the security package associated with the credential.
/// </summary>
public SecPkgInfo PackageInfo { get; private set; } public SecPkgInfo PackageInfo { get; private set; }
/// <summary>
/// Gets the name of the security package that owns the credential.
/// </summary>
public string SecurityPackage public string SecurityPackage
{ {
get get
@@ -44,6 +69,9 @@ namespace NSspi.Credentials
} }
} }
/// <summary>
/// Returns the name of the principle of the credential.
/// </summary>
public string Name public string Name
{ {
get get
@@ -107,6 +135,9 @@ namespace NSspi.Credentials
} }
} }
/// <summary>
/// Gets the UTC time the credentials expire.
/// </summary>
public DateTime Expiry public DateTime Expiry
{ {
get get
@@ -124,6 +155,9 @@ namespace NSspi.Credentials
} }
} }
/// <summary>
/// Gets a handle to the credential.
/// </summary>
public SafeCredentialHandle Handle public SafeCredentialHandle Handle
{ {
get get
@@ -141,6 +175,9 @@ namespace NSspi.Credentials
} }
} }
/// <summary>
/// Releases all resources associated with the credential.
/// </summary>
public void Dispose() public void Dispose()
{ {
Dispose( true ); Dispose( true );

View File

@@ -12,30 +12,6 @@ namespace NSspi.Credentials
{ {
internal static class CredentialNativeMethods internal static class CredentialNativeMethods
{ {
/*
SECURITY_STATUS SEC_Entry AcquireCredentialsHandle(
_In_ SEC_CHAR *pszPrincipal, // [in] name of principal. NULL = principal of current security context
_In_ SEC_CHAR *pszPackage, // [in] name of security package - "Kerberos", "Negotiate", "NTLM", etc
_In_ ULONG fCredentialUse, // [in] flags indicating use.
_In_ PLUID pvLogonID, // [in] pointer to logon identifier. NULL = we're not specifying the id of another logon session
_In_ PVOID pAuthData, // [in] package-specific data. NULL = default credentials for security package
_In_ SEC_GET_KEY_FN pGetKeyFn, // [in] pointer to GetKey function. NULL = we're not using a callback to retrieve the credentials
_In_ PVOID pvGetKeyArgument, // [in] value to pass to GetKey
_Out_ PCredHandle phCredential, // [out] credential handle (this must be already allocated)
_Out_ PTimeStamp ptsExpiry // [out] lifetime of the returned credentials
);
SECURITY_STATUS SEC_Entry FreeCredentialsHandle(
_In_ PCredHandle phCredential
);
SECURITY_STATUS SEC_Entry QueryCredentialsAttributes(
_In_ PCredHandle phCredential,
_In_ ULONG ulAttribute,
_Out_ PVOID pBuffer
);
*/
[ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail)] [ReliabilityContract( Consistency.WillNotCorruptState, Cer.MayFail)]
[DllImport( "Secur32.dll", EntryPoint = "AcquireCredentialsHandle", CharSet = CharSet.Unicode )] [DllImport( "Secur32.dll", EntryPoint = "AcquireCredentialsHandle", CharSet = CharSet.Unicode )]
internal static extern SecurityStatus AcquireCredentialsHandle( internal static extern SecurityStatus AcquireCredentialsHandle(

View File

@@ -6,18 +6,14 @@ using System.Threading.Tasks;
namespace NSspi.Credentials namespace NSspi.Credentials
{ {
/* /// <summary>
#define SECPKG_CRED_ATTR_NAMES 1 /// Identifies credential query types.
#define SECPKG_CRED_ATTR_SSI_PROVIDER 2 /// </summary>
#define SECPKG_CRED_ATTR_KDC_PROXY_SETTINGS 3
#define SECPKG_CRED_ATTR_CERT 4
*/
public enum CredentialQueryAttrib : uint public enum CredentialQueryAttrib : uint
{ {
/// <summary>
/// Queries the credential's principle name.
/// </summary>
Names = 1, Names = 1,
SsiProvider = 2,
KdcProxySettings = 3,
Cert = 4
} }
} }

View File

@@ -6,10 +6,27 @@ using System.Threading.Tasks;
namespace NSspi.Credentials namespace NSspi.Credentials
{ {
/// <summary>
/// Indicates the manner in which a credential will be used for SSPI authentication.
/// </summary>
public enum CredentialUse : uint public enum CredentialUse : uint
{ {
/// <summary>
/// The credentials will be used for establishing a security context with an inbound request, eg,
/// the credentials will be used by a server building a security context with a client.
/// </summary>
Inbound = 1, Inbound = 1,
/// <summary>
/// The credentials will be used for establishing a security context as an outbound request,
/// eg, the credentials will be used by a client to build a security context with a server.
/// </summary>
Outbound = 2, Outbound = 2,
/// <summary>
/// The credentials may be used to to either build a client's security context or a server's
/// security context.
/// </summary>
Both = 3, Both = 3,
} }
} }

View File

@@ -7,8 +7,18 @@ using System.Threading.Tasks;
namespace NSspi.Credentials namespace NSspi.Credentials
{ {
/// <summary>
/// Acquires a handle to the credentials of the user associated with the current process.
/// </summary>
public class CurrentCredential : Credential public class CurrentCredential : Credential
{ {
/// <summary>
/// Initializes a new instance of the CurrentCredential class.
/// </summary>
/// <param name="securityPackage">The security package to acquire the credential handle
/// from.</param>
/// <param name="use">The manner in which the credentials will be used - Inbound typically
/// represents servers, outbound typically represent clients.</param>
public CurrentCredential( string securityPackage, CredentialUse use ) : public CurrentCredential( string securityPackage, CredentialUse use ) :
base( securityPackage ) base( securityPackage )
{ {

View File

@@ -7,9 +7,16 @@ using System.Threading.Tasks;
namespace NSspi.Credentials.Credentials namespace NSspi.Credentials.Credentials
{ {
/// <summary>
/// Stores the result from a query of a credential's principle name.
/// </summary>
[StructLayout( LayoutKind.Sequential )] [StructLayout( LayoutKind.Sequential )]
public struct QueryNameAttribCarrier internal struct QueryNameAttribCarrier
{ {
/// <summary>
/// A pointer to a null-terminated ascii c-string containing the principle name
/// associated with a credential
/// </summary>
public IntPtr Name; public IntPtr Name;
} }
} }

View File

@@ -7,7 +7,9 @@ using System.Threading.Tasks;
namespace NSspi.Credentials namespace NSspi.Credentials
{ {
/// <summary>
/// Provides a managed handle to an SSPI credential.
/// </summary>
public class SafeCredentialHandle : SafeSspiHandle public class SafeCredentialHandle : SafeSspiHandle
{ {
public SafeCredentialHandle() public SafeCredentialHandle()

View File

@@ -7,6 +7,9 @@ using System.Threading.Tasks;
namespace NSspi.Credentials namespace NSspi.Credentials
{ {
/// <summary>
/// Represents the credentials of the user running the current process, for use as an SSPI server.
/// </summary>
public class ServerCredential : CurrentCredential public class ServerCredential : CurrentCredential
{ {
public ServerCredential( string package ) public ServerCredential( string package )