summaryrefslogtreecommitdiffstats
path: root/net/http/http_auth.h
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-27 03:19:42 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-27 03:19:42 +0000
commitc3b35c2100dba30c517116bc9a5a4e4149c3a8e5 (patch)
treeff42c902c4ee9afd7864a2bda8e5e815a876bc76 /net/http/http_auth.h
parente5be6612288df667ca6ae4a86060bc883a498eea (diff)
downloadchromium_src-c3b35c2100dba30c517116bc9a5a4e4149c3a8e5.zip
chromium_src-c3b35c2100dba30c517116bc9a5a4e4149c3a8e5.tar.gz
chromium_src-c3b35c2100dba30c517116bc9a5a4e4149c3a8e5.tar.bz2
Initial stab at http authentication (basic + digest) in new http stack.
General design: - class HttpAuth -- utility class for http-auth logic. - class HttpAuth::ChallengeTokenizer -- parsing of www-Authenticate headers. - class HttpAuthHandler -- base class for authentication schemes (inspired by nsIHttpAuthenticator) - class HttpAuthHandlerBasic : HttpAuthHandler -- logic for basic auth. - class HttpAuthHandlerDigest : HttpAuthHandler -- logic for digest auth. - The auth integration in HttpNetworkTransaction mimics that of HttpTransactionWinHttp: + HttpNetworkTransaction::ApplyAuth() -- set the authorization headers. + HttpNetworkTransaction::PopulateAuthChallenge() -- process the challenges. BUG=2346 Review URL: http://codereview.chromium.org/4063 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2658 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_auth.h')
-rw-r--r--net/http/http_auth.h120
1 files changed, 120 insertions, 0 deletions
diff --git a/net/http/http_auth.h b/net/http/http_auth.h
new file mode 100644
index 0000000..34d10f0
--- /dev/null
+++ b/net/http/http_auth.h
@@ -0,0 +1,120 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_HTTP_HTTP_AUTH_H_
+#define NET_HTTP_HTTP_AUTH_H_
+
+#include "net/http/http_util.h"
+
+namespace net {
+
+class HttpAuthHandler;
+class HttpResponseHeaders;
+
+// Utility class for http authentication.
+class HttpAuth {
+ public:
+
+ // Http authentication can be done the the proxy server, origin server,
+ // or both. This enum tracks who the target is.
+ enum Target {
+ AUTH_PROXY = 0,
+ AUTH_SERVER = 1,
+ };
+
+ // Get the name of the header containing the auth challenge
+ // (either WWW-Authenticate or Proxy-Authenticate).
+ static std::string GetChallengeHeaderName(Target target);
+
+ // Get the name of the header where the credentials go
+ // (either Authorization or Proxy-Authorization).
+ static std::string GetAuthorizationHeaderName(Target target);
+
+ // Create a handler to generate credentials for the challenge. If the
+ // challenge is unsupported or invalid, returns NULL.
+ // The caller owns the returned pointer.
+ static HttpAuthHandler* CreateAuthHandler(const std::string& challenge,
+ Target target);
+
+ // Iterate through the challenge headers, and pick the best one that
+ // we support. Returns the implementation class for handling the challenge.
+ // If no supported challenge was found, returns NULL.
+ // The caller owns the returned pointer.
+ static HttpAuthHandler* ChooseBestChallenge(
+ const HttpResponseHeaders* headers, Target target);
+
+ // ChallengeTokenizer breaks up a challenge string into the the auth scheme
+ // and parameter list, according to RFC 2617 Sec 1.2:
+ // challenge = auth-scheme 1*SP 1#auth-param
+ //
+ // Check valid() after each iteration step in case it was malformed.
+ // Also note that value() will give whatever is to the right of the equals
+ // sign, quotemarks and all. Use unquoted_value() to get the logical value.
+ class ChallengeTokenizer {
+ public:
+ ChallengeTokenizer(std::string::const_iterator begin,
+ std::string::const_iterator end)
+ : props_(begin, end, ','), valid_(true) {
+ Init(begin, end);
+ }
+
+ // Get the auth scheme of the challenge.
+ std::string::const_iterator scheme_begin() const { return scheme_begin_; }
+ std::string::const_iterator scheme_end() const { return scheme_end_; }
+ std::string scheme() const {
+ return std::string(scheme_begin_, scheme_end_);
+ }
+
+ // Returns false if there was a parse error.
+ bool valid() const {
+ return valid_;
+ }
+
+ // Advances the iterator to the next name-value pair, if any.
+ // Returns true if there is none to consume.
+ bool GetNext();
+
+ // The name of the current name-value pair.
+ std::string::const_iterator name_begin() const { return name_begin_; }
+ std::string::const_iterator name_end() const { return name_end_; }
+ std::string name() const {
+ return std::string(name_begin_, name_end_);
+ }
+
+ // The value of the current name-value pair.
+ std::string::const_iterator value_begin() const { return value_begin_; }
+ std::string::const_iterator value_end() const { return value_end_; }
+ std::string value() const {
+ return std::string(value_begin_, value_end_);
+ }
+
+ // If value() has quotemarks, unquote it.
+ std::string unquoted_value() const;
+
+ // True if the name-value pair's value has quote marks.
+ bool value_is_quoted() const { return value_is_quoted_; }
+
+ private:
+ void Init(std::string::const_iterator begin,
+ std::string::const_iterator end);
+
+ HttpUtil::ValuesIterator props_;
+ bool valid_;
+
+ std::string::const_iterator scheme_begin_;
+ std::string::const_iterator scheme_end_;
+
+ std::string::const_iterator name_begin_;
+ std::string::const_iterator name_end_;
+
+ std::string::const_iterator value_begin_;
+ std::string::const_iterator value_end_;
+
+ bool value_is_quoted_;
+ };
+};
+
+} // namespace net
+
+#endif // NET_HTTP_HTTP_AUTH_H_