示例#1
0
        public IEnumerable <X509Certificate2> GetCertificates()
        {
            Int32 enumStatus = 0;

            OpenEnumContext();

            while (enumStatus != (int)VMCAEnum.End)
            {
                IntPtr pCert = new IntPtr();

                UInt32 error = VMCAAdaptor.VMCAGetNextCertificate(_context, out pCert, out _currentIndex, out enumStatus);
                VMCAError.Check(error);

                if ((VMCAEnum)enumStatus != VMCAEnum.Success)
                {
                    yield break;
                }

                string certString = Marshal.PtrToStringAnsi(pCert);
                VMCAAdaptor.VMCAFreeCertificate(pCert);

                var cert = new X509Certificate2(ASCIIEncoding.ASCII.GetBytes(certString));
                yield return(cert);
            }
        }
示例#2
0
        public static bool Validate(string certificate)
        {
            UInt32 result = VMCAAdaptor.VMCAValidateCACertificate(certificate);

            VMCAError.Check(result);
            return(true);
        }
示例#3
0
 public void OpenEnumContext()
 {
     if (_context.ToInt64() == 0)
     {
         UInt32 error = VMCAAdaptor.VMCAOpenEnumContextHA(Client.ServerContext, Client.ServerName, (int)Filter, out _context);
         VMCAError.Check(error);
     }
 }
示例#4
0
        public static string GetCertificateAsString(X509Certificate2 cert)
        {
            var    certStringPtr = new IntPtr();
            UInt32 result        = VMCAAdaptor.VMCAGetCertificateAsString(cert.ExportToPem(), out certStringPtr);

            VMCAError.Check(result);

            var certString = Marshal.PtrToStringAnsi(certStringPtr);

            VMCAAdaptor.VMCAFreeString(certStringPtr);

            return(certString);
        }
示例#5
0
        public static KeyPairData Create(UInt32 length)
        {
            IntPtr pk  = new IntPtr();
            IntPtr pbk = new IntPtr();

            try {
                UInt32 result = VMCAAdaptor.VMCACreatePrivateKey(null, length, out pk, out pbk);
                VMCAError.Check(result);

                string pkString  = Marshal.PtrToStringAnsi(pk);
                string pbkString = Marshal.PtrToStringAnsi(pbk);
                return(new KeyPairData(pbkString, pkString));
            } finally {
                VMCAAdaptor.VMCAFreeString(pk);
                VMCAAdaptor.VMCAFreeString(pbk);
            }
        }
示例#6
0
        public void Revoke()
        {
            UInt32 result = VMCAAdaptor.VMCARevokeCertificate(_client.ServerName, _certificate);

            VMCAError.Check(result);
        }