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

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: 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..a68684c20187738d4340073e631547994fa73f7e
--- /dev/null
+++ b/chrome/browser/managed_mode/managed_user_passphrase.cc
@@ -0,0 +1,40 @@
+// 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 "crypto/encryptor.h"
+#include "crypto/symmetric_key.h"
+
+const std::string ManagedUserPassphrase::kSalt_ = "managed_salt";
Pam (message me for reviews) 2013/01/07 14:51:49 You'll be fixing this as your very next change, ri
+
+void ManagedUserPassphrase::GenerateHashFromPassphrase(
+ const std::string& passphrase,
+ std::string* encoded_passphrase_hash) {
+ DCHECK(encoded_passphrase_hash);
Pam (message me for reviews) 2013/01/07 14:51:49 This should just be a CHECK. If somebody passes a
Bernhard Bauer 2013/01/08 17:43:14 Well, then you can probably leave it out completel
+ std::string passphrase_hash;
+ GetPassphraseHash(passphrase, &passphrase_hash);
+ if (!base::Base64Encode(passphrase_hash, encoded_passphrase_hash)) {
Bernhard Bauer 2013/01/07 14:20:22 Nit: I usually do `bool success = ...; DCHECK(succ
+ NOTREACHED();
+ }
+}
+
+void ManagedUserPassphrase::GetPassphraseHash(const std::string& passphrase,
+ std::string* passphrase_hash) {
Bernhard Bauer 2013/01/07 14:20:22 Please align this parameter with the previous one
+ 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,
+ kSalt_,
+ 128,
+ 1));
+ DCHECK(encryption_key.get());
Pam (message me for reviews) 2013/01/07 14:51:49 I don't think this is necessary, since the next li
+ if (!encryption_key->GetRawKey(passphrase_hash)) {
+ NOTREACHED();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698