From: Yurii Zinchuk/Tizen Services & IoT (PLT) /SRPOL/Engineer/Samsung Electronics Date: Fri, 2 Jun 2023 08:20:18 +0000 (+0200) Subject: add certificate manager X-Git-Tag: accepted/tizen/unified/20230829.181410~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7e2c69b22fea1350cce8610ddf07792590d17d6b;p=profile%2Fiot%2Fapps%2Fdotnet%2Fsettings.git add certificate manager --- diff --git a/SettingMainGadget/SettingMainGadget/About/SettingCertificateManager.cs b/SettingMainGadget/SettingMainGadget/About/SettingCertificateManager.cs new file mode 100644 index 0000000..1760517 --- /dev/null +++ b/SettingMainGadget/SettingMainGadget/About/SettingCertificateManager.cs @@ -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 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(); + } + + 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(); + } + + return CertSvc.GetCertLists(instance, storeCertList, length); + } + } +}