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

Unified Diff: remoting/host/host_secret.cc

Issue 8662001: Remove AccessVerifier interface. (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
Index: remoting/host/host_secret.cc
diff --git a/remoting/host/host_secret.cc b/remoting/host/host_secret.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3a3d183035b95df54e50e42d698dfd3ea9ece578
--- /dev/null
+++ b/remoting/host/host_secret.cc
@@ -0,0 +1,41 @@
+// Copyright (c) 2011 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.
+
+#include "remoting/host/host_secret.h"
+
+#include <vector>
+
+#include "base/logging.h"
+#include "base/rand_util.h"
+
+namespace remoting {
+
+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 kHostSecretLength = 5;
+const char kHostSecretAlphabet[] = "0123456789";
Wez 2011/11/29 05:58:47 Now that the alphabet for codes is 0-9, we could j
Sergey Ulanov 2011/11/29 18:52:01 Done.
+
+// Generates cryptographically strong random number in the range [0, max).
+int CryptoRandomInt(int max) {
+ uint32 random_int32;
+ base::RandBytes(&random_int32, sizeof(random_int32));
+ return random_int32 % max;
+}
+
+} // namespace
+
+std::string GenerateRandomHostSecret() {
+ std::vector<char> result;
Wez 2011/11/29 05:58:47 Can't we just create the string and generate rando
Sergey Ulanov 2011/11/29 18:52:01 Done.
+ int alphabet_size = strlen(kHostSecretAlphabet);
+ result.resize(kHostSecretLength);
+ for (int i = 0; i < kHostSecretLength; ++i) {
+ result[i] = kHostSecretAlphabet[CryptoRandomInt(alphabet_size)];
+ }
+ return std::string(result.begin(), result.end());
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698