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

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: Merge with trunk 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
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/basictypes.h"
11 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/scoped_ptr.h"
12 #include "base/string16.h" 14 #include "base/string16.h"
13 #include "net/http/http_auth_handler.h" 15 #include "net/http/http_auth_handler.h"
14 #include "net/http/http_auth_handler_factory.h" 16 #include "net/http/http_auth_handler_factory.h"
15 17
16 namespace net { 18 namespace net {
17 19
18 // Code for handling http digest authentication. 20 // Code for handling http digest authentication.
19 class HttpAuthHandlerDigest : public HttpAuthHandler { 21 class HttpAuthHandlerDigest : public HttpAuthHandler {
20 public: 22 public:
23 // A NonceGenerator is a simple interface for generating client nonces.
24 // Unit tests can override the default client nonce behavior with fixed
25 // nonce generation to get reproducible results.
26 class NonceGenerator {
27 public:
28 NonceGenerator();
29 virtual ~NonceGenerator();
30
31 // Generates a client nonce.
32 virtual std::string GenerateNonce() const = 0;
33 private:
34 DISALLOW_COPY_AND_ASSIGN(NonceGenerator);
35 };
36
37 // DynamicNonceGenerator does a random shuffle of 16
38 // characters to generate a client nonce.
39 class DynamicNonceGenerator : public NonceGenerator {
40 public:
41 DynamicNonceGenerator();
42 virtual std::string GenerateNonce() const;
43 private:
44 DISALLOW_COPY_AND_ASSIGN(DynamicNonceGenerator);
45 };
46
47 // FixedNonceGenerator always uses the same string specified at
48 // construction time as the client nonce.
49 class FixedNonceGenerator : public NonceGenerator {
50 public:
51 explicit FixedNonceGenerator(const std::string& nonce);
52
53 virtual std::string GenerateNonce() const;
54
55 private:
56 const std::string nonce_;
57 DISALLOW_COPY_AND_ASSIGN(FixedNonceGenerator);
58 };
59
21 class Factory : public HttpAuthHandlerFactory { 60 class Factory : public HttpAuthHandlerFactory {
22 public: 61 public:
23 Factory(); 62 Factory();
24 virtual ~Factory(); 63 virtual ~Factory();
25 64
26 virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge, 65 virtual int CreateAuthHandler(HttpAuth::ChallengeTokenizer* challenge,
27 HttpAuth::Target target, 66 HttpAuth::Target target,
28 const GURL& origin, 67 const GURL& origin,
29 CreateReason reason, 68 CreateReason reason,
30 int digest_nonce_count, 69 int digest_nonce_count,
31 const BoundNetLog& net_log, 70 const BoundNetLog& net_log,
32 scoped_ptr<HttpAuthHandler>* handler); 71 scoped_ptr<HttpAuthHandler>* handler);
72
73 // This factory owns the passed in |nonce_generator|.
74 void set_nonce_generator(const NonceGenerator* nonce_generator);
75
76 private:
77 scoped_ptr<const NonceGenerator> nonce_generator_;
wtc 2010/11/17 20:21:51 I know the C++ language allows deleting a const po
cbentzel 2010/11/18 12:06:38 I tend to veer towards const-heaviness. Flame war
33 }; 78 };
34 79
35 HttpAuth::AuthorizationResult HandleAnotherChallenge( 80 HttpAuth::AuthorizationResult HandleAnotherChallenge(
36 HttpAuth::ChallengeTokenizer* challenge); 81 HttpAuth::ChallengeTokenizer* challenge);
37 82
38 protected: 83 protected:
39 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); 84 virtual bool Init(HttpAuth::ChallengeTokenizer* challenge);
40 85
41 virtual int GenerateAuthTokenImpl(const string16* username, 86 virtual int GenerateAuthTokenImpl(const string16* username,
42 const string16* password, 87 const string16* password,
(...skipping 20 matching lines...) Expand all
63 ALGORITHM_MD5_SESS, 108 ALGORITHM_MD5_SESS,
64 }; 109 };
65 110
66 // Possible values for QualityOfProtection. 111 // Possible values for QualityOfProtection.
67 // auth-int is not supported, see http://crbug.com/62890 for justification. 112 // auth-int is not supported, see http://crbug.com/62890 for justification.
68 enum QualityOfProtection { 113 enum QualityOfProtection {
69 QOP_UNSPECIFIED, 114 QOP_UNSPECIFIED,
70 QOP_AUTH, 115 QOP_AUTH,
71 }; 116 };
72 117
73 explicit HttpAuthHandlerDigest(int nonce_count); 118 // |nonce_count| indicates how many times the server-specified nonce has
119 // been used so far.
120 // |nonce_generator| is used to create a client nonce, and is not owned by
121 // the handler. The lifetime of the |nonce_generator| must exceed that of this
122 // handler.
123 HttpAuthHandlerDigest(int nonce_count, const NonceGenerator* nonce_generator);
74 ~HttpAuthHandlerDigest(); 124 ~HttpAuthHandlerDigest();
75 125
76 // Parse the challenge, saving the results into this instance. 126 // Parse the challenge, saving the results into this instance.
77 // Returns true on success. 127 // Returns true on success.
78 bool ParseChallenge(HttpAuth::ChallengeTokenizer* challenge); 128 bool ParseChallenge(HttpAuth::ChallengeTokenizer* challenge);
79 129
80 // Parse an individual property. Returns true on success. 130 // Parse an individual property. Returns true on success.
81 bool ParseChallengeProperty(const std::string& name, 131 bool ParseChallengeProperty(const std::string& name,
82 const std::string& value); 132 const std::string& value);
83 133
(...skipping 19 matching lines...) Expand all
103 const std::string& nc) const; 153 const std::string& nc) const;
104 154
105 // Build up the value for (Authorization/Proxy-Authorization). 155 // Build up the value for (Authorization/Proxy-Authorization).
106 std::string AssembleCredentials(const std::string& method, 156 std::string AssembleCredentials(const std::string& method,
107 const std::string& path, 157 const std::string& path,
108 const string16& username, 158 const string16& username,
109 const string16& password, 159 const string16& password,
110 const std::string& cnonce, 160 const std::string& cnonce,
111 int nonce_count) const; 161 int nonce_count) const;
112 162
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. 163 // Information parsed from the challenge.
119 std::string nonce_; 164 std::string nonce_;
120 std::string domain_; 165 std::string domain_;
121 std::string opaque_; 166 std::string opaque_;
122 bool stale_; 167 bool stale_;
123 DigestAlgorithm algorithm_; 168 DigestAlgorithm algorithm_;
124 QualityOfProtection qop_; 169 QualityOfProtection qop_;
125 170
126 int nonce_count_; 171 int nonce_count_;
127 172 const NonceGenerator* nonce_generator_;
wtc 2010/11/17 20:21:51 In contrast, it is fine to use a const pointer her
128 // Forces the cnonce to be the same each time, for unit tests.
129 static bool fixed_cnonce_;
130 }; 173 };
131 174
132 } // namespace net 175 } // namespace net
133 176
134 #endif // NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ 177 #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') | net/http/http_auth_handler_factory.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698