mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Wi-Fi Direct security implementation
PiperOrigin-RevId: 939931482
This commit is contained in:
@@ -239,7 +239,6 @@ class WifiDirectMedium : public api::WifiDirectMedium {
|
||||
std::unique_ptr<api::WifiDirectServerSocket> ListenForService(
|
||||
int port) override;
|
||||
|
||||
// Advertiser start WiFiDirect GO with specific Credentials.
|
||||
bool StartWifiDirect(WifiDirectCredentials* wifi_direct_credentials) override;
|
||||
// Advertiser stop the current WiFiDirect GO.
|
||||
bool StopWifiDirect() override;
|
||||
@@ -347,6 +346,7 @@ class WifiDirectMedium : public api::WifiDirectMedium {
|
||||
std::string ip_address_local_;
|
||||
std::string ip_address_remote_;
|
||||
absl::CondVar is_ip_address_ready_;
|
||||
std::string remote_device_name_;
|
||||
|
||||
WifiDirectServerSocket* server_socket_ptr_ ABSL_GUARDED_BY(mutex_) = nullptr;
|
||||
SubmittableExecutor listener_executor_;
|
||||
|
||||
@@ -251,8 +251,10 @@ std::unique_ptr<api::WifiDirectServerSocket> WifiDirectMedium::ListenForService(
|
||||
|
||||
bool WifiDirectMedium::StartWifiDirect(
|
||||
WifiDirectCredentials* wifi_direct_credentials) {
|
||||
remote_device_name_ = wifi_direct_credentials->GetRemoteDeviceName();
|
||||
LOG(INFO) << __func__ << ": remote_device_name from credentials: "
|
||||
<< remote_device_name_;
|
||||
absl::MutexLock lock(mutex_);
|
||||
LOG(INFO) << __func__ << ": Start to create WiFiDirect.";
|
||||
if (IsBeaconing()) {
|
||||
LOG(WARNING) << "Cannot create WiFiDirect GO again when it is running.";
|
||||
return true;
|
||||
@@ -431,6 +433,12 @@ fire_and_forget WifiDirectMedium::OnConnectionRequested(
|
||||
LOG(INFO) << "Receive connection request from: "
|
||||
<< winrt::to_string(device_name)
|
||||
<< "; device ID: " << winrt::to_string(device_id);
|
||||
if (!remote_device_name_.empty() &&
|
||||
!absl::EqualsIgnoreCase(remote_device_name_,
|
||||
winrt::to_string(device_name))) {
|
||||
LOG(INFO) << "Ignore the connection request from the unrelated device.";
|
||||
return winrt::fire_and_forget();
|
||||
}
|
||||
|
||||
DeviceInformation windows_device_info(connection_request.DeviceInformation());
|
||||
auto deviceInfoP =
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
@@ -123,6 +123,12 @@ class WifiDirectCredentials {
|
||||
return technology_;
|
||||
}
|
||||
|
||||
// Get/Set Remote Device Name.
|
||||
std::string GetRemoteDeviceName() const { return remote_device_name_; }
|
||||
void SetRemoteDeviceName(const std::string& remote_device_name) {
|
||||
remote_device_name_ = remote_device_name;
|
||||
}
|
||||
|
||||
private:
|
||||
// There are 2 types of WifiDirectAuthType.
|
||||
// 1. Without Service Discovery: the credentials are ssid/password.
|
||||
@@ -137,6 +143,7 @@ class WifiDirectCredentials {
|
||||
std::string gateway_ = "0.0.0.0";
|
||||
int port_ = 0;
|
||||
int frequency_ = -1;
|
||||
std::string remote_device_name_;
|
||||
location::nearby::proto::connections::ConnectionBand band_;
|
||||
location::nearby::proto::connections::ConnectionTechnology technology_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user