Index: chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_mac.cc |
diff --git a/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_mac.cc b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_mac.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6d04259022231fe3b95190af4f4753ea8b0c2655 |
--- /dev/null |
+++ b/chrome/browser/extensions/api/networking_private/networking_private_credentials_getter_mac.cc |
@@ -0,0 +1,88 @@ |
+// Copyright 2014 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/extensions/api/networking_private/networking_private_credentials_getter.h" |
+ |
+#include <Security/Security.h> |
+ |
+#include "base/base64.h" |
+#include "base/bind.h" |
+#include "chrome/browser/extensions/api/networking_private/networking_private_crypto.h" |
+#include "content/public/browser/browser_thread.h" |
+ |
+const char kErrorNotFound[] = "Error.NotFound"; |
+const char kErrorEncryption[] = "Error.Encryption"; |
+ |
+using content::BrowserThread; |
+ |
+namespace extensions { |
+ |
+class NetworkingPrivateCredentialsGetterMac |
+ : public NetworkingPrivateCredentialsGetter { |
+ public: |
+ explicit NetworkingPrivateCredentialsGetterMac(); |
+ |
+ virtual void Start( |
+ const std::string& network_guid, |
+ const std::string& public_key, |
+ const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
+ VerifyAndEncryptCredentialsCallback& callback) OVERRIDE; |
+ |
+ private: |
+ virtual ~NetworkingPrivateCredentialsGetterMac(); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(NetworkingPrivateCredentialsGetterMac); |
+}; |
+ |
+NetworkingPrivateCredentialsGetterMac::NetworkingPrivateCredentialsGetterMac() { |
+} |
+ |
+NetworkingPrivateCredentialsGetterMac:: |
+ ~NetworkingPrivateCredentialsGetterMac() {} |
+ |
+void NetworkingPrivateCredentialsGetterMac::Start( |
+ const std::string& network_guid, |
+ const std::string& public_key, |
+ const extensions::NetworkingPrivateServiceClient::CryptoVerify:: |
+ VerifyAndEncryptCredentialsCallback& callback) { |
+ static const char kAirPortServiceName[] = "AirPort"; |
+ |
+ UInt32 password_length = 0; |
+ void* password_data = NULL; |
+ OSStatus status = noErr; |
+ status = SecKeychainFindGenericPassword(NULL, |
+ strlen(kAirPortServiceName), |
+ kAirPortServiceName, |
+ network_guid.length(), |
+ network_guid.c_str(), |
+ &password_length, |
+ &password_data, |
+ NULL); |
+ |
+ if (status != noErr || !password_data) { |
+ callback.Run("", kErrorNotFound); |
+ return; |
+ } |
+ |
+ std::string key_data(reinterpret_cast<char*>(password_data), password_length); |
+ SecKeychainItemFreeContent(NULL, password_data); |
+ |
+ NetworkingPrivateCrypto crypto; |
+ std::string ciphertext; |
+ if (!crypto.EncryptByteString(public_key, key_data, &ciphertext)) { |
+ callback.Run("", kErrorEncryption); |
+ return; |
+ } |
+ |
+ std::string base64_encoded_ciphertext; |
+ base::Base64Encode(ciphertext, &base64_encoded_ciphertext); |
+ callback.Run(base64_encoded_ciphertext, ""); |
+} |
+ |
+NetworkingPrivateCredentialsGetter* NetworkingPrivateCredentialsGetter:: |
+ Create() { |
+ return new NetworkingPrivateCredentialsGetterMac(callback); |
+} |
+ |
+} // namespace extensions |