Exemplo n.º 1
0
        public bool DeleteCertificate(X509Certificate2 cert)
        {
            var result = VMCertStoreAdaptor.VmAfdDeleteCertificate(Client.ServerName,
                                                                   (UInt32)_hStore, cert.ExportToPem());

            VMCertStoreError.Check(result);
            return(true);
        }
Exemplo n.º 2
0
        public bool AddCertificate(string alias, X509Certificate2 certificate, string privateKey, bool autoRefresh)
        {
            UInt32 autoRefreshVal = (UInt32)(autoRefresh ? 1 : 0);
            var    result         = VMCertStoreAdaptor.VmAfdAddCertificate(Client.ServerName,
                                                                           (UInt32)CertType, alias, certificate.ExportToPem(), privateKey, autoRefreshVal);

            VMCertStoreError.Check(result);
            return(true);
        }
Exemplo n.º 3
0
        public IEnumerable <CertDTO> GetCertificates()
        {
            var lst    = new List <CertDTO> ();
            var result = VMCertStoreAdaptor.VmAfdOpenCertStore(Client.ServerName, (UInt32)CertType, out _hStore);

            VMCertStoreError.Check(result);

            var ptr = new IntPtr();

            UInt32 maxSize = 25, index = 0;

            while (true)
            {
                result = VMCertStoreAdaptor.VmAfdEnumCertificates(Client.ServerName, (UInt32)CertType, index, maxSize, out ptr);
                VMCertStoreError.Check(result);


                if (ptr != null)
                {
                    int sz        = Marshal.SizeOf(typeof(VMCertStoreAdaptor.VMAFD_CERT_CONTAINER));
                    var certArray = new VMCertStoreAdaptor.VMAFD_CERT_CONTAINER[100];

                    var first = (VMCertStoreAdaptor.VMAFD_CERT_ARRAY)Marshal.PtrToStructure(
                        ptr, typeof(VMCertStoreAdaptor.VMAFD_CERT_ARRAY));

                    for (UInt32 i = 0; i < first.dwCount; i++)
                    {
                        certArray [i] = (VMCertStoreAdaptor.VMAFD_CERT_CONTAINER)Marshal.PtrToStructure(
                            new IntPtr(first.certificates.ToInt64() + (sz * i)), typeof(VMCertStoreAdaptor.VMAFD_CERT_CONTAINER));
                        var certString  = Marshal.PtrToStringUni(certArray [i].pCert);
                        var aliasString = Marshal.PtrToStringUni(certArray [i].pAlias);

                        lst.Add(new CertDTO {
                            Alias = aliasString,
                            Cert  = certString.GetX509Certificate2FromString()
                        });
                    }
                    if (first.dwCount < maxSize)
                    {
                        break;
                    }
                    index += first.dwCount;
                }
            }

            return(lst);
        }
Exemplo n.º 4
0
        public void CloseStore()
        {
            var result = VMCertStoreAdaptor.VmAfdCloseCertStore(Client.ServerName, _hStore);

            VMCertStoreError.Check(result);
        }