Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SafeCertContextHandleWithKeyContainerDeletion.cs
Go to the documentation of this file.
1
using
System
;
2
using
System.Runtime.InteropServices
;
3
using
System.Security.Cryptography
;
4
5
namespace
Internal.Cryptography.Pal.Native
;
6
7
internal
sealed
class
SafeCertContextHandleWithKeyContainerDeletion
:
SafeCertContextHandle
8
{
9
protected
sealed
override
bool
ReleaseHandle
()
10
{
11
using
(
SafeCertContextHandle
pCertContext = global::Interop.crypt32.CertDuplicateCertificateContext(
handle
))
12
{
13
DeleteKeyContainer
(pCertContext);
14
}
15
base.ReleaseHandle();
16
return
true
;
17
}
18
19
public
unsafe
static
void
DeleteKeyContainer
(
SafeCertContextHandle
pCertContext)
20
{
21
if
(pCertContext.
IsInvalid
)
22
{
23
return
;
24
}
25
int
pcbData = 0;
26
if
(!global::Interop.crypt32.CertGetCertificateContextProperty(pCertContext,
CertContextPropId
.CERT_KEY_PROV_INFO_PROP_ID,
null
, ref pcbData))
27
{
28
return
;
29
}
30
byte
[]
array
=
new
byte
[pcbData];
31
if
(!global::Interop.crypt32.CertGetCertificateContextProperty(pCertContext,
CertContextPropId
.CERT_KEY_PROV_INFO_PROP_ID,
array
, ref pcbData))
32
{
33
return
;
34
}
35
fixed (
byte
* ptr =
array
)
36
{
37
CRYPT_KEY_PROV_INFO
* ptr2 = (
CRYPT_KEY_PROV_INFO
*)ptr;
38
if
(ptr2->
dwProvType
== 0)
39
{
40
string
provider =
Marshal
.
PtrToStringUni
((
IntPtr
)ptr2->
pwszProvName
);
41
string
keyName =
Marshal
.
PtrToStringUni
((
IntPtr
)ptr2->
pwszContainerName
);
42
try
43
{
44
using
CngKey
cngKey =
CngKey
.
Open
(keyName,
new
CngProvider
(provider));
45
cngKey.Delete();
46
}
47
catch
(
CryptographicException
)
48
{
49
}
50
}
51
else
52
{
53
CryptAcquireContextFlags
dwFlags = (ptr2->
dwFlags
&
CryptAcquireContextFlags
.CRYPT_MACHINE_KEYSET) |
CryptAcquireContextFlags
.CRYPT_DELETEKEYSET;
54
global::Interop.cryptoapi.CryptAcquireContext(out var _, ptr2->
pwszContainerName
, ptr2->
pwszProvName
, ptr2->
dwProvType
, dwFlags);
55
}
56
}
57
}
58
}
Internal.Cryptography.Pal.Native.SafeCertContextHandleWithKeyContainerDeletion.DeleteKeyContainer
static unsafe void DeleteKeyContainer(SafeCertContextHandle pCertContext)
Definition
SafeCertContextHandleWithKeyContainerDeletion.cs:19
Internal.Cryptography.Pal.Native.SafeCertContextHandleWithKeyContainerDeletion.ReleaseHandle
override bool ReleaseHandle()
Definition
SafeCertContextHandleWithKeyContainerDeletion.cs:9
Internal.Cryptography.Pal.Native.SafeCertContextHandleWithKeyContainerDeletion
Definition
SafeCertContextHandleWithKeyContainerDeletion.cs:8
Internal.Cryptography.Pal.Native.SafeCertContextHandle
Definition
SafeCertContextHandle.cs:6
Internal.Cryptography.Pal.Native.SafePointerHandle.IsInvalid
override bool IsInvalid
Definition
SafePointerHandle.cs:9
System.Runtime.InteropServices.Marshal.PtrToStringUni
static unsafe? string PtrToStringUni(IntPtr ptr)
Definition
Marshal.cs:652
System.Runtime.InteropServices.Marshal
Definition
Marshal.cs:14
System.Security.Cryptography.CngKey.Open
static CngKey Open(string keyName)
Definition
CngKey.cs:799
System.Security.Cryptography.CngKey
Definition
CngKey.cs:10
System.Security.Cryptography.CngProvider
Definition
CngProvider.cs:6
System.Security.Cryptography.CryptographicException
Definition
CryptographicException.cs:9
Internal.Cryptography.Pal.Native.CertContextPropId
CertContextPropId
Definition
CertContextPropId.cs:4
Internal.Cryptography.Pal.Native.CryptAcquireContextFlags
CryptAcquireContextFlags
Definition
CryptAcquireContextFlags.cs:7
Internal.Cryptography.Pal.Native
Definition
CERT_BASIC_CONSTRAINTS2_INFO.cs:1
System.Runtime.InteropServices
Definition
SequenceMarshal.cs:4
System.Security.Cryptography
Definition
CryptoPool.cs:3
System.ExceptionArgument.handle
@ handle
System.ExceptionArgument.array
@ array
System
Definition
BlockingCollection.cs:8
Internal.Cryptography.Pal.Native.CRYPT_KEY_PROV_INFO.dwProvType
int dwProvType
Definition
CRYPT_KEY_PROV_INFO.cs:11
Internal.Cryptography.Pal.Native.CRYPT_KEY_PROV_INFO.pwszProvName
unsafe char * pwszProvName
Definition
CRYPT_KEY_PROV_INFO.cs:9
Internal.Cryptography.Pal.Native.CRYPT_KEY_PROV_INFO.dwFlags
CryptAcquireContextFlags dwFlags
Definition
CRYPT_KEY_PROV_INFO.cs:13
Internal.Cryptography.Pal.Native.CRYPT_KEY_PROV_INFO.pwszContainerName
unsafe char * pwszContainerName
Definition
CRYPT_KEY_PROV_INFO.cs:7
Internal.Cryptography.Pal.Native.CRYPT_KEY_PROV_INFO
Definition
CRYPT_KEY_PROV_INFO.cs:6
System.IntPtr
Definition
IntPtr.cs:14
source
System.Security.Cryptography.X509Certificates
Internal.Cryptography.Pal.Native
SafeCertContextHandleWithKeyContainerDeletion.cs
Generated by
1.10.0