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