security: Fix certificate loop detection in v2::Validator

Change-Id: I0e55cd6ee9744df07fa13dcd8ee337909c49430f
diff --git a/src/security/v2/validator.cpp b/src/security/v2/validator.cpp
index 4928c67..6dc1f91 100644
--- a/src/security/v2/validator.cpp
+++ b/src/security/v2/validator.cpp
@@ -133,6 +133,12 @@
     return;
   }
 
+  if (state->hasSeenCertificateName(certRequest->m_interest.getName())) {
+    state->fail({ValidationError::Code::LOOP_DETECTED,
+                 "Validation loop detected for certificate `" + certRequest->m_interest.getName().toUri() + "`"});
+    return;
+  }
+
   NDN_LOG_DEBUG_DEPTH("Retrieving " << certRequest->m_interest.getName());
 
   auto cert = findTrustedCert(certRequest->m_interest);