Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(291)

Side by Side Diff: net/http/http_auth_handler_digest.h

Issue 5034001: Remove static "set_fixed_cnonce" in favor of NonceGenerator objects.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/http/http_auth_handler_digest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ 5 #ifndef NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_
6 #define NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ 6 #define NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/gtest_prod_util.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/scoped_ptr.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "net/http/http_auth_handler.h" 14 #include "net/http/http_auth_handler.h"
14 #include "net/http/http_auth_handler_factory.h" 15 #include "net/http/http_auth_handler_factory.h"
15 16
16 namespace net { 17 namespace net {
17 18
18 // Code for handling http digest authentication. 19 // Code for handling http digest authentication.
19 class HttpAuthHandlerDigest : public HttpAuthHandler { 20 class HttpAuthHandlerDigest : public HttpAuthHandler {
20 public: 21 public:
22 class NonceGenerator {
23 public:
24 virtual ~NonceGenerator();
25 virtual std::string GenerateNonce() const = 0;
26 };
27
28 class DynamicNonceGenerator : public NonceGenerator {
29 public:
30 virtual std::string GenerateNonce() const;
31 };
32
33 // For unit tests
34 class FixedNonceGenerator : public NonceGenerator {
35 public:
36 explicit FixedNonceGenerator(const std::string& nonce);
37
38 virtual std::string GenerateNonce() const;
39
40 private:
41 std::string nonce_;
eroman 2010/11/16 00:02:35 nit: const
42 };
43
21 class Factory : public HttpAuthHandlerFactory { 44 class Factory : public HttpAuthHandlerFactory {
22 public: 45 public:
23 Factory(); 46 Factory();
24 virtual ~Factory(); 47 virtual ~Factory();
25 48
26 virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge, 49 virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge,
eroman 2010/11/16 00:02:35 Important: this creates a new dependency which I d
27 HttpAuth::Target target, 50 HttpAuth::Target target,
28 const GURL& origin, 51 const GURL& origin,
29 CreateReason reason, 52 CreateReason reason,
30 int digest_nonce_count, 53 int digest_nonce_count,
31 const BoundNetLog& net_log, 54 const BoundNetLog& net_log,
32 scoped_ptr<HttpAuthHandler>* handler); 55 scoped_ptr<HttpAuthHandler>* handler);
56
57 void set_nonce_generator(const NonceGenerator* nonce_generator);
eroman 2010/11/16 00:02:35 should mention ownership. (even though it is a co
58
59 private:
60 scoped_ptr<const NonceGenerator> nonce_generator_;
33 }; 61 };
34 62
35 HttpAuth::AuthorizationResult HandleAnotherChallenge( 63 HttpAuth::AuthorizationResult HandleAnotherChallenge(
36 HttpAuth::ChallengeTokenizer* challenge); 64 HttpAuth::ChallengeTokenizer* challenge);
37 65
38 protected: 66 protected:
39 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); 67 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge);
40 68
41 virtual int GenerateAuthTokenImpl(const string16* username, 69 virtual int GenerateAuthTokenImpl(const string16* username,
42 const string16* password, 70 const string16* password,
(...skipping 20 matching lines...) Expand all
63 ALGORITHM_MD5_SESS, 91 ALGORITHM_MD5_SESS,
64 }; 92 };
65 93
66 // Possible values for QualityOfProtection. 94 // Possible values for QualityOfProtection.
67 // auth-int is not supported, see http://crbug.com/62890 for justification. 95 // auth-int is not supported, see http://crbug.com/62890 for justification.
68 enum QualityOfProtection { 96 enum QualityOfProtection {
69 QOP_UNSPECIFIED, 97 QOP_UNSPECIFIED,
70 QOP_AUTH, 98 QOP_AUTH,
71 }; 99 };
72 100
73 explicit HttpAuthHandlerDigest(int nonce_count); 101 HttpAuthHandlerDigest(int nonce_count, const NonceGenerator* nonce_generator);
eroman 2010/11/16 00:02:35 Please mention ownerhsip model.
74 ~HttpAuthHandlerDigest(); 102 ~HttpAuthHandlerDigest();
75 103
76 // Parse the challenge, saving the results into this instance. 104 // Parse the challenge, saving the results into this instance.
77 // Returns true on success. 105 // Returns true on success.
78 bool ParseChallenge(HttpAuth::ChallengeTokenizer* challenge); 106 bool ParseChallenge(HttpAuth::ChallengeTokenizer* challenge);
79 107
80 // Parse an individual property. Returns true on success. 108 // Parse an individual property. Returns true on success.
81 bool ParseChallengeProperty(const std::string& name, 109 bool ParseChallengeProperty(const std::string& name,
82 const std::string& value); 110 const std::string& value);
83 111
(...skipping 19 matching lines...) Expand all
103 const std::string& nc) const; 131 const std::string& nc) const;
104 132
105 // Build up the value for (Authorization/Proxy-Authorization). 133 // Build up the value for (Authorization/Proxy-Authorization).
106 std::string AssembleCredentials(const std::string& method, 134 std::string AssembleCredentials(const std::string& method,
107 const std::string& path, 135 const std::string& path,
108 const string16& username, 136 const string16& username,
109 const string16& password, 137 const string16& password,
110 const std::string& cnonce, 138 const std::string& cnonce,
111 int nonce_count) const; 139 int nonce_count) const;
112 140
113 // Forces cnonce to be the same each time. This is used for unit tests.
114 static void SetFixedCnonce(bool fixed_cnonce) {
115 fixed_cnonce_ = fixed_cnonce;
116 }
117
118 // Information parsed from the challenge. 141 // Information parsed from the challenge.
119 std::string nonce_; 142 std::string nonce_;
120 std::string domain_; 143 std::string domain_;
121 std::string opaque_; 144 std::string opaque_;
122 bool stale_; 145 bool stale_;
123 DigestAlgorithm algorithm_; 146 DigestAlgorithm algorithm_;
124 QualityOfProtection qop_; 147 QualityOfProtection qop_;
125 148
126 int nonce_count_; 149 int nonce_count_;
127 150 const NonceGenerator* nonce_generator_;
128 // Forces the cnonce to be the same each time, for unit tests.
129 static bool fixed_cnonce_;
130 }; 151 };
131 152
132 } // namespace net 153 } // namespace net
133 154
134 #endif // NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ 155 #endif // NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_
OLDNEW
« no previous file with comments | « no previous file | net/http/http_auth_handler_digest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698