Example #1
0
        /// <summary>
        /// Determines whether a named Diffie-Hellman session type and association type can be used together.
        /// </summary>
        /// <param name="protocol">The protocol carrying the names of the session and association types.</param>
        /// <param name="associationType">The value of the openid.assoc_type parameter.</param>
        /// <param name="sessionType">The value of the openid.session_type parameter.</param>
        /// <returns>
        ///     <c>true</c> if the named association and session types are compatible; otherwise, <c>false</c>.
        /// </returns>
        internal static bool IsDHSessionCompatible(Protocol protocol, string associationType, string sessionType)
        {
            ErrorUtilities.VerifyArgumentNotNull(protocol, "protocol");
            ErrorUtilities.VerifyNonZeroLength(associationType, "associationType");
            ErrorUtilities.VerifyArgumentNotNull(sessionType, "sessionType");

            // All association types can work when no DH session is used at all.
            if (string.Equals(sessionType, protocol.Args.SessionType.NoEncryption, StringComparison.Ordinal))
            {
                return(true);
            }

            // When there _is_ a DH session, it must match in hash length with the association type.
            int associationSecretLengthInBytes = GetSecretLength(protocol, associationType);
            int sessionHashLengthInBytes       = DiffieHellmanUtilities.Lookup(protocol, sessionType).HashSize / 8;

            return(associationSecretLengthInBytes == sessionHashLengthInBytes);
        }
Example #2
0
        /// <summary>
        /// Determines whether a named Diffie-Hellman session type and association type can be used together.
        /// </summary>
        /// <param name="protocol">The protocol carrying the names of the session and association types.</param>
        /// <param name="associationType">The value of the openid.assoc_type parameter.</param>
        /// <param name="sessionType">The value of the openid.session_type parameter.</param>
        /// <returns>
        ///     <c>true</c> if the named association and session types are compatible; otherwise, <c>false</c>.
        /// </returns>
        internal static bool IsDHSessionCompatible(Protocol protocol, string associationType, string sessionType)
        {
            Contract.Requires <ArgumentNullException>(protocol != null);
            Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(associationType));
            Contract.Requires <ArgumentNullException>(sessionType != null);

            // All association types can work when no DH session is used at all.
            if (string.Equals(sessionType, protocol.Args.SessionType.NoEncryption, StringComparison.Ordinal))
            {
                return(true);
            }

            // When there _is_ a DH session, it must match in hash length with the association type.
            int associationSecretLengthInBytes = GetSecretLength(protocol, associationType);
            int sessionHashLengthInBytes       = DiffieHellmanUtilities.Lookup(protocol, sessionType).HashSize / 8;

            return(associationSecretLengthInBytes == sessionHashLengthInBytes);
        }
        /// <summary>
        /// Determines whether a named Diffie-Hellman session type and association type can be used together.
        /// </summary>
        /// <param name="protocol">The protocol carrying the names of the session and association types.</param>
        /// <param name="associationType">The value of the openid.assoc_type parameter.</param>
        /// <param name="sessionType">The value of the openid.session_type parameter.</param>
        /// <returns>
        ///     <c>true</c> if the named association and session types are compatible; otherwise, <c>false</c>.
        /// </returns>
        internal static bool IsDHSessionCompatible(Protocol protocol, string associationType, string sessionType)
        {
            Requires.NotNull(protocol, "protocol");
            Requires.NotNullOrEmpty(associationType, "associationType");
            Requires.NotNull(sessionType, "sessionType");

            // All association types can work when no DH session is used at all.
            if (string.Equals(sessionType, protocol.Args.SessionType.NoEncryption, StringComparison.Ordinal))
            {
                return(true);
            }

            if (OpenIdUtilities.IsDiffieHellmanPresent)
            {
                // When there _is_ a DH session, it must match in hash length with the association type.
                int associationSecretLengthInBytes = GetSecretLength(protocol, associationType);
                int sessionHashLengthInBytes       = DiffieHellmanUtilities.Lookup(protocol, sessionType).HashSize / 8;
                return(associationSecretLengthInBytes == sessionHashLengthInBytes);
            }
            else
            {
                return(false);
            }
        }