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

Unified Diff: remoting/host/host_secret.cc

Issue 8734012: Always generate host secrets of correct length. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/host_secret.cc
diff --git a/remoting/host/host_secret.cc b/remoting/host/host_secret.cc
index 1ed86224e0ad0297214394b46f3ae57125d6d116..b7b9368b2c9508487dbe4c1d05723939556c6c82 100644
--- a/remoting/host/host_secret.cc
+++ b/remoting/host/host_secret.cc
@@ -4,6 +4,8 @@
#include "remoting/host/host_secret.h"
+#include <iomanip>
+#include <sstream>
#include <vector>
#include "base/logging.h"
@@ -17,7 +19,8 @@ namespace {
// 5 digits means 100K possible host secrets with uniform distribution, which
// should be enough for short-term passwords, given that we rate-limit guesses
// in the cloud and expire access codes after a small number of attempts.
-const int kMaxHostSecret = 100000;
+const int kHostSecretLength = 5;
+const int kMaxHostSecret = 100000; // Must be equal 10^kHostSecretLength.
Wez 2011/11/30 00:34:26 Can this be 10^kHostSecretLength, or will that end
Sergey Ulanov 2011/11/30 01:12:26 Done.
// Generates cryptographically strong random number in the range [0, max).
int CryptoRandomInt(int max) {
@@ -29,7 +32,10 @@ int CryptoRandomInt(int max) {
} // namespace
std::string GenerateSupportHostSecret() {
- return base::IntToString(CryptoRandomInt(kMaxHostSecret));
+ std::stringstream out;
+ out << std::setfill('0') << std::setw(kHostSecretLength)
+ << CryptoRandomInt(kMaxHostSecret);
+ return out.str();
Wez 2011/11/30 00:34:26 Ick. Beginning to think the byte-by-byte version
Sergey Ulanov 2011/11/30 01:12:26 Yes. Some other code in chromium uses the same app
}
} // namespace remoting
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698