Esempio n. 1
0
        public void BouncyCertFromCoreFxCert()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

#if NETCOREAPP
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                logger.LogDebug("Test skipped for netcoreapp and macOS as not able to load certificates from a .pfx file pre .NET Core 5.0.");
                return;
            }
#endif

            var coreFxCert = new X509Certificate2("certs/localhost.pfx", string.Empty, X509KeyStorageFlags.Exportable);
            Assert.NotNull(coreFxCert);
            Assert.NotNull(coreFxCert.PrivateKey);

            string coreFxFingerprint = DtlsUtils.Fingerprint(coreFxCert).ToString();
            logger.LogDebug($"Core FX certificate fingerprint {coreFxFingerprint}.");

            var bcCert = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate(coreFxCert);
            Assert.NotNull(bcCert);

            var bcKey = Org.BouncyCastle.Security.DotNetUtilities.GetKeyPair(coreFxCert.PrivateKey).Private;
            Assert.NotNull(bcKey);

            string bcFingerprint = DtlsUtils.Fingerprint(bcCert).ToString();
            logger.LogDebug($"BouncyCastle certificate fingerprint {bcFingerprint}.");

            Assert.Equal(coreFxFingerprint, bcFingerprint);
        }
Esempio n. 2
0
        public void GetCertifcateFingerprintUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            (var tlsCert, var pvtKey) = DtlsUtils.CreateSelfSignedTlsCert();
            Assert.NotNull(tlsCert);

            var fingerprint = DtlsUtils.Fingerprint(tlsCert);

            logger.LogDebug($"Fingerprint {fingerprint}.");

            Assert.NotNull(fingerprint.algorithm);
            Assert.NotNull(fingerprint.value);
        }