Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Inflate the token
        /// </summary>
        /// <param name="source">Stream to inflate the token from</param>
        /// <returns>TRUE if inflation is complete</returns>
        public override bool Inflate(Stream source)
        {
            // Reset inflation size
            InflationSize = 0;

            // We skip option identifier because it was read by construction factory
            // Read the length of the data for the option
            uint optionDataLength = TDSUtilities.ReadUInt(source);

            // Update inflation offset
            InflationSize += sizeof(uint);

            // Read one byte for the flags
            byte temp = (byte)source.ReadByte();

            // Update inflation offset
            InflationSize += sizeof(byte);

            // Get the bit and set as a fedauth echo bit
            Echo = (TdsPreLoginFedAuthRequiredOption)(temp & 0x01);

            // Get the remaining 7 bits and set as a library.
            Library = (TDSFedAuthLibraryType)(temp >> 1);

            // When using the ADAL library, a FedAuthToken is never included, nor is its length included
            if (Library != TDSFedAuthLibraryType.ADAL)
            {
                // Length of the FedAuthToken
                uint fedauthTokenLen = TDSUtilities.ReadUInt(source);

                // Update inflation offset
                InflationSize += sizeof(uint);

                // Check if the fedauth token is in the login7
                if (fedauthTokenLen > 0)
                {
                    // Allocate a container
                    Token = new byte[fedauthTokenLen];

                    // Read the Fedauth token.
                    source.Read(Token, 0, (int)fedauthTokenLen);

                    // Update inflation offset
                    InflationSize += fedauthTokenLen;
                }
            }
            else
            {
                // Instead the workflow is included
                Workflow = (TDSFedAuthADALWorkflow)source.ReadByte();
            }

            switch (Library)
            {
            case TDSFedAuthLibraryType.IDCRL:
                IsRequestingAuthenticationInfo = false;
                return(ReadIDCRLLogin(source, optionDataLength));

            case TDSFedAuthLibraryType.SECURITY_TOKEN:
                IsRequestingAuthenticationInfo = false;
                return(ReadSecurityTokenLogin(source, optionDataLength));

            case TDSFedAuthLibraryType.ADAL:
                IsRequestingAuthenticationInfo = true;
                return(true);

            default:
                return(false);
            }
        }
        /// <summary>
        /// Inflate the token
        /// </summary>
        /// <param name="source">Stream to inflate the token from</param>
        /// <returns>TRUE if inflation is complete</returns>
        public override bool Inflate(Stream source)
        {
            // Reset inflation size
            InflationSize = 0;

            // We skip option identifier because it was read by construction factory
            // Read the length of the data for the option
            uint optionDataLength = TDSUtilities.ReadUInt(source);

            // Update inflation offset
            InflationSize += sizeof(uint);

            // Read one byte for the flags
            byte temp = (byte)source.ReadByte();

            // Update inflation offset
            InflationSize += sizeof(byte);

            // Get the bit and set as a fedauth echo bit
            Echo = (TdsPreLoginFedAuthRequiredOption)(temp & 0x01);

            // Get the remaining 7 bits and set as a library.
            Library = (TDSFedAuthLibraryType)(temp >> 1);

            // When using the ADAL library, a FedAuthToken is never included, nor is its length included
            if (Library != TDSFedAuthLibraryType.ADAL)
            {
                // Length of the FedAuthToken
                uint fedauthTokenLen = TDSUtilities.ReadUInt(source);

                // Update inflation offset
                InflationSize += sizeof(uint);

                // Check if the fedauth token is in the login7
                if (fedauthTokenLen > 0)
                {
                    // Allocate a container
                    Token = new byte[fedauthTokenLen];

                    // Read the Fedauth token.
                    source.Read(Token, 0, (int)fedauthTokenLen);

                    // Update inflation offset
                    InflationSize += fedauthTokenLen;
                }
            }
            else
            {
                // Instead the workflow is included
                Workflow = (TDSFedAuthADALWorkflow)source.ReadByte();
            }

            switch (Library)
            {
                case TDSFedAuthLibraryType.IDCRL:
                    IsRequestingAuthenticationInfo = false;
                    return ReadIDCRLLogin(source, optionDataLength);

                case TDSFedAuthLibraryType.SECURITY_TOKEN:
                    IsRequestingAuthenticationInfo = false;
                    return ReadSecurityTokenLogin(source, optionDataLength);

                case TDSFedAuthLibraryType.ADAL:
                    IsRequestingAuthenticationInfo = true;
                    return true;

                default:
                    return false;
            }
        }
        /// <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);
            }
        }