src: do not crash if identity cannot be created
This is useful during testing with dummy keychain to save overhead
Change-Id: I73eee512aba9afc3d768270e0e5b4212c7adf058
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 9a62a24..cbd981e 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -292,11 +292,20 @@
try {
m_keyChain.deleteIdentity(m_keyChain.getPib().getIdentity(nlsrInstanceName));
- } catch (const std::exception& e) {
+ }
+ catch (const std::exception& e) {
NLSR_LOG_WARN(e.what());
}
- auto nlsrInstanceIdentity = m_keyChain.createIdentity(nlsrInstanceName);
+ ndn::security::Identity nlsrInstanceIdentity;
+ try {
+ nlsrInstanceIdentity = m_keyChain.createIdentity(nlsrInstanceName);
+ }
+ catch (const std::exception& e) {
+ NLSR_LOG_ERROR("Unable to create identity, NLSR will run without security!");
+ NLSR_LOG_DEBUG("Can be ignored if running in non-production environments.");
+ return;
+ }
auto nlsrInstanceKey = nlsrInstanceIdentity.getDefaultKey();
ndn::security::v2::Certificate certificate;