shill: Infrastucture for encrypting/decrypting/scrambling store values.
This adds a CryptoProvider that registers and provides access to different
prioritized crypto modules (currently DES-CBC and ROT47). Use the provider in
KeyFileStore to provide an API for getting and setting crypted string values.
BUG=chromium-os:16963
TEST=unit tests
Change-Id: I492516890eb3f527758d354cd8890088cb99dea4
Reviewed-on: http://gerrit.chromium.org/gerrit/3395
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Chris Masone <cmasone@chromium.org>
diff --git a/crypto_provider.h b/crypto_provider.h
new file mode 100644
index 0000000..9bed7d4
--- /dev/null
+++ b/crypto_provider.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2011 The Chromium OS 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 SHILL_CRYPTO_PROVIDER_
+#define SHILL_CRYPTO_PROVIDER_
+
+#include <base/file_path.h>
+#include <base/memory/scoped_vector.h>
+#include <gtest/gtest_prod.h> // for FRIEND_TEST
+
+namespace shill {
+
+class CryptoInterface;
+class GLib;
+
+class CryptoProvider {
+ public:
+ explicit CryptoProvider(GLib *glib);
+
+ void Init();
+
+ // Returns |plaintext| encrypted by the highest priority available crypto
+ // module capable of performing the operation. If no module succeeds, returns
+ // |plaintext| as is.
+ std::string Encrypt(const std::string &plaintext);
+
+ // Returns |ciphertext| decrypted by the highest priority available crypto
+ // module capable of performing the operation. If no module succeeds, returns
+ // |ciphertext| as is.
+ std::string Decrypt(const std::string &ciphertext);
+
+ void set_key_matter_file(const FilePath &path) { key_matter_file_ = path; }
+
+ private:
+ FRIEND_TEST(CryptoProviderTest, Init);
+ FRIEND_TEST(KeyFileStoreTest, OpenClose);
+ typedef ScopedVector<CryptoInterface> Cryptos;
+
+ static const char kKeyMatterFile[];
+
+ GLib *glib_;
+
+ // Registered crypto modules in high to low priority order.
+ Cryptos cryptos_;
+
+ FilePath key_matter_file_;
+
+ DISALLOW_COPY_AND_ASSIGN(CryptoProvider);
+};
+
+} // namespace shill
+
+#endif // SHILL_CRYPTO_PROVIDER_