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

Side by Side 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 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 #include "remoting/host/host_secret.h" 5 #include "remoting/host/host_secret.h"
6 6
7 #include <iomanip>
8 #include <sstream>
7 #include <vector> 9 #include <vector>
8 10
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/rand_util.h" 12 #include "base/rand_util.h"
11 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
12 14
13 namespace remoting { 15 namespace remoting {
14 16
15 namespace { 17 namespace {
16 18
17 // 5 digits means 100K possible host secrets with uniform distribution, which 19 // 5 digits means 100K possible host secrets with uniform distribution, which
18 // should be enough for short-term passwords, given that we rate-limit guesses 20 // should be enough for short-term passwords, given that we rate-limit guesses
19 // in the cloud and expire access codes after a small number of attempts. 21 // in the cloud and expire access codes after a small number of attempts.
20 const int kMaxHostSecret = 100000; 22 const int kHostSecretLength = 5;
23 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.
21 24
22 // Generates cryptographically strong random number in the range [0, max). 25 // Generates cryptographically strong random number in the range [0, max).
23 int CryptoRandomInt(int max) { 26 int CryptoRandomInt(int max) {
24 uint64 random_int32; 27 uint64 random_int32;
25 base::RandBytes(&random_int32, sizeof(random_int32)); 28 base::RandBytes(&random_int32, sizeof(random_int32));
26 return random_int32 % max; 29 return random_int32 % max;
27 } 30 }
28 31
29 } // namespace 32 } // namespace
30 33
31 std::string GenerateSupportHostSecret() { 34 std::string GenerateSupportHostSecret() {
32 return base::IntToString(CryptoRandomInt(kMaxHostSecret)); 35 std::stringstream out;
36 out << std::setfill('0') << std::setw(kHostSecretLength)
37 << CryptoRandomInt(kMaxHostSecret);
38 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
33 } 39 }
34 40
35 } // namespace remoting 41 } // namespace remoting
OLDNEW
« 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