From 9d5027739a072b12d0115e260b52c5db9859872d Mon Sep 17 00:00:00 2001 From: zen6 Date: Sat, 6 Dec 2025 23:22:45 +0100 Subject: [PATCH] fix(storage): fix MongoStore.ListCertificates to correctly iterate cursor and decode documents (CRL bug) --- internal/storage/mongo.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/internal/storage/mongo.go b/internal/storage/mongo.go index b4d8d8b..d116829 100644 --- a/internal/storage/mongo.go +++ b/internal/storage/mongo.go @@ -177,20 +177,7 @@ func (m *MongoStore) ListCertificates() []*pki.Certificate { } defer cursor.Close(ctx) - var certs []*pki.Certificate - if err = cursor.All(ctx, &certs); err != nil { - return []*pki.Certificate{} - } - - // Reconvertir les documents en certificats var results []*pki.Certificate - if err = cursor.All(ctx, &[]CertificateDoc{}); err != nil { - return []*pki.Certificate{} - } - - cursor, _ = m.collection.Find(ctx, bson.M{}) - defer cursor.Close(ctx) - for cursor.Next(ctx) { var doc CertificateDoc if err := cursor.Decode(&doc); err != nil { @@ -209,9 +196,10 @@ func (m *MongoStore) ListCertificates() []*pki.Certificate { // Décoder le certificat X.509 if doc.Cert != "" { - certBytes, _ := base64.StdEncoding.DecodeString(doc.Cert) - if parsedCert, _ := parseCertificate(certBytes); parsedCert != nil { - cert.Cert = parsedCert + if certBytes, err := base64.StdEncoding.DecodeString(doc.Cert); err == nil { + if parsedCert, err := parseCertificate(certBytes); err == nil && parsedCert != nil { + cert.Cert = parsedCert + } } }