using SignLib;
using SignLib.Certificates;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
 

using System.Security.Cryptography.X509Certificates;


namespace SignLibTest
{

    class Program
    {

        //static X509Certificate2 GetSampleCertificateToVerify()
        //{
        //    try
        //    {
        //        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.microsoft.com");
        //        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        //        response.Close();

        //        return new X509Certificate2(request.ServicePoint.Certificate.GetRawCertData());

        //    }
        //    catch
        //    {
        //        throw;
        //    }

        //}

        static void VerifyCertificate()
        {

            //check if the certificate is time valid
            //Verify a certificate
            X509Certificate2 certificate = new X509Certificate2("demo_certificate.cer");

            Console.WriteLine("Verify against the local time: " + DigitalCertificate.VerifyDigitalCertificate(certificate, VerificationType.LocalTime));
            Console.WriteLine("Verify against the CRL: " + DigitalCertificate.VerifyDigitalCertificate(certificate, VerificationType.CRL));
            Console.WriteLine("Verify against the OCSP: " + DigitalCertificate.VerifyDigitalCertificate(certificate, VerificationType.OCSP));

            //CertificateStatus.Expired - the certificate is expired
            //CertificateStatus.Revoked - the certificate is revoked 
            //CertificateStatus.Unknown - the CRL or the OCSP service is unavailable
            //CertificateStatus.Valid - the certificate is OK


            Console.WriteLine("Done certificate validation.");

        }

        static void Main(string[] args)
        {
            try
            {
                VerifyCertificate();

                Console.WriteLine("All done!");
            }
            catch (Exception ex)
            {
                Console.Write("General exception: " + ex.Message);
            }

        }
    }
}


