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