Updated comments.
This commit is contained in:
@@ -7,8 +7,15 @@ using System.Threading.Tasks;
|
||||
|
||||
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
|
||||
{
|
||||
/// <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 )
|
||||
: base( package, CredentialUse.Outbound )
|
||||
{
|
||||
|
||||
@@ -12,16 +12,35 @@ using NSspi.Credentials.Credentials;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides access to the pre-existing credentials of a security principle.
|
||||
/// </summary>
|
||||
public class Credential : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the Credential has been disposed.
|
||||
/// </summary>
|
||||
private bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// The name of the security package that controls the credential.
|
||||
/// </summary>
|
||||
private string securityPackage;
|
||||
|
||||
/// <summary>
|
||||
/// A safe handle to the credential's handle.
|
||||
/// </summary>
|
||||
private SafeCredentialHandle safeCredHandle;
|
||||
|
||||
/// <summary>
|
||||
/// The UTC time the credentials expire.
|
||||
/// </summary>
|
||||
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 )
|
||||
{
|
||||
this.disposed = false;
|
||||
@@ -31,9 +50,15 @@ namespace NSspi.Credentials
|
||||
|
||||
this.PackageInfo = PackageSupport.GetPackageCapabilities( this.SecurityPackage );
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets metadata for the security package associated with the credential.
|
||||
/// </summary>
|
||||
public SecPkgInfo PackageInfo { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name of the security package that owns the credential.
|
||||
/// </summary>
|
||||
public string SecurityPackage
|
||||
{
|
||||
get
|
||||
@@ -44,6 +69,9 @@ namespace NSspi.Credentials
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the name of the principle of the credential.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
@@ -107,6 +135,9 @@ namespace NSspi.Credentials
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the UTC time the credentials expire.
|
||||
/// </summary>
|
||||
public DateTime Expiry
|
||||
{
|
||||
get
|
||||
@@ -124,6 +155,9 @@ namespace NSspi.Credentials
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a handle to the credential.
|
||||
/// </summary>
|
||||
public SafeCredentialHandle Handle
|
||||
{
|
||||
get
|
||||
@@ -141,6 +175,9 @@ namespace NSspi.Credentials
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases all resources associated with the credential.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose( true );
|
||||
|
||||
@@ -12,30 +12,6 @@ namespace NSspi.Credentials
|
||||
{
|
||||
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)]
|
||||
[DllImport( "Secur32.dll", EntryPoint = "AcquireCredentialsHandle", CharSet = CharSet.Unicode )]
|
||||
internal static extern SecurityStatus AcquireCredentialsHandle(
|
||||
|
||||
@@ -6,18 +6,14 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
/*
|
||||
#define SECPKG_CRED_ATTR_NAMES 1
|
||||
#define SECPKG_CRED_ATTR_SSI_PROVIDER 2
|
||||
#define SECPKG_CRED_ATTR_KDC_PROXY_SETTINGS 3
|
||||
#define SECPKG_CRED_ATTR_CERT 4
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Identifies credential query types.
|
||||
/// </summary>
|
||||
public enum CredentialQueryAttrib : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// Queries the credential's principle name.
|
||||
/// </summary>
|
||||
Names = 1,
|
||||
SsiProvider = 2,
|
||||
KdcProxySettings = 3,
|
||||
Cert = 4
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,27 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
/// <summary>
|
||||
/// Indicates the manner in which a credential will be used for SSPI authentication.
|
||||
/// </summary>
|
||||
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,
|
||||
|
||||
/// <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,
|
||||
|
||||
/// <summary>
|
||||
/// The credentials may be used to to either build a client's security context or a server's
|
||||
/// security context.
|
||||
/// </summary>
|
||||
Both = 3,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
/// <summary>
|
||||
/// Acquires a handle to the credentials of the user associated with the current process.
|
||||
/// </summary>
|
||||
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 ) :
|
||||
base( securityPackage )
|
||||
{
|
||||
|
||||
@@ -7,9 +7,16 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials.Credentials
|
||||
{
|
||||
/// <summary>
|
||||
/// Stores the result from a query of a credential's principle name.
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace NSspi.Credentials
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Provides a managed handle to an SSPI credential.
|
||||
/// </summary>
|
||||
public class SafeCredentialHandle : SafeSspiHandle
|
||||
{
|
||||
public SafeCredentialHandle()
|
||||
|
||||
@@ -7,6 +7,9 @@ using System.Threading.Tasks;
|
||||
|
||||
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 ServerCredential( string package )
|
||||
|
||||
Reference in New Issue
Block a user