| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/easy_unlock_client.h" | 5 #include "chromeos/dbus/easy_unlock_client.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // EasyUnlockClient::Create). | 39 // EasyUnlockClient::Create). |
| 40 class EasyUnlockClientImpl : public EasyUnlockClient { | 40 class EasyUnlockClientImpl : public EasyUnlockClient { |
| 41 public: | 41 public: |
| 42 EasyUnlockClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} | 42 EasyUnlockClientImpl() : proxy_(NULL), weak_ptr_factory_(this) {} |
| 43 | 43 |
| 44 virtual ~EasyUnlockClientImpl() {} | 44 virtual ~EasyUnlockClientImpl() {} |
| 45 | 45 |
| 46 // EasyUnlockClient override. | 46 // EasyUnlockClient override. |
| 47 virtual void PerformECDHKeyAgreement(const std::string& private_key, | 47 virtual void PerformECDHKeyAgreement(const std::string& private_key, |
| 48 const std::string& public_key, | 48 const std::string& public_key, |
| 49 const DataCallback& callback) OVERRIDE { | 49 const DataCallback& callback) override { |
| 50 dbus::MethodCall method_call( | 50 dbus::MethodCall method_call( |
| 51 easy_unlock::kEasyUnlockServiceInterface, | 51 easy_unlock::kEasyUnlockServiceInterface, |
| 52 easy_unlock::kPerformECDHKeyAgreementMethod); | 52 easy_unlock::kPerformECDHKeyAgreementMethod); |
| 53 dbus::MessageWriter writer(&method_call); | 53 dbus::MessageWriter writer(&method_call); |
| 54 // NOTE: DBus expects that data sent as string is UTF-8 encoded. This is | 54 // NOTE: DBus expects that data sent as string is UTF-8 encoded. This is |
| 55 // not guaranteed here, so the method uses byte arrays. | 55 // not guaranteed here, so the method uses byte arrays. |
| 56 AppendStringAsByteArray(private_key, &writer); | 56 AppendStringAsByteArray(private_key, &writer); |
| 57 AppendStringAsByteArray(public_key, &writer); | 57 AppendStringAsByteArray(public_key, &writer); |
| 58 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 58 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 59 base::Bind(&EasyUnlockClientImpl::OnData, | 59 base::Bind(&EasyUnlockClientImpl::OnData, |
| 60 weak_ptr_factory_.GetWeakPtr(), | 60 weak_ptr_factory_.GetWeakPtr(), |
| 61 callback)); | 61 callback)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // EasyUnlockClient override. | 64 // EasyUnlockClient override. |
| 65 virtual void GenerateEcP256KeyPair(const KeyPairCallback& callback) OVERRIDE { | 65 virtual void GenerateEcP256KeyPair(const KeyPairCallback& callback) override { |
| 66 dbus::MethodCall method_call( | 66 dbus::MethodCall method_call( |
| 67 easy_unlock::kEasyUnlockServiceInterface, | 67 easy_unlock::kEasyUnlockServiceInterface, |
| 68 easy_unlock::kGenerateEcP256KeyPairMethod); | 68 easy_unlock::kGenerateEcP256KeyPairMethod); |
| 69 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 69 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 70 base::Bind(&EasyUnlockClientImpl::OnKeyPair, | 70 base::Bind(&EasyUnlockClientImpl::OnKeyPair, |
| 71 weak_ptr_factory_.GetWeakPtr(), | 71 weak_ptr_factory_.GetWeakPtr(), |
| 72 callback)); | 72 callback)); |
| 73 } | 73 } |
| 74 | 74 |
| 75 // EasyUnlockClient override. | 75 // EasyUnlockClient override. |
| 76 virtual void CreateSecureMessage(const std::string& payload, | 76 virtual void CreateSecureMessage(const std::string& payload, |
| 77 const CreateSecureMessageOptions& options, | 77 const CreateSecureMessageOptions& options, |
| 78 const DataCallback& callback) OVERRIDE { | 78 const DataCallback& callback) override { |
| 79 dbus::MethodCall method_call( | 79 dbus::MethodCall method_call( |
| 80 easy_unlock::kEasyUnlockServiceInterface, | 80 easy_unlock::kEasyUnlockServiceInterface, |
| 81 easy_unlock::kCreateSecureMessageMethod); | 81 easy_unlock::kCreateSecureMessageMethod); |
| 82 dbus::MessageWriter writer(&method_call); | 82 dbus::MessageWriter writer(&method_call); |
| 83 // NOTE: DBus expects that data sent as string is UTF-8 encoded. This is | 83 // NOTE: DBus expects that data sent as string is UTF-8 encoded. This is |
| 84 // not guaranteed here, so the method uses byte arrays. | 84 // not guaranteed here, so the method uses byte arrays. |
| 85 AppendStringAsByteArray(payload, &writer); | 85 AppendStringAsByteArray(payload, &writer); |
| 86 AppendStringAsByteArray(options.key, &writer); | 86 AppendStringAsByteArray(options.key, &writer); |
| 87 AppendStringAsByteArray(options.associated_data, &writer); | 87 AppendStringAsByteArray(options.associated_data, &writer); |
| 88 AppendStringAsByteArray(options.public_metadata, &writer); | 88 AppendStringAsByteArray(options.public_metadata, &writer); |
| 89 AppendStringAsByteArray(options.verification_key_id, &writer); | 89 AppendStringAsByteArray(options.verification_key_id, &writer); |
| 90 AppendStringAsByteArray(options.decryption_key_id, &writer); | 90 AppendStringAsByteArray(options.decryption_key_id, &writer); |
| 91 writer.AppendString(options.encryption_type); | 91 writer.AppendString(options.encryption_type); |
| 92 writer.AppendString(options.signature_type); | 92 writer.AppendString(options.signature_type); |
| 93 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 93 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 94 base::Bind(&EasyUnlockClientImpl::OnData, | 94 base::Bind(&EasyUnlockClientImpl::OnData, |
| 95 weak_ptr_factory_.GetWeakPtr(), | 95 weak_ptr_factory_.GetWeakPtr(), |
| 96 callback)); | 96 callback)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // EasyUnlockClient override. | 99 // EasyUnlockClient override. |
| 100 virtual void UnwrapSecureMessage(const std::string& message, | 100 virtual void UnwrapSecureMessage(const std::string& message, |
| 101 const UnwrapSecureMessageOptions& options, | 101 const UnwrapSecureMessageOptions& options, |
| 102 const DataCallback& callback) OVERRIDE { | 102 const DataCallback& callback) override { |
| 103 dbus::MethodCall method_call( | 103 dbus::MethodCall method_call( |
| 104 easy_unlock::kEasyUnlockServiceInterface, | 104 easy_unlock::kEasyUnlockServiceInterface, |
| 105 easy_unlock::kUnwrapSecureMessageMethod); | 105 easy_unlock::kUnwrapSecureMessageMethod); |
| 106 dbus::MessageWriter writer(&method_call); | 106 dbus::MessageWriter writer(&method_call); |
| 107 // NOTE: DBus expects that data sent as string is UTF-8 encoded. This is | 107 // NOTE: DBus expects that data sent as string is UTF-8 encoded. This is |
| 108 // not guaranteed here, so the method uses byte arrays. | 108 // not guaranteed here, so the method uses byte arrays. |
| 109 AppendStringAsByteArray(message, &writer); | 109 AppendStringAsByteArray(message, &writer); |
| 110 AppendStringAsByteArray(options.key, &writer); | 110 AppendStringAsByteArray(options.key, &writer); |
| 111 AppendStringAsByteArray(options.associated_data, &writer); | 111 AppendStringAsByteArray(options.associated_data, &writer); |
| 112 writer.AppendString(options.encryption_type); | 112 writer.AppendString(options.encryption_type); |
| 113 writer.AppendString(options.signature_type); | 113 writer.AppendString(options.signature_type); |
| 114 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 114 proxy_->CallMethod(&method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
| 115 base::Bind(&EasyUnlockClientImpl::OnData, | 115 base::Bind(&EasyUnlockClientImpl::OnData, |
| 116 weak_ptr_factory_.GetWeakPtr(), | 116 weak_ptr_factory_.GetWeakPtr(), |
| 117 callback)); | 117 callback)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 protected: | 120 protected: |
| 121 virtual void Init(dbus::Bus* bus) OVERRIDE { | 121 virtual void Init(dbus::Bus* bus) override { |
| 122 proxy_ = | 122 proxy_ = |
| 123 bus->GetObjectProxy( | 123 bus->GetObjectProxy( |
| 124 easy_unlock::kEasyUnlockServiceName, | 124 easy_unlock::kEasyUnlockServiceName, |
| 125 dbus::ObjectPath(easy_unlock::kEasyUnlockServicePath)); | 125 dbus::ObjectPath(easy_unlock::kEasyUnlockServicePath)); |
| 126 } | 126 } |
| 127 | 127 |
| 128 private: | 128 private: |
| 129 void OnData(const DataCallback& callback, dbus::Response* response) { | 129 void OnData(const DataCallback& callback, dbus::Response* response) { |
| 130 if (!response) { | 130 if (!response) { |
| 131 callback.Run(""); | 131 callback.Run(""); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 EasyUnlockClient::~EasyUnlockClient() { | 179 EasyUnlockClient::~EasyUnlockClient() { |
| 180 } | 180 } |
| 181 | 181 |
| 182 // static | 182 // static |
| 183 EasyUnlockClient* EasyUnlockClient::Create() { | 183 EasyUnlockClient* EasyUnlockClient::Create() { |
| 184 return new EasyUnlockClientImpl(); | 184 return new EasyUnlockClientImpl(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 } // namespace chromeos | 187 } // namespace chromeos |
| OLD | NEW |