From dd7c1e1ca13a214e9adb614f8972f66274120aa0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Blin?=
 <sebastien.blin@savoirfairelinux.com>
Date: Fri, 30 Jul 2021 10:19:30 -0400
Subject: [PATCH] certstore: only check first id to avoid removing certificates

Change-Id: Icc2baab0a6a52cbfee9b975187294c70477b5de0
GitLab: #579
---
 src/security/certstore.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/security/certstore.cpp b/src/security/certstore.cpp
index 17e7eb3e80..c2ff3563d9 100644
--- a/src/security/certstore.cpp
+++ b/src/security/certstore.cpp
@@ -68,11 +68,13 @@ CertificateStore::loadLocalCertificates()
         try {
             auto crt = std::make_shared<crypto::Certificate>(
                 fileutils::loadFile(certPath_ + DIR_SEPARATOR_CH + f));
+            auto id = crt->getId().toString();
+            auto longId = crt->getLongId().toString();
+            if (id != f && longId != f)
+                throw std::logic_error("Certificate id mismatch");
             while (crt) {
-                auto id = crt->getId().toString();
-                auto longId = crt->getLongId().toString();
-                if (id != f && longId != f)
-                    throw std::logic_error("Certificate id mismatch");
+                id = crt->getId().toString();
+                longId = crt->getLongId().toString();
                 certs_.emplace(std::move(id), crt);
                 certs_.emplace(std::move(longId), crt);
                 loadRevocations(*crt);
-- 
GitLab