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

Side by Side 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 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
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/host/host_secret.h"
6
7 #include <vector>
8
9 #include "base/logging.h"
10 #include "base/rand_util.h"
11
12 namespace remoting {
13
14 namespace {
15
16 // 5 digits means 100K possible host secrets with uniform distribution, which
17 // should be enough for short-term passwords, given that we rate-limit guesses
18 // in the cloud and expire access codes after a small number of attempts.
19 const int kHostSecretLength = 5;
20 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.
21
22 // Generates cryptographically strong random number in the range [0, max).
23 int CryptoRandomInt(int max) {
24 uint32 random_int32;
25 base::RandBytes(&random_int32, sizeof(random_int32));
26 return random_int32 % max;
27 }
28
29 } // namespace
30
31 std::string GenerateRandomHostSecret() {
32 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.
33 int alphabet_size = strlen(kHostSecretAlphabet);
34 result.resize(kHostSecretLength);
35 for (int i = 0; i < kHostSecretLength; ++i) {
36 result[i] = kHostSecretAlphabet[CryptoRandomInt(alphabet_size)];
37 }
38 return std::string(result.begin(), result.end());
39 }
40
41 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698