Ejemplo n.º 1
0
        /// <summary>
        /// Generates digest HA2 value as per RFC 2617 subclause 3.2.2.3.
        /// </summary>
        /// <param name="method"></param>
        /// <param name="url"></param>
        /// <param name="entity_body"></param>
        /// <returns></returns>
        public static String GetDigestHA2(String method, String url, byte[] entity_body, String qop)
        {
            /* RFC 2617 - 3.2.2.3 A2
             *
             *  If the "qop" directive's value is "auth" or is unspecified, then A2
             *  is:
             *  A2       = Method ":" digest-url-value
             *
             *  If the "qop" value is "auth-int", then A2 is:
             *  A2       = Method ":" digest-url-value ":" H(entity-body)
             */
            String A2 = String.Empty;

            if (String.IsNullOrEmpty(qop) || String.Equals(qop, "auth", StringComparison.InvariantCultureIgnoreCase))
            {
                A2 = String.Format("{0}:{1}", method, url);
            }
            else if (String.Equals(qop, "auth-int", StringComparison.InvariantCultureIgnoreCase))
            {
                if (entity_body != null && entity_body.Length > 0)
                {
                    String hEntity = TSK_MD5.Compute(entity_body);
                    A2 = String.Format("{0}:{1}:{2}", method, url, hEntity);
                }
                else
                {
                    A2 = String.Format("{0}:{1}:{2}", method, url, TSK_MD5.EMPTY);
                }
            }

            return(TSK_MD5.Compute(A2));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates HTTP digest response as per RFC 2617 subclause 3.2.2.1.
        /// </summary>
        /// <param name="ha1">HA1 string generated using  @ref thttp_auth_digest_HA1 or @ref thttp_auth_digest_HA1sess.</param>
        /// <param name="nonce">The nonce value</param>
        /// <param name="noncecount">The nonce count</param>
        /// <param name="cnonce">The client nounce (unquoted)</param>
        /// <param name="qop">The Quality Of Protection (unquoted)</param>
        /// <param name="ha2">HA2 string generated using @ref thttp_auth_digest_HA2</param>
        /// <returns></returns>
        public static String GetDigestResponse(String ha1, String nonce, UInt32 noncecount, String cnonce, String qop, String ha2)
        {
            /* RFC 2617 3.2.2.1 Request-Digest
             *
             *      ============ CASE 1 ============
             *      If the "qop" value is "auth" or "auth-int":
             *      request-digest  = <"> < KD ( H(A1),     unq(nonce-value)
             *      ":" nc-value
             *      ":" unq(cnonce-value)
             *      ":" unq(qop-value)
             *      ":" H(A2)
             *      ) <">
             *      ============ CASE 2 ============
             *      If the "qop" directive is not present (this construction is for
             *      compatibility with RFC 2069):
             *      request-digest  =
             *      <"> < KD ( H(A1), unq(nonce-value) ":" H(A2) ) >
             *      <">
             */

            String res;

            if (String.Equals(qop, "auth", StringComparison.InvariantCultureIgnoreCase) || String.Equals(qop, "auth-int", StringComparison.InvariantCultureIgnoreCase))
            {
                /* CASE 1 */
                res = String.Format("{0}:{1}:{2}:{3}:{4}:{5}", ha1, nonce, noncecount, cnonce, qop, ha2);
            }
            else
            {
                /* CASE 2 */
                res = String.Format("{0}:{1}:{2}", ha1, nonce, ha2);
            }

            return(TSK_MD5.Compute(res));
        }
Ejemplo n.º 3
0
 private void ResetCNonce()
 {
     if (!String.IsNullOrEmpty(mQop))
     {
         mCnonce = TSK_MD5.Compute(TSK_String.Random());
         mNc     = 1;
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates digest HA1 value as per RFC 2617 subclause 3.2.2.2.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="realm"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static String GetDigestHA1(String username, String realm, String password)
        {
            /* RFC 2617 - 3.2.2.2 A1
             *          A1       = unq(username-value) ":" unq(realm-value) ":" passwd
             */
            String A1 = String.Format("{0}:{1}:{2}", username, realm, password);

            return(TSK_MD5.Compute(A1));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generates digest HA1 value for 'MD5-sess' algo as per RFC 2617 subclause 3.2.2.2.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="realm"></param>
        /// <param name="password"></param>
        /// <param name="nonce"></param>
        /// <param name="cnonce"></param>
        /// <returns></returns>
        public static String GetDigestHA1Sess(String username, String realm, String password, String nonce, String cnonce)
        {
            String A1Sess = String.Format("{0}:{1}:{2}:{3}:{4}", username, realm, password, nonce, cnonce);

            return(TSK_MD5.Compute(A1Sess));
        }