* * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an “AS IS” BASIS, without * warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the * License for the specific language governing permissions and limitations * under the License. */
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); }