731 references to CAPI
System (731)
security\system\security\cryptography\asnencodeddata.cs (7)
24internal AsnEncodedData (string oid, CAPI.CRYPTOAPI_BLOB encodedBlob) : this(oid, CAPI.BlobToByteArray(encodedBlob)) {} 25internal AsnEncodedData (Oid oid, CAPI.CRYPTOAPI_BLOB encodedBlob) : this(oid, CAPI.BlobToByteArray(encodedBlob)) {} 87return CAPI.CryptFormatObject(CAPI.X509_ASN_ENCODING, 88multiLine ? CAPI.CRYPT_FORMAT_STR_MULTI_LINE : 0,
security\system\security\cryptography\cryptoapi.cs (40)
2766CAPI.CRYPTOAPI_BLOB blob = (CAPI.CRYPTOAPI_BLOB) Marshal.PtrToStructure(pBlob, typeof(CAPI.CRYPTOAPI_BLOB)); 2776byte[] BlobToByteArray(CAPI.CRYPTOAPI_BLOB blob) { 2807ptr = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbDecoded)); 2850pbDecoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbDecoded)); 2885pbEncoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbEncoded)); 2922pbEncoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbEncoded)); 2954if (dwDisplayType == CAPI.CERT_NAME_ATTR_TYPE) 2955pszCommonName = X509Utils.StringToAnsiPtr(CAPI.szOID_COMMON_NAME); 2962(dwDisplayType == CAPI.CERT_NAME_ATTR_TYPE ? pszCommonName.DangerousGetHandle() : new IntPtr(&dwStrType)), 2968ptr = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(2 * cchCount)); 2972(dwDisplayType == CAPI.CERT_NAME_ATTR_TYPE ? pszCommonName.DangerousGetHandle() : new IntPtr(&dwStrType)), 3012parameters.Flags = (CspProviderFlags) ((dwFlags & CAPI.CRYPT_MACHINE_KEYSET) == CAPI.CRYPT_MACHINE_KEYSET ? CspProviderFlags.UseMachineKeyStore : 0); 3029if (!rc && Marshal.GetLastWin32Error() == CAPI.NTE_BAD_KEYSET) { 3034dwFlags | CAPI.CRYPT_NEWKEYSET); 3087pOIDInfo = (CRYPT_OID_INFO) Marshal.PtrToStructure(pv, typeof(CAPI.CRYPT_OID_INFO)); 3112pOIDInfo = (CRYPT_OID_INFO) Marshal.PtrToStructure(pv, typeof(CAPI.CRYPT_OID_INFO)); 3149pbFormat = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbFormat)); 3199pbFormat = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbFormat)); 3665IntPtr pEnumContext = CAPI.CertEnumCertificatesInStore(safeCertStoreHandle, IntPtr.Zero); 3667CAPI.CRYPTOAPI_BLOB blob = new CAPI.CRYPTOAPI_BLOB(); 3668if (!CAPI.CertSetCertificateContextProperty(pEnumContext, 3673pEnumContext = CAPI.CertEnumCertificatesInStore(safeCertStoreHandle, pEnumContext); 3926[DllImport(CAPI.KERNEL32, SetLastError = true), 3962[DllImport(CAPI.KERNEL32, SetLastError=true), 3996[DllImport(CAPI.ADVAPI32, SetLastError=true), 4030[DllImport(CAPI.CRYPT32, SetLastError=true), 4067[DllImport(CAPI.CRYPT32, SetLastError=true), 4100[DllImport(CAPI.CRYPT32, SetLastError=true), 4143[DllImport(CAPI.CRYPT32, SetLastError=true),
security\system\security\cryptography\oid.cs (6)
48string oidValue = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_NAME_KEY, oid, group); 88string oidValue = X509Utils.FindOidInfo(CAPI.CRYPT_OID_INFO_NAME_KEY, friendlyName, group); 101string friendlyName = X509Utils.FindOidInfo(CAPI.CRYPT_OID_INFO_OID_KEY, oidValue, group); 117m_friendlyName = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_OID_KEY, m_value, m_group); 126string oidValue = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_NAME_KEY, m_friendlyName, m_group); 155string oidValue = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_NAME_KEY, oid, OidGroup.All);
security\system\security\cryptography\x509\x500Name.cs (33)
41internal X500DistinguishedName (CAPI.CRYPTOAPI_BLOB encodedDistinguishedNameBlob) : base (new Oid(), encodedDistinguishedNameBlob) {} 77uint dwStrType = CAPI.CERT_X500_NAME_STR | MapNameToStrFlag(flag); 81CAPI.CRYPTOAPI_BLOB nameBlob; 86uint cchDecoded = CAPI.CertNameToStrW(CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 92throw new CryptographicException(CAPI.CERT_E_INVALID_NAME); 94using (SafeLocalAllocHandle pwszDecodeName = CAPI.LocalAlloc(CAPI.LPTR, new IntPtr(2 * cchDecoded))) { 95if (CAPI.CertNameToStrW(CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 100throw new CryptographicException(CAPI.CERT_E_INVALID_NAME); 120return CAPI.CryptFormatObject(CAPI.X509_ASN_ENCODING, 121multiLine ? CAPI.CRYPT_FORMAT_STR_MULTI_LINE : 0, 122new IntPtr(CAPI.X509_NAME), 138uint dwStrType = CAPI.CERT_X500_NAME_STR | MapNameToStrFlag(flag); 140if (!CAPI.CertStrToNameW(CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 151if (!CAPI.CertStrToNameW(CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 174dwStrType |= CAPI.CERT_NAME_STR_REVERSE_FLAG; 177dwStrType |= CAPI.CERT_NAME_STR_SEMICOLON_FLAG; 179dwStrType |= CAPI.CERT_NAME_STR_COMMA_FLAG; 181dwStrType |= CAPI.CERT_NAME_STR_CRLF_FLAG; 184dwStrType |= CAPI.CERT_NAME_STR_NO_PLUS_FLAG; 186dwStrType |= CAPI.CERT_NAME_STR_NO_QUOTING_FLAG; 189dwStrType |= CAPI.CERT_NAME_STR_FORCE_UTF8_DIR_STR_FLAG; 192dwStrType |= CAPI.CERT_NAME_STR_ENABLE_UTF8_UNICODE_FLAG; 194dwStrType |= CAPI.CERT_NAME_STR_ENABLE_T61_UNICODE_FLAG;
security\system\security\cryptography\x509\x509certificate2.cs (178)
95case CAPI.CALG_RSA_KEYX: 96case CAPI.CALG_RSA_SIGN: 103case CAPI.CALG_DSS_SIGN: 142case CAPI.CALG_DSS_SIGN: 143pszStructType = new IntPtr(CAPI.X509_DSS_PUBLICKEY); 146case CAPI.CALG_RSA_SIGN: 147case CAPI.CALG_RSA_KEYX: 148pszStructType = new IntPtr(CAPI.RSA_CSP_PUBLICKEYBLOB); 151case CAPI.CALG_DH_SF: 152case CAPI.CALG_DH_EPHEM: 164bool result = CAPI.DecodeObject(pszStructType, 171if ((uint) pszStructType == CAPI.RSA_CSP_PUBLICKEYBLOB) { 174} else if ((uint) pszStructType == CAPI.X509_DSS_PUBLICKEY) { 178result = CAPI.DecodeObject(new IntPtr(CAPI.X509_DSS_PARAMETERS), 206CAPI.CRYPTOAPI_BLOB pDssPubKey = (CAPI.CRYPTOAPI_BLOB) Marshal.PtrToStructure(decodedKeyValue.DangerousGetHandle(), typeof(CAPI.CRYPTOAPI_BLOB)); 207CAPI.CERT_DSS_PARAMETERS pDssParameters = (CAPI.CERT_DSS_PARAMETERS) Marshal.PtrToStructure(decodedParameters.DangerousGetHandle(), typeof(CAPI.CERT_DSS_PARAMETERS)); 211throw new CryptographicException(CAPI.NTE_BAD_PUBLIC_KEY); 221bw.Write(CAPI.PUBLICKEYBLOB); // pPubKeyStruc->bType = PUBLICKEYBLOB 222bw.Write(CAPI.CUR_BLOB_VERSION); // pPubKeyStruc->bVersion = CUR_BLOB_VERSION 224bw.Write(CAPI.CALG_DSS_SIGN); // pPubKeyStruc->aiKeyAlg = CALG_DSS_SIGN; 227bw.Write(CAPI.DSS_MAGIC); // pCspPubKey->magic = DSS_MAGIC; We are constructing a DSS1 Csp blob. 238throw new CryptographicException(CAPI.NTE_BAD_PUBLIC_KEY); 249throw new CryptographicException(CAPI.NTE_BAD_PUBLIC_KEY); 260throw new CryptographicException(CAPI.NTE_BAD_PUBLIC_KEY); 320m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 327m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 332m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 340m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 345m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 357m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 368m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 375m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 387m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 394m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 405m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 412m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 419m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 606return CAPI.CertGetCertificateContextProperty(m_safeCertContext, 607CAPI.CERT_ARCHIVED_PROP_ID, 617ptr = CAPI.LocalAlloc(CAPI.LPTR, new IntPtr(Marshal.SizeOf(typeof(CAPI.CRYPTOAPI_BLOB)))); 619if (!CAPI.CertSetCertificateContextProperty(m_safeCertContext, 620CAPI.CERT_ARCHIVED_PROP_ID, 653if (!CAPI.CertGetCertificateContextProperty(m_safeCertContext, 654CAPI.CERT_FRIENDLY_NAME_PROP_ID, 659ptr = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbData)); 660if (!CAPI.CertGetCertificateContextProperty(m_safeCertContext, 661CAPI.CERT_FRIENDLY_NAME_PROP_ID, 694CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) m_safeCertContext.DangerousGetHandle()); 695CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 714CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) m_safeCertContext.DangerousGetHandle()); 715CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 735CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) m_safeCertContext.DangerousGetHandle()); 736CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 759hasPrivateKey = CAPI.CertGetCertificateContextProperty(m_safeCertContext, 760CAPI.CERT_KEY_CONTEXT_PROP_ID, 765hasPrivateKey = CAPI.CertGetCertificateContextProperty(m_safeCertContext, 766CAPI.CERT_KEY_PROV_INFO_PROP_ID, 792case CAPI.CALG_RSA_KEYX: 793case CAPI.CALG_RSA_SIGN: 798case CAPI.CALG_DSS_SIGN: 903CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) m_safeCertContext.DangerousGetHandle()); 904CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 953uint issuerFlag = forIssuer ? CAPI.CERT_NAME_ISSUER_FLAG : 0; 957case CAPI.CERT_NAME_SIMPLE_DISPLAY_TYPE: 958return CAPI.GetCertNameInfo(m_safeCertContext, issuerFlag, type); 960case CAPI.CERT_NAME_EMAIL_TYPE: 961return CAPI.GetCertNameInfo(m_safeCertContext, issuerFlag, type); 966CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) m_safeCertContext.DangerousGetHandle()); 967CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 970pAltName[0] = CAPI.CertFindExtension(forIssuer ? CAPI.szOID_ISSUER_ALT_NAME : CAPI.szOID_SUBJECT_ALT_NAME, 973pAltName[1] = CAPI.CertFindExtension(forIssuer ? CAPI.szOID_ISSUER_ALT_NAME2 : CAPI.szOID_SUBJECT_ALT_NAME2, 978CAPI.CERT_EXTENSION extension = (CAPI.CERT_EXTENSION) Marshal.PtrToStructure(pAltName[i], typeof(CAPI.CERT_EXTENSION)); 986bool result = CAPI.DecodeObject(ptr.DangerousGetHandle(), 992CAPI.CERT_ALT_NAME_INFO altNameInfo = (CAPI.CERT_ALT_NAME_INFO) Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CERT_ALT_NAME_INFO)); 995IntPtr pAltInfoPtr = new IntPtr((long) altNameInfo.rgAltEntry + index * Marshal.SizeOf(typeof(CAPI.CERT_ALT_NAME_ENTRY))); 996CAPI.CERT_ALT_NAME_ENTRY altNameEntry = (CAPI.CERT_ALT_NAME_ENTRY) Marshal.PtrToStructure(pAltInfoPtr, typeof(CAPI.CERT_ALT_NAME_ENTRY)); 999case CAPI.CERT_NAME_UPN_TYPE: 1000if (altNameEntry.dwAltNameChoice == CAPI.CERT_ALT_NAME_OTHER_NAME) { 1001CAPI.CERT_OTHER_NAME otherName = (CAPI.CERT_OTHER_NAME) Marshal.PtrToStructure(altNameEntry.Value.pOtherName, typeof(CAPI.CERT_OTHER_NAME)); 1002if (otherName.pszObjId == CAPI.szOID_NT_PRINCIPAL_NAME) { 1005result = CAPI.DecodeObject(new IntPtr(CAPI.X509_UNICODE_ANY_STRING), 1010CAPI.CERT_NAME_VALUE nameValue = (CAPI.CERT_NAME_VALUE) Marshal.PtrToStructure(pUpnName.DangerousGetHandle(), typeof(CAPI.CERT_NAME_VALUE)); 1019case CAPI.CERT_NAME_DNS_TYPE: 1020if (altNameEntry.dwAltNameChoice == CAPI.CERT_ALT_NAME_DNS_NAME) 1025case CAPI.CERT_NAME_URL_TYPE: 1026if (altNameEntry.dwAltNameChoice == CAPI.CERT_ALT_NAME_URL) 1043name = CAPI.GetCertNameInfo(m_safeCertContext, issuerFlag, CAPI.CERT_NAME_ATTR_TYPE); 1056m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 1065m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 1074m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 1085m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 1096m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 1107m_safeCertContext = CAPI.CertDuplicateCertificateContext(this.Handle); 1144new IntPtr(CAPI.CERT_CHAIN_POLICY_BASE), 1146return (hr == CAPI.S_OK); 1196if (!CAPI.CertGetCertificateContextProperty(safeCertContext, 1197CAPI.CERT_KEY_PROV_INFO_PROP_ID, 1201if (dwErrorCode == CAPI.CRYPT_E_NOT_FOUND) 1207ptr = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbData)); 1208if (!CAPI.CertGetCertificateContextProperty(safeCertContext, 1209CAPI.CERT_KEY_PROV_INFO_PROP_ID, 1213if (dwErrorCode == CAPI.CRYPT_E_NOT_FOUND) 1219CAPI.CRYPT_KEY_PROV_INFO pKeyProvInfo = (CAPI.CRYPT_KEY_PROV_INFO) Marshal.PtrToStructure(ptr.DangerousGetHandle(), typeof(CAPI.CRYPT_KEY_PROV_INFO)); 1224parameters.Flags = (CspProviderFlags) ((pKeyProvInfo.dwFlags & CAPI.CRYPT_MACHINE_KEYSET) == CAPI.CRYPT_MACHINE_KEYSET ? CspProviderFlags.UseMachineKeyStore : 0); 1304CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 1305CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 1313CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 1314CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 1327if (!CAPI.CryptQueryObject(CAPI.CERT_QUERY_OBJECT_BLOB, 1329CAPI.CERT_QUERY_CONTENT_FLAG_ALL, 1330CAPI.CERT_QUERY_FORMAT_FLAG_ALL, 1352if (!CAPI.CryptQueryObject(CAPI.CERT_QUERY_OBJECT_FILE, 1354CAPI.CERT_QUERY_CONTENT_FLAG_ALL, 1355CAPI.CERT_QUERY_FORMAT_FLAG_ALL, 1374CAPI.CRYPTOAPI_BLOB DataBlob = new CAPI.CRYPTOAPI_BLOB(); 1378if (!CAPI.CertSetCertificateContextProperty(safeCertContextHandle, 1379CAPI.CERT_FRIENDLY_NAME_PROP_ID, 1392CAPI.CRYPT_KEY_PROV_INFO keyProvInfo = new CAPI.CRYPT_KEY_PROV_INFO(); 1396keyProvInfo.dwFlags = asymmetricAlgorithm.CspKeyContainerInfo.MachineKeyStore ? CAPI.CRYPT_MACHINE_KEYSET : 0; 1401ptr = CAPI.LocalAlloc(CAPI.LPTR, new IntPtr(Marshal.SizeOf(typeof(CAPI.CRYPT_KEY_PROV_INFO)))); 1406if (!CAPI.CertSetCertificateContextProperty(safeCertContextHandle, 1407CAPI.CERT_KEY_PROV_INFO_PROP_ID, 1413Marshal.DestroyStructure(ptr.DangerousGetHandle(), typeof(CAPI.CRYPT_KEY_PROV_INFO));
security\system\security\cryptography\x509\x509certificate2collection.cs (223)
299uint dwSaveAs = CAPI.CERT_STORE_SAVE_AS_PKCS7; 301CAPI.CRYPTOAPI_BLOB DataBlob = new CAPI.CRYPTOAPI_BLOB(); 306safeCertContextHandle = CAPI.CertEnumCertificatesInStore(safeCertStoreHandle, safeCertContextHandle); 308CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 315safeCertContextHandle = CAPI.CertEnumCertificatesInStore(safeCertStoreHandle, safeCertContextHandle); 318if (!CAPI.CertSerializeCertificateStoreElement(safeCertContextHandle, 323pbEncoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbEncoded)); 324if (!CAPI.CertSerializeCertificateStoreElement(safeCertContextHandle, 336if (!CAPI.PFXExportCertStore(safeCertStoreHandle, 339CAPI.EXPORT_PRIVATE_KEYS | CAPI.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY)) 342pbEncoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(DataBlob.cbData)); 344if (!CAPI.PFXExportCertStore(safeCertStoreHandle, 347CAPI.EXPORT_PRIVATE_KEYS | CAPI.REPORT_NOT_ABLE_TO_EXPORT_PRIVATE_KEY)) 358dwSaveAs = CAPI.CERT_STORE_SAVE_AS_STORE; 361if (!CAPI.CertSaveStore(safeCertStoreHandle, 362CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 364CAPI.CERT_STORE_SAVE_TO_MEMORY, 369pbEncoded = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(DataBlob.cbData)); 372if (!CAPI.CertSaveStore(safeCertStoreHandle, 373CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 375CAPI.CERT_STORE_SAVE_TO_MEMORY, 410uint dwFindType = CAPI.CERT_FIND_ANY; 413CAPI.CRYPTOAPI_BLOB HashBlob = new CAPI.CRYPTOAPI_BLOB(); 426dwFindType = CAPI.CERT_FIND_HASH; 434dwFindType = CAPI.CERT_FIND_SUBJECT_STR; 451dwFindType = CAPI.CERT_FIND_ISSUER_STR; 511oidValue = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_NAME_KEY, (string) findValue, OidGroup.Policy); 524oidValue = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_NAME_KEY, (string)findValue, OidGroup.Policy); 537oidValue = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_NAME_KEY, (string)findValue, OidGroup.ExtensionOrAttribute); 549CAPI.KEY_USAGE_STRUCT[] KeyUsages = new CAPI.KEY_USAGE_STRUCT[] { 550new CAPI.KEY_USAGE_STRUCT("DigitalSignature", CAPI.CERT_DIGITAL_SIGNATURE_KEY_USAGE), 551new CAPI.KEY_USAGE_STRUCT("NonRepudiation", CAPI.CERT_NON_REPUDIATION_KEY_USAGE), 552new CAPI.KEY_USAGE_STRUCT("KeyEncipherment", CAPI.CERT_KEY_ENCIPHERMENT_KEY_USAGE), 553new CAPI.KEY_USAGE_STRUCT("DataEncipherment", CAPI.CERT_DATA_ENCIPHERMENT_KEY_USAGE), 554new CAPI.KEY_USAGE_STRUCT("KeyAgreement", CAPI.CERT_KEY_AGREEMENT_KEY_USAGE), 555new CAPI.KEY_USAGE_STRUCT("KeyCertSign", CAPI.CERT_KEY_CERT_SIGN_KEY_USAGE), 556new CAPI.KEY_USAGE_STRUCT("CrlSign", CAPI.CERT_CRL_SIGN_KEY_USAGE), 557new CAPI.KEY_USAGE_STRUCT("EncipherOnly", CAPI.CERT_ENCIPHER_ONLY_KEY_USAGE), 558new CAPI.KEY_USAGE_STRUCT("DecipherOnly", CAPI.CERT_DECIPHER_ONLY_KEY_USAGE) 592SafeCertStoreHandle safeTargetStoreHandle = CAPI.CertOpenStore(new IntPtr(CAPI.CERT_STORE_PROV_MEMORY), 593CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 595CAPI.CERT_STORE_ENUM_ARCHIVED_FLAG | CAPI.CERT_STORE_CREATE_NEW_FLAG, 628int hr = CAPI.S_OK; 631pEnumContext = CAPI.CertFindCertificateInStore(safeSourceStoreHandle, 632CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 641if (hr == CAPI.S_FALSE) { 645if (hr == CAPI.S_FALSE) // skip this certificate 649if (hr != CAPI.S_OK) 662new IntPtr(CAPI.CERT_CHAIN_POLICY_BASE), 664if (hr == CAPI.S_FALSE) // skip this certificate 667if (hr != CAPI.S_OK) 676if (!CAPI.CertAddCertificateLinkToStore(safeTargetStoreHandle, 678CAPI.CERT_STORE_ADD_ALWAYS, 689pEnumContext = CAPI.CertFindCertificateInStore(safeSourceStoreHandle, 690CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 700if (hr != CAPI.S_FALSE && hr != CAPI.S_OK) 712string rdn = CAPI.GetCertNameInfo(safeCertContextHandle, 0, CAPI.CERT_NAME_RDN_TYPE); 714return CAPI.S_FALSE; 715return CAPI.S_OK; 726string rdn = CAPI.GetCertNameInfo(safeCertContextHandle, CAPI.CERT_NAME_ISSUER_FLAG, CAPI.CERT_NAME_RDN_TYPE); 728return CAPI.S_FALSE; 729return CAPI.S_OK; 741CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 742CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 750return CAPI.S_FALSE; 754return CAPI.S_FALSE; 757return CAPI.S_OK; 770CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 771if (CAPI.CertVerifyTimeValidity(ref ft, pCertContext.pCertInfo) == 0) 772return CAPI.S_OK; 774return CAPI.S_FALSE; 787CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 788if (CAPI.CertVerifyTimeValidity(ref ft, pCertContext.pCertInfo) == 1) 789return CAPI.S_OK; 791return CAPI.S_FALSE; 804CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 805if (CAPI.CertVerifyTimeValidity(ref ft, pCertContext.pCertInfo) == -1) 806return CAPI.S_OK; 808return CAPI.S_FALSE; 825CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 826CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 828pV1Template = CAPI.CertFindExtension(CAPI.szOID_ENROLL_CERTTYPE_EXTENSION, 831pV2Template = CAPI.CertFindExtension(CAPI.szOID_CERTIFICATE_TEMPLATE, 836return CAPI.S_FALSE; 839CAPI.CERT_EXTENSION extension = (CAPI.CERT_EXTENSION) Marshal.PtrToStructure(pV1Template, typeof(CAPI.CERT_EXTENSION)); 846bool result = CAPI.DecodeObject(new IntPtr(CAPI.X509_UNICODE_ANY_STRING), 851CAPI.CERT_NAME_VALUE pNameValue = (CAPI.CERT_NAME_VALUE) Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CERT_NAME_VALUE)); 854return CAPI.S_OK; 859CAPI.CERT_EXTENSION extension = (CAPI.CERT_EXTENSION) Marshal.PtrToStructure(pV2Template, typeof(CAPI.CERT_EXTENSION)); 866bool result = CAPI.DecodeObject(new IntPtr(CAPI.X509_CERTIFICATE_TEMPLATE), 871CAPI.CERT_TEMPLATE_EXT pTemplate = (CAPI.CERT_TEMPLATE_EXT) Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CERT_TEMPLATE_EXT)); 873string oidValue = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_NAME_KEY, (string)pvCallbackData, OidGroup.Template); 877return CAPI.S_OK; 881return CAPI.S_FALSE; 895return CAPI.S_FALSE; 900if (!CAPI.CertGetValidUsages(1, new IntPtr(&pCertContext), new IntPtr(&cNumOIDs), rghOIDs, new IntPtr(&cbOIDs))) 901return CAPI.S_FALSE; 903rghOIDs = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbOIDs)); 904if (!CAPI.CertGetValidUsages(1, new IntPtr(&pCertContext), new IntPtr(&cNumOIDs), rghOIDs, new IntPtr(&cbOIDs))) 905return CAPI.S_FALSE; 909return CAPI.S_OK; 915return CAPI.S_OK; 918return CAPI.S_FALSE; 932return CAPI.S_FALSE; 933CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 934CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 936IntPtr pExtension = CAPI.CertFindExtension(CAPI.szOID_CERT_POLICIES, 940return CAPI.S_FALSE; 942CAPI.CERT_EXTENSION extension = (CAPI.CERT_EXTENSION) Marshal.PtrToStructure(pExtension, typeof(CAPI.CERT_EXTENSION)); 949bool result = CAPI.DecodeObject(new IntPtr(CAPI.X509_CERT_POLICIES), 954CAPI.CERT_POLICIES_INFO pInfo = (CAPI.CERT_POLICIES_INFO) Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CERT_POLICIES_INFO)); 956IntPtr pPolicyInfoPtr = new IntPtr((long) pInfo.rgPolicyInfo + index * Marshal.SizeOf(typeof(CAPI.CERT_POLICY_INFO))); 957CAPI.CERT_POLICY_INFO pPolicyInfo = (CAPI.CERT_POLICY_INFO) Marshal.PtrToStructure(pPolicyInfoPtr, typeof(CAPI.CERT_POLICY_INFO)); 959return CAPI.S_OK; 963return CAPI.S_FALSE; 975CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 976CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 978IntPtr pExtension = CAPI.CertFindExtension((string) pvCallbackData, 982return CAPI.S_FALSE; 984return CAPI.S_OK; 998CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) safeCertContextHandle.DangerousGetHandle()); 1000if (!CAPI.CertGetIntendedKeyUsage(CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 1004return CAPI.S_OK; // no key usage means it is valid for all key usages. 1008return CAPI.S_OK; 1010return CAPI.S_FALSE; 1027if (!CAPI.CertGetCertificateContextProperty(safeCertContextHandle, 1028CAPI.CERT_KEY_IDENTIFIER_PROP_ID, 1031return CAPI.S_FALSE; 1033ptr = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(cbData)); 1034if (!CAPI.CertGetCertificateContextProperty(safeCertContextHandle, 1035CAPI.CERT_KEY_IDENTIFIER_PROP_ID, 1038return CAPI.S_FALSE; 1042return CAPI.S_FALSE; 1050return CAPI.S_FALSE; 1053return CAPI.S_OK; 1057(CAPI.CERT_QUERY_CONTENT_FLAG_CERT | 1058CAPI.CERT_QUERY_CONTENT_FLAG_SERIALIZED_CERT | 1059CAPI.CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED | 1060CAPI.CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED | 1061CAPI.CERT_QUERY_CONTENT_FLAG_PKCS7_UNSIGNED | 1062CAPI.CERT_QUERY_CONTENT_FLAG_PFX | 1063CAPI.CERT_QUERY_CONTENT_FLAG_SERIALIZED_STORE); 1075if (!CAPI.CryptQueryObject(CAPI.CERT_QUERY_OBJECT_BLOB, 1078CAPI.CERT_QUERY_FORMAT_FLAG_ALL, 1088if (contentType == CAPI.CERT_QUERY_CONTENT_PFX) { 1090safeCertStoreHandle = CAPI.PFXImportCertStore(CAPI.CERT_QUERY_OBJECT_BLOB, 1113if (!CAPI.CryptQueryObject(CAPI.CERT_QUERY_OBJECT_FILE, 1116CAPI.CERT_QUERY_FORMAT_FLAG_ALL, 1126if (contentType == CAPI.CERT_QUERY_CONTENT_PFX) { 1128safeCertStoreHandle = CAPI.PFXImportCertStore(CAPI.CERT_QUERY_OBJECT_FILE,
security\system\security\cryptography\x509\x509chain.cs (71)
115m_safeCertChainHandle = CAPI.CertDuplicateCertificateChain(chainContext); 194if (certificate.Extensions[CAPI.szOID_CRL_DIST_POINTS] != null || 195certificate.Extensions[CAPI.szOID_AUTHORITY_INFO_ACCESS] != null) { 207int hr = BuildChain(m_useMachineContext ? new IntPtr(CAPI.HCCE_LOCAL_MACHINE) : new IntPtr(CAPI.HCCE_CURRENT_USER), 218if (hr != CAPI.S_OK) 225CAPI.CERT_CHAIN_POLICY_PARA PolicyPara = new CAPI.CERT_CHAIN_POLICY_PARA(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_PARA))); 226CAPI.CERT_CHAIN_POLICY_STATUS PolicyStatus = new CAPI.CERT_CHAIN_POLICY_STATUS(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_STATUS))); 230if (!CAPI.CertVerifyCertificateChainPolicy(new IntPtr(CAPI.CERT_CHAIN_POLICY_BASE), 237CAPI.SetLastError(PolicyStatus.dwError); 276using (SafeX509ChainHandle safeCertChainHandle = CAPI.CertDuplicateCertificateChain(m_safeCertChainHandle)) { 277CAPI.CERT_CHAIN_CONTEXT pChain = new CAPI.CERT_CHAIN_CONTEXT(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_CONTEXT))); 359CAPI.CERT_CHAIN_PARA ChainPara = new CAPI.CERT_CHAIN_PARA(); 369ChainPara.RequestedUsage.dwType = CAPI.USAGE_MATCH_TYPE_AND; 377ChainPara.RequestedIssuancePolicy.dwType = CAPI.USAGE_MATCH_TYPE_AND; 391if (!CAPI.CertGetCertificateChain(hChainEngine, 406return CAPI.S_OK; 425new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_NOT_SIGNATURE_VALID, CAPI.TRUST_E_CERT_SIGNATURE, X509ChainStatusFlags.NotSignatureValid), 426new X509ChainErrorMapping(CAPI.CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID, CAPI.TRUST_E_CERT_SIGNATURE, X509ChainStatusFlags.CtlNotSignatureValid), 427new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_UNTRUSTED_ROOT, CAPI.CERT_E_UNTRUSTEDROOT, X509ChainStatusFlags.UntrustedRoot), 428new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_PARTIAL_CHAIN, CAPI.CERT_E_CHAINING, X509ChainStatusFlags.PartialChain), 429new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_REVOKED, CAPI.CRYPT_E_REVOKED, X509ChainStatusFlags.Revoked), 430new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_NOT_VALID_FOR_USAGE, CAPI.CERT_E_WRONG_USAGE, X509ChainStatusFlags.NotValidForUsage), 431new X509ChainErrorMapping(CAPI.CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE, CAPI.CERT_E_WRONG_USAGE, X509ChainStatusFlags.CtlNotValidForUsage), 432new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_NOT_TIME_VALID, CAPI.CERT_E_EXPIRED, X509ChainStatusFlags.NotTimeValid), 433new X509ChainErrorMapping(CAPI.CERT_TRUST_CTL_IS_NOT_TIME_VALID, CAPI.CERT_E_EXPIRED, X509ChainStatusFlags.CtlNotTimeValid), 434new X509ChainErrorMapping(CAPI.CERT_TRUST_INVALID_NAME_CONSTRAINTS, CAPI.CERT_E_INVALID_NAME, X509ChainStatusFlags.InvalidNameConstraints), 435new X509ChainErrorMapping(CAPI.CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT, CAPI.CERT_E_INVALID_NAME, X509ChainStatusFlags.HasNotSupportedNameConstraint), 436new X509ChainErrorMapping(CAPI.CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT, CAPI.CERT_E_INVALID_NAME, X509ChainStatusFlags.HasNotDefinedNameConstraint), 437new X509ChainErrorMapping(CAPI.CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT, CAPI.CERT_E_INVALID_NAME, X509ChainStatusFlags.HasNotPermittedNameConstraint), 438new X509ChainErrorMapping(CAPI.CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT, CAPI.CERT_E_INVALID_NAME, X509ChainStatusFlags.HasExcludedNameConstraint), 439new X509ChainErrorMapping(CAPI.CERT_TRUST_INVALID_POLICY_CONSTRAINTS, CAPI.CERT_E_INVALID_POLICY, X509ChainStatusFlags.InvalidPolicyConstraints), 440new X509ChainErrorMapping(CAPI.CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY, CAPI.CERT_E_INVALID_POLICY, X509ChainStatusFlags.NoIssuanceChainPolicy), 441new X509ChainErrorMapping(CAPI.CERT_TRUST_INVALID_BASIC_CONSTRAINTS, CAPI.TRUST_E_BASIC_CONSTRAINTS, X509ChainStatusFlags.InvalidBasicConstraints), 442new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_NOT_TIME_NESTED, CAPI.CERT_E_VALIDITYPERIODNESTING, X509ChainStatusFlags.NotTimeNested), 443new X509ChainErrorMapping(CAPI.CERT_TRUST_REVOCATION_STATUS_UNKNOWN, CAPI.CRYPT_E_NO_REVOCATION_CHECK, X509ChainStatusFlags.RevocationStatusUnknown), 444new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_OFFLINE_REVOCATION, CAPI.CRYPT_E_REVOCATION_OFFLINE, X509ChainStatusFlags.OfflineRevocation), 445new X509ChainErrorMapping(CAPI.CERT_TRUST_IS_EXPLICIT_DISTRUST, CAPI.TRUST_E_EXPLICIT_DISTRUST, X509ChainStatusFlags.ExplicitDistrust), 446new X509ChainErrorMapping(CAPI.CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT, CAPI.CERT_E_CRITICAL, X509ChainStatusFlags.HasNotSupportedCriticalExtension), 447new X509ChainErrorMapping(CAPI.CERT_TRUST_HAS_WEAK_SIGNATURE, CAPI.CERTSRV_E_WEAK_SIGNATURE_OR_KEY, X509ChainStatusFlags.HasWeakSignature),
security\system\security\cryptography\x509\x509chainelement.cs (6)
26CAPI.CERT_CHAIN_ELEMENT chainElement = new CAPI.CERT_CHAIN_ELEMENT(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_ELEMENT))); 75CAPI.CERT_SIMPLE_CHAIN simpleChain = new CAPI.CERT_SIMPLE_CHAIN(Marshal.SizeOf(typeof(CAPI.CERT_SIMPLE_CHAIN)));
security\system\security\cryptography\x509\x509extension.cs (83)
27CAPI.CERT_EXTENSION extension = (CAPI.CERT_EXTENSION) Marshal.PtrToStructure(pExtension, typeof(CAPI.CERT_EXTENSION)); 95public X509KeyUsageExtension() : base (CAPI.szOID_KEY_USAGE) { 103base (CAPI.szOID_KEY_USAGE, EncodeExtension(keyUsages), critical) {} 106base (CAPI.szOID_KEY_USAGE, encodedKeyUsage.RawData, critical) {} 128bool result = CAPI.DecodeObject(new IntPtr(CAPI.X509_KEY_USAGE), 135CAPI.CRYPTOAPI_BLOB pKeyUsage = (CAPI.CRYPTOAPI_BLOB) Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CRYPTOAPI_BLOB)); 151CAPI.CRYPT_BIT_BLOB blob = new CAPI.CRYPT_BIT_BLOB(); 157if (!CAPI.EncodeObject(CAPI.szOID_KEY_USAGE, new IntPtr(&blob), out encodedKeyUsages)) 170public X509BasicConstraintsExtension() : base (CAPI.szOID_BASIC_CONSTRAINTS2) { 175base (CAPI.szOID_BASIC_CONSTRAINTS2, EncodeExtension(certificateAuthority, hasPathLengthConstraint, pathLengthConstraint), critical) {} 178base (CAPI.szOID_BASIC_CONSTRAINTS2, encodedBasicConstraints.RawData, critical) {} 216if (Oid.Value == CAPI.szOID_BASIC_CONSTRAINTS) { 217bool result = CAPI.DecodeObject(new IntPtr(CAPI.X509_BASIC_CONSTRAINTS), 224CAPI.CERT_BASIC_CONSTRAINTS_INFO pBasicConstraints = (CAPI.CERT_BASIC_CONSTRAINTS_INFO) Marshal.PtrToStructure(decoded.DangerousGetHandle(), 225typeof(CAPI.CERT_BASIC_CONSTRAINTS_INFO)); 231m_isCA = (isCA[0] & CAPI.CERT_CA_SUBJECT_FLAG) != 0 ? true : false; 235bool result = CAPI.DecodeObject(new IntPtr(CAPI.X509_BASIC_CONSTRAINTS2), 242CAPI.CERT_BASIC_CONSTRAINTS2_INFO pBasicConstraints2 = (CAPI.CERT_BASIC_CONSTRAINTS2_INFO) Marshal.PtrToStructure(decoded.DangerousGetHandle(), 243typeof(CAPI.CERT_BASIC_CONSTRAINTS2_INFO)); 258CAPI.CERT_BASIC_CONSTRAINTS2_INFO pBasicConstraints2 = new CAPI.CERT_BASIC_CONSTRAINTS2_INFO(); 268if (!CAPI.EncodeObject(CAPI.szOID_BASIC_CONSTRAINTS2, new IntPtr(&pBasicConstraints2), out encodedBasicConstraints)) 279public X509EnhancedKeyUsageExtension() : base (CAPI.szOID_ENHANCED_KEY_USAGE) { 285base (CAPI.szOID_ENHANCED_KEY_USAGE, EncodeExtension(enhancedKeyUsages), critical) {} 288base (CAPI.szOID_ENHANCED_KEY_USAGE, encodedEnhancedKeyUsages.RawData, critical) {} 317bool result = CAPI.DecodeObject(new IntPtr(CAPI.X509_ENHANCED_KEY_USAGE), 324CAPI.CERT_ENHKEY_USAGE pEnhKeyUsage = (CAPI.CERT_ENHKEY_USAGE) Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CERT_ENHKEY_USAGE)); 348CAPI.CERT_ENHKEY_USAGE pEnhKeyUsage = new CAPI.CERT_ENHKEY_USAGE(); 351if (!CAPI.EncodeObject(CAPI.szOID_ENHANCED_KEY_USAGE, new IntPtr(&pEnhKeyUsage), out encodedEnhancedKeyUsages)) 369public X509SubjectKeyIdentifierExtension() : base (CAPI.szOID_SUBJECT_KEY_IDENTIFIER) { 378base (CAPI.szOID_SUBJECT_KEY_IDENTIFIER, EncodeExtension(subjectKeyIdentifier), critical) {} 384base (CAPI.szOID_SUBJECT_KEY_IDENTIFIER, EncodeExtension(subjectKeyIdentifier), critical) {} 390base (CAPI.szOID_SUBJECT_KEY_IDENTIFIER, encodedSubjectKeyIdentifier.RawData, critical) {} 396base (CAPI.szOID_SUBJECT_KEY_IDENTIFIER, EncodePublicKey(key, X509SubjectKeyIdentifierHashAlgorithm.Sha1), critical) {} 402base (CAPI.szOID_SUBJECT_KEY_IDENTIFIER, EncodePublicKey(key, algorithm), critical) {} 427SafeLocalAllocHandle pb = X509Utils.StringToAnsiPtr(CAPI.szOID_SUBJECT_KEY_IDENTIFIER); 428bool result = CAPI.DecodeObject(pb.DangerousGetHandle(), 435CAPI.CRYPTOAPI_BLOB pSubjectKeyIdentifier = (CAPI.CRYPTOAPI_BLOB) Marshal.PtrToStructure(decoded.DangerousGetHandle(), typeof(CAPI.CRYPTOAPI_BLOB)); 436byte[] hexArray = CAPI.BlobToByteArray(pSubjectKeyIdentifier); 462CAPI.CRYPTOAPI_BLOB pSubjectKeyIdentifier = new CAPI.CRYPTOAPI_BLOB(); 466if (!CAPI.EncodeObject(CAPI.szOID_SUBJECT_KEY_IDENTIFIER, new IntPtr(&pSubjectKeyIdentifier), out encodedSubjectKeyIdentifier)) 479CAPI.CERT_PUBLIC_KEY_INFO2 * pPublicKeyInfo = null; 484uint cbPublicKeyInfo = (uint) (Marshal.SizeOf(typeof(CAPI.CERT_PUBLIC_KEY_INFO2)) + 489publicKeyInfo = CAPI.LocalAlloc(CAPI.LPTR, new IntPtr(cbPublicKeyInfo)); 490pPublicKeyInfo = (CAPI.CERT_PUBLIC_KEY_INFO2 *) publicKeyInfo.DangerousGetHandle(); 491IntPtr pszObjId = new IntPtr((long) pPublicKeyInfo + Marshal.SizeOf(typeof(CAPI.CERT_PUBLIC_KEY_INFO2))); 519CAPI.CERT_PUBLIC_KEY_INFO2 * pPublicKeyInfo = (CAPI.CERT_PUBLIC_KEY_INFO2 *) publicKeyInfo.DangerousGetHandle(); 535if (!CAPI.CryptHashCertificate( 537CAPI.CALG_SHA1, 550if (!CAPI.CryptHashPublicKeyInfo( 552CAPI.CALG_SHA1, 554CAPI.X509_ASN_ENCODING, 604using (SafeCertContextHandle certContext = CAPI.CertDuplicateCertificateContext(safeCertContextHandle)) { 605CAPI.CERT_CONTEXT pCertContext = *((CAPI.CERT_CONTEXT*) certContext.DangerousGetHandle()); 606CAPI.CERT_INFO pCertInfo = (CAPI.CERT_INFO) Marshal.PtrToStructure(pCertContext.pCertInfo, typeof(CAPI.CERT_INFO)); 611X509Extension extension = new X509Extension(new IntPtr((long)rgExtensions + (index * Marshal.SizeOf(typeof(CAPI.CERT_EXTENSION))))); 637string oidValue = X509Utils.FindOidInfoWithFallback(CAPI.CRYPT_OID_INFO_NAME_KEY, oid, OidGroup.ExtensionOrAttribute);
security\system\security\cryptography\x509\x509store.cs (14)
116m_safeCertStoreHandle = CAPI.CertDuplicateStore(storeHandle); 156m_safeCertStoreHandle = CAPI.CertOpenStore(new IntPtr(CAPI.CERT_STORE_PROV_SYSTEM), 157CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 170CAPI.CertControlStore(m_safeCertStoreHandle, 172CAPI.CERT_STORE_CTRL_AUTO_RESYNC, 198if (!CAPI.CertAddCertificateContextToStore(m_safeCertStoreHandle, 200CAPI.CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES, 277SafeCertContextHandle safeCertContext2 = CAPI.CertFindCertificateInStore(safeCertStoreHandle, 278CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 280CAPI.CERT_FIND_EXISTING, 293if (!CAPI.CertDeleteCertificateFromStore(safeCertContext2))
security\system\security\cryptography\x509\x509utils.cs (70)
28return ((dwValueType & CAPI.CERT_RDN_TYPE_MASK) >= CAPI.CERT_RDN_NUMERIC_STRING); 35case CAPI.CERT_QUERY_CONTENT_CERT: 37case CAPI.CERT_QUERY_CONTENT_SERIALIZED_STORE: 39case CAPI.CERT_QUERY_CONTENT_SERIALIZED_CERT: 41case CAPI.CERT_QUERY_CONTENT_PKCS7_SIGNED: 42case CAPI.CERT_QUERY_CONTENT_PKCS7_UNSIGNED: 44case CAPI.CERT_QUERY_CONTENT_PKCS7_SIGNED_EMBED: 46case CAPI.CERT_QUERY_CONTENT_PFX: 89dwFlags |= CAPI.CRYPT_USER_KEYSET; 91dwFlags |= CAPI.CRYPT_MACHINE_KEYSET; 94dwFlags |= CAPI.CRYPT_EXPORTABLE; 96dwFlags |= CAPI.CRYPT_USER_PROTECTED; 99dwFlags |= CAPI.PKCS12_NO_PERSIST_KEY | CAPI.PKCS12_ALWAYS_CNG_KSP; 110dwFlags |= CAPI.CERT_STORE_READONLY_FLAG; 113dwFlags |= CAPI.CERT_STORE_MAXIMUM_ALLOWED_FLAG; 118dwFlags |= CAPI.CERT_STORE_OPEN_EXISTING_FLAG; 120dwFlags |= CAPI.CERT_STORE_ENUM_ARCHIVED_FLAG; 123dwFlags |= CAPI.CERT_SYSTEM_STORE_LOCAL_MACHINE; 125dwFlags |= CAPI.CERT_SYSTEM_STORE_CURRENT_USER; 135type = CAPI.CERT_NAME_SIMPLE_DISPLAY_TYPE; 138type = CAPI.CERT_NAME_EMAIL_TYPE; 141type = CAPI.CERT_NAME_UPN_TYPE; 145type = CAPI.CERT_NAME_DNS_TYPE; 148type = CAPI.CERT_NAME_URL_TYPE; 164dwFlags |= CAPI.CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY; 167dwFlags |= CAPI.CERT_CHAIN_REVOCATION_CHECK_END_CERT; 169dwFlags |= CAPI.CERT_CHAIN_REVOCATION_CHECK_CHAIN; 171dwFlags |= CAPI.CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT; 271SafeLocalAllocHandle pb = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(managed.Length)); 318SafeLocalAllocHandle pb = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(arr.Length)); 329SafeLocalAllocHandle pb = CAPI.LocalAlloc(CAPI.LMEM_FIXED, new IntPtr(arr.Length)); 354safeCertStoreHandle = CAPI.CertOpenStore(new IntPtr(CAPI.CERT_STORE_PROV_MEMORY), 355CAPI.X509_ASN_ENCODING | CAPI.PKCS_7_ASN_ENCODING, 357CAPI.CERT_STORE_ENUM_ARCHIVED_FLAG | CAPI.CERT_STORE_CREATE_NEW_FLAG, 369if (!CAPI.CertAddCertificateLinkToStore(safeCertStoreHandle, 371CAPI.CERT_STORE_ADD_ALWAYS, 384CAPI.CRYPT_OID_INFO pOIDInfo = CAPI.CryptFindOIDInfo(CAPI.CRYPT_OID_INFO_OID_KEY, pszOid, 0); 401case CAPI.CRYPT_OID_INFO_OID_KEY: 405case CAPI.CRYPT_OID_INFO_NAME_KEY: 414CAPI.CRYPT_OID_INFO pOidInfo = CAPI.CryptFindOIDInfo(keyType, pvKey, oidGroup); 417if (keyType == CAPI.CRYPT_OID_INFO_OID_KEY) { 507safeLocalAllocHandle = CAPI.LocalAlloc(CAPI.LPTR, new IntPtr((uint)ptrSize + (uint)oidSize)); 524IntPtr pEnumContext = CAPI.CertEnumCertificatesInStore(safeCertStoreHandle, IntPtr.Zero); 528pEnumContext = CAPI.CertEnumCertificatesInStore(safeCertStoreHandle, pEnumContext); 556CAPI.CERT_CHAIN_POLICY_PARA PolicyPara = new CAPI.CERT_CHAIN_POLICY_PARA(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_PARA))); 557CAPI.CERT_CHAIN_POLICY_STATUS PolicyStatus = new CAPI.CERT_CHAIN_POLICY_STATUS(Marshal.SizeOf(typeof(CAPI.CERT_CHAIN_POLICY_STATUS))); 561int hr = X509Chain.BuildChain(new IntPtr(CAPI.HCCE_CURRENT_USER), 571if (hr != CAPI.S_OK) 575if (CAPI.CertVerifyCertificateChainPolicy(pszPolicy, pChainContext, ref PolicyPara, ref PolicyStatus)) { 580return CAPI.S_FALSE; 586return CAPI.S_OK; 594uint dwErrorCode = CAPI.FormatMessage (CAPI.FORMAT_MESSAGE_FROM_SYSTEM | CAPI.FORMAT_MESSAGE_IGNORE_INSERTS,