Fixing the bug in issuing intro cert in the policy manager
Fixing the conversion bug in intro-cert
diff --git a/src/sync-intro-certificate.cc b/src/sync-intro-certificate.cc
index 5c966c8..e9587e9 100644
--- a/src/sync-intro-certificate.cc
+++ b/src/sync-intro-certificate.cc
@@ -113,7 +113,7 @@
   if(i >= certificateName.size())
     throw SecException("Wrong SyncIntroCertificate Name!");
 
-  m_keyName = certificateName.getSubName(keyNameStart, keyNameEnd);
+  m_keyName = certificateName.getSubName(keyNameStart, keyNameEnd - keyNameStart);
 
   string typeComponent = certificateName.get(certificateName.size() - 2).toUri();
   if(typeComponent == string("PRODUCER"))
diff --git a/src/sync-policy-manager.cc b/src/sync-policy-manager.cc
index d0ea7c8..a788b66 100644
--- a/src/sync-policy-manager.cc
+++ b/src/sync-policy-manager.cc
@@ -12,6 +12,7 @@
 
 #include "sync-intro-certificate.h"
 #include "sync-logging.h"
+#include <ndn.cxx/security/identity/identity-manager.h>
 
 using namespace ndn;
 using namespace ndn::security;
@@ -27,6 +28,7 @@
   , m_signingCertificateName(signingCertificateName.getPrefix(signingCertificateName.size()-1))
   , m_syncPrefix(syncPrefix)
   , m_stepLimit(stepLimit)
+  , m_identityManager(Ptr<security::IdentityManager>::Create())
 {
   Name wotPrefix = syncPrefix;
   wotPrefix.append("WOT");
@@ -263,9 +265,37 @@
 {
   Ptr<SyncIntroCertificate> introCertificate = Ptr<SyncIntroCertificate>(new SyncIntroCertificate(*introCertificateData));
   if(forIntroducer)
-    m_trustedIntroducers.insert(pair <Name, Publickey > (introCertificate->getPublicKeyName(), introCertificate->getPublicKeyInfo()));
+    {
+      m_trustedIntroducers.insert(pair <Name, Publickey > (introCertificate->getPublicKeyName(), introCertificate->getPublicKeyInfo()));
+      SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
+                                                introCertificate->getPublicKeyName(),
+                                                m_identityManager->getDefaultKeyNameForIdentity(m_signingIdentity),
+                                                introCertificate->getNotBefore(),
+                                                introCertificate->getNotAfter(),
+                                                introCertificate->getPublicKeyInfo(),
+                                                SyncIntroCertificate::INTRODUCER);
+                                                // : SyncIntroCertificate::PRODUCER)
+      ndn::Name certName = m_identityManager->getDefaultCertificateNameByIdentity(m_signingIdentity);
+      _LOG_DEBUG("Publish Intro Certificate on Verified: " << syncIntroCertificate.getName());
+      m_identityManager->signByCertificate(syncIntroCertificate, certName);
+      m_handler->putToNdnd(*syncIntroCertificate.encodeToWire());
+    }
   else
-    m_trustedProducers.insert(pair <Name, Publickey > (introCertificate->getPublicKeyName(), introCertificate->getPublicKeyInfo()));
+    {
+      m_trustedProducers.insert(pair <Name, Publickey > (introCertificate->getPublicKeyName(), introCertificate->getPublicKeyInfo()));
+      SyncIntroCertificate syncIntroCertificate(m_syncPrefix,
+                                                introCertificate->getPublicKeyName(),
+                                                m_identityManager->getDefaultKeyNameForIdentity(m_signingIdentity),
+                                                introCertificate->getNotBefore(),
+                                                introCertificate->getNotAfter(),
+                                                introCertificate->getPublicKeyInfo(),
+                                                SyncIntroCertificate::PRODUCER);
+      // : SyncIntroCertificate::PRODUCER)
+      ndn::Name certName = m_identityManager->getDefaultCertificateNameByIdentity(m_signingIdentity);
+      _LOG_DEBUG("Publish Intro Certificate on Verified: " << syncIntroCertificate.getName());
+      m_identityManager->signByCertificate(syncIntroCertificate, certName);
+      m_handler->putToNdnd(*syncIntroCertificate.encodeToWire());
+    }
 
   if(verifySignature(*originalData, introCertificate->getPublicKeyInfo()))      
     verifiedCallback(originalData);    
diff --git a/src/sync-policy-manager.h b/src/sync-policy-manager.h
index fac9b4a..ad4345a 100644
--- a/src/sync-policy-manager.h
+++ b/src/sync-policy-manager.h
@@ -118,6 +118,7 @@
   std::map<ndn::Name, ndn::security::Publickey> m_trustedProducers;
   std::map<ndn::Name, SpecificPolicyRule> m_chatDataRules;
 
+  ndn::Ptr<ndn::security::IdentityManager> m_identityManager;
   ndn::Ptr<ndn::Wrapper> m_handler;
 };