Beispiel #1
0
        public void ToX509CertificateTest(Certificate target)
        {
            X509Certificate2 expected = new DisposableX509Certificate2(target.ToX509Certificate().GetRawCertData());
            X509Certificate2 actual   = target.ToX509Certificate();

            Assert.Equal(expected, actual);
        }
Beispiel #2
0
 public void ExcludePrivateKey()
 {
     if (this.HasData)
     {
         using (DisposableX509Certificate2 cert = this.ToX509CertificateNoKeys())
         {
             this.SetX509Certificate(cert, false);
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// loads and verifies the cert records from the files, ensuring that the types
        /// match up
        /// </summary>
        /// <typeparam name="T">Type of record that is expected</typeparam>
        /// <param name="path">path to the bin file to be loaded</param>
        /// <returns>bytes from the bin file</returns>
        protected Certificate LoadAndVerifyCertFromFile(string path)
        {
            byte[] bytes = null;

            //----------------------------------------------------------------------------------------------------
            //---read the stream from the bytes
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                //Console.WriteLine("checking [{0}]", path);
                bytes = new BinaryReader(fs).ReadBytes((int)new FileInfo(path).Length);

                using (DisposableX509Certificate2 x509 = new DisposableX509Certificate2(bytes))
                {
                    Certificate cert = new Certificate(x509.FriendlyName, x509, false);
                    return(cert);
                }
            }
        }
        void Print(Certificate cert)
        {
            if (cert == null)
            {
                WriteLine("No certificate found");
                return;
            }

            CommandUI.Print("Owner", cert.Owner);
            CommandUI.Print("Thumbprint", cert.Thumbprint);
            CommandUI.Print("ID", cert.ID);
            CommandUI.Print("CreateDate", cert.CreateDate);
            CommandUI.Print("ValidStart", cert.ValidStartDate);
            CommandUI.Print("ValidEnd", cert.ValidEndDate);
            CommandUI.Print("Status", cert.Status);

            if (cert.HasData)
            {
                using (DisposableX509Certificate2 x509 = cert.ToX509Certificate())
                {
                    Print(x509);
                }
            }
        }