Esempio n. 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);
            }
        }
Esempio n. 2
0
        public static bool Validate(string certificate)
        {
            UInt32 result = VMCAAdaptor.VMCAValidateCACertificate(certificate);

            VMCAError.Check(result);
            return(true);
        }
Esempio n. 3
0
 public void OpenEnumContext()
 {
     if (_context.ToInt64() == 0)
     {
         UInt32 error = VMCAAdaptor.VMCAOpenEnumContextHA(Client.ServerContext, Client.ServerName, (int)Filter, out _context);
         VMCAError.Check(error);
     }
 }
Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 6
0
        public void Revoke()
        {
            UInt32 result = VMCAAdaptor.VMCARevokeCertificate(_client.ServerName, _certificate);

            VMCAError.Check(result);
        }