Fix the bug when user type in NONE when selecting CAs

Change-Id: Ie12c058ec0685a537300f11dd227771f8e719c28
diff --git a/src/client-config.cpp b/src/client-config.cpp
index 47b75da..19f8a89 100644
--- a/src/client-config.cpp
+++ b/src/client-config.cpp
@@ -20,6 +20,7 @@
 
 #include "client-config.hpp"
 #include <ndn-cxx/util/io.hpp>
+#include <fstream>
 
 namespace ndn {
 namespace ndncert {
@@ -55,6 +56,32 @@
   m_localNdncertAnchor = configSection.get("local-ndncert-anchor", "");
 }
 
+void
+ClientConfig::save(const std::string& fileName)
+{
+  JsonSection configJson;
+  JsonSection caList;
+  std::stringstream ss;
+  for (const auto& item : m_caItems) {
+    JsonSection caItem;
+    caItem.put("ca-prefix", item.m_caName.toUri());
+    caItem.put("ca-info", item.m_caInfo);
+    caItem.put("probe", item.m_probe);
+    ss.str(std::string());
+    io::save(item.m_anchor, ss);
+    caItem.put("certificate", ss.str());
+    caList.push_back(std::make_pair("", caItem));
+  }
+  configJson.add_child("ca-list", caList);
+  ss.str(std::string());
+  boost::property_tree::write_json(ss, configJson);
+
+  std::ofstream configFile;
+  configFile.open(fileName, std::ios::trunc);
+  configFile << ss.str();
+  configFile.close();
+}
+
 ClientCaItem
 ClientConfig::extractCaItem(const JsonSection& configSection)
 {
diff --git a/src/client-config.hpp b/src/client-config.hpp
index ddbdc74..ba02efa 100644
--- a/src/client-config.hpp
+++ b/src/client-config.hpp
@@ -68,6 +68,9 @@
   load(const JsonSection& configSection);
 
   void
+  save(const std::string& fileName);
+
+  void
   addNewCaItem(const ClientCaItem& item);
 
   void
diff --git a/src/client-module.cpp b/src/client-module.cpp
index 12d835d..24947f4 100644
--- a/src/client-module.cpp
+++ b/src/client-module.cpp
@@ -55,8 +55,23 @@
   return interest;
 }
 
+bool
+ClientModule::verifyProbeInfoResponse(const Data& reply)
+{
+  // parse the ca item
+  auto contentJson = getJsonFromData(reply);
+  auto caItem = ClientConfig::extractCaItem(contentJson);
+
+  // verify the probe Data's sig
+  if (!security::verifySignature(reply, caItem.m_anchor)) {
+    _LOG_ERROR("Cannot verify data signature from " << m_ca.m_caName.toUri());
+    return false;
+  }
+  return true;
+}
+
 void
-ClientModule::onProbeInfoResponse(const Data& reply)
+ClientModule::addCaFromProbeInfoResponse(const Data& reply)
 {
   // parse the ca item
   auto contentJson = getJsonFromData(reply);
@@ -73,12 +88,6 @@
   if (!findItem) {
     m_config.m_caItems.push_back(caItem);
   }
-
-  // verify the probe Data's sig
-  if (!security::verifySignature(reply, caItem.m_anchor)) {
-    _LOG_ERROR("Cannot verify data signature from " << m_ca.m_caName.toUri());
-    return;
-  }
 }
 
 shared_ptr<Interest>
diff --git a/src/client-module.hpp b/src/client-module.hpp
index 330b3c6..806c5bc 100644
--- a/src/client-module.hpp
+++ b/src/client-module.hpp
@@ -71,6 +71,9 @@
   shared_ptr<Interest>
   generateProbeInfoInterest(const Name& caName);
 
+  bool
+  verifyProbeInfoResponse(const Data& reply);
+
   /**
    * @brief Process the replied PROBE INFO Data packet
    * Warning: this function will add a new trust anchor into the application.
@@ -78,7 +81,7 @@
    * can be verified in later challenge phase.
    */
   void
-  onProbeInfoResponse(const Data& reply);
+  addCaFromProbeInfoResponse(const Data& reply);
 
   shared_ptr<Interest>
   generateProbeInterest(const ClientCaItem& ca, const std::string& probeInfo);