Function: url-digest-auth-build-response

url-digest-auth-build-response is a byte-compiled function defined in url-auth.el.gz.

Signature

(url-digest-auth-build-response KEY URL REALM ATTRS)

Documentation

Compute authorization string for the given challenge using KEY.

The string looks like "Digest username="John", realm="The Realm", ..."

Part of the challenge is already solved in a pre-computed KEY which is list of a realm (or a directory), user name, and hash tokens HA1 and HA2.

Some fields are filled as is from the given URL, REALM, and using the contents of alist ATTRS.

ATTRS is expected to contain at least the server's "nonce" value. It also might contain the optional "opaque" value. Newer implementations conforming to RFC 2617 should also contain qop (Quality Of Protection) and related attributes.

Restrictions on Quality of Protection scheme: The qop value
"auth-int" or algorithm any other than "MD5" are not
implemented.

Source Code

;; Defined in /usr/src/emacs/lisp/url/url-auth.el.gz
(defun url-digest-auth-build-response (key url realm attrs)
  "Compute authorization string for the given challenge using KEY.

The string looks like \"Digest username=\"John\", realm=\"The
Realm\", ...\"

Part of the challenge is already solved in a pre-computed KEY
which is list of a realm (or a directory), user name, and hash
tokens HA1 and HA2.

Some fields are filled as is from the given URL, REALM, and
using the contents of alist ATTRS.

ATTRS is expected to contain at least the server's \"nonce\"
value.  It also might contain the optional \"opaque\" value.
Newer implementations conforming to RFC 2617 should also contain
qop (Quality Of Protection) and related attributes.

Restrictions on Quality of Protection scheme: The qop value
\"auth-int\" or algorithm any other than \"MD5\" are not
implemented."

  (when key
    (let ((user (nth 1 key))
          (ha1 (nth 2 key))
          (ha2 (nth 3 key))
          (digest-uri (url-filename url))
          (qop (cdr-safe (assoc "qop" attrs)))
          (nonce (cdr-safe (assoc "nonce" attrs)))
          (opaque (cdr-safe (assoc "opaque" attrs))))

      (concat
       "Digest "
       (url-digest-auth-name-value-string
        (append (list (cons 'username user)
                      (cons 'realm realm)
                      (cons 'nonce nonce)
                      (cons 'uri digest-uri))

                (cond
                 ((null qop)
                  (list (cons 'response (url-digest-auth-make-request-digest
                                         ha1 ha2 nonce))))
                 ((string= qop "auth")
                  (let ((nc (url-digest-auth-nonce-count nonce))
                        (cnonce (url-digest-auth-make-cnonce)))
                    (list (cons 'qop qop)
                          (cons 'nc nc)
                          (cons 'cnonce cnonce)
                          (cons 'response
                                (url-digest-auth-make-request-digest-qop
                                 qop ha1 ha2 nonce nc cnonce)))))
                 (t (message "Quality of protection \"%s\" is not implemented." qop)
                    nil))


                (if opaque (list (cons 'opaque opaque)))))))))