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

Unified Diff: net/http/http_auth_handler_digest.cc

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 side-by-side diff with in-line comments
Download patch
Index: net/http/http_auth_handler_digest.cc
===================================================================
--- net/http/http_auth_handler_digest.cc (revision 66330)
+++ net/http/http_auth_handler_digest.cc (working copy)
@@ -45,16 +45,19 @@
// auth-int | | req-method:req-uri:MD5(req-entity-body) |
//=====================+==========================================+
+HttpAuthHandlerDigest::NonceGenerator::NonceGenerator() {
+}
-//static
-bool HttpAuthHandlerDigest::fixed_cnonce_ = false;
+HttpAuthHandlerDigest::NonceGenerator::~NonceGenerator() {
+}
-// static
-std::string HttpAuthHandlerDigest::GenerateNonce() {
+HttpAuthHandlerDigest::DynamicNonceGenerator::DynamicNonceGenerator() {
+}
+
+std::string HttpAuthHandlerDigest::DynamicNonceGenerator::GenerateNonce()
+ const {
// This is how mozilla generates their cnonce -- a 16 digit hex string.
static const char domain[] = "0123456789abcdef";
- if (fixed_cnonce_)
- return std::string(domain);
std::string cnonce;
cnonce.reserve(16);
for (int i = 0; i < 16; ++i)
@@ -62,6 +65,15 @@
return cnonce;
}
+HttpAuthHandlerDigest::FixedNonceGenerator::FixedNonceGenerator(
+ const std::string& nonce)
+ : nonce_(nonce) {
+}
+
+std::string HttpAuthHandlerDigest::FixedNonceGenerator::GenerateNonce() const {
+ return nonce_;
+}
+
// static
std::string HttpAuthHandlerDigest::QopToString(QualityOfProtection qop) {
switch (qop) {
@@ -91,11 +103,14 @@
}
}
-HttpAuthHandlerDigest::HttpAuthHandlerDigest(int nonce_count)
+HttpAuthHandlerDigest::HttpAuthHandlerDigest(
+ int nonce_count, const NonceGenerator* nonce_generator)
: stale_(false),
algorithm_(ALGORITHM_UNSPECIFIED),
qop_(QOP_UNSPECIFIED),
- nonce_count_(nonce_count) {
+ nonce_count_(nonce_count),
+ nonce_generator_(nonce_generator) {
+ DCHECK(nonce_generator_);
}
HttpAuthHandlerDigest::~HttpAuthHandlerDigest() {
@@ -108,7 +123,7 @@
CompletionCallback* callback,
std::string* auth_token) {
// Generate a random client nonce.
- std::string cnonce = GenerateNonce();
+ std::string cnonce = nonce_generator_->GenerateNonce();
// Extract the request method and path -- the meaning of 'path' is overloaded
// in certain cases, to be a hostname.
@@ -327,12 +342,18 @@
return true;
}
-HttpAuthHandlerDigest::Factory::Factory() {
+HttpAuthHandlerDigest::Factory::Factory()
+ : nonce_generator_(new DynamicNonceGenerator()) {
}
HttpAuthHandlerDigest::Factory::~Factory() {
}
+void HttpAuthHandlerDigest::Factory::set_nonce_generator(
+ const NonceGenerator* nonce_generator) {
+ nonce_generator_.reset(nonce_generator);
+}
+
int HttpAuthHandlerDigest::Factory::CreateAuthHandler(
HttpAuth::ChallengeTokenizer* challenge,
HttpAuth::Target target,
@@ -344,7 +365,7 @@
// TODO(cbentzel): Move towards model of parsing in the factory
// method and only constructing when valid.
scoped_ptr<HttpAuthHandler> tmp_handler(
- new HttpAuthHandlerDigest(digest_nonce_count));
+ new HttpAuthHandlerDigest(digest_nonce_count, nonce_generator_.get()));
if (!tmp_handler->InitFromChallenge(challenge, target, origin, net_log))
return ERR_INVALID_RESPONSE;
handler->swap(tmp_handler);

Powered by Google App Engine
This is Rietveld 408576698