/// <summary>
        /// Initialization Constructor.
        /// </summary>
        public TDSLogin7FedAuthOptionToken(TdsPreLoginFedAuthRequiredOption echo,
                                           TDSFedAuthLibraryType libraryType,
                                           byte[] token,
                                           byte[] nonce,
                                           byte[] channelBindingToken,
                                           bool fIncludeSignature,
                                           bool fRequestingFurtherInfo,
                                           TDSFedAuthMSALWorkflow workflow = TDSFedAuthMSALWorkflow.USERNAME_PASSWORD)
            : this()
        {
            Echo                           = echo;
            Library                        = libraryType;
            Token                          = token;
            Nonce                          = nonce;
            ChannelBingingToken            = channelBindingToken;
            IsRequestingAuthenticationInfo = fRequestingFurtherInfo;
            Workflow                       = workflow;

            if (libraryType != TDSFedAuthLibraryType.SECURITY_TOKEN && fIncludeSignature)
            {
                Signature = new byte[s_signatureDataLength];
                Signature = _GenerateRandomBytes(32);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Inflate the token
        /// NOTE: This operation is not continuable and assumes that the entire token is available in the stream
        /// </summary>
        /// <param name="source">Stream to inflate the token from</param>
        /// <returns>TRUE if inflation is complete</returns>
        public override bool Inflate(Stream source)
        {
            // Prepare a list of options
            IList <TDSPreLoginTokenOption> options = new List <TDSPreLoginTokenOption>();

            // Inflate all options until terminator is detected
            do
            {
                // Create a new option
                options.Add(new TDSPreLoginTokenOption());

                // Inflate it
                if (!options[options.Count - 1].Inflate(source))
                {
                    return(false);
                }
            }while (options[options.Count - 1].Type != TDSPreLoginTokenOptionType.Terminator);

            // Order the options in ascending order by offset
            // For the most cases this should not change the order of the options in the stream, but just in case
            options = options.OrderBy(o => o.Position).ToList();

            // Calculate current inflation offset
            ushort inflationOffset = (ushort)options.Sum(o => o.TokenLength);

            // Iterate through each option and inflate it
            foreach (TDSPreLoginTokenOption option in options)
            {
                // Ensure that current offset points to the option
                while (inflationOffset < option.Position)
                {
                    // Read the stream
                    source.ReadByte();

                    // Advance position
                    inflationOffset++;
                }

                // Check the type of the pre-login packet option type
                switch (option.Type)
                {
                case TDSPreLoginTokenOptionType.Version:
                {
                    // Check if version fits
                    if (option.Length >= 6)
                    {
                        // Read the data of the specified length at the specified position
                        Version = new Version(
                            source.ReadByte() & 0xff,                      // Major
                            source.ReadByte(),                             // Minor
                            (source.ReadByte() << 8) + source.ReadByte()); // Build (swap bytes)

                        // Read sub-build
                        SubBuild = TDSUtilities.ReadUShort(source);

                        // Update the offset
                        inflationOffset += 6;
                    }

                    break;
                }

                case TDSPreLoginTokenOptionType.Encryption:
                {
                    // Check is option fits
                    if (option.Length >= 1)
                    {
                        // Read encryption
                        Encryption = (TDSPreLoginTokenEncryptionType)source.ReadByte();

                        // Update the offset
                        inflationOffset += 1;
                    }

                    break;
                }

                case TDSPreLoginTokenOptionType.Instance:
                {
                    // Currently does nothing.
                    break;
                }

                case TDSPreLoginTokenOptionType.ThreadID:
                {
                    // Check if thread ID fits
                    if (option.Length >= 4)
                    {
                        // Read the data of the specified length at the specified position (big-endian)
                        ThreadID = TDSUtilities.ReadUInt(source);

                        // Update the offset
                        inflationOffset += 4;
                    }

                    break;
                }

                case TDSPreLoginTokenOptionType.Mars:
                {
                    // Check is option fits
                    if (option.Length >= 1)
                    {
                        // Read byte
                        IsMARS = (source.ReadByte() == 0x01);

                        // Update the offset
                        inflationOffset += 1;
                    }

                    break;
                }

                case TDSPreLoginTokenOptionType.TraceID:
                {
                    if (option.Length >= 36)
                    {
                        // Allocate memory
                        ClientTraceID = new byte[16];

                        // Read connection Trace ID
                        source.Read(ClientTraceID, 0, 16);

                        // Allocate memory
                        ActivityID = new byte[20];

                        // Read Activity ID.
                        source.Read(ActivityID, 0, 20);

                        // Update the offset
                        inflationOffset += 36;
                    }
                    break;
                }

                case TDSPreLoginTokenOptionType.FederatedAuthenticationRequired:
                {
                    if (option.Length >= 1)
                    {
                        // Read authentication type.
                        FedAuthRequired = (TdsPreLoginFedAuthRequiredOption)source.ReadByte();

                        // Update the offset
                        inflationOffset += 1;
                    }
                    break;
                }

                case TDSPreLoginTokenOptionType.NonceOption:
                {
                    if (option.Length >= 32)
                    {
                        //Allocate memory
                        Nonce = new byte[32];

                        // Read Nonce.
                        source.Read(Nonce, 0, 32);

                        // Update the offset
                        inflationOffset += 32;
                    }
                    break;
                }
                }
            }

            return(true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initialization constructor
 /// </summary>
 public TDSPreLoginToken(Version version, TDSPreLoginTokenEncryptionType encryption, bool isMARS, uint threadID, TdsPreLoginFedAuthRequiredOption fedAuthRequired) :
     this(version, encryption, isMARS, threadID)
 {
     FedAuthRequired = fedAuthRequired;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Inflate the token
        /// NOTE: This operation is not continuable and assumes that the entire token is available in the stream
        /// </summary>
        /// <param name="source">Stream to inflate the token from</param>
        /// <returns>TRUE if inflation is complete</returns>
        public override bool Inflate(Stream source)
        {
            // Prepare a list of options
            IList<TDSPreLoginTokenOption> options = new List<TDSPreLoginTokenOption>();

            // Inflate all options until terminator is detected
            do
            {
                // Create a new option
                options.Add(new TDSPreLoginTokenOption());

                // Inflate it
                if (!options[options.Count - 1].Inflate(source))
                {
                    return false;
                }
            }
            while (options[options.Count - 1].Type != TDSPreLoginTokenOptionType.Terminator);

            // Order the options in ascending order by offset
            // For the most cases this should not change the order of the options in the stream, but just in case
            options = options.OrderBy(o => o.Position).ToList();

            // Calculate current inflation offset 
            ushort inflationOffset = (ushort)options.Sum(o => o.TokenLength);

            // Iterate through each option and inflate it
            foreach (TDSPreLoginTokenOption option in options)
            {
                // Ensure that current offset points to the option
                while (inflationOffset < option.Position)
                {
                    // Read the stream
                    source.ReadByte();

                    // Advance position
                    inflationOffset++;
                }

                // Check the type of the pre-login packet option type
                switch (option.Type)
                {
                    case TDSPreLoginTokenOptionType.Version:
                        {
                            // Check if version fits
                            if (option.Length >= 6)
                            {
                                // Read the data of the specified length at the specified position
                                Version = new Version(
                                    source.ReadByte() & 0xff, // Major
                                    source.ReadByte(), // Minor
                                    (source.ReadByte() << 8) + source.ReadByte());  // Build (swap bytes)

                                // Read sub-build
                                SubBuild = TDSUtilities.ReadUShort(source);

                                // Update the offset
                                inflationOffset += 6;
                            }

                            break;
                        }
                    case TDSPreLoginTokenOptionType.Encryption:
                        {
                            // Check is option fits
                            if (option.Length >= 1)
                            {
                                // Read encryption
                                Encryption = (TDSPreLoginTokenEncryptionType)source.ReadByte();

                                // Update the offset
                                inflationOffset += 1;
                            }

                            break;
                        }
                    case TDSPreLoginTokenOptionType.Instance:
                        {
                            // Currently does nothing.
                            break;
                        }
                    case TDSPreLoginTokenOptionType.ThreadID:
                        {
                            // Check if thread ID fits
                            if (option.Length >= 4)
                            {
                                // Read the data of the specified length at the specified position (big-endian)
                                ThreadID = TDSUtilities.ReadUInt(source);

                                // Update the offset
                                inflationOffset += 4;
                            }

                            break;
                        }
                    case TDSPreLoginTokenOptionType.Mars:
                        {
                            // Check is option fits
                            if (option.Length >= 1)
                            {
                                // Read byte
                                IsMARS = (source.ReadByte() == 0x01);

                                // Update the offset
                                inflationOffset += 1;
                            }

                            break;
                        }
                    case TDSPreLoginTokenOptionType.TraceID:
                        {
                            if (option.Length >= 36)
                            {
                                // Allocate memory
                                ClientTraceID = new byte[16];

                                // Read connection Trace ID
                                source.Read(ClientTraceID, 0, 16);

                                // Allocate memory
                                ActivityID = new byte[20];

                                // Read Activity ID.
                                source.Read(ActivityID, 0, 20);

                                // Update the offset
                                inflationOffset += 36;
                            }
                            break;
                        }
                    case TDSPreLoginTokenOptionType.FederatedAuthenticationRequired:
                        {
                            if (option.Length >= 1)
                            {
                                // Read authentication type.
                                FedAuthRequired = (TdsPreLoginFedAuthRequiredOption)source.ReadByte();

                                // Update the offset
                                inflationOffset += 1;
                            }
                            break;
                        }
                    case TDSPreLoginTokenOptionType.NonceOption:
                        {
                            if (option.Length >= 32)
                            {
                                //Allocate memory
                                Nonce = new byte[32];

                                // Read Nonce.
                                source.Read(Nonce, 0, 32);

                                // Update the offset
                                inflationOffset += 32;
                            }
                            break;
                        }
                }
            }

            return true;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initialization constructor
 /// </summary>		
 public TDSPreLoginToken(Version version, TDSPreLoginTokenEncryptionType encryption, bool isMARS, uint threadID, TdsPreLoginFedAuthRequiredOption fedAuthRequired) :
     this(version, encryption, isMARS, threadID)
 {
     FedAuthRequired = fedAuthRequired;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Initialization Constructor.
        /// </summary>
        public TDSLogin7FedAuthOptionToken(TdsPreLoginFedAuthRequiredOption echo,
                                            TDSFedAuthLibraryType libraryType,
                                            byte[] token,
                                            byte[] nonce,
                                            byte[] channelBindingToken,
                                            bool fIncludeSignature,
                                            bool fRequestingFurtherInfo,
                                            TDSFedAuthADALWorkflow workflow = TDSFedAuthADALWorkflow.USERNAME_PASSWORD)
            : this()
        {
            Echo = echo;
            Library = libraryType;
            Token = token;
            Nonce = nonce;
            ChannelBingingToken = channelBindingToken;
            IsRequestingAuthenticationInfo = fRequestingFurtherInfo;
            Workflow = workflow;

            if (libraryType != TDSFedAuthLibraryType.SECURITY_TOKEN && fIncludeSignature)
            {
                Signature = new byte[s_signatureDataLength];
                Signature = _GenerateRandomBytes(32);
            }
        }