Skip to content

Linux + iPhone Continuity / iMessage / SMS

hostnames instead of hardcoded

Zack Bartel206cc52effce
diff --git a/src/cli/main.cpp b/src/cli/main.cpp
index 117b649..4c00106 100644
--- a/src/cli/main.cpp
+++ b/src/cli/main.cpp
@@ -1,5 +1,6 @@
#include <iostream>
#include <string>
+#include <unistd.h>
#include <tether/client.hpp>
#include <tether/discovery.hpp>
#include <tether/crypto.hpp>
@@ -113,7 +114,9 @@ int main(int argc, char* argv[]) {
std::string err;
if (action == "pair") {
- std::string resp = client.pair("CLI", err);
+ char hostname[256] = {};
+ gethostname(hostname, sizeof(hostname) - 1);
+ std::string resp = client.pair(hostname, err);
if (!err.empty()) {
std::cerr << err << "\n";
return 1;
diff --git a/src/core/src/client.cpp b/src/core/src/client.cpp
index 6ab28bd..c8758bc 100644
--- a/src/core/src/client.cpp
+++ b/src/core/src/client.cpp
@@ -161,7 +161,27 @@ std::string Client::list_devices() {
bool Client::accept_device(const std::string& fingerprint, const std::string& name) {
tether::Crypto::instance().init();
- tether::Crypto::instance().add_known_host(name, fingerprint);
+
+ // Check if the daemon stored a name from the pair_request
+ std::string resolved_name = name;
+ std::string pending_path = tether::get_runtime_dir() + "/pending_pairs.json";
+ nlohmann::json pending;
+
+ std::ifstream ifs(pending_path);
+ if (ifs.is_open()) {
+ try { pending = nlohmann::json::parse(ifs); } catch (...) {}
+ ifs.close();
+ }
+
+ if (pending.contains(fingerprint) && pending[fingerprint].is_string()) {
+ resolved_name = pending[fingerprint].get<std::string>();
+ // Remove the accepted entry
+ pending.erase(fingerprint);
+ std::ofstream ofs(pending_path);
+ ofs << pending.dump(4);
+ }
+
+ tether::Crypto::instance().add_known_host(resolved_name, fingerprint);
return true;
}
diff --git a/src/core/src/net.cpp b/src/core/src/net.cpp
index a9db107..b342e86 100644
--- a/src/core/src/net.cpp
+++ b/src/core/src/net.cpp
@@ -328,6 +328,20 @@ namespace tether {
std::string dev_name = j.value("device_name", "Unknown Device");
std::cout << "[Pairing Request Pending] from " << dev_name
<< ". Accept by running: tether --accept " << print << std::endl;
+
+ // Persist the pending request so accept_device can retrieve the name
+ {
+ std::string pending_path = get_runtime_dir() + "/pending_pairs.json";
+ nlohmann::json pending;
+ std::ifstream ifs(pending_path);
+ if (ifs.is_open()) {
+ try { pending = nlohmann::json::parse(ifs); } catch (...) {}
+ ifs.close();
+ }
+ pending[print] = dev_name;
+ std::ofstream ofs(pending_path);
+ ofs << pending.dump(4);
+ }
nlohmann::json resp;
resp["command"] = "pair_pending";
diff --git a/src/gtk/main.cpp b/src/gtk/main.cpp
index 96e2742..34716ac 100644
--- a/src/gtk/main.cpp
+++ b/src/gtk/main.cpp
@@ -5,6 +5,7 @@
#include <iostream>
#include <string>
#include <thread>
+#include <unistd.h>
#include <nlohmann/json.hpp>
// Always-connected local unix socket client.
@@ -299,7 +300,9 @@ static void on_btn_pair_clicked(GtkWidget* widget, gpointer) {
}
std::string err;
- std::string resp = pair_client.pair("Tether GTK", err);
+ char hostname[256] = {};
+ gethostname(hostname, sizeof(hostname) - 1);
+ std::string resp = pair_client.pair(hostname, err);
GtkWidget* dlg = gtk_message_dialog_new(
GTK_WINDOW(gtk_widget_get_toplevel(widget)),