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

Unified Diff: chrome/browser/chromeos/login/owner_key_utils.h

Issue 3017020: Refactoring key generation and export util code to make mocking possible. (Closed)
Patch Set: address comments per davemoore Created 10 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/owner_key_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/login/owner_key_utils.h
diff --git a/chrome/browser/chromeos/login/owner_key_utils.h b/chrome/browser/chromeos/login/owner_key_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..8900ed435f51545d3e2cfce1f7503a862afa0501
--- /dev/null
+++ b/chrome/browser/chromeos/login/owner_key_utils.h
@@ -0,0 +1,70 @@
+// Copyright (c) 2010 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_
+#define CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_
+
+#include "base/basictypes.h"
+
+// Forward declarations of NSS data structures.
+struct SECKEYPrivateKeyStr;
+struct SECKEYPublicKeyStr;
+struct SECItemStr;
+
+typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey;
+typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
+typedef struct SECItemStr SECItem;
+
+class FilePath;
+
+class OwnerKeyUtils {
+ public:
+ class Factory {
+ public:
+ virtual OwnerKeyUtils* CreateOwnerKeyUtils() = 0;
+ };
+
+ OwnerKeyUtils();
+ virtual ~OwnerKeyUtils();
+
+ // Sets the factory used by the static method Create to create an
+ // OwnerKeyUtils. OwnerKeyUtils does not take ownership of
+ // |factory|. A value of NULL results in an OwnerKeyUtils being
+ // created directly.
+#if defined(UNIT_TEST)
+ static void set_factory(Factory* factory) { factory_ = factory; }
+#endif
+
+ // Creates an OwnerKeyUtils, ownership returns to the caller. If there is no
+ // Factory (the default) this creates and returns a new OwnerKeyUtils.
+ static OwnerKeyUtils* Create();
+
+ // Generate a public/private RSA keypair and store them in the NSS database.
+ // The keys will be kKeySizeInBits in length (Recommend >= 2048 bits).
+ //
+ // Returns false on error.
+ //
+ // The caller takes ownership of both objects, which are allocated by libnss.
+ // To free them, call
+ // SECKEY_DestroyPrivateKey(*private_key_out);
+ // SECKEY_DestroyPublicKey(*public_key_out);
+ virtual bool GenerateKeyPair(SECKEYPrivateKey** private_key_out,
+ SECKEYPublicKey** public_key_out) = 0;
+
+ // DER encodes |key| and writes it out to |key_file|.
+ // The blob on disk is a DER-encoded X509 SubjectPublicKeyInfo object.
+ // Returns false on error.
+ virtual bool ExportPublicKey(SECKEYPublicKey* key,
+ const FilePath& key_file) = 0;
+
+ // Assumes that the file at |key_file| exists.
+ // Caller takes ownership of returned object; returns NULL on error.
+ // To free, call SECKEY_DestroyPublicKey.
+ virtual SECKEYPublicKey* ImportPublicKey(const FilePath& key_file) = 0;
+
+ private:
+ static Factory* factory_;
+};
+
+#endif // CHROME_BROWSER_CHROMEOS_LOGIN_OWNER_KEY_UTILS_H_
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/owner_key_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698