security: Ensure that KeyChain::getDefaultCeritifcate() does not return 0

Change-Id: I46e4bf19d94bc4b5cf017d8305b81696e1b78ab6
Refs: #1740
diff --git a/src/security/key-chain.hpp b/src/security/key-chain.hpp
index 0a6c65c..bb04f5c 100644
--- a/src/security/key-chain.hpp
+++ b/src/security/key-chain.hpp
@@ -508,7 +508,10 @@
   shared_ptr<IdentityCertificate>
   getDefaultCertificate() const
   {
-    return m_pib->defaultCertificate();
+    if (!static_cast<bool>(m_pib->getDefaultCertificate()))
+      const_cast<KeyChain*>(this)->setDefaultCertificateInternal();
+
+    return m_pib->getDefaultCertificate();
   }
 
   void
@@ -731,10 +734,10 @@
 void
 KeyChain::sign(T& packet)
 {
-  if (!static_cast<bool>(m_pib->defaultCertificate()))
+  if (!static_cast<bool>(m_pib->getDefaultCertificate()))
     setDefaultCertificateInternal();
 
-  sign(packet, *m_pib->defaultCertificate());
+  sign(packet, *m_pib->getDefaultCertificate());
 }
 
 template<typename T>