Ejemplo n.º 1
0
        public string GetServerVersion()
        {
            var    serverVersionPtr = new IntPtr();
            UInt32 dwError          = VMCAAdaptor.VMCAGetServerVersionHA(
                _serverContext,
                ServerName, out serverVersionPtr);

            VMCAError.Check(dwError);
            string version = Marshal.PtrToStringAnsi(serverVersionPtr);

            VMCAAdaptor.VMCAFreeVersion(serverVersionPtr);
            return(version);
        }
Ejemplo n.º 2
0
 public void CloseServer()
 {
     try
     {
         if (_serverContext != IntPtr.Zero)
         {
             VMCAAdaptor.VMCACloseServer(_serverContext);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Ejemplo n.º 3
0
        public X509Certificate2 GetVMCASignedCertificate(VMCAAdaptor.VMCA_PKCS_10_REQ_DATA certRequest, string privateKey, DateTime notBefore, DateTime notAfter)
        {
            IntPtr pCert   = new IntPtr();
            long   nBefore = notBefore.ToTime_t();
            long   nAfter  = notAfter.ToTime_t();
            UInt32 dwError = VMCAAdaptor.VMCAGetSignedCertificateHA(_serverContext,
                                                                    ServerName, certRequest, privateKey, "", nBefore, nAfter, out pCert);

            VMCAError.Check(dwError);
            string certString = Marshal.PtrToStringAnsi(pCert);

            VMCAAdaptor.VMCAFreeCertificate(pCert);
            return(new X509Certificate2(ASCIIEncoding.ASCII.GetBytes(certString)));
        }
Ejemplo n.º 4
0
        public string GetCSR(string privateKey)
        {
            IntPtr pCSR = new IntPtr();

            var    requestData = GetRequestData();
            UInt32 result      = VMCAAdaptor.VMCACreateSigningRequest(requestData, privateKey, "", out pCSR);

            VMCAError.Check(result);

            string csr = Marshal.PtrToStringAnsi(pCSR);

            VMCAAdaptor.VMCAFreeCSR(pCSR);
            return(csr);
        }
Ejemplo n.º 5
0
        public X509Certificate2 GetRootCertificate()
        {
            IntPtr pCert = new IntPtr();

            UInt32 dwError = VMCAAdaptor.VMCAGetRootCACertificateHA(
                _serverContext,
                ServerName,
                out pCert);

            VMCAError.Check(dwError);

            string certString = Marshal.PtrToStringAnsi(pCert);

            VMCAAdaptor.VMCAFreeCertificate(pCert);

            return(new X509Certificate2(ASCIIEncoding.ASCII.GetBytes(certString)));
        }
Ejemplo n.º 6
0
        public VMCACertificate GetSelfSignedCertificate(string privateKey, DateTime notBefore, DateTime notAfter)
        {
            IntPtr pCert = new IntPtr();

            var    requestData = GetRequestData();
            long   nBefore     = notBefore.ToTime_t();
            long   nAfter      = notAfter.ToTime_t();
            UInt32 result      = VMCAAdaptor.VMCACreateSelfSignedCertificate(requestData, privateKey, "", nBefore, nAfter, out pCert);

            VMCAError.Check(result);

            string cert = Marshal.PtrToStringAnsi(pCert);

            VMCAAdaptor.VMCAFreeCertificate(pCert);

            return(new VMCACertificate(Client, cert));
        }
Ejemplo n.º 7
0
 void EnsureServerContext()
 {
     try {
         if (_serverContext != IntPtr.Zero)
         {
             return;
         }
         UInt32 result = VMCAAdaptor.VMCAOpenServerA(
             ServerName,
             UserName,
             DomainName,
             Password,
             0,
             IntPtr.Zero,
             out _serverContext);
         VMCAError.Check(result);
     } catch (Exception) {
         UserName = "";
         Password = "";
         throw;
     }
 }
Ejemplo n.º 8
0
        public void AddRootCertificate(string rootCert, string passPhrase, string privateKey)
        {
            UInt32 dwError = VMCAAdaptor.VMCAAddRootCertificate(ServerName, rootCert, passPhrase, privateKey);

            VMCAError.Check(dwError);
        }