From e66ba708afc6b18db21838a1e5ea3d75f6db2f16 Mon Sep 17 00:00:00 2001
From: Edric Milaret <edric.ladent-milaret@savoirfairelinux.com>
Date: Tue, 7 Jun 2016 12:59:45 -0400
Subject: [PATCH] ios: fix dht certificate path

We can't save and use the fullpath of the certificate as it change
at each start on Simulator and at update on real device

Change-Id: I82e6e3c500cd6396edeca6c72785d82aee311979
Tuleap: #313
---
 src/ringdht/ringaccount.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/ringdht/ringaccount.cpp b/src/ringdht/ringaccount.cpp
index 43aac58f18..7c91778c7b 100644
--- a/src/ringdht/ringaccount.cpp
+++ b/src/ringdht/ringaccount.cpp
@@ -459,8 +459,14 @@ RingAccount::loadIdentity()
     dht::crypto::PrivateKey dht_key;
 
     try {
+#if TARGET_OS_IPHONE
+        const auto path = fileutils::get_data_dir() + DIR_SEPARATOR_STR + getAccountID() + DIR_SEPARATOR_STR;
+        dht_cert = dht::crypto::Certificate(fileutils::loadFile(path + tlsCertificateFile_));
+        dht_key = dht::crypto::PrivateKey(fileutils::loadFile(path + tlsPrivateKeyFile_), tlsPassword_);
+#else
         dht_cert = dht::crypto::Certificate(fileutils::loadFile(tlsCertificateFile_));
         dht_key = dht::crypto::PrivateKey(fileutils::loadFile(tlsPrivateKeyFile_), tlsPassword_);
+#endif
     }
     catch (const std::exception& e) {
         RING_ERR("Error loading identity: %s", e.what());
@@ -479,8 +485,13 @@ RingAccount::loadIdentity()
 
         // save the chain including CA
         saveIdentity(id, idPath_ + DIR_SEPARATOR_STR "dht");
+#if TARGET_OS_IPHONE
+        tlsCertificateFile_ = "dht.crt";
+        tlsPrivateKeyFile_ =  "dht.key";
+#else
         tlsCertificateFile_ = idPath_ + DIR_SEPARATOR_STR "dht.crt";
         tlsPrivateKeyFile_ = idPath_ + DIR_SEPARATOR_STR "dht.key";
+#endif
         tlsPassword_ = {};
 
         username_ = RING_URI_PREFIX+id.second->getId().toString();
-- 
GitLab