From f24dea11433fbd085a91a5449bd390775042a9c0 Mon Sep 17 00:00:00 2001 From: aromaa Date: Thu, 21 Jul 2022 16:36:03 +0300 Subject: [PATCH] Add GetDevicePublicKey --- .../Properties/AssemblyInfo.cs | 2 +- .../Security/CertificateManager.cs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/nanoFramework.System.Net/Properties/AssemblyInfo.cs b/nanoFramework.System.Net/Properties/AssemblyInfo.cs index 3642cc8..2202180 100644 --- a/nanoFramework.System.Net/Properties/AssemblyInfo.cs +++ b/nanoFramework.System.Net/Properties/AssemblyInfo.cs @@ -11,7 +11,7 @@ //////////////////////////////////////////////////////////////// // update this whenever the native assembly signature changes // -[assembly: AssemblyNativeVersion("100.1.5.0")] +[assembly: AssemblyNativeVersion("100.1.5.1")] //////////////////////////////////////////////////////////////// // Setting ComVisible to false makes the types in this assembly not visible diff --git a/nanoFramework.System.Net/Security/CertificateManager.cs b/nanoFramework.System.Net/Security/CertificateManager.cs index c82707f..d86b255 100644 --- a/nanoFramework.System.Net/Security/CertificateManager.cs +++ b/nanoFramework.System.Net/Security/CertificateManager.cs @@ -74,5 +74,27 @@ public static bool AddCaCertificateBundle(string ca) /// [MethodImpl(MethodImplOptions.InternalCall)] public static extern bool AddCaCertificateBundle(byte[] ca); + + /// + /// Loads the device public key from the device certificate store. + /// If public key was found, initializes a new instance of the . + /// + /// The certificate that was loaded from the certificate store. + /// + /// This method is exclusive of nanoFramework. There is no equivalent in .NET framework. + /// + public static X509Certificate GetDevicePublicKey() + { + byte[] certificate = GetDevicePublicKeyRaw(); + if (certificate is not null) + { + return new X509Certificate(certificate); + } + + return null; + } + + [MethodImpl(MethodImplOptions.InternalCall)] + private static extern byte[] GetDevicePublicKeyRaw(); } }