C# Class modauthtkt.AuthenticationTicket

This class is a .NET implementation of mod_auth_tkt http://www.openfusion.com.au/labs/mod_auth_tkt/ This is part of the mod_auth_tkt algorithm implementation
Exibir arquivo Open project: AppliedIS/csharp_auth_tkt

Public Methods

Method Description
Create ( AuthenticationTicketData ticketData, string secret, bool encode = false ) : string

Creates a Base64-encoded ticket based on the provided data.

The ticket is created using the mod_auth_tkt algorithm.

Create ( string userId, string userData, string tokens, System.DateTime timeStamp, string secret, bool encode = false, string ipAddress = AuthenticationTicketData.DefaultIPAddress, string version = AuthenticationTicketData.DefaultVersion ) : string

Creates a Base64-encoded ticket based on the provided data.

The ticket is created using the mod_auth_tkt algorithm.

ExtractData ( string ticket, string secret = null, bool encoded = false, string ipAddress = AuthenticationTicketData.DefaultIPAddress ) : AuthenticationTicketData

Extracts the data from a provided ticket.

Validate ( string ticket, string secret, bool encoded = false, string ipAddress = AuthenticationTicketData.DefaultIPAddress, string version = AuthenticationTicketData.DefaultVersion ) : bool

Validates a ticket based on the provided data.

Private Methods

Method Description
CreateDigest ( AuthenticationTicketData ticketData, string secret ) : string

Creates the digest portion of the ticket from the provided data.

The algorithm for the digest is as follows: digest = MD5(digest0 + key) where Version 1.3: digest0 = MD5(iptstamp + key + user_id + user_data) Version 2.0: digest0 = MD5(iptstamp + key + user_id + '\0' + token_list + '\0' + user_data)

CreateIPTimeStamp ( uint ipAddress, uint timestamp ) : string

Creates the IP Address / Timestamp byte array used in the digest.

IPTStamp is a 8 bytes long byte array, bytes 0-3 are filled with client's IP address as a binary number in network byte order, bytes 4-7 are filled with timestamp as a binary number in network byte order.

Decode ( string data, string secret, uint timestamp, int offset ) : string

Decodes a data string.

Encode ( string data, string secret, uint timestamp, int offset ) : string

Encodes a data string.

GetDecodeIndex ( int a, int b, int c ) : int

Gets the index in the decoded character string by solving for x in the equation: (x + a) % b = c where x is between 0 and b

Parse ( string ticket ) : AuthenticationTicketData

Parses the decoded ticket.

The expected format of the ticket is: digest (32 chars) + hex timestamp (8 chars) + user ID + '!' + user data OR digest (32 chars) + hex timestamp (8 chars) + user ID + '!' + tokens + '!' user data

Method Details

Create() public static method

Creates a Base64-encoded ticket based on the provided data.
The ticket is created using the mod_auth_tkt algorithm.
public static Create ( AuthenticationTicketData ticketData, string secret, bool encode = false ) : string
ticketData AuthenticationTicketData Data used to create the ticket.
secret string Secret key used to create the ticket.
encode bool True if the user id, user data, and tokens are to be encoded; false otherwise
return string

Create() public static method

Creates a Base64-encoded ticket based on the provided data.
The ticket is created using the mod_auth_tkt algorithm.
public static Create ( string userId, string userData, string tokens, System.DateTime timeStamp, string secret, bool encode = false, string ipAddress = AuthenticationTicketData.DefaultIPAddress, string version = AuthenticationTicketData.DefaultVersion ) : string
userId string User ID
userData string User Data
tokens string Comma-delimited string of data
timeStamp System.DateTime Time Stamp
secret string Secret key used to create the ticket
encode bool True if the user id, user data, and tokens are to be encoded; false otherwise
ipAddress string IP Address
version string Version of the mod_auth_tkt algorithm used to create the ticket
return string

ExtractData() public static method

Extracts the data from a provided ticket.
public static ExtractData ( string ticket, string secret = null, bool encoded = false, string ipAddress = AuthenticationTicketData.DefaultIPAddress ) : AuthenticationTicketData
ticket string Base64-encoded ticket to parse for data
secret string Secret key used to create the ticket
encoded bool True if the user id, user data, and tokens are encoded; false otherwise
ipAddress string IP Address used to create the ticket
return AuthenticationTicketData

Validate() public static method

Validates a ticket based on the provided data.
public static Validate ( string ticket, string secret, bool encoded = false, string ipAddress = AuthenticationTicketData.DefaultIPAddress, string version = AuthenticationTicketData.DefaultVersion ) : bool
ticket string Base64-encoded ticket to be validated
secret string Secret key used to create the ticket
encoded bool True if the user id, user data, and tokens are encoded; false otherwise
ipAddress string IP Address used to create the ticket
version string Version of the mod_auth_tkt algorithm used to validate the ticket
return bool