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

Unified Diff: chrome/browser/managed_mode/managed_user_passphrase.cc

Issue 11783008: Add a lock to the managed user settings page and require authentication for unlocking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Several fixes Created 7 years, 11 months 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: chrome/browser/managed_mode/managed_user_passphrase.cc
diff --git a/chrome/browser/managed_mode/managed_user_passphrase.cc b/chrome/browser/managed_mode/managed_user_passphrase.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d33a8fa578cea1e670960beb46ae2bae425e4fb8
--- /dev/null
+++ b/chrome/browser/managed_mode/managed_user_passphrase.cc
@@ -0,0 +1,59 @@
+// Copyright (c) 2012 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 "chrome/browser/managed_mode/managed_user_passphrase.h"
+
+#include "base/base64.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+#include "crypto/encryptor.h"
+#include "crypto/random.h"
+#include "crypto/symmetric_key.h"
+
+const int kNumberOfIterations = 1;
+const int kDerivedKeySize = 128;
+
+ManagedUserPassphrase::ManagedUserPassphrase(const std::string& salt)
+ : salt_(salt) {
+ if (salt_.empty())
+ GenerateRandomSalt();
+}
+
+ManagedUserPassphrase::~ManagedUserPassphrase() {}
+
+std::string ManagedUserPassphrase::GetSalt() {
+ return salt_;
+}
+
+void ManagedUserPassphrase::GenerateRandomSalt() {
+ std::string bytes(32, '\0');
Bernhard Bauer 2013/01/08 17:43:14 Can you pull the size out into a constant as well?
Adrian Kuegel 2013/01/09 12:10:05 Done.
+ crypto::RandBytes(WriteInto(&bytes, bytes.size()), bytes.size());
Bernhard Bauer 2013/01/08 17:43:14 I think this will set the length of the string to
Adrian Kuegel 2013/01/09 12:10:05 Yes, you are right. The question is: which real sa
Bernhard Bauer 2013/02/04 16:13:35 32 is fine. You probably should set kSaltSize to 3
Adrian Kuegel 2013/02/05 12:12:35 Done.
+ bool success = base::Base64Encode(bytes, &salt_);
+ DCHECK(success);
+}
+
+void ManagedUserPassphrase::GenerateHashFromPassphrase(
+ const std::string& passphrase,
+ std::string* encoded_passphrase_hash) {
+ CHECK(encoded_passphrase_hash);
+ std::string passphrase_hash;
+ GetPassphraseHash(passphrase, &passphrase_hash);
+ bool success = base::Base64Encode(passphrase_hash, encoded_passphrase_hash);
+ DCHECK(success);
+}
+
+void ManagedUserPassphrase::GetPassphraseHash(const std::string& passphrase,
+ std::string* passphrase_hash) {
+ DCHECK(passphrase_hash);
+ // Create a hash from the user-provided passphrase and our hard-coded salt.
+ scoped_ptr<crypto::SymmetricKey> encryption_key(
+ crypto::SymmetricKey::DeriveKeyFromPassword(
+ crypto::SymmetricKey::AES,
+ passphrase,
+ salt_,
+ kNumberOfIterations,
+ kDerivedKeySize));
+ bool success = encryption_key->GetRawKey(passphrase_hash);
+ DCHECK(success);
+}

Powered by Google App Engine
This is Rietveld 408576698