Digest Authentication

  1. Client對Resource發存取請求。
  2. Server回應Header WWW-Authenticate: Digest realm、qop、nonce與Opaque。
  3. Client以realm、nonce與Opaque做驗證。
  4. Server回應驗證結果。
  • realm: 提示user此resource該輸入的account與password。
  • qop: quality of protection,決定驗證字串的表達方式。步驟二中,server應提供所支援的方式,包含auth與auth-int。
  • nonce: 用於某次請求的字串。可能是個timestamp。
  • opaque: 詳細用途不曉得。根據rfc2617中表達內容,像是一種server的metadata。

步驟三中,在給server request header中的response ,會根據qop而有所不同。可參考link中的Overview。另外附加的nonceCount與clientNonce,是由client所控制決定,用來避免Chosen Plaintext attacks。Server可根據內容決定驗證結果。

在spring-securiry-web 3.2.5版本中,僅支援qop=auth,其中nonceCount與clientNonce只要與response對得起來,並不會另外做特別驗證。

cURL

curl --digest -u "user:passwd" http://request_url

Postman

與cURL最大差別在於要發兩次request,一次是為了拿nonce,一次是驗證並拿回結果。

  1. 針對resource的URL發一次request。
  2. 從header內容中拿取realm與nonce。如果有opaque也要拿出來用。
  3. 填至Digest Auth表單中,並點擊Refresh headers。Postman會自動幫你算出response內容。
  4. 發出請求。