add certificate manager
authorYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Fri, 2 Jun 2023 08:20:18 +0000 (10:20 +0200)
committerYurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics <y.zinchuk@samsung.com>
Wed, 12 Jul 2023 07:37:46 +0000 (09:37 +0200)
SettingMainGadget/SettingMainGadget/About/SettingCertificateManager.cs [new file with mode: 0644]

diff --git a/SettingMainGadget/SettingMainGadget/About/SettingCertificateManager.cs b/SettingMainGadget/SettingMainGadget/About/SettingCertificateManager.cs
new file mode 100644 (file)
index 0000000..1760517
--- /dev/null
@@ -0,0 +1,38 @@
+using SettingCore;
+using System;
+using System.Collections.Generic;
+using static Interop;
+using static Interop.CertSvc;
+
+namespace SettingMainGadget.About
+{
+    class SettingCertificateManager
+    {
+        public static certificateMetadata CertificateMetadata { get; set; }
+
+        public static List<certificateMetadata> GetRootCertList()
+        {
+            int result = CertSvc.InstanceNew(out IntPtr instance);
+            if ((CertSvc.ErrorCode)result != CertSvc.ErrorCode.CERTSVC_SUCCESS)
+            {
+                Logger.Warn($"Unable to create cert instance, result: {result}");
+                return new List<certificateMetadata>();
+            }
+
+            result = CertSvc.GetPKCS12CertificateListFromStore(instance, CertSvc.CertStoreType.ALL_STORE, 0, out IntPtr storeCertList, out int length);
+            if ((CertSvc.ErrorCode)result != CertSvc.ErrorCode.CERTSVC_SUCCESS)
+            {
+                Logger.Warn($"Unable to get root certificates, result: {result}");
+                result = CertSvc.FreePKCS12CertificateListFromStore(instance, out storeCertList);
+                if ((CertSvc.ErrorCode)result != CertSvc.ErrorCode.CERTSVC_SUCCESS)
+                {
+                    Logger.Warn($"Unable to free certlist, result: {result}");
+                }
+                CertSvc.InstanceFree(instance);
+                return new List<certificateMetadata>();
+            }
+
+            return CertSvc.GetCertLists(instance, storeCertList, length);
+        }
+    }
+}